Dotclear

source: admin/post.php @ 2761:6b76144ca48b

Revision 2761:6b76144ca48b, 27.5 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

CKEditor can now load external plugins such as tags, series,...
Closes #1992

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

Sites map