Dotclear

source: admin/posts_actions.php @ 851:0993f64c4809

Revision 851:0993f64c4809, 4.9 KB checked in by Dsls <dsls@…>, 13 years ago (diff)

sexy step 2 : no more cats.

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?user_id='.$_POST['user_id'].
34          '&status='.$_POST['status'].
35          '&selected='.$_POST['selected'].
36          '&month='.$_POST['month'].
37          '&lang='.$_POST['lang'].
38          '&sortby='.$_POST['sortby'].
39          '&order='.$_POST['order'].
40          '&page='.$_POST['page'].
41          '&nb='.$_POST['nb'];
42     }
43     
44     foreach ($entries as $k => $v) {
45          $entries[$k] = (integer) $v;
46     }
47     
48     $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') ';
49     
50     if (!isset($_POST['full_content']) || empty($_POST['full_content'])) {
51          $params['no_content'] = true;
52     }
53     
54     if (isset($_POST['post_type'])) {
55          $params['post_type'] = $_POST['post_type'];
56     }
57     
58     $posts = $core->blog->getPosts($params);
59     
60     # --BEHAVIOR-- adminPostsActions
61     $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir);
62     
63     if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action))
64     {
65          switch ($action) {
66               case 'unpublish' : $status = 0; break;
67               case 'schedule' : $status = -1; break;
68               case 'pending' : $status = -2; break;
69               default : $status = 1; break;
70          }
71         
72          try
73          {
74               while ($posts->fetch()) {
75                    $core->blog->updPostStatus($posts->post_id,$status);
76               }
77               
78               http::redirect($redir);
79          }
80          catch (Exception $e)
81          {
82               $core->error->add($e->getMessage());
83          }
84     }
85     elseif ($action == 'selected' || $action == 'unselected')
86     {
87          try
88          {
89               while ($posts->fetch()) {
90                    $core->blog->updPostSelected($posts->post_id,$action == 'selected');
91               }
92               
93               http::redirect($redir);
94          }
95          catch (Exception $e)
96          {
97               $core->error->add($e->getMessage());
98          }
99     }
100     elseif ($action == 'delete')
101     {
102          try
103          {
104               while ($posts->fetch()) {
105                    # --BEHAVIOR-- adminBeforePostDelete
106                    $core->callBehavior('adminBeforePostDelete',$posts->post_id);                   
107                    $core->blog->delPost($posts->post_id);
108               }
109               
110               http::redirect($redir);
111          }
112          catch (Exception $e)
113          {
114               $core->error->add($e->getMessage());
115          }
116         
117     }
118     elseif ($action == 'author' && isset($_POST['new_auth_id'])
119     && $core->auth->check('admin',$core->blog->id))
120     {
121          $new_user_id = $_POST['new_auth_id'];
122         
123          try
124          {
125               if ($core->getUser($new_user_id)->isEmpty()) {
126                    throw new Exception(__('This user does not exist'));
127               }
128               
129               while ($posts->fetch())
130               {
131                    $cur = $core->con->openCursor($core->prefix.'post');
132                    $cur->user_id = $new_user_id;
133                    $cur->update('WHERE post_id = '.(integer) $posts->post_id);
134               }
135               
136               http::redirect($redir);
137          }
138          catch (Exception $e)
139          {
140               $core->error->add($e->getMessage());
141          }
142     }
143}
144
145/* DISPLAY
146-------------------------------------------------------- */
147dcPage::open(
148     __('Entries'),
149     dcPage::jsMetaEditor().
150     # --BEHAVIOR-- adminBeforePostDelete
151     $core->callBehavior('adminPostsActionsHeaders')
152);
153
154if (!isset($action)) {
155     dcPage::close();
156     exit;
157}
158
159$hidden_fields = '';
160while ($posts->fetch()) {
161     $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id);
162}
163
164if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false)
165{
166     $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir']));
167}
168else
169{
170     $hidden_fields .=
171     form::hidden(array('user_id'),$_POST['user_id']).
172     form::hidden(array('status'),$_POST['status']).
173     form::hidden(array('selected'),$_POST['selected']).
174     form::hidden(array('month'),$_POST['month']).
175     form::hidden(array('lang'),$_POST['lang']).
176     form::hidden(array('sortby'),$_POST['sortby']).
177     form::hidden(array('order'),$_POST['order']).
178     form::hidden(array('page'),$_POST['page']).
179     form::hidden(array('nb'),$_POST['nb']);
180}
181
182if (isset($_POST['post_type'])) {
183     $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']);
184}
185
186# --BEHAVIOR-- adminPostsActionsContent
187$core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields);
188
189if ($action == 'author' && $core->auth->check('admin',$core->blog->id))
190{
191     echo '<h2 class="page-title">'.__('Change author for entries').'</h2>';
192     
193     echo
194     '<form action="posts_actions.php" method="post">'.
195     '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '.
196     form::field('new_auth_id',20,255).
197     '</label> ';
198     
199     echo
200     $hidden_fields.
201     $core->formNonce().
202     form::hidden(array('action'),'author').
203     '<input type="submit" value="'.__('Save').'" /></p>'.
204     '</form>';
205}
206
207echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>';
208
209dcPage::close();
210?>
Note: See TracBrowser for help on using the repository browser.

Sites map