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