1 | <?php |
---|
2 | /* Code adapted from include/picture_comment.inc.php and picture.php */ |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // Category's infos |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | $category = $page['category']; |
---|
9 | |
---|
10 | $url_self = duplicate_index_url(array( |
---|
11 | 'category' => array( |
---|
12 | 'id'=>$category['id'], |
---|
13 | 'name'=>$category['name'], |
---|
14 | 'permalink'=>$category['permalink'] |
---|
15 | ), |
---|
16 | array('start') |
---|
17 | )); |
---|
18 | |
---|
19 | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | // Actions |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | if (isset($_GET['action'])) { |
---|
24 | switch ($_GET['action']) { |
---|
25 | case 'edit_comment' : { |
---|
26 | check_pwg_token(); |
---|
27 | include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions |
---|
28 | check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID); |
---|
29 | $author_id = get_comment_author_id_albums($_GET['comment_to_edit']); |
---|
30 | |
---|
31 | if (can_manage_comment('edit', $author_id)) { |
---|
32 | if (!empty($_POST['content'])) { |
---|
33 | update_user_comment_albums(array( |
---|
34 | 'comment_id' => $_GET['comment_to_edit'], |
---|
35 | 'image_id' => $category['id'], |
---|
36 | 'content' => $_POST['content'] |
---|
37 | ), $_POST['key']); |
---|
38 | |
---|
39 | redirect($url_self); |
---|
40 | } else { |
---|
41 | $edit_comment = $_GET['comment_to_edit']; |
---|
42 | break; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | case 'delete_comment' : { |
---|
47 | check_pwg_token(); |
---|
48 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
49 | check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID); |
---|
50 | $author_id = get_comment_author_id_albums($_GET['comment_to_delete']); |
---|
51 | |
---|
52 | if (can_manage_comment('delete', $author_id)) { |
---|
53 | delete_user_comment_albums($_GET['comment_to_delete']); |
---|
54 | } |
---|
55 | |
---|
56 | redirect($url_self); |
---|
57 | } |
---|
58 | case 'validate_comment' : { |
---|
59 | check_pwg_token(); |
---|
60 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
61 | check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID); |
---|
62 | $author_id = get_comment_author_id_albums($_GET['comment_to_validate']); |
---|
63 | |
---|
64 | if (can_manage_comment('validate', $author_id)) { |
---|
65 | validate_user_comment_albums($_GET['comment_to_validate']); |
---|
66 | } |
---|
67 | |
---|
68 | redirect($url_self); |
---|
69 | } |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | // +-----------------------------------------------------------------------+ |
---|
75 | // Insert comment |
---|
76 | // +-----------------------------------------------------------------------+ |
---|
77 | if ($category['commentable'] and isset($_POST['content'])) { |
---|
78 | if (is_a_guest() and !$conf['comments_forall']) { |
---|
79 | die('Session expired'); |
---|
80 | } |
---|
81 | |
---|
82 | $comm = array( |
---|
83 | 'author' => trim( @$_POST['author'] ), |
---|
84 | 'content' => trim( $_POST['content'] ), |
---|
85 | 'image_id' => $category['id'], |
---|
86 | ); |
---|
87 | |
---|
88 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
89 | $comment_action = insert_user_comment_albums($comm, @$_POST['key'], $infos); |
---|
90 | |
---|
91 | switch ($comment_action) { |
---|
92 | case 'moderate': |
---|
93 | array_push($infos, l10n('An administrator must authorize your comment before it is visible.')); |
---|
94 | case 'validate': |
---|
95 | array_push($infos, l10n('Your comment has been registered')); |
---|
96 | break; |
---|
97 | case 'reject': |
---|
98 | set_status_header(403); |
---|
99 | array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules')); |
---|
100 | break; |
---|
101 | default: |
---|
102 | trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); |
---|
103 | } |
---|
104 | |
---|
105 | $template->assign(($comment_action=='reject') ? 'errors' : 'infos', $infos); |
---|
106 | trigger_action('user_comment_insertion', array_merge($comm, array('action'=>$comment_action))); |
---|
107 | |
---|
108 | } elseif (isset($_POST['content'])) { |
---|
109 | set_status_header(403); |
---|
110 | die('ugly spammer'); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | // +-----------------------------------------------------------------------+ |
---|
115 | // Display comments |
---|
116 | // +-----------------------------------------------------------------------+ |
---|
117 | if ($category['commentable']) { |
---|
118 | if (!is_admin()) { |
---|
119 | $validated_clause = " AND validated = 'true'"; |
---|
120 | } else { |
---|
121 | $validated_clause = null; |
---|
122 | } |
---|
123 | |
---|
124 | // number of comments for this category |
---|
125 | $query = 'SELECT COUNT(*) AS nb_comments |
---|
126 | FROM '.COA_TABLE.' |
---|
127 | WHERE category_id = '.$category['id'] |
---|
128 | .$validated_clause.' |
---|
129 | ;'; |
---|
130 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
131 | |
---|
132 | // navigation bar creation, custom again |
---|
133 | if (isset($_GET['start_comments'])) { |
---|
134 | $page['start_comments'] = $_GET['start_comments']; |
---|
135 | } else { |
---|
136 | $page['start_comments'] = 0; |
---|
137 | } |
---|
138 | include_once(COA_PATH.'include/functions.inc.php'); |
---|
139 | |
---|
140 | $navigation_bar = create_comment_navigation_bar( |
---|
141 | duplicate_index_url(array(), array('start')), |
---|
142 | $row['nb_comments'], |
---|
143 | $page['start_comments'], |
---|
144 | $conf['nb_comment_page'] |
---|
145 | ); |
---|
146 | |
---|
147 | $template->assign(array( |
---|
148 | 'COMMENT_COUNT' => $row['nb_comments'], |
---|
149 | 'comment_navbar' => $navigation_bar, |
---|
150 | )); |
---|
151 | |
---|
152 | if ($row['nb_comments'] > 0) { |
---|
153 | // get comments |
---|
154 | $query = 'SELECT |
---|
155 | com.id, |
---|
156 | com.author, |
---|
157 | com.author_id, |
---|
158 | '.$conf['user_fields']['username'].' AS username, |
---|
159 | com.date, |
---|
160 | com.category_id, |
---|
161 | com.content, |
---|
162 | com.validated |
---|
163 | FROM '.COA_TABLE.' AS com |
---|
164 | LEFT JOIN '.USERS_TABLE.' AS u |
---|
165 | ON u.'.$conf['user_fields']['id'].' = author_id |
---|
166 | WHERE category_id = '.$category['id'].' |
---|
167 | '.$validated_clause.' |
---|
168 | ORDER BY date ASC |
---|
169 | LIMIT '.$conf['nb_comment_page'].' OFFSET '.$page['start_comments'].' |
---|
170 | ;'; |
---|
171 | $result = pwg_query($query); |
---|
172 | |
---|
173 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
174 | // author |
---|
175 | if (!empty($row['author'])) { |
---|
176 | $author = $row['author']; |
---|
177 | if ($author == 'guest') { |
---|
178 | $author = l10n('guest'); |
---|
179 | } |
---|
180 | } else { |
---|
181 | $author = stripslashes($row['username']); |
---|
182 | } |
---|
183 | |
---|
184 | // comment content |
---|
185 | $tpl_comment = array( |
---|
186 | 'AUTHOR' => trigger_event('render_comment_author', $author), |
---|
187 | 'DATE' => format_date($row['date'], true), |
---|
188 | 'CONTENT' => trigger_event('render_comment_content', $row['content']), |
---|
189 | ); |
---|
190 | |
---|
191 | // rights |
---|
192 | if (can_manage_comment('delete', $row['author_id'])) { |
---|
193 | $tpl_comment['U_DELETE'] = add_url_params($url_self, array( |
---|
194 | 'action' => 'delete_comment', |
---|
195 | 'comment_to_delete' => $row['id'], |
---|
196 | 'pwg_token' => get_pwg_token(), |
---|
197 | )); |
---|
198 | } |
---|
199 | if (can_manage_comment('edit', $row['author_id'])) { |
---|
200 | $tpl_comment['U_EDIT'] = add_url_params($url_self, array( |
---|
201 | 'action' => 'edit_comment', |
---|
202 | 'comment_to_edit' => $row['id'], |
---|
203 | 'pwg_token' => get_pwg_token(), |
---|
204 | )); |
---|
205 | if (isset($edit_comment) and ($row['id'] == $edit_comment)) { |
---|
206 | $key = get_ephemeral_key(2, $category['id']); |
---|
207 | $tpl_comment['IN_EDIT'] = true; |
---|
208 | $tpl_comment['KEY'] = $key; |
---|
209 | $tpl_comment['CONTENT'] = $row['content']; |
---|
210 | } |
---|
211 | } |
---|
212 | if (is_admin() AND $row['validated'] != 'true') { |
---|
213 | $tpl_comment['U_VALIDATE'] = add_url_params($url_self, array( |
---|
214 | 'action' => 'validate_comment', |
---|
215 | 'comment_to_validate' => $row['id'], |
---|
216 | 'pwg_token' => get_pwg_token(), |
---|
217 | )); |
---|
218 | } |
---|
219 | |
---|
220 | // template |
---|
221 | $template->append('comments', $tpl_comment); |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | // comment form |
---|
226 | $show_add_comment_form = true; |
---|
227 | if (isset($edit_comment)) { |
---|
228 | $show_add_comment_form = false; |
---|
229 | } |
---|
230 | if (is_a_guest() and !$conf['comments_forall']) { |
---|
231 | $show_add_comment_form = false; |
---|
232 | } |
---|
233 | |
---|
234 | if ($show_add_comment_form) { |
---|
235 | $key = get_ephemeral_key(3, $category['id']); |
---|
236 | $content = null; |
---|
237 | if ('reject'===@$comment_action) { |
---|
238 | $content = htmlspecialchars(stripslashes($comm['content'])); |
---|
239 | } |
---|
240 | $template->assign('comment_add', array( |
---|
241 | 'F_ACTION' => $url_self, |
---|
242 | 'KEY' => $key, |
---|
243 | 'CONTENT' => $content, |
---|
244 | 'SHOW_AUTHOR' => !is_classic_user(), |
---|
245 | )); |
---|
246 | } |
---|
247 | |
---|
248 | // template |
---|
249 | $template->assign(array( |
---|
250 | 'COA_PATH' => COA_PATH, // for css |
---|
251 | 'COA_ABSOLUTE_PATH' => dirname(__FILE__) .'/../', // for template |
---|
252 | )); |
---|
253 | |
---|
254 | $template->set_filename('comments_on_albums', dirname(__FILE__) .'/../template/coa_albums.tpl'); |
---|
255 | $template->concat('PLUGIN_INDEX_CONTENT_END', $template->parse('comments_on_albums', true)); |
---|
256 | |
---|
257 | $template->set_filename('comments_on_albums_messages', dirname(__FILE__) .'/../template/coa_messages.tpl'); |
---|
258 | $template->concat('PLUGIN_INDEX_CONTENT_BEFORE', $template->parse('comments_on_albums_messages', true)); |
---|
259 | } |
---|
260 | |
---|
261 | ?> |
---|