[9624] | 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 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 6 | // | category infos | |
---|
[9624] | 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | $category = $page['category']; |
---|
| 9 | |
---|
| 10 | $url_self = duplicate_index_url(array( |
---|
[10984] | 11 | 'category' => array( |
---|
[11267] | 12 | 'id' => $category['id'], |
---|
| 13 | 'name' => $category['name'], |
---|
| 14 | 'permalink' => $category['permalink'] |
---|
| 15 | ), |
---|
[10984] | 16 | array('start') |
---|
[11267] | 17 | )); |
---|
[9624] | 18 | |
---|
| 19 | |
---|
| 20 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 21 | // | actions | |
---|
[9624] | 22 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 23 | if (isset($_GET['action'])) |
---|
| 24 | { |
---|
| 25 | switch ($_GET['action']) |
---|
| 26 | { |
---|
| 27 | case 'edit_comment' : |
---|
| 28 | { |
---|
[10984] | 29 | check_pwg_token(); |
---|
[11267] | 30 | |
---|
[10984] | 31 | include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions |
---|
[11267] | 32 | |
---|
[10984] | 33 | check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID); |
---|
[11267] | 34 | |
---|
[10984] | 35 | $author_id = get_comment_author_id_albums($_GET['comment_to_edit']); |
---|
[9624] | 36 | |
---|
[11267] | 37 | if (can_manage_comment('edit', $author_id)) |
---|
| 38 | { |
---|
| 39 | if (!empty($_POST['content'])) |
---|
| 40 | { |
---|
[10984] | 41 | $comment_action = update_user_comment_albums( |
---|
| 42 | array( |
---|
| 43 | 'comment_id' => $_GET['comment_to_edit'], |
---|
[12562] | 44 | 'category_id' => $category['id'], |
---|
[10984] | 45 | 'content' => $_POST['content'] |
---|
[11267] | 46 | ), |
---|
[10984] | 47 | $_POST['key'] |
---|
[11267] | 48 | ); |
---|
[10984] | 49 | |
---|
| 50 | $infos = array(); |
---|
| 51 | |
---|
| 52 | switch ($comment_action) |
---|
| 53 | { |
---|
| 54 | case 'moderate': |
---|
| 55 | array_push($infos, l10n('An administrator must authorize your comment before it is visible.')); |
---|
| 56 | case 'validate': |
---|
| 57 | array_push($infos, l10n('Your comment has been registered')); |
---|
| 58 | break; |
---|
| 59 | case 'reject': |
---|
| 60 | set_status_header(403); |
---|
| 61 | array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules')); |
---|
| 62 | break; |
---|
| 63 | default: |
---|
| 64 | trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); |
---|
| 65 | } |
---|
[9624] | 66 | |
---|
[10984] | 67 | $template->assign( |
---|
[11267] | 68 | ($comment_action=='reject') ? 'errors' : 'infos', |
---|
| 69 | $infos |
---|
| 70 | ); |
---|
[10213] | 71 | |
---|
[10984] | 72 | unset($_POST['content']); |
---|
| 73 | break; |
---|
[11267] | 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
[10984] | 77 | $edit_comment = $_GET['comment_to_edit']; |
---|
| 78 | break; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | } |
---|
[11267] | 82 | case 'delete_comment' : |
---|
| 83 | { |
---|
[10984] | 84 | check_pwg_token(); |
---|
[11267] | 85 | |
---|
[10984] | 86 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
[11267] | 87 | |
---|
[10984] | 88 | check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID); |
---|
[11267] | 89 | |
---|
[10984] | 90 | $author_id = get_comment_author_id_albums($_GET['comment_to_delete']); |
---|
[9624] | 91 | |
---|
[11267] | 92 | if (can_manage_comment('delete', $author_id)) |
---|
| 93 | { |
---|
[10984] | 94 | delete_user_comment_albums($_GET['comment_to_delete']); |
---|
| 95 | } |
---|
[9624] | 96 | |
---|
[10984] | 97 | redirect($url_self); |
---|
| 98 | } |
---|
[11267] | 99 | case 'validate_comment' : |
---|
| 100 | { |
---|
[10984] | 101 | check_pwg_token(); |
---|
[11267] | 102 | |
---|
[10984] | 103 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
[11267] | 104 | |
---|
[10984] | 105 | check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID); |
---|
[11267] | 106 | |
---|
[10984] | 107 | $author_id = get_comment_author_id_albums($_GET['comment_to_validate']); |
---|
[9624] | 108 | |
---|
[11267] | 109 | if (can_manage_comment('validate', $author_id)) |
---|
| 110 | { |
---|
[10984] | 111 | validate_user_comment_albums($_GET['comment_to_validate']); |
---|
| 112 | } |
---|
[9624] | 113 | |
---|
[10984] | 114 | redirect($url_self); |
---|
| 115 | } |
---|
| 116 | } |
---|
[9624] | 117 | } |
---|
| 118 | |
---|
| 119 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 120 | // | insert comment | |
---|
[9624] | 121 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 122 | if ($category['commentable'] and isset($_POST['content'])) |
---|
| 123 | { |
---|
| 124 | if (is_a_guest() and !$conf['comments_forall']) |
---|
| 125 | { |
---|
[10984] | 126 | die('Session expired'); |
---|
| 127 | } |
---|
[9624] | 128 | |
---|
[10984] | 129 | $comm = array( |
---|
| 130 | 'author' => trim( @$_POST['author'] ), |
---|
| 131 | 'content' => trim( $_POST['content'] ), |
---|
[12562] | 132 | 'category_id' => $category['id'], |
---|
[10984] | 133 | ); |
---|
[9624] | 134 | |
---|
[10984] | 135 | include_once(COA_PATH.'include/functions_comment.inc.php'); |
---|
[11267] | 136 | |
---|
[10984] | 137 | $comment_action = insert_user_comment_albums($comm, @$_POST['key'], $infos); |
---|
[9624] | 138 | |
---|
[11267] | 139 | switch ($comment_action) |
---|
| 140 | { |
---|
[10984] | 141 | case 'moderate': |
---|
| 142 | array_push($infos, l10n('An administrator must authorize your comment before it is visible.')); |
---|
| 143 | case 'validate': |
---|
| 144 | array_push($infos, l10n('Your comment has been registered')); |
---|
| 145 | break; |
---|
| 146 | case 'reject': |
---|
| 147 | set_status_header(403); |
---|
| 148 | array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules')); |
---|
| 149 | break; |
---|
| 150 | default: |
---|
| 151 | trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); |
---|
| 152 | } |
---|
[9624] | 153 | |
---|
[11267] | 154 | $template->assign( |
---|
| 155 | ($comment_action=='reject') ? 'errors' : 'infos', |
---|
| 156 | $infos |
---|
| 157 | ); |
---|
| 158 | |
---|
| 159 | // allow plugins to notify what's going on |
---|
| 160 | trigger_action( 'user_comment_insertion', |
---|
| 161 | array_merge($comm, array('action'=>$comment_action) ) |
---|
| 162 | ); |
---|
[10984] | 163 | |
---|
[11267] | 164 | } |
---|
| 165 | else if (isset($_POST['content'])) |
---|
| 166 | { |
---|
[10984] | 167 | set_status_header(403); |
---|
| 168 | die('ugly spammer'); |
---|
[9624] | 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 173 | // | display comments | |
---|
[9624] | 174 | // +-----------------------------------------------------------------------+ |
---|
[11267] | 175 | if ($category['commentable']) |
---|
| 176 | { |
---|
| 177 | if (!is_admin()) |
---|
| 178 | { |
---|
[10984] | 179 | $validated_clause = " AND validated = 'true'"; |
---|
[11267] | 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
[10984] | 183 | $validated_clause = null; |
---|
| 184 | } |
---|
[9624] | 185 | |
---|
[10984] | 186 | // number of comments for this category |
---|
[11267] | 187 | $query = ' |
---|
| 188 | SELECT |
---|
| 189 | COUNT(*) AS nb_comments |
---|
| 190 | FROM '.COA_TABLE.' |
---|
| 191 | WHERE category_id = '.$category['id'] |
---|
| 192 | .$validated_clause.' |
---|
| 193 | ;'; |
---|
[10984] | 194 | $row = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[9624] | 195 | |
---|
[10984] | 196 | // navigation bar creation, custom again |
---|
[11267] | 197 | if (isset($_GET['start_comments'])) |
---|
| 198 | { |
---|
[10984] | 199 | $page['start_comments'] = $_GET['start_comments']; |
---|
[11267] | 200 | } |
---|
| 201 | else |
---|
| 202 | { |
---|
[10984] | 203 | $page['start_comments'] = 0; |
---|
| 204 | } |
---|
| 205 | include_once(COA_PATH.'include/functions.inc.php'); |
---|
[9624] | 206 | |
---|
[10984] | 207 | $navigation_bar = create_comment_navigation_bar( |
---|
| 208 | duplicate_index_url(array(), array('start')), |
---|
| 209 | $row['nb_comments'], |
---|
| 210 | $page['start_comments'], |
---|
| 211 | $conf['nb_comment_page'] |
---|
[11267] | 212 | ); |
---|
[9624] | 213 | |
---|
[11267] | 214 | $template->assign( |
---|
| 215 | array( |
---|
| 216 | 'COMMENT_COUNT' => $row['nb_comments'], |
---|
| 217 | 'comment_navbar' => $navigation_bar, |
---|
| 218 | ) |
---|
| 219 | ); |
---|
[9624] | 220 | |
---|
[11267] | 221 | if ($row['nb_comments'] > 0) |
---|
| 222 | { |
---|
[10984] | 223 | // get comments |
---|
[11267] | 224 | $query = ' |
---|
| 225 | SELECT |
---|
| 226 | com.id, |
---|
| 227 | com.author, |
---|
| 228 | com.author_id, |
---|
| 229 | '.$conf['user_fields']['username'].' AS username, |
---|
| 230 | com.date, |
---|
| 231 | com.category_id, |
---|
| 232 | com.content, |
---|
| 233 | com.validated |
---|
| 234 | FROM '.COA_TABLE.' AS com |
---|
| 235 | LEFT JOIN '.USERS_TABLE.' AS u |
---|
| 236 | ON u.'.$conf['user_fields']['id'].' = author_id |
---|
| 237 | WHERE category_id = '.$category['id'].' |
---|
| 238 | '.$validated_clause.' |
---|
| 239 | ORDER BY date ASC |
---|
| 240 | LIMIT '.$conf['nb_comment_page'].' OFFSET '.$page['start_comments'].' |
---|
| 241 | ;'; |
---|
[10984] | 242 | $result = pwg_query($query); |
---|
[9624] | 243 | |
---|
[11267] | 244 | while ($row = pwg_db_fetch_assoc($result)) |
---|
| 245 | { |
---|
[10984] | 246 | // author |
---|
[11267] | 247 | if (!empty($row['author'])) |
---|
| 248 | { |
---|
[10984] | 249 | $author = $row['author']; |
---|
[11267] | 250 | if ($author == 'guest') |
---|
| 251 | { |
---|
[10984] | 252 | $author = l10n('guest'); |
---|
| 253 | } |
---|
[11267] | 254 | } |
---|
| 255 | else |
---|
| 256 | { |
---|
[10984] | 257 | $author = stripslashes($row['username']); |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | // comment content |
---|
| 261 | $tpl_comment = array( |
---|
[11251] | 262 | 'ID' => $row['id'], |
---|
[10984] | 263 | 'AUTHOR' => trigger_event('render_comment_author', $author), |
---|
| 264 | 'DATE' => format_date($row['date'], true), |
---|
[11417] | 265 | 'CONTENT' => trigger_event('render_comment_content', $row['content'], 'album'), |
---|
[11267] | 266 | ); |
---|
[10984] | 267 | |
---|
| 268 | // rights |
---|
[11267] | 269 | if (can_manage_comment('delete', $row['author_id'])) |
---|
| 270 | { |
---|
| 271 | $tpl_comment['U_DELETE'] = add_url_params( |
---|
| 272 | $url_self, |
---|
| 273 | array( |
---|
| 274 | 'action' => 'delete_comment', |
---|
| 275 | 'comment_to_delete' => $row['id'], |
---|
| 276 | 'pwg_token' => get_pwg_token(), |
---|
| 277 | ) |
---|
| 278 | ); |
---|
[10984] | 279 | } |
---|
[11267] | 280 | if (can_manage_comment('edit', $row['author_id'])) |
---|
| 281 | { |
---|
| 282 | $tpl_comment['U_EDIT'] = add_url_params( |
---|
| 283 | $url_self, |
---|
| 284 | array( |
---|
| 285 | 'action' => 'edit_comment', |
---|
| 286 | 'comment_to_edit' => $row['id'], |
---|
| 287 | 'pwg_token' => get_pwg_token(), |
---|
| 288 | ) |
---|
| 289 | ); |
---|
| 290 | if (isset($edit_comment) and ($row['id'] == $edit_comment)) |
---|
| 291 | { |
---|
[10984] | 292 | $key = get_ephemeral_key(2, $category['id']); |
---|
| 293 | $tpl_comment['IN_EDIT'] = true; |
---|
| 294 | $tpl_comment['KEY'] = $key; |
---|
| 295 | $tpl_comment['CONTENT'] = $row['content']; |
---|
| 296 | } |
---|
| 297 | } |
---|
[11267] | 298 | if (is_admin() AND $row['validated'] != 'true') |
---|
| 299 | { |
---|
| 300 | $tpl_comment['U_VALIDATE'] = add_url_params( |
---|
| 301 | $url_self, |
---|
| 302 | array( |
---|
| 303 | 'action' => 'validate_comment', |
---|
| 304 | 'comment_to_validate' => $row['id'], |
---|
| 305 | 'pwg_token' => get_pwg_token(), |
---|
| 306 | ) |
---|
| 307 | ); |
---|
[10984] | 308 | } |
---|
| 309 | |
---|
| 310 | $template->append('comments', $tpl_comment); |
---|
| 311 | } |
---|
| 312 | } |
---|
[9624] | 313 | |
---|
[10984] | 314 | // comment form |
---|
| 315 | $show_add_comment_form = true; |
---|
[11267] | 316 | if (isset($edit_comment)) |
---|
| 317 | { |
---|
[10984] | 318 | $show_add_comment_form = false; |
---|
| 319 | } |
---|
[11267] | 320 | if (is_a_guest() and !$conf['comments_forall']) |
---|
| 321 | { |
---|
[10984] | 322 | $show_add_comment_form = false; |
---|
| 323 | } |
---|
[9624] | 324 | |
---|
[11267] | 325 | if ($show_add_comment_form) |
---|
| 326 | { |
---|
[10984] | 327 | $key = get_ephemeral_key(3, $category['id']); |
---|
| 328 | $content = null; |
---|
[11267] | 329 | if ('reject'===@$comment_action) |
---|
| 330 | { |
---|
[10984] | 331 | $content = htmlspecialchars(stripslashes($comm['content'])); |
---|
| 332 | } |
---|
[11267] | 333 | $template->assign( |
---|
| 334 | 'comment_add', |
---|
| 335 | array( |
---|
| 336 | 'F_ACTION' => $url_self, |
---|
| 337 | 'KEY' => $key, |
---|
| 338 | 'CONTENT' => $content, |
---|
| 339 | 'SHOW_AUTHOR' => !is_classic_user(), |
---|
| 340 | ) |
---|
| 341 | ); |
---|
[10984] | 342 | } |
---|
| 343 | |
---|
| 344 | // template |
---|
[11267] | 345 | $template->assign( |
---|
| 346 | array( |
---|
| 347 | 'COA_PATH' => COA_PATH, // for css |
---|
| 348 | 'COA_ABSOLUTE_PATH' => dirname(__FILE__) .'/../', // for template |
---|
| 349 | ) |
---|
| 350 | ); |
---|
[10984] | 351 | |
---|
[11267] | 352 | $template->set_filename('comments_on_albums', dirname(__FILE__) .'/../template/albums.tpl'); |
---|
[10984] | 353 | $template->concat('PLUGIN_INDEX_CONTENT_END', $template->parse('comments_on_albums', true)); |
---|
| 354 | |
---|
[11267] | 355 | if (isset($infos)) |
---|
| 356 | { |
---|
| 357 | $template->set_prefilter('index', 'coa_messages'); |
---|
[12562] | 358 | } |
---|
| 359 | |
---|
| 360 | function coa_messages($content, &$smarty) |
---|
| 361 | { |
---|
| 362 | $replacement = ' |
---|
[11267] | 363 | {if isset($errors)} |
---|
| 364 | <div class="errors"> |
---|
| 365 | <ul> |
---|
| 366 | {foreach from=$errors item=error} |
---|
| 367 | <li>{$error}</li> |
---|
| 368 | {/foreach} |
---|
| 369 | </ul> |
---|
| 370 | </div> |
---|
| 371 | {/if} |
---|
| 372 | {if isset($infos)} |
---|
| 373 | <div class="infos"> |
---|
| 374 | <ul> |
---|
| 375 | {foreach from=$infos item=info} |
---|
| 376 | <li>{$info}</li> |
---|
| 377 | {/foreach} |
---|
| 378 | </ul> |
---|
| 379 | </div> |
---|
| 380 | {/if}'; |
---|
| 381 | |
---|
[12562] | 382 | return $replacement.$content; |
---|
[11267] | 383 | } |
---|
[9624] | 384 | } |
---|
| 385 | |
---|
| 386 | ?> |
---|