source: trunk/category.php @ 422

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