Dotclear

source: admin/post.php @ 1719:b8c48f380463

Revision 1719:b8c48f380463, 23.1 KB checked in by Dsls, 11 years ago (diff)

Added dcAdminCombos utility class, lots of combos available from everywhere now. Closes #1599

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

Sites map