1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | //--------------------------------------------------------------------- include |
---|
25 | define('PHPWG_ROOT_PATH','./'); |
---|
26 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
27 | include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); |
---|
28 | |
---|
29 | // Check Access and exit when user status is not ok |
---|
30 | check_status(ACCESS_GUEST); |
---|
31 | |
---|
32 | |
---|
33 | // access authorization check |
---|
34 | if (isset($page['category'])) |
---|
35 | { |
---|
36 | check_restrictions($page['category']['id']); |
---|
37 | } |
---|
38 | if ($page['start']>0 && $page['start']>=count($page['items'])) |
---|
39 | { |
---|
40 | page_not_found('', duplicate_index_url(array('start'=>0))); |
---|
41 | } |
---|
42 | |
---|
43 | trigger_action('loc_begin_index'); |
---|
44 | |
---|
45 | //---------------------------------------------- change of image display order |
---|
46 | if (isset($_GET['image_order'])) |
---|
47 | { |
---|
48 | if ( (int)$_GET['image_order'] > 0) |
---|
49 | { |
---|
50 | pwg_set_session_var('image_order', (int)$_GET['image_order']); |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | pwg_unset_session_var('image_order'); |
---|
55 | } |
---|
56 | redirect( |
---|
57 | duplicate_index_url( |
---|
58 | array(), // nothing to redefine |
---|
59 | array('start') // changing display order goes back to section first page |
---|
60 | ) |
---|
61 | ); |
---|
62 | } |
---|
63 | if (isset($_GET['display'])) |
---|
64 | { |
---|
65 | $page['meta_robots']['noindex']=1; |
---|
66 | if (array_key_exists($_GET['display'], ImageStdParams::get_defined_type_map())) |
---|
67 | { |
---|
68 | pwg_set_session_var('index_deriv', $_GET['display']); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | //-------------------------------------------------------------- initialization |
---|
73 | // navigation bar |
---|
74 | $page['navigation_bar'] = array(); |
---|
75 | if (count($page['items']) > $page['nb_image_page']) |
---|
76 | { |
---|
77 | $page['navigation_bar'] = create_navigation_bar( |
---|
78 | duplicate_index_url(array(), array('start')), |
---|
79 | count($page['items']), |
---|
80 | $page['start'], |
---|
81 | $page['nb_image_page'], |
---|
82 | true, 'start' |
---|
83 | ); |
---|
84 | } |
---|
85 | |
---|
86 | $template->assign('thumb_navbar', $page['navigation_bar'] ); |
---|
87 | |
---|
88 | // caddie filling :-) |
---|
89 | if (isset($_GET['caddie'])) |
---|
90 | { |
---|
91 | fill_caddie($page['items']); |
---|
92 | redirect(duplicate_index_url()); |
---|
93 | } |
---|
94 | |
---|
95 | if (isset($page['is_homepage']) and $page['is_homepage']) |
---|
96 | { |
---|
97 | $canonical_url = get_gallery_home_url(); |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | $start = $page['nb_image_page'] * round($page['start'] / $page['nb_image_page']); |
---|
102 | if ($start>0 && $start >= count($page['items']) ) |
---|
103 | { |
---|
104 | $start -= $page['nb_image_page']; |
---|
105 | } |
---|
106 | $canonical_url = duplicate_index_url(array('start' => $start)); |
---|
107 | } |
---|
108 | $template->assign('U_CANONICAL', $canonical_url); |
---|
109 | |
---|
110 | //-------------------------------------------------------------- page title |
---|
111 | $title = $page['title']; |
---|
112 | $template_title = $page['section_title']; |
---|
113 | if (count($page['items']) > 0) |
---|
114 | { |
---|
115 | $template_title.= ' ['.count($page['items']).']'; |
---|
116 | } |
---|
117 | $template->assign('TITLE', $template_title); |
---|
118 | |
---|
119 | //-------------------------------------------------------------- menubar |
---|
120 | include( PHPWG_ROOT_PATH.'include/menubar.inc.php'); |
---|
121 | |
---|
122 | $template->set_filename('index', 'index.tpl'); |
---|
123 | |
---|
124 | // +-----------------------------------------------------------------------+ |
---|
125 | // | index page (categories, thumbnails, search, calendar, random, etc.) | |
---|
126 | // +-----------------------------------------------------------------------+ |
---|
127 | if ( empty($page['is_external']) or !$page['is_external'] ) |
---|
128 | { |
---|
129 | //----------------------------------------------------- template initialization |
---|
130 | $page['body_id'] = 'theCategoryPage'; |
---|
131 | |
---|
132 | if (isset($page['flat']) or isset($page['chronology_field'])) |
---|
133 | { |
---|
134 | $template->assign( |
---|
135 | 'U_MODE_NORMAL', |
---|
136 | duplicate_index_url( array(), array('chronology_field', 'start', 'flat') ) |
---|
137 | ); |
---|
138 | } |
---|
139 | |
---|
140 | if ($conf['index_flat_icon'] and !isset($page['flat']) and 'categories' == $page['section']) |
---|
141 | { |
---|
142 | $template->assign( |
---|
143 | 'U_MODE_FLAT', |
---|
144 | duplicate_index_url(array('flat' => ''), array('start', 'chronology_field')) |
---|
145 | ); |
---|
146 | } |
---|
147 | |
---|
148 | if (!isset($page['chronology_field'])) |
---|
149 | { |
---|
150 | $chronology_params = array( |
---|
151 | 'chronology_field' => 'created', |
---|
152 | 'chronology_style' => 'monthly', |
---|
153 | 'chronology_view' => 'list', |
---|
154 | ); |
---|
155 | if ($conf['index_created_date_icon']) |
---|
156 | { |
---|
157 | $template->assign( |
---|
158 | 'U_MODE_CREATED', |
---|
159 | duplicate_index_url( $chronology_params, array('start', 'flat') ) |
---|
160 | ); |
---|
161 | } |
---|
162 | if ($conf['index_posted_date_icon']) |
---|
163 | { |
---|
164 | $chronology_params['chronology_field'] = 'posted'; |
---|
165 | $template->assign( |
---|
166 | 'U_MODE_POSTED', |
---|
167 | duplicate_index_url( $chronology_params, array('start', 'flat') ) |
---|
168 | ); |
---|
169 | } |
---|
170 | } |
---|
171 | else |
---|
172 | { |
---|
173 | if ($page['chronology_field'] == 'created') |
---|
174 | { |
---|
175 | $chronology_field = 'posted'; |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | $chronology_field = 'created'; |
---|
180 | } |
---|
181 | if ($conf['index_'.$chronology_field.'_date_icon']) |
---|
182 | { |
---|
183 | $url = duplicate_index_url( |
---|
184 | array('chronology_field'=>$chronology_field ), |
---|
185 | array('chronology_date', 'start', 'flat') |
---|
186 | ); |
---|
187 | $template->assign( |
---|
188 | 'U_MODE_'.strtoupper($chronology_field), |
---|
189 | $url |
---|
190 | ); |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | if ('search' == $page['section']) |
---|
195 | { |
---|
196 | $template->assign( |
---|
197 | 'U_SEARCH_RULES', |
---|
198 | get_root_url().'search_rules.php?search_id='.$page['search'] |
---|
199 | ); |
---|
200 | } |
---|
201 | |
---|
202 | if (isset($page['category']) and is_admin()) |
---|
203 | { |
---|
204 | $template->assign( |
---|
205 | 'U_EDIT', |
---|
206 | get_root_url().'admin.php?page=album-'.$page['category']['id'] |
---|
207 | ); |
---|
208 | } |
---|
209 | |
---|
210 | if (is_admin() and !empty($page['items'])) |
---|
211 | { |
---|
212 | $template->assign( |
---|
213 | 'U_CADDIE', |
---|
214 | add_url_params(duplicate_index_url(), array('caddie'=>1) ) |
---|
215 | ); |
---|
216 | } |
---|
217 | |
---|
218 | if ( $page['section']=='search' and $page['start']==0 and |
---|
219 | !isset($page['chronology_field']) and isset($page['qsearch_details']) ) |
---|
220 | { |
---|
221 | $template->assign('QUERY_SEARCH', |
---|
222 | htmlspecialchars($page['qsearch_details']['q']) ); |
---|
223 | |
---|
224 | $cats = array_merge( |
---|
225 | (array)@$page['qsearch_details']['matching_cats_no_images'], |
---|
226 | (array)@$page['qsearch_details']['matching_cats'] ); |
---|
227 | if (count($cats)) |
---|
228 | { |
---|
229 | usort($cats, 'name_compare'); |
---|
230 | $hints = array(); |
---|
231 | foreach ( $cats as $cat ) |
---|
232 | { |
---|
233 | $hints[] = get_cat_display_name( array($cat), '', false ); |
---|
234 | } |
---|
235 | $template->assign( 'category_search_results', $hints); |
---|
236 | } |
---|
237 | |
---|
238 | $tags = (array)@$page['qsearch_details']['matching_tags']; |
---|
239 | foreach ( $tags as $tag ) |
---|
240 | { |
---|
241 | $tag['URL'] = make_index_url(array('tags'=>array($tag))); |
---|
242 | $template->append( 'tag_search_results', $tag); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | // image order |
---|
247 | if ( $conf['index_sort_order_input'] |
---|
248 | and count($page['items']) > 0 |
---|
249 | and $page['section'] != 'most_visited' |
---|
250 | and $page['section'] != 'best_rated') |
---|
251 | { |
---|
252 | $preferred_image_orders = get_category_preferred_image_orders(); |
---|
253 | $order_idx = pwg_get_session_var( 'image_order', 0 ); |
---|
254 | |
---|
255 | // get first order field and direction |
---|
256 | $first_order = substr($conf['order_by'], 9); |
---|
257 | if (($pos = strpos($first_order, ',')) !== false) |
---|
258 | { |
---|
259 | $first_order = substr($first_order, 0, $pos); |
---|
260 | } |
---|
261 | $first_order = trim($first_order); |
---|
262 | |
---|
263 | $url = add_url_params( |
---|
264 | duplicate_index_url(), |
---|
265 | array('image_order' => '') |
---|
266 | ); |
---|
267 | $tpl_orders = array(); |
---|
268 | $order_selected = false; |
---|
269 | |
---|
270 | foreach ($preferred_image_orders as $order_id => $order) |
---|
271 | { |
---|
272 | if ($order[2]) |
---|
273 | { |
---|
274 | // force select if the field is the first field of order_by |
---|
275 | if (!$order_selected && $order[1]==$first_order) |
---|
276 | { |
---|
277 | $order_idx = $order_id; |
---|
278 | $order_selected = true; |
---|
279 | } |
---|
280 | |
---|
281 | $tpl_orders[ $order_id ] = array( |
---|
282 | 'DISPLAY' => $order[0], |
---|
283 | 'URL' => $url.$order_id, |
---|
284 | 'SELECTED' => $order_idx==$order_id, |
---|
285 | ); |
---|
286 | } |
---|
287 | } |
---|
288 | |
---|
289 | $tpl_orders[0]['SELECTED'] = !$order_selected; // unselect "Default" if another one is selected |
---|
290 | $template->assign('image_orders', $tpl_orders); |
---|
291 | } |
---|
292 | |
---|
293 | // category comment |
---|
294 | if ($page['start']==0 and !isset($page['chronology_field']) and !empty($page['comment']) ) |
---|
295 | { |
---|
296 | $template->assign('CONTENT_DESCRIPTION', $page['comment'] ); |
---|
297 | } |
---|
298 | |
---|
299 | if ( isset($page['category']['count_categories']) and $page['category']['count_categories']==0 ) |
---|
300 | {// count_categories might be computed by menubar - if the case unassign flat link if no sub albums |
---|
301 | $template->clear_assign('U_MODE_FLAT'); |
---|
302 | } |
---|
303 | |
---|
304 | //------------------------------------------------------ main part : thumbnails |
---|
305 | if ( 0==$page['start'] |
---|
306 | and !isset($page['flat']) |
---|
307 | and !isset($page['chronology_field']) |
---|
308 | and ('recent_cats'==$page['section'] or 'categories'==$page['section']) |
---|
309 | and (!isset($page['category']['count_categories']) or $page['category']['count_categories']>0 ) |
---|
310 | ) |
---|
311 | { |
---|
312 | include(PHPWG_ROOT_PATH.'include/category_cats.inc.php'); |
---|
313 | } |
---|
314 | |
---|
315 | if ( !empty($page['items']) ) |
---|
316 | { |
---|
317 | include(PHPWG_ROOT_PATH.'include/category_default.inc.php'); |
---|
318 | $url = add_url_params( |
---|
319 | duplicate_index_url(), |
---|
320 | array('display' => '') |
---|
321 | ); |
---|
322 | |
---|
323 | $selected_type = $template->get_template_vars('derivative_params')->type; |
---|
324 | $template->clear_assign( 'derivative_params' ); |
---|
325 | $type_map = ImageStdParams::get_defined_type_map(); |
---|
326 | unset($type_map[IMG_XXLARGE], $type_map[IMG_XLARGE]); |
---|
327 | |
---|
328 | foreach($type_map as $params) |
---|
329 | { |
---|
330 | $template->append( |
---|
331 | 'image_derivatives', |
---|
332 | array( |
---|
333 | 'DISPLAY' => l10n($params->type), |
---|
334 | 'URL' => $url.$params->type, |
---|
335 | 'SELECTED' => ($params->type == $selected_type ? true:false), |
---|
336 | ) |
---|
337 | ); |
---|
338 | } |
---|
339 | } |
---|
340 | |
---|
341 | // slideshow |
---|
342 | // execute after init thumbs in order to have all picture informations |
---|
343 | if (!empty($page['cat_slideshow_url'])) |
---|
344 | { |
---|
345 | if (isset($_GET['slideshow'])) |
---|
346 | { |
---|
347 | redirect($page['cat_slideshow_url']); |
---|
348 | } |
---|
349 | elseif ($conf['index_slideshow_icon']) |
---|
350 | { |
---|
351 | $template->assign('U_SLIDESHOW', $page['cat_slideshow_url']); |
---|
352 | } |
---|
353 | } |
---|
354 | } |
---|
355 | |
---|
356 | //------------------------------------------------------------ end |
---|
357 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
358 | trigger_action('loc_end_index'); |
---|
359 | flush_page_messages(); |
---|
360 | $template->parse_index_buttons(); |
---|
361 | $template->pparse('index'); |
---|
362 | |
---|
363 | //------------------------------------------------------------ log informations |
---|
364 | pwg_log(); |
---|
365 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
366 | ?> |
---|