source: trunk/category.php @ 362

Last change on this file since 362 was 362, checked in by z0rglub, 20 years ago

header global refactoring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.9 KB
Line 
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-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 362 $
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$phpwg_root_path = './';
30include_once( $phpwg_root_path.'include/common.inc.php' );
31//---------------------------------------------------------------------- logout
32if ( 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  header( 'Request-URI: '.$url ); 
40  header( 'Content-Location: '.$url ); 
41  header( 'Location: '.$url );
42  exit();
43}
44//-------------------------------------------------- access authorization check
45if ( isset( $_GET['cat'] ) ) check_cat_id( $_GET['cat'] );
46check_login_authorization();
47if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
48{
49  check_restrictions( $page['cat'] );
50}
51//-------------------------------------------------------------- initialization
52// detection of the start picture to display
53if ( !isset( $_GET['start'] )
54     or !is_numeric( $_GET['start'] )
55     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
56  $page['start'] = 0;
57else
58  $page['start'] = $_GET['start'];
59
60initialize_category();
61
62// creation of the array containing the cat ids to expand in the menu
63// $page['tab_expand'] contains an array with the category ids
64// $page['expand'] contains the string to display in URL with comma
65$page['tab_expand'] = array();
66if ( isset ( $_GET['expand'] ) and $_GET['expand'] != 'all' )
67{
68  $tab_expand = explode( ',', $_GET['expand'] );
69  foreach ( $tab_expand as $id ) {
70    if ( is_numeric( $id ) ) array_push( $page['tab_expand'], $id );
71  }
72}
73if ( isset($page['cat']) && is_numeric( $page['cat'] ) )
74{
75  // the category displayed (in the URL cat=23) must be seen in the menu ->
76  // parent categories must be expanded
77  $uppercats = explode( ',', $page['uppercats'] );
78  foreach ( $uppercats as $uppercat ) {
79    array_push( $page['tab_expand'], $uppercat );
80  }
81}
82$page['tab_expand'] = array_unique( $page['tab_expand'] );
83$page['expand'] = implode( ',', $page['tab_expand'] );
84// in case of expanding all authorized cats
85// The $page['expand'] equals 'all' and
86// $page['tab_expand'] contains all the authorized cat ids
87if ( $user['expand']
88     or ( isset( $_GET['expand'] ) and $_GET['expand'] == 'all' ) )
89{
90  $page['tab_expand'] = array();
91  $page['expand'] = 'all';
92}
93// Sometimes, a "num" is provided in the URL. It is the number
94// of the picture to show. This picture must be in the thumbnails page.
95// We have to find the right $page['start'] that show the num picture
96// in this category
97if ( isset( $_GET['num'] )
98     and is_numeric( $_GET['num'] )
99     and $_GET['num'] >= 0 )
100{
101  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
102  $page['start']*= $user['nb_image_page'];
103}
104// creating the structure of the categories (useful for displaying the menu)
105// creating the plain structure : array of all the available categories and
106// their relative informations, see the definition of the function
107// get_user_plain_structure for further details.
108$page['plain_structure'] = get_user_plain_structure();
109$page['structure'] = create_user_structure( '' );
110$page['structure'] = update_structure( $page['structure'] );
111
112//----------------------------------------------------- template initialization
113
114//
115// Start output of page
116//
117$title = $page['title'];
118include('include/page_header.php');
119
120$template->set_filenames( array('category'=>'category.tpl') );
121initialize_template();
122
123//-------------------------------------------------------------- category title
124$cat_title = $lang['no_category'];
125if ( isset ( $page['cat'] ) )
126{
127  if ( is_numeric( $page['cat'] ) )
128  {
129    $cat_title = get_cat_display_name( $page['cat_name'], '<br />',
130                                    'font-style:italic;' );
131  }
132  else
133  {
134    if ( $page['cat'] == 'search' )
135    {
136      $page['title'].= ' : <span style="font-style:italic;">';
137      $page['title'].= $_GET['search']."</span>";
138    }
139    $page['title'] = replace_space( $page['title'] );
140  }
141}
142
143$template->assign_vars(array(
144  'NB_PICTURE' => count_user_total_images(),
145  'TITLE' => $cat_title,
146  'USERNAME' => $user['username'],
147 
148  'S_TOP'=>$conf['top_number'],
149  'S_SHORT_PERIOD'=>$user['short_period'],
150  'S_LONG_PERIOD'=>$user['long_period'],
151  'S_WEBMASTER'=>$conf['webmaster'],
152  'S_MAIL'=>$conf['mail_webmaster'],
153
154  'L_CATEGORIES' => $lang['categories'],
155  'L_HINT_CATEGORY' => $lang['hint_category'],
156  'L_SUBCAT' => $lang['sub-cat'],
157  'L_IMG_AVAILABLE' => $lang['images_available'],
158  'L_TOTAL' => $lang['total'],
159  'L_FAVORITE_HINT' => $lang['favorite_cat_hint'],
160  'L_FAVORITE' => $lang['favorite_cat'],
161  'L_STATS' => $lang['stats'],
162  'L_MOST_VISITED_HINT' => $lang['most_visited_cat_hint'],
163  'L_MOST_VISITED' => $lang['most_visited_cat'],
164  'L_RECENT_HINT' => $lang['recent_cat_hint'],
165  'L_RECENT' => $lang['recent_cat'],
166  'L_SUMMARY' => $lang['title_menu'],
167  'L_UPLOAD' => $lang['upload_picture'],
168  'L_COMMENT' => $lang['comments'],
169  'L_NB_IMG' => $lang['nb_image_category'],
170  'L_USER' => $lang['connected_user'],
171  'L_RECENT_IMAGE' => $lang['recent_image'],
172  'L_DAYS' => $lang['days'],
173  'L_SEND_MAIL' => $lang['send_mail'],
174  'L_TITLE_MAIL' => $lang['title_send_mail'],
175 
176  'T_COLLAPSED' => $user['lien_collapsed'],
177  'T_SHORT'=>get_icon( time() ),
178  'T_LONG'=>get_icon( time() - ( $user['short_period'] * 24 * 60 * 60 + 1 ) ),
179
180  'U_HOME' => add_session_id( 'category.php' ),
181  'U_FAVORITE' => add_session_id( './category.php?cat=fav&amp;expand='.$page['expand'] ),
182  'U_MOST_VISITED'=>add_session_id( './category.php?cat=most_visited&amp;expand='.$page['expand'] ),
183  'U_RECENT'=>add_session_id( './category.php?cat=recent&amp;expand='.$page['expand'] )
184  )
185);
186
187foreach ( $page['structure'] as $category ) {
188  // display category is a function relative to the template
189  display_category( $category, '&nbsp;');
190}
191
192// favorites management
193if ( !$user['is_the_guest'] )
194{
195  // searching the number of favorite picture
196  $query = 'SELECT COUNT(*) AS count';
197  $query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';';
198  $result = mysql_query( $query );
199  $row = mysql_fetch_array( $result );
200  $template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) );
201}
202//--------------------------------------------------------------------- summary
203$sum_title = '';
204$sum_name='';
205$sum_url = '';
206if ( !$user['is_the_guest'] )
207{
208  $sum_name=replace_space($lang['logout']);
209  $sum_url = 'category.php?act=logout';
210}
211else
212{
213  $sum_title =  $lang['hint_login'];
214  $sum_name=replace_space( $lang['menu_login']);
215  $sum_url = 'identification.php';
216}
217$template->assign_block_vars('summary', array(
218  'TITLE'=>$sum_title,
219  'NAME'=>$sum_name,
220  'U_SUMMARY'=>add_session_id( $sum_url ),
221  )
222);
223
224// customization link
225if ( !$user['is_the_guest'] )
226{
227  $template->assign_block_vars('summary', array(
228  'TITLE'=>$lang['hint_customize'],
229  'NAME'=>$lang['customize'],
230  'U_SUMMARY'=>add_session_id('profile.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] )),
231  ));
232}
233
234// search link
235$template->assign_block_vars('summary', array(
236'TITLE'=>$lang['hint_search'],
237'NAME'=>$lang['search'],
238'U_SUMMARY'=>add_session_id( 'search.php' ),
239));
240
241// comments link
242$template->assign_block_vars('summary', array(
243'TITLE'=>$lang['hint_comments'],
244'NAME'=>$lang['comments'],
245'U_SUMMARY'=>add_session_id( 'comments.php' ),
246));
247
248// about link
249$template->assign_block_vars('summary', array(
250'TITLE'=>$lang['hint_about'],
251'NAME'=>$lang['about'],
252'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) )
253));
254
255// administration link
256if ( $user['status'] == 'admin' )
257{
258  $template->assign_block_vars('summary', array(
259    'TITLE'=>$lang['hint_admin'],
260    'NAME'=>$lang['admin'],
261    'U_SUMMARY'=>add_session_id( 'admin.php' )
262    ));
263}
264
265//------------------------------------------------------------------ thumbnails
266if ( isset( $page['cat'] ) && $page['cat_nb_images'] != 0 )
267{
268  $array_cat_directories = array();
269 
270  $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
271  $query.= ',storage_category_id';
272  $query.= ' FROM '.IMAGES_TABLE.' AS i';
273  $query.=' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id';
274  $query.= $page['where'];
275  $query.= $conf['order_by'];
276  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
277  $query.= ';';
278  $result = mysql_query( $query );
279
280  $template->assign_block_vars('thumbnails', array());
281
282  // iteration counter to use a new <tr> every "$nb_image_line" pictures
283  $cell_number = 0;
284  // iteration counter to be sure not to create too much lines in the table
285  $line_number = 0;
286
287  while ( $row = mysql_fetch_array( $result ) )
288  {
289    // retrieving the storage dir of the picture
290    if ( !isset($array_cat_directories[$row['storage_category_id']]))
291    {
292      $array_cat_directories[$row['storage_category_id']] =
293        get_complete_dir( $row['storage_category_id'] );
294    }
295    $cat_directory = $array_cat_directories[$row['storage_category_id']];
296
297    $file = get_filename_wo_extension( $row['file'] );
298    // name of the picture
299    if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name'];
300    else $name = str_replace( '_', ' ', $file );
301
302    if ( $page['cat'] == 'search' )
303    {
304      $name = replace_search( $name, $_GET['search'] );
305    }
306    // thumbnail url
307    $thumbnail_url = $cat_directory;
308    $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
309    $thumbnail_url.= $file.'.'.$row['tn_ext'];
310    // message in title for the thumbnail
311    $thumbnail_title = $row['file'];
312    if ( $row['filesize'] == '' )
313      $poids = floor( filesize( $cat_directory.$row['file'] ) / 1024 );
314    else
315      $poids = $row['filesize'];
316    $thumbnail_title .= ' : '.$poids.' KB';
317    // url link on picture.php page
318    $url_link = './picture.php?cat='.$page['cat'];
319    $url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
320    if ( $page['cat'] == 'search' )
321    {
322      $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
323    }
324    // date of availability for creation icon
325    list( $year,$month,$day ) = explode( '-', $row['date_available'] );
326    $date = mktime( 0, 0, 0, $month, $day, $year );
327   
328        // sending vars to display
329        if (!$cell_number && ( $line_number< $user['nb_line_page']))
330    {
331      $template->assign_block_vars('thumbnails.line', array());
332      $cell_number = 0;
333          $line_number++;
334    }
335        if ( $cell_number++ == $user['nb_image_line'] -1) $cell_number = 0;
336       
337        $template->assign_block_vars('thumbnails.line.thumbnail', array(
338          'IMAGE'=>$thumbnail_url,
339          'IMAGE_ALT'=>$row['file'],
340          'IMAGE_TITLE'=>$thumbnail_title,
341          'IMAGE_NAME'=>$name,
342          'IMAGE_TS'=>get_icon( $date ),
343
344          'U_IMG_LINK'=>add_session_id( $url_link )
345          ));
346
347    if ( $conf['show_comments'] && $user['show_nb_comments'] )
348    {
349      $vtp->addSession( $handle, 'nb_comments' );
350      $query = 'SELECT COUNT(*) AS nb_comments';
351      $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id'];
352      $query.= " AND validated = 'true'";
353      $query.= ';';
354      $row = mysql_fetch_array( mysql_query( $query ) );
355      $vtp->setVar( $handle, 'nb_comments.nb', $row['nb_comments'] );
356      $vtp->closeSession( $handle, 'nb_comments' );
357    }
358  }
359}
360//-------------------------------------------------------------- empty category
361else
362{
363  $subcats=array();
364  if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] );
365  else                     $subcats = get_non_empty_subcat_ids( '' );
366  $cell_number = 0;
367  $i = 0;
368 
369  $template->assign_block_vars('thumbnails', array());
370 
371  foreach ( $subcats as $subcat_id => $non_empty_id ) 
372  {
373    $name = '<img src="'.$user['lien_collapsed'].'" style="border:none;"';
374    $name.= ' alt="&gt;"/> ';
375    $name.= '[ <span style="font-weight:bold;">';
376    $name.= $page['plain_structure'][$subcat_id]['name'];
377    $name.= '</span> ]';
378
379    // searching the representative picture of the category
380    $query = 'SELECT representative_picture_id';
381    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$non_empty_id;
382    $query.= ';';
383    $row = mysql_fetch_array( mysql_query( $query ) );
384   
385    $query = 'SELECT file,tn_ext,storage_category_id';
386    $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
387    $query.= ' WHERE category_id = '.$non_empty_id;
388    $query.= ' AND id = image_id';
389    // if the category has a representative picture, this is its thumbnail
390    // that will be displayed !
391    if ( isset( $row['representative_picture_id'] ) )
392      $query.= ' AND id = '.$row['representative_picture_id'];
393    else
394      $query.= ' ORDER BY RAND()';
395    $query.= ' LIMIT 0,1';
396    $query.= ';';
397    $image_result = mysql_query( $query );
398    $image_row    = mysql_fetch_array( $image_result );
399
400    $file = get_filename_wo_extension( $image_row['file'] );
401
402    // creating links for thumbnail and associated category
403    $thumbnail_link = get_complete_dir( $image_row['storage_category_id'] );
404    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
405    $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
406
407    $thumbnail_title = $lang['hint_category'];
408
409    $url_link = './category.php?cat='.$subcat_id;
410    if ( isset($page['cat'])&& !in_array( $page['cat'], $page['tab_expand'] ) )
411    {
412      array_push( $page['tab_expand'], $page['cat'] );
413      $page['expand'] = implode( ',', $page['tab_expand'] );
414    }
415    $url_link.= '&amp;expand='.$page['expand'];
416    // we add the category to explore in the expand list
417    if ( $page['expand'] != '' ) $url_link.= ',';
418    $url_link.= $subcat_id;
419
420    $date = $page['plain_structure'][$subcat_id]['date_last'];
421
422    // sending vars to display
423        if (!$cell_number && $i < count( $subcats ))
424    {
425      $template->assign_block_vars('thumbnails.line', array());
426      $cell_number = 0;
427          $i++;
428    }
429        if ( $cell_number++ == $user['nb_image_line'] -1) $cell_number = 0;
430       
431        $template->assign_block_vars('thumbnails.line.thumbnail', array(
432          'IMAGE'=>$thumbnail_link,
433          'IMAGE_ALT'=>$image_row['file'],
434          'IMAGE_TITLE'=>$thumbnail_title,
435          'IMAGE_NAME'=>$name,
436          'IMAGE_TS'=>get_icon( $date ),
437
438          'U_IMG_LINK'=>add_session_id( $url_link )
439          )); 
440  }
441}
442//------------------------------------------------------- category informations
443if ( isset ( $page['cat'] ) )
444{
445  $cat_name='';
446  // total number of pictures in the category
447  if ( is_numeric( $page['cat'] ) )
448  {
449    $cat_name=get_cat_display_name( $page['cat_name'],' - ','font-style:italic;' );
450    // upload a picture in the category
451    if ( $page['cat_site_id'] == 1
452         and $conf['upload_available']
453         and $page['cat_uploadable'] )
454    {
455      $url = './upload.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
456          $template->assign_block_vars('upload',array('U_UPLOAD'=>add_session_id( $url )));
457    }
458  }
459  else
460  {
461    $cat_name= $page['title'];
462  }
463  $template->assign_block_vars('cat_infos',array(
464    'CAT_NAME'=>$cat_name,
465    'NB_IMG_CAT' => $page['cat_nb_images']
466        ));
467
468  // navigation bar
469  if ( $page['navigation_bar'] != '' )
470  { 
471    $template->assign_block_vars('cat_infos.navigation',array('NAV_BAR' => $page['navigation_bar']));
472  }
473  // category comment
474  if ( isset( $page['comment'] ) and $page['comment'] != '' )
475  {
476    $template->assign_block_vars('cat_infos.navigation',array('COMMENTS' => $page['cat_comment']));
477  }
478}
479//------------------------------------------------------------ log informations
480pwg_log( 'category', $page['title'] );
481mysql_close();
482
483$template->pparse('category');
484include('include/page_tail.php');
485?>
Note: See TracBrowser for help on using the repository browser.