source: trunk/category.php @ 393

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