bludit/admin/controllers/edit-post.php

71 lines
1.6 KiB
PHP
Raw Normal View History

2015-05-05 03:00:01 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Functions
// ============================================================================
function editPost($args)
{
global $dbPosts;
2015-07-20 05:14:12 +02:00
global $Language;
2015-05-05 03:00:01 +02:00
// Post status, published or draft.
if( isset($args['publish']) ) {
$args['status'] = "published";
}
else {
$args['status'] = "draft";
}
// Edit the post.
if( $dbPosts->edit($args) )
{
2015-07-20 05:14:12 +02:00
Alert::set($Language->g('the-changes-have-been-saved'));
2015-07-04 02:14:58 +02:00
Redirect::page('admin', 'edit-post/'.$args['key']);
2015-05-05 03:00:01 +02:00
}
else
{
2015-07-20 05:14:12 +02:00
Alert::set($Language->g('an-error-occurred-while-trying-to-edit-the-post'));
2015-05-05 03:00:01 +02:00
}
}
function deletePost($key)
{
global $dbPosts;
if( $dbPosts->delete($key) )
{
Alert::set('The post has been deleted successfull');
Redirect::page('admin', 'manage-posts');
}
else
{
2015-07-20 05:14:12 +02:00
Alert::set('an-error-occurred-while-trying-to-delete-the-post');
2015-05-05 03:00:01 +02:00
}
}
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
if( isset($_POST['delete']) ) {
deletePost($_POST['key']);
}
else {
editPost($_POST);
}
}
// ============================================================================
// Main
// ============================================================================
if(!$dbPosts->postExists($layout['parameters'])) {
Redirect::page('admin', 'manage-posts');
}
$_Post = buildPost($layout['parameters']);
2015-07-07 00:22:03 +02:00
$layout['title'] .= ' - '.$Language->g('Edit post').' - '.$_Post->title();