Dotclear

source: admin/post.php @ 3703:53c8bef8608a

Revision 3703:53c8bef8608a, 33.7 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use array form of optionnal parameters for form::combo(), code formatting (PSR-2)

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

Sites map