Ajax response improves

This commit is contained in:
Diego Najar 2019-01-31 20:07:59 +01:00
parent 79095de5ca
commit ec7e0aaf4c
6 changed files with 15 additions and 43 deletions

View File

@ -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
)));
));
?>

View File

@ -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();

View File

@ -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();

View File

@ -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
)));
));
?>

View File

@ -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
)));
));
?>

View File

@ -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
)));
));
?>