Dotclear

source: plugins/pages/class.actionpage.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 4.0 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

RevLine 
[2055]1<?php
[3731]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 */
[2055]11
[3730]12class dcPagesActionsPage extends dcPostsActionsPage
13{
[3874]14    public function __construct($core, $uri, $redirect_args = [])
[3730]15    {
16        parent::__construct($core, $uri, $redirect_args);
[3874]17        $this->redirect_fields = [];
[3730]18        $this->caller_title    = __('Pages');
[2055]19
[3730]20    }
[2055]21
[3730]22    public function error(Exception $e)
23    {
24        $this->core->error->add($e->getMessage());
25        $this->beginPage(dcPage::breadcrumb(
[3874]26            [
[3730]27                html::escapeHTML($this->core->blog->name) => '',
28                __('Pages')                               => $this->getRedirection(true),
29                __('Pages actions')                       => ''
[3874]30            ])
[3730]31        );
32        $this->endPage();
33    }
[2055]34
[3730]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>';
[2055]43
[3730]44    }
[2566]45
[3730]46    public function endPage()
47    {
48        echo '</body></html>';
49    }
[2055]50
[3730]51    public function loadDefaults()
52    {
53        DefaultPagesActions::adminPagesActionsPage($this->core, $this);
[3874]54        $this->actions['reorder'] = ['dcPagesActionsPage', 'doReorderPages'];
[3730]55        $this->core->callBehavior('adminPagesActionsPage', $this->core, $this);
[2566]56
[3730]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    }
[2566]67
[3730]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            }
[2566]74
[3730]75            $strReq = "WHERE blog_id = '" . $core->con->escape($core->blog->id) . "' " .
76            "AND post_id " . $core->con->in($post_id);
[2566]77
[3730]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            }
[2566]82
[3730]83            $cur = $core->con->openCursor($core->prefix . 'post');
[2566]84
[3730]85            $cur->post_position = (integer) $value - 1;
86            $cur->post_upddt    = date('Y-m-d H:i:s');
[2566]87
[3730]88            $cur->update($strReq);
89            $core->blog->triggerBlog();
[2566]90
[3730]91        }
92
93        dcPage::addSuccessNotice(__('Selected pages have been successfully reordered.'));
94        $ap->redirect(false);
95    }
[2055]96}
97
[2566]98class DefaultPagesActions
[2055]99{
[3730]100    public static function adminPagesActionsPage($core, $ap)
101    {
102        if ($core->auth->check('publish,contentadmin', $core->blog->id)) {
103            $ap->addAction(
[3874]104                [__('Status') => [
[3730]105                    __('Publish')         => 'publish',
106                    __('Unpublish')       => 'unpublish',
107                    __('Schedule')        => 'schedule',
108                    __('Mark as pending') => 'pending'
[3874]109                ]],
110                ['dcDefaultPostActions', 'doChangePostStatus']
[3730]111            );
112        }
113        if ($core->auth->check('admin', $core->blog->id)) {
114            $ap->addAction(
[3874]115                [__('Change') => [
116                    __('Change author') => 'author']],
117                ['dcDefaultPostActions', 'doChangePostAuthor']
[3730]118            );
119        }
120        if ($core->auth->check('delete,contentadmin', $core->blog->id)) {
121            $ap->addAction(
[3874]122                [__('Delete') => [
123                    __('Delete') => 'delete']],
124                ['dcDefaultPostActions', 'doDeletePost']
[3730]125            );
126        }
127    }
[2566]128}
Note: See TracBrowser for help on using the repository browser.

Sites map