Dotclear

source: admin/post.php @ 2854:2d4e6314b899

Revision 2854:2d4e6314b899, 27.7 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Add tags into inject ckeditor for adminPostEditor behavior
Addresses #2011

@TODO : need to find a way to add multiple context: for example comment tab on admin/post.php page

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

Sites map