source: trunk/category.php @ 13

Last change on this file since 13 was 10, checked in by z0rglub, 21 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 KB
Line 
1<?php
2/***************************************************************************
3 *                               category.php                              *
4 *                            -------------------                          *
5 *   application          : PhpWebGallery 1.3                              *
6 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
7 *                                                                         *
8 ***************************************************************************/
9
10/***************************************************************************
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 ***************************************************************************/
17// determine the initial instant to indicate the generation time of this page
18$t1 = explode( ' ', microtime() );
19$t2 = explode( '.', $t1[0] );
20$t2 = $t1[1].'.'.$t2[1];
21//----------------------------------------------------------- personnal include
22include_once( './include/init.inc.php' );
23//-------------------------------------------------- access authorization check
24check_cat_id( $_GET['cat'] );
25check_login_authorization();
26if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
27{
28  check_restrictions( $page['cat'] );
29}
30//-------------------------------------------------------------- initialization
31// creation of the array containing the cat ids to expand in the menu
32// $page['tab_expand'] contains an array with the category ids
33// $page['expand'] contains the string to display in URL with comma
34$page['tab_expand'] = array();
35if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
36{
37  $j = 0;
38  $tab_expand = explode( ",", $_GET['expand'] );
39  $size = sizeof( $tab_expand );
40  for ( $i = 0; $i < $size; $i++ )
41  {
42    if ( is_numeric( $tab_expand[$i] ) )
43    {
44      $page['tab_expand'][$j++] = $tab_expand[$i];
45    }
46  }
47  $page['expand'] = implode( ',', $page['tab_expand'] );
48}
49// in case of expanding all authorized cats
50// The $page['expand'] equals 'all' and
51// $page['tab_expand'] contains all the authorized cat ids
52if ( $user['expand'] == 'true' or $_GET['expand'] == 'all' )
53{
54  $page['tab_expand'] = array();
55  $query = 'select id';
56  $query.= ' from '.PREFIX_TABLE.'categories';
57  $query.= ' where id_uppercat is null;';
58  $result = mysql_query( $query );
59  $i = 0;
60  while ( $row = mysql_fetch_array( $result ) )
61  {
62    $page['tab_expand'][$i++] = $row['id'];
63  }
64  $page['expand'] = 'all';
65}
66// detection of the start picture to display
67if ( !isset( $_GET['start'] )
68     or !is_numeric( $_GET['start'] )
69     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
70{
71  $page['start'] = 0;
72}
73else
74{
75  $page['start'] = $_GET['start'];
76}
77// Sometimes, a "num" is provided in the URL. It is the number
78// of the picture to show. This picture must be in the thumbnails page.
79// We have to find the right $page['start'] that show the num picture
80// in this category
81if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
82{
83  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
84  $page['start']*= $user['nb_image_page'];
85}
86initialize_category();
87//----------------------------------------------------- template initialization
88$vtp = new VTemplate;
89$handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' );
90initialize_template();
91
92$tpl = array( 'categories','hint_category','sub-cat','images_available',
93              'total','title_menu','nb_image_category','send_mail',
94              'title_send_mail','generation_time','upload_name',
95              'connected_user','recent_image','days','generation_time',
96              'favorite_cat_hint','favorite_cat','stats',
97              'most_visited_cat_hint','most_visited_cat','recent_cat',
98              'recent_cat_hint' );
99templatize_array( $tpl, 'lang', $handle );
100
101$tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' );
102templatize_array( $tpl, 'conf', $handle );
103
104$tpl = array( 'short_period','long_period','style','lien_collapsed',
105              'username' );
106templatize_array( $tpl, 'user', $handle );
107
108$tpl = array( 'title','navigation_bar','cat_comment','cat_nb_images' );
109templatize_array( $tpl, 'page', $handle );
110
111// special global template vars
112$vtp->setGlobalVar( $handle, 'icon_short', get_icon( time() ) );
113$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
114$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
115$nb_total_pictures = get_total_image( "", $user['restrictions'] );
116$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
117//------------------------------------------------------------- categories menu
118// normal categories
119display_cat( '', '&nbsp;', $user['restrictions'], $page['tab_expand'] );
120// favorites cat
121if ( !$user['is_the_guest'] )
122{
123  $vtp->addSession( $handle, 'favorites' );
124  $url = add_session_id('./category.php?cat=fav&amp;expand='.$page['expand'] );
125  $vtp->setVar( $handle, 'favorites.url', $url );
126  // searching the number of favorite picture
127  $query = 'select count(*) as count';
128  $query.= ' from '.PREFIX_TABLE.'favorites';
129  $query.= ' where user_id = '.$user['id'].';';
130  $result = mysql_query( $query );
131  $row = mysql_fetch_array( $result );
132  $vtp->setVar( $handle, 'favorites.nb_favorites', $row['count'] );
133  $vtp->closeSession( $handle, 'favorites' );
134}
135// most visited pictures category
136$url = add_session_id( './category.php?cat=most_visited'.
137                       '&amp;expand='.$page['expand'] );
138$vtp->setGlobalVar( $handle, 'most_visited_url', $url );
139// recent pictures
140$url = add_session_id( './category.php?cat=recent'.
141                       '&amp;expand='.$page['expand'] );
142$vtp->setGlobalVar( $handle, 'recent_url', $url );
143//--------------------------------------------------------------------- summary
144$vtp->addSession( $handle, 'summary' );
145$vtp->setVar( $handle, 'summary.url', './identification.php' );
146if ( !$user['is_the_guest'] )
147{
148  $vtp->setVar( $handle, 'summary.title', '' );
149  $vtp->setVar( $handle, 'summary.name',
150                replace_space( $lang['change_login'] ) );
151}
152else
153{
154  $vtp->setVar( $handle, 'summary.title', $lang['hint_login'] );
155  $vtp->setVar( $handle, 'summary.name',
156                replace_space( $lang['login'] ) );
157}
158$vtp->closeSession( $handle, 'summary' );
159// links for registered users
160if ( !$user['is_the_guest'] )
161{
162  // logout link
163  $vtp->addSession( $handle, 'summary' );
164  $vtp->setVar( $handle, 'summary.url', './category.php?cat='.$page['cat'] );
165  $vtp->setVar( $handle, 'summary.title', '' );
166  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['logout'] ) );
167  $vtp->closeSession( $handle, 'summary' );
168  // customization link
169  $vtp->addSession( $handle, 'summary' );
170  $url = './profile.php?cat='.$page['cat'];
171  $url.= '&amp;expand='.$page['expand'];
172  if ( $page['cat'] == 'search' )
173  {
174    $url.= '&amp;search='.$_GET['search'];
175  }
176  $vtp->setVar( $handle, 'summary.url', add_session_id( $url ) );
177  $vtp->setVar( $handle, 'summary.title', $lang['hint_customize'] );
178  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['customize'] ) );
179  $vtp->closeSession( $handle, 'summary' );
180}
181// search link
182$vtp->addSession( $handle, 'summary' );
183$vtp->setVar( $handle, 'summary.url', add_session_id( './search.php' ) );
184$vtp->setVar( $handle, 'summary.title', $lang['hint_search'] );
185$vtp->setVar( $handle, 'summary.name', replace_space( $lang['search'] ) );
186$vtp->closeSession( $handle, 'summary' );
187// about link
188$vtp->addSession( $handle, 'summary' );
189$vtp->setVar( $handle, 'summary.url',
190              add_session_id( './about.php?expand='.$page['expand'] ) );
191$vtp->setVar( $handle, 'summary.title', $lang['hint_about'] );
192$vtp->setVar( $handle, 'summary.name', replace_space( $lang['about'] ) );
193$vtp->closeSession( $handle, 'summary' );
194// administration link
195if ( $user['status'] == 'admin' )
196{
197  $vtp->addSession( $handle, 'summary' );
198  $vtp->setVar( $handle, 'summary.url',
199                add_session_id( './admin/admin.php' ) );
200  $vtp->setVar( $handle, 'summary.title', $lang['hint_admin'] );
201  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['admin'] ) );
202  $vtp->closeSession( $handle, 'summary' );
203}
204//-------------------------------------------------------------- category title
205if ( isset ( $page['cat'] ) )
206{
207  if ( is_numeric( $page['cat'] ) )
208  {
209    $cat_title = get_cat_display_name( $page['cat_name'], '<br />',
210                                    'font-style:italic;' );
211    $vtp->setGlobalVar( $handle, "cat_title", $cat_title );
212  }
213  else
214  {
215    if ( $page['cat'] == 'search' )
216    {
217      $page['title'].= ' : <span style="font-style:italic;">';
218      $page['title'].= $_GET['search']."</span>";
219    }
220    $page['title'] = replace_space( $page['title'] );
221    $vtp->setGlobalVar( $handle, "cat_title", $page['title'] );
222  }
223}
224else
225{
226  $vtp->setGlobalVar( $handle, "cat_title",
227                      replace_space( $lang['no_category'] ) );
228}
229//------------------------------------------------------------------ thumbnails
230if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
231{
232  if ( is_numeric( $page['cat'] ) )
233  {
234    $cat_directory = $page['cat_dir'];
235  }
236  else if ( $page['cat'] == 'search' or $page['cat'] == 'fav' )
237  {
238    $array_cat_directories = array();
239  }
240 
241  $query = 'select id,file,date_available,comment,';
242  $query.= ' author,tn_ext,name,filesize,width,height,cat_id';
243  $query.= ' from '.PREFIX_TABLE.'images';
244  $query.= $page['where'];
245  $query.= $conf['order_by'];
246  $query.= ' limit '.$page['start'].','.$page['nb_image_page'];
247  $query.= ';';
248  $result = mysql_query( $query );
249
250  $vtp->addSession( $handle, 'thumbnails' );
251  $vtp->addSession( $handle, 'line' );
252  // compteur d'itération pour aller à la ligne
253  // toutes les "$nb_image_ligne" images
254  $i = 1;
255  while ( $row = mysql_fetch_array( $result ) )
256  {
257    if ( !is_numeric( $page['cat'] ) )
258    {
259      if ( $array_cat_directories[$row['cat_id']] == '' )
260      {
261        $cat_result = get_cat_info( $row['cat_id'] );
262        $array_cat_directories[$row['cat_id']] = $cat_result['dir'];
263      }
264      $cat_directory = $array_cat_directories[$row['cat_id']];
265    }
266    // filename without extension
267    $file = substr ( $row['file'], 0, strrpos ( $row['file'], '.' ) );
268    // name of the picture
269    if ( $row['name'] != '' )
270    {
271      $name = $row['name'];
272    }
273    else
274    {
275      $name = str_replace( '_', ' ', $file );
276    }
277    if ( $page['cat'] == 'search' )
278    {
279      $name = replace_search( $name, $_GET['search'] );
280    }
281    // thumbnail url
282    $thumbnail_url = $cat_directory;
283    $thumbnail_url.= 'thumbnail/'.$conf['prefixe_thumbnail'];
284    $thumbnail_url.= $file.'.'.$row['tn_ext'];
285    // message in title for the thumbnail
286    $tab_date = explode( '-', $row['date_available'] );
287    $thumbnail_title = $lang['registration_date'];
288    $thumbnail_title.= ' '.$tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0];
289    if ( $row['comment'] != '' )
290    {             
291      $thumbnail_title .= "\n".$lang['comment'].' : '.$row['comment'];
292    }             
293    if ( $row['author'] != '' )
294    {             
295      $thumbnail_title .= "\n".$lang['author'].' : '.$row['author'];
296    }
297    if ( $row['width'] == '' )
298    {
299      $taille_image = @getimagesize( $lien_image );
300      $width = $taille_image[0];
301      $height = $taille_image[1];
302    }
303    else
304    {
305      $width = $row['width'];
306      $height = $row['height'];
307    }
308    $thumbnail_title .= "\n".$lang['size'].' : '.$width.'*'.$height;
309    $thumbnail_title .= "\n".$lang['file'].' : '.$row['file'];
310    if ( $row['filesize'] == '' )
311    {
312      $poids = floor( filesize( $lien_image ) / 1024 );
313    }
314    else
315    {
316      $poids = $row['filesize'];
317    }
318    $thumbnail_title .= "\n".$lang['filesize'].' : '.$poids.' KB';
319    // url link on picture.php page
320    $url_link = './picture.php?cat='.$page['cat'];
321    $url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
322    if ( $page['cat'] == 'search' )
323    {
324      $url_link.= '&amp;search='.$_GET['search'];
325    }
326    // date of availability for creation icon
327    $date = explode( '-', $row['date_available'] );
328    $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
329    // sending vars to display
330    $vtp->addSession( $handle, 'thumbnail' );
331    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
332    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_url );
333    $vtp->setVar( $handle, 'thumbnail.alt', $row['file'] );
334    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
335    $vtp->setVar( $handle, 'thumbnail.name', $name );
336    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
337
338    if ( $conf['show_comments'] and $user['show_nb_comments'] )
339    {
340      $vtp->addSession( $handle, 'nb_comments' );
341      $query = 'select count(*) as nb_comments';
342      $query.= ' from '.PREFIX_TABLE.'comments';
343      $query.= ' where image_id = '.$row['id'];
344      $query.= ';';
345      $row = mysql_fetch_array( mysql_query( $query ) );
346      $vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] );
347      $vtp->closeSession( $handle, 'nb_comments' );
348    }
349   
350    $vtp->closeSession( $handle, 'thumbnail' );
351   
352    if ( $i == $user['nb_image_line'] )
353    {
354      $vtp->closeSession( $handle, 'line' );
355      $vtp->addSession( $handle, 'line' );
356      $i = 1;
357    }
358    else
359    {
360      $i++;
361    }
362  }
363  if ( $i < $user['nb_image_line'] )
364  {
365    $vtp->closeSession( $handle, 'line' );
366  }
367  $vtp->closeSession( $handle, 'thumbnails' );
368}
369elseif ( isset( $page['cat'] )
370         and is_numeric( $page['cat'] )
371         and $page['cat_nb_images'] == 0 )
372{
373  $vtp->addSession( $handle, 'thumbnails' );
374 
375  $query = 'select id,name,dir,date_dernier';
376  $query.= ' from '.PREFIX_TABLE.'categories';
377  $query.= ' where id_uppercat = '.$page['cat'];
378  $query.= ' order by rank;';
379  $cat_result = mysql_query( $query );
380  $i = 1;
381  $vtp->addSession( $handle, 'line' );
382  while ( $cat_row = mysql_fetch_array( $cat_result ) )
383  {
384    $result = get_cat_info( $cat_row['id'] );
385    $cat_directory = $result['dir'];
386
387    $name = '[ <span style="font-weight:bold;">';
388    if ( $cat_row['name'] != '' )
389    {
390      $name.= $cat_row['name'];
391    }
392    else
393    {
394      $name.= $cat_row['dir'];
395    }
396    $name.= '</span> ]';
397    $name = replace_space( $name );
398   
399    $query = 'select file,tn_ext';
400    $query.= ' from '.PREFIX_TABLE.'images';
401    $query.= ' where cat_id = '.$cat_row['id'];
402    $query.= ' order by rand()';
403    $query.= ' limit 0,1';
404    $query.= ';';
405    $image_result = mysql_query( $query );
406    $image_row = mysql_fetch_array( $image_result );
407
408    $file = substr ( $image_row['file'], 0,
409                     strrpos ( $image_row['file'], '.' ) );
410
411    // creating links for thumbnail and associated category
412    $lien_image = $cat_directory;
413    $lien_thumbnail = $lien_image;
414    $lien_thumbnail.= 'thumbnail/'.$conf['prefixe_thumbnail'];
415    $lien_thumbnail.= $file.'.'.$image_row['tn_ext'];
416    $lien_image.= $image_row['file'];
417
418    $thumbnail_title = '';
419
420    $url_link = './category.php?cat='.$cat_row['id'];
421    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
422    {
423      $page['tab_expand'][sizeof( $page['tab_expand'] )] = $page['cat'];
424      $page['expand'] = implode( ',', $page['tab_expand'] );
425    }
426    $url_link.= '&amp;expand='.$page['expand'];
427
428    // sending vars to display
429    $vtp->addSession( $handle, 'thumbnail' );
430    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
431    $vtp->setVar( $handle, 'thumbnail.src', $lien_thumbnail );
432    $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
433    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
434    $vtp->setVar( $handle, 'thumbnail.name', $name );
435
436    $date = explode( '-', $cat_row['date_dernier'] );
437    $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
438    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
439
440    $vtp->closeSession( $handle, 'thumbnail' );
441
442    if ( $i == $user['nb_image_line'] )
443    {
444      $vtp->closeSession( $handle, 'line' );
445      $vtp->addSession( $handle, 'line' );
446      $i = 1;
447    }
448    else
449    {
450      $i++;
451    }
452  }
453  $vtp->closeSession( $handle, 'thumbnails' );
454}
455//------------------------------------------------------- category informations
456if ( isset ( $page['cat'] ) )
457{
458  $vtp->addSession( $handle, 'cat_infos' );
459  // navigation bar
460  if ( $page['navigation_bar'] != '' )
461  {
462    $vtp->addSession( $handle, 'navigation' );
463    $vtp->closeSession( $handle, 'navigation' );
464  }
465  // category comment
466  if ( isset( $page['comment'] ) and $page['comment'] != '' )
467  {
468    $vtp->addSession( $handle, 'cat_comment' );
469    $vtp->closeSession( $handle, 'cat_navigation' );
470  }
471  // total number of pictures in the category
472  if ( is_numeric( $page['cat'] ) )
473  {
474    $vtp->setVar( $handle, 'cat_infos.cat_name',
475                  get_cat_display_name( $page['cat_name'], ' - ',
476                                        'font-style:italic;' ) );
477  }
478  else
479  {
480    $vtp->setVar( $handle, 'cat_infos.cat_name', $page['title'] );
481  }
482  // upload a picture in the category
483  if ( $page['cat_site_id'] == 1 and $conf['upload_available'] )
484  {
485    $vtp->addSession( $handle, 'upload' );
486    $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
487    $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
488    $vtp->closeSession( $handle, 'upload' );
489  }
490  $vtp->closeSession( $handle, 'cat_infos' );
491}
492//------------------------------------------------------------ log informations
493pwg_log( 'category', $page['title'] );
494mysql_close();
495//------------------------------------------------------------- generation time
496$time = get_elapsed_time( $t2, get_moment() );
497$vtp->setGlobalVar( $handle, 'time', $time );
498//----------------------------------------------------------- html code display
499$code = $vtp->Display( $handle, 0 );
500echo $code;
501?>
Note: See TracBrowser for help on using the repository browser.