auth->getOption('post_format'); $post_editor = $core->auth->getOption('editor'); $post_password = ''; $post_url = ''; $post_lang = $core->auth->getInfo('user_lang'); $post_title = ''; $post_excerpt = ''; $post_excerpt_xhtml = ''; $post_content = ''; $post_content_xhtml = ''; $post_notes = ''; $post_status = $core->auth->getInfo('user_post_status'); $post_selected = false; $post_open_comment = $core->blog->settings->system->allow_comments; $post_open_tb = $core->blog->settings->system->allow_trackbacks; $page_title = __('New entry'); $can_view_page = true; $can_edit_post = $core->auth->check('usage,contentadmin', $core->blog->id); $can_publish = $core->auth->check('publish,contentadmin', $core->blog->id); $can_delete = false; $post_headlink = ''; $post_link = '%s'; $next_link = $prev_link = $next_headlink = $prev_headlink = null; # If user can't publish if (!$can_publish) { $post_status = -2; } # Getting categories $categories_combo = dcAdminCombos::getCategoriesCombo( $core->blog->getCategories() ); $status_combo = dcAdminCombos::getPostStatusesCombo(); $img_status_pattern = ''; # Formats combo $core_formaters = $core->getFormaters(); $available_formats = ['' => '']; foreach ($core_formaters as $editor => $formats) { foreach ($formats as $format) { $available_formats[$format] = $format; } } # Languages combo $rs = $core->blog->getLangs(['order' => 'asc']); $lang_combo = dcAdminCombos::getLangsCombo($rs, true); # Validation flag $bad_dt = false; # Trackbacks $TB = new dcTrackback($core); $tb_urls = $tb_excerpt = ''; # Get entry informations if (!empty($_REQUEST['id'])) { $page_title = __('Edit entry'); $params['post_id'] = $_REQUEST['id']; $post = $core->blog->getPosts($params); if ($post->isEmpty()) { $core->error->add(__('This entry does not exist.')); $can_view_page = false; } else { $post_id = $post->post_id; $cat_id = $post->cat_id; $post_dt = date('Y-m-d H:i', strtotime($post->post_dt)); $post_format = $post->post_format; $post_password = $post->post_password; $post_url = $post->post_url; $post_lang = $post->post_lang; $post_title = $post->post_title; $post_excerpt = $post->post_excerpt; $post_excerpt_xhtml = $post->post_excerpt_xhtml; $post_content = $post->post_content; $post_content_xhtml = $post->post_content_xhtml; $post_notes = $post->post_notes; $post_status = $post->post_status; $post_selected = (boolean) $post->post_selected; $post_open_comment = (boolean) $post->post_open_comment; $post_open_tb = (boolean) $post->post_open_tb; $can_edit_post = $post->isEditable(); $can_delete = $post->isDeletable(); $next_rs = $core->blog->getNextPost($post, 1); $prev_rs = $core->blog->getNextPost($post, -1); if ($next_rs !== null) { $next_link = sprintf($post_link, $next_rs->post_id, html::escapeHTML($next_rs->post_title), __('Next entry') . ' »'); $next_headlink = sprintf($post_headlink, 'next', html::escapeHTML($next_rs->post_title), $next_rs->post_id); } if ($prev_rs !== null) { $prev_link = sprintf($post_link, $prev_rs->post_id, html::escapeHTML($prev_rs->post_title), '« ' . __('Previous entry')); $prev_headlink = sprintf($post_headlink, 'previous', html::escapeHTML($prev_rs->post_title), $prev_rs->post_id); } try { $core->media = new dcMedia($core); } catch (Exception $e) { $core->error->add($e->getMessage()); } # Sanitize trackbacks excerpt $tb_excerpt = empty($_POST['tb_excerpt']) ? $post_excerpt_xhtml . ' ' . $post_content_xhtml : $_POST['tb_excerpt']; $tb_excerpt = html::decodeEntities(html::clean($tb_excerpt)); $tb_excerpt = text::cutString(html::escapeHTML($tb_excerpt), 255); $tb_excerpt = preg_replace('/\s+/ms', ' ', $tb_excerpt); } } if (isset($_REQUEST['section']) && $_REQUEST['section'] == 'trackbacks') { $anchor = 'trackbacks'; } else { $anchor = 'comments'; } $comments_actions_page = new dcCommentsActionsPage($core, $core->adminurl->get('admin.post'), ['id' => $post_id, '_ANCHOR' => $anchor, 'section' => $anchor]); if ($comments_actions_page->process()) { return; } # Ping blogs if (!empty($_POST['ping'])) { if (!empty($_POST['tb_urls']) && $post_id && $post_status == 1 && $can_edit_post) { $tb_urls = $_POST['tb_urls']; $tb_urls = str_replace("\r", '', $tb_urls); $tb_post_title = html::escapeHTML(trim(html::clean($post_title))); $tb_post_url = $post->getURL(); foreach (explode("\n", $tb_urls) as $tb_url) { try { # --BEHAVIOR-- adminBeforePingTrackback $core->callBehavior('adminBeforePingTrackback', $tb_url, $post_id, $tb_post_title, $tb_excerpt, $tb_post_url); $TB->ping($tb_url, $post_id, $tb_post_title, $tb_excerpt, $tb_post_url); } catch (Exception $e) { $core->error->add($e->getMessage()); } } if (!$core->error->flag()) { dcPage::addSuccessNotice(__('All pings sent.')); $core->adminurl->redirect( 'admin.post', ['id' => $post_id, 'tb' => '1'] ); } } } # Format excerpt and content elseif (!empty($_POST) && $can_edit_post) { $post_format = $_POST['post_format']; $post_excerpt = $_POST['post_excerpt']; $post_content = $_POST['post_content']; $post_title = $_POST['post_title']; $cat_id = (integer) $_POST['cat_id']; if (isset($_POST['post_status'])) { $post_status = (integer) $_POST['post_status']; } if (empty($_POST['post_dt'])) { $post_dt = ''; } else { try { $post_dt = strtotime($_POST['post_dt']); if ($post_dt == false || $post_dt == -1) { $bad_dt = true; throw new Exception(__('Invalid publication date')); } $post_dt = date('Y-m-d H:i', $post_dt); } catch (Exception $e) { $core->error->add($e->getMessage()); } } $post_open_comment = !empty($_POST['post_open_comment']); $post_open_tb = !empty($_POST['post_open_tb']); $post_selected = !empty($_POST['post_selected']); $post_lang = $_POST['post_lang']; $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null; $post_notes = $_POST['post_notes']; if (isset($_POST['post_url'])) { $post_url = $_POST['post_url']; } $core->blog->setPostContent( $post_id, $post_format, $post_lang, $post_excerpt, $post_excerpt_xhtml, $post_content, $post_content_xhtml ); } # Delete post if (!empty($_POST['delete']) && $can_delete) { try { # --BEHAVIOR-- adminBeforePostDelete $core->callBehavior('adminBeforePostDelete', $post_id); $core->blog->delPost($post_id); $core->adminurl->redirect("admin.posts"); } catch (Exception $e) { $core->error->add($e->getMessage()); } } # Create or update post if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt) { # Create category if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { $cur_cat = $core->con->openCursor($core->prefix . 'category'); $cur_cat->cat_title = $_POST['new_cat_title']; $cur_cat->cat_url = ''; $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : ''; # --BEHAVIOR-- adminBeforeCategoryCreate $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat); # --BEHAVIOR-- adminAfterCategoryCreate $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id); } $cur = $core->con->openCursor($core->prefix . 'post'); $cur->post_title = $post_title; $cur->cat_id = ($cat_id ?: null); $cur->post_dt = $post_dt ? date('Y-m-d H:i:00', strtotime($post_dt)) : ''; $cur->post_format = $post_format; $cur->post_password = $post_password; $cur->post_lang = $post_lang; $cur->post_title = $post_title; $cur->post_excerpt = $post_excerpt; $cur->post_excerpt_xhtml = $post_excerpt_xhtml; $cur->post_content = $post_content; $cur->post_content_xhtml = $post_content_xhtml; $cur->post_notes = $post_notes; $cur->post_status = $post_status; $cur->post_selected = (integer) $post_selected; $cur->post_open_comment = (integer) $post_open_comment; $cur->post_open_tb = (integer) $post_open_tb; if (isset($_POST['post_url'])) { $cur->post_url = $post_url; } # Update post if ($post_id) { try { # --BEHAVIOR-- adminBeforePostUpdate $core->callBehavior('adminBeforePostUpdate', $cur, $post_id); $core->blog->updPost($post_id, $cur); # --BEHAVIOR-- adminAfterPostUpdate $core->callBehavior('adminAfterPostUpdate', $cur, $post_id); dcPage::addSuccessNotice(sprintf(__('The post "%s" has been successfully updated'), html::escapeHTML($cur->post_title))); $core->adminurl->redirect( 'admin.post', ['id' => $post_id] ); } catch (Exception $e) { $core->error->add($e->getMessage()); } } else { $cur->user_id = $core->auth->userID(); try { # --BEHAVIOR-- adminBeforePostCreate $core->callBehavior('adminBeforePostCreate', $cur); $return_id = $core->blog->addPost($cur); # --BEHAVIOR-- adminAfterPostCreate $core->callBehavior('adminAfterPostCreate', $cur, $return_id); dcPage::addSuccessNotice(__('Entry has been successfully created.')); $core->adminurl->redirect( 'admin.post', ['id' => $return_id] ); } catch (Exception $e) { $core->error->add($e->getMessage()); } } } # Getting categories $categories_combo = dcAdminCombos::getCategoriesCombo( $core->blog->getCategories() ); /* DISPLAY -------------------------------------------------------- */ $default_tab = 'edit-entry'; if (!$can_edit_post) { $default_tab = ''; } if (!empty($_GET['co'])) { $default_tab = 'comments'; } elseif (!empty($_GET['tb'])) { $default_tab = 'trackbacks'; } if ($post_id) { switch ($post_status) { case 1: $img_status = sprintf($img_status_pattern, __('Published'), 'check-on.png'); break; case 0: $img_status = sprintf($img_status_pattern, __('Unpublished'), 'check-off.png'); break; case -1: $img_status = sprintf($img_status_pattern, __('Scheduled'), 'scheduled.png'); break; case -2: $img_status = sprintf($img_status_pattern, __('Pending'), 'check-wrn.png'); break; default: $img_status = ''; } $edit_entry_str = __('“%s”'); $page_title_edit = sprintf($edit_entry_str, html::escapeHTML($post_title)) . ' ' . $img_status; } else { $img_status = ''; } $admin_post_behavior = ''; if ($post_editor) { $p_edit = $c_edit = ''; if (!empty($post_editor[$post_format])) { $p_edit = $post_editor[$post_format]; } if (!empty($post_editor['xhtml'])) { $c_edit = $post_editor['xhtml']; } if ($p_edit == $c_edit) { $admin_post_behavior .= $core->callBehavior('adminPostEditor', $p_edit, 'post', ['#post_excerpt', '#post_content', '#comment_content'], $post_format); } else { $admin_post_behavior .= $core->callBehavior('adminPostEditor', $p_edit, 'post', ['#post_excerpt', '#post_content'], $post_format); $admin_post_behavior .= $core->callBehavior('adminPostEditor', $c_edit, 'comment', ['#comment_content'], 'xhtml'); } } dcPage::open($page_title . ' - ' . __('Entries'), dcPage::jsDatePicker() . dcPage::jsModal() . dcPage::jsMetaEditor() . $admin_post_behavior . dcPage::jsLoad('js/_post.js') . dcPage::jsConfirmClose('entry-form', 'comment-form') . # --BEHAVIOR-- adminPostHeaders $core->callBehavior('adminPostHeaders') . dcPage::jsPageTabs($default_tab) . $next_headlink . "\n" . $prev_headlink, dcPage::breadcrumb( [ html::escapeHTML($core->blog->name) => '', __('Entries') => $core->adminurl->get("admin.posts"), ($post_id ? $page_title_edit : $page_title) => '' ]) , [ 'x-frame-allow' => $core->blog->url ] ); if (!empty($_GET['upd'])) { dcPage::success(__('Entry has been successfully updated.')); } elseif (!empty($_GET['crea'])) { dcPage::success(__('Entry has been successfully created.')); } elseif (!empty($_GET['attached'])) { dcPage::success(__('File has been successfully attached.')); } elseif (!empty($_GET['rmattach'])) { dcPage::success(__('Attachment has been successfully removed.')); } if (!empty($_GET['creaco'])) { dcPage::success(__('Comment has been successfully created.')); } if (!empty($_GET['tbsent'])) { dcPage::success(__('All pings sent.')); } # XHTML conversion if (!empty($_GET['xconv'])) { $post_excerpt = $post_excerpt_xhtml; $post_content = $post_content_xhtml; $post_format = 'xhtml'; dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.')); } if ($post_id && $post->post_status == 1) { echo '
' . __('Go to this entry on the site') . '
'; } if ($post_id) { echo ' '; } # Exit if we cannot view page if (!$can_view_page) { dcPage::helpBlock('core_post'); dcPage::close(); exit; } # Controls comments or trakbacks capabilities $isContributionAllowed = function ($id, $dt, $com = true) { global $core; if (!$id) { return true; } if ($com) { if (($core->blog->settings->system->comments_ttl == 0) || (time() - $core->blog->settings->system->comments_ttl * 86400 < $dt)) { return true; } } else { if (($core->blog->settings->system->trackbacks_ttl == 0) || (time() - $core->blog->settings->system->trackbacks_ttl * 86400 < $dt)) { return true; } } return false; }; # Show comments or trackbacks $showComments = function ($rs, $has_action, $tb = false) { global $core; echo '' . __('Author') . ' | ' . '' . __('Date') . ' | ' . '' . __('IP address') . ' | ' . '' . __('Status') . ' | ' . '' . __('Edit') . ' | ' . '|
---|---|---|---|---|---|
' . ($has_action ? form::checkbox(['comments[]'], $rs->comment_id, [ 'checked' => isset($comments[$rs->comment_id]), 'extra_html' => 'title="' . ($tb ? __('select this trackback') : __('select this comment') . '"') ] ) : '') . ' | ' . '' . html::escapeHTML($rs->comment_author) . ' | ' . '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $rs->comment_dt) . ' | ' . '$rs->comment_ip]) . '">' . $rs->comment_ip . ' | ' . '' . $img_status . ' | ' . '' . ' ' . __('Edit') . ' | ' . '
' . form::combo('post_status', $status_combo, ['default' => $post_status, 'class' => 'maximal', 'disabled' => !$can_publish]) . '
', 'post_dt' => '' . form::field('post_dt', 16, 16, $post_dt, ($bad_dt ? 'invalid' : '')) . /* Previous line will be replaced by this one as soon as every browser will support datetime-local input type Dont forget to remove call to datepicker in post.js form::datetime('post_dt', [ 'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', strtotime($post_dt))), 'class' => ($bad_dt ? 'invalid' : '') ]) . */ '
', 'post_lang' => '' . form::combo('post_lang', $lang_combo, $post_lang) . '
', 'post_format' => '' . form::combo('post_format', $available_formats, $post_format, 'maximal') . '
' . '' . '
' . form::combo('cat_id', $categories_combo, $cat_id, 'maximal') . '
' . ($core->auth->check('categories', $core->blog->id) ? '' . __('Warning: Comments are not more accepted for this entry.') . '
') : '' . __('Comments are not accepted on this blog so far.') . '
') . '' . ($core->blog->settings->system->allow_trackbacks ? ($isContributionAllowed($post_id, strtotime($post_dt), false) ? '' : '' . __('Warning: Trackbacks are not more accepted for this entry.') . '
') : '' . __('Trackbacks are not accepted on this blog so far.') . '
') . '' . form::field('post_password', 10, 32, html::escapeHTML($post_password), 'maximal') . '
', 'post_url' => '' . form::field('post_url', 10, 255, html::escapeHTML($post_url), 'maximal') . '
' . '' . __('Warning: If you set the URL manually, it may conflict with another entry.') . '
' . '' . form::field('post_title', 20, 255, [ 'default' => html::escapeHTML($post_title), 'class' => 'maximal', 'extra_html' => 'required placeholder="' . __('Title') . '" lang="' . $post_lang . '" spellcheck="true"' ]) . '
', "post_excerpt" => '' . form::textarea('post_excerpt', 50, 5, [ 'default' => html::escapeHTML($post_excerpt), 'extra_html' => 'lang="' . $post_lang . '" spellcheck="true"' ]) . '
', "post_content" => '' . form::textarea('post_content', 50, $core->auth->getOption('edit_size'), [ 'default' => html::escapeHTML($post_content), 'extra_html' => 'required placeholder="' . __('Content') . '" lang="' . $post_lang . '" spellcheck="true"' ]) . '
', "post_notes" => '' . form::textarea('post_notes', 50, 5, [ 'default' => html::escapeHTML($post_notes), 'extra_html' => 'lang="' . $post_lang . '" spellcheck="true"' ]) . '
' ] ); # --BEHAVIOR-- adminPostFormItems $core->callBehavior('adminPostFormItems', $main_items, $sidebar_items, isset($post) ? $post : null, 'post'); echo '
' . __('Add a comment') . '
'; if ($has_action) { echo ''; } /* Add a comment -------------------------------------------------------- */ echo '' . __('Add a comment') . '
' . '' . '