fixed ajax calls

This commit is contained in:
Diego Najar 2017-07-13 22:39:04 +02:00
parent 7d196f8e16
commit 0676b0b768
10 changed files with 44 additions and 74 deletions

View File

@ -368,7 +368,7 @@ table.statistics tr:last-child td {
#alert { #alert {
top: 0; top: 0;
color: #ffffff; color: #ffffff;
padding: 20px 60px; padding: 8px 80px;
display: none; display: none;
position: fixed; position: fixed;
text-align: center; text-align: center;

View File

@ -150,6 +150,12 @@ $(document).ready(function() {
</div> </div>
<script>
$( "#bludit-logo" ).dblclick(function() {
alert( "Hey! what are you doing ?" );
});
</script>
<!-- Javascript --> <!-- Javascript -->
<?php include(PATH_JS.'functions.php') ?> <?php include(PATH_JS.'functions.php') ?>

View File

@ -214,28 +214,28 @@ $(document).ready(function()
var text = $(this).val(); var text = $(this).val();
var parent = $("#jsparent").val(); var parent = $("#jsparent").val();
checkSlugPage(text, parent, key, $("#jsslug")); generateSlug(text, parent, key, $("#jsslug"));
}); });
$("#jstitle").keyup(function() { $("#jstitle").keyup(function() {
var text = $(this).val(); var text = $(this).val();
var parent = $("#jsparent").val(); var parent = $("#jsparent").val();
checkSlugPage(text, parent, key, $("#jsslug")); generateSlug(text, parent, key, $("#jsslug"));
}); });
$("#jsparent").change(function() { $("#jsparent").change(function() {
var parent = $(this).val(); var parent = $(this).val();
var text = $("#jsslug").val(); var text = $("#jsslug").val();
if(parent==NO_PARENT_CHAR) { if (parent=="") {
$("#jsparentExample").text(""); $("#jsparentExample").text("");
} }
else { else {
$("#jsparentExample").text(parent+"/"); $("#jsparentExample").text(parent+"/");
} }
checkSlugPage(text, parent, key, $("#jsslug")); generateSlug(text, parent, key, $("#jsslug"));
}); });
$("#jsdelete").click(function() { $("#jsdelete").click(function() {

View File

@ -193,28 +193,28 @@ $(document).ready(function()
var text = $(this).val(); var text = $(this).val();
var parent = $("#jsparent").val(); var parent = $("#jsparent").val();
checkSlugPage(text, parent, "", $("#jsslug")); generateSlug(text, parent, "", $("#jsslug"));
}); });
$("#jstitle").keyup(function() { $("#jstitle").keyup(function() {
var text = $(this).val(); var text = $(this).val();
var parent = $("#jsparent").val(); var parent = $("#jsparent").val();
checkSlugPage(text, parent, "", $("#jsslug")); generateSlug(text, parent, "", $("#jsslug"));
}); });
$("#jsparent").change(function() { $("#jsparent").change(function() {
var parent = $(this).val(); var parent = $(this).val();
var text = $("#jsslug").val(); var text = $("#jsslug").val();
if(parent==NO_PARENT_CHAR) { if(parent=="") {
$("#jsparentExample").text(""); $("#jsparentExample").text("");
} }
else { else {
$("#jsparentExample").text(parent+"/"); $("#jsparentExample").text(parent+"/");
} }
checkSlugPage(text, parent, "", $("#jsslug")); generateSlug(text, parent, "", $("#jsslug"));
}); });
// Button Save as draft // Button Save as draft

View File

@ -51,7 +51,7 @@ echo '
} }
for($i=1; $i<=Paginator::amountOfPages(); $i++) { for($i=1; $i<=Paginator::amountOfPages(); $i++) {
echo '<li><a href='.Paginator::absoluteUrl($i).' class="page">'.$i.'</a></li>'; echo '<li><a href="'.Paginator::absoluteUrl($i).'" class="page">'.$i.'</a></li>';
} }
// Show next page link // Show next page link

View File

@ -8,7 +8,7 @@ header('Content-Type: application/json');
$filename = isset($_POST['filename']) ? $_POST['filename'] : ''; $filename = isset($_POST['filename']) ? $_POST['filename'] : '';
if( empty($filename) ) { if( empty($filename) ) {
echo json_encode( array('status'=>0, 'msg'=>'The filename is empty.') ); echo json_encode( array('status'=>1, 'msg'=>'The filename is empty.') );
exit; exit;
} }
@ -21,13 +21,13 @@ if( Sanitize::pathFile(PATH_UPLOADS.$filename) ) {
// Delete the thumnails. // Delete the thumnails.
Filesystem::rmfile(PATH_UPLOADS_THUMBNAILS.$filename); Filesystem::rmfile(PATH_UPLOADS_THUMBNAILS.$filename);
echo json_encode( array('status'=>1, 'msg'=>'The file was deleted.') ); echo json_encode( array('status'=>0, 'msg'=>'The file was deleted.') );
exit; exit;
} }
exit(json_encode(array( exit(json_encode(array(
'status'=>0, 'status'=>1,
'msg'=>'The file does not exist.' 'msg'=>'The file does not exist.'
))); )));

View File

