Dotclear

source: admin/post.php @ 2761:6b76144ca48b

Revision 2761:6b76144ca48b, 27.5 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

CKEditor can now load external plugins such as tags, series,...
Closes #1992

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

Sites map