From e9accae2a7dfda2c1e2151e3aa4eb2d437d263f4 Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Sun, 7 Feb 2016 14:32:46 +0100 Subject: [PATCH] Use Response in Access --- php/Access/Access.php | 4 +++- php/Access/Admin.php | 11 ++++++----- php/Access/Guest.php | 23 ++++++++++++----------- php/Access/Installation.php | 3 ++- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/php/Access/Access.php b/php/Access/Access.php index 6b471fe..43b8bab 100644 --- a/php/Access/Access.php +++ b/php/Access/Access.php @@ -2,11 +2,13 @@ namespace Lychee\Access; +use Lychee\Modules\Response; + abstract class Access { final protected static function fnNotFound() { - exit('Error: Function not found! Please check the spelling of the called function.'); + Response::error('Function not found! Please check the spelling of the called function.'); } diff --git a/php/Access/Admin.php b/php/Access/Admin.php index 2a5b3f5..1de45a3 100644 --- a/php/Access/Admin.php +++ b/php/Access/Admin.php @@ -5,6 +5,7 @@ namespace Lychee\Access; use Lychee\Modules\Album; use Lychee\Modules\Import; use Lychee\Modules\Photo; +use Lychee\Modules\Response; use Lychee\Modules\Session; use Lychee\Modules\Settings; use Lychee\Modules\Validator; @@ -72,7 +73,7 @@ final class Admin extends Access { private static function getAlbumsAction() { $album = new Album(null); - echo json_encode($album->getAll(false)); + Response::json($album->getAll(false)); } @@ -81,7 +82,7 @@ final class Admin extends Access { Validator::required(isset($_POST['albumID']), __METHOD__); $album = new Album($_POST['albumID']); - echo json_encode($album->get()); + Response::json($album->get()); } @@ -145,7 +146,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoID'], $_POST['albumID']), __METHOD__); $photo = new Photo($_POST['photoID']); - echo json_encode($photo->get($_POST['albumID'])); + Response::json($photo->get($_POST['albumID'])); } @@ -256,7 +257,7 @@ final class Admin extends Access { Validator::required(isset($_POST['term']), __METHOD__); - echo json_encode(search($_POST['term'])); + Response::json(search($_POST['term'])); } @@ -265,7 +266,7 @@ final class Admin extends Access { private static function initAction() { $session = new Session(); - echo json_encode($session->init(false)); + Response::json($session->init(false)); } diff --git a/php/Access/Guest.php b/php/Access/Guest.php index de30713..88abf02 100644 --- a/php/Access/Guest.php +++ b/php/Access/Guest.php @@ -4,6 +4,7 @@ namespace Lychee\Access; use Lychee\Modules\Album; use Lychee\Modules\Photo; +use Lychee\Modules\Response; use Lychee\Modules\Session; use Lychee\Modules\Validator; @@ -44,7 +45,7 @@ final class Guest extends Access { private static function getAlbumsAction() { $album = new Album(null); - echo json_encode($album->getAll(true)); + Response::json($album->getAll(true)); } @@ -57,13 +58,13 @@ final class Guest extends Access { if ($album->getPublic()) { // Album public - if ($album->checkPassword($_POST['password'])) echo json_encode($album->get()); - else echo 'Warning: Wrong password!'; + if ($album->checkPassword($_POST['password'])) Response::json($album->get()); + else Response::warning('Wrong password!'); } else { // Album private - echo 'Warning: Album private!'; + Response::warning('Album private!'); } @@ -100,9 +101,9 @@ final class Guest extends Access { $pgP = $photo->getPublic($_POST['password']); - if ($pgP===2) echo json_encode($photo->get($_POST['albumID'])); - else if ($pgP===1) echo 'Warning: Wrong password!'; - else if ($pgP===0) echo 'Warning: Photo private!'; + if ($pgP===2) Response::json($photo->get($_POST['albumID'])); + else if ($pgP===1) Response::warning('Wrong password!'); + else if ($pgP===0) Response::warning('Photo private!'); } @@ -111,7 +112,7 @@ final class Guest extends Access { private static function initAction() { $session = new Session(); - echo json_encode($session->init(true)); + Response::json($session->init(true)); } @@ -143,12 +144,12 @@ final class Guest extends Access { // Album Public if ($album->checkPassword($_GET['password'])) $album->getArchive(); - else exit('Warning: Wrong password!'); + else Response::warning('Wrong password!'); } else { // Album Private - exit('Warning: Album private or not downloadable!'); + Response::warning('Album private or not downloadable!'); } @@ -171,7 +172,7 @@ final class Guest extends Access { } else { // Photo Private - exit('Warning: Photo private or password incorrect!'); + Response::warning('Photo private or password incorrect!'); } diff --git a/php/Access/Installation.php b/php/Access/Installation.php index 0a4a2e2..370d0d0 100644 --- a/php/Access/Installation.php +++ b/php/Access/Installation.php @@ -3,6 +3,7 @@ namespace Lychee\Access; use Lychee\Modules\Config; +use Lychee\Modules\Response; use Lychee\Modules\Validator; final class Installation extends Access { @@ -36,7 +37,7 @@ final class Installation extends Access { 'status' => LYCHEE_STATUS_NOCONFIG ); - echo json_encode($return); + Response::json($return); }