Dotclear

source: admin/post.php @ 2064:43a191ddc184

Revision 2064:43a191ddc184, 26.5 KB checked in by Dsls, 12 years ago (diff)

keep comments ids in mind

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

Sites map