Dotclear

source: admin/posts_actions.php @ 782:01efbf050a8a

Revision 782:01efbf050a8a, 6.0 KB checked in by Dsls <dsls@…>, 14 years ago (diff)

Merged last default changes with formfilter branch

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2011 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
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17$params = array();
18
19/* Actions
20-------------------------------------------------------- */
21if (!empty($_POST['action']) && !empty($_POST['entries']))
22{
23     $entries = $_POST['entries'];
24     $action = $_POST['action'];
25     
26     if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
27     {
28          $redir = $_POST['redir'];
29     }
30     else
31     {
32          $redir =
33          'posts.php?'.urldecode($_POST['f_query']);
34     }
35     
36     foreach ($entries as $k => $v) {
37          $entries[$k] = (integer) $v;
38     }
39     
40     $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') ';
41     
42     if (!isset($_POST['full_content']) || empty($_POST['full_content'])) {
43          $params['no_content'] = true;
44     }
45     
46     if (isset($_POST['post_type'])) {
47          $params['post_type'] = $_POST['post_type'];
48     }
49     
50     $posts = $core->blog->getPosts($params);
51     
52     # --BEHAVIOR-- adminPostsActions
53     $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir);
54     
55     if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action))
56     {
57          switch ($action) {
58               case 'unpublish' : $status = 0; break;
59               case 'schedule' : $status = -1; break;
60               case 'pending' : $status = -2; break;
61               default : $status = 1; break;
62          }
63         
64          try
65          {
66               while ($posts->fetch()) {
67                    $core->blog->updPostStatus($posts->post_id,$status);
68               }
69               
70               http::redirect($redir);
71          }
72          catch (Exception $e)
73          {
74               $core->error->add($e->getMessage());
75          }
76     }
77     elseif ($action == 'selected' || $action == 'unselected')
78     {
79          try
80          {
81               while ($posts->fetch()) {
82                    $core->blog->updPostSelected($posts->post_id,$action == 'selected');
83               }
84               
85               http::redirect($redir);
86          }
87          catch (Exception $e)
88          {
89               $core->error->add($e->getMessage());
90          }
91     }
92     elseif ($action == 'delete')
93     {
94          try
95          {
96               while ($posts->fetch()) {
97                    # --BEHAVIOR-- adminBeforePostDelete
98                    $core->callBehavior('adminBeforePostDelete',$posts->post_id);                   
99                    $core->blog->delPost($posts->post_id);
100               }
101               
102               http::redirect($redir);
103          }
104          catch (Exception $e)
105          {
106               $core->error->add($e->getMessage());
107          }
108         
109     }
110     elseif ($action == 'category' && isset($_POST['new_cat_id']))
111     {
112          try
113          {
114               while ($posts->fetch())
115               {
116                    $new_cat_id = (integer) $_POST['new_cat_id'];
117                    $core->blog->updPostCategory($posts->post_id,$new_cat_id);
118               }
119               http::redirect($redir);
120          }
121          catch (Exception $e)
122          {
123               $core->error->add($e->getMessage());
124          }
125     }
126     elseif ($action == 'author' && isset($_POST['new_auth_id'])
127     && $core->auth->check('admin',$core->blog->id))
128     {
129          $new_user_id = $_POST['new_auth_id'];
130         
131          try
132          {
133               if ($core->getUser($new_user_id)->isEmpty()) {
134                    throw new Exception(__('This user does not exist'));
135               }
136               
137               while ($posts->fetch())
138               {
139                    $cur = $core->con->openCursor($core->prefix.'post');
140                    $cur->user_id = $new_user_id;
141                    $cur->update('WHERE post_id = '.(integer) $posts->post_id);
142               }
143               
144               http::redirect($redir);
145          }
146          catch (Exception $e)
147          {
148               $core->error->add($e->getMessage());
149          }
150     }
151}
152
153/* DISPLAY
154-------------------------------------------------------- */
155dcPage::open(
156     __('Entries'),
157     dcPage::jsMetaEditor().
158     # --BEHAVIOR-- adminBeforePostDelete
159     $core->callBehavior('adminPostsActionsHeaders')
160);
161
162if (!isset($action)) {
163     dcPage::close();
164     exit;
165}
166
167$hidden_fields = '';
168while ($posts->fetch()) {
169     $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id);
170}
171
172if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
173{
174     $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir']));
175}
176else
177{
178     $hidden_fields .=
179     form::hidden(array('user_id'),$_POST['user_id']).
180     form::hidden(array('cat_id'),$_POST['cat_id']).
181     form::hidden(array('status'),$_POST['status']).
182     form::hidden(array('selected'),$_POST['selected']).
183     form::hidden(array('month'),$_POST['month']).
184     form::hidden(array('lang'),$_POST['lang']).
185     form::hidden(array('sortby'),$_POST['sortby']).
186     form::hidden(array('order'),$_POST['order']).
187     form::hidden(array('page'),$_POST['page']).
188     form::hidden(array('nb'),$_POST['nb']);
189}
190
191if (isset($_POST['post_type'])) {
192     $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']);
193}
194
195# --BEHAVIOR-- adminPostsActionsContent
196$core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields);
197
198if ($action == 'category')
199{
200     echo '<h2 class="page-title">'.__('Change category for entries').'</h2>';
201     
202     # categories list
203     # Getting categories
204     $categories_combo = array('&nbsp;' => '');
205     try {
206          $categories = $core->blog->getCategories(array('post_type'=>'post'));
207          while ($categories->fetch()) {
208               $categories_combo[] = new formSelectOption(
209                    str_repeat('&nbsp;&nbsp;',$categories->level-1).
210                    ($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title),
211                    $categories->cat_id
212               );
213          }
214     } catch (Exception $e) { }
215     
216     echo
217     '<form action="posts_actions.php" method="post">'.
218     '<p><label for="new_cat_id" class="classic">'.__('Category:').' '.
219     form::combo('new_cat_id',$categories_combo,'').
220     '</label> ';
221     
222     echo
223     $hidden_fields.
224     $core->formNonce().
225     form::hidden(array('action'),'category').
226     '<input type="submit" value="'.__('Save').'" /></p>'.
227     '</form>';
228}
229elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id))
230{
231     echo '<h2 class="page-title">'.__('Change author for entries').'</h2>';
232     
233     echo
234     '<form action="posts_actions.php" method="post">'.
235     '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '.
236     form::field('new_auth_id',20,255).
237     '</label> ';
238     
239     echo
240     $hidden_fields.
241     $core->formNonce().
242     form::hidden(array('action'),'author').
243     '<input type="submit" value="'.__('Save').'" /></p>'.
244     '</form>';
245}
246
247echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>';
248
249dcPage::close();
250?>
Note: See TracBrowser for help on using the repository browser.

Sites map