| 1 | <?php |
|---|
| 2 | // +-----------------------------------------------------------------------+ |
|---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
|---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
|---|
| 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
|---|
| 6 | // +-----------------------------------------------------------------------+ |
|---|
| 7 | // | file : $Id$ |
|---|
| 8 | // | last update : $Date$ |
|---|
| 9 | // | last modifier : $Author$ |
|---|
| 10 | // | revision : $Revision$ |
|---|
| 11 | // +-----------------------------------------------------------------------+ |
|---|
| 12 | // | This program is free software; you can redistribute it and/or modify | |
|---|
| 13 | // | it under the terms of the GNU General Public License as published by | |
|---|
| 14 | // | the Free Software Foundation | |
|---|
| 15 | // | | |
|---|
| 16 | // | This program is distributed in the hope that it will be useful, but | |
|---|
| 17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
|---|
| 18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
|---|
| 19 | // | General Public License for more details. | |
|---|
| 20 | // | | |
|---|
| 21 | // | You should have received a copy of the GNU General Public License | |
|---|
| 22 | // | along with this program; if not, write to the Free Software | |
|---|
| 23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
|---|
| 24 | // | USA. | |
|---|
| 25 | // +-----------------------------------------------------------------------+ |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * This file is included by the main page to show thumbnails for a category |
|---|
| 29 | * that have only subcategories or to show recent categories |
|---|
| 30 | * |
|---|
| 31 | */ |
|---|
| 32 | |
|---|
| 33 | if ($page['section']=='recent_cats') |
|---|
| 34 | { |
|---|
| 35 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
|---|
| 36 | $query = ' |
|---|
| 37 | SELECT |
|---|
| 38 | id, name, permalink, representative_picture_id, comment, nb_images, uppercats, |
|---|
| 39 | date_last, max_date_last, count_images, count_categories, global_rank |
|---|
| 40 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
|---|
| 41 | ON id = cat_id and user_id = '.$user['id'].' |
|---|
| 42 | WHERE date_last >= SUBDATE( |
|---|
| 43 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY |
|---|
| 44 | ) |
|---|
| 45 | '.get_sql_condition_FandF |
|---|
| 46 | ( |
|---|
| 47 | array |
|---|
| 48 | ( |
|---|
| 49 | 'visible_categories' => 'id', |
|---|
| 50 | ), |
|---|
| 51 | 'AND' |
|---|
| 52 | ).' |
|---|
| 53 | ;'; |
|---|
| 54 | } |
|---|
| 55 | else |
|---|
| 56 | { |
|---|
| 57 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
|---|
| 58 | $query = ' |
|---|
| 59 | SELECT |
|---|
| 60 | id, name, permalink, representative_picture_id, comment, nb_images, |
|---|
| 61 | date_last, max_date_last, count_images, count_categories |
|---|
| 62 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
|---|
| 63 | ON id = cat_id and user_id = '.$user['id'].' |
|---|
| 64 | WHERE id_uppercat '. |
|---|
| 65 | (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).' |
|---|
| 66 | '.get_sql_condition_FandF |
|---|
| 67 | ( |
|---|
| 68 | array |
|---|
| 69 | ( |
|---|
| 70 | 'visible_categories' => 'id', |
|---|
| 71 | ), |
|---|
| 72 | 'AND' |
|---|
| 73 | ).' |
|---|
| 74 | ORDER BY rank |
|---|
| 75 | ;'; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | $result = pwg_query($query); |
|---|
| 79 | $categories = array(); |
|---|
| 80 | $category_ids = array(); |
|---|
| 81 | $image_ids = array(); |
|---|
| 82 | |
|---|
| 83 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 84 | { |
|---|
| 85 | $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last']; |
|---|
| 86 | |
|---|
| 87 | if (isset($row['representative_picture_id']) |
|---|
| 88 | and is_numeric($row['representative_picture_id'])) |
|---|
| 89 | { // if a representative picture is set, it has priority |
|---|
| 90 | $image_id = $row['representative_picture_id']; |
|---|
| 91 | } |
|---|
| 92 | else if ($conf['allow_random_representative']) |
|---|
| 93 | {// searching a random representant among elements in sub-categories |
|---|
| 94 | $query = ' |
|---|
| 95 | SELECT image_id |
|---|
| 96 | FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic |
|---|
| 97 | ON ic.category_id = c.id'; |
|---|
| 98 | $query.= ' |
|---|
| 99 | WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' |
|---|
| 100 | '.get_sql_condition_FandF |
|---|
| 101 | ( |
|---|
| 102 | array |
|---|
| 103 | ( |
|---|
| 104 | 'forbidden_categories' => 'c.id', |
|---|
| 105 | 'visible_categories' => 'c.id', |
|---|
| 106 | 'visible_images' => 'image_id' |
|---|
| 107 | ), |
|---|
| 108 | 'AND' |
|---|
| 109 | ).' |
|---|
| 110 | ORDER BY RAND() |
|---|
| 111 | LIMIT 0,1 |
|---|
| 112 | ;'; |
|---|
| 113 | $subresult = pwg_query($query); |
|---|
| 114 | if (mysql_num_rows($subresult) > 0) |
|---|
| 115 | { |
|---|
| 116 | list($image_id) = mysql_fetch_row($subresult); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | else |
|---|
| 120 | { // searching a random representant among representant of sub-categories |
|---|
| 121 | $query = ' |
|---|
| 122 | SELECT representative_picture_id |
|---|
| 123 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
|---|
| 124 | ON id = cat_id and user_id = '.$user['id'].' |
|---|
| 125 | WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' |
|---|
| 126 | AND representative_picture_id IS NOT NULL |
|---|
| 127 | '.get_sql_condition_FandF |
|---|
| 128 | ( |
|---|
| 129 | array |
|---|
| 130 | ( |
|---|
| 131 | 'visible_categories' => 'id', |
|---|
| 132 | ), |
|---|
| 133 | 'AND' |
|---|
| 134 | ).' |
|---|
| 135 | ORDER BY RAND() |
|---|
| 136 | LIMIT 0,1 |
|---|
| 137 | ;'; |
|---|
| 138 | $subresult = pwg_query($query); |
|---|
| 139 | if (mysql_num_rows($subresult) > 0) |
|---|
| 140 | { |
|---|
| 141 | list($image_id) = mysql_fetch_row($subresult); |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | if (isset($image_id)) |
|---|
| 146 | { |
|---|
| 147 | $row['representative_picture_id'] = $image_id; |
|---|
| 148 | array_push($image_ids, $image_id); |
|---|
| 149 | array_push($categories, $row); |
|---|
| 150 | array_push($category_ids, $row['id']); |
|---|
| 151 | } |
|---|
| 152 | unset($image_id); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | if ($conf['display_fromto']) |
|---|
| 156 | { |
|---|
| 157 | $dates_of_category = array(); |
|---|
| 158 | if (count($category_ids) > 0) |
|---|
| 159 | { |
|---|
| 160 | $query = ' |
|---|
| 161 | SELECT |
|---|
| 162 | category_id, |
|---|
| 163 | MIN(date_creation) AS date_creation_min, |
|---|
| 164 | MAX(date_creation) AS date_creation_max |
|---|
| 165 | FROM '.IMAGE_CATEGORY_TABLE.' |
|---|
| 166 | INNER JOIN '.IMAGES_TABLE.' ON image_id = id |
|---|
| 167 | WHERE category_id IN ('.implode(',', $category_ids).') |
|---|
| 168 | '.get_sql_condition_FandF |
|---|
| 169 | ( |
|---|
| 170 | array |
|---|
| 171 | ( |
|---|
| 172 | 'visible_categories' => 'category_id', |
|---|
| 173 | 'visible_images' => 'id' |
|---|
| 174 | ), |
|---|
| 175 | 'AND' |
|---|
| 176 | ).' |
|---|
| 177 | GROUP BY category_id |
|---|
| 178 | ;'; |
|---|
| 179 | $result = pwg_query($query); |
|---|
| 180 | while ($row = mysql_fetch_array($result)) |
|---|
| 181 | { |
|---|
| 182 | $dates_of_category[ $row['category_id'] ] = array( |
|---|
| 183 | 'from' => $row['date_creation_min'], |
|---|
| 184 | 'to' => $row['date_creation_max'], |
|---|
| 185 | ); |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | if ($page['section']=='recent_cats') |
|---|
| 191 | { |
|---|
| 192 | usort($categories, 'global_rank_compare'); |
|---|
| 193 | } |
|---|
| 194 | if (count($categories) > 0) |
|---|
| 195 | { |
|---|
| 196 | $thumbnail_src_of = array(); |
|---|
| 197 | |
|---|
| 198 | $query = ' |
|---|
| 199 | SELECT id, path, tn_ext |
|---|
| 200 | FROM '.IMAGES_TABLE.' |
|---|
| 201 | WHERE id IN ('.implode(',', $image_ids).') |
|---|
| 202 | ;'; |
|---|
| 203 | $result = pwg_query($query); |
|---|
| 204 | while ($row = mysql_fetch_assoc($result)) |
|---|
| 205 | { |
|---|
| 206 | $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); |
|---|
| 207 | } |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | if (count($categories) > 0) |
|---|
| 211 | { |
|---|
| 212 | // Update filtered data |
|---|
| 213 | if (function_exists('update_cats_with_filtered_data')) |
|---|
| 214 | { |
|---|
| 215 | update_cats_with_filtered_data($categories); |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | // add default event handler for rendering category literal description |
|---|
| 219 | add_event_handler('render_category_literal_description', |
|---|
| 220 | create_function('$d', |
|---|
| 221 | 'return strip_tags($d, \'<a><br><p><b><i><small><strong><font>\');')); |
|---|
| 222 | |
|---|
| 223 | trigger_action('loc_begin_index_category_thumbnails', $categories); |
|---|
| 224 | if ($conf['subcatify']) |
|---|
| 225 | { |
|---|
| 226 | $template->set_filename('mainpage_categories', 'mainpage_categories.tpl'); |
|---|
| 227 | |
|---|
| 228 | foreach ($categories as $category) |
|---|
| 229 | { |
|---|
| 230 | if ($page['section']=='recent_cats') |
|---|
| 231 | { |
|---|
| 232 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
|---|
| 233 | } |
|---|
| 234 | else |
|---|
| 235 | { |
|---|
| 236 | $name = $category['name']; |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']); |
|---|
| 240 | |
|---|
| 241 | $template->assign_block_vars( |
|---|
| 242 | 'categories.category', |
|---|
| 243 | array( |
|---|
| 244 | 'SRC' => $thumbnail_src_of[$category['representative_picture_id']], |
|---|
| 245 | 'ALT' => $category['name'], |
|---|
| 246 | 'TITLE' => $lang['hint_category'], |
|---|
| 247 | 'ICON' => $icon_ts, |
|---|
| 248 | |
|---|
| 249 | 'URL' => make_index_url( |
|---|
| 250 | array( |
|---|
| 251 | 'category' => $category |
|---|
| 252 | ) |
|---|
| 253 | ), |
|---|
| 254 | 'CAPTION_NB_IMAGES' => get_display_images_count |
|---|
| 255 | ( |
|---|
| 256 | $category['nb_images'], |
|---|
| 257 | $category['count_images'], |
|---|
| 258 | $category['count_categories'], |
|---|
| 259 | true, |
|---|
| 260 | '<br />' |
|---|
| 261 | ), |
|---|
| 262 | 'DESCRIPTION' => |
|---|
| 263 | trigger_event('render_category_literal_description', |
|---|
| 264 | trigger_event('render_category_description', |
|---|
| 265 | @$category['comment'])), |
|---|
| 266 | 'NAME' => $name, |
|---|
| 267 | ) |
|---|
| 268 | ); |
|---|
| 269 | |
|---|
| 270 | if ($conf['display_fromto']) |
|---|
| 271 | { |
|---|
| 272 | if (isset($dates_of_category[ $category['id'] ])) |
|---|
| 273 | { |
|---|
| 274 | $from = $dates_of_category[ $category['id'] ]['from']; |
|---|
| 275 | $to = $dates_of_category[ $category['id'] ]['to']; |
|---|
| 276 | |
|---|
| 277 | if (!empty($from)) |
|---|
| 278 | { |
|---|
| 279 | $info = ''; |
|---|
| 280 | |
|---|
| 281 | if ($from == $to) |
|---|
| 282 | { |
|---|
| 283 | $info = format_date($from); |
|---|
| 284 | } |
|---|
| 285 | else |
|---|
| 286 | { |
|---|
| 287 | $info = sprintf( |
|---|
| 288 | l10n('from %s to %s'), |
|---|
| 289 | format_date($from), |
|---|
| 290 | format_date($to) |
|---|
| 291 | ); |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | $template->assign_block_vars( |
|---|
| 295 | 'categories.category.dates', |
|---|
| 296 | array( |
|---|
| 297 | 'INFO' => $info, |
|---|
| 298 | ) |
|---|
| 299 | ); |
|---|
| 300 | } |
|---|
| 301 | } |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | //plugins need to add/modify sth in this loop ? |
|---|
| 305 | trigger_action('loc_index_category_thumbnail', |
|---|
| 306 | $category, 'categories.category' ); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories'); |
|---|
| 310 | } |
|---|
| 311 | else |
|---|
| 312 | { |
|---|
| 313 | $template->set_filename( 'thumbnails', 'thumbnails.tpl'); |
|---|
| 314 | // first line |
|---|
| 315 | $template->assign_block_vars('thumbnails.line', array()); |
|---|
| 316 | // current row displayed |
|---|
| 317 | $row_number = 0; |
|---|
| 318 | |
|---|
| 319 | if ($page['section']=='recent_cats') |
|---|
| 320 | { |
|---|
| 321 | $old_level_separator = $conf['level_separator']; |
|---|
| 322 | $conf['level_separator'] = '<br />'; |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | foreach ($categories as $category) |
|---|
| 326 | { |
|---|
| 327 | $template->assign_block_vars( |
|---|
| 328 | 'thumbnails.line.thumbnail', |
|---|
| 329 | array( |
|---|
| 330 | 'IMAGE' => $thumbnail_src_of[ $category['representative_picture_id'] ], |
|---|
| 331 | 'IMAGE_ALT' => $category['name'], |
|---|
| 332 | 'IMAGE_TITLE' => get_display_images_count |
|---|
| 333 | ( |
|---|
| 334 | $category['nb_images'], |
|---|
| 335 | $category['count_images'], |
|---|
| 336 | $category['count_categories'], |
|---|
| 337 | true, |
|---|
| 338 | ' / ' |
|---|
| 339 | ), |
|---|
| 340 | |
|---|
| 341 | 'U_IMG_LINK' => make_index_url( |
|---|
| 342 | array( |
|---|
| 343 | 'category' => $category |
|---|
| 344 | ) |
|---|
| 345 | ), |
|---|
| 346 | 'CLASS' => 'thumbCat', |
|---|
| 347 | ) |
|---|
| 348 | ); |
|---|
| 349 | if ($page['section']=='recent_cats') |
|---|
| 350 | { |
|---|
| 351 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
|---|
| 352 | } |
|---|
| 353 | else |
|---|
| 354 | { |
|---|
| 355 | $name = $category['name']; |
|---|
| 356 | $template->merge_block_vars( |
|---|
| 357 | 'thumbnails.line.thumbnail', |
|---|
| 358 | array( |
|---|
| 359 | 'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']), |
|---|
| 360 | ) |
|---|
| 361 | ); |
|---|
| 362 | } |
|---|
| 363 | $template->assign_block_vars( |
|---|
| 364 | 'thumbnails.line.thumbnail.category_name', |
|---|
| 365 | array( |
|---|
| 366 | 'NAME' => $name |
|---|
| 367 | ) |
|---|
| 368 | ); |
|---|
| 369 | |
|---|
| 370 | //plugins need to add/modify sth in this loop ? |
|---|
| 371 | trigger_action('loc_index_category_thumbnail', |
|---|
| 372 | $category, 'thumbnails.line.thumbnail' ); |
|---|
| 373 | |
|---|
| 374 | // create a new line ? |
|---|
| 375 | if (++$row_number == $user['nb_image_line']) |
|---|
| 376 | { |
|---|
| 377 | $template->assign_block_vars('thumbnails.line', array()); |
|---|
| 378 | $row_number = 0; |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | if ( isset($old_level_separator) ) |
|---|
| 383 | { |
|---|
| 384 | $conf['level_separator']=$old_level_separator; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | $template->assign_var_from_handle('CATEGORIES', 'thumbnails'); |
|---|
| 388 | unset( $template->_tpldata['thumbnails.'] );//maybe write a func for that |
|---|
| 389 | } |
|---|
| 390 | trigger_action('loc_end_index_category_thumbnails', $categories); |
|---|
| 391 | } |
|---|
| 392 | ?> |
|---|