source: trunk/category.php @ 381

Last change on this file since 381 was 375, checked in by gweltas, 20 years ago

New default template - User side

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