source: trunk/category.php @ 453

Last change on this file since 453 was 453, checked in by z0rglub, 20 years ago

display search results even if no element found

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.5 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-07-26 20:41:11 +0000 (Mon, 26 Jul 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 453 $
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
153if ( !isset( $page['title'] ) )
154{
155  $page['title'] = $lang['no_category'];
156}
157$template_title = $page['title'];
158if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 )
159{
160  $template_title.= ' ['.$page['cat_nb_images'].']';
161}
162
163$icon_recent = get_icon(date('Y-m-d'));
164
165$template->assign_vars(array(
166  'NB_PICTURE' => count_user_total_images(),
167  'TITLE' => $template_title,
168  'USERNAME' => $user['username'],
169  'TOP_VISITED'=>$conf['top_number'],
170
171  'L_CATEGORIES' => $lang['categories'],
172  'L_HINT_CATEGORY' => $lang['hint_category'],
173  'L_SUBCAT' => $lang['sub-cat'],
174  'L_IMG_AVAILABLE' => $lang['images_available'],
175  'L_TOTAL' => $lang['total'],
176  'L_FAVORITE_HINT' => $lang['favorite_cat_hint'],
177  'L_FAVORITE' => $lang['favorite_cat'],
178  'L_SPECIAL_CATEGORIES' => $lang['special_categories'],
179  'L_MOST_VISITED_HINT' => $lang['most_visited_cat_hint'],
180  'L_MOST_VISITED' => $lang['most_visited_cat'],
181  'L_RECENT_PICS_HINT' => $lang['recent_pics_cat_hint'],
182  'L_RECENT_PICS' => $lang['recent_pics_cat'],
183  'L_RECENT_CATS_HINT' => $lang['recent_cats_cat_hint'],
184  'L_RECENT_CATS' => $lang['recent_cats_cat'],
185  'L_CALENDAR' => $lang['calendar'],
186  'L_CALENDAR_HINT' => $lang['calendar_hint'],
187  'L_SUMMARY' => $lang['title_menu'],
188  'L_UPLOAD' => $lang['upload_picture'],
189  'L_COMMENT' => $lang['comments'],
190  'L_IDENTIFY' => $lang['ident_title'],
191  'L_SUBMIT' => $lang['menu_login'],
192  'L_USERNAME' => $lang['login'],
193  'L_PASSWORD' => $lang['password'],
194  'L_HELLO' => $lang['hello'],
195  'L_LOGOUT' => $lang['logout'],
196  'L_ADMIN' => $lang['admin'],
197  'L_ADMIN_HINT' => $lang['hint_admin'],
198  'L_PROFILE' => $lang['customize'],
199  'L_PROFILE_HINT' => $lang['hint_customize'],
200 
201  'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ),
202 
203  'T_COLLAPSED' => $user['lien_collapsed'],
204  'T_RECENT' => $icon_recent,
205
206  'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ),
207  'U_FAVORITE' => add_session_id( PHPWG_ROOT_PATH.'category.php?cat=fav' ),
208  'U_MOST_VISITED'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=most_visited' ),
209  'U_RECENT_PICS'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent_pics' ),
210  'U_RECENT_CATS'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent_cats' ),
211  'U_CALENDAR'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=calendar' ),
212  'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout',
213  'U_ADMIN'=>add_session_id( PHPWG_ROOT_PATH.'admin.php' ),
214  'U_PROFILE'=>add_session_id(PHPWG_ROOT_PATH.'profile.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ))
215  )
216);
217
218foreach ( $page['structure'] as $category ) {
219  // display category is a function relative to the template
220  display_category( $category, '&nbsp;');
221}
222
223// authentification mode management
224if ( !$user['is_the_guest'] )
225{
226  // searching the number of favorite picture
227  $query = 'SELECT COUNT(*) AS count';
228  $query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';';
229  $result = mysql_query( $query );
230  $row = mysql_fetch_array( $result );
231  $template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) );
232  $template->assign_block_vars('username', array());
233}
234//--------------------------------------------------------------------- summary
235
236if ( !$user['is_the_guest'] )
237{
238  $template->assign_block_vars('logout',array());
239  // administration link
240  if ( $user['status'] == 'admin' )
241  {
242    $template->assign_block_vars('logout.admin', array());
243  }
244}
245else
246{
247  $template->assign_block_vars('login',array());
248}
249
250// search link
251$template->assign_block_vars('summary', array(
252'TITLE'=>$lang['hint_search'],
253'NAME'=>$lang['search'],
254'U_SUMMARY'=>add_session_id( 'search.php' ),
255));
256
257// comments link
258$template->assign_block_vars('summary', array(
259'TITLE'=>$lang['hint_comments'],
260'NAME'=>$lang['comments'],
261'U_SUMMARY'=>add_session_id( 'comments.php' ),
262));
263
264// about link
265$template->assign_block_vars('summary', array(
266'TITLE'=>$lang['hint_about'],
267'NAME'=>$lang['about'],
268'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) )
269));
270
271//------------------------------------------------------ main part : thumbnails
272if (isset($page['cat'])
273    and ((is_numeric($page['cat']) and $page['cat_nb_images'] != 0)
274         or $page['cat'] == 'search'))
275{
276  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
277}
278elseif (isset($page['cat']) and $page['cat'] == 'calendar')
279{
280  include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php');
281}
282elseif (isset($page['cat']) and $page['cat'] == 'recent_cats')
283{
284  include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php');
285}
286else
287{
288  include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php');
289}
290//------------------------------------------------------- category informations
291if ( isset ( $page['cat'] ) )
292{
293  // upload a picture in the category
294  if ( is_numeric( $page['cat'] )
295       and $page['cat_site_id'] == 1
296       and $conf['upload_available']
297       and $page['cat_uploadable'] )
298  {
299    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
300    $template->assign_block_vars(
301      'upload',
302      array('U_UPLOAD'=>add_session_id( $url ))
303      );
304  }
305
306  if ( $page['navigation_bar'] != ''
307       or ( isset( $page['comment'] ) and $page['comment'] != '' ) )
308  {
309    $template->assign_block_vars('cat_infos',array());
310  }
311 
312  // navigation bar
313  if ( $page['navigation_bar'] != '' )
314  { 
315    $template->assign_block_vars(
316      'cat_infos.navigation',
317      array('NAV_BAR' => $page['navigation_bar'])
318      );
319  }
320  // category comment
321  if ( isset( $page['comment'] ) and $page['comment'] != '' )
322  {
323    $template->assign_block_vars(
324      'cat_infos.comment',
325      array('COMMENTS' => $page['comment'])
326      );
327  }
328}
329//------------------------------------------------------------ log informations
330pwg_log( 'category', $page['title'] );
331mysql_close();
332
333$template->pparse('category');
334include(PHPWG_ROOT_PATH.'include/page_tail.php');
335?>
Note: See TracBrowser for help on using the repository browser.