Dotclear

source: admin/post.php @ 2385:3939542624d6

Revision 2385:3939542624d6, 26.6 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add l10n for a message, fixes #1780

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

Sites map