Dotclear

source: admin/post.php @ 3731:3770620079d4

Revision 3731:3770620079d4, 34.2 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Simplify licence block at the beginning of each file

Line 
1<?php
2/**
3 * @package Dotclear
4 * @subpackage Backend
5 *
6 * @copyright Olivier Meunier & Association Dotclear
7 * @copyright GPL-2.0-only
8 */
9
10require dirname(__FILE__) . '/../inc/admin/prepend.php';
11
12dcPage::check('usage,contentadmin');
13
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       = '';
24$post_excerpt_xhtml = '';
25$post_content       = '';
26$post_content_xhtml = '';
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;
32
33$page_title = __('New entry');
34
35$can_view_page = true;
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;
39
40$post_headlink = '<link rel="%s" title="%s" href="' . $core->adminurl->get('admin.post', array('id' => "%s"), '&amp;', true) . '" />';
41$post_link     = '<a href="' . $core->adminurl->get('admin.post', array('id' => "%s"), '&amp;', true) . '" title="%s">%s</a>';
42$next_link     = $prev_link     = $next_headlink     = $prev_headlink     = null;
43
44# If user can't publish
45if (!$can_publish) {
46    $post_status = -2;
47}
48
49# Getting categories
50$categories_combo = dcAdminCombos::getCategoriesCombo(
51    $core->blog->getCategories()
52);
53
54$status_combo = dcAdminCombos::getPostStatusesCombo();
55
56$img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />';
57
58# Formats combo
59$core_formaters    = $core->getFormaters();
60$available_formats = array('' => '');
61foreach ($core_formaters as $editor => $formats) {
62    foreach ($formats as $format) {
63        $available_formats[$format] = $format;
64    }
65}
66
67# Languages combo
68$rs         = $core->blog->getLangs(array('order' => 'asc'));
69$lang_combo = dcAdminCombos::getLangsCombo($rs, true);
70
71# Validation flag
72$bad_dt = false;
73
74# Trackbacks
75$TB      = new dcTrackback($core);
76$tb_urls = $tb_excerpt = '';
77
78# Get entry informations
79if (!empty($_REQUEST['id'])) {
80    $page_title = __('Edit entry');
81
82    $params['post_id'] = $_REQUEST['id'];
83
84    $post = $core->blog->getPosts($params);
85
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;
107
108        $can_edit_post = $post->isEditable();
109        $can_delete    = $post->isDeletable();
110
111        $next_rs = $core->blog->getNextPost($post, 1);
112        $prev_rs = $core->blog->getNextPost($post, -1);
113
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        }
120
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        }
127
128        try {
129            $core->media = new dcMedia($core);
130        } catch (Exception $e) {
131            $core->error->add($e->getMessage());
132        }
133
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    }
142}
143if (isset($_REQUEST['section']) && $_REQUEST['section'] == 'trackbacks') {
144    $anchor = 'trackbacks';
145} else {
146    $anchor = 'comments';
147}
148
149$comments_actions_page = new dcCommentsActionsPage($core, $core->adminurl->get('admin.post'), array('id' => $post_id, '_ANCHOR' => $anchor, 'section' => $anchor));
150
151if ($comments_actions_page->process()) {
152    return;
153}
154
155# Ping blogs
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();
162
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);
167
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        }
173
174        if (!$core->error->flag()) {
175            dcPage::addSuccessNotice(__('All pings sent.'));
176            $core->adminurl->redirect(
177                'admin.post',
178                array('id' => $post_id, 'tb' => '1')
179            );
180        }
181    }
182}
183
184# Format excerpt and content
185elseif (!empty($_POST) && $can_edit_post) {
186    $post_format  = $_POST['post_format'];
187    $post_excerpt = $_POST['post_excerpt'];
188    $post_content = $_POST['post_content'];
189
190    $post_title = $_POST['post_title'];
191
192    $cat_id = (integer) $_POST['cat_id'];
193
194    if (isset($_POST['post_status'])) {
195        $post_status = (integer) $_POST['post_status'];
196    }
197
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    }
213
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;
219
220    $post_notes = $_POST['post_notes'];
221
222    if (isset($_POST['post_url'])) {
223        $post_url = $_POST['post_url'];
224    }
225
226    $core->blog->setPostContent(
227        $post_id, $post_format, $post_lang,
228        $post_excerpt, $post_excerpt_xhtml, $post_content, $post_content_xhtml
229    );
230}
231
232# Delete post
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    }
242}
243
244# Create or update post
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)) {
248
249        $cur_cat            = $core->con->openCursor($core->prefix . 'category');
250        $cur_cat->cat_title = $_POST['new_cat_title'];
251        $cur_cat->cat_url   = '';
252
253        $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : '';
254
255        # --BEHAVIOR-- adminBeforeCategoryCreate
256        $core->callBehavior('adminBeforeCategoryCreate', $cur_cat);
257
258        $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat);
259
260        # --BEHAVIOR-- adminAfterCategoryCreate
261        $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id);
262    }
263
264    $cur = $core->con->openCursor($core->prefix . 'post');
265
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;
282
283    if (isset($_POST['post_url'])) {
284        $cur->post_url = $post_url;
285    }
286
287    # Update post
288    if ($post_id) {
289        try {
290            # --BEHAVIOR-- adminBeforePostUpdate
291            $core->callBehavior('adminBeforePostUpdate', $cur, $post_id);
292
293            $core->blog->updPost($post_id, $cur);
294
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',
300                array('id' => $post_id)
301            );
302        } catch (Exception $e) {
303            $core->error->add($e->getMessage());
304        }
305    } else {
306        $cur->user_id = $core->auth->userID();
307
308        try {
309            # --BEHAVIOR-- adminBeforePostCreate
310            $core->callBehavior('adminBeforePostCreate', $cur);
311
312            $return_id = $core->blog->addPost($cur);
313
314            # --BEHAVIOR-- adminAfterPostCreate
315            $core->callBehavior('adminAfterPostCreate', $cur, $return_id);
316
317            dcPage::addSuccessNotice(__('Entry has been successfully created.'));
318            $core->adminurl->redirect(
319                'admin.post',
320                array('id' => $return_id)
321            );
322        } catch (Exception $e) {
323            $core->error->add($e->getMessage());
324        }
325    }
326}
327
328# Getting categories
329$categories_combo = dcAdminCombos::getCategoriesCombo(
330    $core->blog->getCategories()
331);
332/* DISPLAY
333-------------------------------------------------------- */
334$default_tab = 'edit-entry';
335if (!$can_edit_post) {
336    $default_tab = '';
337}
338if (!empty($_GET['co'])) {
339    $default_tab = 'comments';
340} elseif (!empty($_GET['tb'])) {
341    $default_tab = 'trackbacks';
342}
343
344if ($post_id) {
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;
363} else {
364    $img_status = '';
365}
366
367$admin_post_behavior = '';
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',
378            $p_edit, 'post', array('#post_excerpt', '#post_content', '#comment_content'), $post_format);
379    } else {
380        $admin_post_behavior .= $core->callBehavior('adminPostEditor',
381            $p_edit, 'post', array('#post_excerpt', '#post_content'), $post_format);
382        $admin_post_behavior .= $core->callBehavior('adminPostEditor',
383            $c_edit, 'comment', array('#comment_content'), 'xhtml');
384    }
385}
386
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(
399        array(
400            html::escapeHTML($core->blog->name)         => '',
401            __('Entries')                               => $core->adminurl->get("admin.posts"),
402            ($post_id ? $page_title_edit : $page_title) => ''
403        ))
404    , array(
405        'x-frame-allow' => $core->blog->url
406    )
407);
408
409if (!empty($_GET['upd'])) {
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.'));
417}
418
419if (!empty($_GET['creaco'])) {
420    dcPage::success(__('Comment has been successfully created.'));
421}
422if (!empty($_GET['tbsent'])) {
423    dcPage::success(__('All pings sent.'));
424}
425
426# XHTML conversion
427if (!empty($_GET['xconv'])) {
428    $post_excerpt = $post_excerpt_xhtml;
429    $post_content = $post_content_xhtml;
430    $post_format  = 'xhtml';
431
432    dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.'));
433}
434
435if ($post_id && $post->post_status == 1) {
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-blue.png" alt="" /></a></p>';
437}
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;}
443
444    # --BEHAVIOR-- adminPostNavLinks
445    $core->callBehavior('adminPostNavLinks', isset($post) ? $post : null, 'post');
446
447    echo '</p>';
448}
449
450# Exit if we cannot view page
451if (!$can_view_page) {
452    dcPage::helpBlock('core_post');
453    dcPage::close();
454    exit;
455}
456
457# Controls comments or trakbacks capabilities
458$isContributionAllowed = function ($id, $dt, $com = true) {
459    global $core;
460
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;
476};
477
478# Show comments or trackbacks
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>';
490    $comments = array();
491    if (isset($_REQUEST['comments'])) {
492        foreach ($_REQUEST['comments'] as $v) {
493            $comments[(integer) $v] = true;
494        }
495    }
496
497    while ($rs->fetch()) {
498        $comment_url = $core->adminurl->get("admin.comment", array('id' => $rs->comment_id));
499
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        }
515
516        echo
517        '<tr class="line' . ($rs->comment_status != 1 ? ' offline' : '') . '"' .
518        ' id="c' . $rs->comment_id . '">' .
519
520        '<td class="nowrap">' .
521        ($has_action ? form::checkbox(array('comments[]'), $rs->comment_id,
522            array(
523                'checked'    => isset($comments[$rs->comment_id]),
524                'extra_html' => 'title="' . ($tb ? __('select this trackback') : __('select this comment') . '"')
525            )
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>' .
529        '<td class="nowrap"><a href="' . $core->adminurl->get("admin.comments", array('ip' => $rs->comment_ip)) . '">' . $rs->comment_ip . '</a></td>' .
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>' .
533
534            '</tr>';
535    }
536
537    echo '</table></div>';
538};
539
540/* Post form if we can edit post
541-------------------------------------------------------- */
542if ($can_edit_post) {
543    $sidebar_items = new ArrayObject(array(
544        'status-box'  => array(
545            'title' => __('Status'),
546            'items' => array(
547                'post_status' =>
548                '<p class="entry-status"><label for="post_status">' . __('Entry status') . ' ' . $img_status . '</label>' .
549                form::combo('post_status', $status_combo,
550                    array('default' => $post_status, 'class' => 'maximal', 'disabled' => !$can_publish)) .
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' : '')) .
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
559                form::datetime('post_dt', array(
560                'default' => html::escapeHTML(dt::str('%Y-%m-%dT%H:%M', strtotime($post_dt))),
561                'class' => ($bad_dt ? 'invalid' : '')
562                )) .
563                 */
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="' .
575                $core->adminurl->get('admin.post', array('id' => $post_id, 'xconv' => '1')) .
576                '">' .
577                __('Convert to XHTML') . '</a></p></div>')),
578        'metas-box'   => array(
579            'title' => __('Filing'),
580            'items' => array(
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) ?
592                    '<div>' .
593                    '<h5 id="create_cat">' . __('Add a new category') . '</h5>' .
594                    '<p><label for="new_cat_title">' . __('Title:') . ' ' .
595                    form::field('new_cat_title', 30, 255, array('class' => 'maximal')) . '</label></p>' .
596                    '<p><label for="new_cat_parent">' . __('Parent:') . ' ' .
597                    form::combo('new_cat_parent', $categories_combo, '', 'maximal') .
598                    '</label></p>' .
599                    '</div>'
600                    : '') .
601                '</div>')),
602        'options-box' => array(
603            'title' => __('Options'),
604            'items' => array(
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                        '' :
614                        '<p class="form-note warn">' .
615                        __('Warning: Comments are not more accepted for this entry.') . '</p>') :
616                    '<p class="form-note warn">' .
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>'
640            ))));
641
642    $main_items = new ArrayObject(array(
643        "post_title"   =>
644        '<p class="col">' .
645        '<label class="required no-margin bold" for="post_title"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label>' .
646        form::field('post_title', 20, 255, array(
647            'default'    => html::escapeHTML($post_title),
648            'class'      => 'maximal',
649            'extra_html' => 'required placeholder="' . __('Title') . '"'
650        )) .
651        '</p>',
652
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>',
658
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'),
663            array(
664                'default'    => html::escapeHTML($post_content),
665                'extra_html' => 'required placeholder="' . __('Content') . '"'
666            )) .
667        '</p>',
668
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>'
674    )
675    );
676
677    # --BEHAVIOR-- adminPostFormItems
678    $core->callBehavior('adminPostFormItems', $main_items, $sidebar_items, isset($post) ? $post : null, 'post');
679
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">';
685
686    echo '<h3 class="out-of-screen-if-js">' . __('Edit post') . '</h3>';
687
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;
726        }
727        echo '</div>';
728    }
729
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
746    $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC');
747
748    $comments = $core->blog->getComments(array_merge($params, array('comment_trackback' => 0)));
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) .
775        form::hidden(array('section'), 'comments') .
776        form::hidden(array('id'), $post_id) .
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>' .
792    form::field('comment_author', 30, 255, array(
793        'default'    => html::escapeHTML($core->auth->getInfo('user_cn')),
794        'extra_html' => 'required placeholder="' . __('Author') . '"'
795    )) .
796    '</p>' .
797
798    '<p><label for="comment_email">' . __('Email:') . '</label>' .
799    form::email('comment_email', 30, 255, html::escapeHTML($core->auth->getInfo('user_email'))) .
800    '</p>' .
801
802    '<p><label for="comment_site">' . __('Web site:') . '</label>' .
803    form::url('comment_site', 30, 255, html::escapeHTML($core->auth->getInfo('user_url'))) .
804    '</p>' .
805
806    '<p class="area"><label for="comment_content" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' .
807    __('Comment:') . '</label> ' .
808    form::textarea('comment_content', 50, 8, array('extra_html' => 'required placeholder="' . __('Comment') . '"')) .
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
826    $params     = array('post_id' => $post_id, 'order' => 'comment_dt ASC');
827    $trackbacks = $core->blog->getComments(array_merge($params, array('comment_trackback' => 1)));
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) .
862        form::hidden(array('section'), 'trackbacks') .
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">';
874
875        echo
876        '<h3>' . __('Ping blogs') . '</h3>' .
877        '<form action="' . $core->adminurl->get("admin.post", array('id' => $post_id)) . '" id="trackback-form" method="post">' .
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="' .
890            $core->adminurl->get("admin.post", array('id' => $post_id, 'tb_auto' => 1, 'tb' => 1)) .
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>';
908        }
909
910        echo '</div>';
911    }
912
913    echo '</div>'; #trackbacks
914}
915
916dcPage::helpBlock('core_post', 'core_trackbacks', 'core_wiki');
917dcPage::close();
Note: See TracBrowser for help on using the repository browser.

Sites map