Dotclear

source: inc/admin/actions/class.dcactionblogs.php @ 3627:9bccfc2257ad

Revision 3627:9bccfc2257ad, 4.7 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

Use PHP 5.5+ new password functions, closes #2182

Warnings:

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

Sites map