| 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 | |
|---|
| 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 | '&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 | $posts_ids = array(); |
|---|
| 61 | while ($posts->fetch()) { |
|---|
| 62 | $posts_ids[] = $posts->post_id; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | # --BEHAVIOR-- adminPostsActions |
|---|
| 66 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); |
|---|
| 67 | |
|---|
| 68 | if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) |
|---|
| 69 | { |
|---|
| 70 | switch ($action) { |
|---|
| 71 | case 'unpublish' : $status = 0; break; |
|---|
| 72 | case 'schedule' : $status = -1; break; |
|---|
| 73 | case 'pending' : $status = -2; break; |
|---|
| 74 | default : $status = 1; break; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | try |
|---|
| 78 | { |
|---|
| 79 | $core->blog->updPostsStatus($posts_ids,$status); |
|---|
| 80 | |
|---|
| 81 | http::redirect($redir); |
|---|
| 82 | } |
|---|
| 83 | catch (Exception $e) |
|---|
| 84 | { |
|---|
| 85 | $core->error->add($e->getMessage()); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | elseif ($action == 'selected' || $action == 'unselected') |
|---|
| 89 | { |
|---|
| 90 | try |
|---|
| 91 | { |
|---|
| 92 | $core->blog->updPostsSelected($posts_ids,$action == 'selected'); |
|---|
| 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 | // Backward compatibility |
|---|
| 106 | foreach($posts_ids as $post_id) |
|---|
| 107 | { |
|---|
| 108 | # --BEHAVIOR-- adminBeforePostDelete |
|---|
| 109 | $core->callBehavior('adminBeforePostDelete',(integer) $post_id); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | # --BEHAVIOR-- adminBeforePostsDelete |
|---|
| 113 | $core->callBehavior('adminBeforePostsDelete',$posts_ids); |
|---|
| 114 | |
|---|
| 115 | $core->blog->delPosts($posts_ids); |
|---|
| 116 | |
|---|
| 117 | http::redirect($redir); |
|---|
| 118 | } |
|---|
| 119 | catch (Exception $e) |
|---|
| 120 | { |
|---|
| 121 | $core->error->add($e->getMessage()); |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | } |
|---|
| 125 | elseif ($action == 'author' && isset($_POST['new_auth_id']) |
|---|
| 126 | && $core->auth->check('admin',$core->blog->id)) |
|---|
| 127 | { |
|---|
| 128 | $new_user_id = $_POST['new_auth_id']; |
|---|
| 129 | |
|---|
| 130 | try |
|---|
| 131 | { |
|---|
| 132 | if ($core->getUser($new_user_id)->isEmpty()) { |
|---|
| 133 | throw new Exception(__('This user does not exist')); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | $cur = $core->con->openCursor($core->prefix.'post'); |
|---|
| 137 | $cur->user_id = $new_user_id; |
|---|
| 138 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
|---|
| 139 | |
|---|
| 140 | http::redirect($redir); |
|---|
| 141 | } |
|---|
| 142 | catch (Exception $e) |
|---|
| 143 | { |
|---|
| 144 | $core->error->add($e->getMessage()); |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | elseif ($action == 'lang' && isset($_POST['new_lang'])) |
|---|
| 148 | { |
|---|
| 149 | $new_lang = $_POST['new_lang']; |
|---|
| 150 | try |
|---|
| 151 | { |
|---|
| 152 | $cur = $core->con->openCursor($core->prefix.'post'); |
|---|
| 153 | $cur->post_lang = $new_lang; |
|---|
| 154 | $cur->update('WHERE post_id '.$core->con->in($posts_ids)); |
|---|
| 155 | |
|---|
| 156 | http::redirect($redir); |
|---|
| 157 | } |
|---|
| 158 | catch (Exception $e) |
|---|
| 159 | { |
|---|
| 160 | $core->error->add($e->getMessages()); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | } |
|---|
| 164 | |
|---|
| 165 | /* DISPLAY |
|---|
| 166 | -------------------------------------------------------- */ |
|---|
| 167 | // Get current users list |
|---|
| 168 | $usersList = ''; |
|---|
| 169 | if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) { |
|---|
| 170 | $params = array( |
|---|
| 171 | 'limit' => 100, |
|---|
| 172 | 'order' => 'nb_post DESC' |
|---|
| 173 | ); |
|---|
| 174 | $rs = $core->getUsers($params); |
|---|
| 175 | while ($rs->fetch()) |
|---|
| 176 | { |
|---|
| 177 | $usersList .= ($usersList != '' ? ',' : '').'"'.$rs->user_id.'"'; |
|---|
| 178 | } |
|---|
| 179 | } |
|---|
| 180 | dcPage::open( |
|---|
| 181 | __('Entries'), |
|---|
| 182 | '<script type="text/javascript">'."\n". |
|---|
| 183 | "//<![CDATA[\n". |
|---|
| 184 | 'usersList = ['.$usersList.']'."\n". |
|---|
| 185 | "\n//]]>\n". |
|---|
| 186 | "</script>\n". |
|---|
| 187 | dcPage::jsLoad('js/jquery/jquery.autocomplete.js'). |
|---|
| 188 | dcPage::jsLoad('js/_posts_actions.js'). |
|---|
| 189 | dcPage::jsMetaEditor(). |
|---|
| 190 | # --BEHAVIOR-- adminBeforePostDelete |
|---|
| 191 | $core->callBehavior('adminPostsActionsHeaders') |
|---|
| 192 | ); |
|---|
| 193 | |
|---|
| 194 | if (!isset($action)) { |
|---|
| 195 | dcPage::close(); |
|---|
| 196 | exit; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | $hidden_fields = ''; |
|---|
| 200 | foreach ($posts as $post) { |
|---|
| 201 | $hidden_fields .= form::hidden(array('entries[]'),$post->post_id); |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
|---|
| 205 | { |
|---|
| 206 | $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); |
|---|
| 207 | } |
|---|
| 208 | else |
|---|
| 209 | { |
|---|
| 210 | $hidden_fields .= |
|---|
| 211 | form::hidden(array('user_id'),$_POST['user_id']). |
|---|
| 212 | form::hidden(array('status'),$_POST['status']). |
|---|
| 213 | form::hidden(array('selected'),$_POST['selected']). |
|---|
| 214 | form::hidden(array('month'),$_POST['month']). |
|---|
| 215 | form::hidden(array('lang'),$_POST['lang']). |
|---|
| 216 | form::hidden(array('sortby'),$_POST['sortby']). |
|---|
| 217 | form::hidden(array('order'),$_POST['order']). |
|---|
| 218 | form::hidden(array('page'),$_POST['page']). |
|---|
| 219 | form::hidden(array('nb'),$_POST['nb']); |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | if (isset($_POST['post_type'])) { |
|---|
| 223 | $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | # --BEHAVIOR-- adminPostsActionsContent |
|---|
| 227 | $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); |
|---|
| 228 | |
|---|
| 229 | if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
|---|
| 230 | { |
|---|
| 231 | } |
|---|
| 232 | elseif ($action == 'lang') |
|---|
| 233 | { |
|---|
| 234 | echo '<h2 class="page-title">'.__('Change language for entries').'</h2>'; |
|---|
| 235 | |
|---|
| 236 | # lang list |
|---|
| 237 | # Languages combo |
|---|
| 238 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
|---|
| 239 | $all_langs = l10n::getISOcodes(0,1); |
|---|
| 240 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); |
|---|
| 241 | while ($rs->fetch()) { |
|---|
| 242 | if (isset($all_langs[$rs->post_lang])) { |
|---|
| 243 | $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang; |
|---|
| 244 | unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]); |
|---|
| 245 | } else { |
|---|
| 246 | $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang; |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | unset($all_langs); |
|---|
| 250 | unset($rs); |
|---|
| 251 | |
|---|
| 252 | echo |
|---|
| 253 | '<form action="posts_actions.php" method="post">'. |
|---|
| 254 | '<p><label for="new_lang" class="classic">'.__('Entry lang:').' '. |
|---|
| 255 | form::combo('new_lang',$lang_combo,''). |
|---|
| 256 | '</label> '; |
|---|
| 257 | |
|---|
| 258 | echo |
|---|
| 259 | $hidden_fields. |
|---|
| 260 | $core->formNonce(). |
|---|
| 261 | form::hidden(array('action'),'lang'). |
|---|
| 262 | '<input type="submit" value="'.__('Save').'" /></p>'. |
|---|
| 263 | '</form>'; |
|---|
| 264 | |
|---|
| 265 | echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; |
|---|
| 266 | |
|---|
| 267 | echo |
|---|
| 268 | '<form action="posts_actions.php" method="post">'. |
|---|
| 269 | '<p><label for="new_auth_id" class="classic">'.__('Author ID:').' '. |
|---|
| 270 | form::field('new_auth_id',20,255). |
|---|
| 271 | '</label> '; |
|---|
| 272 | |
|---|
| 273 | echo |
|---|
| 274 | $hidden_fields. |
|---|
| 275 | $core->formNonce(). |
|---|
| 276 | form::hidden(array('action'),'author'). |
|---|
| 277 | '<input type="submit" value="'.__('Save').'" /></p>'. |
|---|
| 278 | '</form>'; |
|---|
| 279 | } |
|---|
| 280 | |
|---|
| 281 | echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>'; |
|---|
| 282 | |
|---|
| 283 | dcPage::close(); |
|---|
| 284 | ?> |
|---|