Dotclear

source: admin/post.php @ 2722:b09bad9e6f96

Revision 2722:b09bad9e6f96, 28.4 KB checked in by Dsls, 11 years ago (diff)

fixed php notice in post.php

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

Sites map