Dotclear

source: inc/admin/actions/class.dcactionposts.php @ 2494:b168f47c7f9c

Revision 2494:b168f47c7f9c, 12.6 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Typo, thank's mirovonben, fixes #1821

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 dcPostsActionsPage extends dcActionsPage
15{
16     public function __construct($core,$uri,$redirect_args=array()) {
17          parent::__construct($core,$uri,$redirect_args);
18          $this->redirect_fields = array('user_id','cat_id','status',
19          'selected','attachment','month','lang','sortby','order','page','nb');
20          $this->loadDefaults();
21     }
22
23     protected function loadDefaults() {
24          // We could have added a behavior here, but we want default action
25          // to be setup first
26          dcDefaultPostActions::adminPostsActionsPage($this->core,$this);
27          $this->core->callBehavior('adminPostsActionsPage',$this->core,$this);
28
29     }
30
31     public function beginPage($breadcrumb='',$head='') {
32          if ($this->in_plugin) {
33               echo '<html><head><title>'.__('Entries').'</title>'.
34                    dcPage::jsLoad('js/_posts_actions.js').
35                    $head.
36                    '</script></head><body>'.
37                    $breadcrumb;
38          } else {
39               dcPage::open(
40                    __('Entries'),
41                    dcPage::jsLoad('js/_posts_actions.js').
42                    $head,
43                    $breadcrumb
44               );
45          }
46          echo '<p><a class="back" href="'.$this->getRedirection(true).'">'.__('Back to entries list').'</a></p>';
47     }
48
49     public function endPage() {
50          if ($this->in_plugin) {
51               echo '</body></html>';
52          } else {
53               dcPage::close();
54          }
55     }
56
57     public function error(Exception $e) {
58          $this->core->error->add($e->getMessage());
59          $this->beginPage(dcPage::breadcrumb(
60               array(
61                    html::escapeHTML($this->core->blog->name) => '',
62                    $this->getCallerTitle() => $this->getRedirection(true),
63                    __('Entries actions') => ''
64               ))
65          );
66          $this->endPage();
67     }
68
69     protected function fetchEntries($from) {
70          if (!empty($from['entries']))
71          {
72               $entries = $from['entries'];
73
74               foreach ($entries as $k => $v) {
75                    $entries[$k] = (integer) $v;
76               }
77
78               $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') ';
79
80               if (!isset($from['full_content']) || empty($from['full_content'])) {
81                    $params['no_content'] = true;
82               }
83
84               if (isset($from['post_type'])) {
85                    $params['post_type'] = $from['post_type'];
86               }
87
88               $posts = $this->core->blog->getPosts($params);
89               while ($posts->fetch())  {
90                    $this->entries[$posts->post_id] = $posts->post_title;
91               }
92               $this->rs = $posts;
93          } else {
94               $this->rs = $this->core->con->select("SELECT blog_id FROM ".$this->core->prefix."blog WHERE false");;
95          }
96     }
97}
98
99class dcDefaultPostActions
100{
101     public static function adminPostsActionsPage($core, $ap) {
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          $ap->addAction(
114               array(__('Mark')=> array(
115                    __('Mark as selected') => 'selected',
116                    __('Mark as unselected') => 'unselected'
117               )),
118               array('dcDefaultPostActions','doUpdateSelectedPost')
119          );
120          $ap->addAction(
121               array(__('Change') => array(
122                    __('Change category') => 'category',
123               )),
124               array('dcDefaultPostActions','doChangePostCategory')
125          );
126          $ap->addAction(
127               array(__('Change') => array(
128                    __('Change language') => 'lang',
129               )),
130               array('dcDefaultPostActions','doChangePostLang')
131          );
132          if ($core->auth->check('admin',$core->blog->id))
133          {
134               $ap->addAction(
135                    array(__('Change') => array(
136                         __('Change author') => 'author')),
137                    array('dcDefaultPostActions','doChangePostAuthor')
138               );
139          }
140          if ($core->auth->check('delete,contentadmin',$core->blog->id)) {
141               $ap->addAction(
142                    array(__('Delete') => array(
143                         __('Delete') => 'delete')),
144                    array('dcDefaultPostActions','doDeletePost')
145               );
146          }
147     }
148
149     public static function doChangePostStatus($core, dcPostsActionsPage $ap, $post) {
150          switch ($ap->getAction()) {
151               case 'unpublish' : $status = 0; break;
152               case 'schedule' : $status = -1; break;
153               case 'pending' : $status = -2; break;
154               default : $status = 1; break;
155          }
156          $posts_ids = $ap->getIDs();
157          if (empty($posts_ids)) {
158               throw new Exception(__('No entry selected'));
159          }
160          $core->blog->updPostsStatus($posts_ids,$status);
161          dcPage::addSuccessNotice(sprintf(
162               __(
163                    '%d entry has been successfully updated to status : "%s"',
164                    '%d entries have been successfully updated to status : "%s"',
165                    count($posts_ids)
166               ),
167               count($posts_ids),
168               $core->blog->getPostStatus($status))
169          );
170          $ap->redirect(true);
171     }
172
173     public static function doUpdateSelectedPost($core, dcPostsActionsPage $ap, $post) {
174          $posts_ids = $ap->getIDs();
175          if (empty($posts_ids)) {
176               throw new Exception(__('No entry selected'));
177          }
178          $action = $ap->getAction();
179          $core->blog->updPostsSelected($posts_ids,$action == 'selected');
180          if ($action == 'selected') {
181               dcPage::addSuccessNotice(sprintf(
182                    __(
183                         '%d entry has been successfully marked as selected',
184                         '%d entries have been successfully marked as selected',
185                         count($posts_ids)
186                    ),
187                    count($posts_ids))
188               );
189          } else {
190               dcPage::addSuccessNotice(sprintf(
191                    __(
192                         '%d entry has been successfully marked as unselected',
193                         '%d entries have been successfully marked as unselected',
194                         count($posts_ids)
195                    ),
196                    count($posts_ids))
197               );
198          }
199          $ap->redirect(true);
200     }
201
202     public static function doDeletePost($core, dcPostsActionsPage $ap, $post) {
203
204          $posts_ids = $ap->getIDs();
205          if (empty($posts_ids)) {
206               throw new Exception(__('No entry selected'));
207          }
208          // Backward compatibility
209          foreach($posts_ids as $post_id)
210          {
211               # --BEHAVIOR-- adminBeforePostDelete
212               $core->callBehavior('adminBeforePostDelete',(integer) $post_id);
213          }
214
215          # --BEHAVIOR-- adminBeforePostsDelete
216          $core->callBehavior('adminBeforePostsDelete',$posts_ids);
217
218          $core->blog->delPosts($posts_ids);
219          dcPage::addSuccessNotice(sprintf(
220               __(
221                    '%d entry has been successfully deleted',
222                    '%d entries have been successfully deleted',
223                    count($posts_ids)
224               ),
225               count($posts_ids))
226          );
227
228          $ap->redirect(false);
229     }
230
231     public static function doChangePostCategory($core, dcPostsActionsPage $ap, $post) {
232          if (isset($post['new_cat_id'])) {
233               $posts_ids = $ap->getIDs();
234               if (empty($posts_ids)) {
235                    throw new Exception(__('No entry selected'));
236               }
237               $new_cat_id = $post['new_cat_id'];
238               if (!empty($post['new_cat_title']) && $core->auth->check('categories', $core->blog->id))
239               {
240                    $cur_cat = $core->con->openCursor($core->prefix.'category');
241                    $cur_cat->cat_title = $post['new_cat_title'];
242                    $cur_cat->cat_url = '';
243                    $title = $cur_cat->cat_title;
244
245                    $parent_cat = !empty($post['new_cat_parent']) ? $post['new_cat_parent'] : '';
246
247                    # --BEHAVIOR-- adminBeforeCategoryCreate
248                    $core->callBehavior('adminBeforeCategoryCreate', $cur_cat);
249
250                    $new_cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat);
251
252                    # --BEHAVIOR-- adminAfterCategoryCreate
253                    $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $new_cat_id);
254               }
255
256               $core->blog->updPostsCategory($posts_ids, $new_cat_id);
257               $title = $core->blog->getCategory($new_cat_id);
258               dcPage::addSuccessNotice(sprintf(
259                    __(
260                         '%d entry has been successfully moved to category "%s"',
261                         '%d entries have been successfully moved to category "%s"',
262                         count($posts_ids)
263                    ),
264                    count($posts_ids),
265                    html::escapeHTML($title->cat_title))
266               );
267
268               $ap->redirect(true);
269          } else {
270
271               $ap->beginPage(
272                    dcPage::breadcrumb(
273                         array(
274                              html::escapeHTML($core->blog->name) => '',
275                              $ap->getCallerTitle() => $ap->getRedirection(true),
276                              __('Change category for this selection') => ''
277               )));
278               # categories list
279               # Getting categories
280               $categories_combo = dcAdminCombos::getCategoriesCombo(
281                    $core->blog->getCategories()
282               );
283               echo
284               '<form action="'.$ap->getURI().'" method="post">'.
285               $ap->getCheckboxes().
286               '<p><label for="new_cat_id" class="classic">'.__('Category:').'</label> '.
287               form::combo(array('new_cat_id'),$categories_combo,'');
288
289               if ($core->auth->check('categories', $core->blog->id)) {
290                    echo
291                    '<div>'.
292                    '<p id="new_cat">'.__('Create a new category for the post(s)').'</p>'.
293                    '<p><label for="new_cat_title">'.__('Title:').'</label> '.
294                    form::field('new_cat_title',30,255,'','').'</p>'.
295                    '<p><label for="new_cat_parent">'.__('Parent:').'</label> '.
296                    form::combo('new_cat_parent',$categories_combo,'','').
297                    '</p>'.
298                    '</div>';
299               }
300
301               echo
302               $core->formNonce().
303               $ap->getHiddenFields().
304               form::hidden(array('action'),'category').
305               '<input type="submit" value="'.__('Save').'" /></p>'.
306               '</form>';
307               $ap->endPage();
308
309          }
310
311     }
312     public static function doChangePostAuthor($core, dcPostsActionsPage $ap, $post) {
313          if (isset($post['new_auth_id']) && $core->auth->check('admin',$core->blog->id)) {
314               $new_user_id = $post['new_auth_id'];
315               $posts_ids = $ap->getIDs();
316               if (empty($posts_ids)) {
317                    throw new Exception(__('No entry selected'));
318               }
319               if ($core->getUser($new_user_id)->isEmpty()) {
320                    throw new Exception(__('This user does not exist'));
321               }
322
323               $cur = $core->con->openCursor($core->prefix.'post');
324               $cur->user_id = $new_user_id;
325               $cur->update('WHERE post_id '.$core->con->in($posts_ids));
326               dcPage::addSuccessNotice(sprintf(
327                    __(
328                         '%d entry has been successfully set to user "%s"',
329                         '%d entries have been successfully set to user "%s"',
330                         count($posts_ids)
331                    ),
332                    count($posts_ids),
333                    html::escapeHTML($new_user_id))
334               );
335
336
337               $ap->redirect(true);
338          } else {
339               $usersList = '';
340               if ($core->auth->check('admin',$core->blog->id)) {
341                    $params = array(
342                         'limit' => 100,
343                         'order' => 'nb_post DESC'
344                         );
345                    $rs = $core->getUsers($params);
346                    while ($rs->fetch())
347                    {
348                         $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"';
349                    }
350               }
351               $ap->beginPage(
352                    dcPage::breadcrumb(
353                         array(
354                              html::escapeHTML($core->blog->name) => '',
355                              $ap->getCallerTitle() => $ap->getRedirection(true),
356                              __('Change author for this selection') => '')),
357                         dcPage::jsLoad('js/jquery/jquery.autocomplete.js').
358                         '<script type="text/javascript">'."\n".
359                         "//<![CDATA[\n".
360                         'usersList = ['.$usersList.']'."\n".
361                         "\n//]]>\n".
362                         "</script>\n"
363               );
364
365               echo
366               '<form action="'.$ap->getURI().'" method="post">'.
367               $ap->getCheckboxes().
368               '<p><label for="new_auth_id" class="classic">'.__('New author (author ID):').'</label> '.
369               form::field('new_auth_id',20,255);
370
371               echo
372                    $core->formNonce().$ap->getHiddenFields().
373                    form::hidden(array('action'),'author').
374                    '<input type="submit" value="'.__('Save').'" /></p>'.
375                    '</form>';
376               $ap->endPage();
377          }
378     }
379     public static function doChangePostLang($core, dcPostsActionsPage $ap, $post) {
380          $posts_ids = $ap->getIDs();
381          if (empty($posts_ids)) {
382               throw new Exception(__('No entry selected'));
383          }
384          if (isset($post['new_lang'])) {
385               $new_lang = $post['new_lang'];
386               $cur = $core->con->openCursor($core->prefix.'post');
387               $cur->post_lang = $new_lang;
388               $cur->update('WHERE post_id '.$core->con->in($posts_ids));
389               dcPage::addSuccessNotice(sprintf(
390                    __(
391                         '%d entry has been successfully set to language "%s"',
392                         '%d entries have been successfully set to language "%s"',
393                         count($posts_ids)
394                    ),
395                    count($posts_ids),
396                    html::escapeHTML(l10n::getLanguageName($new_lang)))
397               );
398               $ap->redirect(true);
399          } else {
400               $ap->beginPage(
401                    dcPage::breadcrumb(
402                         array(
403                              html::escapeHTML($core->blog->name) => '',
404                              $ap->getCallerTitle() => $ap->getRedirection(true),
405                              __('Change language for this selection') => ''
406               )));
407               # lang list
408               # Languages combo
409               $rs = $core->blog->getLangs(array('order'=>'asc'));
410               $all_langs = l10n::getISOcodes(0,1);
411               $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
412               while ($rs->fetch()) {
413                    if (isset($all_langs[$rs->post_lang])) {
414                         $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang;
415                         unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]);
416                    } else {
417                         $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang;
418                    }
419               }
420               unset($all_langs);
421               unset($rs);
422
423               echo
424               '<form action="'.$ap->getURI().'" method="post">'.
425               $ap->getCheckboxes().
426
427               '<p><label for="new_lang" class="classic">'.__('Entry language:').'</label> '.
428               form::combo('new_lang',$lang_combo,'');
429
430               echo
431                    $core->formNonce().$ap->getHiddenFields().
432                    form::hidden(array('action'),'lang').
433                    '<input type="submit" value="'.__('Save').'" /></p>'.
434                    '</form>';
435               $ap->endPage();
436          }
437     }
438}
Note: See TracBrowser for help on using the repository browser.

Sites map