source: trunk/category.php @ 507

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

add rating feature

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 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-08-30 22:00:46 +0000 (Mon, 30 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 507 $
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//-------------------------------------------------------------- initialization
49// detection of the start picture to display
50if ( !isset( $_GET['start'] )
51     or !is_numeric( $_GET['start'] )
52     or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
53  $page['start'] = 0;
54else
55  $page['start'] = $_GET['start'];
56
57initialize_category();
58
59// creation of the array containing the cat ids to expand in the menu
60// $page['tab_expand'] contains an array with the category ids
61// $page['expand'] contains the string to display in URL with comma
62$page['tab_expand'] = array();
63if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
64{
65  // the category displayed (in the URL cat=23) must be seen in the menu ->
66  // parent categories must be expanded
67  $uppercats = explode( ',', $page['uppercats'] );
68  foreach ( $uppercats as $uppercat ) {
69    array_push( $page['tab_expand'], $uppercat );
70  }
71}
72// in case of expanding all authorized cats $page['tab_expand'] is empty
73if ( $user['expand'] )
74{
75  $page['tab_expand'] = array();
76}
77
78// Sometimes, a "num" is provided in the URL. It is the number
79// of the picture to show. This picture must be in the thumbnails page.
80// We have to find the right $page['start'] that show the num picture
81// in this category
82if ( isset( $_GET['num'] )
83     and is_numeric( $_GET['num'] )
84     and $_GET['num'] >= 0 )
85{
86  $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] );
87  $page['start']*= $user['nb_image_page'];
88}
89// creating the structure of the categories (useful for displaying the menu)
90// creating the plain structure : array of all the available categories and
91// their relative informations, see the definition of the function
92// get_user_plain_structure for further details.
93$page['plain_structure'] = get_user_plain_structure();
94$page['structure'] = create_user_structure( '' );
95$page['structure'] = update_structure( $page['structure'] );
96//----------------------------------------------------- template initialization
97//
98// Start output of page
99//
100$title = $page['title'];
101include(PHPWG_ROOT_PATH.'include/page_header.php');
102
103$template->set_filenames( array('category'=>'category.tpl') );
104
105//-------------------------------------------------------------- category title
106if ( !isset( $page['title'] ) )
107{
108  $page['title'] = $lang['no_category'];
109}
110$template_title = $page['title'];
111if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 )
112{
113  $template_title.= ' ['.$page['cat_nb_images'].']';
114}
115
116$icon_recent = get_icon(date('Y-m-d'));
117
118$page['menu'] = '';
119foreach ($page['structure'] as $category)
120{
121  $page['menu'].= get_html_menu_category($category);
122}
123
124$template->assign_vars(array(
125  'NB_PICTURE' => count_user_total_images(),
126  'TITLE' => $template_title,
127  'USERNAME' => $user['username'],
128  'TOP_NUMBER'=>$conf['top_number'],
129  'MENU_CATEGORIES_CONTENT'=>$page['menu'],
130
131  'L_CATEGORIES' => $lang['categories'],
132  'L_HINT_CATEGORY' => $lang['hint_category'],
133  'L_SUBCAT' => $lang['sub-cat'],
134  'L_IMG_AVAILABLE' => $lang['images_available'],
135  'L_TOTAL' => $lang['total'],
136  'L_FAVORITE_HINT' => $lang['favorite_cat_hint'],
137  'L_FAVORITE' => $lang['favorite_cat'],
138  'L_SPECIAL_CATEGORIES' => $lang['special_categories'],
139  'L_MOST_VISITED_HINT' => $lang['most_visited_cat_hint'],
140  'L_MOST_VISITED' => $lang['most_visited_cat'],
141  'L_BEST_RATED_HINT' => $lang['best_rated_cat_hint'],
142  'L_BEST_RATED' => $lang['best_rated_cat'],
143  'L_RECENT_PICS_HINT' => $lang['recent_pics_cat_hint'],
144  'L_RECENT_PICS' => $lang['recent_pics_cat'],
145  'L_RECENT_CATS_HINT' => $lang['recent_cats_cat_hint'],
146  'L_RECENT_CATS' => $lang['recent_cats_cat'],
147  'L_CALENDAR' => $lang['calendar'],
148  'L_CALENDAR_HINT' => $lang['calendar_hint'],
149  'L_SUMMARY' => $lang['title_menu'],
150  'L_UPLOAD' => $lang['upload_picture'],
151  'L_COMMENT' => $lang['comments'],
152  'L_IDENTIFY' => $lang['ident_title'],
153  'L_SUBMIT' => $lang['menu_login'],
154  'L_USERNAME' => $lang['login'],
155  'L_PASSWORD' => $lang['password'],
156  'L_HELLO' => $lang['hello'],
157  'L_LOGOUT' => $lang['logout'],
158  'L_ADMIN' => $lang['admin'],
159  'L_ADMIN_HINT' => $lang['hint_admin'],
160  'L_PROFILE' => $lang['customize'],
161  'L_PROFILE_HINT' => $lang['hint_customize'],
162 
163  'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ),
164 
165  'T_COLLAPSED' => $user['lien_collapsed'],
166  'T_RECENT' => $icon_recent,
167
168  'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ),
169  'U_FAVORITE' => add_session_id( PHPWG_ROOT_PATH.'category.php?cat=fav' ),
170  'U_MOST_VISITED'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=most_visited' ),
171  'U_BEST_RATED'=>add_session_id(PHPWG_ROOT_PATH.'category.php?cat=best_rated'),
172  'U_RECENT_PICS'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent_pics' ),
173  'U_RECENT_CATS'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent_cats' ),
174  'U_CALENDAR'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=calendar' ),
175  'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout',
176  'U_ADMIN'=>add_session_id( PHPWG_ROOT_PATH.'admin.php' ),
177  'U_PROFILE'=>add_session_id(PHPWG_ROOT_PATH.'profile.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ))
178  )
179);
180
181// authentification mode management
182if ( !$user['is_the_guest'] )
183{
184  // searching the number of favorite picture
185  $query = 'SELECT COUNT(*) AS count';
186  $query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';';
187  $result = mysql_query( $query );
188  $row = mysql_fetch_array( $result );
189  $template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) );
190  $template->assign_block_vars('username', array());
191}
192//--------------------------------------------------------------------- summary
193
194if ( !$user['is_the_guest'] )
195{
196  $template->assign_block_vars('logout',array());
197  // administration link
198  if ( $user['status'] == 'admin' )
199  {
200    $template->assign_block_vars('logout.admin', array());
201  }
202}
203else
204{
205  $template->assign_block_vars('login',array());
206}
207
208// search link
209$template->assign_block_vars('summary', array(
210'TITLE'=>$lang['hint_search'],
211'NAME'=>$lang['search'],
212'U_SUMMARY'=>add_session_id( 'search.php' ),
213));
214
215// comments link
216$template->assign_block_vars('summary', array(
217'TITLE'=>$lang['hint_comments'],
218'NAME'=>$lang['comments'],
219'U_SUMMARY'=>add_session_id( 'comments.php' ),
220));
221
222// about link
223$template->assign_block_vars('summary', array(
224'TITLE'=>$lang['hint_about'],
225'NAME'=>$lang['about'],
226'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] ) )
227));
228
229//------------------------------------------------------ main part : thumbnails
230if (isset($page['cat'])
231    and ((is_numeric($page['cat']) and $page['cat_nb_images'] != 0)
232         or $page['cat'] == 'search'
233         or $page['cat'] == 'most_visited'
234         or $page['cat'] == 'recent_pics'
235         or $page['cat'] == 'best_rated'))
236{
237  include(PHPWG_ROOT_PATH.'include/category_default.inc.php');
238}
239elseif (isset($page['cat']) and $page['cat'] == 'calendar')
240{
241  include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php');
242}
243elseif (isset($page['cat']) and $page['cat'] == 'recent_cats')
244{
245  include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php');
246}
247else
248{
249  include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php');
250}
251//------------------------------------------------------- category informations
252if ( isset ( $page['cat'] ) )
253{
254  // upload a picture in the category
255  if ( is_numeric( $page['cat'] )
256       and $page['cat_site_id'] == 1
257       and $conf['upload_available']
258       and $page['cat_uploadable'] )
259  {
260    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
261    $template->assign_block_vars(
262      'upload',
263      array('U_UPLOAD'=>add_session_id( $url ))
264      );
265  }
266
267  if ( $page['navigation_bar'] != ''
268       or ( isset( $page['comment'] ) and $page['comment'] != '' ) )
269  {
270    $template->assign_block_vars('cat_infos',array());
271  }
272 
273  // navigation bar
274  if ( $page['navigation_bar'] != '' )
275  { 
276    $template->assign_block_vars(
277      'cat_infos.navigation',
278      array('NAV_BAR' => $page['navigation_bar'])
279      );
280  }
281  // category comment
282  if ( isset( $page['comment'] ) and $page['comment'] != '' )
283  {
284    $template->assign_block_vars(
285      'cat_infos.comment',
286      array('COMMENTS' => $page['comment'])
287      );
288  }
289}
290//------------------------------------------------------------ log informations
291pwg_log( 'category', $page['title'] );
292mysql_close();
293
294$template->pparse('category');
295include(PHPWG_ROOT_PATH.'include/page_tail.php');
296?>
Note: See TracBrowser for help on using the repository browser.