Dotclear

source: admin/post.php @ 1619:5d925866b5b3

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

page_php: restore forgoten Hide in widget Pages
post_php: Include conversion button in hide/show syntax box

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::success(__('Entry has been successfully updated.'));
373}
374elseif (!empty($_GET['crea'])) {
375     dcPage::success(__('Entry has been successfully created.'));
376}
377elseif (!empty($_GET['attached'])) {
378     dcPage::success(__('File has been successfully attached.'));
379}
380elseif (!empty($_GET['rmattach'])) {
381     dcPage::success(__('Attachment has been successfully removed.'));
382}
383
384if (!empty($_GET['creaco'])) {
385     dcPage::success(__('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                         '<div>'.
442                         '<h5 id="label_format"><label for="post_format" class="ib">'.__('Text formating').'</label></h5>'.
443                         '<p>'.form::combo('post_format',$formaters_combo,$post_format,'maximal').
444                         '</p>'.
445                         '<p>'.($post_id && $post_format != 'xhtml' ? 
446                         '<a id="convert-xhtml" class="button maximal" href="post.php?id='.$post_id.'&amp;xconv=1">'.
447                         __('Convert to XHTML').'</a>' : '').'</p></div>')),
448          'metas-box' => array(
449               'title' => __('Ordering'),
450               'items' => array(
451                    'post_selected' => 
452                         '<p><label for="post_selected" class="classic">'.
453                         form::checkbox('post_selected',1,$post_selected).' '.
454                         __('Selected entry').'</label></p>',
455                    'cat_id' =>
456                         '<p><label for="cat_id" class="ib">'.__('Category').'</label>'.
457                         form::combo('cat_id',$categories_combo,$cat_id,'maximal').
458                         '</p>'.
459                         ($core->auth->check('categories', $core->blog->id) ?
460                              '<div>'.
461                              '<h5 id="create_cat">'.__('Add a new category').'</h5>'.
462                              '<p><label for="new_cat_title">'.__('Title:').' '.
463                              form::field('new_cat_title',30,255,'','maximal').'</label></p>'.
464                              '<p><label for="new_cat_parent">'.__('Parent:').' '.
465                              form::combo('new_cat_parent',$categories_combo,'','maximal').
466                              '</label></p>'.
467                              '</div>'
468                         : ''))),
469          'options-box' => array(
470               'title' => __('Options'),
471               'items' => array(
472                    'post_open_comment' =>
473                         '<p><label for="post_open_comment" class="classic">'.
474                         form::checkbox('post_open_comment',1,$post_open_comment).' '.
475                         __('Accept comments').'</label></p>'.
476                         ($core->blog->settings->system->allow_comments ? 
477                              (isContributionAllowed($post_id,strtotime($post_dt),true) ? 
478                                   '' :
479                                   '<p class="form-note warn">'.
480                                   __('Warning: Comments are not more accepted for this entry.').'</p>') : 
481                              '<p class="form-note warn">'.
482                              __('Warning: Comments are not accepted on this blog.').'</p>'),
483                    'post_open_tb' =>
484                         '<p><label for="post_open_tb" class="classic">'.
485                         form::checkbox('post_open_tb',1,$post_open_tb).' '.
486                         __('Accept trackbacks').'</label></p>'.
487                         ($core->blog->settings->system->allow_trackbacks ? 
488                              (isContributionAllowed($post_id,strtotime($post_dt),false) ? 
489                                   '' :
490                                   '<p class="form-note warn">'.
491                                   __('Warning: Trackbacks are not more accepted for this entry.').'</p>') : 
492                              '<p class="form-note warn">'.__('Warning: Trackbacks are not accepted on this blog.').'</p>'),
493                    'post_password' =>
494                         '<p><label for="post_password" class="ib">'.__('Password').'</label>'.
495                         form::field('post_password',10,32,html::escapeHTML($post_password),'maximal').
496                         '</p>',
497                    'post_url' =>
498                         '<div class="lockable">'.
499                         '<p><label for="post_url" class="ib">'.__('Edit basename').'</label>'.
500                         form::field('post_url',10,255,html::escapeHTML($post_url),'maximal').
501                         '</p>'.
502                         '<p class="form-note warn">'.
503                         __('Warning: If you set the URL manually, it may conflict with another entry.').
504                         '</p></div>'
505     ))));
506
507     $main_items = new ArrayObject(array(
508          "post_title" =>
509               '<p class="col">'.
510               '<label class="required no-margin"><abbr title="'.__('Required field').'">*</abbr> '.__('Title:').'</label>'.
511               form::field('post_title',20,255,html::escapeHTML($post_title),'maximal').
512               '</p>',
513         
514          "post_excerpt" =>
515               '<p class="area" id="excerpt-area"><label for="post_excerpt">'.__('Excerpt:').'<span class="form-note">'.
516               __('Add an introduction to the post.').'</span></label> '.
517               form::textarea('post_excerpt',50,5,html::escapeHTML($post_excerpt)).
518               '</p>',
519         
520          "post_content" =>
521               '<p class="area"><label class="required" '.
522               'for="post_content"><abbr title="'.__('Required field').'">*</abbr> '.__('Content:').'</label> '.
523               form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content)).
524               '</p>',
525         
526          "post_notes" =>
527               '<p class="area" id="notes-area"><label for="post_notes">'.__('Personal notes:').'<span class="form-note">'.
528               __('Add unpublished notes.').'</span></label>'.
529               form::textarea('post_notes',50,5,html::escapeHTML($post_notes)).
530               '</p>'
531          )
532     );
533     
534     # --BEHAVIOR-- adminPostFormItems
535     $core->callBehavior('adminPostFormItems',$main_items,$sidebar_items, isset($post) ? $post : null);
536
537     echo '<div class="multi-part" title="'.($post_id ? __('Edit entry') : __('New entry')).'" id="edit-entry">';
538     echo '<form action="post.php" method="post" id="entry-form">';
539     echo '<div id="entry-wrapper">';
540     echo '<div id="entry-content"><div class="constrained">';
541
542     echo '<h3 class="hidden">'.__('Edit post').'</h3>';
543     
544     foreach ($main_items as $id => $item) {
545          echo $item;
546     }
547
548     # --BEHAVIOR-- adminPostForm (may be deprecated)
549     $core->callBehavior('adminPostForm',isset($post) ? $post : null);
550     
551     echo
552     '<p class="border-top">'.
553     ($post_id ? form::hidden('id',$post_id) : '').
554     '<input type="submit" value="'.__('Save').' (s)" '.
555     'accesskey="s" name="save" /> ';
556     if ($post_id) {
557          $preview_url =
558          $core->blog->url.$core->url->getURLFor('preview',$core->auth->userID().'/'.
559          http::browserUID(DC_MASTER_KEY.$core->auth->userID().$core->auth->getInfo('user_pwd')).
560          '/'.$post->post_url);
561          echo '<a id="post-preview" href="'.$preview_url.'" class="button" accesskey="p">'.__('Preview').' (p)'.'</a> ';
562     } else {
563          echo
564          '<a id="post-cancel" href="index.php" class="button" accesskey="c">'.__('Cancel').' (c)</a>';
565     }
566
567     echo
568     ($can_delete ? '<input type="submit" class="delete" value="'.__('Delete').'" name="delete" />' : '').
569     $core->formNonce().
570     '</p>';
571     
572     echo '</div></div>';          // End #entry-content
573     echo '</div>';      // End #entry-wrapper
574
575     echo '<div id="entry-sidebar">';
576     
577     foreach ($sidebar_items as $id => $c) {
578          echo '<div id="'.$id.'" class="box">'.
579               '<h4>'.$c['title'].'</h4>';
580          foreach ($c['items'] as $e_name=>$e_content) {
581               echo $e_content;
582          }
583          echo '</div>';
584     }
585     
586     
587     # --BEHAVIOR-- adminPostFormSidebar (may be deprecated)
588     $core->callBehavior('adminPostFormSidebar',isset($post) ? $post : null);
589     echo '</div>';      // End #entry-sidebar
590
591     echo '</form>';
592     
593     # --BEHAVIOR-- adminPostForm
594     $core->callBehavior('adminPostAfterForm',isset($post) ? $post : null);
595     
596     echo '</div>';
597     
598     if ($post_id && $post->post_status == 1) {
599          echo '<p><a href="trackbacks.php?id='.$post_id.'" class="multi-part">'.
600          __('Ping blogs').'</a></p>';
601     }
602     
603}
604
605
606/* Comments and trackbacks
607-------------------------------------------------------- */
608if ($post_id)
609{
610     $params = array('post_id' => $post_id, 'order' => 'comment_dt ASC');
611     
612     $comments = $core->blog->getComments(array_merge($params,array('comment_trackback'=>0)));
613     $trackbacks = $core->blog->getComments(array_merge($params,array('comment_trackback'=>1)));
614     
615     # Actions combo box
616     $combo_action = array();
617     if ($can_edit_post && $core->auth->check('publish,contentadmin',$core->blog->id))
618     {
619          $combo_action[__('Publish')] = 'publish';
620          $combo_action[__('Unpublish')] = 'unpublish';
621          $combo_action[__('Mark as pending')] = 'pending';
622          $combo_action[__('Mark as junk')] = 'junk';
623     }
624     
625     if ($can_edit_post && $core->auth->check('delete,contentadmin',$core->blog->id))
626     {
627          $combo_action[__('Delete')] = 'delete';
628     }
629     
630     echo
631     '<div id="comments" class="multi-part" title="'.__('Comments').'">';
632         
633     # --BEHAVIOR-- adminCommentsActionsCombo
634     $core->callBehavior('adminCommentsActionsCombo',array(&$combo_action));
635     
636     $has_action = !empty($combo_action) && (!$trackbacks->isEmpty() || !$comments->isEmpty());
637     echo 
638     '<p class="top-add"><a class="button add onblog_link" href="#comment-form">'.__('Add a comment').'</a></p>';
639     
640     if ($has_action) {
641          echo '<form action="comments_actions.php" id="form-comments" method="post" class="clear">';
642     }
643     
644     echo '<h3 class="clear">'.__('Trackbacks').'</h3>';
645     
646     if (!$trackbacks->isEmpty()) {
647          showComments($trackbacks,$has_action,true);
648     } else {
649          echo '<p>'.__('No trackback').'</p>';
650     }
651     
652     echo '<h3>'.__('Comments').'</h3>';
653     if (!$comments->isEmpty()) {
654          showComments($comments,$has_action);
655     } else {
656          echo '<p>'.__('No comment').'</p>';
657     }
658     
659     if ($has_action) {
660          echo
661          '<div class="two-cols">'.
662          '<p class="col checkboxes-helpers"></p>'.
663         
664          '<p class="col right"><label for="action" class="classic">'.__('Selected comments action:').'</label> '.
665          form::combo('action',$combo_action).
666          form::hidden('redir','post.php?id='.$post_id.'&amp;co=1').
667          $core->formNonce().
668          '<input type="submit" value="'.__('ok').'" /></p>'.
669          '</div>'.
670          '</form>';
671     }
672     /* Add a comment
673     -------------------------------------------------------- */
674
675     echo
676     '<div class="fieldset clear">'.
677     '<h3>'.__('Add a comment').'</h3>'.
678     
679     '<form action="comment.php" method="post" id="comment-form">'.
680     '<div class="constrained">'.
681     '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr> '.__('Name:').'</label>'.
682     form::field('comment_author',30,255,html::escapeHTML($core->auth->getInfo('user_cn'))).
683     '</p>'.
684     
685     '<p><label for="comment_email">'.__('Email:').'</label>'.
686     form::field('comment_email',30,255,html::escapeHTML($core->auth->getInfo('user_email'))).
687     '</p>'.
688     
689     '<p><label for="comment_site">'.__('Web site:').'</label>'.
690     form::field('comment_site',30,255,html::escapeHTML($core->auth->getInfo('user_url'))).
691     '</p>'.
692     
693     '<p class="area"><label for="comment_content" class="required"><abbr title="'.__('Required field').'">*</abbr> '.
694     __('Comment:').'</label> '.
695     form::textarea('comment_content',50,8,html::escapeHTML('')).
696     '</p>'.
697     
698     '<p>'.form::hidden('post_id',$post_id).
699     $core->formNonce().
700     '<input type="submit" name="add" value="'.__('Save').'" /></p>'.
701     '</div>'. #constrained
702
703     '</form>'.
704     '</div>'. #add comment
705     '</div>'; #comments
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