Dotclear

source: plugins/pages/class.actionpage.php @ 3730:5c45a5df9a59

Revision 3730:5c45a5df9a59, 4.3 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Code formatting (PSR-2)

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

Sites map