1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-01-07 13:10:44 +0000 (Sat, 07 Jan 2006) $ |
---|
10 | // | last modifier : $Author: nikrou $ |
---|
11 | // | revision : $Revision: 1000 $ |
---|
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 |
---|
29 | define('PHPWG_ROOT_PATH','./'); |
---|
30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
31 | //---------------------------------------------------------------------- logout |
---|
32 | if ( 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 |
---|
42 | if (isset($_GET['cat'])) |
---|
43 | { |
---|
44 | check_cat_id($_GET['cat']); |
---|
45 | } |
---|
46 | check_login_authorization(); |
---|
47 | if (isset($page['cat']) and is_numeric($page['cat'])) |
---|
48 | { |
---|
49 | check_restrictions($page['cat']); |
---|
50 | } |
---|
51 | //-------------------------------------------------------------- initialization |
---|
52 | // detection of the start picture to display |
---|
53 | if ( !isset( $_GET['start'] ) |
---|
54 | or !is_numeric( $_GET['start'] ) |
---|
55 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
56 | { |
---|
57 | $page['start'] = 0; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | $page['start'] = $_GET['start']; |
---|
62 | } |
---|
63 | |
---|
64 | // Sometimes, a "num" is provided in the URL. It is the number |
---|
65 | // of the picture to show. This picture must be in the thumbnails page. |
---|
66 | // We have to find the right $page['start'] that show the num picture |
---|
67 | // in this category |
---|
68 | if ( isset( $_GET['num'] ) |
---|
69 | and is_numeric( $_GET['num'] ) |
---|
70 | and $_GET['num'] >= 0 ) |
---|
71 | { |
---|
72 | $page['start'] = floor( $_GET['num'] / $user['nb_image_page'] ); |
---|
73 | $page['start']*= $user['nb_image_page']; |
---|
74 | } |
---|
75 | |
---|
76 | initialize_category(); |
---|
77 | |
---|
78 | // caddie filling :-) |
---|
79 | if (isset($_GET['caddie'])) |
---|
80 | { |
---|
81 | // include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
82 | |
---|
83 | $query = ' |
---|
84 | SELECT DISTINCT(id) |
---|
85 | FROM '.IMAGES_TABLE.' AS i |
---|
86 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id |
---|
87 | '.$page['where'].' |
---|
88 | ;'; |
---|
89 | fill_caddie(array_from_query($query, 'id')); |
---|
90 | } |
---|
91 | |
---|
92 | // creation of the array containing the cat ids to expand in the menu |
---|
93 | // $page['tab_expand'] contains an array with the category ids |
---|
94 | // $page['expand'] contains the string to display in URL with comma |
---|
95 | $page['tab_expand'] = array(); |
---|
96 | if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) |
---|
97 | { |
---|
98 | // the category displayed (in the URL cat=23) must be seen in the menu -> |
---|
99 | // parent categories must be expanded |
---|
100 | $uppercats = explode( ',', $page['uppercats'] ); |
---|
101 | foreach ( $uppercats as $uppercat ) { |
---|
102 | array_push( $page['tab_expand'], $uppercat ); |
---|
103 | } |
---|
104 | } |
---|
105 | // in case of expanding all authorized cats $page['tab_expand'] is empty |
---|
106 | if ( $user['expand'] ) |
---|
107 | { |
---|
108 | $page['tab_expand'] = array(); |
---|
109 | } |
---|
110 | //----------------------------------------------------- template initialization |
---|
111 | // |
---|
112 | // Start output of page |
---|
113 | // |
---|
114 | $title = $page['title']; |
---|
115 | $page['body_id'] = 'theCategoryPage'; |
---|
116 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
117 | |
---|
118 | $template->set_filenames( array('category'=>'category.tpl') ); |
---|
119 | //-------------------------------------------------------------- category title |
---|
120 | if (isset($page['cat']) and is_numeric($page['cat'])) |
---|
121 | { |
---|
122 | $template_title = get_cat_display_name($page['cat_name'], |
---|
123 | 'category.php?cat=', |
---|
124 | false); |
---|
125 | } |
---|
126 | else |
---|
127 | { |
---|
128 | $template_title = $page['title']; |
---|
129 | } |
---|
130 | |
---|
131 | if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 ) |
---|
132 | { |
---|
133 | $template_title.= ' ['.$page['cat_nb_images'].']'; |
---|
134 | } |
---|
135 | |
---|
136 | $icon_recent = get_icon(date('Y-m-d')); |
---|
137 | |
---|
138 | $template->assign_vars( |
---|
139 | array( |
---|
140 | 'NB_PICTURE' => count_user_total_images(), |
---|
141 | 'TITLE' => $template_title, |
---|
142 | 'USERNAME' => $user['username'], |
---|
143 | 'TOP_NUMBER'=>$conf['top_number'], |
---|
144 | 'MENU_CATEGORIES_CONTENT'=>get_categories_menu(), |
---|
145 | |
---|
146 | 'L_CATEGORIES' => $lang['categories'], |
---|
147 | 'L_HINT_CATEGORY' => $lang['hint_category'], |
---|
148 | 'L_SUBCAT' => $lang['sub-cat'], |
---|
149 | 'L_IMG_AVAILABLE' => $lang['images_available'], |
---|
150 | 'L_TOTAL' => $lang['total'], |
---|
151 | 'L_SPECIAL_CATEGORIES' => $lang['special_categories'], |
---|
152 | 'L_SUMMARY' => $lang['title_menu'], |
---|
153 | 'L_UPLOAD' => $lang['upload_picture'], |
---|
154 | 'L_COMMENT' => $lang['comments'], |
---|
155 | 'L_IDENTIFY' => $lang['identification'], |
---|
156 | 'L_PASSWORD' => $lang['password'], |
---|
157 | 'L_HELLO' => $lang['hello'], |
---|
158 | 'L_REGISTER' => $lang['ident_register'], |
---|
159 | 'L_LOGOUT' => $lang['logout'], |
---|
160 | 'L_ADMIN' => $lang['admin'], |
---|
161 | 'L_ADMIN_HINT' => $lang['hint_admin'], |
---|
162 | 'L_PROFILE' => $lang['customize'], |
---|
163 | 'L_PROFILE_HINT' => $lang['hint_customize'], |
---|
164 | 'L_REMEMBER_ME' => $lang['remember_me'], |
---|
165 | |
---|
166 | 'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ), |
---|
167 | 'T_RECENT' => $icon_recent, |
---|
168 | |
---|
169 | 'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ), |
---|
170 | 'U_REGISTER' => add_session_id( PHPWG_ROOT_PATH.'register.php' ), |
---|
171 | 'U_LOST_PASSWORD' => add_session_id(PHPWG_ROOT_PATH.'password.php'), |
---|
172 | 'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout', |
---|
173 | 'U_ADMIN'=>add_session_id( PHPWG_ROOT_PATH.'admin.php' ), |
---|
174 | 'U_PROFILE'=>add_session_id(PHPWG_ROOT_PATH.'profile.php') |
---|
175 | ) |
---|
176 | ); |
---|
177 | //-------------------------------------------------------------- external links |
---|
178 | if (count($conf['links']) > 0) |
---|
179 | { |
---|
180 | $template->assign_block_vars('links', array()); |
---|
181 | |
---|
182 | foreach ($conf['links'] as $url => $label) |
---|
183 | { |
---|
184 | $template->assign_block_vars( |
---|
185 | 'links.link', |
---|
186 | array( |
---|
187 | 'URL' => $url, |
---|
188 | 'LABEL' => $label |
---|
189 | )); |
---|
190 | } |
---|
191 | } |
---|
192 | //---------------------------------------------------------- special categories |
---|
193 | // favorites categories |
---|
194 | if ( !$user['is_the_guest'] ) |
---|
195 | { |
---|
196 | $template->assign_block_vars('username', array()); |
---|
197 | |
---|
198 | $template->assign_block_vars( |
---|
199 | 'special_cat', |
---|
200 | array( |
---|
201 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=fav'), |
---|
202 | 'TITLE' => $lang['favorite_cat_hint'], |
---|
203 | 'NAME' => $lang['favorite_cat'] |
---|
204 | )); |
---|
205 | } |
---|
206 | // most visited |
---|
207 | $template->assign_block_vars( |
---|
208 | 'special_cat', |
---|
209 | array( |
---|
210 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=most_visited'), |
---|
211 | 'TITLE' => $lang['most_visited_cat_hint'], |
---|
212 | 'NAME' => $lang['most_visited_cat'] |
---|
213 | )); |
---|
214 | // best rated |
---|
215 | if ($conf['rate']) |
---|
216 | { |
---|
217 | $template->assign_block_vars( |
---|
218 | 'special_cat', |
---|
219 | array( |
---|
220 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=best_rated'), |
---|
221 | 'TITLE' => $lang['best_rated_cat_hint'], |
---|
222 | 'NAME' => $lang['best_rated_cat'] |
---|
223 | ) |
---|
224 | ); |
---|
225 | } |
---|
226 | // random |
---|
227 | $template->assign_block_vars( |
---|
228 | 'special_cat', |
---|
229 | array( |
---|
230 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'random.php'), |
---|
231 | 'TITLE' => $lang['random_cat_hint'], |
---|
232 | 'NAME' => $lang['random_cat'] |
---|
233 | )); |
---|
234 | // recent pics |
---|
235 | $template->assign_block_vars( |
---|
236 | 'special_cat', |
---|
237 | array( |
---|
238 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=recent_pics'), |
---|
239 | 'TITLE' => $lang['recent_pics_cat_hint'], |
---|
240 | 'NAME' => $lang['recent_pics_cat'] |
---|
241 | )); |
---|
242 | // recent cats |
---|
243 | $template->assign_block_vars( |
---|
244 | 'special_cat', |
---|
245 | array( |
---|
246 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=recent_cats'), |
---|
247 | 'TITLE' => $lang['recent_cats_cat_hint'], |
---|
248 | 'NAME' => $lang['recent_cats_cat'] |
---|
249 | )); |
---|
250 | // calendar |
---|
251 | $template->assign_block_vars( |
---|
252 | 'special_cat', |
---|
253 | array( |
---|
254 | 'URL' => add_session_id(PHPWG_ROOT_PATH.'category.php?cat=calendar'), |
---|
255 | 'TITLE' => $lang['calendar_hint'], |
---|
256 | 'NAME' => $lang['calendar'] |
---|
257 | )); |
---|
258 | //--------------------------------------------------------------------- summary |
---|
259 | |
---|
260 | if ($user['is_the_guest']) |
---|
261 | { |
---|
262 | $template->assign_block_vars('register', array()); |
---|
263 | $template->assign_block_vars('login', array()); |
---|
264 | |
---|
265 | $template->assign_block_vars('quickconnect', array()); |
---|
266 | if ($conf['authorize_remembering']) |
---|
267 | { |
---|
268 | $template->assign_block_vars('quickconnect.remember_me', array()); |
---|
269 | } |
---|
270 | } |
---|
271 | else |
---|
272 | { |
---|
273 | $template->assign_block_vars('hello', array()); |
---|
274 | $template->assign_block_vars('profile', array()); |
---|
275 | |
---|
276 | // the logout link has no meaning with Apache authentication : it is not |
---|
277 | // possible to logout with this kind of authentication. |
---|
278 | if (!$conf['apache_authentication']) |
---|
279 | { |
---|
280 | $template->assign_block_vars('logout', array()); |
---|
281 | } |
---|
282 | |
---|
283 | if ('admin' == $user['status']) |
---|
284 | { |
---|
285 | $template->assign_block_vars('admin', array()); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | // search link |
---|
290 | $template->assign_block_vars('summary', array( |
---|
291 | 'TITLE'=>$lang['hint_search'], |
---|
292 | 'NAME'=>$lang['search'], |
---|
293 | 'U_SUMMARY'=>add_session_id( 'search.php' ), |
---|
294 | )); |
---|
295 | |
---|
296 | // comments link |
---|
297 | $template->assign_block_vars('summary', array( |
---|
298 | 'TITLE'=>$lang['hint_comments'], |
---|
299 | 'NAME'=>$lang['comments'], |
---|
300 | 'U_SUMMARY'=>add_session_id( 'comments.php' ), |
---|
301 | )); |
---|
302 | |
---|
303 | // about link |
---|
304 | $template->assign_block_vars('summary', array( |
---|
305 | 'TITLE'=>$lang['about_page_title'], |
---|
306 | 'NAME'=>$lang['About'], |
---|
307 | 'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) ) |
---|
308 | )); |
---|
309 | |
---|
310 | // notification |
---|
311 | $template->assign_block_vars( |
---|
312 | 'summary', |
---|
313 | array( |
---|
314 | 'TITLE'=>l10n('notification'), |
---|
315 | 'NAME'=>l10n('Notification'), |
---|
316 | 'U_SUMMARY'=>add_session_id(PHPWG_ROOT_PATH.'notification.php') |
---|
317 | )); |
---|
318 | |
---|
319 | if (isset($page['cat']) |
---|
320 | and is_numeric($page['cat']) |
---|
321 | and 'admin' == $user['status']) |
---|
322 | { |
---|
323 | $template->assign_block_vars( |
---|
324 | 'edit', |
---|
325 | array( |
---|
326 | 'URL' => |
---|
327 | add_session_id( |
---|
328 | PHPWG_ROOT_PATH.'admin.php?page=cat_modify' |
---|
329 | .'&cat_id='.$page['cat'] |
---|
330 | ) |
---|
331 | ) |
---|
332 | ); |
---|
333 | } |
---|
334 | |
---|
335 | //------------------------------------------------------ main part : thumbnails |
---|
336 | if (isset($page['cat']) |
---|
337 | and ((is_numeric($page['cat']) and $page['cat_nb_images'] != 0) |
---|
338 | or in_array($page['cat'], |
---|
339 | array('search' |
---|
340 | ,'most_visited' |
---|
341 | ,'recent_pics' |
---|
342 | ,'best_rated' |
---|
343 | ,'list' |
---|
344 | ,'fav' |
---|
345 | )))) |
---|
346 | { |
---|
347 | include(PHPWG_ROOT_PATH.'include/category_default.inc.php'); |
---|
348 | |
---|
349 | if ('admin' == $user['status']) |
---|
350 | { |
---|
351 | $template->assign_block_vars( |
---|
352 | 'caddie', |
---|
353 | array( |
---|
354 | 'URL' => |
---|
355 | add_session_id( |
---|
356 | PHPWG_ROOT_PATH.'category.php' |
---|
357 | .get_query_string_diff(array('caddie')).'&caddie=1') |
---|
358 | ) |
---|
359 | ); |
---|
360 | } |
---|
361 | } |
---|
362 | elseif (isset($page['cat']) and $page['cat'] == 'calendar') |
---|
363 | { |
---|
364 | include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php'); |
---|
365 | } |
---|
366 | elseif (isset($page['cat']) and $page['cat'] == 'recent_cats') |
---|
367 | { |
---|
368 | include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php'); |
---|
369 | } |
---|
370 | else |
---|
371 | { |
---|
372 | include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php'); |
---|
373 | } |
---|
374 | //------------------------------------------------------- category informations |
---|
375 | if ( isset ( $page['cat'] ) ) |
---|
376 | { |
---|
377 | // upload a picture in the category |
---|
378 | if (is_numeric($page['cat']) |
---|
379 | and $page['cat_site_id'] == 1 |
---|
380 | and $page['cat_dir'] != '' |
---|
381 | and $page['cat_uploadable']) |
---|
382 | { |
---|
383 | $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat']; |
---|
384 | $template->assign_block_vars( |
---|
385 | 'upload', |
---|
386 | array('U_UPLOAD'=>add_session_id( $url )) |
---|
387 | ); |
---|
388 | } |
---|
389 | |
---|
390 | if ( $page['navigation_bar'] != '' |
---|
391 | or ( isset( $page['comment'] ) and $page['comment'] != '' ) ) |
---|
392 | { |
---|
393 | $template->assign_block_vars('cat_infos',array()); |
---|
394 | } |
---|
395 | |
---|
396 | // navigation bar |
---|
397 | if ( $page['navigation_bar'] != '' ) |
---|
398 | { |
---|
399 | $template->assign_block_vars( |
---|
400 | 'cat_infos.navigation', |
---|
401 | array('NAV_BAR' => $page['navigation_bar']) |
---|
402 | ); |
---|
403 | } |
---|
404 | // category comment |
---|
405 | if ( isset( $page['comment'] ) and $page['comment'] != '' ) |
---|
406 | { |
---|
407 | $template->assign_block_vars( |
---|
408 | 'cat_infos.comment', |
---|
409 | array('COMMENTS' => $page['comment']) |
---|
410 | ); |
---|
411 | } |
---|
412 | } |
---|
413 | //------------------------------------------------------------ log informations |
---|
414 | pwg_log( 'category', $page['title'] ); |
---|
415 | |
---|
416 | $template->parse('category'); |
---|
417 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
418 | ?> |
---|