Changeset 1492:a7112dcc916c for admin/post.php
- Timestamp:
- 08/20/13 11:01:52 (12 years ago)
- Branch:
- twig
- Parents:
- 1491:2b9253624dbe (diff), 1486:602b24e80834 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/post.php
r1468 r1492 4 4 # This file is part of Dotclear 2. 5 5 # 6 # Copyright (c) 2003-201 3Olivier Meunier & Association Dotclear6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 7 7 # Licensed under the GPL version 2.0 license. 8 8 # See LICENSE file or … … 15 15 dcPage::check('usage,contentadmin'); 16 16 17 $post_id = ''; 18 $cat_id = ''; 19 $post_dt = ''; 20 $post_format = $core->auth->getOption('post_format'); 21 $post_password = ''; 22 $post_url = ''; 23 $post_lang = $core->auth->getInfo('user_lang'); 24 $post_title = ''; 25 $post_excerpt = ''; 26 $post_excerpt_xhtml = ''; 27 $post_content = ''; 28 $post_content_xhtml = ''; 29 $post_notes = ''; 30 $post_status = $core->auth->getInfo('user_post_status'); 31 $post_selected = false; 32 $post_open_comment = $core->blog->settings->system->allow_comments; 33 $post_open_tb = $core->blog->settings->system->allow_trackbacks; 17 class PostActions 18 { 19 public static function savePost($form) { 20 global $_ctx, $core; 21 try { 22 $form->check($_ctx); 23 $_ctx->setAlert('save'); 24 $form->cat_id = (integer) $form->cat_id; 25 26 if (!empty($form->post_dt)) { 27 try 28 { 29 $post_dt = strtotime($form->post_dt); 30 if ($post_dt == false || $post_dt == -1) { 31 $bad_dt = true; 32 throw new Exception(__('Invalid publication date')); 33 } 34 $form->post_dt = date('Y-m-d H:i',$post_dt); 35 } 36 catch (Exception $e) 37 { 38 $core->error->add($e->getMessage()); 39 } 40 } 41 $post_excerpt = $form->post_excerpt; 42 $post_content = $form->post_content; 43 $post_excerpt_xhtml = ''; 44 $post_content_xhtml = ''; 45 $core->blog->setPostContent( 46 $form->id,$form->post_format,$form->post_lang, 47 $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 48 ); 49 $form->post_excerpt = $post_excerpt; 50 $form->post_content = $post_content; 51 $form->post_excerpt_xhtml = $post_excerpt_xhtml; 52 $form->post_content_xhtml = $post_content_xhtml; 53 54 $cur = $core->con->openCursor($core->prefix.'post'); 55 56 $cur->post_title = $form->post_title; 57 $cur->cat_id = $form->cat_id ? $form->cat_id : null; 58 $cur->post_dt = $form->post_dt ? date('Y-m-d H:i:00',strtotime($form->post_dt)) : ''; 59 $cur->post_format = $form->post_format; 60 $cur->post_password = $form->post_password; 61 $cur->post_lang = $form->post_lang; 62 $cur->post_title = $form->post_title; 63 $cur->post_excerpt = $form->post_excerpt; 64 $cur->post_excerpt_xhtml = $form->post_excerpt_xhtml; 65 $cur->post_content = $form->post_content; 66 $cur->post_content_xhtml = $form->post_content_xhtml; 67 $cur->post_notes = $form->post_notes; 68 $cur->post_status = $form->post_status; 69 $cur->post_selected = (integer) $form->post_selected; 70 $cur->post_open_comment = (integer) $form->post_open_comment; 71 $cur->post_open_tb = (integer) $form->post_open_tb; 72 73 if (!empty($form->post_url)) { 74 $cur->post_url = $form->post_url; 75 } 76 77 # Update post 78 if ($form->id) 79 { 80 # --BEHAVIOR-- adminBeforePostUpdate 81 $core->callBehavior('adminBeforePostUpdate',$cur,$form->id); 82 83 $core->blog->updPost($form->id,$cur); 84 85 # --BEHAVIOR-- adminAfterPostUpdate 86 $core->callBehavior('adminAfterPostUpdate',$cur,$form->id); 87 88 http::redirect('post.php?id='.$form->id.'&upd=1'); 89 } 90 else 91 { 92 $cur->user_id = $core->auth->userID(); 93 # --BEHAVIOR-- adminBeforePostCreate 94 $core->callBehavior('adminBeforePostCreate',$cur); 95 96 $return_id = $core->blog->addPost($cur); 97 98 # --BEHAVIOR-- adminAfterPostCreate 99 $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 100 101 http::redirect('post.php?id='.$return_id.'&crea=1'); 102 } 103 104 } catch (Exception $e) { 105 $ctx->setError($e->getMessage()); 106 } 107 } 108 function deletePost($form) { 109 echo $form->id->getValue(); exit; 110 } 111 } 34 112 35 113 $page_title = __('New entry'); 36 114 $post_id=''; 37 115 $can_view_page = true; 38 116 $can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id); … … 47 125 # If user can't publish 48 126 if (!$can_publish) { 49 $ post_status = -2;127 $form->post_status = -2; 50 128 } 51 129 … … 55 133 $categories = $core->blog->getCategories(array('post_type'=>'post')); 56 134 while ($categories->fetch()) { 57 $categories_combo[ ] = new formSelectOption(58 str_repeat(' ',$categories->level-1). ($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title),59 $categories->cat_id60 );135 $categories_combo[$categories->cat_id] = 136 str_repeat(' ',$categories->level-1). 137 ($categories->level-1 == 0 ? '' : '• '). 138 html::escapeHTML($categories->cat_title); 61 139 } 62 140 } catch (Exception $e) { } … … 64 142 # Status combo 65 143 foreach ($core->blog->getAllPostStatus() as $k => $v) { 66 $status_combo[$v] = (string) $k; 67 } 68 $img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />'; 144 $status_combo[$k] = $v; 145 } 69 146 70 147 # Formaters combo … … 76 153 $rs = $core->blog->getLangs(array('order'=>'asc')); 77 154 $all_langs = l10n::getISOcodes(0,1); 78 $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes( 1,1));155 $lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(0,1)); 79 156 while ($rs->fetch()) { 80 157 if (isset($all_langs[$rs->post_lang])) { 81 $lang_combo[__('Most used')][$ all_langs[$rs->post_lang]] = $rs->post_lang;82 unset($lang_combo[__('Available')][$ all_langs[$rs->post_lang]]);158 $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 159 unset($lang_combo[__('Available')][$rs->post_lang]); 83 160 } else { 84 $lang_combo[__('Most used')][$rs->post_lang] = $ rs->post_lang;161 $lang_combo[__('Most used')][$rs->post_lang] = $all_langs[$rs->post_lang]; 85 162 } 86 163 } … … 88 165 unset($rs); 89 166 90 # Validation flag 91 $bad_dt = false; 92 167 $form = new dcForm($core,'post','post.php'); 168 $form 169 ->addField( 170 new dcFieldText('post_title','', array( 171 'maxlength' => 255, 172 'required' => true, 173 'label' => __('Title')))) 174 ->addField( 175 new dcFieldTextArea('post_excerpt','', array( 176 'cols' => 50, 177 'rows' => 5, 178 'label' => __("Excerpt:")))) 179 ->addField( 180 new dcFieldTextArea('post_content','', array( 181 'required' => true, 182 'label' => __("Content:")))) 183 ->addField( 184 new dcFieldTextArea('post_notes','', array( 185 'label' => __("Notes")))) 186 ->addField( 187 new dcFieldSubmit('save',__('Save'),array( 188 'action' => array('PostActions','savePost')))) 189 ->addField( 190 new dcFieldSubmit('delete',__('Delete'),array( 191 'action' => 'deletePost'))) 192 ->addField( 193 new dcFieldCombo('post_status',$core->auth->getInfo('user_post_status'),$status_combo,array( 194 'disabled' => !$can_publish, 195 'label' => __('Entry status')))) 196 ->addField( 197 new dcFieldCombo('cat_id','',$categories_combo,array( 198 "label" => __('Category')))) 199 ->addField( 200 new dcFieldCombo('new_cat_parent','',$categories_combo,array( 201 "label" => __('Parent:')))) 202 ->addField( 203 new dcFieldText('new_cat_title','', array( 204 'maxlength' => 255, 205 'label' => __('Title')))) 206 207 ->addField( 208 new dcFieldText('post_dt','',array( 209 "label" => __('Publication date and hour')))) 210 ->addField( 211 new dcFieldCombo('post_format',$core->auth->getOption('post_format'),$formaters_combo,array( 212 "label" => __('Text formating')))) 213 ->addField( 214 new dcFieldCheckbox ('post_open_comment',$core->blog->settings->system->allow_comments,array( 215 "label" => __('Accept comments')))) 216 ->addField( 217 new dcFieldCheckbox ('post_open_tb',$core->blog->settings->system->allow_trackbacks,array( 218 "label" => __('Accept trackbacks')))) 219 ->addField( 220 new dcFieldCheckbox ('post_selected',array(1=>false),array( 221 "label" => __('Selected entry')))) 222 ->addField( 223 new dcFieldCombo ('post_lang',$core->auth->getInfo('user_lang'),$lang_combo, array( 224 "label" => __('Entry lang:')))) 225 ->addField( 226 new dcFieldText('post_password','',array( 227 "maxlength" => 32, 228 "label" => __('Entry password:')))) 229 ->addField( 230 new dcFieldText('post_url','',array( 231 "maxlength" => 255, 232 "label" => __('Basename:')))) 233 ->addField( 234 new dcFieldHidden ('id','')) 235 ; 93 236 # Get entry informations 94 237 if (!empty($_REQUEST['id'])) 95 238 { 96 $page_title = __('Edit entry');97 98 239 $params['post_id'] = $_REQUEST['id']; 99 240 … … 107 248 else 108 249 { 109 $post_id = $post->post_id; 110 $cat_id = $post->cat_id; 111 $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 112 $post_format = $post->post_format; 113 $post_password = $post->post_password; 114 $post_url = $post->post_url; 115 $post_lang = $post->post_lang; 116 $post_title = $post->post_title; 117 $post_excerpt = $post->post_excerpt; 118 $post_excerpt_xhtml = $post->post_excerpt_xhtml; 119 $post_content = $post->post_content; 120 $post_content_xhtml = $post->post_content_xhtml; 121 $post_notes = $post->post_notes; 122 $post_status = $post->post_status; 123 $post_selected = (boolean) $post->post_selected; 124 $post_open_comment = (boolean) $post->post_open_comment; 125 $post_open_tb = (boolean) $post->post_open_tb; 250 $form->id = $post_id = $post->post_id; 251 $form->cat_id = $post->cat_id; 252 $form->post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 253 $form->post_format = $post->post_format; 254 $form->post_password = $post->post_password; 255 $form->post_url = $post->post_url; 256 $form->post_lang = $post->post_lang; 257 $form->post_title = $post->post_title; 258 $form->post_excerpt = $post->post_excerpt; 259 $form->post_excerpt_xhtml = $post->post_excerpt_xhtml; 260 $form->post_content = $post->post_content; 261 $form->post_content_xhtml = $post->post_content_xhtml; 262 $form->post_notes = $post->post_notes; 263 $form->post_status = $post->post_status; 264 $form->post_selected = (boolean) $post->post_selected; 265 $form->post_open_comment = (boolean) $post->post_open_comment; 266 $form->post_open_tb = (boolean) $post->post_open_tb; 267 $form->can_edit_post = $post->isEditable(); 268 $form->can_delete= $post->isDeletable(); 269 $page_title = __('Edit entry'); 270 271 } 272 } 273 if ($post_id) { 274 $_ctx->post_id = $post->post_id; 275 276 $_ctx->preview_url = 277 $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 278 http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 279 '/'.$post->post_url); 126 280 127 $can_edit_post = $post->isEditable(); 128 $can_delete= $post->isDeletable(); 129 130 $next_rs = $core->blog->getNextPost($post,1); 131 $prev_rs = $core->blog->getNextPost($post,-1); 132 133 if ($next_rs !== null) { 134 $next_link = sprintf($post_link,$next_rs->post_id, 135 html::escapeHTML($next_rs->post_title),__('Next entry').' »'); 136 $next_headlink = sprintf($post_headlink,'next', 137 html::escapeHTML($next_rs->post_title),$next_rs->post_id); 138 } 139 140 if ($prev_rs !== null) { 141 $prev_link = sprintf($post_link,$prev_rs->post_id, 142 html::escapeHTML($prev_rs->post_title),'« '.__('Previous entry')); 143 $prev_headlink = sprintf($post_headlink,'previous', 144 html::escapeHTML($prev_rs->post_title),$prev_rs->post_id); 145 } 146 147 try { 148 $core->media = new dcMedia($core); 149 } catch (Exception $e) {} 150 } 151 } 152 153 # Format excerpt and content 154 if (!empty($_POST) && $can_edit_post) 155 { 156 $post_format = $_POST['post_format']; 157 $post_excerpt = $_POST['post_excerpt']; 158 $post_content = $_POST['post_content']; 159 160 $post_title = $_POST['post_title']; 161 162 $cat_id = (integer) $_POST['cat_id']; 163 164 if (isset($_POST['post_status'])) { 165 $post_status = (integer) $_POST['post_status']; 166 } 167 168 if (empty($_POST['post_dt'])) { 169 $post_dt = ''; 170 } else { 171 try 172 { 173 $post_dt = strtotime($_POST['post_dt']); 174 if ($post_dt == false || $post_dt == -1) { 175 $bad_dt = true; 176 throw new Exception(__('Invalid publication date')); 177 } 178 $post_dt = date('Y-m-d H:i',$post_dt); 179 } 180 catch (Exception $e) 181 { 182 $core->error->add($e->getMessage()); 183 } 184 } 185 186 $post_open_comment = !empty($_POST['post_open_comment']); 187 $post_open_tb = !empty($_POST['post_open_tb']); 188 $post_selected = !empty($_POST['post_selected']); 189 $post_lang = $_POST['post_lang']; 190 $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; 191 192 $post_notes = $_POST['post_notes']; 193 194 if (isset($_POST['post_url'])) { 195 $post_url = $_POST['post_url']; 196 } 197 198 $core->blog->setPostContent( 199 $post_id,$post_format,$post_lang, 200 $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml 201 ); 202 } 203 204 # Delete post 205 if (!empty($_POST['delete']) && $can_delete) 206 { 207 try { 208 # --BEHAVIOR-- adminBeforePostDelete 209 $core->callBehavior('adminBeforePostDelete',$post_id); 210 $core->blog->delPost($post_id); 211 http::redirect('posts.php'); 212 } catch (Exception $e) { 213 $core->error->add($e->getMessage()); 214 } 215 } 216 217 # Create or update post 218 if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt) 219 { 220 # Create category 221 if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { 222 223 $cur_cat = $core->con->openCursor($core->prefix.'category'); 224 $cur_cat->cat_title = $_POST['new_cat_title']; 225 $cur_cat->cat_url = ''; 226 227 $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; 228 229 # --BEHAVIOR-- adminBeforeCategoryCreate 230 $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); 231 232 $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); 233 234 # --BEHAVIOR-- adminAfterCategoryCreate 235 $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id); 236 } 237 238 $cur = $core->con->openCursor($core->prefix.'post'); 239 240 $cur->post_title = $post_title; 241 $cur->cat_id = ($cat_id ? $cat_id : null); 242 $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 243 $cur->post_format = $post_format; 244 $cur->post_password = $post_password; 245 $cur->post_lang = $post_lang; 246 $cur->post_title = $post_title; 247 $cur->post_excerpt = $post_excerpt; 248 $cur->post_excerpt_xhtml = $post_excerpt_xhtml; 249 $cur->post_content = $post_content; 250 $cur->post_content_xhtml = $post_content_xhtml; 251 $cur->post_notes = $post_notes; 252 $cur->post_status = $post_status; 253 $cur->post_selected = (integer) $post_selected; 254 $cur->post_open_comment = (integer) $post_open_comment; 255 $cur->post_open_tb = (integer) $post_open_tb; 256 257 if (isset($_POST['post_url'])) { 258 $cur->post_url = $post_url; 259 } 260 261 # Update post 262 if ($post_id) 263 { 264 try 265 { 266 # --BEHAVIOR-- adminBeforePostUpdate 267 $core->callBehavior('adminBeforePostUpdate',$cur,$post_id); 268 269 $core->blog->updPost($post_id,$cur); 270 271 # --BEHAVIOR-- adminAfterPostUpdate 272 $core->callBehavior('adminAfterPostUpdate',$cur,$post_id); 273 274 http::redirect('post.php?id='.$post_id.'&upd=1'); 275 } 276 catch (Exception $e) 277 { 278 $core->error->add($e->getMessage()); 279 } 280 } 281 else 282 { 283 $cur->user_id = $core->auth->userID(); 284 285 try 286 { 287 # --BEHAVIOR-- adminBeforePostCreate 288 $core->callBehavior('adminBeforePostCreate',$cur); 289 290 $return_id = $core->blog->addPost($cur); 291 292 # --BEHAVIOR-- adminAfterPostCreate 293 $core->callBehavior('adminAfterPostCreate',$cur,$return_id); 294 295 http::redirect('post.php?id='.$return_id.'&crea=1'); 296 } 297 catch (Exception $e) 298 { 299 $core->error->add($e->getMessage()); 300 } 301 } 302 } 303 304 # Getting categories 305 $categories_combo = array(__('(No cat)') => ''); 306 try { 307 $categories = $core->blog->getCategories(array('post_type'=>'post')); 308 if (!$categories->isEmpty()) { 309 while ($categories->fetch()) { 310 $catparents_combo[] = $categories_combo[] = new formSelectOption( 311 str_repeat(' ',$categories->level-1).($categories->level-1 == 0 ? '' : '• ').html::escapeHTML($categories->cat_title), 312 $categories->cat_id 313 ); 314 } 315 } 316 } catch (Exception $e) { } 281 282 $form_comment = new dcForm($core,'add-comment','post.php'); 283 $form_comment 284 ->addField( 285 new dcFieldText('comment_author','', array( 286 'maxlength' => 255, 287 'required' => true, 288 'label' => __('Name:')))) 289 ->addField( 290 new dcFieldText('comment_email','', array( 291 'maxlength' => 255, 292 'required' => true, 293 'label' => __('Email:')))) 294 ->addField( 295 new dcFieldText('comment_site','', array( 296 'maxlength' => 255, 297 'label' => __('Web site:')))) 298 ->addField( 299 new dcFieldTextArea('comment_content','', array( 300 'required' => true, 301 'label' => __('Comment:')))) 302 ->addField( 303 new dcFieldSubmit('add',__('Save'),array( 304 'action' => 'addComment'))) 305 ; 306 307 308 } 309 310 $form->setup(); 311 312 $sidebar_blocks = new ArrayObject(array( 313 'status-box' => array( 314 'title' => __('Status'), 315 'items' => array('post_status','post_dt','post_lang','post_format')), 316 'metas-box' => array( 317 'title' => __('Ordering'), 318 'items' => array('post_selected','cat_id')), 319 'options-box' => array( 320 'title' => __('Options'), 321 'items' => array('post_open_comment','post_open_tb','post_password','post_url')) 322 )); 323 324 $main_blocks = new ArrayObject(array( 325 "post_title","post_excerpt","post_content","post_notes" 326 )); 327 328 329 $_ctx->sidebar_blocks = $sidebar_blocks; 330 $_ctx->main_blocks = $main_blocks; 317 331 318 332 /* DISPLAY … … 325 339 $default_tab = 'comments'; 326 340 } 327 328 if ($post_id) { 329 switch ($post_status) { 330 case 1: 331 $img_status = sprintf($img_status_pattern,__('Published'),'check-on.png'); 332 break; 333 case 0: 334 $img_status = sprintf($img_status_pattern,__('Unpublished'),'check-off.png'); 335 break; 336 case -1: 337 $img_status = sprintf($img_status_pattern,__('Scheduled'),'scheduled.png'); 338 break; 339 case -2: 340 $img_status = sprintf($img_status_pattern,__('Pending'),'check-wrn.png'); 341 break; 342 default: 343 $img_status = ''; 344 } 345 $edit_entry_str = __('“%s”'); 346 $page_title_edit = sprintf($edit_entry_str, html::escapeHTML($post_title)).' '.$img_status; 347 } else { 348 $img_status = ''; 349 } 350 351 352 dcPage::open($page_title.' - '.__('Entries'), 353 dcPage::jsDatePicker(). 354 dcPage::jsToolBar(). 355 dcPage::jsModal(). 356 dcPage::jsMetaEditor(). 357 dcPage::jsLoad('js/_post.js'). 358 dcPage::jsConfirmClose('entry-form','comment-form'). 359 # --BEHAVIOR-- adminPostHeaders 360 $core->callBehavior('adminPostHeaders'). 361 dcPage::jsPageTabs($default_tab). 362 $next_headlink."\n".$prev_headlink, 363 dcPage::breadcrumb( 341 $page_title_edit = __('Edit entry'); 342 $_ctx 343 ->setBreadCrumb( 364 344 array( 365 345 html::escapeHTML($core->blog->name) => '', 366 346 __('Entries') => 'posts.php', 367 '<span class="page-title">'.($post_id ? $page_title_edit : $page_title).'</span>' => '' 368 )) 369 ); 370 371 if (!empty($_GET['upd'])) { 372 dcPage::message(__('Entry has been successfully updated.')); 373 } 374 elseif (!empty($_GET['crea'])) { 375 dcPage::message(__('Entry has been successfully created.')); 376 } 377 elseif (!empty($_GET['attached'])) { 378 dcPage::message(__('File has been successfully attached.')); 379 } 380 elseif (!empty($_GET['rmattach'])) { 381 dcPage::message(__('Attachment has been successfully removed.')); 382 } 383 384 if (!empty($_GET['creaco'])) { 385 dcPage::message(__('Comment has been successfully created.')); 386 } 387 388 # XHTML conversion 389 if (!empty($_GET['xconv'])) 390 { 391 $post_excerpt = $post_excerpt_xhtml; 392 $post_content = $post_content_xhtml; 393 $post_format = 'xhtml'; 394 395 dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.')); 396 } 397 398 if ($post_id && $post->post_status == 1) { 399 echo '<p><a class="onblog_link" href="'.$post->getURL().'" onclick="window.open(this.href);return false;" title="'.$post_title.' ('.__('new window').')'.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>'; 400 } 401 if ($post_id) 402 { 403 echo '<p class="nav_prevnext">'; 404 if ($prev_link) { echo $prev_link; } 405 if ($next_link && $prev_link) { echo ' | '; } 406 if ($next_link) { echo $next_link; } 407 408 # --BEHAVIOR-- adminPostNavLinks 409 $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null); 410 411 echo '</p>'; 412 } 413 414 # Exit if we cannot view page 415 if (!$can_view_page) { 416 dcPage::helpBlock('core_post'); 417 dcPage::close(); 418 exit; 419 } 420 /* Post form if we can edit post 421 -------------------------------------------------------- */ 422 if ($can_edit_post) 423 { 424 $sidebar_items = new ArrayObject(array( 425 'status-box' => array( 426 'title' => __('Status'), 427 'items' => array( 428 'post_status' => 429 '<p class="entry-status"><label for="post_status" class="ib">'.__('Entry status').' '.$img_status.'</label>'. 430 form::combo('post_status',$status_combo,$post_status,'maximal','',!$can_publish). 431 '</p>', 432 'post_dt' => 433 '<p><label for="post_dt" class="ib">'.__('Publication date and hour').'</label>'. 434 form::field('post_dt',16,16,$post_dt,($bad_dt ? 'invalid' : '')). 435 '</p>', 436 'post_lang' => 437 '<p><label for="post_lang" class="ib">'.__('Entry lang').'</label>'. 438 form::combo('post_lang',$lang_combo,$post_lang). 439 '</p>', 440 'post_format' => 441 '<p><label for="post_format" class="ib">'.__('Text formating').'</label>'. 442 form::combo('post_format',$formaters_combo,$post_format,'maximal'). 443 '</p>'. 444 '<p>'.($post_id && $post_format != 'xhtml' ? 445 '<a id="convert-xhtml" class="button maximal" href="post.php?id='.$post_id.'&xconv=1">'. 446 __('Convert to XHTML').'</a>' : '').'</p>')), 447 'metas-box' => array( 448 'title' => __('Ordering'), 449 'items' => array( 450 'post_selected' => 451 '<p><label for="post_selected" class="classic">'. 452 form::checkbox('post_selected',1,$post_selected).' '. 453 __('Selected entry').'</label></p>', 454 'cat_id' => 455 '<p><label for="cat_id" class="ib">'.__('Category').'</label>'. 456 form::combo('cat_id',$categories_combo,$cat_id,'maximal'). 457 '</p>'. 458 ($core->auth->check('categories', $core->blog->id) ? 459 '<div>'. 460 '<p id="new_cat">'.__('Add a new category').'</p>'. 461 '<p><label for="new_cat_title">'.__('Title:').' '. 462 form::field('new_cat_title',30,255,'','maximal').'</label></p>'. 463 '<p><label for="new_cat_parent">'.__('Parent:').' '. 464 form::combo('new_cat_parent',$categories_combo,'','maximal'). 465 '</label></p>'. 466 '</div>' 467 : ''))), 468 'options-box' => array( 469 'title' => __('Options'), 470 'items' => array( 471 'post_open_comment' => 472 '<p><label for="post_open_comment" class="classic">'. 473 form::checkbox('post_open_comment',1,$post_open_comment).' '. 474 __('Accept comments').'</label></p>'. 475 ($core->blog->settings->system->allow_comments ? 476 (isContributionAllowed($post_id,strtotime($post_dt),true) ? 477 '' : 478 '<p class="form-note warn">'. 479 __('Warning: Comments are not more accepted for this entry.').'</p>') : 480 '<p class="form-note warn">'. 481 __('Warning: Comments are not accepted on this blog.').'</p>'), 482 'post_open_tb' => 483 '<p><label for="post_open_tb" class="classic">'. 484 form::checkbox('post_open_tb',1,$post_open_tb).' '. 485 __('Accept trackbacks').'</label></p>'. 486 ($core->blog->settings->system->allow_trackbacks ? 487 (isContributionAllowed($post_id,strtotime($post_dt),false) ? 488 '' : 489 '<p class="form-note warn">'. 490 __('Warning: Trackbacks are not more accepted for this entry.').'</p>') : 491 '<p class="form-note warn">'.__('Warning: Trackbacks are not accepted on this blog.').'</p>'), 492 'post_password' => 493 '<p><label for="post_password" class="ib">'.__('Password').'</label>'. 494 form::field('post_password',10,32,html::escapeHTML($post_password),'maximal'). 495 '</p>', 496 'post_url' => 497 '<div class="lockable">'. 498 '<p><label for="post_url" class="ib">'.__('Edit basename').'</label>'. 499 form::field('post_url',10,255,html::escapeHTML($post_url),'maximal'). 500 '</p>'. 501 '<p class="form-note warn">'. 502 __('Warning: If you set the URL manually, it may conflict with another entry.'). 503 '</p></div>' 504 )))); 505 506 $main_items = new ArrayObject(array( 507 "post_title" => 508 '<p class="col">'. 509 '<label class="required no-margin"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'. 510 form::field('post_title',20,255,html::escapeHTML($post_title),'maximal'). 511 '</p>', 512 513 "post_excerpt" => 514 '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'<span class="form-note">'. 515 __('Add an introduction to the post.').'</span></label> '. 516 form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)). 517 '</p>', 518 519 "post_content" => 520 '<p class="area"><label class="required" '. 521 'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '. 522 form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)). 523 '</p>', 524 525 "post_notes" => 526 '<p class="area" id="notes-area"><label for="post_notes">'.__('Personal notes:').'<span class="form-note">'. 527 __('Add unpublished notes.').'</span></label>'. 528 form::textarea('post_notes',50,5,html::escapeHTML($post_notes)). 529 '</p>' 530 ) 531 ); 532 533 # --BEHAVIOR-- adminPostFormItems 534 $core->callBehavior('adminPostFormItems',$main_items,$sidebar_items, isset($post) ? $post : null); 535 536 echo '<div class="multi-part" title="'.($post_id ? __('Edit entry') : __('New entry')).'" id="edit-entry">'; 537 echo '<form action="post.php" method="post" id="entry-form">'; 538 echo '<div id="entry-wrapper">'; 539 echo '<div id="entry-content"><div class="constrained">'; 540 541 echo '<h3 class="hidden">'.__('Edit post').'</h3>'; 542 543 foreach ($main_items as $id => $item) { 544 echo $item; 545 } 546 547 # --BEHAVIOR-- adminPostForm (may be deprecated) 548 $core->callBehavior('adminPostForm',isset($post) ? $post : null); 549 550 echo 551 '<p class="border-top">'. 552 ($post_id ? form::hidden('id',$post_id) : ''). 553 '<input type="submit" value="'.__('Save').' (s)" '. 554 'accesskey="s" name="save" /> '; 555 if ($post_id) { 556 $preview_url = 557 $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'. 558 http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')). 559 '/'.$post->post_url); 560 echo '<a id="post-preview" href="'.$preview_url.'" class="button" accesskey="p">'.__('Preview').' (p)'.'</a> '; 561 } else { 562 echo 563 '<a id="post-cancel" href="index.php" class="button" accesskey="c">'.__('Cancel').' (c)</a>'; 564 } 565 566 echo 567 ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : ''). 568 $core->formNonce(). 569 '</p>'; 570 571 echo '</div></div>'; // End #entry-content 572 echo '</div>'; // End #entry-wrapper 573 574 echo '<div id="entry-sidebar">'; 575 576 foreach ($sidebar_items as $id => $c) { 577 echo '<div id="'.$id.'" class="box">'. 578 '<h4>'.$c['title'].'</h4>'; 579 foreach ($c['items'] as $e_name=>$e_content) { 580 echo $e_content; 581 } 582 echo '</div>'; 583 } 584 585 586 # --BEHAVIOR-- adminPostFormSidebar (may be deprecated) 587 $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null); 588 echo '</div>'; // End #entry-sidebar 589 590 echo '</form>'; 591 592 # --BEHAVIOR-- adminPostForm 593 $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null); 594 595 echo '</div>'; 596 597 if ($post_id && $post->post_status == 1) { 598 echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'. 599 __('Ping blogs').'</a></p>'; 600 } 601 602 } 603 604 605 /* Comments and trackbacks 606 -------------------------------------------------------- */ 607 if ($post_id) 608 { 609 $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC'); 610 611 $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0))); 612 $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1))); 613 614 # Actions combo box 615 $combo_action = array(); 616 if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id)) 617 { 618 $combo_action[__('Publish')] = 'publish'; 619 $combo_action[__('Unpublish')] = 'unpublish'; 620 $combo_action[__('Mark as pending')] = 'pending'; 621 $combo_action[__('Mark as junk')] = 'junk'; 622 } 623 624 if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id)) 625 { 626 $combo_action[__('Delete')] = 'delete'; 627 } 628 629 # --BEHAVIOR-- adminCommentsActionsCombo 630 $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action)); 631 632 $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty()); 633 634 echo 635 '<div id="comments" class="multi-part" title="'.__('Comments').'">'; 636 637 if ($has_action) { 638 echo '<form action="comments_actions.php" id="form-comments" method="post">'; 639 } 640 641 echo '<h3>'.__('Trackbacks').'</h3>'; 642 643 if (!$trackbacks->isEmpty()) { 644 showComments($trackbacks,$has_action,true); 645 } else { 646 echo '<p>'.__('No trackback').'</p>'; 647 } 648 649 echo '<h3>'.__('Comments').'</h3>'; 650 if (!$comments->isEmpty()) { 651 showComments($comments,$has_action); 652 } else { 653 echo '<p>'.__('No comment').'</p>'; 654 } 655 656 if ($has_action) { 657 echo 658 '<div class="two-cols">'. 659 '<p class="col checkboxes-helpers"></p>'. 660 661 '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '. 662 form::combo('action',$combo_action). 663 form::hidden('redir','post.php?id='.$post_id.'&co=1'). 664 $core->formNonce(). 665 '<input type="submit" value="'.__('ok').'" /></p>'. 666 '</div>'. 667 '</form>'; 668 } 669 670 echo '</div>'; 671 } 672 673 /* Add a comment 674 -------------------------------------------------------- */ 675 if ($post_id) 676 { 677 echo 678 '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'. 679 '<h3>'.__('Add a comment').'</h3>'. 680 681 '<form action="comment.php" method="post" id="comment-form">'. 682 '<div class="constrained">'. 683 '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').'</label>'. 684 form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))). 685 '</p>'. 686 687 '<p><label for="comment_email">'.__('Email:').'</label>'. 688 form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))). 689 '</p>'. 690 691 '<p><label for="comment_site">'.__('Web site:').'</label>'. 692 form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))). 693 '</p>'. 694 695 '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '. 696 __('Comment:').'</label> '. 697 form::textarea('comment_content',50,8,html::escapeHTML('')). 698 '</p>'. 699 700 '<p>'.form::hidden('post_id',$post_id). 701 $core->formNonce(). 702 '<input type="submit" name="add" value="'.__('Save').'" /></p>'. 703 '</div>'. 704 '</form>'. 705 '</div>'; 706 } 707 708 # Controls comments or trakbacks capabilities 709 function isContributionAllowed($id,$dt,$com=true) 710 { 711 global $core; 712 713 if (!$id) { 714 return true; 715 } 716 if ($com) { 717 if (($core->blog->settings->system->comments_ttl == 0) || 718 (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) { 719 return true; 720 } 721 } else { 722 if (($core->blog->settings->system->trackbacks_ttl == 0) || 723 (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) { 724 return true; 725 } 726 } 727 return false; 728 } 729 730 # Show comments or trackbacks 731 function showComments($rs,$has_action,$tb=false) 732 { 733 echo 734 '<table class="comments-list"><tr>'. 735 '<th colspan="2">'.__('Author').'</th>'. 736 '<th>'.__('Date').'</th>'. 737 '<th class="nowrap">'.__('IP address').'</th>'. 738 '<th>'.__('Status').'</th>'. 739 '<th> </th>'. 740 '</tr>'; 741 742 while($rs->fetch()) 743 { 744 $comment_url = 'comment.php?id='.$rs->comment_id; 745 746 $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 747 switch ($rs->comment_status) { 748 case 1: 749 $img_status = sprintf($img,__('Published'),'check-on.png'); 750 break; 751 case 0: 752 $img_status = sprintf($img,__('Unpublished'),'check-off.png'); 753 break; 754 case -1: 755 $img_status = sprintf($img,__('Pending'),'check-wrn.png'); 756 break; 757 case -2: 758 $img_status = sprintf($img,__('Junk'),'junk.png'); 759 break; 760 } 761 762 echo 763 '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'. 764 ' id="c'.$rs->comment_id.'">'. 765 766 '<td class="nowrap">'. 767 ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'. 768 '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'. 769 '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'. 770 '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'. 771 '<td class="nowrap status">'.$img_status.'</td>'. 772 '<td class="nowrap status"><a href="'.$comment_url.'">'. 773 '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /></a></td>'. 774 775 '</tr>'; 776 } 777 778 echo '</table>'; 779 } 780 781 dcPage::helpBlock('core_post','core_trackbacks','core_wiki'); 782 dcPage::close(); 347 ($post_id ? $page_title_edit : $page_title) => '' 348 )) 349 ->default_tab = $default_tab; 350 351 352 353 $core->tpl->display('post.html.twig'); 783 354 ?>
Note: See TracChangeset
for help on using the changeset viewer.