Dotclear

source: admin/post.php @ 2682:cac55fdd7178

Revision 2682:cac55fdd7178, 26.8 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Addresses #1896. Multiple editors.
Fix issue when no editor is activated or when choosen editor has been deactivated.

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

Sites map