[1597] | 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-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | branch : BSF (Best So Far) |
---|
| 8 | // | file : $Id: category_cats.inc.php 1651 2006-12-13 00:05:16Z rub $ |
---|
| 9 | // | last update : $Date: 2006-12-13 00:05:16 +0000 (Wed, 13 Dec 2006) $ |
---|
| 10 | // | last modifier : $Author: rub $ |
---|
| 11 | // | revision : $Revision: 1651 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * This file is included by the main page to show thumbnails for a category |
---|
| 30 | * that have only subcategories or to show recent categories |
---|
| 31 | * |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | if ($page['section']=='recent_cats') |
---|
| 35 | { |
---|
[1624] | 36 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
[1597] | 37 | $query = ' |
---|
[1624] | 38 | SELECT |
---|
| 39 | id,name, representative_picture_id, comment, nb_images, uppercats, |
---|
[1641] | 40 | date_last, max_date_last, count_images, count_categories |
---|
[1624] | 41 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 42 | ON id = cat_id and user_id = '.$user['id'].' |
---|
[1597] | 43 | WHERE date_last > SUBDATE( |
---|
| 44 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY |
---|
[1624] | 45 | );'; |
---|
[1597] | 46 | } |
---|
| 47 | else |
---|
| 48 | { |
---|
[1624] | 49 | // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE |
---|
[1597] | 50 | $query = ' |
---|
[1624] | 51 | SELECT |
---|
| 52 | id,name, representative_picture_id, comment, nb_images, |
---|
[1641] | 53 | date_last, max_date_last, count_images, count_categories |
---|
[1624] | 54 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 55 | ON id = cat_id and user_id = '.$user['id'].' |
---|
[1597] | 56 | WHERE id_uppercat '. |
---|
[1648] | 57 | (!isset($page['category']) ? 'is NULL' : '= '.$page['category']); |
---|
[1651] | 58 | if ($page['filter_local_mode']) |
---|
[1648] | 59 | { |
---|
| 60 | $query.= ' |
---|
| 61 | AND max_date_last > SUBDATE( |
---|
| 62 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; |
---|
| 63 | } |
---|
| 64 | $query.= ' |
---|
[1597] | 65 | ORDER BY rank |
---|
| 66 | ;'; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | $result = pwg_query($query); |
---|
| 70 | $categories = array(); |
---|
| 71 | $image_ids = array(); |
---|
| 72 | |
---|
| 73 | while ($row = mysql_fetch_assoc($result)) |
---|
| 74 | { |
---|
[1643] | 75 | $row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last']; |
---|
[1624] | 76 | |
---|
[1597] | 77 | if (isset($row['representative_picture_id']) |
---|
| 78 | and is_numeric($row['representative_picture_id'])) |
---|
| 79 | { // if a representative picture is set, it has priority |
---|
| 80 | $image_id = $row['representative_picture_id']; |
---|
| 81 | } |
---|
| 82 | else if ($conf['allow_random_representative']) |
---|
| 83 | {// searching a random representant among elements in sub-categories |
---|
| 84 | $query = ' |
---|
| 85 | SELECT image_id |
---|
| 86 | FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
[1648] | 87 | ON ic.category_id = c.id'; |
---|
[1651] | 88 | if ($page['filter_local_mode'] or $user['filter_global_mode']) |
---|
[1648] | 89 | { |
---|
| 90 | $query.= ' |
---|
| 91 | INNER JOIN '.IMAGES_TABLE.' AS i on ic.image_id = i.id '; |
---|
| 92 | } |
---|
| 93 | $query.= ' |
---|
[1597] | 94 | WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' |
---|
[1648] | 95 | AND c.id NOT IN ('.$user['forbidden_categories'].')'; |
---|
[1651] | 96 | if ($page['filter_local_mode'] or $user['filter_global_mode']) |
---|
[1648] | 97 | { |
---|
| 98 | $query.= ' |
---|
| 99 | AND i.date_available > SUBDATE( |
---|
| 100 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; |
---|
| 101 | } |
---|
| 102 | $query.= ' |
---|
[1597] | 103 | ORDER BY RAND() |
---|
| 104 | LIMIT 0,1 |
---|
| 105 | ;'; |
---|
| 106 | $subresult = pwg_query($query); |
---|
| 107 | if (mysql_num_rows($subresult) > 0) |
---|
| 108 | { |
---|
| 109 | list($image_id) = mysql_fetch_row($subresult); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | { // searching a random representant among representant of sub-categories |
---|
| 114 | $query = ' |
---|
| 115 | SELECT representative_picture_id |
---|
[1648] | 116 | FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' |
---|
| 117 | ON id = cat_id and user_id = '.$user['id'].' |
---|
[1597] | 118 | WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\' |
---|
[1648] | 119 | AND representative_picture_id IS NOT NULL'; |
---|
[1651] | 120 | if ($page['filter_local_mode'] or $user['filter_global_mode']) |
---|
[1648] | 121 | { |
---|
| 122 | $query.= ' |
---|
| 123 | AND max_date_last > SUBDATE( |
---|
| 124 | CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; |
---|
| 125 | } |
---|
| 126 | $query.= ' |
---|
[1597] | 127 | ORDER BY RAND() |
---|
| 128 | LIMIT 0,1 |
---|
| 129 | ;'; |
---|
| 130 | $subresult = pwg_query($query); |
---|
| 131 | if (mysql_num_rows($subresult) > 0) |
---|
| 132 | { |
---|
| 133 | list($image_id) = mysql_fetch_row($subresult); |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | if (isset($image_id)) |
---|
| 138 | { |
---|
| 139 | $row['representative_picture_id'] = $image_id; |
---|
| 140 | array_push($image_ids, $image_id); |
---|
| 141 | array_push($categories, $row); |
---|
| 142 | } |
---|
| 143 | unset($image_id); |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | if (count($categories) > 0) |
---|
| 147 | { |
---|
| 148 | $thumbnail_src_of = array(); |
---|
| 149 | |
---|
| 150 | $query = ' |
---|
| 151 | SELECT id, path, tn_ext |
---|
| 152 | FROM '.IMAGES_TABLE.' |
---|
| 153 | WHERE id IN ('.implode(',', $image_ids).') |
---|
| 154 | ;'; |
---|
| 155 | $result = pwg_query($query); |
---|
| 156 | while ($row = mysql_fetch_assoc($result)) |
---|
| 157 | { |
---|
| 158 | $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | if (count($categories) > 0) |
---|
| 163 | { |
---|
| 164 | if ($conf['subcatify']) |
---|
| 165 | { |
---|
| 166 | $template->set_filenames( |
---|
| 167 | array( |
---|
| 168 | 'mainpage_categories' => 'mainpage_categories.tpl', |
---|
| 169 | ) |
---|
| 170 | ); |
---|
| 171 | |
---|
| 172 | foreach ($categories as $category) |
---|
| 173 | { |
---|
| 174 | $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>'); |
---|
| 175 | if ($page['section']=='recent_cats') |
---|
| 176 | { |
---|
| 177 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
| 178 | } |
---|
| 179 | else |
---|
| 180 | { |
---|
| 181 | $name = $category['name']; |
---|
| 182 | } |
---|
| 183 | |
---|
[1638] | 184 | $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']); |
---|
| 185 | |
---|
[1597] | 186 | $template->assign_block_vars( |
---|
| 187 | 'categories.category', |
---|
| 188 | array( |
---|
| 189 | 'SRC' => $thumbnail_src_of[$category['representative_picture_id']], |
---|
| 190 | 'ALT' => $category['name'], |
---|
| 191 | 'TITLE' => $lang['hint_category'], |
---|
| 192 | 'ICON' => $icon_ts, |
---|
| 193 | |
---|
| 194 | 'URL' => make_index_url( |
---|
| 195 | array( |
---|
| 196 | 'category' => $category['id'], |
---|
| 197 | 'cat_name' => $category['name'], |
---|
| 198 | ) |
---|
| 199 | ), |
---|
[1624] | 200 | 'CAPTION_NB_IMAGES' => get_display_images_count |
---|
| 201 | ( |
---|
| 202 | $category['nb_images'], |
---|
| 203 | $category['count_images'], |
---|
| 204 | $category['count_categories'] |
---|
| 205 | ), |
---|
[1597] | 206 | 'DESCRIPTION' => @$comment, |
---|
| 207 | 'NAME' => $name, |
---|
| 208 | ) |
---|
| 209 | ); |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories'); |
---|
| 213 | } |
---|
| 214 | else |
---|
| 215 | { |
---|
| 216 | $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',)); |
---|
| 217 | // first line |
---|
| 218 | $template->assign_block_vars('thumbnails.line', array()); |
---|
| 219 | // current row displayed |
---|
| 220 | $row_number = 0; |
---|
| 221 | |
---|
| 222 | if ($page['section']=='recent_cats') |
---|
| 223 | { |
---|
| 224 | $old_level_separator = $conf['level_separator']; |
---|
| 225 | $conf['level_separator'] = '<br />'; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | foreach ($categories as $category) |
---|
| 229 | { |
---|
| 230 | $template->assign_block_vars( |
---|
| 231 | 'thumbnails.line.thumbnail', |
---|
| 232 | array( |
---|
| 233 | 'IMAGE' => $thumbnail_src_of[ $category['representative_picture_id'] ], |
---|
| 234 | 'IMAGE_ALT' => $category['name'], |
---|
| 235 | 'IMAGE_TITLE' => $lang['hint_category'], |
---|
| 236 | |
---|
| 237 | 'U_IMG_LINK' => make_index_url( |
---|
| 238 | array( |
---|
| 239 | 'category' => $category['id'], |
---|
| 240 | 'cat_name' => $category['name'], |
---|
| 241 | ) |
---|
| 242 | ), |
---|
| 243 | 'CLASS' => 'thumbCat', |
---|
| 244 | ) |
---|
| 245 | ); |
---|
| 246 | if ($page['section']=='recent_cats') |
---|
| 247 | { |
---|
| 248 | $name = get_cat_display_name_cache($category['uppercats'], null, false); |
---|
| 249 | } |
---|
| 250 | else |
---|
| 251 | { |
---|
| 252 | $name = $category['name']; |
---|
| 253 | $template->merge_block_vars( |
---|
| 254 | 'thumbnails.line.thumbnail', |
---|
| 255 | array( |
---|
[1624] | 256 | 'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']), |
---|
[1597] | 257 | ) |
---|
| 258 | ); |
---|
| 259 | } |
---|
| 260 | $template->assign_block_vars( |
---|
| 261 | 'thumbnails.line.thumbnail.category_name', |
---|
| 262 | array( |
---|
| 263 | 'NAME' => $name |
---|
| 264 | ) |
---|
| 265 | ); |
---|
| 266 | |
---|
| 267 | // create a new line ? |
---|
| 268 | if (++$row_number == $user['nb_image_line']) |
---|
| 269 | { |
---|
| 270 | $template->assign_block_vars('thumbnails.line', array()); |
---|
| 271 | $row_number = 0; |
---|
| 272 | } |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | if ( isset($old_level_separator) ) |
---|
| 276 | { |
---|
| 277 | $conf['level_separator']=$old_level_separator; |
---|
| 278 | } |
---|
| 279 | |
---|
| 280 | $template->assign_var_from_handle('THUMBNAILS', 'thumbnails'); |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | ?> |
---|