Dotclear

source: admin/post.php @ 1530:18df991c4c1a

Revision 1530:18df991c4c1a, 23.9 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Quick new cat: adjustments after last merge with 2.5.

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12
13require dirname(__FILE__).'/../inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17$post_id = '';
18$cat_id = '';
19$post_dt = '';
20$post_format = $core->auth->getOption('post_format');
21$post_password = '';
22$post_url = '';
23$post_lang = $core->auth->getInfo('user_lang');
24$post_title = '';
25$post_excerpt = '';
26$post_excerpt_xhtml = '';
27$post_content = '';
28$post_content_xhtml = '';
29$post_notes = '';
30$post_status = $core->auth->getInfo('user_post_status');
31$post_selected = false;
32$post_open_comment = $core->blog->settings->system->allow_comments;
33$post_open_tb = $core->blog->settings->system->allow_trackbacks;
34
35$page_title = __('New entry');
36
37$can_view_page = true;
38$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
39$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
40$can_delete = false;
41
42$post_headlink = '<link rel="%s" title="%s" href="post.php?id=%s" />';
43$post_link = '<a href="post.php?id=%s" title="%s">%s</a>';
44
45$next_link = $prev_link = $next_headlink = $prev_headlink = null;
46
47# If user can't publish
48if (!$can_publish) {
49     $post_status = -2;
50}
51
52# Getting categories
53$categories_combo = array('&nbsp;' => '');
54try {
55     $categories = $core->blog->getCategories(array('post_type'=>'post'));
56     while ($categories->fetch()) {
57          $categories_combo[] = new formSelectOption(
58               str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title),
59               $categories->cat_id
60          );
61     }
62} catch (Exception $e) { }
63
64# Status combo
65foreach ($core->blog->getAllPostStatus() as $k => $v) {
66     $status_combo[$v] = (string) $k;
67}
68$img_status_pattern = '<img class="img_select_option" alt="%1$s" title="%1$s" src="images/%2$s" />';
69
70# Formaters combo
71foreach ($core->getFormaters() as $v) {
72     $formaters_combo[$v] = $v;
73}
74
75# Languages combo
76$rs = $core->blog->getLangs(array('order'=>'asc'));
77$all_langs = l10n::getISOcodes(0,1);
78$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
79while ($rs->fetch()) {
80     if (isset($all_langs[$rs->post_lang])) {
81          $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang;
82          unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]);
83     } else {
84          $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang;
85     }
86}
87unset($all_langs);
88unset($rs);
89
90# Validation flag
91$bad_dt = false;
92
93# Get entry informations
94if (!empty($_REQUEST['id']))
95{
96     $page_title = __('Edit entry');
97     
98     $params['post_id'] = $_REQUEST['id'];
99     
100     $post = $core->blog->getPosts($params);
101     
102     if ($post->isEmpty())
103     {
104          $core->error->add(__('This entry does not exist.'));
105          $can_view_page = false;
106     }
107     else
108     {
109          $post_id = $post->post_id;
110          $cat_id = $post->cat_id;
111          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
112          $post_format = $post->post_format;
113          $post_password = $post->post_password;
114          $post_url = $post->post_url;
115          $post_lang = $post->post_lang;
116          $post_title = $post->post_title;
117          $post_excerpt = $post->post_excerpt;
118          $post_excerpt_xhtml = $post->post_excerpt_xhtml;
119          $post_content = $post->post_content;
120          $post_content_xhtml = $post->post_content_xhtml;
121          $post_notes = $post->post_notes;
122          $post_status = $post->post_status;
123          $post_selected = (boolean) $post->post_selected;
124          $post_open_comment = (boolean) $post->post_open_comment;
125          $post_open_tb = (boolean) $post->post_open_tb;
126         
127          $can_edit_post = $post->isEditable();
128          $can_delete= $post->isDeletable();
129         
130          $next_rs = $core->blog->getNextPost($post,1);
131          $prev_rs = $core->blog->getNextPost($post,-1);
132         
133          if ($next_rs !== null) {
134               $next_link = sprintf($post_link,$next_rs->post_id,
135                    html::escapeHTML($next_rs->post_title),__('Next entry').'&nbsp;&#187;');
136               $next_headlink = sprintf($post_headlink,'next',
137                    html::escapeHTML($next_rs->post_title),$next_rs->post_id);
138          }
139         
140          if ($prev_rs !== null) {
141               $prev_link = sprintf($post_link,$prev_rs->post_id,
142                    html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('Previous entry'));
143               $prev_headlink = sprintf($post_headlink,'previous',
144                    html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);
145          }
146         
147          try {
148               $core->media = new dcMedia($core);
149          } catch (Exception $e) {}
150     }
151}
152
153# Format excerpt and content
154if (!empty($_POST) && $can_edit_post)
155{
156     $post_format = $_POST['post_format'];
157     $post_excerpt = $_POST['post_excerpt'];
158     $post_content = $_POST['post_content'];
159     
160     $post_title = $_POST['post_title'];
161     
162     $cat_id = (integer) $_POST['cat_id'];
163     
164     if (isset($_POST['post_status'])) {
165          $post_status = (integer) $_POST['post_status'];
166     }
167     
168     if (empty($_POST['post_dt'])) {
169          $post_dt = '';
170     } else {
171          try
172          {
173               $post_dt = strtotime($_POST['post_dt']);
174               if ($post_dt == false || $post_dt == -1) {
175                    $bad_dt = true;
176                    throw new Exception(__('Invalid publication date'));
177               }
178               $post_dt = date('Y-m-d H:i',$post_dt);
179          }
180          catch (Exception $e)
181          {
182               $core->error->add($e->getMessage());
183          }
184     }
185     
186     $post_open_comment = !empty($_POST['post_open_comment']);
187     $post_open_tb = !empty($_POST['post_open_tb']);
188     $post_selected = !empty($_POST['post_selected']);
189     $post_lang = $_POST['post_lang'];
190     $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null;
191     
192     $post_notes = $_POST['post_notes'];
193     
194     if (isset($_POST['post_url'])) {
195          $post_url = $_POST['post_url'];
196     }
197     
198     $core->blog->setPostContent(
199          $post_id,$post_format,$post_lang,
200          $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
201     );
202}
203
204# Delete post
205if (!empty($_POST['delete']) && $can_delete)
206{
207     try {
208          # --BEHAVIOR-- adminBeforePostDelete
209          $core->callBehavior('adminBeforePostDelete',$post_id);
210          $core->blog->delPost($post_id);
211          http::redirect('posts.php');
212     } catch (Exception $e) {
213          $core->error->add($e->getMessage());
214     }
215}
216
217# Create or update post
218if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post && !$bad_dt)
219{
220     # Create category
221     if (!empty($_POST['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) {
222     
223          $cur_cat = $core->con->openCursor($core->prefix.'category');
224          $cur_cat->cat_title = $_POST['new_cat_title'];
225          $cur_cat->cat_url = '';
226         
227          $parent_cat = !empty($_POST['new_cat_parent']) ? $_POST['new_cat_parent'] : '';
228         
229          # --BEHAVIOR-- adminBeforeCategoryCreate
230          $core->callBehavior('adminBeforeCategoryCreate', $cur_cat);
231         
232          $cat_id = $core->blog->addCategory($cur_cat, (integer) $parent_cat);
233         
234          # --BEHAVIOR-- adminAfterCategoryCreate
235          $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $cat_id);
236     }
237     
238     $cur = $core->con->openCursor($core->prefix.'post');
239     
240     $cur->post_title = $post_title;
241     $cur->cat_id = ($cat_id ? $cat_id : null);
242     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';
243     $cur->post_format = $post_format;
244     $cur->post_password = $post_password;
245     $cur->post_lang = $post_lang;
246     $cur->post_title = $post_title;
247     $cur->post_excerpt = $post_excerpt;
248     $cur->post_excerpt_xhtml = $post_excerpt_xhtml;
249     $cur->post_content = $post_content;
250     $cur->post_content_xhtml = $post_content_xhtml;
251     $cur->post_notes = $post_notes;
252     $cur->post_status = $post_status;
253     $cur->post_selected = (integer) $post_selected;
254     $cur->post_open_comment = (integer) $post_open_comment;
255     $cur->post_open_tb = (integer) $post_open_tb;
256     
257     if (isset($_POST['post_url'])) {
258          $cur->post_url = $post_url;
259     }
260     
261     # Update post
262     if ($post_id)
263     {
264          try
265          {
266               # --BEHAVIOR-- adminBeforePostUpdate
267               $core->callBehavior('adminBeforePostUpdate',$cur,$post_id);
268               
269               $core->blog->updPost($post_id,$cur);
270               
271               # --BEHAVIOR-- adminAfterPostUpdate
272               $core->callBehavior('adminAfterPostUpdate',$cur,$post_id);
273               
274               http::redirect('post.php?id='.$post_id.'&upd=1');
275          }
276          catch (Exception $e)
277          {
278               $core->error->add($e->getMessage());
279          }
280     }
281     else
282     {
283          $cur->user_id = $core->auth->userID();
284         
285          try
286          {
287               # --BEHAVIOR-- adminBeforePostCreate
288               $core->callBehavior('adminBeforePostCreate',$cur);
289               
290               $return_id = $core->blog->addPost($cur);
291               
292               # --BEHAVIOR-- adminAfterPostCreate
293               $core->callBehavior('adminAfterPostCreate',$cur,$return_id);
294               
295               http::redirect('post.php?id='.$return_id.'&crea=1');
296          }
297          catch (Exception $e)
298          {
299               $core->error->add($e->getMessage());
300          }
301     }
302}
303
304# Getting categories
305$categories_combo = array(__('(No cat)') => '');
306try {
307     $categories = $core->blog->getCategories(array('post_type'=>'post'));
308     if (!$categories->isEmpty()) {
309          while ($categories->fetch()) {
310               $catparents_combo[] = $categories_combo[] = new formSelectOption(
311                    str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title),
312                    $categories->cat_id
313               );
314          }
315     }
316} catch (Exception $e) { }
317
318/* DISPLAY
319-------------------------------------------------------- */
320$default_tab = 'edit-entry';
321if (!$can_edit_post) {
322     $default_tab = '';
323}
324if (!empty($_GET['co'])) {
325     $default_tab = 'comments';
326}
327
328if ($post_id) {
329     switch ($post_status) {
330          case 1:
331               $img_status = sprintf($img_status_pattern,__('Published'),'check-on.png');
332               break;
333          case 0:
334               $img_status = sprintf($img_status_pattern,__('Unpublished'),'check-off.png');
335               break;
336          case -1:
337               $img_status = sprintf($img_status_pattern,__('Scheduled'),'scheduled.png');
338               break;
339          case -2:
340               $img_status = sprintf($img_status_pattern,__('Pending'),'check-wrn.png');
341               break;
342          default:
343               $img_status = '';
344     }
345     $edit_entry_str = __('&ldquo;%s&rdquo;');
346     $page_title_edit = sprintf($edit_entry_str, html::escapeHTML($post_title)).' '.$img_status;
347} else {
348     $img_status = '';
349}
350
351
352dcPage::open($page_title.' - '.__('Entries'),
353     dcPage::jsDatePicker().
354     dcPage::jsToolBar().
355     dcPage::jsModal().
356     dcPage::jsMetaEditor().
357     dcPage::jsLoad('js/_post.js').
358     dcPage::jsConfirmClose('entry-form','comment-form').
359     # --BEHAVIOR-- adminPostHeaders
360     $core->callBehavior('adminPostHeaders').
361     dcPage::jsPageTabs($default_tab).
362     $next_headlink."\n".$prev_headlink,
363     dcPage::breadcrumb(
364          array(
365               html::escapeHTML($core->blog->name) => '',
366               __('Entries') => 'posts.php',
367               '<span class="page-title">'.($post_id ? $page_title_edit : $page_title).'</span>' => ''
368          ))
369);
370
371if (!empty($_GET['upd'])) {
372     dcPage::message(__('Entry has been successfully updated.'));
373}
374elseif (!empty($_GET['crea'])) {
375     dcPage::message(__('Entry has been successfully created.'));
376}
377elseif (!empty($_GET['attached'])) {
378     dcPage::message(__('File has been successfully attached.'));
379}
380elseif (!empty($_GET['rmattach'])) {
381     dcPage::message(__('Attachment has been successfully removed.'));
382}
383
384if (!empty($_GET['creaco'])) {
385     dcPage::message(__('Comment has been successfully created.'));
386}
387
388# XHTML conversion
389if (!empty($_GET['xconv']))
390{
391     $post_excerpt = $post_excerpt_xhtml;
392     $post_content = $post_content_xhtml;
393     $post_format = 'xhtml';
394     
395     dcPage::message(__('Don\'t forget to validate your XHTML conversion by saving your post.'));
396}
397
398if ($post_id && $post->post_status == 1) {
399     echo '<p><a class="onblog_link" href="'.$post->getURL().'" onclick="window.open(this.href);return false;" title="'.$post_title.' ('.__('new window').')'.'">'.__('Go to this entry on the site').' <img src="images/outgoing-blue.png" alt="" /></a></p>';
400}
401if ($post_id)
402{
403     echo '<p class="nav_prevnext">';
404     if ($prev_link) { echo $prev_link; }
405     if ($next_link && $prev_link) { echo ' | '; }
406     if ($next_link) { echo $next_link; }
407     
408     # --BEHAVIOR-- adminPostNavLinks
409     $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null);
410     
411     echo '</p>';
412}
413
414# Exit if we cannot view page
415if (!$can_view_page) {
416     dcPage::helpBlock('core_post');
417     dcPage::close();
418     exit;
419}
420/* Post form if we can edit post
421-------------------------------------------------------- */
422if ($can_edit_post)
423{
424     $sidebar_items = new ArrayObject(array(
425          'status-box' => array(
426               'title' => __('Status'),
427               'items' => array(
428                    'post_status' => 
429                         '<p class="entry-status"><label for="post_status" class="ib">'.__('Entry status').' '.$img_status.'</label>'.
430                         form::combo('post_status',$status_combo,$post_status,'maximal','',!$can_publish).
431                         '</p>',
432                    'post_dt' => 
433                         '<p><label for="post_dt" class="ib">'.__('Publication date and hour').'</label>'.
434                         form::field('post_dt',16,16,$post_dt,($bad_dt ? 'invalid' : '')).
435                         '</p>',
436                    'post_lang' =>
437                         '<p><label for="post_lang" class="ib">'.__('Entry lang').'</label>'.
438                         form::combo('post_lang',$lang_combo,$post_lang).
439                         '</p>',
440                    'post_format' =>
441                         '<p><label for="post_format" class="ib">'.__('Text formating').'</label>'.
442                         form::combo('post_format',$formaters_combo,$post_format,'maximal').
443                         '</p>'.
444                         '<p>'.($post_id && $post_format != 'xhtml' ? 
445                         '<a id="convert-xhtml" class="button maximal" href="post.php?id='.$post_id.'&amp;xconv=1">'.
446                         __('Convert to XHTML').'</a>' : '').'</p>')),
447          'metas-box' => array(
448               'title' => __('Ordering'),
449               'items' => array(
450                    'post_selected' => 
451                         '<p><label for="post_selected" class="classic">'.
452                         form::checkbox('post_selected',1,$post_selected).' '.
453                         __('Selected entry').'</label></p>',
454                    'cat_id' =>
455                         '<p><label for="cat_id" class="ib">'.__('Category').'</label>'.
456                         form::combo('cat_id',$categories_combo,$cat_id,'maximal').
457                         '</p>'.
458                         ($core->auth->check('categories', $core->blog->id) ?
459                              '<div>'.
460                              '<h5 id="create_cat">'.__('Add a new category').'</h5>'.
461                              '<p><label for="new_cat_title">'.__('Title:').' '.
462                              form::field('new_cat_title',30,255,'','maximal').'</label></p>'.
463                              '<p><label for="new_cat_parent">'.__('Parent:').' '.
464                              form::combo('new_cat_parent',$categories_combo,'','maximal').
465                              '</label></p>'.
466                              '</div>'
467                         : ''))),
468          'options-box' => array(
469               'title' => __('Options'),
470               'items' => array(
471                    'post_open_comment' =>
472                         '<p><label for="post_open_comment" class="classic">'.
473                         form::checkbox('post_open_comment',1,$post_open_comment).' '.
474                         __('Accept comments').'</label></p>'.
475                         ($core->blog->settings->system->allow_comments ? 
476                              (isContributionAllowed($post_id,strtotime($post_dt),true) ? 
477                                   '' :
478                                   '<p class="form-note warn">'.
479                                   __('Warning: Comments are not more accepted for this entry.').'</p>') : 
480                              '<p class="form-note warn">'.
481                              __('Warning: Comments are not accepted on this blog.').'</p>'),
482                    'post_open_tb' =>
483                         '<p><label for="post_open_tb" class="classic">'.
484                         form::checkbox('post_open_tb',1,$post_open_tb).' '.
485                         __('Accept trackbacks').'</label></p>'.
486                         ($core->blog->settings->system->allow_trackbacks ? 
487                              (isContributionAllowed($post_id,strtotime($post_dt),false) ? 
488                                   '' :
489                                   '<p class="form-note warn">'.
490                                   __('Warning: Trackbacks are not more accepted for this entry.').'</p>') : 
491                              '<p class="form-note warn">'.__('Warning: Trackbacks are not accepted on this blog.').'</p>'),
492                    'post_password' =>
493                         '<p><label for="post_password" class="ib">'.__('Password').'</label>'.
494                         form::field('post_password',10,32,html::escapeHTML($post_password),'maximal').
495                         '</p>',
496                    'post_url' =>
497                         '<div class="lockable">'.
498                         '<p><label for="post_url" class="ib">'.__('Edit basename').'</label>'.
499                         form::field('post_url',10,255,html::escapeHTML($post_url),'maximal').
500                         '</p>'.
501                         '<p class="form-note warn">'.
502                         __('Warning: If you set the URL manually, it may conflict with another entry.').
503                         '</p></div>'
504     ))));
505
506     $main_items = new ArrayObject(array(
507          "post_title" =>
508               '<p class="col">'.
509               '<label class="required no-margin"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
510               form::field('post_title',20,255,html::escapeHTML($post_title),'maximal').
511               '</p>',
512         
513          "post_excerpt" =>
514               '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'<span class="form-note">'.
515               __('Add an introduction to the post.').'</span></label> '.
516               form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)).
517               '</p>',
518         
519          "post_content" =>
520               '<p class="area"><label class="required" '.
521               'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
522               form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)).
523               '</p>',
524         
525          "post_notes" =>
526               '<p class="area" id="notes-area"><label for="post_notes">'.__('Personal notes:').'<span class="form-note">'.
527               __('Add unpublished notes.').'</span></label>'.
528               form::textarea('post_notes',50,5,html::escapeHTML($post_notes)).
529               '</p>'
530          )
531     );
532     
533     # --BEHAVIOR-- adminPostFormItems
534     $core->callBehavior('adminPostFormItems',$main_items,$sidebar_items, isset($post) ? $post : null);
535
536     echo '<div class="multi-part" title="'.($post_id ? __('Edit entry') : __('New entry')).'" id="edit-entry">';
537     echo '<form action="post.php" method="post" id="entry-form">';
538     echo '<div id="entry-wrapper">';
539     echo '<div id="entry-content"><div class="constrained">';
540
541     echo '<h3 class="hidden">'.__('Edit post').'</h3>';
542     
543     foreach ($main_items as $id => $item) {
544          echo $item;
545     }
546
547     # --BEHAVIOR-- adminPostForm (may be deprecated)
548     $core->callBehavior('adminPostForm',isset($post) ? $post : null);
549     
550     echo
551     '<p class="border-top">'.
552     ($post_id ? form::hidden('id',$post_id) : '').
553     '<input type="submit" value="'.__('Save').' (s)" '.
554     'accesskey="s" name="save" /> ';
555     if ($post_id) {
556          $preview_url =
557          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'.
558          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
559          '/'.$post->post_url);
560          echo '<a id="post-preview" href="'.$preview_url.'" class="button" accesskey="p">'.__('Preview').' (p)'.'</a> ';
561     } else {
562          echo
563          '<a id="post-cancel" href="index.php" class="button" accesskey="c">'.__('Cancel').' (c)</a>';
564     }
565
566     echo
567     ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : '').
568     $core->formNonce().
569     '</p>';
570     
571     echo '</div></div>';          // End #entry-content
572     echo '</div>';      // End #entry-wrapper
573
574     echo '<div id="entry-sidebar">';
575     
576     foreach ($sidebar_items as $id => $c) {
577          echo '<div id="'.$id.'" class="box">'.
578               '<h4>'.$c['title'].'</h4>';
579          foreach ($c['items'] as $e_name=>$e_content) {
580               echo $e_content;
581          }
582          echo '</div>';
583     }
584     
585     
586     # --BEHAVIOR-- adminPostFormSidebar (may be deprecated)
587     $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null);
588     echo '</div>';      // End #entry-sidebar
589
590     echo '</form>';
591     
592     # --BEHAVIOR-- adminPostForm
593     $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null);
594     
595     echo '</div>';
596     
597     if ($post_id && $post->post_status == 1) {
598          echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'.
599          __('Ping blogs').'</a></p>';
600     }
601     
602}
603
604
605/* Comments and trackbacks
606-------------------------------------------------------- */
607if ($post_id)
608{
609     $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC');
610     
611     $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0)));
612     $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1)));
613     
614     # Actions combo box
615     $combo_action = array();
616     if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id))
617     {
618          $combo_action[__('Publish')] = 'publish';
619          $combo_action[__('Unpublish')] = 'unpublish';
620          $combo_action[__('Mark as pending')] = 'pending';
621          $combo_action[__('Mark as junk')] = 'junk';
622     }
623     
624     if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id))
625     {
626          $combo_action[__('Delete')] = 'delete';
627     }
628     
629     # --BEHAVIOR-- adminCommentsActionsCombo
630     $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
631     
632     $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty());
633     
634     echo
635     '<div id="comments" class="multi-part" title="'.__('Comments').'">';
636     
637     if ($has_action) {
638          echo '<form action="comments_actions.php" id="form-comments" method="post">';
639     }
640     
641     echo '<h3>'.__('Trackbacks').'</h3>';
642     
643     if (!$trackbacks->isEmpty()) {
644          showComments($trackbacks,$has_action,true);
645     } else {
646          echo '<p>'.__('No trackback').'</p>';
647     }
648     
649     echo '<h3>'.__('Comments').'</h3>';
650     if (!$comments->isEmpty()) {
651          showComments($comments,$has_action);
652     } else {
653          echo '<p>'.__('No comment').'</p>';
654     }
655     
656     if ($has_action) {
657          echo
658          '<div class="two-cols">'.
659          '<p class="col checkboxes-helpers"></p>'.
660         
661          '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
662          form::combo('action',$combo_action).
663          form::hidden('redir','post.php?id='.$post_id.'&amp;co=1').
664          $core->formNonce().
665          '<input type="submit" value="'.__('ok').'" /></p>'.
666          '</div>'.
667          '</form>';
668     }
669     
670     echo '</div>';
671}
672
673/* Add a comment
674-------------------------------------------------------- */
675if ($post_id)
676{
677     echo
678     '<div class="multi-part" id="add-comment" title="'.__('Add a comment').'">'.
679     '<h3>'.__('Add a comment').'</h3>'.
680     
681     '<form action="comment.php" method="post" id="comment-form">'.
682     '<div class="constrained">'.
683     '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').'</label>'.
684     form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))).
685     '</p>'.
686     
687     '<p><label for="comment_email">'.__('Email:').'</label>'.
688     form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))).
689     '</p>'.
690     
691     '<p><label for="comment_site">'.__('Web site:').'</label>'.
692     form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))).
693     '</p>'.
694     
695     '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '.
696     __('Comment:').'</label> '.
697     form::textarea('comment_content',50,8,html::escapeHTML('')).
698     '</p>'.
699     
700     '<p>'.form::hidden('post_id',$post_id).
701     $core->formNonce().
702     '<input type="submit" name="add" value="'.__('Save').'" /></p>'.
703     '</div>'.
704     '</form>'.
705     '</div>';
706}
707
708# Controls comments or trakbacks capabilities
709function isContributionAllowed($id,$dt,$com=true)
710{
711     global $core;
712
713     if (!$id) {
714          return true;
715     }
716     if ($com) {
717          if (($core->blog->settings->system->comments_ttl == 0) || 
718               (time() - $core->blog->settings->system->comments_ttl*86400 < $dt)) {
719               return true;
720          }
721     } else {
722          if (($core->blog->settings->system->trackbacks_ttl == 0) || 
723               (time() - $core->blog->settings->system->trackbacks_ttl*86400 < $dt)) {
724               return true;
725          }
726     }
727     return false;
728}
729
730# Show comments or trackbacks
731function showComments($rs,$has_action,$tb=false)
732{
733     echo
734     '<table class="comments-list"><tr>'.
735     '<th colspan="2" class="first">'.__('Author').'</th>'.
736     '<th>'.__('Date').'</th>'.
737     '<th class="nowrap">'.__('IP address').'</th>'.
738     '<th>'.__('Status').'</th>'.
739     '<th>'.__('Edit').'</th>'.
740     '</tr>';
741     
742     while($rs->fetch())
743     {
744          $comment_url = 'comment.php?id='.$rs->comment_id;
745         
746          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />';
747          switch ($rs->comment_status) {
748               case 1:
749                    $img_status = sprintf($img,__('Published'),'check-on.png');
750                    break;
751               case 0:
752                    $img_status = sprintf($img,__('Unpublished'),'check-off.png');
753                    break;
754               case -1:
755                    $img_status = sprintf($img,__('Pending'),'check-wrn.png');
756                    break;
757               case -2:
758                    $img_status = sprintf($img,__('Junk'),'junk.png');
759                    break;
760          }
761         
762          echo
763          '<tr class="line'.($rs->comment_status != 1 ? ' offline' : '').'"'.
764          ' id="c'.$rs->comment_id.'">'.
765         
766          '<td class="nowrap">'.
767          ($has_action ? form::checkbox(array('comments[]'),$rs->comment_id,'','','',0,'title="'.($tb ? __('select this trackback') : __('select this comment')).'"') : '').'</td>'.
768          '<td class="maximal">'.html::escapeHTML($rs->comment_author).'</td>'.
769          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rs->comment_dt).'</td>'.
770          '<td class="nowrap"><a href="comments.php?ip='.$rs->comment_ip.'">'.$rs->comment_ip.'</a></td>'.
771          '<td class="nowrap status">'.$img_status.'</td>'.
772          '<td class="nowrap status"><a href="'.$comment_url.'">'.
773          '<img src="images/edit-mini.png" alt="" title="'.__('Edit this comment').'" /> '.__('Edit').'</a></td>'.
774         
775          '</tr>';
776     }
777     
778     echo '</table>';
779}
780
781dcPage::helpBlock('core_post','core_trackbacks','core_wiki');
782dcPage::close();
783?>
Note: See TracBrowser for help on using the repository browser.

Sites map