Dotclear

source: admin/post.php @ 2666:88000a305897

Revision 2666:88000a305897, 26.5 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Si je connais les pluriels en anglais ? No comments. Addresses #1470

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

Sites map