source: trunk/category.php @ 405

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

redirections modification : use of a HTML refresh page instead of header PHP
function. The purpose is to avoid redirections failure when extra characters
are found in included PHP files.

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