Dotclear

source: admin/post.php @ 1621:ee70ba4550a7

Revision 1621:ee70ba4550a7, 24.1 KB checked in by Anne Kozlika <kozlika@…>, 11 years ago (diff)

Page: add New comment button and new comment form in "Comments" tab.
CSS: inputs borders

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

Sites map