source: trunk/category.php @ 14

Last change on this file since 14 was 14, 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','lien_collapsed', 'username' );
105templatize_array( $tpl, 'user', $handle );
106
107$tpl = array( 'title','navigation_bar','cat_comment','cat_nb_images' );
108templatize_array( $tpl, 'page', $handle );
109
110// special global template vars
111$vtp->setGlobalVar( $handle, 'icon_short', get_icon( time() ) );
112$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
113$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
114$nb_total_pictures = get_total_image( "", $user['restrictions'] );
115$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
116//------------------------------------------------------------- categories menu
117// normal categories
118display_cat( '', '&nbsp;', $user['restrictions'], $page['tab_expand'] );
119// favorites cat
120if ( !$user['is_the_guest'] )
121{
122  $vtp->addSession( $handle, 'favorites' );
123  $url = add_session_id('./category.php?cat=fav&amp;expand='.$page['expand'] );
124  $vtp->setVar( $handle, 'favorites.url', $url );
125  // searching the number of favorite picture
126  $query = 'select count(*) as count';
127  $query.= ' from '.PREFIX_TABLE.'favorites';
128  $query.= ' where user_id = '.$user['id'].';';
129  $result = mysql_query( $query );
130  $row = mysql_fetch_array( $result );
131  $vtp->setVar( $handle, 'favorites.nb_favorites', $row['count'] );
132  $vtp->closeSession( $handle, 'favorites' );
133}
134// most visited pictures category
135$url = add_session_id( './category.php?cat=most_visited'.
136                       '&amp;expand='.$page['expand'] );
137$vtp->setGlobalVar( $handle, 'most_visited_url', $url );
138// recent pictures
139$url = add_session_id( './category.php?cat=recent'.
140                       '&amp;expand='.$page['expand'] );
141$vtp->setGlobalVar( $handle, 'recent_url', $url );
142//--------------------------------------------------------------------- summary
143$vtp->addSession( $handle, 'summary' );
144$vtp->setVar( $handle, 'summary.url', './identification.php' );
145if ( !$user['is_the_guest'] )
146{
147  $vtp->setVar( $handle, 'summary.title', '' );
148  $vtp->setVar( $handle, 'summary.name',
149                replace_space( $lang['change_login'] ) );
150}
151else
152{
153  $vtp->setVar( $handle, 'summary.title', $lang['hint_login'] );
154  $vtp->setVar( $handle, 'summary.name',
155                replace_space( $lang['login'] ) );
156}
157$vtp->closeSession( $handle, 'summary' );
158// links for registered users
159if ( !$user['is_the_guest'] )
160{
161  // logout link
162  $vtp->addSession( $handle, 'summary' );
163  $vtp->setVar( $handle, 'summary.url', './category.php?cat='.$page['cat'] );
164  $vtp->setVar( $handle, 'summary.title', '' );
165  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['logout'] ) );
166  $vtp->closeSession( $handle, 'summary' );
167  // customization link
168  $vtp->addSession( $handle, 'summary' );
169  $url = './profile.php?cat='.$page['cat'];
170  $url.= '&amp;expand='.$page['expand'];
171  if ( $page['cat'] == 'search' )
172  {
173    $url.= '&amp;search='.$_GET['search'];
174  }
175  $vtp->setVar( $handle, 'summary.url', add_session_id( $url ) );
176  $vtp->setVar( $handle, 'summary.title', $lang['hint_customize'] );
177  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['customize'] ) );
178  $vtp->closeSession( $handle, 'summary' );
179}
180// search link
181$vtp->addSession( $handle, 'summary' );
182$vtp->setVar( $handle, 'summary.url', add_session_id( './search.php' ) );
183$vtp->setVar( $handle, 'summary.title', $lang['hint_search'] );
184$vtp->setVar( $handle, 'summary.name', replace_space( $lang['search'] ) );
185$vtp->closeSession( $handle, 'summary' );
186// about link
187$vtp->addSession( $handle, 'summary' );
188$vtp->setVar( $handle, 'summary.url',
189              add_session_id( './about.php?expand='.$page['expand'] ) );
190$vtp->setVar( $handle, 'summary.title', $lang['hint_about'] );
191$vtp->setVar( $handle, 'summary.name', replace_space( $lang['about'] ) );
192$vtp->closeSession( $handle, 'summary' );
193// administration link
194if ( $user['status'] == 'admin' )
195{
196  $vtp->addSession( $handle, 'summary' );
197  $vtp->setVar( $handle, 'summary.url',
198                add_session_id( './admin/admin.php' ) );
199  $vtp->setVar( $handle, 'summary.title', $lang['hint_admin'] );
200  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['admin'] ) );
201  $vtp->closeSession( $handle, 'summary' );
202}
203//-------------------------------------------------------------- category title
204if ( isset ( $page['cat'] ) )
205{
206  if ( is_numeric( $page['cat'] ) )
207  {
208    $cat_title = get_cat_display_name( $page['cat_name'], '<br />',
209                                    'font-style:italic;' );
210    $vtp->setGlobalVar( $handle, "cat_title", $cat_title );
211  }
212  else
213  {
214    if ( $page['cat'] == 'search' )
215    {
216      $page['title'].= ' : <span style="font-style:italic;">';
217      $page['title'].= $_GET['search']."</span>";
218    }
219    $page['title'] = replace_space( $page['title'] );
220    $vtp->setGlobalVar( $handle, "cat_title", $page['title'] );
221  }
222}
223else
224{
225  $vtp->setGlobalVar( $handle, "cat_title",
226                      replace_space( $lang['no_category'] ) );
227}
228//------------------------------------------------------------------ thumbnails
229if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
230{
231  if ( is_numeric( $page['cat'] ) )
232  {
233    $cat_directory = $page['cat_dir'];
234  }
235  else if ( $page['cat'] == 'search' or $page['cat'] == 'fav' )
236  {
237    $array_cat_directories = array();
238  }
239 
240  $query = 'select id,file,date_available,comment,';
241  $query.= ' author,tn_ext,name,filesize,width,height,cat_id';
242  $query.= ' from '.PREFIX_TABLE.'images';
243  $query.= $page['where'];
244  $query.= $conf['order_by'];
245  $query.= ' limit '.$page['start'].','.$page['nb_image_page'];
246  $query.= ';';
247  $result = mysql_query( $query );
248
249  $vtp->addSession( $handle, 'thumbnails' );
250  $vtp->addSession( $handle, 'line' );
251  // compteur d'itération pour aller à la ligne
252  // toutes les "$nb_image_ligne" images
253  $i = 1;
254  while ( $row = mysql_fetch_array( $result ) )
255  {
256    if ( !is_numeric( $page['cat'] ) )
257    {
258      if ( $array_cat_directories[$row['cat_id']] == '' )
259      {
260        $cat_result = get_cat_info( $row['cat_id'] );
261        $array_cat_directories[$row['cat_id']] = $cat_result['dir'];
262      }
263      $cat_directory = $array_cat_directories[$row['cat_id']];
264    }
265    // filename without extension
266    $file = substr ( $row['file'], 0, strrpos ( $row['file'], '.' ) );
267    // name of the picture
268    if ( $row['name'] != '' )
269    {
270      $name = $row['name'];
271    }
272    else
273    {
274      $name = str_replace( '_', ' ', $file );
275    }
276    if ( $page['cat'] == 'search' )
277    {
278      $name = replace_search( $name, $_GET['search'] );
279    }
280    // thumbnail url
281    $thumbnail_url = $cat_directory;
282    $thumbnail_url.= 'thumbnail/'.$conf['prefixe_thumbnail'];
283    $thumbnail_url.= $file.'.'.$row['tn_ext'];
284    // message in title for the thumbnail
285    $tab_date = explode( '-', $row['date_available'] );
286    $thumbnail_title = $lang['registration_date'];
287    $thumbnail_title.= ' '.$tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0];
288    if ( $row['comment'] != '' )
289    {             
290      $thumbnail_title .= "\n".$lang['comment'].' : '.$row['comment'];
291    }             
292    if ( $row['author'] != '' )
293    {             
294      $thumbnail_title .= "\n".$lang['author'].' : '.$row['author'];
295    }
296    if ( $row['width'] == '' )
297    {
298      $taille_image = @getimagesize( $lien_image );
299      $width = $taille_image[0];
300      $height = $taille_image[1];
301    }
302    else
303    {
304      $width = $row['width'];
305      $height = $row['height'];
306    }
307    $thumbnail_title .= "\n".$lang['size'].' : '.$width.'*'.$height;
308    $thumbnail_title .= "\n".$lang['file'].' : '.$row['file'];
309    if ( $row['filesize'] == '' )
310    {
311      $poids = floor( filesize( $lien_image ) / 1024 );
312    }
313    else
314    {
315      $poids = $row['filesize'];
316    }
317    $thumbnail_title .= "\n".$lang['filesize'].' : '.$poids.' KB';
318    // url link on picture.php page
319    $url_link = './picture.php?cat='.$page['cat'];
320    $url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
321    if ( $page['cat'] == 'search' )
322    {
323      $url_link.= '&amp;search='.$_GET['search'];
324    }
325    // date of availability for creation icon
326    $date = explode( '-', $row['date_available'] );
327    $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
328    // sending vars to display
329    $vtp->addSession( $handle, 'thumbnail' );
330    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
331    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_url );
332    $vtp->setVar( $handle, 'thumbnail.alt', $row['file'] );
333    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
334    $vtp->setVar( $handle, 'thumbnail.name', $name );
335    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
336
337    if ( $conf['show_comments'] and $user['show_nb_comments'] )
338    {
339      $vtp->addSession( $handle, 'nb_comments' );
340      $query = 'select count(*) as nb_comments';
341      $query.= ' from '.PREFIX_TABLE.'comments';
342      $query.= ' where image_id = '.$row['id'];
343      $query.= ';';
344      $row = mysql_fetch_array( mysql_query( $query ) );
345      $vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] );
346      $vtp->closeSession( $handle, 'nb_comments' );
347    }
348   
349    $vtp->closeSession( $handle, 'thumbnail' );
350   
351    if ( $i == $user['nb_image_line'] )
352    {
353      $vtp->closeSession( $handle, 'line' );
354      $vtp->addSession( $handle, 'line' );
355      $i = 1;
356    }
357    else
358    {
359      $i++;
360    }
361  }
362  if ( $i < $user['nb_image_line'] )
363  {
364    $vtp->closeSession( $handle, 'line' );
365  }
366  $vtp->closeSession( $handle, 'thumbnails' );
367}
368elseif ( isset( $page['cat'] )
369         and is_numeric( $page['cat'] )
370         and $page['cat_nb_images'] == 0 )
371{
372  $vtp->addSession( $handle, 'thumbnails' );
373 
374  $query = 'select id,name,dir,date_dernier';
375  $query.= ' from '.PREFIX_TABLE.'categories';
376  $query.= ' where id_uppercat = '.$page['cat'];
377  $query.= ' order by rank;';
378  $cat_result = mysql_query( $query );
379  $i = 1;
380  $vtp->addSession( $handle, 'line' );
381  while ( $cat_row = mysql_fetch_array( $cat_result ) )
382  {
383    $result = get_cat_info( $cat_row['id'] );
384    $cat_directory = $result['dir'];
385
386    $name = '[ <span style="font-weight:bold;">';
387    if ( $cat_row['name'] != '' )
388    {
389      $name.= $cat_row['name'];
390    }
391    else
392    {
393      $name.= $cat_row['dir'];
394    }
395    $name.= '</span> ]';
396    $name = replace_space( $name );
397   
398    $query = 'select file,tn_ext';
399    $query.= ' from '.PREFIX_TABLE.'images';
400    $query.= ' where cat_id = '.$cat_row['id'];
401    $query.= ' order by rand()';
402    $query.= ' limit 0,1';
403    $query.= ';';
404    $image_result = mysql_query( $query );
405    $image_row = mysql_fetch_array( $image_result );
406
407    $file = substr ( $image_row['file'], 0,
408                     strrpos ( $image_row['file'], '.' ) );
409
410    // creating links for thumbnail and associated category
411    $lien_image = $cat_directory;
412    $lien_thumbnail = $lien_image;
413    $lien_thumbnail.= 'thumbnail/'.$conf['prefixe_thumbnail'];
414    $lien_thumbnail.= $file.'.'.$image_row['tn_ext'];
415    $lien_image.= $image_row['file'];
416
417    $thumbnail_title = '';
418
419    $url_link = './category.php?cat='.$cat_row['id'];
420    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
421    {
422      $page['tab_expand'][sizeof( $page['tab_expand'] )] = $page['cat'];
423      $page['expand'] = implode( ',', $page['tab_expand'] );
424    }
425    $url_link.= '&amp;expand='.$page['expand'];
426
427    // sending vars to display
428    $vtp->addSession( $handle, 'thumbnail' );
429    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
430    $vtp->setVar( $handle, 'thumbnail.src', $lien_thumbnail );
431    $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
432    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
433    $vtp->setVar( $handle, 'thumbnail.name', $name );
434
435    $date = explode( '-', $cat_row['date_dernier'] );
436    $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
437    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
438
439    $vtp->closeSession( $handle, 'thumbnail' );
440
441    if ( $i == $user['nb_image_line'] )
442    {
443      $vtp->closeSession( $handle, 'line' );
444      $vtp->addSession( $handle, 'line' );
445      $i = 1;
446    }
447    else
448    {
449      $i++;
450    }
451  }
452  $vtp->closeSession( $handle, 'thumbnails' );
453}
454//------------------------------------------------------- category informations
455if ( isset ( $page['cat'] ) )
456{
457  $vtp->addSession( $handle, 'cat_infos' );
458  // navigation bar
459  if ( $page['navigation_bar'] != '' )
460  {
461    $vtp->addSession( $handle, 'navigation' );
462    $vtp->closeSession( $handle, 'navigation' );
463  }
464  // category comment
465  if ( isset( $page['comment'] ) and $page['comment'] != '' )
466  {
467    $vtp->addSession( $handle, 'comment' );
468    $vtp->setVar( $handle, 'comment.cat_comment', $page['comment'] );
469    $vtp->closeSession( $handle, 'comment' );
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.