Dotclear

source: inc/admin/actions/class.dcactionblogs.php @ 3707:3a350757c847

Revision 3707:3a350757c847, 6.1 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use array form of optionnal parameters for form::checkbox() where is relevant, 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 -----------------------------------------
12if (!defined('DC_RC_PATH')) {return;}
13
14class dcBlogsActionsPage extends dcActionsPage
15{
16    public function __construct($core, $uri, $redirect_args = array())
17    {
18        parent::__construct($core, $uri, $redirect_args);
19        $this->redirect_fields = array('status', 'sortby', 'order', 'page', 'nb');
20        $this->field_entries   = 'blogs';
21        $this->title_cb        = __('Blogs');
22        $this->loadDefaults();
23        $core->callBehavior('adminBlogsActionsPage', $core, $this);
24    }
25
26    protected function loadDefaults()
27    {
28        // We could have added a behavior here, but we want default action
29        // to be setup first
30        dcDefaultBlogActions::adminBlogsActionsPage($this->core, $this);
31    }
32
33    public function beginPage($breadcrumb = '', $head = '')
34    {
35        if ($this->in_plugin) {
36            echo '<html><head><title>' . __('Blogs') . '</title>' .
37            dcPage::jsLoad('js/_blogs_actions.js') .
38                $head .
39                '</script></head><body>' .
40                $breadcrumb;
41        } else {
42            dcPage::open(
43                __('Blogs'),
44                dcPage::jsLoad('js/_blogs_actions.js') .
45                $head,
46                $breadcrumb
47            );
48        }
49        echo '<p><a class="back" href="' . $this->getRedirection(true) . '">' . __('Back to blogs list') . '</a></p>';
50    }
51
52    public function endPage()
53    {
54        dcPage::close();
55    }
56
57    public function error(Exception $e)
58    {
59        $this->core->error->add($e->getMessage());
60        $this->beginPage(dcPage::breadcrumb(
61            array(
62                html::escapeHTML($this->core->blog->name) => '',
63                __('Blogs')                               => $this->core->adminurl->get('admin.blogs'),
64                __('Blogs actions')                       => ''
65            ))
66        );
67        $this->endPage();
68    }
69
70    public function getCheckboxes()
71    {
72        $ret = '';
73        foreach ($this->entries as $id => $res) {
74            $ret .=
75            '<tr>' .
76            '<td class="minimal">' . form::checkbox(array($this->field_entries . '[]'), $id,
77                array(
78                    'checked' => true
79                )) .
80            '</td>' .
81            '<td>' . $res['blog'] . '</td>' .
82            '<td>' . $res['name'] . '</td>' .
83            '</tr>';
84        }
85
86        return
87        '<table class="blogs-list"><tr>' .
88        '<th colspan="2">' . __('Blog id') . '</th><th>' . __('Blog name') . '</th>' .
89            '</tr>' . $ret . '</table>';
90    }
91
92    protected function fetchEntries($from)
93    {
94        $params = array();
95        if (!empty($from['blogs'])) {
96            $params['blog_id'] = $from['blogs'];
97        }
98
99        $bl = $this->core->getBlogs($params);
100        while ($bl->fetch()) {
101            $this->entries[$bl->blog_id] = array(
102                'blog' => $bl->blog_id,
103                'name' => $bl->blog_name
104            );
105        }
106        $this->rs = $bl;
107    }
108}
109
110class dcDefaultBlogActions
111{
112    public static function adminBlogsActionsPage($core, dcBlogsActionsPage $ap)
113    {
114        if (!$core->auth->isSuperAdmin()) {
115            return;
116        }
117
118        $ap->addAction(
119            array(__('Status') => array(
120                __('Set online')     => 'online',
121                __('Set offline')    => 'offline',
122                __('Set as removed') => 'remove'
123            )),
124            array('dcDefaultBlogActions', 'doChangeBlogStatus')
125        );
126        $ap->addAction(
127            array(__('Delete') => array(
128                __('Delete') => 'delete')),
129            array('dcDefaultBlogActions', 'doDeleteBlog')
130        );
131    }
132
133    public static function doChangeBlogStatus($core, dcBlogsActionsPage $ap, $post)
134    {
135        if (!$core->auth->isSuperAdmin()) {
136            return;
137        }
138
139        $action = $ap->getAction();
140        $ids    = $ap->getIDs();
141        if (empty($ids)) {
142            throw new Exception(__('No blog selected'));
143        }
144        switch ($action) {
145            case 'online':$status = 1;
146                break;
147            case 'offline':$status = 0;
148                break;
149            case 'remove':$status = -1;
150                break;
151            default:$status = 1;
152                break;
153        }
154
155        $cur              = $core->con->openCursor($core->prefix . 'blog');
156        $cur->blog_status = $status;
157        //$cur->blog_upddt = date('Y-m-d H:i:s');
158        $cur->update('WHERE blog_id ' . $core->con->in($ids));
159
160        dcPage::addSuccessNotice(__('Selected blogs have been successfully updated.'));
161        $ap->redirect(true);
162    }
163
164    public static function doDeleteBlog($core, dcBlogsActionsPage $ap, $post)
165    {
166        if (!$core->auth->isSuperAdmin()) {
167            return;
168        }
169
170        $ap_ids = $ap->getIDs();
171        if (empty($ap_ids)) {
172            throw new Exception(__('No blog selected'));
173        }
174
175        if (!$core->auth->checkPassword($_POST['pwd'])) {
176            throw new Exception(__('Password verification failed'));
177        }
178
179        $ids = array();
180        foreach ($ap_ids as $id) {
181            if ($id == $core->blog->id) {
182                dcPage::addWarningNotice(__('The current blog cannot be deleted.'));
183            } else {
184                $ids[] = $id;
185            }
186        }
187
188        if (!empty($ids)) {
189            # --BEHAVIOR-- adminBeforeBlogsDelete
190            $core->callBehavior('adminBeforeBlogsDelete', $ids);
191
192            foreach ($ids as $id) {
193                $core->delBlog($id);
194            }
195
196            dcPage::addSuccessNotice(sprintf(
197                __(
198                    '%d blog has been successfully deleted',
199                    '%d blogs have been successfully deleted',
200                    count($ids)
201                ),
202                count($ids))
203            );
204        }
205        $ap->redirect(false);
206    }
207}
Note: See TracBrowser for help on using the repository browser.

Sites map