Dotclear

source: admin/post.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 34.0 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

RevLine 
[0]1<?php
[3731]2/**
3 * @package Dotclear
4 * @subpackage Backend
5 *
6 * @copyright Olivier Meunier & Association Dotclear
7 * @copyright GPL-2.0-only
8 */
[0]9
[3703]10require dirname(__FILE__) . '/../inc/admin/prepend.php';
[0]11
12dcPage::check('usage,contentadmin');
13
[3703]14$post_id            = '';
15$cat_id             = '';
16$post_dt            = '';
17$post_format        = $core->auth->getOption('post_format');
18$post_editor        = $core->auth->getOption('editor');
19$post_password      = '';
20$post_url           = '';
21$post_lang          = $core->auth->getInfo('user_lang');
22$post_title         = '';
23$post_excerpt       = '';
[0]24$post_excerpt_xhtml = '';
[3703]25$post_content       = '';
[0]26$post_content_xhtml = '';
[3703]27$post_notes         = '';
28$post_status        = $core->auth->getInfo('user_post_status');
29$post_selected      = false;
30$post_open_comment  = $core->blog->settings->system->allow_comments;
31$post_open_tb       = $core->blog->settings->system->allow_trackbacks;
[0]32
[195]33$page_title = __('New entry');
[0]34
35$can_view_page = true;
[3703]36$can_edit_post = $core->auth->check('usage,contentadmin', $core->blog->id);
37$can_publish   = $core->auth->check('publish,contentadmin', $core->blog->id);
38$can_delete    = false;
[0]39
[3874]40$post_headlink = '<link rel="%s" title="%s" href="' . $core->adminurl->get('admin.post', ['id' => "%s"], '&amp;', true) . '" />';
41$post_link     = '<a href="' . $core->adminurl->get('admin.post', ['id' => "%s"], '&amp;', true) . '" title="%s">%s</a>';
[3703]42$next_link     = $prev_link     = $next_headlink     = $prev_headlink     = null;
[0]43
44# If user can't publish
45if (!$can_publish) {
[3703]46    $post_status = -2;
[0]47}
48
[1288]49# Getting categories
[1719]50$categories_combo = dcAdminCombos::getCategoriesCombo(
[3703]51    $core->blog->getCategories()
[1719]52);
[1288]53
[1719]54$status_combo = dcAdminCombos::getPostStatusesCombo();
55
[933]56$img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />';
[0]57
[2736]58# Formats combo
[3703]59$core_formaters    = $core->getFormaters();
[3874]60$available_formats = ['' => ''];
[2736]61foreach ($core_formaters as $editor => $formats) {
[3703]62    foreach ($formats as $format) {
63        $available_formats[$format] = $format;
64    }
[2705]65}
[0]66
67# Languages combo
[3874]68$rs         = $core->blog->getLangs(['order' => 'asc']);
[3703]69$lang_combo = dcAdminCombos::getLangsCombo($rs, true);
[0]70
[957]71# Validation flag
72$bad_dt = false;
[0]73
[1783]74# Trackbacks
[3703]75$TB      = new dcTrackback($core);
[1783]76$tb_urls = $tb_excerpt = '';
77
[0]78# Get entry informations
[2705]79if (!empty($_REQUEST['id'])) {
[3703]80    $page_title = __('Edit entry');
[2542]81
[3703]82    $params['post_id'] = $_REQUEST['id'];
[2542]83
[3703]84    $post = $core->blog->getPosts($params);
[2542]85
[3703]86    if ($post->isEmpty()) {
87        $core->error->add(__('This entry does not exist.'));
88        $can_view_page = false;
89    } else {
90        $post_id            = $post->post_id;
91        $cat_id             = $post->cat_id;
92        $post_dt            = date('Y-m-d H:i', strtotime($post->post_dt));
93        $post_format        = $post->post_format;
94        $post_password      = $post->post_password;
95        $post_url           = $post->post_url;
96        $post_lang          = $post->post_lang;
97        $post_title         = $post->post_title;
98        $post_excerpt       = $post->post_excerpt;
99        $post_excerpt_xhtml = $post->post_excerpt_xhtml;
100        $post_content       = $post->post_content;
101        $post_content_xhtml = $post->post_content_xhtml;
102        $post_notes         = $post->post_notes;
103        $post_status        = $post->post_status;
104        $post_selected      = (boolean) $post->post_selected;
105        $post_open_comment  = (boolean) $post->post_open_comment;
106        $post_open_tb       = (boolean) $post->post_open_tb;
[2542]107
[3703]108        $can_edit_post = $post->isEditable();
109        $can_delete    = $post->isDeletable();
[2542]110
[3703]111        $next_rs = $core->blog->getNextPost($post, 1);
112        $prev_rs = $core->blog->getNextPost($post, -1);
[2542]113
[3703]114        if ($next_rs !== null) {
115            $next_link = sprintf($post_link, $next_rs->post_id,
116                html::escapeHTML($next_rs->post_title), __('Next entry') . '&nbsp;&#187;');
117            $next_headlink = sprintf($post_headlink, 'next',
118                html::escapeHTML($next_rs->post_title), $next_rs->post_id);
119        }
[2542]120
[3703]121        if ($prev_rs !== null) {
122            $prev_link = sprintf($post_link, $prev_rs->post_id,
123                html::escapeHTML($prev_rs->post_title), '&#171;&nbsp;' . __('Previous entry'));
124            $prev_headlink = sprintf($post_headlink, 'previous',
125                html::escapeHTML($prev_rs->post_title), $prev_rs->post_id);
126        }
[2542]127
[3703]128        try {
129            $core->media = new dcMedia($core);
130        } catch (Exception $e) {
131            $core->error->add($e->getMessage());
132        }
[1783]133
[3703]134        # Sanitize trackbacks excerpt
135        $tb_excerpt = empty($_POST['tb_excerpt']) ?
136        $post_excerpt_xhtml . ' ' . $post_content_xhtml :
137        $_POST['tb_excerpt'];
138        $tb_excerpt = html::decodeEntities(html::clean($tb_excerpt));
139        $tb_excerpt = text::cutString(html::escapeHTML($tb_excerpt), 255);
140        $tb_excerpt = preg_replace('/\s+/ms', ' ', $tb_excerpt);
141    }
[1783]142}
[3703]143if (isset($_REQUEST['section']) && $_REQUEST['section'] == 'trackbacks') {
144    $anchor = 'trackbacks';
[2067]145} else {
[3703]146    $anchor = 'comments';
[2542]147}
[2071]148
[3874]149$comments_actions_page = new dcCommentsActionsPage($core, $core->adminurl->get('admin.post'), ['id' => $post_id, '_ANCHOR' => $anchor, 'section' => $anchor]);
[2067]150
151if ($comments_actions_page->process()) {
[3703]152    return;
[2067]153}
[1783]154
155# Ping blogs
[3703]156if (!empty($_POST['ping'])) {
157    if (!empty($_POST['tb_urls']) && $post_id && $post_status == 1 && $can_edit_post) {
158        $tb_urls       = $_POST['tb_urls'];
159        $tb_urls       = str_replace("\r", '', $tb_urls);
160        $tb_post_title = html::escapeHTML(trim(html::clean($post_title)));
161        $tb_post_url   = $post->getURL();
[2542]162
[3703]163        foreach (explode("\n", $tb_urls) as $tb_url) {
164            try {
165                # --BEHAVIOR-- adminBeforePingTrackback
166                $core->callBehavior('adminBeforePingTrackback', $tb_url, $post_id, $tb_post_title, $tb_excerpt, $tb_post_url);
[3415]167
[3703]168                $TB->ping($tb_url, $post_id, $tb_post_title, $tb_excerpt, $tb_post_url);
169            } catch (Exception $e) {
170                $core->error->add($e->getMessage());
171            }
172        }
[2542]173
[3703]174        if (!$core->error->flag()) {
175            dcPage::addSuccessNotice(__('All pings sent.'));
176            $core->adminurl->redirect(
177                'admin.post',
[3874]178                ['id' => $post_id, 'tb' => '1']
[3703]179            );
180        }
181    }
[0]182}
183
184# Format excerpt and content
[2705]185elseif (!empty($_POST) && $can_edit_post) {
[3703]186    $post_format  = $_POST['post_format'];
187    $post_excerpt = $_POST['post_excerpt'];
188    $post_content = $_POST['post_content'];
[2542]189
[3703]190    $post_title = $_POST['post_title'];
[2542]191
[3703]192    $cat_id = (integer) $_POST['cat_id'];
[2542]193
[3703]194    if (isset($_POST['post_status'])) {
195        $post_status = (integer) $_POST['post_status'];
196    }
[2542]197
[3703]198    if (empty($_POST['post_dt'])) {
199        $post_dt = '';
200    } else {
201        try
202        {
203            $post_dt = strtotime($_POST['post_dt']);
204            if ($post_dt == false || $post_dt == -1) {
205                $bad_dt = true;
206                throw new Exception(__('Invalid publication date'));
207            }
208            $post_dt = date('Y-m-d H:i', $post_dt);
209        } catch (Exception $e) {
210            $core->error->add($e->getMessage());
211        }
212    }
[2542]213
[3703]214    $post_open_comment = !empty($_POST['post_open_comment']);
215    $post_open_tb      = !empty($_POST['post_open_tb']);
216    $post_selected     = !empty($_POST['post_selected']);
217    $post_lang         = $_POST['post_lang'];
218    $post_password     = !empty($_POST['post_password']) ? $_POST['post_password'] : null;
[2542]219
[3703]220    $post_notes = $_POST['post_notes'];
[2542]221
[3703]222    if (isset($_POST['post_url'])) {
223        $post_url = $_POST['post_url'];
224    }
[2542]225
[3703]226    $core->blog->setPostContent(
227        $post_id, $post_format, $post_lang,
228        $post_excerpt, $post_excerpt_xhtml, $post_content, $post_content_xhtml
229    );
[0]230}
231
[1068]232# Delete post
[3703]233if (!empty($_POST['delete']) && $can_delete) {
234    try {
235        # --BEHAVIOR-- adminBeforePostDelete
236        $core->callBehavior('adminBeforePostDelete', $post_id);
237        $core->blog->delPost($post_id);
238        $core->adminurl->redirect("admin.posts");
239    } catch (Exception $e) {
240        $core->error->add($e->getMessage());
241    }
[1068]242}
243
[0]244# Create or update post
[3703]245if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt) {
246    # Create category
247    if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) {
[2542]248
[3703]249        $cur_cat            = $core->con->openCursor($core->prefix . 'category');
250        $cur_cat->cat_title = $_POST['new_cat_title'];
251        $cur_cat->cat_url   = '';
[2542]252
[3703]253        $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : '';
[2542]254
[3703]255        # --BEHAVIOR-- adminBeforeCategoryCreate
256        $core->callBehavior('adminBeforeCategoryCreate', $cur_cat);
[2542]257
[3703]258        $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat);
[2542]259
[3703]260        # --BEHAVIOR-- adminAfterCategoryCreate
261        $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id);
262    }
[2542]263
[3703]264    $cur = $core->con->openCursor($core->prefix . 'post');
[2542]265
[3703]266    $cur->post_title         = $post_title;
267    $cur->cat_id             = ($cat_id ?: null);
268    $cur->post_dt            = $post_dt ? date('Y-m-d H:i:00', strtotime($post_dt)) : '';
269    $cur->post_format        = $post_format;
270    $cur->post_password      = $post_password;
271    $cur->post_lang          = $post_lang;
272    $cur->post_title         = $post_title;
273    $cur->post_excerpt       = $post_excerpt;
274    $cur->post_excerpt_xhtml = $post_excerpt_xhtml;
275    $cur->post_content       = $post_content;
276    $cur->post_content_xhtml = $post_content_xhtml;
277    $cur->post_notes         = $post_notes;
278    $cur->post_status        = $post_status;
279    $cur->post_selected      = (integer) $post_selected;
280    $cur->post_open_comment  = (integer) $post_open_comment;
281    $cur->post_open_tb       = (integer) $post_open_tb;
[2542]282
[3703]283    if (isset($_POST['post_url'])) {
284        $cur->post_url = $post_url;
285    }
[2542]286
[3703]287    # Update post
288    if ($post_id) {
289        try {
290            # --BEHAVIOR-- adminBeforePostUpdate
291            $core->callBehavior('adminBeforePostUpdate', $cur, $post_id);
[2542]292
[3703]293            $core->blog->updPost($post_id, $cur);
[2542]294
[3703]295            # --BEHAVIOR-- adminAfterPostUpdate
296            $core->callBehavior('adminAfterPostUpdate', $cur, $post_id);
297            dcPage::addSuccessNotice(sprintf(__('The post "%s" has been successfully updated'), html::escapeHTML($cur->post_title)));
298            $core->adminurl->redirect(
299                'admin.post',
[3874]300                ['id' => $post_id]
[3703]301            );
302        } catch (Exception $e) {
303            $core->error->add($e->getMessage());
304        }
305    } else {
306        $cur->user_id = $core->auth->userID();
[2542]307
[3703]308        try {
309            # --BEHAVIOR-- adminBeforePostCreate
310            $core->callBehavior('adminBeforePostCreate', $cur);
[2542]311
[3703]312            $return_id = $core->blog->addPost($cur);
[2542]313
[3703]314            # --BEHAVIOR-- adminAfterPostCreate
315            $core->callBehavior('adminAfterPostCreate', $cur, $return_id);
[2256]316
[3703]317            dcPage::addSuccessNotice(__('Entry has been successfully created.'));
318            $core->adminurl->redirect(
319                'admin.post',
[3874]320                ['id' => $return_id]
[3703]321            );
322        } catch (Exception $e) {
323            $core->error->add($e->getMessage());
324        }
325    }
[0]326}
327
[1417]328# Getting categories
[1719]329$categories_combo = dcAdminCombos::getCategoriesCombo(
[3703]330    $core->blog->getCategories()
[1719]331);
[0]332/* DISPLAY
333-------------------------------------------------------- */
334$default_tab = 'edit-entry';
335if (!$can_edit_post) {
[3703]336    $default_tab = '';
[0]337}
338if (!empty($_GET['co'])) {
[3703]339    $default_tab = 'comments';
340} elseif (!empty($_GET['tb'])) {
341    $default_tab = 'trackbacks';
[1783]342}
[0]343
[1358]344if ($post_id) {
[3703]345    switch ($post_status) {
346        case 1:
347            $img_status = sprintf($img_status_pattern, __('Published'), 'check-on.png');
348            break;
349        case 0:
350            $img_status = sprintf($img_status_pattern, __('Unpublished'), 'check-off.png');
351            break;
352        case -1:
353            $img_status = sprintf($img_status_pattern, __('Scheduled'), 'scheduled.png');
354            break;
355        case -2:
356            $img_status = sprintf($img_status_pattern, __('Pending'), 'check-wrn.png');
357            break;
358        default:
359            $img_status = '';
360    }
361    $edit_entry_str  = __('&ldquo;%s&rdquo;');
362    $page_title_edit = sprintf($edit_entry_str, html::escapeHTML($post_title)) . ' ' . $img_status;
[1427]363} else {
[3703]364    $img_status = '';
[1358]365}
366
[2705]367$admin_post_behavior = '';
[2856]368if ($post_editor) {
369    $p_edit = $c_edit = '';
370    if (!empty($post_editor[$post_format])) {
371        $p_edit = $post_editor[$post_format];
372    }
373    if (!empty($post_editor['xhtml'])) {
374        $c_edit = $post_editor['xhtml'];
375    }
376    if ($p_edit == $c_edit) {
377        $admin_post_behavior .= $core->callBehavior('adminPostEditor',
[3874]378            $p_edit, 'post', ['#post_excerpt', '#post_content', '#comment_content'], $post_format);
[2856]379    } else {
380        $admin_post_behavior .= $core->callBehavior('adminPostEditor',
[3874]381            $p_edit, 'post', ['#post_excerpt', '#post_content'], $post_format);
[2856]382        $admin_post_behavior .= $core->callBehavior('adminPostEditor',
[3874]383            $c_edit, 'comment', ['#comment_content'], 'xhtml');
[2856]384    }
[2705]385}
[1358]386
[3703]387dcPage::open($page_title . ' - ' . __('Entries'),
388    dcPage::jsDatePicker() .
389    dcPage::jsModal() .
390    dcPage::jsMetaEditor() .
391    $admin_post_behavior .
392    dcPage::jsLoad('js/_post.js') .
393    dcPage::jsConfirmClose('entry-form', 'comment-form') .
394    # --BEHAVIOR-- adminPostHeaders
395    $core->callBehavior('adminPostHeaders') .
396    dcPage::jsPageTabs($default_tab) .
397    $next_headlink . "\n" . $prev_headlink,
398    dcPage::breadcrumb(
[3874]399        [
[3703]400            html::escapeHTML($core->blog->name)         => '',
401            __('Entries')                               => $core->adminurl->get("admin.posts"),
402            ($post_id ? $page_title_edit : $page_title) => ''
[3874]403        ])
404    , [
[3703]405        'x-frame-allow' => $core->blog->url
[3874]406    ]
[0]407);
408
409if (!empty($_GET['upd'])) {
[3703]410    dcPage::success(__('Entry has been successfully updated.'));
411} elseif (!empty($_GET['crea'])) {
412    dcPage::success(__('Entry has been successfully created.'));
413} elseif (!empty($_GET['attached'])) {
414    dcPage::success(__('File has been successfully attached.'));
415} elseif (!empty($_GET['rmattach'])) {
416    dcPage::success(__('Attachment has been successfully removed.'));
[0]417}
418
419if (!empty($_GET['creaco'])) {
[3703]420    dcPage::success(__('Comment has been successfully created.'));
[907]421}
[1783]422if (!empty($_GET['tbsent'])) {
[3703]423    dcPage::success(__('All pings sent.'));
[1783]424}
[0]425
426# XHTML conversion
[3703]427if (!empty($_GET['xconv'])) {
428    $post_excerpt = $post_excerpt_xhtml;
429    $post_content = $post_content_xhtml;
430    $post_format  = 'xhtml';
[2542]431
[3703]432    dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.'));
[0]433}
434
435if ($post_id && $post->post_status == 1) {
[3771]436    echo '<p><a class="onblog_link outgoing" href="' . $post->getURL() . '" title="' . html::escapeHTML($post_title) . '">' . __('Go to this entry on the site') . ' <img src="images/outgoing-link.svg" alt="" /></a></p>';
[0]437}
[3703]438if ($post_id) {
439    echo '<p class="nav_prevnext">';
440    if ($prev_link) {echo $prev_link;}
441    if ($next_link && $prev_link) {echo ' | ';}
442    if ($next_link) {echo $next_link;}
[2542]443
[3703]444    # --BEHAVIOR-- adminPostNavLinks
445    $core->callBehavior('adminPostNavLinks', isset($post) ? $post : null, 'post');
[2542]446
[3703]447    echo '</p>';
[0]448}
449
450# Exit if we cannot view page
451if (!$can_view_page) {
[3703]452    dcPage::helpBlock('core_post');
453    dcPage::close();
454    exit;
[0]455}
[3491]456
457# Controls comments or trakbacks capabilities
[3703]458$isContributionAllowed = function ($id, $dt, $com = true) {
459    global $core;
[3491]460
[3703]461    if (!$id) {
462        return true;
463    }
464    if ($com) {
465        if (($core->blog->settings->system->comments_ttl == 0) ||
466            (time() - $core->blog->settings->system->comments_ttl * 86400 < $dt)) {
467            return true;
468        }
469    } else {
470        if (($core->blog->settings->system->trackbacks_ttl == 0) ||
471            (time() - $core->blog->settings->system->trackbacks_ttl * 86400 < $dt)) {
472            return true;
473        }
474    }
475    return false;
[3491]476};
477
478# Show comments or trackbacks
[3703]479$showComments = function ($rs, $has_action, $tb = false) {
480    global $core;
481    echo
482    '<div class="table-outer">' .
483    '<table class="comments-list"><tr>' .
484    '<th colspan="2" class="first">' . __('Author') . '</th>' .
485    '<th>' . __('Date') . '</th>' .
486    '<th class="nowrap">' . __('IP address') . '</th>' .
487    '<th>' . __('Status') . '</th>' .
488    '<th>' . __('Edit') . '</th>' .
489        '</tr>';
[3874]490    $comments = [];
[3703]491    if (isset($_REQUEST['comments'])) {
492        foreach ($_REQUEST['comments'] as $v) {
493            $comments[(integer) $v] = true;
494        }
495    }
[3491]496
[3703]497    while ($rs->fetch()) {
[3874]498        $comment_url = $core->adminurl->get("admin.comment", ['id' => $rs->comment_id]);
[3491]499
[3703]500        $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
501        switch ($rs->comment_status) {
502            case 1:
503                $img_status = sprintf($img, __('Published'), 'check-on.png');
504                break;
505            case 0:
506                $img_status = sprintf($img, __('Unpublished'), 'check-off.png');
507                break;
508            case -1:
509                $img_status = sprintf($img, __('Pending'), 'check-wrn.png');
510                break;
511            case -2:
512                $img_status = sprintf($img, __('Junk'), 'junk.png');
513                break;
514        }
[3491]515
[3703]516        echo
517        '<tr class="line' . ($rs->comment_status != 1 ? ' offline' : '') . '"' .
518        ' id="c' . $rs->comment_id . '">' .
[3491]519
[3703]520        '<td class="nowrap">' .
[3874]521        ($has_action ? form::checkbox(['comments[]'], $rs->comment_id,
522            [
[3707]523                'checked'    => isset($comments[$rs->comment_id]),
524                'extra_html' => 'title="' . ($tb ? __('select this trackback') : __('select this comment') . '"')
[3874]525            ]
[3710]526        ) : '') . '</td>' .
527        '<td class="maximal">' . html::escapeHTML($rs->comment_author) . '</td>' .
528        '<td class="nowrap">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $rs->comment_dt) . '</td>' .
[3874]529        '<td class="nowrap"><a href="' . $core->adminurl->get("admin.comments", ['ip' => $rs->comment_ip]) . '">' . $rs->comment_ip . '</a></td>' .
[3710]530        '<td class="nowrap status">' . $img_status . '</td>' .
531        '<td class="nowrap status"><a href="' . $comment_url . '">' .
532        '<img src="images/edit-mini.png" alt="" title="' . __('Edit this comment') . '" /> ' . __('Edit') . '</a></td>' .
[3491]533
[3710]534            '</tr>';
535    }
[3491]536
[3710]537    echo '</table></div>';
538};
[3491]539
[0]540/* Post form if we can edit post
541-------------------------------------------------------- */
[3710]542if ($can_edit_post) {
[3874]543    $sidebar_items = new ArrayObject([
544        'status-box'  => [
[3710]545            'title' => __('Status'),
[3874]546            'items' => [
[3710]547                'post_status' =>
548                '<p class="entry-status"><label for="post_status">' . __('Entry status') . ' ' . $img_status . '</label>' .
549                form::combo('post_status', $status_combo,
[3874]550                    ['default' => $post_status, 'class' => 'maximal', 'disabled' => !$can_publish]) .
[3710]551                '</p>',
552                'post_dt'     =>
553                '<p><label for="post_dt">' . __('Publication date and hour') . '</label>' .
554                form::field('post_dt', 16, 16, $post_dt, ($bad_dt ? 'invalid' : '')) .
[3725]555                /*
556                Previous line will be replaced by this one as soon as every browser will support datetime-local input type
557                Dont forget to remove call to datepicker in post.js
558
[3874]559                form::datetime('post_dt', [
[3730]560                'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', strtotime($post_dt))),
561                'class' => ($bad_dt ? 'invalid' : '')
[3874]562                ]) .
[3730]563                 */
[3710]564                '</p>',
565                'post_lang'   =>
566                '<p><label for="post_lang">' . __('Entry language') . '</label>' .
567                form::combo('post_lang', $lang_combo, $post_lang) .
568                '</p>',
569                'post_format' =>
570                '<div>' .
571                '<h5 id="label_format"><label for="post_format" class="classic">' . __('Text formatting') . '</label></h5>' .
572                '<p>' . form::combo('post_format', $available_formats, $post_format, 'maximal') . '</p>' .
573                '<p class="format_control control_no_xhtml">' .
574                '<a id="convert-xhtml" class="button' . ($post_id && $post_format != 'wiki' ? ' hide' : '') . '" href="' .
[3874]575                $core->adminurl->get('admin.post', ['id' => $post_id, 'xconv' => '1']) .
[3710]576                '">' .
[3874]577                __('Convert to XHTML') . '</a></p></div>']],
578        'metas-box'   => [
[3710]579            'title' => __('Filing'),
[3874]580            'items' => [
[3710]581                'post_selected' =>
582                '<p><label for="post_selected" class="classic">' .
583                form::checkbox('post_selected', 1, $post_selected) . ' ' .
584                __('Selected entry') . '</label></p>',
585                'cat_id'        =>
586                '<div>' .
587                '<h5 id="label_cat_id">' . __('Category') . '</h5>' .
588                '<p><label for="cat_id">' . __('Category:') . '</label>' .
589                form::combo('cat_id', $categories_combo, $cat_id, 'maximal') .
590                '</p>' .
591                ($core->auth->check('categories', $core->blog->id) ?
[3703]592                    '<div>' .
[3710]593                    '<h5 id="create_cat">' . __('Add a new category') . '</h5>' .
594                    '<p><label for="new_cat_title">' . __('Title:') . ' ' .
[3874]595                    form::field('new_cat_title', 30, 255, ['class' => 'maximal']) . '</label></p>' .
[3710]596                    '<p><label for="new_cat_parent">' . __('Parent:') . ' ' .
597                    form::combo('new_cat_parent', $categories_combo, '', 'maximal') .
598                    '</label></p>' .
599                    '</div>'
600                    : '') .
[3874]601                '</div>']],
602        'options-box' => [
[3710]603            'title' => __('Options'),
[3874]604            'items' => [
[3710]605                'post_open_comment_tb' =>
606                '<div>' .
607                '<h5 id="label_comment_tb">' . __('Comments and trackbacks list') . '</h5>' .
608                '<p><label for="post_open_comment" class="classic">' .
609                form::checkbox('post_open_comment', 1, $post_open_comment) . ' ' .
610                __('Accept comments') . '</label></p>' .
611                ($core->blog->settings->system->allow_comments ?
612                    ($isContributionAllowed($post_id, strtotime($post_dt), true) ?
613                        '' :
[3703]614                        '<p class="form-note warn">' .
[3710]615                        __('Warning: Comments are not more accepted for this entry.') . '</p>') :
[3703]616                    '<p class="form-note warn">' .
[3710]617                    __('Comments are not accepted on this blog so far.') . '</p>') .
618                '<p><label for="post_open_tb" class="classic">' .
619                form::checkbox('post_open_tb', 1, $post_open_tb) . ' ' .
620                __('Accept trackbacks') . '</label></p>' .
621                ($core->blog->settings->system->allow_trackbacks ?
622                    ($isContributionAllowed($post_id, strtotime($post_dt), false) ?
623                        '' :
624                        '<p class="form-note warn">' .
625                        __('Warning: Trackbacks are not more accepted for this entry.') . '</p>') :
626                    '<p class="form-note warn">' . __('Trackbacks are not accepted on this blog so far.') . '</p>') .
627                '</div>',
628                'post_password'        =>
629                '<p><label for="post_password">' . __('Password') . '</label>' .
630                form::field('post_password', 10, 32, html::escapeHTML($post_password), 'maximal') .
631                '</p>',
632                'post_url'             =>
633                '<div class="lockable">' .
634                '<p><label for="post_url">' . __('Edit basename') . '</label>' .
635                form::field('post_url', 10, 255, html::escapeHTML($post_url), 'maximal') .
636                '</p>' .
637                '<p class="form-note warn">' .
638                __('Warning: If you set the URL manually, it may conflict with another entry.') .
639                '</p></div>'
[3874]640            ]]]);
[1398]641
[3874]642    $main_items = new ArrayObject([
[3710]643        "post_title"   =>
644        '<p class="col">' .
645        '<label class="required no-margin bold" for="post_title"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label>' .
[3874]646        form::field('post_title', 20, 255, [
[3725]647            'default'    => html::escapeHTML($post_title),
648            'class'      => 'maximal',
649            'extra_html' => 'required placeholder="' . __('Title') . '"'
[3874]650        ]) .
[3710]651        '</p>',
[2542]652
[3710]653        "post_excerpt" =>
654        '<p class="area" id="excerpt-area"><label for="post_excerpt" class="bold">' . __('Excerpt:') . ' <span class="form-note">' .
655        __('Introduction to the post.') . '</span></label> ' .
656        form::textarea('post_excerpt', 50, 5, html::escapeHTML($post_excerpt)) .
657        '</p>',
[2542]658
[3710]659        "post_content" =>
660        '<p class="area" id="content-area"><label class="required bold" ' .
661        'for="post_content"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Content:') . '</label> ' .
662        form::textarea('post_content', 50, $core->auth->getOption('edit_size'),
[3874]663            [
[3710]664                'default'    => html::escapeHTML($post_content),
665                'extra_html' => 'required placeholder="' . __('Content') . '"'
[3874]666            ]) .
[3710]667        '</p>',
[2542]668
[3710]669        "post_notes"   =>
670        '<p class="area" id="notes-area"><label for="post_notes" class="bold">' . __('Personal notes:') . ' <span class="form-note">' .
671        __('Unpublished notes.') . '</span></label>' .
672        form::textarea('post_notes', 50, 5, html::escapeHTML($post_notes)) .
673        '</p>'
[3874]674    ]
[3710]675    );
[2542]676
[3710]677    # --BEHAVIOR-- adminPostFormItems
678    $core->callBehavior('adminPostFormItems', $main_items, $sidebar_items, isset($post) ? $post : null, 'post');
[1398]679
[3710]680    echo '<div class="multi-part" title="' . ($post_id ? __('Edit entry') : __('New entry')) .
681    sprintf(' &rsaquo; %s', $post_format) . '" id="edit-entry">';
682    echo '<form action="' . $core->adminurl->get('admin.post') . '" method="post" id="entry-form">';
683    echo '<div id="entry-wrapper">';
684    echo '<div id="entry-content"><div class="constrained">';
[1398]685
[3710]686    echo '<h3 class="out-of-screen-if-js">' . __('Edit post') . '</h3>';
[2542]687
[3710]688    foreach ($main_items as $id => $item) {
689        echo $item;
690    }
691
692    # --BEHAVIOR-- adminPostForm (may be deprecated)
693    $core->callBehavior('adminPostForm', isset($post) ? $post : null, 'post');
694
695    echo
696    '<p class="border-top">' .
697    ($post_id ? form::hidden('id', $post_id) : '') .
698    '<input type="submit" value="' . __('Save') . ' (s)" ' .
699        'accesskey="s" name="save" /> ';
700    if ($post_id) {
701        $preview_url =
702        $core->blog->url . $core->url->getURLFor('preview', $core->auth->userID() . '/' .
703            http::browserUID(DC_MASTER_KEY . $core->auth->userID() . $core->auth->cryptLegacy($core->auth->userID())) .
704            '/' . $post->post_url);
705        echo '<a id="post-preview" href="' . $preview_url . '" class="button modal" accesskey="p">' . __('Preview') . ' (p)' . '</a>';
706    } else {
707        echo
708        '<a id="post-cancel" href="' . $core->adminurl->get("admin.home") . '" class="button" accesskey="c">' . __('Cancel') . ' (c)</a>';
709    }
710
711    echo
712    ($can_delete ? ' <input type="submit" class="delete" value="' . __('Delete') . '" name="delete" />' : '') .
713    $core->formNonce() .
714        '</p>';
715
716    echo '</div></div>'; // End #entry-content
717    echo '</div>';       // End #entry-wrapper
718
719    echo '<div id="entry-sidebar" role="complementary">';
720
721    foreach ($sidebar_items as $id => $c) {
722        echo '<div id="' . $id . '" class="sb-box">' .
723            '<h4>' . $c['title'] . '</h4>';
724        foreach ($c['items'] as $e_name => $e_content) {
725            echo $e_content;
[3707]726        }
[3710]727        echo '</div>';
728    }
[1398]729
[3710]730    # --BEHAVIOR-- adminPostFormSidebar (may be deprecated)
731    $core->callBehavior('adminPostFormSidebar', isset($post) ? $post : null, 'post');
732    echo '</div>'; // End #entry-sidebar
733
734    echo '</form>';
735
736    # --BEHAVIOR-- adminPostForm
737    $core->callBehavior('adminPostAfterForm', isset($post) ? $post : null, 'post');
738
739    echo '</div>';
740}
741
742if ($post_id) {
743    /* Comments
744    -------------------------------------------------------- */
745
[3874]746    $params = ['post_id' => $post_id, 'order' => 'comment_dt ASC'];
[3710]747
[3874]748    $comments = $core->blog->getComments(array_merge($params, ['comment_trackback' => 0]));
[3710]749
750    echo
751    '<div id="comments" class="clear multi-part" title="' . __('Comments') . '">';
752    $combo_action = $comments_actions_page->getCombo();
753    $has_action   = !empty($combo_action) && !$comments->isEmpty();
754    echo
755    '<p class="top-add"><a class="button add" href="#comment-form">' . __('Add a comment') . '</a></p>';
756
757    if ($has_action) {
758        echo '<form action="' . $core->adminurl->get('admin.post') . '" id="form-comments" method="post">';
759    }
760
761    echo '<h3>' . __('Comments') . '</h3>';
762    if (!$comments->isEmpty()) {
763        $showComments($comments, $has_action);
764    } else {
765        echo '<p>' . __('No comments') . '</p>';
766    }
767
768    if ($has_action) {
769        echo
770        '<div class="two-cols">' .
771        '<p class="col checkboxes-helpers"></p>' .
772
773        '<p class="col right"><label for="action" class="classic">' . __('Selected comments action:') . '</label> ' .
774        form::combo('action', $combo_action) .
[3874]775        form::hidden(['section'], 'comments') .
776        form::hidden(['id'], $post_id) .
[3710]777        $core->formNonce() .
778        '<input type="submit" value="' . __('ok') . '" /></p>' .
779            '</div>' .
780            '</form>';
781    }
782    /* Add a comment
783    -------------------------------------------------------- */
784
785    echo
786    '<div class="fieldset clear">' .
787    '<h3>' . __('Add a comment') . '</h3>' .
788
789    '<form action="' . $core->adminurl->get("admin.comment") . '" method="post" id="comment-form">' .
790    '<div class="constrained">' .
791    '<p><label for="comment_author" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Name:') . '</label>' .
[3874]792    form::field('comment_author', 30, 255, [
[3725]793        'default'    => html::escapeHTML($core->auth->getInfo('user_cn')),
794        'extra_html' => 'required placeholder="' . __('Author') . '"'
[3874]795    ]) .
[3710]796    '</p>' .
797
798    '<p><label for="comment_email">' . __('Email:') . '</label>' .
[3725]799    form::email('comment_email', 30, 255, html::escapeHTML($core->auth->getInfo('user_email'))) .
[3710]800    '</p>' .
801
802    '<p><label for="comment_site">' . __('Web site:') . '</label>' .
[3725]803    form::url('comment_site', 30, 255, html::escapeHTML($core->auth->getInfo('user_url'))) .
[3710]804    '</p>' .
805
806    '<p class="area"><label for="comment_content" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' .
807    __('Comment:') . '</label> ' .
[3874]808    form::textarea('comment_content', 50, 8, ['extra_html' => 'required placeholder="' . __('Comment') . '"']) .
[3710]809    '</p>' .
810
811    '<p>' .
812    form::hidden('post_id', $post_id) .
813    $core->formNonce() .
814    '<input type="submit" name="add" value="' . __('Save') . '" /></p>' .
815    '</div>' . #constrained
816
817    '</form>' .
818    '</div>' . #add comment
819    '</div>'; #comments
820}
821
822if ($post_id && $post_status == 1) {
823    /* Trackbacks
824    -------------------------------------------------------- */
825
[3874]826    $params     = ['post_id' => $post_id, 'order' => 'comment_dt ASC'];
827    $trackbacks = $core->blog->getComments(array_merge($params, ['comment_trackback' => 1]));
[3710]828
829    # Actions combo box
830    $combo_action = $comments_actions_page->getCombo();
831    $has_action   = !empty($combo_action) && !$trackbacks->isEmpty();
832
833    if (!empty($_GET['tb_auto'])) {
834        $tb_urls = implode("\n", $TB->discover($post_excerpt_xhtml . ' ' . $post_content_xhtml));
835    }
836
837    # Display tab
838    echo
839    '<div id="trackbacks" class="clear multi-part" title="' . __('Trackbacks') . '">';
840
841    # tracbacks actions
842    if ($has_action) {
843        echo '<form action="' . $core->adminurl->get("admin.post") . '" id="form-trackbacks" method="post">';
844    }
845
846    echo '<h3>' . __('Trackbacks received') . '</h3>';
847
848    if (!$trackbacks->isEmpty()) {
849        $showComments($trackbacks, $has_action, true);
850    } else {
851        echo '<p>' . __('No trackback') . '</p>';
852    }
853
854    if ($has_action) {
855        echo
856        '<div class="two-cols">' .
857        '<p class="col checkboxes-helpers"></p>' .
858
859        '<p class="col right"><label for="action" class="classic">' . __('Selected trackbacks action:') . '</label> ' .
860        form::combo('action', $combo_action) .
861        form::hidden('id', $post_id) .
[3874]862        form::hidden(['section'], 'trackbacks') .
[3710]863        $core->formNonce() .
864        '<input type="submit" value="' . __('ok') . '" /></p>' .
865            '</div>' .
866            '</form>';
867    }
868
869    /* Add trackbacks
870    -------------------------------------------------------- */
871    if ($can_edit_post && $post->post_status) {
872        echo
873            '<div class="fieldset clear">';
[1783]874
[3703]875        echo
[3710]876        '<h3>' . __('Ping blogs') . '</h3>' .
[3874]877        '<form action="' . $core->adminurl->get("admin.post", ['id' => $post_id]) . '" id="trackback-form" method="post">' .
[3710]878        '<p><label for="tb_urls" class="area">' . __('URLs to ping:') . '</label>' .
879        form::textarea('tb_urls', 60, 5, $tb_urls) .
880        '</p>' .
881
882        '<p><label for="tb_excerpt" class="area">' . __('Excerpt to send:') . '</label>' .
883        form::textarea('tb_excerpt', 60, 5, $tb_excerpt) . '</p>' .
884
885        '<p>' .
886        $core->formNonce() .
887        '<input type="submit" name="ping" value="' . __('Ping blogs') . '" />' .
888            (empty($_GET['tb_auto']) ?
889            '&nbsp;&nbsp;<a class="button" href="' .
[3874]890            $core->adminurl->get("admin.post", ['id' => $post_id, 'tb_auto' => 1, 'tb' => 1]) .
[3710]891            '">' . __('Auto discover ping URLs') . '</a>'
892            : '') .
893            '</p>' .
894            '</form>';
895
896        $pings = $TB->getPostPings($post_id);
897
898        if (!$pings->isEmpty()) {
899            echo '<h3>' . __('Previously sent pings') . '</h3>';
900
901            echo '<ul class="nice">';
902            while ($pings->fetch()) {
903                echo
904                '<li>' . dt::dt2str(__('%Y-%m-%d %H:%M'), $pings->ping_dt) . ' - ' .
905                $pings->ping_url . '</li>';
906            }
907            echo '</ul>';
[3707]908        }
[1783]909
[3703]910        echo '</div>';
911    }
[1783]912
[3710]913    echo '</div>'; #trackbacks
914}
[1783]915
[3710]916dcPage::helpBlock('core_post', 'core_trackbacks', 'core_wiki');
917dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map