Dotclear

source: admin/post.php @ 2681:0d5aeefe7bd8

Revision 2681:0d5aeefe7bd8, 26.6 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Addresse #1896 : simplify; get editor from core instead of retrieve it from parameter

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

Sites map