Dotclear

source: admin/post.php @ 2181:f30610fc3af1

Revision 2181:f30610fc3af1, 26.6 KB checked in by Dsls, 12 years ago (diff)

Non-repeatable notifications, step 1, see #1710.

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

Sites map