Dotclear

source: admin/post.php @ 1537:a3ac778e9132

Revision 1537:a3ac778e9132, 21.8 KB checked in by Lepeltier kévin, 12 years ago (diff)

Ticket #1406 : on encapsule new dcMedia dans des try catch pour crriger plusieurs bug.

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

Sites map