Dotclear

source: admin/posts_actions.php @ 500:f88db2e809f4

Revision 500:f88db2e809f4, 6.2 KB checked in by kozlika, 14 years ago (diff)

First step for #1247. Il faudra revenir sur les pages media.php, permissions.php, plugins/antispam/index.php (la couleur on verra après ; pour l'instant c'est très voyant, très pratique pour bosser et aussi très gai, na !)

Dans ce commit aussi : réorganisation de la feuille de style pour s'y retrouver plus facilement.

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

Sites map