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

82 lines
2.1 KiB
PHP
Raw Normal View History

2015-05-05 01:00:01 +00:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2015-08-30 22:18:06 -03:00
// ============================================================================
// Check role
// ============================================================================
2015-05-05 01:00:01 +00:00
// ============================================================================
// Functions
// ============================================================================
function editPost($args)
{
global $dbPosts;
2015-07-20 00:14:12 -03:00
global $Language;
2015-08-02 21:49:12 -03:00
2015-05-05 01:00:01 +00:00
// Edit the post.
if( $dbPosts->edit($args) )
{
2015-08-30 22:18:06 -03:00
// Reindex tags, this function is in 70.posts.php
reIndexTagsPosts();
2015-08-29 02:02:09 -03:00
2015-07-22 00:15:02 -03:00
Alert::set($Language->g('The changes have been saved'));
2015-10-18 19:45:58 -03:00
Redirect::page('admin', 'edit-post/'.$args['slug']);
2015-05-05 01:00:01 +00:00
}
else
{
2015-07-22 00:15:02 -03:00
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to edit the post.');
2015-05-05 01:00:01 +00:00
}
2015-08-30 22:18:06 -03:00
return false;
2015-05-05 01:00:01 +00:00
}
function deletePost($key)
{
global $dbPosts;
2015-07-22 00:15:02 -03:00
global $Language;
2015-05-05 01:00:01 +00:00
if( $dbPosts->delete($key) )
{
2015-08-30 22:18:06 -03:00
// Reindex tags, this function is in 70.posts.php
reIndexTagsPosts();
2015-08-29 02:02:09 -03:00
2015-07-22 00:15:02 -03:00
Alert::set($Language->g('The post has been deleted successfully'));
2015-05-05 01:00:01 +00:00
Redirect::page('admin', 'manage-posts');
}
else
{
2015-07-22 00:15:02 -03:00
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to delete the post.');
2015-05-05 01:00:01 +00:00
}
}
2015-08-02 21:49:12 -03:00
// ============================================================================
// Main before POST
// ============================================================================
2015-05-05 01:00:01 +00:00
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
2015-10-18 19:45:58 -03:00
if( isset($_POST['delete-post']) ) {
2015-05-05 01:00:01 +00:00
deletePost($_POST['key']);
}
else {
editPost($_POST);
}
}
// ============================================================================
2015-08-02 21:49:12 -03:00
// Main after POST
2015-05-05 01:00:01 +00:00
// ============================================================================
2015-07-25 21:25:13 -03:00
if(!$dbPosts->postExists($layout['parameters']))
{
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the post: '.$layout['parameters']);
2015-05-05 01:00:01 +00:00
Redirect::page('admin', 'manage-posts');
}
$_Post = buildPost($layout['parameters']);
2015-07-06 19:22:03 -03:00
$layout['title'] .= ' - '.$Language->g('Edit post').' - '.$_Post->title();