Dotclear

source: admin/post.php @ 2694:1873a0e11790

Revision 2694:1873a0e11790, 27.2 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Add link to preferences when no editor has been choosen.
Add an empty option in editor select to see directly no editor has been choosen.
Addresses #1896

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

Sites map