bludit/kernel/admin/controllers/edit-page.php

88 lines
2.3 KiB
PHP
Raw Normal View History

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;
2015-05-05 03:00:01 +02:00
if(!isset($args['parent'])) {
$args['parent'] = NO_PARENT_CHAR;
}
2016-01-08 00:43:09 +01:00
// Add the page, if the $key is FALSE the creation of the post failure.
$key = $dbPages->edit($args);
if($key)
2015-05-05 03:00:01 +02:00
{
2015-08-31 03:18:06 +02:00
$dbPages->regenerateCli();
2015-08-29 07:02:09 +02:00
2016-01-08 00:43:09 +01:00
// Call the plugins after page created.
Theme::plugins('afterPageModify');
// Alert the user
2015-07-22 05:15:02 +02:00
Alert::set($Language->g('The changes have been saved'));
2015-10-19 00:45:58 +02:00
Redirect::page('admin', 'edit-page/'.$args['slug']);
2015-05-05 03:00:01 +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
}
}
function deletePage($key)
{
global $dbPages;
2015-07-20 05:14:12 +02:00
global $Language;
2015-08-03 02:49:12 +02:00
2015-05-05 03:00:01 +02:00
if( $dbPages->delete($key) )
{
2016-01-08 00:43:09 +01:00
// Call the plugins after post created.
Theme::plugins('afterPageDelete');
2015-07-22 05:15:02 +02:00
Alert::set($Language->g('The page has been deleted successfully'));
2015-05-05 03:00:01 +02:00
Redirect::page('admin', 'manage-pages');
}
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
}
}
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
// ============================================================================
2015-07-26 02:25:13 +02:00
if(!$dbPages->pageExists($layout['parameters']))
{
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the page: '.$layout['parameters']);
2015-05-05 03:00:01 +02:00
Redirect::page('admin', 'manage-pages');
}
$_Page = $pages[$layout['parameters']];