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