[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[270] | 6 | # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | |
---|
| 13 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
| 14 | |
---|
| 15 | dcPage::check('usage,contentadmin'); |
---|
| 16 | |
---|
| 17 | $params = array(); |
---|
| 18 | |
---|
| 19 | /* Actions |
---|
| 20 | -------------------------------------------------------- */ |
---|
| 21 | if (!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 | |
---|
[1030] | 61 | $posts_ids = array(); |
---|
| 62 | while ($posts->fetch()) { |
---|
| 63 | $posts_ids[] = $posts->post_id; |
---|
| 64 | } |
---|
| 65 | |
---|
[0] | 66 | # --BEHAVIOR-- adminPostsActions |
---|
| 67 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); |
---|
| 68 | |
---|
| 69 | if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) |
---|
| 70 | { |
---|
| 71 | switch ($action) { |
---|
| 72 | case 'unpublish' : $status = 0; break; |
---|
| 73 | case 'schedule' : $status = -1; break; |
---|
| 74 | case 'pending' : $status = -2; break; |
---|
| 75 | default : $status = 1; break; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | try |
---|
| 79 | { |
---|
[1030] | 80 | $core->blog->updPostsStatus($posts_ids,$status); |
---|
[0] | 81 | |
---|
| 82 | http::redirect($redir); |
---|
| 83 | } |
---|
| 84 | catch (Exception $e) |
---|
| 85 | { |
---|
| 86 | $core->error->add($e->getMessage()); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | elseif ($action == 'selected' || $action == 'unselected') |
---|
| 90 | { |
---|
| 91 | try |
---|
| 92 | { |
---|
[1030] | 93 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
[0] | 94 | |
---|
| 95 | http::redirect($redir); |
---|
| 96 | } |
---|
| 97 | catch (Exception $e) |
---|
| 98 | { |
---|
| 99 | $core->error->add($e->getMessage()); |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | elseif ($action == 'delete') |
---|
| 103 | { |
---|
| 104 | try |
---|
| 105 | { |
---|
[1030] | 106 | // Backward compatibility |
---|
| 107 | foreach($posts_ids as $post_id) |
---|
| 108 | { |
---|
[0] | 109 | # --BEHAVIOR-- adminBeforePostDelete |
---|
[1030] | 110 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
---|
[0] | 111 | } |
---|
| 112 | |
---|
[1030] | 113 | # --BEHAVIOR-- adminBeforePostsDelete |
---|
| 114 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
---|
| 115 | |
---|
| 116 | $core->blog->delPosts($posts_ids); |
---|
| 117 | |
---|
[0] | 118 | http::redirect($redir); |
---|
| 119 | } |
---|
| 120 | catch (Exception $e) |
---|
| 121 | { |
---|
| 122 | $core->error->add($e->getMessage()); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | } |
---|
| 126 | elseif ($action == 'category' && isset($_POST['new_cat_id'])) |
---|
| 127 | { |
---|
| 128 | try |
---|
| 129 | { |
---|
[1030] | 130 | $core->blog->updPostsCategory($posts_ids,$_POST['new_cat_id']); |
---|
| 131 | |
---|
[0] | 132 | http::redirect($redir); |
---|
| 133 | } |
---|
| 134 | catch (Exception $e) |
---|
| 135 | { |
---|
| 136 | $core->error->add($e->getMessage()); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | elseif ($action == 'author' && isset($_POST['new_auth_id']) |
---|
| 140 | && $core->auth->check('admin',$core->blog->id)) |
---|
| 141 | { |
---|
| 142 | $new_user_id = $_POST['new_auth_id']; |
---|
| 143 | |
---|
| 144 | try |
---|
| 145 | { |
---|
| 146 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
| 147 | throw new Exception(__('This user does not exist')); |
---|
| 148 | } |
---|
| 149 | |
---|
[1030] | 150 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
| 151 | $cur->user_id = $new_user_id; |
---|
| 152 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
[0] | 153 | |
---|
| 154 | http::redirect($redir); |
---|
| 155 | } |
---|
| 156 | catch (Exception $e) |
---|
| 157 | { |
---|
| 158 | $core->error->add($e->getMessage()); |
---|
| 159 | } |
---|
| 160 | } |
---|
[1102] | 161 | elseif ($action == 'lang' && isset($_POST['new_lang'])) |
---|
| 162 | { |
---|
| 163 | $new_lang = $_POST['new_lang']; |
---|
| 164 | try |
---|
| 165 | { |
---|
| 166 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
| 167 | $cur->post_lang = $new_lang; |
---|
| 168 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
---|
| 169 | |
---|
| 170 | http::redirect($redir); |
---|
| 171 | } |
---|
| 172 | catch (Exception $e) |
---|
| 173 | { |
---|
| 174 | $core->error->add($e->getMessages()); |
---|
| 175 | } |
---|
| 176 | } |
---|
[0] | 177 | } |
---|
| 178 | |
---|
| 179 | /* DISPLAY |
---|
| 180 | -------------------------------------------------------- */ |
---|
[1035] | 181 | // Get current users list |
---|
| 182 | $usersList = ''; |
---|
| 183 | if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) { |
---|
| 184 | $params = array( |
---|
| 185 | 'limit' => 100, |
---|
| 186 | 'order' => 'nb_post DESC' |
---|
| 187 | ); |
---|
| 188 | $rs = $core->getUsers($params); |
---|
| 189 | while ($rs->fetch()) |
---|
| 190 | { |
---|
| 191 | $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"'; |
---|
| 192 | } |
---|
| 193 | } |
---|
[0] | 194 | dcPage::open( |
---|
| 195 | __('Entries'), |
---|
[1035] | 196 | '<script type="text/javascript">'."\n". |
---|
| 197 | "//<![CDATA[\n". |
---|
| 198 | 'usersList = ['.$usersList.']'."\n". |
---|
| 199 | "\n//]]>\n". |
---|
| 200 | "</script>\n". |
---|
| 201 | dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). |
---|
| 202 | dcPage::jsLoad('js/_posts_actions.js'). |
---|
[0] | 203 | dcPage::jsMetaEditor(). |
---|
| 204 | # --BEHAVIOR-- adminBeforePostDelete |
---|
| 205 | $core->callBehavior('adminPostsActionsHeaders') |
---|
| 206 | ); |
---|
| 207 | |
---|
| 208 | if (!isset($action)) { |
---|
| 209 | dcPage::close(); |
---|
| 210 | exit; |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | $hidden_fields = ''; |
---|
| 214 | while ($posts->fetch()) { |
---|
| 215 | $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
| 219 | { |
---|
| 220 | $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | $hidden_fields .= |
---|
| 225 | form::hidden(array('user_id'),$_POST['user_id']). |
---|
| 226 | form::hidden(array('cat_id'),$_POST['cat_id']). |
---|
| 227 | form::hidden(array('status'),$_POST['status']). |
---|
| 228 | form::hidden(array('selected'),$_POST['selected']). |
---|
| 229 | form::hidden(array('month'),$_POST['month']). |
---|
| 230 | form::hidden(array('lang'),$_POST['lang']). |
---|
| 231 | form::hidden(array('sortby'),$_POST['sortby']). |
---|
| 232 | form::hidden(array('order'),$_POST['order']). |
---|
| 233 | form::hidden(array('page'),$_POST['page']). |
---|
| 234 | form::hidden(array('nb'),$_POST['nb']); |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | if (isset($_POST['post_type'])) { |
---|
| 238 | $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | # --BEHAVIOR-- adminPostsActionsContent |
---|
| 242 | $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); |
---|
| 243 | |
---|
| 244 | if ($action == 'category') |
---|
| 245 | { |
---|
[500] | 246 | echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; |
---|
[0] | 247 | |
---|
| 248 | # categories list |
---|
| 249 | # Getting categories |
---|
| 250 | $categories_combo = array(' ' => ''); |
---|
| 251 | try { |
---|
| 252 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 253 | while ($categories->fetch()) { |
---|
| 254 | $categories_combo[] = new formSelectOption( |
---|
[252] | 255 | str_repeat(' ',$categories->level-1). |
---|
| 256 | ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), |
---|
[0] | 257 | $categories->cat_id |
---|
| 258 | ); |
---|
| 259 | } |
---|
| 260 | } catch (Exception $e) { } |
---|
| 261 | |
---|
| 262 | echo |
---|
| 263 | '<form action="posts_actions.php" method="post">'. |
---|
[70] | 264 | '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. |
---|
[0] | 265 | form::combo('new_cat_id',$categories_combo,''). |
---|
| 266 | '</label> '; |
---|
| 267 | |
---|
| 268 | echo |
---|
| 269 | $hidden_fields. |
---|
| 270 | $core->formNonce(). |
---|
| 271 | form::hidden(array('action'),'category'). |
---|
[217] | 272 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
[0] | 273 | '</form>'; |
---|
| 274 | } |
---|
[1102] | 275 | elseif ($action == 'lang') |
---|
| 276 | { |
---|
| 277 | echo '<h2 class="page-title">'.__('Change language for entries').'</h2>'; |
---|
| 278 | |
---|
| 279 | # lang list |
---|
| 280 | # Languages combo |
---|
| 281 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
| 282 | $all_langs = l10n::getISOcodes(0,1); |
---|
| 283 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
| 284 | while ($rs->fetch()) { |
---|
| 285 | if (isset($all_langs[$rs->post_lang])) { |
---|
| 286 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
| 287 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
| 288 | } else { |
---|
| 289 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | unset($all_langs); |
---|
| 293 | unset($rs); |
---|
| 294 | |
---|
| 295 | echo |
---|
| 296 | '<form action="posts_actions.php" method="post">'. |
---|
| 297 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').' '. |
---|
| 298 | form::combo('new_lang',$lang_combo,''). |
---|
| 299 | '</label> '; |
---|
| 300 | |
---|
| 301 | echo |
---|
| 302 | $hidden_fields. |
---|
| 303 | $core->formNonce(). |
---|
| 304 | form::hidden(array('action'),'lang'). |
---|
| 305 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
| 306 | '</form>'; |
---|
| 307 | |
---|
| 308 | } |
---|
[0] | 309 | elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
| 310 | { |
---|
[500] | 311 | echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; |
---|
[0] | 312 | |
---|
| 313 | echo |
---|
| 314 | '<form action="posts_actions.php" method="post">'. |
---|
[70] | 315 | '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '. |
---|
[0] | 316 | form::field('new_auth_id',20,255). |
---|
| 317 | '</label> '; |
---|
| 318 | |
---|
| 319 | echo |
---|
| 320 | $hidden_fields. |
---|
| 321 | $core->formNonce(). |
---|
| 322 | form::hidden(array('action'),'author'). |
---|
[217] | 323 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
[0] | 324 | '</form>'; |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>'; |
---|
| 328 | |
---|
| 329 | dcPage::close(); |
---|
| 330 | ?> |
---|