source: trunk/category.php @ 20

Last change on this file since 20 was 20, 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.4 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'].'&amp;mode='.$_GET['mode'];
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?'.$_SERVER['QUERY_STRING'] ) );
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,tn_ext,name,filesize,cat_id';
241  $query.= ' FROM '.PREFIX_TABLE.'images';
242  $query.= $page['where'];
243  $query.= $conf['order_by'];
244  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
245  $query.= ';';
246  echo $query;
247  $result = mysql_query( $query );
248
249  $vtp->addSession( $handle, 'thumbnails' );
250  $vtp->addSession( $handle, 'line' );
251  // iteration counter to use a new <tr> every "$nb_image_line" pictures
252  $cell_number = 1;
253  // iteration counter to be sure not to create too much lines in the table
254  $line_number = 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    $file = get_filename_wo_extension( $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['prefix_thumbnail'];
283    $thumbnail_url.= $file.'.'.$row['tn_ext'];
284    // message in title for the thumbnail
285    $thumbnail_title = $row['file'];
286    if ( $row['filesize'] == '' )
287    {
288      $poids = floor( filesize( $lien_image ) / 1024 );
289    }
290    else
291    {
292      $poids = $row['filesize'];
293    }
294    $thumbnail_title .= ' : '.$poids.' KB';
295    // url link on picture.php page
296    $url_link = './picture.php?cat='.$page['cat'];
297    $url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
298    if ( $page['cat'] == 'search' )
299    {
300      $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
301    }
302    // date of availability for creation icon
303    list( $year,$month,$day ) = explode( '-', $row['date_available'] );
304    $date = mktime( 0, 0, 0, $month, $day, $year );
305    // sending vars to display
306    $vtp->addSession( $handle, 'thumbnail' );
307    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
308    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_url );
309    $vtp->setVar( $handle, 'thumbnail.alt', $row['file'] );
310    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
311    $vtp->setVar( $handle, 'thumbnail.name', $name );
312    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
313
314    if ( $conf['show_comments'] and $user['show_nb_comments'] )
315    {
316      $vtp->addSession( $handle, 'nb_comments' );
317      $query = 'SELECT COUNT(*) AS nb_comments';
318      $query.= ' FROM '.PREFIX_TABLE.'comments';
319      $query.= ' WHERE image_id = '.$row['id'];
320      $query.= ';';
321      $row = mysql_fetch_array( mysql_query( $query ) );
322      $vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] );
323      $vtp->closeSession( $handle, 'nb_comments' );
324    }
325   
326    $vtp->closeSession( $handle, 'thumbnail' );
327   
328    if ( $cell_number++ == $user['nb_image_line'] )
329    {
330      // creating a new line
331      $vtp->closeSession( $handle, 'line' );
332      // the number of the next cell is 1
333      $cell_number = 1;
334      // we only create a new line if it does not exceed the maximum line
335      // per page for the logged user
336      if ( $line_number++ < $user['nb_line_page'] )
337      {
338        $vtp->addSession( $handle, 'line' );
339      }
340    }
341  }
342  $vtp->closeSession( $handle, 'thumbnails' );
343}
344elseif ( isset( $page['cat'] )
345         and is_numeric( $page['cat'] )
346         and $page['cat_nb_images'] == 0 )
347{
348  $vtp->addSession( $handle, 'thumbnails' );
349  $vtp->addSession( $handle, 'line' );
350
351  $subcats = get_non_empty_sub_cat_ids( $page['cat'] );
352  $cell_number = 1;
353  foreach ( $subcats as $id => $subcat ) {
354    $result = get_cat_info( $subcat['non_empty_cat'] );
355    $cat_directory = $result['dir'];
356
357    $name = '[ <span style="font-weight:bold;">';
358    if ( $subcat['name'] != '' )
359    {
360      $name.= $subcat['name'];
361    }
362    else
363    {
364      $name.= $subcat['dir'];
365    }
366    $name.= '</span> ]';
367    $name = replace_space( $name );
368   
369    $query = 'SELECT file,tn_ext';
370    $query.= ' FROM '.PREFIX_TABLE.'images';
371    $query.= ' WHERE cat_id = '.$subcat['non_empty_cat'];
372    $query.= ' ORDER BY RAND()';
373    $query.= ' LIMIT 0,1';
374    $query.= ';';
375    $image_result = mysql_query( $query );
376    $image_row = mysql_fetch_array( $image_result );
377
378    $file = get_filename_wo_extension( $image_row['file'] );
379
380    // creating links for thumbnail and associated category
381    $lien_image = $cat_directory;
382    $lien_thumbnail = $lien_image;
383    $lien_thumbnail.= 'thumbnail/'.$conf['prefix_thumbnail'];
384    $lien_thumbnail.= $file.'.'.$image_row['tn_ext'];
385    $lien_image.= $image_row['file'];
386
387    $thumbnail_title = $lang['hint_category'];
388
389    $url_link = './category.php?cat='.$subcat['id'];
390    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
391    {
392      array_push( $page['tab_expand'], $page['cat'] );
393      $page['expand'] = implode( ',', $page['tab_expand'] );
394    }
395    $url_link.= '&amp;expand='.$page['expand'];
396    list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
397    $date = mktime( 0, 0, 0, $month, $day, $year );
398
399    // sending vars to display
400    $vtp->addSession( $handle, 'thumbnail' );
401    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
402    $vtp->setVar( $handle, 'thumbnail.src', $lien_thumbnail );
403    $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
404    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
405    $vtp->setVar( $handle, 'thumbnail.name', $name );
406    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
407    $vtp->closeSession( $handle, 'thumbnail' );
408
409    if ( $cell_number++ == $user['nb_image_line'] )
410    {
411      $vtp->closeSession( $handle, 'line' );
412      $cell_number = 1;
413      // we open a new line if the subcat was not the last one
414      if ( $id < count( $subcats ) - 1 )
415      {
416        $vtp->addSession( $handle, 'line' );
417      }
418    }
419  }
420  if ( $id < count( $subcats ) - 1 )
421  {
422    $vtp->closeSession( $handle, 'line' );
423  }
424  $vtp->closeSession( $handle, 'thumbnails' );
425}
426//------------------------------------------------------- category informations
427if ( isset ( $page['cat'] ) )
428{
429  $vtp->addSession( $handle, 'cat_infos' );
430  // navigation bar
431  if ( $page['navigation_bar'] != '' )
432  {
433    $vtp->addSession( $handle, 'navigation' );
434    $vtp->closeSession( $handle, 'navigation' );
435  }
436  // category comment
437  if ( isset( $page['comment'] ) and $page['comment'] != '' )
438  {
439    $vtp->addSession( $handle, 'comment' );
440    $vtp->setVar( $handle, 'comment.cat_comment', $page['comment'] );
441    $vtp->closeSession( $handle, 'comment' );
442  }
443  // total number of pictures in the category
444  if ( is_numeric( $page['cat'] ) )
445  {
446    $vtp->setVar( $handle, 'cat_infos.cat_name',
447                  get_cat_display_name( $page['cat_name'], ' - ',
448                                        'font-style:italic;' ) );
449  }
450  else
451  {
452    $vtp->setVar( $handle, 'cat_infos.cat_name', $page['title'] );
453  }
454  // upload a picture in the category
455  if ( $page['cat_site_id'] == 1 and $conf['upload_available'] )
456  {
457    $vtp->addSession( $handle, 'upload' );
458    $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
459    $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
460    $vtp->closeSession( $handle, 'upload' );
461  }
462  $vtp->closeSession( $handle, 'cat_infos' );
463}
464//------------------------------------------------------------ log informations
465pwg_log( 'category', $page['title'] );
466mysql_close();
467//------------------------------------------------------------- generation time
468$time = get_elapsed_time( $t2, get_moment() );
469$vtp->setGlobalVar( $handle, 'time', $time );
470//----------------------------------------------------------- html code display
471$code = $vtp->Display( $handle, 0 );
472echo $code;
473?>
Note: See TracBrowser for help on using the repository browser.