2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2016-01-08 00:43:09 +01:00
|
|
|
// ============================================================================
|
|
|
|
// Check role
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
function editPage($args)
|
|
|
|
{
|
|
|
|
global $dbPages;
|
2015-07-20 05:14:12 +02:00
|
|
|
global $Language;
|
2017-05-21 22:01:44 +02:00
|
|
|
global $Syslog;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
if(!isset($args['parent'])) {
|
|
|
|
$args['parent'] = NO_PARENT_CHAR;
|
|
|
|
}
|
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
// Edit the page
|
2016-01-08 00:43:09 +01:00
|
|
|
$key = $dbPages->edit($args);
|
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
if($key) {
|
|
|
|
// Re-index categories
|
|
|
|
reindexCategories();
|
2015-08-29 07:02:09 +02:00
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
// Re-index tags
|
|
|
|
reindextags();
|
2017-04-26 18:56:10 +02:00
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
// Call the plugins after page modified
|
2016-01-08 00:43:09 +01:00
|
|
|
Theme::plugins('afterPageModify');
|
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
// Add to syslog
|
|
|
|
$Syslog->add(array(
|
|
|
|
'dictionaryKey'=>'page-edited',
|
|
|
|
'notes'=>$args['title']
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
|
|
|
Alert::set( $Language->g('The changes have been saved') );
|
|
|
|
|
|
|
|
// Redirect
|
|
|
|
Redirect::page('edit-page/'.$key);
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2017-05-21 22:01:44 +02:00
|
|
|
else {
|
2015-07-22 05:15:02 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the page.');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2017-05-21 22:01:44 +02:00
|
|
|
|
|
|
|
return false;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function deletePage($key)
|
|
|
|
{
|
|
|
|
global $dbPages;
|
2015-07-20 05:14:12 +02:00
|
|
|
global $Language;
|
2017-05-21 22:01:44 +02:00
|
|
|
global $Syslog;
|
|
|
|
|
|
|
|
if( $dbPages->delete($key) ) {
|
|
|
|
// Re-index categories
|
|
|
|
reindexCategories();
|
2015-08-03 02:49:12 +02:00
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
// Re-index tags
|
|
|
|
reindextags();
|
|
|
|
|
|
|
|
// Call the plugins after page deleted
|
2016-01-08 00:43:09 +01:00
|
|
|
Theme::plugins('afterPageDelete');
|
|
|
|
|
2017-05-21 22:01:44 +02:00
|
|
|
// Add to syslog
|
|
|
|
$Syslog->add(array(
|
|
|
|
'dictionaryKey'=>'page-deleted',
|
|
|
|
'notes'=>$key
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
|
|
|
Alert::set( $Language->g('The changes have been saved') );
|
|
|
|
|
|
|
|
// Redirect
|
|
|
|
Redirect::page('pages');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2017-05-21 22:01:44 +02:00
|
|
|
else {
|
2015-07-22 05:15:02 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the page.');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2017-05-21 22:01:44 +02:00
|
|
|
|
|
|
|
return false;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Main before POST
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// ============================================================================
|
|
|
|
// POST Method
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
|
|
|
{
|
2015-10-19 00:45:58 +02:00
|
|
|
if( isset($_POST['delete-page']) ) {
|
2015-05-05 03:00:01 +02:00
|
|
|
deletePage($_POST['key']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
editPage($_POST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
2015-08-03 02:49:12 +02:00
|
|
|
// Main after POST
|
2015-05-05 03:00:01 +02:00
|
|
|
// ============================================================================
|
|
|
|
|
2017-05-17 00:04:53 +02:00
|
|
|
if( !$dbPages->exists($layout['parameters']) ) {
|
2015-07-26 02:25:13 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$layout['parameters']);
|
2017-05-17 00:04:53 +02:00
|
|
|
Redirect::page('pages');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2017-05-27 19:46:46 +02:00
|
|
|
$page = $pagesByKey[$layout['parameters']];
|
2017-06-05 22:36:09 +02:00
|
|
|
|
|
|
|
$layout['title'] .= ' - '.$Language->g('Edit Content');
|