[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[2682] | 6 | # Copyright (c) 2003-2014 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 | |
---|
[1414] | 17 | class PostActions |
---|
| 18 | { |
---|
| 19 | public static function savePost($form) { |
---|
| 20 | global $_ctx, $core; |
---|
[1497] | 21 | if (!$form->can_edit_post) { |
---|
| 22 | return; |
---|
| 23 | } |
---|
[1414] | 24 | try { |
---|
| 25 | $form->check($_ctx); |
---|
| 26 | $form->cat_id = (integer) $form->cat_id; |
---|
| 27 | |
---|
| 28 | if (!empty($form->post_dt)) { |
---|
| 29 | try |
---|
| 30 | { |
---|
| 31 | $post_dt = strtotime($form->post_dt); |
---|
| 32 | if ($post_dt == false || $post_dt == -1) { |
---|
| 33 | $bad_dt = true; |
---|
| 34 | throw new Exception(__('Invalid publication date')); |
---|
| 35 | } |
---|
| 36 | $form->post_dt = date('Y-m-d H:i',$post_dt); |
---|
| 37 | } |
---|
| 38 | catch (Exception $e) |
---|
| 39 | { |
---|
| 40 | $core->error->add($e->getMessage()); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | $post_excerpt = $form->post_excerpt; |
---|
| 44 | $post_content = $form->post_content; |
---|
| 45 | $post_excerpt_xhtml = ''; |
---|
| 46 | $post_content_xhtml = ''; |
---|
| 47 | $core->blog->setPostContent( |
---|
| 48 | $form->id,$form->post_format,$form->post_lang, |
---|
| 49 | $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml |
---|
| 50 | ); |
---|
| 51 | $form->post_excerpt = $post_excerpt; |
---|
| 52 | $form->post_content = $post_content; |
---|
| 53 | $form->post_excerpt_xhtml = $post_excerpt_xhtml; |
---|
| 54 | $form->post_content_xhtml = $post_content_xhtml; |
---|
| 55 | |
---|
| 56 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
| 57 | |
---|
| 58 | $cur->post_title = $form->post_title; |
---|
| 59 | $cur->cat_id = $form->cat_id ? $form->cat_id : null; |
---|
| 60 | $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : ''; |
---|
| 61 | $cur->post_format = $form->post_format; |
---|
| 62 | $cur->post_password = $form->post_password; |
---|
| 63 | $cur->post_lang = $form->post_lang; |
---|
| 64 | $cur->post_title = $form->post_title; |
---|
| 65 | $cur->post_excerpt = $form->post_excerpt; |
---|
| 66 | $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml; |
---|
| 67 | $cur->post_content = $form->post_content; |
---|
| 68 | $cur->post_content_xhtml = $form->post_content_xhtml; |
---|
| 69 | $cur->post_notes = $form->post_notes; |
---|
| 70 | $cur->post_status = $form->post_status; |
---|
| 71 | $cur->post_selected = (integer) $form->post_selected; |
---|
| 72 | $cur->post_open_comment = (integer) $form->post_open_comment; |
---|
| 73 | $cur->post_open_tb = (integer) $form->post_open_tb; |
---|
| 74 | |
---|
| 75 | if (!empty($form->post_url)) { |
---|
| 76 | $cur->post_url = $form->post_url; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | # Update post |
---|
| 80 | if ($form->id) |
---|
| 81 | { |
---|
| 82 | # --BEHAVIOR-- adminBeforePostUpdate |
---|
| 83 | $core->callBehavior('adminBeforePostUpdate',$cur,$form->id); |
---|
| 84 | |
---|
| 85 | $core->blog->updPost($form->id,$cur); |
---|
| 86 | |
---|
| 87 | # --BEHAVIOR-- adminAfterPostUpdate |
---|
| 88 | $core->callBehavior('adminAfterPostUpdate',$cur,$form->id); |
---|
| 89 | http::redirect('post.php?id='.$form->id.'&upd=1'); |
---|
| 90 | } |
---|
| 91 | else |
---|
| 92 | { |
---|
| 93 | $cur->user_id = $core->auth->userID(); |
---|
| 94 | # --BEHAVIOR-- adminBeforePostCreate |
---|
| 95 | $core->callBehavior('adminBeforePostCreate',$cur); |
---|
| 96 | |
---|
| 97 | $return_id = $core->blog->addPost($cur); |
---|
| 98 | |
---|
| 99 | # --BEHAVIOR-- adminAfterPostCreate |
---|
| 100 | $core->callBehavior('adminAfterPostCreate',$cur,$return_id); |
---|
| 101 | |
---|
| 102 | http::redirect('post.php?id='.$return_id.'&crea=1'); |
---|
| 103 | } |
---|
[1053] | 104 | |
---|
[1497] | 105 | } catch (Exception $e) { |
---|
| 106 | $_ctx->addError($e->getMessage()); |
---|
| 107 | } |
---|
[1414] | 108 | } |
---|
[1497] | 109 | public static function deletePost($form) { |
---|
| 110 | global $core,$_ctx; |
---|
| 111 | if ($form->can_delete) { |
---|
| 112 | try { |
---|
| 113 | $post_id = $form->id; |
---|
| 114 | $core->callBehavior('adminBeforePostDelete',$post_id); |
---|
| 115 | $core->blog->delPost($post_id); |
---|
| 116 | http::redirect('posts.php'); |
---|
| 117 | exit; |
---|
| 118 | } catch (Exception $e) { |
---|
| 119 | $_ctx->addError($e->getMessage()); |
---|
| 120 | } |
---|
| 121 | } |
---|
[1414] | 122 | } |
---|
[1053] | 123 | } |
---|
[0] | 124 | |
---|
[195] | 125 | $page_title = __('New entry'); |
---|
[1414] | 126 | $post_id=''; |
---|
[0] | 127 | $can_view_page = true; |
---|
| 128 | $can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); |
---|
| 129 | $can_publish = $core->auth->check('publish,contentadmin',$core->blog->id); |
---|
| 130 | $can_delete = false; |
---|
| 131 | |
---|
[2682] | 132 | $post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />'; |
---|
| 133 | $post_link = '<a href="post.php?id=%s" title="%s">%s</a>'; |
---|
[0] | 134 | |
---|
| 135 | $next_link = $prev_link = $next_headlink = $prev_headlink = null; |
---|
| 136 | |
---|
| 137 | # If user can't publish |
---|
| 138 | if (!$can_publish) { |
---|
[992] | 139 | $form->post_status = -2; |
---|
[0] | 140 | } |
---|
| 141 | |
---|
[1288] | 142 | # Getting categories |
---|
[1468] | 143 | $categories_combo = array(' ' => ''); |
---|
| 144 | try { |
---|
| 145 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
| 146 | while ($categories->fetch()) { |
---|
[1053] | 147 | $categories_combo[$categories->cat_id] = |
---|
| 148 | str_repeat(' ',$categories->level-1). |
---|
| 149 | ($categories->level-1 == 0 ? '' : '• '). |
---|
| 150 | html::escapeHTML($categories->cat_title); |
---|
[1468] | 151 | } |
---|
| 152 | } catch (Exception $e) { } |
---|
[1288] | 153 | |
---|
[1468] | 154 | # Status combo |
---|
| 155 | foreach ($core->blog->getAllPostStatus() as $k => $v) { |
---|
[992] | 156 | $status_combo[$k] = $v; |
---|
[1468] | 157 | } |
---|
[0] | 158 | |
---|
| 159 | # Formaters combo |
---|
[1468] | 160 | foreach ($core->getFormaters() as $v) { |
---|
| 161 | $formaters_combo[$v] = $v; |
---|
[2705] | 162 | } |
---|
[0] | 163 | |
---|
| 164 | # Languages combo |
---|
| 165 | $rs = $core->blog->getLangs(array('order'=>'asc')); |
---|
[1468] | 166 | $all_langs = l10n::getISOcodes(0,1); |
---|
[1414] | 167 | $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1)); |
---|
[1468] | 168 | while ($rs->fetch()) { |
---|
| 169 | if (isset($all_langs[$rs->post_lang])) { |
---|
[1414] | 170 | $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; |
---|
| 171 | unset($lang_combo[__('Available')][$rs->post_lang]); |
---|
[1468] | 172 | } else { |
---|
[1414] | 173 | $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; |
---|
[1468] | 174 | } |
---|
| 175 | } |
---|
| 176 | unset($all_langs); |
---|
| 177 | unset($rs); |
---|
[0] | 178 | |
---|
[992] | 179 | $form = new dcForm($core,'post','post.php'); |
---|
| 180 | $form |
---|
| 181 | ->addField( |
---|
| 182 | new dcFieldText('post_title','', array( |
---|
[1414] | 183 | 'maxlength' => 255, |
---|
[992] | 184 | 'required' => true, |
---|
[1493] | 185 | 'label' => __('Title:')))) |
---|
[992] | 186 | ->addField( |
---|
| 187 | new dcFieldTextArea('post_excerpt','', array( |
---|
| 188 | 'cols' => 50, |
---|
| 189 | 'rows' => 5, |
---|
[1493] | 190 | 'label' => __("Excerpt:").'<span class="form-note">'. |
---|
| 191 | __('Add an introduction to the post.').'</span>'))) |
---|
[992] | 192 | ->addField( |
---|
| 193 | new dcFieldTextArea('post_content','', array( |
---|
| 194 | 'required' => true, |
---|
| 195 | 'label' => __("Content:")))) |
---|
| 196 | ->addField( |
---|
| 197 | new dcFieldTextArea('post_notes','', array( |
---|
| 198 | 'label' => __("Notes")))) |
---|
| 199 | ->addField( |
---|
[1053] | 200 | new dcFieldSubmit('save',__('Save'),array( |
---|
[1414] | 201 | 'action' => array('PostActions','savePost')))) |
---|
[992] | 202 | ->addField( |
---|
[1053] | 203 | new dcFieldSubmit('delete',__('Delete'),array( |
---|
[1497] | 204 | 'action' => array('PostActions','deletePost')))) |
---|
[1001] | 205 | ->addField( |
---|
[992] | 206 | new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array( |
---|
| 207 | 'disabled' => !$can_publish, |
---|
[1491] | 208 | 'label' => __('Entry status')))) |
---|
[992] | 209 | ->addField( |
---|
| 210 | new dcFieldCombo('cat_id','',$categories_combo,array( |
---|
[1491] | 211 | "label" => __('Category')))) |
---|
| 212 | ->addField( |
---|
| 213 | new dcFieldCombo('new_cat_parent','',$categories_combo,array( |
---|
| 214 | "label" => __('Parent:')))) |
---|
| 215 | ->addField( |
---|
| 216 | new dcFieldText('new_cat_title','', array( |
---|
| 217 | 'maxlength' => 255, |
---|
| 218 | 'label' => __('Title')))) |
---|
| 219 | |
---|
[992] | 220 | ->addField( |
---|
| 221 | new dcFieldText('post_dt','',array( |
---|
[1491] | 222 | "label" => __('Publication date and hour')))) |
---|
[992] | 223 | ->addField( |
---|
| 224 | new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array( |
---|
[1491] | 225 | "label" => __('Text formating')))) |
---|
[992] | 226 | ->addField( |
---|
| 227 | new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array( |
---|
| 228 | "label" => __('Accept comments')))) |
---|
| 229 | ->addField( |
---|
| 230 | new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array( |
---|
| 231 | "label" => __('Accept trackbacks')))) |
---|
| 232 | ->addField( |
---|
[1414] | 233 | new dcFieldCheckbox ('post_selected',array(1=>false),array( |
---|
[992] | 234 | "label" => __('Selected entry')))) |
---|
| 235 | ->addField( |
---|
| 236 | new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( |
---|
| 237 | "label" => __('Entry lang:')))) |
---|
[1053] | 238 | ->addField( |
---|
[1319] | 239 | new dcFieldText('post_password','',array( |
---|
| 240 | "maxlength" => 32, |
---|
| 241 | "label" => __('Entry password:')))) |
---|
| 242 | ->addField( |
---|
| 243 | new dcFieldText('post_url','',array( |
---|
| 244 | "maxlength" => 255, |
---|
| 245 | "label" => __('Basename:')))) |
---|
| 246 | ->addField( |
---|
[1053] | 247 | new dcFieldHidden ('id','')) |
---|
[992] | 248 | ; |
---|
[2682] | 249 | # Get entry informations |
---|
| 250 | if (!empty($_REQUEST['id'])) |
---|
| 251 | { |
---|
| 252 | $params['post_id'] = $_REQUEST['id']; |
---|
[2390] | 253 | |
---|
[2682] | 254 | $post = $core->blog->getPosts($params); |
---|
[2390] | 255 | |
---|
[2682] | 256 | if ($post->isEmpty()) |
---|
| 257 | { |
---|
| 258 | $core->error->add(__('This entry does not exist.')); |
---|
| 259 | $can_view_page = false; |
---|
| 260 | } |
---|
| 261 | else |
---|
| 262 | { |
---|
[1319] | 263 | $form->id = $post_id = $post->post_id; |
---|
[992] | 264 | $form->cat_id = $post->cat_id; |
---|
| 265 | $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); |
---|
| 266 | $form->post_format = $post->post_format; |
---|
| 267 | $form->post_password = $post->post_password; |
---|
| 268 | $form->post_url = $post->post_url; |
---|
| 269 | $form->post_lang = $post->post_lang; |
---|
| 270 | $form->post_title = $post->post_title; |
---|
| 271 | $form->post_excerpt = $post->post_excerpt; |
---|
[1053] | 272 | $form->post_excerpt_xhtml = $post->post_excerpt_xhtml; |
---|
[992] | 273 | $form->post_content = $post->post_content; |
---|
[1053] | 274 | $form->post_content_xhtml = $post->post_content_xhtml; |
---|
[992] | 275 | $form->post_notes = $post->post_notes; |
---|
| 276 | $form->post_status = $post->post_status; |
---|
| 277 | $form->post_selected = (boolean) $post->post_selected; |
---|
| 278 | $form->post_open_comment = (boolean) $post->post_open_comment; |
---|
| 279 | $form->post_open_tb = (boolean) $post->post_open_tb; |
---|
[1053] | 280 | $form->can_edit_post = $post->isEditable(); |
---|
| 281 | $form->can_delete= $post->isDeletable(); |
---|
[2682] | 282 | $next_rs = $core->blog->getNextPost($post,1); |
---|
| 283 | $prev_rs = $core->blog->getNextPost($post,-1); |
---|
[2390] | 284 | |
---|
| 285 | if ($next_rs !== null) { |
---|
[1493] | 286 | $_ctx->next_post = array('id' => $next_rs->post_id,'title' => $next_rs->post_title); |
---|
[2390] | 287 | } |
---|
| 288 | if ($prev_rs !== null) { |
---|
[1493] | 289 | $_ctx->prev_post = array('id' => $prev_rs->post_id,'title' => $prev_rs->post_title); |
---|
[2390] | 290 | } |
---|
[1333] | 291 | $page_title = __('Edit entry'); |
---|
[0] | 292 | |
---|
[2682] | 293 | } |
---|
| 294 | } |
---|
[1319] | 295 | if ($post_id) { |
---|
| 296 | $_ctx->post_id = $post->post_id; |
---|
[1783] | 297 | |
---|
[1319] | 298 | $_ctx->preview_url = |
---|
| 299 | $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. |
---|
| 300 | http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). |
---|
| 301 | '/'.$post->post_url); |
---|
[1312] | 302 | |
---|
[1468] | 303 | |
---|
[1498] | 304 | $form_comment = new dcForm($core,'add-comment','comment.php'); |
---|
[1319] | 305 | $form_comment |
---|
| 306 | ->addField( |
---|
| 307 | new dcFieldText('comment_author','', array( |
---|
| 308 | 'maxlength' => 255, |
---|
| 309 | 'required' => true, |
---|
| 310 | 'label' => __('Name:')))) |
---|
| 311 | ->addField( |
---|
| 312 | new dcFieldText('comment_email','', array( |
---|
| 313 | 'maxlength' => 255, |
---|
| 314 | 'required' => true, |
---|
| 315 | 'label' => __('Email:')))) |
---|
| 316 | ->addField( |
---|
| 317 | new dcFieldText('comment_site','', array( |
---|
| 318 | 'maxlength' => 255, |
---|
| 319 | 'label' => __('Web site:')))) |
---|
| 320 | ->addField( |
---|
| 321 | new dcFieldTextArea('comment_content','', array( |
---|
| 322 | 'required' => true, |
---|
| 323 | 'label' => __('Comment:')))) |
---|
| 324 | ->addField( |
---|
[1498] | 325 | new dcFieldHidden('post_id',$post_id)) |
---|
| 326 | ->addField( |
---|
[1319] | 327 | new dcFieldSubmit('add',__('Save'),array( |
---|
| 328 | 'action' => 'addComment'))) |
---|
| 329 | ; |
---|
[2390] | 330 | |
---|
[1468] | 331 | |
---|
[2694] | 332 | } |
---|
| 333 | |
---|
[1053] | 334 | $form->setup(); |
---|
[2542] | 335 | |
---|
[1491] | 336 | $sidebar_blocks = new ArrayObject(array( |
---|
| 337 | 'status-box' => array( |
---|
| 338 | 'title' => __('Status'), |
---|
| 339 | 'items' => array('post_status','post_dt','post_lang','post_format')), |
---|
| 340 | 'metas-box' => array( |
---|
| 341 | 'title' => __('Ordering'), |
---|
| 342 | 'items' => array('post_selected','cat_id')), |
---|
| 343 | 'options-box' => array( |
---|
| 344 | 'title' => __('Options'), |
---|
| 345 | 'items' => array('post_open_comment','post_open_tb','post_password','post_url')) |
---|
| 346 | )); |
---|
[2542] | 347 | |
---|
[1491] | 348 | $main_blocks = new ArrayObject(array( |
---|
| 349 | "post_title","post_excerpt","post_content","post_notes" |
---|
| 350 | )); |
---|
[2542] | 351 | |
---|
| 352 | |
---|
[1491] | 353 | $_ctx->sidebar_blocks = $sidebar_blocks; |
---|
| 354 | $_ctx->main_blocks = $main_blocks; |
---|
[2542] | 355 | |
---|
[0] | 356 | /* DISPLAY |
---|
| 357 | -------------------------------------------------------- */ |
---|
| 358 | $default_tab = 'edit-entry'; |
---|
| 359 | if (!$can_edit_post) { |
---|
| 360 | $default_tab = ''; |
---|
| 361 | } |
---|
| 362 | if (!empty($_GET['co'])) { |
---|
| 363 | $default_tab = 'comments'; |
---|
| 364 | } |
---|
[1414] | 365 | $page_title_edit = __('Edit entry'); |
---|
[1089] | 366 | $_ctx |
---|
[1414] | 367 | ->setBreadCrumb( |
---|
[1358] | 368 | array( |
---|
| 369 | html::escapeHTML($core->blog->name) => '', |
---|
| 370 | __('Entries') => 'posts.php', |
---|
[2166] | 371 | ($post_id ? $page_title_edit : $page_title) => '' |
---|
[1414] | 372 | )) |
---|
[1089] | 373 | ->default_tab = $default_tab; |
---|
[1493] | 374 | $_ctx->post_status = $form->post_status; |
---|
| 375 | $_ctx->post_title = $form->post_title; |
---|
| 376 | if ($form->post_status == 1) { |
---|
| 377 | $_ctx->post_url = $post->getURL(); |
---|
| 378 | } |
---|
[0] | 379 | |
---|
| 380 | if (!empty($_GET['upd'])) { |
---|
[1497] | 381 | $_ctx->setAlert(__('Entry has been successfully updated.')); |
---|
[0] | 382 | } |
---|
| 383 | elseif (!empty($_GET['crea'])) { |
---|
[1497] | 384 | $_ctx->setAlert(__('Entry has been successfully created.')); |
---|
[0] | 385 | } |
---|
| 386 | elseif (!empty($_GET['attached'])) { |
---|
[1497] | 387 | $_ctx->setAlert(__('File has been successfully attached.')); |
---|
[0] | 388 | } |
---|
| 389 | elseif (!empty($_GET['rmattach'])) { |
---|
[1497] | 390 | $_ctx->setAlert(__('Attachment has been successfully removed.')); |
---|
[0] | 391 | } |
---|
| 392 | if (!empty($_GET['creaco'])) { |
---|
[1497] | 393 | $_ctx->setAlert(__('Comment has been successfully created.')); |
---|
| 394 | } |
---|
[2390] | 395 | |
---|
[1056] | 396 | $core->tpl->display('post.html.twig'); |
---|
[1312] | 397 | ?> |
---|