Dotclear

source: plugins/pages/page.php @ 3995:58bdf03fbdea

Revision 3995:58bdf03fbdea, 28.4 KB checked in by franck <carnet.franck.paul@…>, 6 years ago (diff)

Switching from inline JS variables to JSON script, pages plugin

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

Sites map