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-06 09:42:07 +0000 (Fri, 06 Aug 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 478 $ |
---|
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'] ) ) check_cat_id( $_GET['cat'] ); |
---|
43 | check_login_authorization(); |
---|
44 | if ( 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 |
---|
50 | if ( !isset( $_GET['start'] ) |
---|
51 | or !is_numeric( $_GET['start'] ) |
---|
52 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
53 | $page['start'] = 0; |
---|
54 | else |
---|
55 | $page['start'] = $_GET['start']; |
---|
56 | |
---|
57 | initialize_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(); |
---|
63 | if ( 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 |
---|
73 | if ( $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 |
---|
82 | if ( 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']; |
---|
101 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
102 | |
---|
103 | $template->set_filenames( array('category'=>'category.tpl') ); |
---|
104 | |
---|
105 | //-------------------------------------------------------------- category title |
---|
106 | if ( !isset( $page['title'] ) ) |
---|
107 | { |
---|
108 | $page['title'] = $lang['no_category']; |
---|
109 | } |
---|
110 | $template_title = $page['title']; |
---|
111 | if ( 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'] = ''; |
---|
119 | foreach ($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_VISITED'=>$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_RECENT_PICS_HINT' => $lang['recent_pics_cat_hint'], |
---|
142 | 'L_RECENT_PICS' => $lang['recent_pics_cat'], |
---|
143 | 'L_RECENT_CATS_HINT' => $lang['recent_cats_cat_hint'], |
---|
144 | 'L_RECENT_CATS' => $lang['recent_cats_cat'], |
---|
145 | 'L_CALENDAR' => $lang['calendar'], |
---|
146 | 'L_CALENDAR_HINT' => $lang['calendar_hint'], |
---|
147 | 'L_SUMMARY' => $lang['title_menu'], |
---|
148 | 'L_UPLOAD' => $lang['upload_picture'], |
---|
149 | 'L_COMMENT' => $lang['comments'], |
---|
150 | 'L_IDENTIFY' => $lang['ident_title'], |
---|
151 | 'L_SUBMIT' => $lang['menu_login'], |
---|
152 | 'L_USERNAME' => $lang['login'], |
---|
153 | 'L_PASSWORD' => $lang['password'], |
---|
154 | 'L_HELLO' => $lang['hello'], |
---|
155 | 'L_LOGOUT' => $lang['logout'], |
---|
156 | 'L_ADMIN' => $lang['admin'], |
---|
157 | 'L_ADMIN_HINT' => $lang['hint_admin'], |
---|
158 | 'L_PROFILE' => $lang['customize'], |
---|
159 | 'L_PROFILE_HINT' => $lang['hint_customize'], |
---|
160 | |
---|
161 | 'F_IDENTIFY' => add_session_id( PHPWG_ROOT_PATH.'identification.php' ), |
---|
162 | |
---|
163 | 'T_COLLAPSED' => $user['lien_collapsed'], |
---|
164 | 'T_RECENT' => $icon_recent, |
---|
165 | |
---|
166 | 'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' ), |
---|
167 | 'U_FAVORITE' => add_session_id( PHPWG_ROOT_PATH.'category.php?cat=fav' ), |
---|
168 | 'U_MOST_VISITED'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=most_visited' ), |
---|
169 | 'U_RECENT_PICS'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent_pics' ), |
---|
170 | 'U_RECENT_CATS'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=recent_cats' ), |
---|
171 | 'U_CALENDAR'=>add_session_id( PHPWG_ROOT_PATH.'category.php?cat=calendar' ), |
---|
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?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] )) |
---|
175 | ) |
---|
176 | ); |
---|
177 | |
---|
178 | // authentification mode management |
---|
179 | if ( !$user['is_the_guest'] ) |
---|
180 | { |
---|
181 | // searching the number of favorite picture |
---|
182 | $query = 'SELECT COUNT(*) AS count'; |
---|
183 | $query.= ' FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';'; |
---|
184 | $result = mysql_query( $query ); |
---|
185 | $row = mysql_fetch_array( $result ); |
---|
186 | $template->assign_block_vars('favorites', array ('NB_FAV'=>$row['count']) ); |
---|
187 | $template->assign_block_vars('username', array()); |
---|
188 | } |
---|
189 | //--------------------------------------------------------------------- summary |
---|
190 | |
---|
191 | if ( !$user['is_the_guest'] ) |
---|
192 | { |
---|
193 | $template->assign_block_vars('logout',array()); |
---|
194 | // administration link |
---|
195 | if ( $user['status'] == 'admin' ) |
---|
196 | { |
---|
197 | $template->assign_block_vars('logout.admin', array()); |
---|
198 | } |
---|
199 | } |
---|
200 | else |
---|
201 | { |
---|
202 | $template->assign_block_vars('login',array()); |
---|
203 | } |
---|
204 | |
---|
205 | // search link |
---|
206 | $template->assign_block_vars('summary', array( |
---|
207 | 'TITLE'=>$lang['hint_search'], |
---|
208 | 'NAME'=>$lang['search'], |
---|
209 | 'U_SUMMARY'=>add_session_id( 'search.php' ), |
---|
210 | )); |
---|
211 | |
---|
212 | // comments link |
---|
213 | $template->assign_block_vars('summary', array( |
---|
214 | 'TITLE'=>$lang['hint_comments'], |
---|
215 | 'NAME'=>$lang['comments'], |
---|
216 | 'U_SUMMARY'=>add_session_id( 'comments.php' ), |
---|
217 | )); |
---|
218 | |
---|
219 | // about link |
---|
220 | $template->assign_block_vars('summary', array( |
---|
221 | 'TITLE'=>$lang['hint_about'], |
---|
222 | 'NAME'=>$lang['about'], |
---|
223 | 'U_SUMMARY'=>add_session_id( 'about.php?'.str_replace( '&', '&', $_SERVER['QUERY_STRING'] ) ) |
---|
224 | )); |
---|
225 | |
---|
226 | //------------------------------------------------------ main part : thumbnails |
---|
227 | if (isset($page['cat']) |
---|
228 | and ((is_numeric($page['cat']) and $page['cat_nb_images'] != 0) |
---|
229 | or $page['cat'] == 'search' |
---|
230 | or $page['cat'] == 'most_visited' |
---|
231 | or $page['cat'] == 'recent_pics')) |
---|
232 | { |
---|
233 | include(PHPWG_ROOT_PATH.'include/category_default.inc.php'); |
---|
234 | } |
---|
235 | elseif (isset($page['cat']) and $page['cat'] == 'calendar') |
---|
236 | { |
---|
237 | include(PHPWG_ROOT_PATH.'include/category_calendar.inc.php'); |
---|
238 | } |
---|
239 | elseif (isset($page['cat']) and $page['cat'] == 'recent_cats') |
---|
240 | { |
---|
241 | include(PHPWG_ROOT_PATH.'include/category_recent_cats.inc.php'); |
---|
242 | } |
---|
243 | else |
---|
244 | { |
---|
245 | include(PHPWG_ROOT_PATH.'include/category_subcats.inc.php'); |
---|
246 | } |
---|
247 | //------------------------------------------------------- category informations |
---|
248 | if ( isset ( $page['cat'] ) ) |
---|
249 | { |
---|
250 | // upload a picture in the category |
---|
251 | if ( is_numeric( $page['cat'] ) |
---|
252 | and $page['cat_site_id'] == 1 |
---|
253 | and $conf['upload_available'] |
---|
254 | and $page['cat_uploadable'] ) |
---|
255 | { |
---|
256 | $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat']; |
---|
257 | $template->assign_block_vars( |
---|
258 | 'upload', |
---|
259 | array('U_UPLOAD'=>add_session_id( $url )) |
---|
260 | ); |
---|
261 | } |
---|
262 | |
---|
263 | if ( $page['navigation_bar'] != '' |
---|
264 | or ( isset( $page['comment'] ) and $page['comment'] != '' ) ) |
---|
265 | { |
---|
266 | $template->assign_block_vars('cat_infos',array()); |
---|
267 | } |
---|
268 | |
---|
269 | // navigation bar |
---|
270 | if ( $page['navigation_bar'] != '' ) |
---|
271 | { |
---|
272 | $template->assign_block_vars( |
---|
273 | 'cat_infos.navigation', |
---|
274 | array('NAV_BAR' => $page['navigation_bar']) |
---|
275 | ); |
---|
276 | } |
---|
277 | // category comment |
---|
278 | if ( isset( $page['comment'] ) and $page['comment'] != '' ) |
---|
279 | { |
---|
280 | $template->assign_block_vars( |
---|
281 | 'cat_infos.comment', |
---|
282 | array('COMMENTS' => $page['comment']) |
---|
283 | ); |
---|
284 | } |
---|
285 | } |
---|
286 | //------------------------------------------------------------ log informations |
---|
287 | pwg_log( 'category', $page['title'] ); |
---|
288 | mysql_close(); |
---|
289 | |
---|
290 | $template->pparse('category'); |
---|
291 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
292 | ?> |
---|