source: trunk/category.php @ 128

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

Internationalization of the "comments" for the number of comments under each
picture.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 KB
Line 
1<?php
2/***************************************************************************
3 *                               category.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: category.php 128 2003-09-17 20:11:57Z z0rglub $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19// determine the initial instant to indicate the generation time of this page
20$t1 = explode( ' ', microtime() );
21$t2 = explode( '.', $t1[0] );
22$t2 = $t1[1].'.'.$t2[1];
23//----------------------------------------------------------- personnal include
24include_once( './include/init.inc.php' );
25//---------------------------------------------------------------------- logout
26if ( $_GET['act'] == 'logout' and isset( $_COOKIE['id'] ) )
27{
28  // cookie deletion if exists
29  setcookie( 'id', '', 0, cookie_path() );
30  $url = 'category.php';
31  header( 'Request-URI: '.$url ); 
32  header( 'Content-Location: '.$url ); 
33  header( 'Location: '.$url );
34  exit();
35}
36//-------------------------------------------------- access authorization check
37// creating the plain structure : array of all the available categories and
38// their relative informations, see the definition of the function
39// get_plain_structure for further details.
40$page['plain_structure'] = get_plain_structure();
41
42check_cat_id( $_GET['cat'] );
43check_login_authorization();
44if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
45{
46  check_restrictions( $page['cat'] );
47}
48//-------------------------------------------------------------- initialization
49// creation of the array containing the cat ids to expand in the menu
50// $page['tab_expand'] contains an array with the category ids
51// $page['expand'] contains the string to display in URL with comma
52$page['tab_expand'] = array();
53if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
54{
55  $tab_expand = explode( ',', $_GET['expand'] );
56  foreach ( $tab_expand as $id ) {
57    if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
58  }
59  $page['expand'] = implode( ',', $page['tab_expand'] );
60}
61// in case of expanding all authorized cats
62// The $page['expand'] equals 'all' and
63// $page['tab_expand'] contains all the authorized cat ids
64if ( $user['expand'] or $_GET['expand'] == 'all' )
65{
66  $page['tab_expand'] = array();
67  $page['expand'] = 'all';
68}
69// detection of the start picture to display
70if ( !isset( $_GET['start'] )
71     or !is_numeric( $_GET['start'] )
72     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
73{
74  $page['start'] = 0;
75}
76else
77{
78  $page['start'] = $_GET['start'];
79}
80// Sometimes, a "num" is provided in the URL. It is the number
81// of the picture to show. This picture must be in the thumbnails page.
82// We have to find the right $page['start'] that show the num picture
83// in this category
84if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
85{
86  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
87  $page['start']*= $user['nb_image_page'];
88}
89// creating the structure of the categories (useful for displaying the menu)
90$page['structure'] = create_structure( '', $user['restrictions'] );
91$page['structure'] = update_structure( $page['structure'] );
92initialize_category();
93//----------------------------------------------------- template initialization
94$vtp = new VTemplate;
95$handle = $vtp->Open( './template/'.$user['template'].'/category.vtp' );
96initialize_template();
97$tpl = array(
98  'categories','hint_category','sub-cat','images_available','total',
99  'title_menu','nb_image_category','send_mail','title_send_mail',
100  'generation_time','connected_user','recent_image','days','generation_time',
101  'favorite_cat_hint','favorite_cat','stats','most_visited_cat_hint',
102  'most_visited_cat','recent_cat','recent_cat_hint','upload_picture',
103  'comments' );
104templatize_array( $tpl, 'lang', $handle );
105
106$tpl = array( 'mail_webmaster','webmaster','top_number','version','site_url' );
107templatize_array( $tpl, 'conf', $handle );
108
109$tpl = array( 'short_period','long_period','lien_collapsed', 'username' );
110templatize_array( $tpl, 'user', $handle );
111
112$tpl = array( 'title','navigation_bar','cat_comment','cat_nb_images' );
113templatize_array( $tpl, 'page', $handle );
114
115// special global template vars
116$vtp->setGlobalVar( $handle, 'icon_short', get_icon( time() ) );
117$icon_long = get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) );
118$vtp->setGlobalVar( $handle, 'icon_long', $icon_long );
119$nb_total_pictures = count_images( $page['structure'] );
120$vtp->setGlobalVar( $handle, 'nb_total_pictures',$nb_total_pictures );
121//------------------------------------------------------------- categories menu
122// normal categories
123foreach ( $page['structure'] as $category ) {
124  // display category is a function relative to the template
125  display_category( $category, '&nbsp;', $handle );
126}
127// favorites cat
128if ( !$user['is_the_guest'] )
129{
130  $vtp->addSession( $handle, 'favorites' );
131  $url = './category.php?cat=fav&amp;expand='.$page['expand'];
132  $vtp->setVar( $handle, 'favorites.url', add_session_id( $url ) );
133  // searching the number of favorite picture
134  $query = 'SELECT COUNT(*) AS count';
135  $query.= ' FROM '.PREFIX_TABLE.'favorites';
136  $query.= ' WHERE user_id = '.$user['id'].';';
137  $result = mysql_query( $query );
138  $row = mysql_fetch_array( $result );
139  $vtp->setVar( $handle, 'favorites.nb_favorites', $row['count'] );
140  $vtp->closeSession( $handle, 'favorites' );
141}
142// most visited pictures category
143$url = './category.php?cat=most_visited&amp;expand='.$page['expand'];
144$vtp->setGlobalVar( $handle, 'most_visited_url', add_session_id( $url ) );
145// recent pictures
146$url = './category.php?cat=recent&amp;expand='.$page['expand'];
147$vtp->setGlobalVar( $handle, 'recent_url', add_session_id( $url ) );
148//--------------------------------------------------------------------- summary
149$vtp->addSession( $handle, 'summary' );
150$vtp->setVar( $handle, 'summary.url', './identification.php' );
151if ( !$user['is_the_guest'] )
152{
153  $vtp->setVar( $handle, 'summary.title', '' );
154  $vtp->setVar( $handle, 'summary.name',replace_space($lang['change_login']));
155}
156else
157{
158  $vtp->setVar( $handle, 'summary.title', $lang['hint_login'] );
159  $vtp->setVar( $handle, 'summary.name',  replace_space( $lang['login'] ) );
160}
161$vtp->closeSession( $handle, 'summary' );
162// links for registered users
163if ( !$user['is_the_guest'] )
164{
165  // logout link
166  $vtp->addSession( $handle, 'summary' );
167  $vtp->setVar( $handle, 'summary.url', './category.php?act=logout' );
168  $vtp->setVar( $handle, 'summary.title', '' );
169  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['logout'] ) );
170  $vtp->closeSession( $handle, 'summary' );
171  // customization link
172  $vtp->addSession( $handle, 'summary' );
173  $url = './profile.php?cat='.$page['cat'];
174  $url.= '&amp;expand='.$page['expand'];
175  if ( $page['cat'] == 'search' )
176  {
177    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
178  }
179  $vtp->setVar( $handle, 'summary.url', add_session_id( $url ) );
180  $vtp->setVar( $handle, 'summary.title', $lang['hint_customize'] );
181  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['customize'] ) );
182  $vtp->closeSession( $handle, 'summary' );
183}
184// search link
185$vtp->addSession( $handle, 'summary' );
186$vtp->setVar( $handle, 'summary.url', add_session_id( './search.php' ) );
187$vtp->setVar( $handle, 'summary.title', $lang['hint_search'] );
188$vtp->setVar( $handle, 'summary.name', replace_space( $lang['search'] ) );
189$vtp->closeSession( $handle, 'summary' );
190// about link
191$vtp->addSession( $handle, 'summary' );
192$vtp->setVar( $handle, 'summary.url', './about.php?'.
193              str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) );
194$vtp->setVar( $handle, 'summary.title', $lang['hint_about'] );
195$vtp->setVar( $handle, 'summary.name', replace_space( $lang['about'] ) );
196$vtp->closeSession( $handle, 'summary' );
197// administration link
198if ( $user['status'] == 'admin' )
199{
200  $vtp->addSession( $handle, 'summary' );
201  $vtp->setVar( $handle, 'summary.url',
202                add_session_id( './admin/admin.php' ) );
203  $vtp->setVar( $handle, 'summary.title', $lang['hint_admin'] );
204  $vtp->setVar( $handle, 'summary.name', replace_space( $lang['admin'] ) );
205  $vtp->closeSession( $handle, 'summary' );
206}
207//-------------------------------------------------------------- category title
208if ( isset ( $page['cat'] ) )
209{
210  if ( is_numeric( $page['cat'] ) )
211  {
212    $cat_title = get_cat_display_name( $page['cat_name'], '<br />',
213                                    'font-style:italic;' );
214    $vtp->setGlobalVar( $handle, "cat_title", $cat_title );
215  }
216  else
217  {
218    if ( $page['cat'] == 'search' )
219    {
220      $page['title'].= ' : <span style="font-style:italic;">';
221      $page['title'].= $_GET['search']."</span>";
222    }
223    $page['title'] = replace_space( $page['title'] );
224    $vtp->setGlobalVar( $handle, "cat_title", $page['title'] );
225  }
226}
227else
228{
229  $vtp->setGlobalVar( $handle, "cat_title",
230                      replace_space( $lang['no_category'] ) );
231}
232//------------------------------------------------------------------ thumbnails
233if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
234{
235  $array_cat_directories = array();
236 
237  $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
238  $query.= ',storage_category_id';
239  $query.= ' FROM '.PREFIX_TABLE.'images AS i';
240  $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
241  $query.= $page['where'];
242  $query.= $conf['order_by'];
243  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
244  $query.= ';';
245  $result = mysql_query( $query );
246
247  $vtp->addSession( $handle, 'thumbnails' );
248  $vtp->addSession( $handle, 'line' );
249  // iteration counter to use a new <tr> every "$nb_image_line" pictures
250  $cell_number = 1;
251  // iteration counter to be sure not to create too much lines in the table
252  $line_number = 1;
253  while ( $row = mysql_fetch_array( $result ) )
254  {
255    // retrieving the storage dir of the picture
256    if ( $array_cat_directories[$row['storage_category_id']] == '' )
257    {
258      $array_cat_directories[$row['storage_category_id']] =
259        get_complete_dir( $row['storage_category_id'] );
260    }
261    $cat_directory = $array_cat_directories[$row['storage_category_id']];
262
263    $file = get_filename_wo_extension( $row['file'] );
264    // name of the picture
265    if ( $row['name'] != '' ) $name = $row['name'];
266    else                      $name = str_replace( '_', ' ', $file );
267
268    if ( $page['cat'] == 'search' )
269    {
270      $name = replace_search( $name, $_GET['search'] );
271    }
272    // thumbnail url
273    $thumbnail_url = $cat_directory;
274    $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
275    $thumbnail_url.= $file.'.'.$row['tn_ext'];
276    // message in title for the thumbnail
277    $thumbnail_title = $row['file'];
278    if ( $row['filesize'] == '' )
279    {
280      $poids = floor( filesize( $lien_image ) / 1024 );
281    }
282    else
283    {
284      $poids = $row['filesize'];
285    }
286    $thumbnail_title .= ' : '.$poids.' KB';
287    // url link on picture.php page
288    $url_link = './picture.php?cat='.$page['cat'];
289    $url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
290    if ( $page['cat'] == 'search' )
291    {
292      $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
293    }
294    // date of availability for creation icon
295    list( $year,$month,$day ) = explode( '-', $row['date_available'] );
296    $date = mktime( 0, 0, 0, $month, $day, $year );
297    // sending vars to display
298    $vtp->addSession( $handle, 'thumbnail' );
299    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
300    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_url );
301    $vtp->setVar( $handle, 'thumbnail.alt', $row['file'] );
302    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
303    $vtp->setVar( $handle, 'thumbnail.name', $name );
304    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
305
306    if ( $conf['show_comments'] and $user['show_nb_comments'] )
307    {
308      $vtp->addSession( $handle, 'nb_comments' );
309      $query = 'SELECT COUNT(*) AS nb_comments';
310      $query.= ' FROM '.PREFIX_TABLE.'comments';
311      $query.= ' WHERE image_id = '.$row['id'];
312      $query.= " AND validated = 'true'";
313      $query.= ';';
314      $row = mysql_fetch_array( mysql_query( $query ) );
315      $vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] );
316      $vtp->closeSession( $handle, 'nb_comments' );
317    }
318   
319    $vtp->closeSession( $handle, 'thumbnail' );
320   
321    if ( $cell_number++ == $user['nb_image_line'] )
322    {
323      // creating a new line
324      $vtp->closeSession( $handle, 'line' );
325      // the number of the next cell is 1
326      $cell_number = 1;
327      // we only create a new line if it does not exceed the maximum line
328      // per page for the logged user
329      if ( $line_number++ < $user['nb_line_page'] )
330      {
331        $vtp->addSession( $handle, 'line' );
332      }
333    }
334  }
335  $vtp->closeSession( $handle, 'thumbnails' );
336}
337//-------------------------------------------------------------- empty category
338elseif ( ( isset( $page['cat'] )
339           and is_numeric( $page['cat'] )
340           and $page['cat_nb_images'] == 0 )
341         or $_GET['cat'] == '' )
342{
343  $vtp->addSession( $handle, 'thumbnails' );
344  $vtp->addSession( $handle, 'line' );
345
346  $subcats = get_non_empty_subcat_ids( $page['cat'] );
347  $cell_number = 1;
348  $i = 0;
349  foreach ( $subcats as $subcat_id => $non_empty_id ) {
350    $subcat_infos  = get_cat_info( $subcat_id );
351
352    $name ='[ <span style="font-weight:bold;">';
353    $name.= $subcat_infos['name'][0];
354    $name.= '</span> ]';
355
356    $query = 'SELECT file,tn_ext,storage_category_id';
357    $query.= ' FROM '.PREFIX_TABLE.'images';
358    $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
359    $query.= ' WHERE category_id = '.$non_empty_id;
360    $query.= ' ORDER BY RAND()';
361    $query.= ' LIMIT 0,1';
362    $query.= ';';
363    $image_result = mysql_query( $query );
364    $image_row    = mysql_fetch_array( $image_result );
365
366    $file = get_filename_wo_extension( $image_row['file'] );
367
368    // creating links for thumbnail and associated category
369    $thumbnail_link = get_complete_dir( $image_row['storage_category_id'] );
370    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
371    $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
372
373    $thumbnail_title = $lang['hint_category'];
374
375    $url_link = './category.php?cat='.$subcat_id;
376    if ( !in_array( $page['cat'], $page['tab_expand'] ) )
377    {
378      array_push( $page['tab_expand'], $page['cat'] );
379      $page['expand'] = implode( ',', $page['tab_expand'] );
380    }
381    $url_link.= '&amp;expand='.$page['expand'];
382    // we add the category to explore in the expand list
383    if ( $page['expand'] != '' ) $url_link.= ',';
384    $url_link.= $subcat_id;
385
386    list( $year,$month,$day ) = explode( '-', $subcat_infos['date_last'] );
387    $date = mktime( 0, 0, 0, $month, $day, $year );
388
389    // sending vars to display
390    $vtp->addSession( $handle, 'thumbnail' );
391    $vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
392    $vtp->setVar( $handle, 'thumbnail.src', $thumbnail_link );
393    $vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
394    $vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
395    $vtp->setVar( $handle, 'thumbnail.name', $name );
396    $vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
397    $vtp->closeSession( $handle, 'thumbnail' );
398
399    if ( $cell_number++ == $user['nb_image_line'] )
400    {
401      $vtp->closeSession( $handle, 'line' );
402      $cell_number = 1;
403      // we open a new line if the subcat was not the last one
404      if ( $i++ < count( $subcats ) - 1 )
405      {
406        $vtp->addSession( $handle, 'line' );
407      }
408    }
409  }
410  if ( $i < count( $subcats ) - 1 )
411  {
412    $vtp->closeSession( $handle, 'line' );
413  }
414  $vtp->closeSession( $handle, 'thumbnails' );
415}
416//------------------------------------------------------- category informations
417if ( isset ( $page['cat'] ) )
418{
419  $vtp->addSession( $handle, 'cat_infos' );
420  // navigation bar
421  if ( $page['navigation_bar'] != '' )
422  {
423    $vtp->addSession( $handle, 'navigation' );
424    $vtp->closeSession( $handle, 'navigation' );
425  }
426  // category comment
427  if ( isset( $page['comment'] ) and $page['comment'] != '' )
428  {
429    $vtp->addSession( $handle, 'comment' );
430    $vtp->setVar( $handle, 'comment.cat_comment', $page['comment'] );
431    $vtp->closeSession( $handle, 'comment' );
432  }
433  // total number of pictures in the category
434  if ( is_numeric( $page['cat'] ) )
435  {
436    $vtp->setVar( $handle, 'cat_infos.cat_name',
437                  get_cat_display_name( $page['cat_name'], ' - ',
438                                        'font-style:italic;' ) );
439  }
440  else
441  {
442    $vtp->setVar( $handle, 'cat_infos.cat_name', $page['title'] );
443  }
444  // upload a picture in the category
445  if ( $page['cat_site_id'] == 1
446       and $conf['upload_available']
447       and $page['cat_uploadable'] )
448  {
449    $vtp->addSession( $handle, 'upload' );
450    $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
451    $vtp->setVar( $handle, 'upload.url', add_session_id( $url ) );
452    $vtp->closeSession( $handle, 'upload' );
453  }
454  $vtp->closeSession( $handle, 'cat_infos' );
455}
456//------------------------------------------------------------ log informations
457pwg_log( 'category', $page['title'] );
458mysql_close();
459//------------------------------------------------------------- generation time
460$time = get_elapsed_time( $t2, get_moment() );
461$vtp->setGlobalVar( $handle, 'time', $time );
462//----------------------------------------------------------- html code display
463$code = $vtp->Display( $handle, 0 );
464echo $code;
465?>
Note: See TracBrowser for help on using the repository browser.