Dotclear

source: admin/post.php @ 2711:fab26880034e

Revision 2711:fab26880034e, 28.9 KB checked in by Dsls, 11 years ago (diff)

Merge

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

Sites map