[166] | 1 | <?php |
---|
[354] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[354] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[354] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-03-22 01:01:47 +0000 (Wed, 22 Mar 2006) $ |
---|
| 10 | // | last modifier : $Author: rvelices $ |
---|
| 11 | // | revision : $Revision: 1092 $ |
---|
| 12 | // +-----------------------------------------------------------------------+ |
---|
| 13 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 14 | // | it under the terms of the GNU General Public License as published by | |
---|
| 15 | // | the Free Software Foundation | |
---|
| 16 | // | | |
---|
| 17 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 20 | // | General Public License for more details. | |
---|
| 21 | // | | |
---|
| 22 | // | You should have received a copy of the GNU General Public License | |
---|
| 23 | // | along with this program; if not, write to the Free Software | |
---|
| 24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 25 | // | USA. | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
[166] | 27 | |
---|
[579] | 28 | // +-----------------------------------------------------------------------+ |
---|
| 29 | // | initialization | |
---|
| 30 | // +-----------------------------------------------------------------------+ |
---|
[393] | 31 | if (!defined('IN_ADMIN')) |
---|
| 32 | { |
---|
| 33 | define('PHPWG_ROOT_PATH','./'); |
---|
[579] | 34 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[393] | 35 | } |
---|
[345] | 36 | |
---|
[1072] | 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | Check Access and exit when user status is not ok | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | check_status(ACCESS_GUEST); |
---|
| 41 | |
---|
[796] | 42 | $sort_order = array( |
---|
| 43 | 'descending' => 'DESC', |
---|
| 44 | 'ascending' => 'ASC' |
---|
| 45 | ); |
---|
| 46 | |
---|
| 47 | // sort_by : database fields proposed for sorting comments list |
---|
| 48 | $sort_by = array( |
---|
| 49 | 'date' => 'comment date', |
---|
[889] | 50 | 'image_id' => 'picture' |
---|
[796] | 51 | ); |
---|
| 52 | |
---|
| 53 | // items_number : list of number of items to display per page |
---|
| 54 | $items_number = array(5,10,20,50,'all'); |
---|
| 55 | |
---|
| 56 | // since when display comments ? |
---|
| 57 | // |
---|
| 58 | $since_options = array( |
---|
| 59 | 1 => array('label' => l10n('today'), |
---|
| 60 | 'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 1 DAY)'), |
---|
| 61 | 2 => array('label' => sprintf(l10n('last %d days'), 7), |
---|
| 62 | 'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 7 DAY)'), |
---|
| 63 | 3 => array('label' => sprintf(l10n('last %d days'), 30), |
---|
| 64 | 'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 30 DAY)'), |
---|
| 65 | 4 => array('label' => l10n('the beginning'), |
---|
| 66 | 'clause' => '1=1') // stupid but generic |
---|
| 67 | ); |
---|
| 68 | |
---|
[1092] | 69 | $page['since'] = isset($_GET['since']) ? $_GET['since'] : 3; |
---|
[796] | 70 | |
---|
| 71 | // on which field sorting |
---|
| 72 | // |
---|
| 73 | $page['sort_by'] = 'date'; |
---|
| 74 | // if the form was submitted, it overloads default behaviour |
---|
| 75 | if (isset($_GET['sort_by'])) |
---|
[393] | 76 | { |
---|
[796] | 77 | $page['sort_by'] = $_GET['sort_by']; |
---|
[393] | 78 | } |
---|
[796] | 79 | |
---|
| 80 | // order to sort |
---|
| 81 | // |
---|
| 82 | $page['sort_order'] = $sort_order['descending']; |
---|
| 83 | // if the form was submitted, it overloads default behaviour |
---|
| 84 | if (isset($_GET['sort_order'])) |
---|
[393] | 85 | { |
---|
[796] | 86 | $page['sort_order'] = $sort_order[$_GET['sort_order']]; |
---|
[393] | 87 | } |
---|
[796] | 88 | |
---|
| 89 | // number of items to display |
---|
| 90 | // |
---|
| 91 | $page['items_number'] = 5; |
---|
| 92 | if (isset($_GET['items_number'])) |
---|
| 93 | { |
---|
| 94 | $page['items_number'] = $_GET['items_number']; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | // which category to filter on ? |
---|
| 98 | $page['cat_clause'] = '1=1'; |
---|
| 99 | if (isset($_GET['cat']) and 0 != $_GET['cat']) |
---|
| 100 | { |
---|
| 101 | $page['cat_clause'] = |
---|
| 102 | 'category_id IN ('.implode(',', get_subcat_ids(array($_GET['cat']))).')'; |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | // search a particular author |
---|
| 106 | $page['author_clause'] = '1=1'; |
---|
| 107 | if (isset($_GET['author']) and !empty($_GET['author'])) |
---|
| 108 | { |
---|
| 109 | if (function_exists('mysql_real_escape_string')) |
---|
| 110 | { |
---|
| 111 | $author = mysql_real_escape_string($_GET['author']); |
---|
| 112 | } |
---|
| 113 | else |
---|
| 114 | { |
---|
| 115 | $author = mysql_escape_string($_GET['author']); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | $page['author_clause'] = 'author = \''.$author.'\''; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // search a substring among comments content |
---|
| 122 | $page['keyword_clause'] = '1=1'; |
---|
| 123 | if (isset($_GET['keyword']) and !empty($_GET['keyword'])) |
---|
| 124 | { |
---|
| 125 | if (function_exists('mysql_real_escape_string')) |
---|
| 126 | { |
---|
| 127 | $keyword = mysql_real_escape_string($_GET['keyword']); |
---|
| 128 | } |
---|
| 129 | else |
---|
| 130 | { |
---|
| 131 | $keyword = mysql_escape_string($_GET['keyword']); |
---|
| 132 | } |
---|
| 133 | $page['keyword_clause'] = |
---|
| 134 | '('. |
---|
| 135 | implode(' AND ', |
---|
| 136 | array_map( |
---|
| 137 | create_function( |
---|
| 138 | '$s', |
---|
| 139 | 'return "content LIKE \'%$s%\'";' |
---|
| 140 | ), |
---|
| 141 | preg_split('/[\s,;]+/', $keyword) |
---|
| 142 | ) |
---|
| 143 | ). |
---|
| 144 | ')'; |
---|
| 145 | } |
---|
| 146 | |
---|
[579] | 147 | // +-----------------------------------------------------------------------+ |
---|
| 148 | // | comments management | |
---|
| 149 | // +-----------------------------------------------------------------------+ |
---|
| 150 | // comments deletion |
---|
| 151 | if (isset($_POST['delete']) and count($_POST['comment_id']) > 0) |
---|
| 152 | { |
---|
| 153 | $query = ' |
---|
| 154 | DELETE FROM '.COMMENTS_TABLE.' |
---|
| 155 | WHERE id IN ('.implode(',', $_POST['comment_id']).') |
---|
| 156 | ;'; |
---|
[587] | 157 | pwg_query($query); |
---|
[579] | 158 | } |
---|
| 159 | // comments validation |
---|
| 160 | if (isset($_POST['validate']) and count($_POST['comment_id']) > 0) |
---|
| 161 | { |
---|
| 162 | $query = ' |
---|
| 163 | UPDATE '.COMMENTS_TABLE.' |
---|
| 164 | SET validated = \'true\' |
---|
[801] | 165 | , validation_date = NOW() |
---|
[579] | 166 | WHERE id IN ('.implode(',', $_POST['comment_id']).') |
---|
| 167 | ;'; |
---|
[587] | 168 | pwg_query($query); |
---|
[579] | 169 | } |
---|
| 170 | // +-----------------------------------------------------------------------+ |
---|
| 171 | // | page header and options | |
---|
| 172 | // +-----------------------------------------------------------------------+ |
---|
[355] | 173 | |
---|
[850] | 174 | $title= l10n('title_comments'); |
---|
| 175 | $page['body_id'] = 'theCommentsPage'; |
---|
| 176 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
| 177 | |
---|
[579] | 178 | $template->set_filenames(array('comments'=>'comments.tpl')); |
---|
| 179 | $template->assign_vars( |
---|
| 180 | array( |
---|
| 181 | 'L_COMMENT_TITLE' => $title, |
---|
[796] | 182 | |
---|
| 183 | 'F_ACTION'=>PHPWG_ROOT_PATH.'comments.php', |
---|
| 184 | 'F_KEYWORD'=>@$_GET['keyword'], |
---|
| 185 | 'F_AUTHOR'=>@$_GET['author'], |
---|
[1090] | 186 | |
---|
[1082] | 187 | 'U_HOME' => make_index_url(), |
---|
[579] | 188 | ) |
---|
| 189 | ); |
---|
[355] | 190 | |
---|
[796] | 191 | // +-----------------------------------------------------------------------+ |
---|
| 192 | // | form construction | |
---|
| 193 | // +-----------------------------------------------------------------------+ |
---|
| 194 | |
---|
| 195 | // Search in a particular category |
---|
| 196 | $blockname = 'category'; |
---|
| 197 | |
---|
| 198 | $template->assign_block_vars( |
---|
| 199 | $blockname, |
---|
| 200 | array('SELECTED' => '', |
---|
| 201 | 'VALUE'=> 0, |
---|
| 202 | 'OPTION' => '------------' |
---|
| 203 | )); |
---|
| 204 | |
---|
| 205 | $query = ' |
---|
| 206 | SELECT id,name,uppercats,global_rank |
---|
| 207 | FROM '.CATEGORIES_TABLE; |
---|
| 208 | if ($user['forbidden_categories'] != '') |
---|
[579] | 209 | { |
---|
[796] | 210 | $query.= ' |
---|
| 211 | WHERE id NOT IN ('.$user['forbidden_categories'].')'; |
---|
| 212 | } |
---|
| 213 | $query.= ' |
---|
| 214 | ;'; |
---|
| 215 | display_select_cat_wrapper($query, array(@$_GET['cat']), $blockname, true); |
---|
| 216 | |
---|
| 217 | // Filter on recent comments... |
---|
| 218 | $blockname = 'since_option'; |
---|
| 219 | |
---|
| 220 | foreach ($since_options as $id => $option) |
---|
| 221 | { |
---|
| 222 | $selected = ($id == $page['since']) ? 'selected="selected"' : ''; |
---|
[1090] | 223 | |
---|
[420] | 224 | $template->assign_block_vars( |
---|
[796] | 225 | $blockname, |
---|
| 226 | array('SELECTED' => $selected, |
---|
| 227 | 'VALUE'=> $id, |
---|
| 228 | 'CONTENT' => $option['label'] |
---|
| 229 | )); |
---|
[355] | 230 | } |
---|
[796] | 231 | |
---|
| 232 | // Sort by |
---|
| 233 | $blockname = 'sort_by_option'; |
---|
| 234 | |
---|
| 235 | foreach ($sort_by as $key => $value) |
---|
| 236 | { |
---|
| 237 | $selected = ($key == $page['sort_by']) ? 'selected="selected"' : ''; |
---|
| 238 | |
---|
| 239 | $template->assign_block_vars( |
---|
| 240 | $blockname, |
---|
| 241 | array('SELECTED' => $selected, |
---|
| 242 | 'VALUE'=> $key, |
---|
| 243 | 'CONTENT' => l10n($value) |
---|
| 244 | )); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | // Sorting order |
---|
| 248 | $blockname = 'sort_order_option'; |
---|
| 249 | |
---|
| 250 | foreach (array_keys($sort_order) as $option) |
---|
| 251 | { |
---|
| 252 | $selected = ($option == $page['sort_order']) ? 'selected="selected"' : ''; |
---|
| 253 | |
---|
| 254 | $template->assign_block_vars( |
---|
| 255 | $blockname, |
---|
| 256 | array('SELECTED' => $selected, |
---|
| 257 | 'VALUE'=> $option, |
---|
| 258 | 'CONTENT' => l10n($option) |
---|
| 259 | )); |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | // Number of items |
---|
| 263 | $blockname = 'items_number_option'; |
---|
| 264 | |
---|
| 265 | foreach ($items_number as $option) |
---|
| 266 | { |
---|
| 267 | $selected = ($option == $page['items_number']) ? 'selected="selected"' : ''; |
---|
| 268 | |
---|
| 269 | $template->assign_block_vars( |
---|
| 270 | $blockname, |
---|
| 271 | array('SELECTED' => $selected, |
---|
| 272 | 'VALUE'=> $option, |
---|
| 273 | 'CONTENT' => is_numeric($option) ? $option : l10n($option) |
---|
| 274 | )); |
---|
| 275 | } |
---|
| 276 | |
---|
[579] | 277 | // +-----------------------------------------------------------------------+ |
---|
[796] | 278 | // | navigation bar | |
---|
| 279 | // +-----------------------------------------------------------------------+ |
---|
| 280 | |
---|
| 281 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 282 | { |
---|
| 283 | $start = $_GET['start']; |
---|
| 284 | } |
---|
| 285 | else |
---|
| 286 | { |
---|
| 287 | $start = 0; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | $query = ' |
---|
| 291 | SELECT COUNT(DISTINCT(id)) |
---|
| 292 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
| 293 | INNER JOIN '.COMMENTS_TABLE.' AS com |
---|
| 294 | ON ic.image_id = com.image_id |
---|
| 295 | WHERE '.$since_options[$page['since']]['clause'].' |
---|
| 296 | AND '.$page['cat_clause'].' |
---|
| 297 | AND '.$page['author_clause'].' |
---|
| 298 | AND '.$page['keyword_clause']; |
---|
| 299 | if ($user['forbidden_categories'] != '') |
---|
| 300 | { |
---|
| 301 | $query.= ' |
---|
| 302 | AND category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
| 303 | } |
---|
| 304 | $query.= ' |
---|
| 305 | ;'; |
---|
| 306 | list($counter) = mysql_fetch_row(pwg_query($query)); |
---|
| 307 | |
---|
| 308 | $url = PHPWG_ROOT_PATH.'comments.php?t=1'.get_query_string_diff(array('start')); |
---|
| 309 | |
---|
| 310 | $navbar = create_navigation_bar($url, |
---|
| 311 | $counter, |
---|
| 312 | $start, |
---|
| 313 | $page['items_number'], |
---|
| 314 | ''); |
---|
| 315 | |
---|
| 316 | $template->assign_vars(array('NAVBAR' => $navbar)); |
---|
| 317 | |
---|
| 318 | // +-----------------------------------------------------------------------+ |
---|
[579] | 319 | // | last comments display | |
---|
| 320 | // +-----------------------------------------------------------------------+ |
---|
[355] | 321 | |
---|
[796] | 322 | $comments = array(); |
---|
| 323 | $element_ids = array(); |
---|
| 324 | $category_ids = array(); |
---|
| 325 | |
---|
[579] | 326 | $query = ' |
---|
[796] | 327 | SELECT com.id AS comment_id |
---|
| 328 | , com.image_id |
---|
| 329 | , ic.category_id |
---|
| 330 | , com.author |
---|
| 331 | , com.date |
---|
| 332 | , com.content |
---|
| 333 | , com.id AS comment_id |
---|
| 334 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
| 335 | INNER JOIN '.COMMENTS_TABLE.' AS com |
---|
| 336 | ON ic.image_id = com.image_id |
---|
| 337 | WHERE '.$since_options[$page['since']]['clause'].' |
---|
| 338 | AND '.$page['cat_clause'].' |
---|
| 339 | AND '.$page['author_clause'].' |
---|
| 340 | AND '.$page['keyword_clause']; |
---|
| 341 | if ($user['forbidden_categories'] != '') |
---|
[166] | 342 | { |
---|
[796] | 343 | $query.= ' |
---|
[579] | 344 | AND category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
[355] | 345 | } |
---|
[579] | 346 | $query.= ' |
---|
[796] | 347 | GROUP BY comment_id |
---|
| 348 | ORDER BY '.$page['sort_by'].' '.$page['sort_order']; |
---|
| 349 | if ('all' != $page['items_number']) |
---|
| 350 | { |
---|
| 351 | $query.= ' |
---|
| 352 | LIMIT '.$start.','.$page['items_number']; |
---|
| 353 | } |
---|
| 354 | $query.= ' |
---|
[579] | 355 | ;'; |
---|
[587] | 356 | $result = pwg_query($query); |
---|
[796] | 357 | while ($row = mysql_fetch_array($result)) |
---|
[393] | 358 | { |
---|
[796] | 359 | array_push($comments, $row); |
---|
| 360 | array_push($element_ids, $row['image_id']); |
---|
| 361 | array_push($category_ids, $row['category_id']); |
---|
[393] | 362 | } |
---|
[796] | 363 | |
---|
| 364 | if (count($comments) > 0) |
---|
[579] | 365 | { |
---|
[796] | 366 | // retrieving element informations |
---|
| 367 | $elements = array(); |
---|
[579] | 368 | $query = ' |
---|
[796] | 369 | SELECT id, name, file, path, tn_ext |
---|
[579] | 370 | FROM '.IMAGES_TABLE.' |
---|
[796] | 371 | WHERE id IN ('.implode(',', $element_ids).') |
---|
[579] | 372 | ;'; |
---|
[796] | 373 | $result = pwg_query($query); |
---|
| 374 | while ($row = mysql_fetch_array($result)) |
---|
[579] | 375 | { |
---|
[796] | 376 | $elements[$row['id']] = $row; |
---|
[579] | 377 | } |
---|
[721] | 378 | |
---|
[796] | 379 | // retrieving category informations |
---|
| 380 | $categories = array(); |
---|
[579] | 381 | $query = ' |
---|
[796] | 382 | SELECT id, uppercats |
---|
| 383 | FROM '.CATEGORIES_TABLE.' |
---|
| 384 | WHERE id IN ('.implode(',', $category_ids).') |
---|
| 385 | ;'; |
---|
| 386 | $result = pwg_query($query); |
---|
| 387 | while ($row = mysql_fetch_array($result)) |
---|
[579] | 388 | { |
---|
[796] | 389 | $categories[$row['id']] = $row; |
---|
[579] | 390 | } |
---|
[796] | 391 | |
---|
| 392 | foreach ($comments as $comment) |
---|
[579] | 393 | { |
---|
[796] | 394 | // name of the picture |
---|
| 395 | $name = get_cat_display_name_cache( |
---|
[1092] | 396 | $categories[$comment['category_id']]['uppercats'], null, false); |
---|
[796] | 397 | $name.= $conf['level_separator']; |
---|
| 398 | if (!empty($elements[$comment['image_id']]['name'])) |
---|
[166] | 399 | { |
---|
[796] | 400 | $name.= $elements[$comment['image_id']]['name']; |
---|
[166] | 401 | } |
---|
[796] | 402 | else |
---|
| 403 | { |
---|
| 404 | $name.= get_name_from_file($elements[$comment['image_id']]['file']); |
---|
| 405 | } |
---|
[1090] | 406 | |
---|
[796] | 407 | // source of the thumbnail picture |
---|
| 408 | $thumbnail_src = get_thumbnail_src( |
---|
| 409 | $elements[$comment['image_id']]['path'], |
---|
| 410 | @$elements[$comment['image_id']]['tn_ext'] |
---|
| 411 | ); |
---|
[1090] | 412 | |
---|
[796] | 413 | // link to the full size picture |
---|
[1090] | 414 | $url = make_picture_url( |
---|
| 415 | array( |
---|
| 416 | 'category' => $comment['category_id'], |
---|
| 417 | 'image_id' => $comment['image_id'], |
---|
| 418 | 'image_file' => $elements[$comment['image_id']]['file'], |
---|
| 419 | ) |
---|
| 420 | ); |
---|
| 421 | |
---|
[464] | 422 | $template->assign_block_vars( |
---|
[796] | 423 | 'picture', |
---|
[464] | 424 | array( |
---|
[796] | 425 | 'TITLE_IMG'=>$name, |
---|
| 426 | 'I_THUMB'=>$thumbnail_src, |
---|
[1004] | 427 | 'U_THUMB'=>$url |
---|
[464] | 428 | )); |
---|
[1090] | 429 | |
---|
[796] | 430 | $author = $comment['author']; |
---|
| 431 | if (empty($comment['author'])) |
---|
[393] | 432 | { |
---|
[796] | 433 | $author = l10n('guest'); |
---|
[166] | 434 | } |
---|
[1090] | 435 | |
---|
[796] | 436 | $template->assign_block_vars( |
---|
[848] | 437 | 'comment', |
---|
[796] | 438 | array( |
---|
[1004] | 439 | 'U_PICTURE' => $url, |
---|
[848] | 440 | 'TN_SRC' => $thumbnail_src, |
---|
| 441 | 'AUTHOR' => $author, |
---|
| 442 | 'DATE'=>format_date($comment['date'],'mysql_datetime',true), |
---|
| 443 | 'CONTENT'=>parse_comment_content($comment['content']), |
---|
[796] | 444 | )); |
---|
[166] | 445 | } |
---|
[579] | 446 | } |
---|
| 447 | // +-----------------------------------------------------------------------+ |
---|
| 448 | // | html code display | |
---|
| 449 | // +-----------------------------------------------------------------------+ |
---|
[393] | 450 | if (defined('IN_ADMIN')) |
---|
| 451 | { |
---|
| 452 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
| 453 | } |
---|
| 454 | else |
---|
| 455 | { |
---|
| 456 | $template->assign_block_vars('title',array()); |
---|
[688] | 457 | $template->parse('comments'); |
---|
[393] | 458 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 459 | } |
---|
[362] | 460 | ?> |
---|