source: trunk/category.php @ 394

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