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