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
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-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  |
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  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
52//-------------------------------------------------------------- initialization
53function display_category( $category, $indent )
54{
55  global $user,$template,$page;
56 
57  $url = PHPWG_ROOT_PATH.'category.php?cat='.$category['id'];
58
59  $style = '';
60  if ( isset( $page['cat'] )
61       and is_numeric( $page['cat'] )
62       and $category['id'] == $page['cat'] )
63  {
64    $style = 'font-weight:normal;color:yellow;';
65  }
66 
67  $name = $category['name'];
68  if (empty($name)) $name = str_replace( '_', ' ', $category['dir'] );
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 
83  if ( $user['expand'] or $category['nb_sub_categories'] == 0 )
84  {
85    $template->assign_block_vars(
86      'category.bulletnolink',
87      array('BULLET_IMAGE' => $user['lien_collapsed'])
88      );
89  }
90  else
91  {
92    $url = PHPWG_ROOT_PATH.'category.php';
93    if (isset($page['cat']))
94    {
95      $url .='?cat='.$page['cat'];
96    }
97   
98    if ( $category['expanded'] )
99    {
100      $img=$user['lien_expanded'];
101    }
102    else
103    {
104      $img=$user['lien_collapsed'];
105    }
106   
107    $template->assign_block_vars(
108      'category.bulletlink',
109      array(
110        'BULLET_IMAGE' =>  $img,
111        'U_BULLET_LINK'=>  add_session_id($url))
112      );
113  }
114 
115  // recursive call
116  if ( $category['expanded'] )
117  {
118    foreach ( $category['subcats'] as $subcat ) 
119        {
120      $template->assign_block_vars('category.subcat', array());
121          display_category( $subcat, $indent.str_repeat( '&nbsp;', 2 ));
122    }
123  }
124}
125
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
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();
140if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
141{
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 );
147  }
148}
149// in case of expanding all authorized cats $page['tab_expand'] is empty
150if ( $user['expand'] )
151{
152  $page['tab_expand'] = array();
153}
154
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
159if ( isset( $_GET['num'] )
160     and is_numeric( $_GET['num'] )
161     and $_GET['num'] >= 0 )
162{
163  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
164  $page['start']*= $user['nb_image_page'];
165}
166// creating the structure of the categories (useful for displaying the menu)
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( '' );
172$page['structure'] = update_structure( $page['structure'] );
173
174//----------------------------------------------------- template initialization
175
176//
177// Start output of page
178//
179$title = $page['title'];
180include(PHPWG_ROOT_PATH.'include/page_header.php');
181
182$template->set_filenames( array('category'=>'category.tpl') );
183
184//-------------------------------------------------------------- category title
185$cat_title = $lang['no_category'];
186if ( isset ( $page['cat'] ) )
187{
188  if ( is_numeric( $page['cat'] ) )
189  {
190    $cat_title = get_cat_display_name( $page['cat_name'], ' &gt; ',
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}
203
204$template->assign_vars(array(
205  'NB_PICTURE' => count_user_total_images(),
206  'TITLE' => $cat_title,
207  'USERNAME' => $user['username'],
208  'TOP_VISITED'=>$conf['top_number'],
209
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'],
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'],
236 
237  'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ),
238 
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 ) ),
242
243  'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ),
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' ),
247  'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout',
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'] ))
250  )
251);
252
253foreach ( $page['structure'] as $category ) {
254  // display category is a function relative to the template
255  display_category( $category, '&nbsp;');
256}
257
258// authentification mode management
259if ( !$user['is_the_guest'] )
260{
261  // searching the number of favorite picture
262  $query = 'SELECT COUNT(*) AS count';
263  $query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';';
264  $result = mysql_query( $query );
265  $row = mysql_fetch_array( $result );
266  $template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) );
267  $template->assign_block_vars('username', array());
268}
269//--------------------------------------------------------------------- summary
270
271if ( !$user['is_the_guest'] )
272{
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  }
279}
280else
281{
282  $template->assign_block_vars('login',array());
283}
284
285// search link
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
292// comments link
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
299// about link
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
306//------------------------------------------------------------------ thumbnails
307if ( isset( $page['cat'] ) && $page['cat_nb_images'] != 0 )
308{
309  $array_cat_directories = array();
310 
311  $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
312  $query.= ',storage_category_id';
313  $query.= ' FROM '.IMAGES_TABLE.' AS i';
314  $query.=' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id';
315  $query.= $page['where'];
316  $query.= $conf['order_by'];
317  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
318  $query.= ';';
319  $result = mysql_query( $query );
320
321  $template->assign_block_vars('thumbnails', array());
322
323  // iteration counter to use a new <tr> every "$nb_image_line" pictures
324  $cell_number = 0;
325  // iteration counter to be sure not to create too much lines in the table
326  $line_number = 0;
327
328  while ( $row = mysql_fetch_array( $result ) )
329  {
330    // retrieving the storage dir of the picture
331    if ( !isset($array_cat_directories[$row['storage_category_id']]))
332    {
333      $array_cat_directories[$row['storage_category_id']] =
334        get_complete_dir( $row['storage_category_id'] );
335    }
336    $cat_directory = $array_cat_directories[$row['storage_category_id']];
337
338    $file = get_filename_wo_extension( $row['file'] );
339    // name of the picture
340    if ( isset( $row['name'] ) and $row['name'] != '' ) $name = $row['name'];
341    else $name = str_replace( '_', ' ', $file );
342
343    if ( $page['cat'] == 'search' )
344    {
345      $name = replace_search( $name, $_GET['search'] );
346    }
347    // thumbnail url
348    $thumbnail_url = $cat_directory;
349    $thumbnail_url.= 'thumbnail/'.$conf['prefix_thumbnail'];
350    $thumbnail_url.= $file.'.'.$row['tn_ext'];
351    // message in title for the thumbnail
352    $thumbnail_title = $row['file'];
353    if ( $row['filesize'] == '' )
354      $poids = floor( filesize( $cat_directory.$row['file'] ) / 1024 );
355    else
356      $poids = $row['filesize'];
357    $thumbnail_title .= ' : '.$poids.' KB';
358    // url link on picture.php page
359    $url_link = './picture.php?cat='.$page['cat'];
360    $url_link.= '&amp;image_id='.$row['id'];
361    if ( $page['cat'] == 'search' )
362    {
363      $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
364    }
365    // date of availability for creation icon
366    list( $year,$month,$day ) = explode( '-', $row['date_available'] );
367    $date = mktime( 0, 0, 0, $month, $day, $year );
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 ),
384
385          'U_IMG_LINK'=>add_session_id( $url_link )
386          ));
387         
388    if ( $conf['show_comments'] && $user['show_nb_comments'] )
389    {
390      $query = 'SELECT COUNT(*) AS nb_comments';
391      $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$row['id'];
392      $query.= " AND validated = 'true'";
393      $query.= ';';
394      $row = mysql_fetch_array( mysql_query( $query ) );
395      $template->assign_block_vars( 'thumbnails.line.thumbnail.nb_comments', 
396            array('NB_COMMENTS'=>$row['nb_comments']) );
397    }
398  }
399}
400//-------------------------------------------------------------- empty category
401else
402{
403  $subcats=array();
404  if (isset($page['cat'])) $subcats = get_non_empty_subcat_ids( $page['cat'] );
405  else                     $subcats = get_non_empty_subcat_ids( '' );
406  $cell_number = 0;
407  $i = 0;
408 
409  $template->assign_block_vars('thumbnails', array());
410 
411  foreach ( $subcats as $subcat_id => $non_empty_id ) 
412  {
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'];
417    $name.= '</span> ]';
418
419    // searching the representative picture of the category
420    $query = 'SELECT representative_picture_id';
421    $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$non_empty_id;
422    $query.= ';';
423    $row = mysql_fetch_array( mysql_query( $query ) );
424   
425    $query = 'SELECT file,tn_ext,storage_category_id';
426    $query.= ' FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE;
427    $query.= ' WHERE category_id = '.$non_empty_id;
428    $query.= ' AND id = image_id';
429    // if the category has a representative picture, this is its thumbnail
430    // that will be displayed !
431    if ( isset( $row['representative_picture_id'] ) )
432      $query.= ' AND id = '.$row['representative_picture_id'];
433    else
434      $query.= ' ORDER BY RAND()';
435    $query.= ' LIMIT 0,1';
436    $query.= ';';
437    $image_result = mysql_query( $query );
438    $image_row    = mysql_fetch_array( $image_result );
439
440    $file = get_filename_wo_extension( $image_row['file'] );
441
442    // creating links for thumbnail and associated category
443    $thumbnail_link = get_complete_dir( $image_row['storage_category_id'] );
444    $thumbnail_link.= 'thumbnail/'.$conf['prefix_thumbnail'];
445    $thumbnail_link.= $file.'.'.$image_row['tn_ext'];
446
447    $thumbnail_title = $lang['hint_category'];
448
449    $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$subcat_id;
450
451    $date = $page['plain_structure'][$subcat_id]['date_last'];
452
453    // sending vars to display
454        if (!$cell_number && $i < count( $subcats ))
455    {
456      $template->assign_block_vars('thumbnails.line', array());
457      $cell_number = 0;
458          $i++;
459    }
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          )); 
471  }
472}
473//------------------------------------------------------- category informations
474if ( isset ( $page['cat'] ) )
475{
476  $cat_name='';
477  // total number of pictures in the category
478  if ( is_numeric( $page['cat'] ) )
479  {
480    $cat_name=get_cat_display_name( $page['cat_name'],' - ','font-style:italic;' );
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    {
486      $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
487          $template->assign_block_vars('upload',array('U_UPLOAD'=>add_session_id( $url )));
488    }
489  }
490  else
491  {
492    $cat_name= $page['title'];
493  }
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  }
509}
510//------------------------------------------------------------ log informations
511pwg_log( 'category', $page['title'] );
512mysql_close();
513
514$template->pparse('category');
515include(PHPWG_ROOT_PATH.'include/page_tail.php');
516?>
Note: See TracBrowser for help on using the repository browser.