diff --git a/php/Access/Admin.php b/php/Access/Admin.php index ea54194..99bbb35 100644 --- a/php/Access/Admin.php +++ b/php/Access/Admin.php @@ -88,7 +88,7 @@ final class Admin extends Access { Validator::required(isset($_POST['title']), __METHOD__); $album = new Album(null); - echo $album->add($_POST['title']); + Response::json($album->add($_POST['title'])); } @@ -97,7 +97,7 @@ final class Admin extends Access { Validator::required(isset($_POST['albumIDs'], $_POST['title']), __METHOD__); $album = new Album($_POST['albumIDs']); - echo $album->setTitle($_POST['title']); + Response::json($album->setTitle($_POST['title'])); } @@ -106,7 +106,7 @@ final class Admin extends Access { Validator::required(isset($_POST['albumID'], $_POST['description']), __METHOD__); $album = new Album($_POST['albumID']); - echo $album->setDescription($_POST['description']); + Response::json($album->setDescription($_POST['description'])); } @@ -115,7 +115,7 @@ final class Admin extends Access { Validator::required(isset($_POST['albumID'], $_POST['password'], $_POST['visible'], $_POST['downloadable']), __METHOD__); $album = new Album($_POST['albumID']); - echo $album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable']); + Response::json($album->setPublic($_POST['public'], $_POST['password'], $_POST['visible'], $_POST['downloadable'])); } @@ -124,7 +124,7 @@ final class Admin extends Access { Validator::required(isset($_POST['albumIDs']), __METHOD__); $album = new Album($_POST['albumIDs']); - echo $album->delete(); + Response::json($album->delete()); } @@ -132,7 +132,7 @@ final class Admin extends Access { Validator::required(isset($_POST['albumIDs']), __METHOD__); $album = new Album($_POST['albumIDs']); - echo $album->merge(); + Response::json($album->merge()); } @@ -152,7 +152,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoIDs'], $_POST['title']), __METHOD__); $photo = new Photo($_POST['photoIDs']); - echo $photo->setTitle($_POST['title']); + Response::json($photo->setTitle($_POST['title'])); } @@ -161,7 +161,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoID'], $_POST['description']), __METHOD__); $photo = new Photo($_POST['photoID']); - echo $photo->setDescription($_POST['description']); + Response::json($photo->setDescription($_POST['description'])); } @@ -170,7 +170,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoIDs']), __METHOD__); $photo = new Photo($_POST['photoIDs']); - echo $photo->setStar(); + Response::json($photo->setStar()); } @@ -179,7 +179,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoID']), __METHOD__); $photo = new Photo($_POST['photoID']); - echo $photo->setPublic(); + Response::json($photo->setPublic()); } @@ -188,7 +188,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoIDs'], $_POST['albumID']), __METHOD__); $photo = new Photo($_POST['photoIDs']); - echo $photo->setAlbum($_POST['albumID']); + Response::json($photo->setAlbum($_POST['albumID'])); } @@ -197,7 +197,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoIDs'], $_POST['tags']), __METHOD__); $photo = new Photo($_POST['photoIDs']); - echo $photo->setTags($_POST['tags']); + Response::json($photo->setTags($_POST['tags'])); } @@ -206,7 +206,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoIDs']), __METHOD__); $photo = new Photo($_POST['photoIDs']); - echo $photo->duplicate(); + Response::json($photo->duplicate()); } @@ -215,7 +215,7 @@ final class Admin extends Access { Validator::required(isset($_POST['photoIDs']), __METHOD__); $photo = new Photo($_POST['photoIDs']); - echo $photo->delete(); + Response::json($photo->delete()); } @@ -223,10 +223,10 @@ final class Admin extends Access { private static function uploadAction() { - Validator::required(isset($_FILES, $_POST['albumID'], $_POST['tags']), __METHOD__); + Validator::required(isset($_FILES, $_POST['albumID']), __METHOD__); $photo = new Photo(null); - echo $photo->add($_FILES, $_POST['albumID'], '', $_POST['tags']); + Response::json($photo->add($_FILES, $_POST['albumID'])); } @@ -235,7 +235,7 @@ final class Admin extends Access { Validator::required(isset($_POST['url'], $_POST['albumID']), __METHOD__); $import = new Import(); - echo $import->url($_POST['url'], $_POST['albumID']); + Response::json($import->url($_POST['url'], $_POST['albumID'])); } @@ -272,14 +272,14 @@ final class Admin extends Access { Validator::required(isset($_POST['user'], $_POST['password']), __METHOD__); $session = new Session(); - echo $session->login($_POST['user'], $_POST['password']); + Response::json($session->login($_POST['user'], $_POST['password'])); } private static function logoutAction() { $session = new Session(); - echo $session->logout(); + Response::json($session->logout()); } @@ -290,7 +290,7 @@ final class Admin extends Access { Validator::required(isset($_POST['username'], $_POST['password']), __METHOD__); if (isset($_POST['oldPassword'])===false) $_POST['oldPassword'] = ''; - echo Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password']); + Response::json(Settings::setLogin($_POST['oldPassword'], $_POST['username'], $_POST['password'])); } @@ -301,8 +301,8 @@ final class Admin extends Access { $sA = Settings::setSortingAlbums($_POST['typeAlbums'], $_POST['orderAlbums']); $sP = Settings::setSortingPhotos($_POST['typePhotos'], $_POST['orderPhotos']); - if ($sA===true&&$sP===true) echo true; - else echo false; + if ($sA===true&&$sP===true) Response::json(true); + else Response::json(false); } @@ -310,7 +310,7 @@ final class Admin extends Access { Validator::required(isset($_POST['key']), __METHOD__); - echo Settings::setDropboxKey($_POST['key']); + Response::json(Settings::setDropboxKey($_POST['key'])); } diff --git a/php/Access/Guest.php b/php/Access/Guest.php index 269fef3..64a764b 100644 --- a/php/Access/Guest.php +++ b/php/Access/Guest.php @@ -55,8 +55,8 @@ final class Guest extends Access { if ($album->getPublic()===true) { // Album public - if ($album->checkPassword($_POST['password'])) Response::json($album->get()); - else Response::warning('Wrong password!'); + if ($album->checkPassword($_POST['password'])===true) Response::json($album->get()); + else Response::warning('Wrong password!'); } else { @@ -76,13 +76,13 @@ final class Guest extends Access { if ($album->getPublic()===true) { // Album public - if ($album->checkPassword($_POST['password'])) echo true; - else echo false; + if ($album->checkPassword($_POST['password'])===true) Response::json(true); + else Response::json(false); } else { // Album private - echo false; + Response::json(false); } @@ -118,14 +118,14 @@ final class Guest extends Access { Validator::required(isset($_POST['user'], $_POST['password']), __METHOD__); $session = new Session(); - echo $session->login($_POST['user'], $_POST['password']); + Response::json($session->login($_POST['user'], $_POST['password'])); } private static function logoutAction() { $session = new Session(); - echo $session->logout(); + Response::json($session->logout()); } diff --git a/src/scripts/api.js b/src/scripts/api.js index 6ed4d2b..d45a007 100644 --- a/src/scripts/api.js +++ b/src/scripts/api.js @@ -27,8 +27,8 @@ api.post = function(fn, params, callback) { } // Convert 1 to true and an empty string to false - if (data==='1') data = true - else if (data==='') data = false + if (data==='true') data = true + else if (data==='false') data = false // Convert to JSON if string start with '{' and ends with '}' if (typeof data==='string' && data.substring(0, 1)==='{' && data.substring(data.length - 1, data.length)==='}') { diff --git a/src/scripts/upload.js b/src/scripts/upload.js index 9f546e7..45eb106 100755 --- a/src/scripts/upload.js +++ b/src/scripts/upload.js @@ -115,7 +115,6 @@ upload.start = { formData.append('function', 'Photo::add') formData.append('albumID', albumID) - formData.append('tags', '') formData.append(0, file) xhr.open('POST', api.path) @@ -128,7 +127,7 @@ upload.start = { file.ready = true // Set status - if (xhr.status===200 && xhr.responseText==='1') { + if (xhr.status===200 && xhr.responseText==='true') { // Success $('.basicModal .rows .row:nth-child(' + (file.num + 1) + ') .status')