1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | category.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-06-15 20:00:40 +0000 (Tue, 15 Jun 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 428 $ |
---|
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 | //--------------------------------------------------------------------- include |
---|
29 | define('PHPWG_ROOT_PATH','./'); |
---|
30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
31 | //---------------------------------------------------------------------- logout |
---|
32 | if ( isset( $_GET['act'] ) |
---|
33 | and $_GET['act'] == 'logout' |
---|
34 | and isset( $_COOKIE['id'] ) ) |
---|
35 | { |
---|
36 | // cookie deletion if exists |
---|
37 | setcookie( 'id', '', 0, cookie_path() ); |
---|
38 | $url = 'category.php'; |
---|
39 | redirect( $url ); |
---|
40 | } |
---|
41 | //-------------------------------------------------- access authorization check |
---|
42 | if ( isset( $_GET['cat'] ) ) check_cat_id( $_GET['cat'] ); |
---|
43 | check_login_authorization(); |
---|
44 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
45 | { |
---|
46 | check_restrictions( $page['cat'] ); |
---|
47 | } |
---|
48 | |
---|
49 | //-------------------------------------------------------------- initialization |
---|
50 | function display_category( $category, $indent ) |
---|
51 | { |
---|
52 | global $user,$template,$page; |
---|
53 | |
---|
54 | $url = PHPWG_ROOT_PATH.'category.php?cat='.$category['id']; |
---|
55 | |
---|
56 | $style = ''; |
---|
57 | if ( isset( $page['cat'] ) |
---|
58 | and is_numeric( $page['cat'] ) |
---|
59 | and $category['id'] == $page['cat'] ) |
---|
60 | { |
---|
61 | $style = 'font-weight:normal;color:yellow;'; |
---|
62 | } |
---|
63 | |
---|
64 | $name = $category['name']; |
---|
65 | if (empty($name)) $name = str_replace( '_', ' ', $category['dir'] ); |
---|
66 | |
---|
67 | $template->assign_block_vars('category', array( |
---|
68 | 'T_NAME' => $style, |
---|
69 | 'LINK_NAME' => $name, |
---|
70 | 'INDENT' => $indent, |
---|
71 | 'U_LINK' => add_session_id($url), |
---|
72 | 'BULLET_IMAGE' => $user['lien_collapsed']) |
---|
73 | ); |
---|
74 | |
---|
75 | if ( $category['nb_images'] > 0 ) |
---|
76 | { |
---|
77 | $template->assign_block_vars( |
---|
78 | 'category.infocat', |
---|
79 | array( |
---|
80 | 'TOTAL_CAT'=>$category['nb_images'], |
---|
81 | 'CAT_ICON'=>get_icon($category['date_last']) |
---|
82 | )); |
---|
83 | } |
---|
84 | |
---|
85 | // recursive call |
---|
86 | if ( $category['expanded'] ) |
---|
87 | { |
---|
88 | foreach ( $category['subcats'] as $subcat ) { |
---|
89 | display_category( $subcat, $indent.str_repeat( ' ', 2 )); |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | // detection of the start picture to display |
---|
95 | if ( !isset( $_GET['start'] ) |
---|
96 | or !is_numeric( $_GET['start'] ) |
---|
97 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
98 | $page['start'] = 0; |
---|
99 | else |
---|
100 | $page['start'] = $_GET['start']; |
---|
101 | |
---|
102 | initialize_category(); |
---|
103 | |
---|
104 | // creation of the array containing the cat ids to expand in the menu |
---|
105 | // $page['tab_expand'] contains an array with the category ids |
---|
106 | // $page['expand'] contains the string to display in URL with comma |
---|
107 | $page['tab_expand'] = array(); |
---|
108 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
109 | { |
---|
110 | // the category displayed (in the URL cat=23) must be seen in the menu -> |
---|
111 | // parent categories must be expanded |
---|
112 | $uppercats = explode( ',', $page['uppercats'] ); |
---|
113 | foreach ( $uppercats as $uppercat ) { |
---|
114 | array_push( $page['tab_expand'], $uppercat ); |
---|
115 | } |
---|
116 | } |
---|
117 | // in case of expanding all authorized cats $page['tab_expand'] is empty |
---|
118 | if ( $user['expand'] ) |
---|
119 | { |
---|
120 | $page['tab_expand'] = array(); |
---|
121 | } |
---|
122 | |
---|
123 | // Sometimes, a "num" is provided in the URL. It is the number |
---|
124 | // of the picture to show. This picture must be in the thumbnails page. |
---|
125 | // We have to find the right $page['start'] that show the num picture |
---|
126 | // in this category |
---|
127 | if ( isset( $_GET['num'] ) |
---|
128 | and is_numeric( $_GET['num'] ) |
---|
129 | and $_GET['num'] >= 0 ) |
---|
130 | { |
---|
131 | $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] ); |
---|
132 | $page['start']*= $user['nb_image_page']; |
---|
133 | } |
---|
134 | // creating the structure of the categories (useful for displaying the menu) |
---|
135 | // creating the plain structure : array of all the available categories and |
---|
136 | // their relative informations, see the definition of the function |
---|
137 | // get_user_plain_structure for further details. |
---|
138 | $page['plain_structure'] = get_user_plain_structure(); |
---|
139 | $page['structure'] = create_user_structure( '' ); |
---|
140 | $page['structure'] = update_structure( $page['structure'] ); |
---|
141 | |
---|
142 | //----------------------------------------------------- template initialization |
---|
143 | |
---|
144 | // |
---|
145 | // Start output of page |
---|
146 | // |
---|
147 | $title = $page['title']; |
---|
148 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
149 | |
---|
150 | $template->set_filenames( array('category'=>'category.tpl') ); |
---|
151 | |
---|
152 | //-------------------------------------------------------------- category title |
---|
153 | if ( !isset( $page['title'] ) ) |
---|
154 | { |
---|
155 | $page['title'] = $lang['no_category']; |
---|
156 | } |
---|
157 | $template_title = $page['title']; |
---|
158 | if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 ) |
---|
159 | { |
---|
160 | $template_title.= ' ['.$page['cat_nb_images'].']'; |
---|
161 | } |
---|
162 | |
---|
163 | $template->assign_vars(array( |
---|
164 | 'NB_PICTURE' => count_user_total_images(), |
---|
165 | 'TITLE' => $template_title, |
---|
166 | 'USERNAME' => $user['username'], |
---|
167 | 'TOP_VISITED'=>$conf['top_number'], |
---|
168 | |
---|
169 | 'L_CATEGORIES' => $lang['categories'], |
---|
170 | 'L_HINT_CATEGORY' => $lang['hint_category'], |
---|
171 | 'L_SUBCAT' => $lang['sub-cat'], |
---|
172 | 'L_IMG_AVAILABLE' => $lang['images_available'], |
---|
173 | 'L_TOTAL' => $lang['total'], |
---|
174 | 'L_FAVORITE_HINT' => $lang['favorite_cat_hint'], |
---|
175 | 'L_FAVORITE' => $lang['favorite_cat'], |
---|
176 | 'L_SPECIAL_CATEGORIES' => $lang['special_categories'], |
---|
177 | 'L_MOST_VISITED_HINT' => $lang['most_visited_cat_hint'], |
---|
178 | 'L_MOST_VISITED' => $lang['most_visited_cat'], |
---|
179 | 'L_RECENT_HINT' => $lang['recent_cat_hint'], |
---|
180 | 'L_RECENT' => $lang['recent_cat'], |
---|
181 | 'L_CALENDAR' => $lang['calendar'], |
---|
182 | 'L_CALENDAR_HINT' => $lang['calendar_hint'], |
---|
183 | 'L_SUMMARY' => $lang['title_menu'], |
---|
184 | 'L_UPLOAD' => $lang['upload_picture'], |
---|
185 | 'L_COMMENT' => $lang['comments'], |
---|
186 | 'L_IDENTIFY' => $lang['ident_title'], |
---|
187 | 'L_SUBMIT' => $lang['menu_login'], |
---|
188 | 'L_USERNAME' => $lang['login'], |
---|
189 | 'L_PASSWORD' => $lang['password'], |
---|
190 | 'L_HELLO' => $lang['hello'], |
---|
191 | 'L_LOGOUT' => $lang['logout'], |
---|
192 | 'L_ADMIN' => $lang['admin'], |
---|
193 | 'L_ADMIN_HINT' => $lang['hint_admin'], |
---|
194 | 'L_PROFILE' => $lang['customize'], |
---|
195 | 'L_PROFILE_HINT' => $lang['hint_customize'], |
---|
196 | |
---|
197 | 'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ), |
---|
198 | |
---|
199 | 'T_COLLAPSED' => $user['lien_collapsed'], |
---|
200 | 'T_SHORT'=>get_icon( time() ), |
---|
201 | 'T_LONG'=>get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) ), |
---|
202 | |
---|
203 | 'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ), |
---|
204 | 'U_FAVORITE' => add_session_id( PHPWG_ROOT_PATH.'category.php?cat=fav' ), |
---|
205 | 'U_MOST_VISITED'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=most_visited' ), |
---|
206 | 'U_RECENT'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent' ), |
---|
207 | 'U_CALENDAR'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=calendar' ), |
---|
208 | 'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout', |
---|
209 | 'U_ADMIN'=>add_session_id( PHPWG_ROOT_PATH.'admin.php' ), |
---|
210 | 'U_PROFILE'=>add_session_id(PHPWG_ROOT_PATH.'profile.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] )) |
---|
211 | ) |
---|
212 | ); |
---|
213 | |
---|
214 | foreach ( $page['structure'] as $category ) { |
---|
215 | // display category is a function relative to the template |
---|
216 | display_category( $category, ' '); |
---|
217 | } |
---|
218 | |
---|
219 | // authentification mode management |
---|
220 | if ( !$user['is_the_guest'] ) |
---|
221 | { |
---|
222 | // searching the number of favorite picture |
---|
223 | $query = 'SELECT COUNT(*) AS count'; |
---|
224 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';'; |
---|
225 | $result = mysql_query( $query ); |
---|
226 | $row = mysql_fetch_array( $result ); |
---|
227 | $template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) ); |
---|
228 | $template->assign_block_vars('username', array()); |
---|
229 | } |
---|
230 | //--------------------------------------------------------------------- summary |
---|
231 | |
---|
232 | if ( !$user['is_the_guest'] ) |
---|
233 | { |
---|
234 | $template->assign_block_vars('logout',array()); |
---|
235 | // administration link |
---|
236 | if ( $user['status'] == 'admin' ) |
---|
237 | { |
---|
238 | $template->assign_block_vars('logout.admin', array()); |
---|
239 | } |
---|
240 | } |
---|
241 | else |
---|
242 | { |
---|
243 | $template->assign_block_vars('login',array()); |
---|
244 | } |
---|
245 | |
---|
246 | // search link |
---|
247 | $template->assign_block_vars('summary', array( |
---|
248 | 'TITLE'=>$lang['hint_search'], |
---|
249 | 'NAME'=>$lang['search'], |
---|
250 | 'U_SUMMARY'=>add_session_id( 'search.php' ), |
---|
251 | )); |
---|
252 | |
---|
253 | // comments link |
---|
254 | $template->assign_block_vars('summary', array( |
---|
255 | 'TITLE'=>$lang['hint_comments'], |
---|
256 | 'NAME'=>$lang['comments'], |
---|
257 | 'U_SUMMARY'=>add_session_id( 'comments.php' ), |
---|
258 | )); |
---|
259 | |
---|
260 | // about link |
---|
261 | $template->assign_block_vars('summary', array( |
---|
262 | 'TITLE'=>$lang['hint_about'], |
---|
263 | 'NAME'=>$lang['about'], |
---|
264 | 'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) ) |
---|
265 | )); |
---|
266 | |
---|
267 | //------------------------------------------------------------------ thumbnails |
---|
268 | if ( isset( $page['cat'] ) && $page['cat_nb_images'] != 0 ) |
---|
269 | { |
---|
270 | $array_cat_directories = array(); |
---|
271 | |
---|
272 | $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize'; |
---|
273 | $query.= ',storage_category_id'; |
---|
274 | $query.= ' FROM '.IMAGES_TABLE.' AS i'; |
---|
275 | $query.=' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id'; |
---|
276 | $query.= $page['where']; |
---|
277 | $query.= $conf['order_by']; |
---|
278 | $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; |
---|
279 | $query.= ';'; |
---|
280 | $result = mysql_query( $query ); |
---|
281 | |
---|
282 | $template->assign_block_vars('thumbnails', array()); |
---|
283 | |
---|
284 | // iteration counter to use a new <tr> every "$nb_image_line" pictures |
---|
285 | $cell_number = 0; |
---|
286 | // iteration counter to be sure not to create too much lines in the table |
---|
287 | $line_number = 0; |
---|
288 | |
---|
289 | $row_number = 1; |
---|
290 | $line_opened = false; |
---|
291 | $displayed_pics = 0; |
---|
292 | |
---|
293 | while ( $row = mysql_fetch_array( $result ) ) |
---|
294 | { |
---|
295 | // retrieving the storage dir of the picture |
---|
296 | if ( !isset($array_cat_directories[$row['storage_category_id']])) |
---|
297 | { |
---|
298 | $array_cat_directories[$row['storage_category_id']] = |
---|
299 | get_complete_dir( $row['storage_category_id'] ); |
---|
300 | } |
---|
301 | $cat_directory = $array_cat_directories[$row['storage_category_id']]; |
---|
302 | |
---|
303 | $file = get_filename_wo_extension( $row['file'] ); |
---|
304 | // name of the picture |
---|
305 | if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name']; |
---|
306 | else $name = str_replace( '_', ' ', $file ); |
---|
307 | |
---|
308 | if ( $page['cat'] == 'search' ) |
---|
309 | { |
---|
310 | $name = replace_search( $name, $_GET['search'] ); |
---|
311 | } |
---|
312 | // thumbnail url |
---|
313 | $thumbnail_url = $cat_directory; |
---|
314 | $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
315 | $thumbnail_url.= $file.'.'.$row['tn_ext']; |
---|
316 | // message in title for the thumbnail |
---|
317 | $thumbnail_title = $row['file']; |
---|
318 | if ( $row['filesize'] == '' ) |
---|
319 | $poids = floor( filesize( $cat_directory.$row['file'] ) / 1024 ); |
---|
320 | else |
---|
321 | $poids = $row['filesize']; |
---|
322 | $thumbnail_title .= ' : '.$poids.' KB'; |
---|
323 | // url link on picture.php page |
---|
324 | $url_link = PHPWG_ROOT_PATH.'picture.php?cat='.$page['cat']; |
---|
325 | $url_link.= '&image_id='.$row['id']; |
---|
326 | if ( $page['cat'] == 'search' ) |
---|
327 | { |
---|
328 | $url_link.= '&search='.$_GET['search'].'&mode='.$_GET['mode']; |
---|
329 | } |
---|
330 | // date of availability for creation icon |
---|
331 | list( $year,$month,$day ) = explode( '-', $row['date_available'] ); |
---|
332 | $date = mktime( 0, 0, 0, $month, $day, $year ); |
---|
333 | |
---|
334 | // create a new line ? |
---|
335 | if ( (!$line_opened or $row_number++ == $user['nb_image_line'] ) |
---|
336 | and $displayed_pics++ < mysql_num_rows( $result ) ) |
---|
337 | { |
---|
338 | $template->assign_block_vars('thumbnails.line', array()); |
---|
339 | $row_number = 1; |
---|
340 | $line_opened = true; |
---|
341 | } |
---|
342 | |
---|
343 | $template->assign_block_vars( |
---|
344 | 'thumbnails.line.thumbnail', |
---|
345 | array( |
---|
346 | 'IMAGE'=>$thumbnail_url, |
---|
347 | 'IMAGE_ALT'=>$row['file'], |
---|
348 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
349 | 'IMAGE_NAME'=>$name, |
---|
350 | 'IMAGE_TS'=>get_icon( $date ), |
---|
351 | |
---|
352 | 'U_IMG_LINK'=>add_session_id( $url_link ) |
---|
353 | )); |
---|
354 | |
---|
355 | if ( $conf['show_comments'] and $user['show_nb_comments'] ) |
---|
356 | { |
---|
357 | $query = 'SELECT COUNT(*) AS nb_comments'; |
---|
358 | $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id']; |
---|
359 | $query.= " AND validated = 'true'"; |
---|
360 | $query.= ';'; |
---|
361 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
362 | $template->assign_block_vars( |
---|
363 | 'thumbnails.line.thumbnail.nb_comments', |
---|
364 | array('NB_COMMENTS'=>$row['nb_comments']) ); |
---|
365 | } |
---|
366 | } |
---|
367 | } |
---|
368 | //-------------------------------------------------------------------- calendar |
---|
369 | elseif ( isset( $page['cat'] ) and $page['cat'] == 'calendar' ) |
---|
370 | { |
---|
371 | // years of image availability |
---|
372 | $query = 'SELECT DISTINCT(YEAR(date_available)) AS year'; |
---|
373 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
374 | $query.= $page['where']; |
---|
375 | $query.= ' AND id = image_id'; |
---|
376 | $query.= ' ORDER BY year'; |
---|
377 | $query.= ';'; |
---|
378 | $result = mysql_query( $query ); |
---|
379 | $calendar_years = array(); |
---|
380 | while ( $row = mysql_fetch_array( $result ) ) |
---|
381 | { |
---|
382 | array_push( $calendar_years, $row['year'] ); |
---|
383 | } |
---|
384 | |
---|
385 | if ( !isset( $page['calendar_year'] ) |
---|
386 | or !in_array( $page['calendar_year'], $calendar_years ) ) |
---|
387 | { |
---|
388 | $page['calendar_year'] = max( $calendar_years ); |
---|
389 | } |
---|
390 | |
---|
391 | // years navigation bar creation |
---|
392 | $years_nav_bar = ''; |
---|
393 | foreach ( $calendar_years as $calendar_year ) { |
---|
394 | if ( $calendar_year == $page['calendar_year'] ) |
---|
395 | { |
---|
396 | $years_nav_bar.= ' <span class="selected">'; |
---|
397 | $years_nav_bar.= $calendar_year; |
---|
398 | $years_nav_bar.= '</span>'; |
---|
399 | } |
---|
400 | else |
---|
401 | { |
---|
402 | $url = PHPWG_ROOT_PATH.'category.php?cat=calendar'; |
---|
403 | $url.= '&year='.$calendar_year; |
---|
404 | $years_nav_bar.= ' '; |
---|
405 | $years_nav_bar.= '<a href="'.add_session_id( $url ).'">'; |
---|
406 | $years_nav_bar.= $calendar_year; |
---|
407 | $years_nav_bar.= '</a>'; |
---|
408 | } |
---|
409 | } |
---|
410 | $template->assign_block_vars( |
---|
411 | 'calendar', |
---|
412 | array( 'YEARS_NAV_BAR' => $years_nav_bar ) |
---|
413 | ); |
---|
414 | |
---|
415 | $query = 'SELECT DISTINCT(MONTH(date_available)) AS month'; |
---|
416 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
417 | $query.= $page['where']; |
---|
418 | $query.= ' AND id = image_id'; |
---|
419 | $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; |
---|
420 | $query.= ' ORDER BY month'; |
---|
421 | $query.= ';'; |
---|
422 | $result = mysql_query( $query ); |
---|
423 | $calendar_months = array(); |
---|
424 | while ( $row = mysql_fetch_array( $result ) ) |
---|
425 | { |
---|
426 | array_push( $calendar_months, $row['month'] ); |
---|
427 | } |
---|
428 | |
---|
429 | // months navigation bar creation |
---|
430 | $months_nav_bar = ''; |
---|
431 | foreach ( $calendar_months as $calendar_month ) { |
---|
432 | if ( isset( $page['calendar_month'] ) |
---|
433 | and $calendar_month == $page['calendar_month'] ) |
---|
434 | { |
---|
435 | $months_nav_bar.= ' <span class="selected">'; |
---|
436 | $months_nav_bar.= $lang['month'][(int)$calendar_month]; |
---|
437 | $months_nav_bar.= '</span>'; |
---|
438 | } |
---|
439 | else |
---|
440 | { |
---|
441 | $url = PHPWG_ROOT_PATH.'category.php?cat=calendar&month='; |
---|
442 | $url.= $page['calendar_year'].'.'; |
---|
443 | if ( $calendar_month < 10 ) |
---|
444 | { |
---|
445 | // adding leading zero |
---|
446 | $url.= '0'; |
---|
447 | } |
---|
448 | $url.= $calendar_month; |
---|
449 | $months_nav_bar.= ' '; |
---|
450 | $months_nav_bar.= '<a href="'.add_session_id( $url ).'">'; |
---|
451 | $months_nav_bar.= $lang['month'][(int)$calendar_month]; |
---|
452 | $months_nav_bar.= '</a>'; |
---|
453 | } |
---|
454 | } |
---|
455 | $template->assign_block_vars( |
---|
456 | 'calendar', |
---|
457 | array( 'MONTHS_NAV_BAR' => $months_nav_bar ) |
---|
458 | ); |
---|
459 | |
---|
460 | $row_number = 1; |
---|
461 | $line_opened = false; |
---|
462 | $displayed_pics = 0; |
---|
463 | $template->assign_block_vars('thumbnails', array()); |
---|
464 | |
---|
465 | if ( !isset( $page['calendar_month'] ) ) |
---|
466 | { |
---|
467 | // for each month of this year, display a random picture |
---|
468 | foreach ( $calendar_months as $calendar_month ) { |
---|
469 | $query = 'SELECT COUNT(id) AS nb_picture_month'; |
---|
470 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
471 | $query.= $page['where']; |
---|
472 | $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; |
---|
473 | $query.= ' AND MONTH(date_available) = '.$calendar_month; |
---|
474 | $query.= ' AND id = image_id'; |
---|
475 | $query.= ';'; |
---|
476 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
477 | $nb_picture_month = $row['nb_picture_month']; |
---|
478 | |
---|
479 | $query = 'SELECT file,tn_ext,date_available,storage_category_id'; |
---|
480 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
481 | $query.= $page['where']; |
---|
482 | $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; |
---|
483 | $query.= ' AND MONTH(date_available) = '.$calendar_month; |
---|
484 | $query.= ' AND id = image_id'; |
---|
485 | $query.= ' ORDER BY RAND()'; |
---|
486 | $query.= ' LIMIT 0,1'; |
---|
487 | $query.= ';'; |
---|
488 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
489 | |
---|
490 | $file = get_filename_wo_extension( $row['file'] ); |
---|
491 | |
---|
492 | // creating links for thumbnail and associated category |
---|
493 | $thumbnail_link = get_complete_dir( $row['storage_category_id'] ); |
---|
494 | $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
495 | $thumbnail_link.= $file.'.'.$row['tn_ext']; |
---|
496 | |
---|
497 | $name = $lang['month'][$calendar_month]; |
---|
498 | $name.= ' '.$page['calendar_year']; |
---|
499 | $name.= ' ['.$nb_picture_month.']'; |
---|
500 | |
---|
501 | $thumbnail_title = $lang['calendar_picture_hint'].$name; |
---|
502 | |
---|
503 | $url_link = PHPWG_ROOT_PATH.'category.php?cat=calendar'; |
---|
504 | $url_link.= '&month='.$page['calendar_year'].'.'; |
---|
505 | if ( $calendar_month < 10 ) |
---|
506 | { |
---|
507 | // adding leading zero |
---|
508 | $url_link.= '0'; |
---|
509 | } |
---|
510 | $url_link.= $calendar_month; |
---|
511 | |
---|
512 | // create a new line ? |
---|
513 | if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] ) |
---|
514 | and $displayed_pics++ < count( $calendar_months ) ) |
---|
515 | { |
---|
516 | $template->assign_block_vars('thumbnails.line', array()); |
---|
517 | $row_number = 1; |
---|
518 | $line_opened = true; |
---|
519 | } |
---|
520 | |
---|
521 | $template->assign_block_vars( |
---|
522 | 'thumbnails.line.thumbnail', |
---|
523 | array( |
---|
524 | 'IMAGE'=>$thumbnail_link, |
---|
525 | 'IMAGE_ALT'=>$row['file'], |
---|
526 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
527 | 'IMAGE_NAME'=>$name, |
---|
528 | |
---|
529 | 'U_IMG_LINK'=>add_session_id( $url_link ) |
---|
530 | ) |
---|
531 | ); |
---|
532 | } |
---|
533 | } |
---|
534 | else |
---|
535 | { |
---|
536 | $query = 'SELECT DISTINCT(date_available) AS day'; |
---|
537 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
538 | $query.= $page['where']; |
---|
539 | $query.= ' AND id = image_id'; |
---|
540 | $query.= ' AND YEAR(date_available) = '.$page['calendar_year']; |
---|
541 | $query.= ' AND MONTH(date_available) = '.$page['calendar_month']; |
---|
542 | $query.= ' ORDER BY day'; |
---|
543 | $query.= ';'; |
---|
544 | $result = mysql_query( $query ); |
---|
545 | $calendar_days = array(); |
---|
546 | while ( $row = mysql_fetch_array( $result ) ) |
---|
547 | { |
---|
548 | array_push( $calendar_days, $row['day'] ); |
---|
549 | } |
---|
550 | // for each month of this year, display a random picture |
---|
551 | foreach ( $calendar_days as $calendar_day ) { |
---|
552 | $query = 'SELECT COUNT(id) AS nb_picture_day'; |
---|
553 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
554 | $query.= $page['where']; |
---|
555 | $query.= " AND date_available = '".$calendar_day."'"; |
---|
556 | $query.= ' AND id = image_id'; |
---|
557 | $query.= ';'; |
---|
558 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
559 | $nb_picture_day = $row['nb_picture_day']; |
---|
560 | |
---|
561 | $query = 'SELECT file,tn_ext,date_available,storage_category_id'; |
---|
562 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
563 | $query.= $page['where']; |
---|
564 | $query.= " AND date_available = '".$calendar_day."'"; |
---|
565 | $query.= ' AND id = image_id'; |
---|
566 | $query.= ' ORDER BY RAND()'; |
---|
567 | $query.= ' LIMIT 0,1'; |
---|
568 | $query.= ';'; |
---|
569 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
570 | |
---|
571 | $file = get_filename_wo_extension( $row['file'] ); |
---|
572 | |
---|
573 | // creating links for thumbnail and associated category |
---|
574 | $thumbnail_link = get_complete_dir( $row['storage_category_id'] ); |
---|
575 | $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
576 | $thumbnail_link.= $file.'.'.$row['tn_ext']; |
---|
577 | |
---|
578 | list($year,$month,$day) = explode( '-', $calendar_day ); |
---|
579 | $unixdate = mktime(0,0,0,$month,$day,$year); |
---|
580 | $name = $lang['day'][date( "w", $unixdate )]; |
---|
581 | $name.= ' '.$day; |
---|
582 | $name.= ' ['.$nb_picture_day.']'; |
---|
583 | |
---|
584 | $thumbnail_title = $lang['calendar_picture_hint'].$name; |
---|
585 | |
---|
586 | $url_link = PHPWG_ROOT_PATH.'category.php?cat=search'; |
---|
587 | |
---|
588 | // create a new line ? |
---|
589 | if ( ( !$line_opened or $row_number++ == $user['nb_image_line'] ) |
---|
590 | and $displayed_pics++ < count( $calendar_months ) ) |
---|
591 | { |
---|
592 | $template->assign_block_vars('thumbnails.line', array()); |
---|
593 | $row_number = 1; |
---|
594 | $line_opened = true; |
---|
595 | } |
---|
596 | |
---|
597 | $template->assign_block_vars( |
---|
598 | 'thumbnails.line.thumbnail', |
---|
599 | array( |
---|
600 | 'IMAGE'=>$thumbnail_link, |
---|
601 | 'IMAGE_ALT'=>$row['file'], |
---|
602 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
603 | 'IMAGE_NAME'=>$name, |
---|
604 | |
---|
605 | 'U_IMG_LINK'=>add_session_id( $url_link ) |
---|
606 | ) |
---|
607 | ); |
---|
608 | } |
---|
609 | } |
---|
610 | } |
---|
611 | //-------------------------------------------------------------- empty category |
---|
612 | else |
---|
613 | { |
---|
614 | $subcats=array(); |
---|
615 | if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] ); |
---|
616 | else $subcats = get_non_empty_subcat_ids( '' ); |
---|
617 | $cell_number = 0; |
---|
618 | $i = 0; |
---|
619 | |
---|
620 | $template->assign_block_vars('thumbnails', array()); |
---|
621 | |
---|
622 | foreach ( $subcats as $subcat_id => $non_empty_id ) |
---|
623 | { |
---|
624 | $name = '<img src="'.$user['lien_collapsed'].'" style="border:none;"'; |
---|
625 | $name.= ' alt=">"/> '; |
---|
626 | $name.= '[ <span style="font-weight:bold;">'; |
---|
627 | $name.= $page['plain_structure'][$subcat_id]['name']; |
---|
628 | $name.= '</span> ]'; |
---|
629 | |
---|
630 | // searching the representative picture of the category |
---|
631 | $query = 'SELECT representative_picture_id'; |
---|
632 | $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$non_empty_id; |
---|
633 | $query.= ';'; |
---|
634 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
635 | |
---|
636 | $query = 'SELECT file,tn_ext,storage_category_id'; |
---|
637 | $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE; |
---|
638 | $query.= ' WHERE category_id = '.$non_empty_id; |
---|
639 | $query.= ' AND id = image_id'; |
---|
640 | // if the category has a representative picture, this is its thumbnail |
---|
641 | // that will be displayed ! |
---|
642 | if ( isset( $row['representative_picture_id'] ) ) |
---|
643 | $query.= ' AND id = '.$row['representative_picture_id']; |
---|
644 | else |
---|
645 | $query.= ' ORDER BY RAND()'; |
---|
646 | $query.= ' LIMIT 0,1'; |
---|
647 | $query.= ';'; |
---|
648 | $image_result = mysql_query( $query ); |
---|
649 | $image_row = mysql_fetch_array( $image_result ); |
---|
650 | |
---|
651 | $file = get_filename_wo_extension( $image_row['file'] ); |
---|
652 | |
---|
653 | // creating links for thumbnail and associated category |
---|
654 | $thumbnail_link = get_complete_dir( $image_row['storage_category_id'] ); |
---|
655 | $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
656 | $thumbnail_link.= $file.'.'.$image_row['tn_ext']; |
---|
657 | |
---|
658 | $thumbnail_title = $lang['hint_category']; |
---|
659 | |
---|
660 | $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$subcat_id; |
---|
661 | |
---|
662 | $date = $page['plain_structure'][$subcat_id]['date_last']; |
---|
663 | |
---|
664 | // sending vars to display |
---|
665 | if (!$cell_number && $i < count( $subcats )) |
---|
666 | { |
---|
667 | $template->assign_block_vars('thumbnails.line', array()); |
---|
668 | $cell_number = 0; |
---|
669 | $i++; |
---|
670 | } |
---|
671 | if ( $cell_number++ == $user['nb_image_line'] -1 ) |
---|
672 | { |
---|
673 | $cell_number = 0; |
---|
674 | } |
---|
675 | |
---|
676 | $template->assign_block_vars( |
---|
677 | 'thumbnails.line.thumbnail', |
---|
678 | array( |
---|
679 | 'IMAGE'=>$thumbnail_link, |
---|
680 | 'IMAGE_ALT'=>$image_row['file'], |
---|
681 | 'IMAGE_TITLE'=>$thumbnail_title, |
---|
682 | 'IMAGE_NAME'=>$name, |
---|
683 | 'IMAGE_TS'=>get_icon( $date ), |
---|
684 | |
---|
685 | 'U_IMG_LINK'=>add_session_id( $url_link ) |
---|
686 | ) |
---|
687 | ); |
---|
688 | } |
---|
689 | } |
---|
690 | //------------------------------------------------------- category informations |
---|
691 | if ( isset ( $page['cat'] ) ) |
---|
692 | { |
---|
693 | // upload a picture in the category |
---|
694 | if ( is_numeric( $page['cat'] ) |
---|
695 | and $page['cat_site_id'] == 1 |
---|
696 | and $conf['upload_available'] |
---|
697 | and $page['cat_uploadable'] ) |
---|
698 | { |
---|
699 | $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat']; |
---|
700 | $template->assign_block_vars( |
---|
701 | 'upload', |
---|
702 | array('U_UPLOAD'=>add_session_id( $url )) |
---|
703 | ); |
---|
704 | } |
---|
705 | |
---|
706 | if ( $page['navigation_bar'] != '' |
---|
707 | or ( isset( $page['comment'] ) and $page['comment'] != '' ) ) |
---|
708 | { |
---|
709 | $template->assign_block_vars('cat_infos',array()); |
---|
710 | } |
---|
711 | |
---|
712 | // navigation bar |
---|
713 | if ( $page['navigation_bar'] != '' ) |
---|
714 | { |
---|
715 | $template->assign_block_vars( |
---|
716 | 'cat_infos.navigation', |
---|
717 | array('NAV_BAR' => $page['navigation_bar']) |
---|
718 | ); |
---|
719 | } |
---|
720 | // category comment |
---|
721 | if ( isset( $page['comment'] ) and $page['comment'] != '' ) |
---|
722 | { |
---|
723 | $template->assign_block_vars( |
---|
724 | 'cat_infos.comment', |
---|
725 | array('COMMENTS' => $page['comment']) |
---|
726 | ); |
---|
727 | } |
---|
728 | } |
---|
729 | //------------------------------------------------------------ log informations |
---|
730 | pwg_log( 'category', $page['title'] ); |
---|
731 | mysql_close(); |
---|
732 | |
---|
733 | $template->pparse('category'); |
---|
734 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
735 | ?> |
---|