Dotclear

source: admin/post.php @ 3466:bcb5e91ab38f

Revision 3466:bcb5e91ab38f, 28.3 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Fix spacing before « delete » button on post and page edition form

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

Sites map