@ -1,29 +1,17 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json'); header('Content-Type: application/json');
// Request $_POST
// type: page or post.
// text: Slug to valid.
// parent: Page parent, if you are checking a slug for a page.
// Response JSON
// slug: valid slug text
$text = isset($_POST['text']) ? $_POST['text'] : ''; $text = isset($_POST['text']) ? $_POST['text'] : '';
$parent = isset($_POST['parent']) ? $_POST['parent'] : PARENT; $parent = isset($_POST['parentKey']) ? $_POST['parentKey'] : PARENT;
$key = isset($_POST['key']) ? $_POST['key'] : ''; $oldKey = isset($_POST['currentKey']) ? $_POST['currentKey'] : '';
if( $_POST['type']==='page' ) { $slug = $dbPages->generateKey($text, $parent, $returnSlug=true, $oldKey);
$slug = $dbPages->generateKey($text, $parent, true, $key);
}
elseif( $_POST['type']==='post' ) {
$slug = $dbPosts->generateKey($text, $key);
}
exit(json_encode(array( exit(json_encode(
'status'=>1, array(
'slug'=>$slug 'status'=>0,
))); 'slug'=>$slug
)
));
?> ?>

View File

@ -17,23 +17,19 @@ $layout['parameters'] = implode('/', $explodeSlug);
// Disable Magic Quotes. // Disable Magic Quotes.
// Thanks, http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting // Thanks, http://stackoverflow.com/questions/517008/how-to-turn-off-magic-quotes-on-shared-hosting
if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) ) if ( in_array( strtolower( ini_get( 'magic_quotes_gpc' ) ), array( '1', 'on' ) ) ) {
{
$_POST = array_map('stripslashes', $_POST); $_POST = array_map('stripslashes', $_POST);
$_GET = array_map('stripslashes', $_GET); $_GET = array_map('stripslashes', $_GET);
$_COOKIE = array_map('stripslashes', $_COOKIE); $_COOKIE = array_map('stripslashes', $_COOKIE);
} }
// --- AJAX --- // --- AJAX ---
if( $layout['slug']==='ajax' ) if ($layout['slug']==='ajax') {
{ if ($Login->isLogged()) {
// Check if the user is loggued.
if($Login->isLogged())
{
// Rules: Security check CSRF // Rules: Security check CSRF
include(PATH_RULES.'99.security.php'); include(PATH_RULES.'99.security.php');
// Load the ajax file. // Load the ajax file
if( Sanitize::pathFile(PATH_AJAX, $layout['parameters'].'.php') ) { if( Sanitize::pathFile(PATH_AJAX, $layout['parameters'].'.php') ) {
include(PATH_AJAX.$layout['parameters'].'.php'); include(PATH_AJAX.$layout['parameters'].'.php');
} }

View File

@ -19,41 +19,21 @@ echo '</script>';
var ajaxRequest; var ajaxRequest;
function checkSlugPage(text, parent, oldKey, writeResponse) function generateSlug(text, parentKey, currentKey, writeResponse) {
{
parent = typeof parent !== 'undefined' ? parent : PARENT;
oldKey = typeof oldKey !== 'undefined' ? oldKey : "";
checkSlug("page", text, parent, oldKey, writeResponse);
}
function checkSlugPost(text, oldKey, writeResponse)
{
checkSlug("post", text, null, oldKey, writeResponse);
}
function checkSlug(type, text, parentPage, key, writeResponse)
{
if(ajaxRequest) { if(ajaxRequest) {
ajaxRequest.abort(); ajaxRequest.abort();
} }
if(type=="page") ajaxRequest = $.ajax({
{ type: "POST",
ajaxRequest = $.ajax({ data: {
type: "POST", tokenCSRF: tokenCSRF,
data:{ tokenCSRF: tokenCSRF, type: "page", text: text, parent: parentPage, key: key}, text: text,
url: "<?php echo HTML_PATH_ADMIN_ROOT.'ajax/slug' ?>" parentKey: parentKey,
}); currentKey: currentKey
} },
else url: "<?php echo HTML_PATH_ADMIN_ROOT.'ajax/slug' ?>"
{ });
ajaxRequest = $.ajax({
type: "POST",
data:{ tokenCSRF: tokenCSRF, type: "post", text: text, key: key },
url: "<?php echo HTML_PATH_ADMIN_ROOT.'ajax/slug' ?>"
});
}
// Callback handler that will be called on success // Callback handler that will be called on success
ajaxRequest.done(function (response, textStatus, jqXHR){ ajaxRequest.done(function (response, textStatus, jqXHR){

View File

@ -68,7 +68,7 @@ class pluginsimpleMDE extends Plugin {
$html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">'; $html .= '<link rel="stylesheet" href="'.$pluginPath.'css/simplemde.min.css">';
// Font-awesome is a dependency of SimpleMDE // Font-awesome is a dependency of SimpleMDE
$html .= '<link rel="stylesheet" href="'.HTML_PATH_ADMIN_THEME_CSS.'font-awesome.min.css">'; $html .= '<link rel="stylesheet" href="'.HTML_PATH_CORE_CSS.'font-awesome/font-awesome.min.css">';
// SimpleMDE js // SimpleMDE js
$html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>'; $html .= '<script src="'.$pluginPath.'js/simplemde.min.js"></script>';