[1597] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[1719] | 5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[1597] | 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | file : $Id: category_cats.inc.php 1900 2007-03-12 22:33:53Z rub $ |
---|
| 8 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
| 9 | // | last modifier : $Author: rub $ |
---|
| 10 | // | revision : $Revision: 1900 $ |
---|
| 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 | { |
---|
[1624] | 35 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
[1597] | 36 | $query = ' |
---|
[1624] | 37 | SELECT |
---|
[1866] | 38 | id, name, permalink, representative_picture_id, comment, nb_images, uppercats, |
---|
[1719] | 39 | date_last, max_date_last, count_images, count_categories, global_rank |
---|
[1624] | 40 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 41 | ON id = cat_id and user_id = '.$user['id'].' |
---|
[1876] | 42 | WHERE date_last >= SUBDATE( |
---|
[1597] | 43 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY |
---|
[1677] | 44 | ) |
---|
| 45 | '.get_sql_condition_FandF |
---|
| 46 | ( |
---|
| 47 | array |
---|
| 48 | ( |
---|
| 49 | 'visible_categories' => 'id', |
---|
| 50 | ), |
---|
| 51 | 'AND' |
---|
| 52 | ).' |
---|
| 53 | ;'; |
---|
[1597] | 54 | } |
---|
| 55 | else |
---|
| 56 | { |
---|
[1624] | 57 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
[1597] | 58 | $query = ' |
---|
[1624] | 59 | SELECT |
---|
[1866] | 60 | id, name, permalink, representative_picture_id, comment, nb_images, |
---|
[1641] | 61 | date_last, max_date_last, count_images, count_categories |
---|
[1624] | 62 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 63 | ON id = cat_id and user_id = '.$user['id'].' |
---|
[1597] | 64 | WHERE id_uppercat '. |
---|
[1861] | 65 | (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).' |
---|
[1677] | 66 | '.get_sql_condition_FandF |
---|
| 67 | ( |
---|
| 68 | array |
---|
| 69 | ( |
---|
| 70 | 'visible_categories' => 'id', |
---|
| 71 | ), |
---|
| 72 | 'AND' |
---|
| 73 | ).' |
---|
[1597] | 74 | ORDER BY rank |
---|
| 75 | ;'; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | $result = pwg_query($query); |
---|
| 79 | $categories = array(); |
---|
| 80 | $image_ids = array(); |
---|
| 81 | |
---|
| 82 | while ($row = mysql_fetch_assoc($result)) |
---|
| 83 | { |
---|
[1643] | 84 | $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last']; |
---|
[1624] | 85 | |
---|
[1597] | 86 | if (isset($row['representative_picture_id']) |
---|
| 87 | and is_numeric($row['representative_picture_id'])) |
---|
| 88 | { // if a representative picture is set, it has priority |
---|
| 89 | $image_id = $row['representative_picture_id']; |
---|
| 90 | } |
---|
| 91 | else if ($conf['allow_random_representative']) |
---|
| 92 | {// searching a random representant among elements in sub-categories |
---|
| 93 | $query = ' |
---|
| 94 | SELECT image_id |
---|
| 95 | FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
[1648] | 96 | ON ic.category_id = c.id'; |
---|
| 97 | $query.= ' |
---|
[1597] | 98 | WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' |
---|
[1677] | 99 | '.get_sql_condition_FandF |
---|
| 100 | ( |
---|
| 101 | array |
---|
| 102 | ( |
---|
| 103 | 'forbidden_categories' => 'c.id', |
---|
| 104 | 'visible_categories' => 'c.id', |
---|
| 105 | 'visible_images' => 'image_id' |
---|
| 106 | ), |
---|
| 107 | 'AND' |
---|
| 108 | ).' |
---|
[1597] | 109 | ORDER BY RAND() |
---|
| 110 | LIMIT 0,1 |
---|
| 111 | ;'; |
---|
| 112 | $subresult = pwg_query($query); |
---|
| 113 | if (mysql_num_rows($subresult) > 0) |
---|
| 114 | { |
---|
| 115 | list($image_id) = mysql_fetch_row($subresult); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { // searching a random representant among representant of sub-categories |
---|
| 120 | $query = ' |
---|
| 121 | SELECT representative_picture_id |
---|
[1648] | 122 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 123 | ON id = cat_id and user_id = '.$user['id'].' |
---|
[1597] | 124 | WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' |
---|
[1677] | 125 | AND representative_picture_id IS NOT NULL |
---|
| 126 | '.get_sql_condition_FandF |
---|
| 127 | ( |
---|
| 128 | array |
---|
| 129 | ( |
---|
| 130 | 'visible_categories' => 'id', |
---|
| 131 | ), |
---|
| 132 | 'AND' |
---|
| 133 | ).' |
---|
[1597] | 134 | ORDER BY RAND() |
---|
| 135 | LIMIT 0,1 |
---|
| 136 | ;'; |
---|
| 137 | $subresult = pwg_query($query); |
---|
| 138 | if (mysql_num_rows($subresult) > 0) |
---|
| 139 | { |
---|
| 140 | list($image_id) = mysql_fetch_row($subresult); |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | if (isset($image_id)) |
---|
| 145 | { |
---|
| 146 | $row['representative_picture_id'] = $image_id; |
---|
| 147 | array_push($image_ids, $image_id); |
---|
| 148 | array_push($categories, $row); |
---|
| 149 | } |
---|
| 150 | unset($image_id); |
---|
| 151 | } |
---|
| 152 | |
---|
[1719] | 153 | if ($page['section']=='recent_cats') |
---|
| 154 | { |
---|
| 155 | usort($categories, 'global_rank_compare'); |
---|
| 156 | } |
---|
[1597] | 157 | if (count($categories) > 0) |
---|
| 158 | { |
---|
| 159 | $thumbnail_src_of = array(); |
---|
| 160 | |
---|
| 161 | $query = ' |
---|
| 162 | SELECT id, path, tn_ext |
---|
| 163 | FROM '.IMAGES_TABLE.' |
---|
| 164 | WHERE id IN ('.implode(',', $image_ids).') |
---|
| 165 | ;'; |
---|
| 166 | $result = pwg_query($query); |
---|
| 167 | while ($row = mysql_fetch_assoc($result)) |
---|
| 168 | { |
---|
| 169 | $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | if (count($categories) > 0) |
---|
| 174 | { |
---|
[1677] | 175 | // Update filtered data |
---|
[1722] | 176 | if (function_exists('update_cats_with_filtered_data')) |
---|
| 177 | { |
---|
| 178 | update_cats_with_filtered_data($categories); |
---|
| 179 | } |
---|
[1880] | 180 | trigger_action('loc_begin_index_category_thumbnails', $categories); |
---|
[1597] | 181 | if ($conf['subcatify']) |
---|
| 182 | { |
---|
[1820] | 183 | $template->set_filename('mainpage_categories', 'mainpage_categories.tpl'); |
---|
[1597] | 184 | |
---|
| 185 | foreach ($categories as $category) |
---|
| 186 | { |
---|
| 187 | $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>'); |
---|
| 188 | if ($page['section']=='recent_cats') |
---|
| 189 | { |
---|
| 190 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
| 191 | } |
---|
| 192 | else |
---|
| 193 | { |
---|
| 194 | $name = $category['name']; |
---|
| 195 | } |
---|
| 196 | |
---|
[1638] | 197 | $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']); |
---|
| 198 | |
---|
[1597] | 199 | $template->assign_block_vars( |
---|
| 200 | 'categories.category', |
---|
| 201 | array( |
---|
| 202 | 'SRC' => $thumbnail_src_of[$category['representative_picture_id']], |
---|
| 203 | 'ALT' => $category['name'], |
---|
| 204 | 'TITLE' => $lang['hint_category'], |
---|
| 205 | 'ICON' => $icon_ts, |
---|
| 206 | |
---|
| 207 | 'URL' => make_index_url( |
---|
| 208 | array( |
---|
[1861] | 209 | 'category' => $category |
---|
[1597] | 210 | ) |
---|
| 211 | ), |
---|
[1624] | 212 | 'CAPTION_NB_IMAGES' => get_display_images_count |
---|
| 213 | ( |
---|
| 214 | $category['nb_images'], |
---|
| 215 | $category['count_images'], |
---|
[1851] | 216 | $category['count_categories'], |
---|
| 217 | true, |
---|
[1869] | 218 | '<br />' |
---|
[1624] | 219 | ), |
---|
[1597] | 220 | 'DESCRIPTION' => @$comment, |
---|
| 221 | 'NAME' => $name, |
---|
| 222 | ) |
---|
| 223 | ); |
---|
[1880] | 224 | |
---|
| 225 | //plugins need to add/modify sth in this loop ? |
---|
| 226 | trigger_action('loc_index_category_thumbnail', |
---|
| 227 | $category, 'categories.category' ); |
---|
[1597] | 228 | } |
---|
| 229 | |
---|
| 230 | $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories'); |
---|
| 231 | } |
---|
| 232 | else |
---|
| 233 | { |
---|
[1820] | 234 | $template->set_filename( 'thumbnails', 'thumbnails.tpl'); |
---|
[1597] | 235 | // first line |
---|
| 236 | $template->assign_block_vars('thumbnails.line', array()); |
---|
| 237 | // current row displayed |
---|
| 238 | $row_number = 0; |
---|
| 239 | |
---|
| 240 | if ($page['section']=='recent_cats') |
---|
| 241 | { |
---|
| 242 | $old_level_separator = $conf['level_separator']; |
---|
| 243 | $conf['level_separator'] = '<br />'; |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | foreach ($categories as $category) |
---|
| 247 | { |
---|
| 248 | $template->assign_block_vars( |
---|
| 249 | 'thumbnails.line.thumbnail', |
---|
| 250 | array( |
---|
| 251 | 'IMAGE' => $thumbnail_src_of[ $category['representative_picture_id'] ], |
---|
| 252 | 'IMAGE_ALT' => $category['name'], |
---|
[1840] | 253 | 'IMAGE_TITLE' => get_display_images_count |
---|
| 254 | ( |
---|
| 255 | $category['nb_images'], |
---|
| 256 | $category['count_images'], |
---|
[1851] | 257 | $category['count_categories'], |
---|
| 258 | true, |
---|
[1884] | 259 | ' / ' |
---|
[1840] | 260 | ), |
---|
[1597] | 261 | |
---|
| 262 | 'U_IMG_LINK' => make_index_url( |
---|
| 263 | array( |
---|
[1861] | 264 | 'category' => $category |
---|
[1597] | 265 | ) |
---|
| 266 | ), |
---|
| 267 | 'CLASS' => 'thumbCat', |
---|
| 268 | ) |
---|
| 269 | ); |
---|
| 270 | if ($page['section']=='recent_cats') |
---|
| 271 | { |
---|
| 272 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
| 273 | } |
---|
| 274 | else |
---|
| 275 | { |
---|
| 276 | $name = $category['name']; |
---|
| 277 | $template->merge_block_vars( |
---|
| 278 | 'thumbnails.line.thumbnail', |
---|
| 279 | array( |
---|
[1624] | 280 | 'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']), |
---|
[1597] | 281 | ) |
---|
| 282 | ); |
---|
| 283 | } |
---|
| 284 | $template->assign_block_vars( |
---|
| 285 | 'thumbnails.line.thumbnail.category_name', |
---|
| 286 | array( |
---|
| 287 | 'NAME' => $name |
---|
| 288 | ) |
---|
| 289 | ); |
---|
| 290 | |
---|
[1880] | 291 | //plugins need to add/modify sth in this loop ? |
---|
| 292 | trigger_action('loc_index_category_thumbnail', |
---|
| 293 | $category, 'thumbnails.line.thumbnail' ); |
---|
| 294 | |
---|
[1597] | 295 | // create a new line ? |
---|
| 296 | if (++$row_number == $user['nb_image_line']) |
---|
| 297 | { |
---|
| 298 | $template->assign_block_vars('thumbnails.line', array()); |
---|
| 299 | $row_number = 0; |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | if ( isset($old_level_separator) ) |
---|
| 304 | { |
---|
| 305 | $conf['level_separator']=$old_level_separator; |
---|
| 306 | } |
---|
| 307 | |
---|
[1820] | 308 | $template->assign_var_from_handle('CATEGORIES', 'thumbnails'); |
---|
| 309 | unset( $template->_tpldata['thumbnails.'] );//maybe write a func for that |
---|
[1597] | 310 | } |
---|
[1880] | 311 | trigger_action('loc_end_index_category_thumbnails', $categories); |
---|
[1597] | 312 | } |
---|
| 313 | ?> |
---|