[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 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(); |
---|
[1345] | 18 | $action = ''; |
---|
[0] | 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 | |
---|
[1030] | 62 | $posts_ids = array(); |
---|
| 63 | while ($posts->fetch()) { |
---|
| 64 | $posts_ids[] = $posts->post_id; |
---|
| 65 | } |
---|
| 66 | |
---|
[0] | 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 | { |
---|
[1030] | 81 | $core->blog->updPostsStatus($posts_ids,$status); |
---|
[0] | 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 | { |
---|
[1030] | 94 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
---|
[0] | 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 | { |
---|
[1030] | 107 | // Backward compatibility |
---|
| 108 | foreach($posts_ids as $post_id) |
---|
| 109 | { |
---|
[0] | 110 | # --BEHAVIOR-- adminBeforePostDelete |
---|
[1030] | 111 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
---|
[0] | 112 | } |
---|
| 113 | |
---|
[1030] | 114 | # --BEHAVIOR-- adminBeforePostsDelete |
---|
| 115 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
---|
| 116 | |
---|
| 117 | $core->blog->delPosts($posts_ids); |
---|
| 118 | |
---|
[0] | 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 | { |
---|
[1030] | 131 | $core->blog->updPostsCategory($posts_ids,$_POST['new_cat_id']); |
---|
| 132 | |
---|
[0] | 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 | |
---|
[1030] | 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)); |
---|
[0] | 154 | |
---|
| 155 | http::redirect($redir); |
---|
| 156 | } |
---|
| 157 | catch (Exception $e) |
---|
| 158 | { |
---|
| 159 | $core->error->add($e->getMessage()); |
---|
| 160 | } |
---|
| 161 | } |
---|
[1102] | 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 | } |
---|
[0] | 178 | } |
---|
| 179 | |
---|
| 180 | /* DISPLAY |
---|
| 181 | -------------------------------------------------------- */ |
---|
[1035] | 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 | } |
---|
[0] | 195 | dcPage::open( |
---|
| 196 | __('Entries'), |
---|
[1035] | 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'). |
---|
[0] | 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 | { |
---|
[500] | 247 | echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; |
---|
[0] | 248 | |
---|
| 249 | # categories list |
---|
| 250 | # Getting categories |
---|
| 251 | $categories_combo = array(' ' => ''); |
---|
| 252 | try { |
---|
| 253 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 254 | while ($categories->fetch()) { |
---|
| 255 | $categories_combo[] = new formSelectOption( |
---|
[252] | 256 | str_repeat(' ',$categories->level-1). |
---|
| 257 | ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), |
---|
[0] | 258 | $categories->cat_id |
---|
| 259 | ); |
---|
| 260 | } |
---|
| 261 | } catch (Exception $e) { } |
---|
| 262 | |
---|
| 263 | echo |
---|
| 264 | '<form action="posts_actions.php" method="post">'. |
---|
[70] | 265 | '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. |
---|
[0] | 266 | form::combo('new_cat_id',$categories_combo,''). |
---|
| 267 | '</label> '; |
---|
| 268 | |
---|
| 269 | echo |
---|
| 270 | $hidden_fields. |
---|
| 271 | $core->formNonce(). |
---|
| 272 | form::hidden(array('action'),'category'). |
---|
[217] | 273 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
[0] | 274 | '</form>'; |
---|
| 275 | } |
---|
[1102] | 276 | elseif ($action == 'lang') |
---|
| 277 | { |
---|
| 278 | echo '<h2 class="page-title">'.__('Change language for entries').'</h2>'; |
---|
| 279 | |
---|
| 280 | # lang list |
---|
| 281 | # Languages combo |
---|
| 282 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
| 283 | $all_langs = l10n::getISOcodes(0,1); |
---|
| 284 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
---|
| 285 | while ($rs->fetch()) { |
---|
| 286 | if (isset($all_langs[$rs->post_lang])) { |
---|
| 287 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
---|
| 288 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
---|
| 289 | } else { |
---|
| 290 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
---|
| 291 | } |
---|
| 292 | } |
---|
| 293 | unset($all_langs); |
---|
| 294 | unset($rs); |
---|
| 295 | |
---|
| 296 | echo |
---|
| 297 | '<form action="posts_actions.php" method="post">'. |
---|
| 298 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').' '. |
---|
| 299 | form::combo('new_lang',$lang_combo,''). |
---|
| 300 | '</label> '; |
---|
| 301 | |
---|
| 302 | echo |
---|
| 303 | $hidden_fields. |
---|
| 304 | $core->formNonce(). |
---|
| 305 | form::hidden(array('action'),'lang'). |
---|
| 306 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
| 307 | '</form>'; |
---|
| 308 | |
---|
| 309 | } |
---|
[0] | 310 | elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
| 311 | { |
---|
[500] | 312 | echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; |
---|
[0] | 313 | |
---|
| 314 | echo |
---|
| 315 | '<form action="posts_actions.php" method="post">'. |
---|
[70] | 316 | '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '. |
---|
[0] | 317 | form::field('new_auth_id',20,255). |
---|
| 318 | '</label> '; |
---|
| 319 | |
---|
| 320 | echo |
---|
| 321 | $hidden_fields. |
---|
| 322 | $core->formNonce(). |
---|
| 323 | form::hidden(array('action'),'author'). |
---|
[217] | 324 | '<input type="submit" value="'.__('Save').'" /></p>'. |
---|
[0] | 325 | '</form>'; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>'; |
---|
| 329 | |
---|
| 330 | dcPage::close(); |
---|
| 331 | ?> |
---|