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