| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @brief pages, a plugin for Dotclear 2 |
|---|
| 4 | * |
|---|
| 5 | * @package Dotclear |
|---|
| 6 | * @subpackage Plugins |
|---|
| 7 | * |
|---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 9 | * @copyright GPL-2.0-only |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | class dcPagesActionsPage extends dcPostsActionsPage |
|---|
| 13 | { |
|---|
| 14 | public function __construct($core, $uri, $redirect_args = array()) |
|---|
| 15 | { |
|---|
| 16 | parent::__construct($core, $uri, $redirect_args); |
|---|
| 17 | $this->redirect_fields = array(); |
|---|
| 18 | $this->caller_title = __('Pages'); |
|---|
| 19 | |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | public function error(Exception $e) |
|---|
| 23 | { |
|---|
| 24 | $this->core->error->add($e->getMessage()); |
|---|
| 25 | $this->beginPage(dcPage::breadcrumb( |
|---|
| 26 | array( |
|---|
| 27 | html::escapeHTML($this->core->blog->name) => '', |
|---|
| 28 | __('Pages') => $this->getRedirection(true), |
|---|
| 29 | __('Pages actions') => '' |
|---|
| 30 | )) |
|---|
| 31 | ); |
|---|
| 32 | $this->endPage(); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public function beginPage($breadcrumb = '', $head = '') |
|---|
| 36 | { |
|---|
| 37 | echo '<html><head><title>' . __('Pages') . '</title>' . |
|---|
| 38 | dcPage::jsLoad('js/_posts_actions.js') . |
|---|
| 39 | $head . |
|---|
| 40 | '</script></head><body>' . |
|---|
| 41 | $breadcrumb; |
|---|
| 42 | echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to pages list') . '</a></p>'; |
|---|
| 43 | |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public function endPage() |
|---|
| 47 | { |
|---|
| 48 | echo '</body></html>'; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | public function loadDefaults() |
|---|
| 52 | { |
|---|
| 53 | DefaultPagesActions::adminPagesActionsPage($this->core, $this); |
|---|
| 54 | $this->actions['reorder'] = array('dcPagesActionsPage', 'doReorderPages'); |
|---|
| 55 | $this->core->callBehavior('adminPagesActionsPage', $this->core, $this); |
|---|
| 56 | |
|---|
| 57 | } |
|---|
| 58 | public function process() |
|---|
| 59 | { |
|---|
| 60 | // fake action for pages reordering |
|---|
| 61 | if (!empty($this->from['reorder'])) { |
|---|
| 62 | $this->from['action'] = 'reorder'; |
|---|
| 63 | } |
|---|
| 64 | $this->from['post_type'] = 'page'; |
|---|
| 65 | return parent::process(); |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | public static function doReorderPages($core, dcPostsActionsPage $ap, $post) |
|---|
| 69 | { |
|---|
| 70 | foreach ($post['order'] as $post_id => $value) { |
|---|
| 71 | if (!$core->auth->check('publish,contentadmin', $core->blog->id)) { |
|---|
| 72 | throw new Exception(__('You are not allowed to change this entry status')); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | $strReq = "WHERE blog_id = '" . $core->con->escape($core->blog->id) . "' " . |
|---|
| 76 | "AND post_id " . $core->con->in($post_id); |
|---|
| 77 | |
|---|
| 78 | #If user can only publish, we need to check the post's owner |
|---|
| 79 | if (!$core->auth->check('contentadmin', $core->blog->id)) { |
|---|
| 80 | $strReq .= "AND user_id = '" . $core->con->escape($core->auth->userID()) . "' "; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | $cur = $core->con->openCursor($core->prefix . 'post'); |
|---|
| 84 | |
|---|
| 85 | $cur->post_position = (integer) $value - 1; |
|---|
| 86 | $cur->post_upddt = date('Y-m-d H:i:s'); |
|---|
| 87 | |
|---|
| 88 | $cur->update($strReq); |
|---|
| 89 | $core->blog->triggerBlog(); |
|---|
| 90 | |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | dcPage::addSuccessNotice(__('Selected pages have been successfully reordered.')); |
|---|
| 94 | $ap->redirect(false); |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | class DefaultPagesActions |
|---|
| 99 | { |
|---|
| 100 | public static function adminPagesActionsPage($core, $ap) |
|---|
| 101 | { |
|---|
| 102 | if ($core->auth->check('publish,contentadmin', $core->blog->id)) { |
|---|
| 103 | $ap->addAction( |
|---|
| 104 | array(__('Status') => array( |
|---|
| 105 | __('Publish') => 'publish', |
|---|
| 106 | __('Unpublish') => 'unpublish', |
|---|
| 107 | __('Schedule') => 'schedule', |
|---|
| 108 | __('Mark as pending') => 'pending' |
|---|
| 109 | )), |
|---|
| 110 | array('dcDefaultPostActions', 'doChangePostStatus') |
|---|
| 111 | ); |
|---|
| 112 | } |
|---|
| 113 | if ($core->auth->check('admin', $core->blog->id)) { |
|---|
| 114 | $ap->addAction( |
|---|
| 115 | array(__('Change') => array( |
|---|
| 116 | __('Change author') => 'author')), |
|---|
| 117 | array('dcDefaultPostActions', 'doChangePostAuthor') |
|---|
| 118 | ); |
|---|
| 119 | } |
|---|
| 120 | if ($core->auth->check('delete,contentadmin', $core->blog->id)) { |
|---|
| 121 | $ap->addAction( |
|---|
| 122 | array(__('Delete') => array( |
|---|
| 123 | __('Delete') => 'delete')), |
|---|
| 124 | array('dcDefaultPostActions', 'doDeletePost') |
|---|
| 125 | ); |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | } |
|---|