Dotclear

source: admin/comment.php @ 1334:bbbe0735f18b

Revision 1334:bbbe0735f18b, 6.8 KB checked in by franck <carnet.franck.paul@…>, 11 years ago (diff)

New dcPage::breadcrumb function, better way to use it, to be continued by me…

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$comment_id = null;
18$comment_dt = '';
19$comment_author = '';
20$comment_email = '';
21$comment_site = '';
22$comment_content = '';
23$comment_ip = '';
24$comment_status = '';
25$comment_trackback = 0;
26$comment_spam_status = '';
27
28# Status combo
29foreach ($core->blog->getAllCommentStatus() as $k => $v) {
30     $status_combo[$v] = (string) $k;
31}
32
33# Adding comment
34if (!empty($_POST['add']) && !empty($_POST['post_id']))
35{
36     try
37     {
38          $rs = $core->blog->getPosts(array('post_id' => $_POST['post_id'], 'post_type' => ''));
39         
40          if ($rs->isEmpty()) {
41               throw new Exception(__('Entry does not exist.'));
42          }
43         
44          $cur = $core->con->openCursor($core->prefix.'comment');
45         
46          $cur->comment_author = $_POST['comment_author'];
47          $cur->comment_email = html::clean($_POST['comment_email']);
48          $cur->comment_site = html::clean($_POST['comment_site']);
49          $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
50          $cur->post_id = (integer) $_POST['post_id'];
51         
52          # --BEHAVIOR-- adminBeforeCommentCreate
53          $core->callBehavior('adminBeforeCommentCreate',$cur);
54         
55          $comment_id = $core->blog->addComment($cur);
56         
57          # --BEHAVIOR-- adminAfterCommentCreate
58          $core->callBehavior('adminAfterCommentCreate',$cur,$comment_id);
59         
60          http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id,false).'&co=1&creaco=1');
61     } catch (Exception $e) {
62          $core->error->add($e->getMessage());
63     }
64}
65
66if (!empty($_REQUEST['id']))
67{
68     $params['comment_id'] = $_REQUEST['id'];
69     
70     try {
71          $rs = $core->blog->getComments($params);
72          if (!$rs->isEmpty()) {
73               $comment_id = $rs->comment_id;
74               $post_id = $rs->post_id;
75               $post_type = $rs->post_type;
76               $post_title = $rs->post_title;
77               $comment_dt = $rs->comment_dt;
78               $comment_author = $rs->comment_author;
79               $comment_email = $rs->comment_email;
80               $comment_site = $rs->comment_site;
81               $comment_content = $rs->comment_content;
82               $comment_ip = $rs->comment_ip;
83               $comment_status = $rs->comment_status;
84               $comment_trackback = (boolean) $rs->comment_trackback;
85               $comment_spam_status = $rs->comment_spam_status;
86          }
87     } catch (Exception $e) {
88          $core->error->add($e->getMessage());
89     }
90}
91
92if (!$comment_id && !$core->error->flag()) {
93     $core->error->add(__('No comment'));
94}
95
96if (!$core->error->flag() && isset($rs))
97{
98     $can_edit = $can_delete = $can_publish = $core->auth->check('contentadmin',$core->blog->id);
99     
100     if (!$core->auth->check('contentadmin',$core->blog->id) && $core->auth->userID() == $rs->user_id) {
101          $can_edit = true;
102          if ($core->auth->check('delete',$core->blog->id)) {
103               $can_delete = true;
104          }
105          if ($core->auth->check('publish',$core->blog->id)) {
106               $can_publish = true;
107          }
108     }
109     
110     # update comment
111     if (!empty($_POST['update']) && $can_edit)
112     {
113          $cur = $core->con->openCursor($core->prefix.'comment');
114         
115          $cur->comment_author = $_POST['comment_author'];
116          $cur->comment_email = html::clean($_POST['comment_email']);
117          $cur->comment_site = html::clean($_POST['comment_site']);
118          $cur->comment_content = $core->HTMLfilter($_POST['comment_content']);
119         
120          if (isset($_POST['comment_status'])) {
121               $cur->comment_status = (integer) $_POST['comment_status'];
122          }
123         
124          try
125          {
126               # --BEHAVIOR-- adminBeforeCommentUpdate
127               $core->callBehavior('adminBeforeCommentUpdate',$cur,$comment_id);
128               
129               $core->blog->updComment($comment_id,$cur);
130               
131               # --BEHAVIOR-- adminAfterCommentUpdate
132               $core->callBehavior('adminAfterCommentUpdate',$cur,$comment_id);
133               
134               http::redirect('comment.php?id='.$comment_id.'&upd=1');
135          }
136          catch (Exception $e)
137          {
138               $core->error->add($e->getMessage());
139          }
140     }
141     
142     if (!empty($_POST['delete']) && $can_delete)
143     {
144          try {
145               # --BEHAVIOR-- adminBeforeCommentDelete
146               $core->callBehavior('adminBeforeCommentDelete',$comment_id);
147               
148               $core->blog->delComment($comment_id);
149               http::redirect($core->getPostAdminURL($rs->post_type,$rs->post_id).'&co=1#c'.$comment_id,false);
150          } catch (Exception $e) {
151               $core->error->add($e->getMessage());
152          }
153     }
154     
155     if (!$can_edit) {
156          $core->error->add(__("You can't edit this comment."));
157     }
158}
159
160/* DISPLAY
161-------------------------------------------------------- */
162dcPage::open(__('Edit comment'),
163     dcPage::jsConfirmClose('comment-form').
164     dcPage::jsToolBar().
165     dcPage::jsLoad('js/_comment.js').
166     # --BEHAVIOR-- adminCommentHeaders
167     $core->callBehavior('adminCommentHeaders')
168);
169
170if ($comment_id)
171{
172     if (!empty($_GET['upd'])) {
173          dcPage::message(__('Comment has been successfully updated.'));
174     }
175     
176     $comment_mailto = '';
177     if ($comment_email)
178     {
179          $comment_mailto = '<a href="mailto:'.html::escapeHTML($comment_email)
180          .'?subject='.rawurlencode(sprintf(__('Your comment on my blog %s'),$core->blog->name))
181          .'&body='
182          .rawurlencode(sprintf(__("Hi!\n\nYou wrote a comment on:\n%s\n\n\n"),$rs->getPostURL()))
183          .'">'.__('Send an e-mail').'</a>';
184     }
185     
186     dcPage::breadcrumb(
187          array(
188               html::escapeHTML($core->blog->name) => '',
189               html::escapeHTML($post_title) => $core->getPostAdminURL($post_type,$post_id).'&amp;co=1#c'.$comment_id,
190               '<span class="page-title">'.__('Edit comment').'</span>' => ''
191          ));
192
193     echo
194     '<form action="comment.php" method="post" id="comment-form">'.
195     '<p>'.__('IP address:').'<br /> '.
196     '<a href="comments.php?ip='.$comment_ip.'">'.$comment_ip.'</a></p>'.
197     
198     '<p>'.__('Date:').'<br /> '.
199     dt::dt2str(__('%Y-%m-%d %H:%M'),$comment_dt).'</p>'.
200     
201     '<p><label for="comment_author" class="required"><abbr title="'.__('Required field').'">*</abbr>'.__('Author:').
202     form::field('comment_author',30,255,html::escapeHTML($comment_author)).
203     '</label></p>'.
204     
205     '<p><label for="comment_email">'.__('Email:').
206     form::field('comment_email',30,255,html::escapeHTML($comment_email)).
207     $comment_mailto.
208     '</label></p>'.
209     
210     '<p><label for="comment_site">'.__('Web site:').
211     form::field('comment_site',30,255,html::escapeHTML($comment_site)).
212     '</label></p>'.
213     
214     '<p><label for="comment_status">'.__('Status:').
215     form::combo('comment_status',$status_combo,$comment_status,'','',!$can_publish).
216     '</label></p>'.
217     
218     # --BEHAVIOR-- adminAfterCommentDesc
219     $core->callBehavior('adminAfterCommentDesc', $rs).
220     
221     '<p class="area"><label for="comment_content">'.__('Comment:').'</label> '.
222     form::textarea('comment_content',50,10,html::escapeHTML($comment_content)).
223     '</p>'.
224     
225     '<p>'.form::hidden('id',$comment_id).
226     $core->formNonce().
227     '<input type="submit" accesskey="s" name="update" value="'.__('Save').'" /> ';
228     
229     if ($can_delete) {
230          echo '<input type="submit" class="delete" name="delete" value="'.__('Delete').'" />';
231     }
232     echo
233     '</p>'.
234     '</form>';
235}
236
237dcPage::helpBlock('core_comments');
238dcPage::close();
239?>
Note: See TracBrowser for help on using the repository browser.

Sites map