Dotclear

source: admin/post.php @ 2682:cac55fdd7178

Revision 2682:cac55fdd7178, 26.8 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Addresses #1896. Multiple editors.
Fix issue when no editor is activated or when choosen editor has been deactivated.

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

Sites map