Dotclear

source: admin/post.php @ 2708:e8b17b3a7413

Revision 2708:e8b17b3a7413, 27.6 KB checked in by Dsls, 11 years ago (diff)

1st attempt for admin url handler. See #1645, see #1959

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

Sites map