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