From ec7e0aaf4c6392088d734f34d12ccfce8f786f68 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Thu, 31 Jan 2019 20:07:59 +0100 Subject: [PATCH] Ajax response improves --- bl-kernel/ajax/generate-slug.php | 5 ++--- bl-kernel/ajax/get-parents.php | 5 +---- bl-kernel/ajax/get-published.php | 5 +---- bl-kernel/ajax/save-as-draft.php | 16 ++++------------ bl-kernel/ajax/upload-logo.php | 11 +++-------- bl-kernel/ajax/upload-profile-picture.php | 16 ++++------------ 6 files changed, 15 insertions(+), 43 deletions(-) diff --git a/bl-kernel/ajax/generate-slug.php b/bl-kernel/ajax/generate-slug.php index b61f65dc..4db1b473 100644 --- a/bl-kernel/ajax/generate-slug.php +++ b/bl-kernel/ajax/generate-slug.php @@ -7,9 +7,8 @@ $oldKey = isset($_POST['currentKey']) ? $_POST['currentKey'] : ''; $slug = $pages->generateKey($text, $parent, $returnSlug=true, $oldKey); -exit (json_encode(array( - 'status'=>0, +ajaxResponse(0, 'Slug generated.', array( 'slug'=>$slug -))); +)); ?> \ No newline at end of file diff --git a/bl-kernel/ajax/get-parents.php b/bl-kernel/ajax/get-parents.php index fac85fcd..2064f4da 100644 --- a/bl-kernel/ajax/get-parents.php +++ b/bl-kernel/ajax/get-parents.php @@ -7,10 +7,7 @@ header('Content-Type: application/json'); $query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false; // ---------------------------------------------------------------------------- if ($query===false) { - exit (json_encode(array( - 'status'=>1, - 'files'=>'Invalid query.' - ))); + ajaxResponse(1, 'Invalid query.'); } $tmp = array(); diff --git a/bl-kernel/ajax/get-published.php b/bl-kernel/ajax/get-published.php index 00ca63f9..51b1f276 100644 --- a/bl-kernel/ajax/get-published.php +++ b/bl-kernel/ajax/get-published.php @@ -7,10 +7,7 @@ header('Content-Type: application/json'); $query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false; // ---------------------------------------------------------------------------- if ($query===false) { - exit (json_encode(array( - 'status'=>1, - 'files'=>'Invalid query.' - ))); + ajaxResponse(1, 'Invalid query.'); } $tmp = array(); diff --git a/bl-kernel/ajax/save-as-draft.php b/bl-kernel/ajax/save-as-draft.php index 41708e70..dcf2d111 100644 --- a/bl-kernel/ajax/save-as-draft.php +++ b/bl-kernel/ajax/save-as-draft.php @@ -13,18 +13,12 @@ $uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false; // Check UUID if (empty($uuid)) { - exit (json_encode(array( - 'status'=>1, - 'message'=>'Autosave fail. UUID not defined.' - ))); + ajaxResponse(1, 'Autosave fail. UUID not defined.'); } // Check content length to create the autosave page if (Text::length($content)<100) { - exit (json_encode(array( - 'status'=>1, - 'message'=>'Autosave not completed. The content length is less than 100 characters.' - ))); + ajaxResponse(1, 'Autosave not completed. The content length is less than 100 characters.'); } $autosaveUUID = 'autosave-'.$uuid; @@ -47,10 +41,8 @@ if (empty($pageKey)) { editPage($page); } -exit (json_encode(array( - 'status'=>0, - 'message'=>'Autosave successfully.', +ajaxResponse(0, 'Autosave successfully.', array( 'uuid'=>$autosaveUUID -))); +)); ?> \ No newline at end of file diff --git a/bl-kernel/ajax/upload-logo.php b/bl-kernel/ajax/upload-logo.php index bfc0ee41..91b0bdcf 100644 --- a/bl-kernel/ajax/upload-logo.php +++ b/bl-kernel/ajax/upload-logo.php @@ -2,10 +2,7 @@ header('Content-Type: application/json'); if (!isset($_FILES['inputFile'])) { - exit (json_encode(array( - 'status'=>1, - 'message'=>'Error trying to upload the site logo.' - ))); + ajaxResponse(1, 'Error trying to upload the site logo.'); } // File extension @@ -32,12 +29,10 @@ chmod(PATH_UPLOADS.$filename, 0644); // Store the filename in the database $site->set(array('logo'=>$filename)); -exit (json_encode(array( - 'status'=>0, - 'message'=>'Image uploaded success.', +ajaxResponse(0, 'Image uploaded.', array( 'filename'=>$filename, 'absoluteURL'=>DOMAIN_UPLOADS.$filename, 'absolutePath'=>PATH_UPLOADS.$filename -))); +)); ?> \ No newline at end of file diff --git a/bl-kernel/ajax/upload-profile-picture.php b/bl-kernel/ajax/upload-profile-picture.php index c831badb..d0366f24 100644 --- a/bl-kernel/ajax/upload-profile-picture.php +++ b/bl-kernel/ajax/upload-profile-picture.php @@ -8,17 +8,11 @@ $username = empty($_POST['username']) ? false : $_POST['username']; // ---------------------------------------------------------------------------- if ($username===false) { - exit (json_encode(array( - 'status'=>1, - 'message'=>'Error in username.' - ))); + ajaxResponse(1, 'Error in username.'); } if (!isset($_FILES['profilePictureInputFile'])) { - exit (json_encode(array( - 'status'=>1, - 'message'=>'Error trying to upload the profile picture.' - ))); + ajaxResponse(1, 'Error trying to upload the profile picture.'); } // File extension @@ -42,12 +36,10 @@ unlink(PATH_TMP.$tmpFilename); // Permissions chmod(PATH_UPLOADS_PROFILES.$filename, 0644); -exit (json_encode(array( - 'status'=>0, - 'message'=>'Image uploaded success.', +ajaxResponse(0, 'Image uploaded.', array( 'filename'=>$filename, 'absoluteURL'=>DOMAIN_UPLOADS_PROFILES.$filename, 'absolutePath'=>PATH_UPLOADS_PROFILES.$filename -))); +)); ?> \ No newline at end of file