1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 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 | // | PhpWebGallery - a PHP based picture gallery | |
---|
25 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | // | file : $Id: functions_calendar.inc.php 2297 2008-04-04 22:57:23Z plg $ |
---|
28 | // | last update : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $ |
---|
29 | // | last modifier : $Author: plg $ |
---|
30 | // | revision : $Revision: 2297 $ |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | // | This program is free software; you can redistribute it and/or modify | |
---|
33 | // | it under the terms of the GNU General Public License as published by | |
---|
34 | // | the Free Software Foundation | |
---|
35 | // | | |
---|
36 | // | This program is distributed in the hope that it will be useful, but | |
---|
37 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
38 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
39 | // | General Public License for more details. | |
---|
40 | // | | |
---|
41 | // | You should have received a copy of the GNU General Public License | |
---|
42 | // | along with this program; if not, write to the Free Software | |
---|
43 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
44 | // | USA. | |
---|
45 | // +-----------------------------------------------------------------------+ |
---|
46 | |
---|
47 | define('CAL_VIEW_LIST', 'list'); |
---|
48 | define('CAL_VIEW_CALENDAR', 'calendar'); |
---|
49 | |
---|
50 | function initialize_calendar() |
---|
51 | { |
---|
52 | global $page, $conf, $user, $template, $filter; |
---|
53 | |
---|
54 | //------------------ initialize the condition on items to take into account --- |
---|
55 | $inner_sql = ' FROM ' . IMAGES_TABLE; |
---|
56 | |
---|
57 | if ($page['section']=='categories') |
---|
58 | { // we will regenerate the items by including subcats elements |
---|
59 | $page['items'] = array(); |
---|
60 | $inner_sql .= ' |
---|
61 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
62 | |
---|
63 | if ( isset($page['category']) ) |
---|
64 | { |
---|
65 | $sub_ids = array_diff( |
---|
66 | get_subcat_ids(array($page['category']['id'])), |
---|
67 | explode(',', $user['forbidden_categories']) |
---|
68 | ); |
---|
69 | |
---|
70 | if (empty($sub_ids)) |
---|
71 | { |
---|
72 | return; // nothing to do |
---|
73 | } |
---|
74 | $inner_sql .= ' |
---|
75 | WHERE category_id IN ('.implode(',',$sub_ids).')'; |
---|
76 | $inner_sql .= ' |
---|
77 | '.get_sql_condition_FandF |
---|
78 | ( |
---|
79 | array |
---|
80 | ( |
---|
81 | 'visible_images' => 'id' |
---|
82 | ), |
---|
83 | 'AND', false |
---|
84 | ); |
---|
85 | } |
---|
86 | else |
---|
87 | { |
---|
88 | $inner_sql .= ' |
---|
89 | '.get_sql_condition_FandF |
---|
90 | ( |
---|
91 | array |
---|
92 | ( |
---|
93 | 'forbidden_categories' => 'category_id', |
---|
94 | 'visible_categories' => 'category_id', |
---|
95 | 'visible_images' => 'id' |
---|
96 | ), |
---|
97 | 'WHERE', true |
---|
98 | ); |
---|
99 | } |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | if ( empty($page['items']) ) |
---|
104 | { |
---|
105 | return; // nothing to do |
---|
106 | } |
---|
107 | $inner_sql .= ' |
---|
108 | WHERE id IN (' . implode(',',$page['items']) .')'; |
---|
109 | } |
---|
110 | |
---|
111 | //-------------------------------------- initialize the calendar parameters --- |
---|
112 | pwg_debug('start initialize_calendar'); |
---|
113 | |
---|
114 | $fields = array( |
---|
115 | // Created |
---|
116 | 'created' => array( |
---|
117 | 'label' => l10n('Creation date'), |
---|
118 | ), |
---|
119 | // Posted |
---|
120 | 'posted' => array( |
---|
121 | 'label' => l10n('Post date'), |
---|
122 | ), |
---|
123 | ); |
---|
124 | |
---|
125 | $styles = array( |
---|
126 | // Monthly style |
---|
127 | 'monthly' => array( |
---|
128 | 'include' => 'calendar_monthly.class.php', |
---|
129 | 'view_calendar' => true, |
---|
130 | ), |
---|
131 | // Weekly style |
---|
132 | 'weekly' => array( |
---|
133 | 'include' => 'calendar_weekly.class.php', |
---|
134 | 'view_calendar' => false, |
---|
135 | ), |
---|
136 | ); |
---|
137 | |
---|
138 | $views = array(CAL_VIEW_LIST,CAL_VIEW_CALENDAR); |
---|
139 | |
---|
140 | // Retrieve calendar field |
---|
141 | if ( !isset( $fields[ $page['chronology_field'] ] ) ) |
---|
142 | { |
---|
143 | die('bad chronology field'); |
---|
144 | } |
---|
145 | |
---|
146 | // Retrieve style |
---|
147 | if ( !isset( $styles[ $page['chronology_style'] ] ) ) |
---|
148 | { |
---|
149 | $page['chronology_style'] = 'monthly'; |
---|
150 | } |
---|
151 | $cal_style = $page['chronology_style']; |
---|
152 | include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); |
---|
153 | $calendar = new Calendar(); |
---|
154 | |
---|
155 | // Retrieve view |
---|
156 | |
---|
157 | if ( !isset($page['chronology_view']) or |
---|
158 | !in_array( $page['chronology_view'], $views ) ) |
---|
159 | { |
---|
160 | $page['chronology_view'] = CAL_VIEW_LIST; |
---|
161 | } |
---|
162 | |
---|
163 | if ( CAL_VIEW_CALENDAR==$page['chronology_view'] and |
---|
164 | !$styles[$cal_style]['view_calendar'] ) |
---|
165 | { |
---|
166 | |
---|
167 | $page['chronology_view'] = CAL_VIEW_LIST; |
---|
168 | } |
---|
169 | |
---|
170 | // perform a sanity check on $requested |
---|
171 | if (!isset($page['chronology_date'])) |
---|
172 | { |
---|
173 | $page['chronology_date'] = array(); |
---|
174 | } |
---|
175 | while ( count($page['chronology_date']) > 3) |
---|
176 | { |
---|
177 | array_pop($page['chronology_date']); |
---|
178 | } |
---|
179 | |
---|
180 | $any_count = 0; |
---|
181 | for ($i = 0; $i < count($page['chronology_date']); $i++) |
---|
182 | { |
---|
183 | if ($page['chronology_date'][$i] == 'any') |
---|
184 | { |
---|
185 | if ($page['chronology_view'] == CAL_VIEW_CALENDAR) |
---|
186 | {// we dont allow any in calendar view |
---|
187 | while ($i < count($page['chronology_date'])) |
---|
188 | { |
---|
189 | array_pop($page['chronology_date']); |
---|
190 | } |
---|
191 | break; |
---|
192 | } |
---|
193 | $any_count++; |
---|
194 | } |
---|
195 | elseif ($page['chronology_date'][$i] == '') |
---|
196 | { |
---|
197 | while ($i < count($page['chronology_date'])) |
---|
198 | { |
---|
199 | array_pop($page['chronology_date']); |
---|
200 | } |
---|
201 | } |
---|
202 | else |
---|
203 | { |
---|
204 | $page['chronology_date'][$i] = (int)$page['chronology_date'][$i]; |
---|
205 | } |
---|
206 | } |
---|
207 | if ($any_count == 3) |
---|
208 | { |
---|
209 | array_pop($page['chronology_date']); |
---|
210 | } |
---|
211 | |
---|
212 | $calendar->initialize($inner_sql); |
---|
213 | |
---|
214 | //echo ('<pre>'. var_export($calendar, true) . '</pre>'); |
---|
215 | |
---|
216 | $must_show_list = true; // true until calendar generates its own display |
---|
217 | if (script_basename() != 'picture') // basename without file extention |
---|
218 | { |
---|
219 | if ($calendar->generate_category_content()) |
---|
220 | { |
---|
221 | $page['items'] = array(); |
---|
222 | $must_show_list = false; |
---|
223 | } |
---|
224 | |
---|
225 | $page['comment'] = ''; |
---|
226 | $template->assign('FILE_CHRONOLOGY_VIEW', 'month_calendar.tpl'); |
---|
227 | |
---|
228 | foreach ($styles as $style => $style_data) |
---|
229 | { |
---|
230 | foreach ($views as $view) |
---|
231 | { |
---|
232 | if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) |
---|
233 | { |
---|
234 | $selected = false; |
---|
235 | |
---|
236 | if ($style!=$cal_style) |
---|
237 | { |
---|
238 | $chronology_date = array(); |
---|
239 | if ( isset($page['chronology_date'][0]) ) |
---|
240 | { |
---|
241 | array_push($chronology_date, $page['chronology_date'][0]); |
---|
242 | } |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | $chronology_date = $page['chronology_date']; |
---|
247 | } |
---|
248 | $url = duplicate_index_url( |
---|
249 | array( |
---|
250 | 'chronology_style' => $style, |
---|
251 | 'chronology_view' => $view, |
---|
252 | 'chronology_date' => $chronology_date, |
---|
253 | ) |
---|
254 | ); |
---|
255 | |
---|
256 | if ($style==$cal_style and $view==$page['chronology_view'] ) |
---|
257 | { |
---|
258 | $selected = true; |
---|
259 | } |
---|
260 | |
---|
261 | $template->append( |
---|
262 | 'chronology_views', |
---|
263 | array( |
---|
264 | 'VALUE' => $url, |
---|
265 | 'CONTENT' => l10n('chronology_'.$style.'_'.$view), |
---|
266 | 'SELECTED' => $selected, |
---|
267 | ) |
---|
268 | ); |
---|
269 | } |
---|
270 | } |
---|
271 | } |
---|
272 | $url = duplicate_index_url( |
---|
273 | array(), array('start', 'chronology_date') |
---|
274 | ); |
---|
275 | $calendar_title = '<a href="'.$url.'">' |
---|
276 | .$fields[$page['chronology_field']]['label'].'</a>'; |
---|
277 | $calendar_title.= $calendar->get_display_name(); |
---|
278 | $template->assign('chronology', |
---|
279 | array( |
---|
280 | 'TITLE' => $calendar_title |
---|
281 | ) |
---|
282 | ); |
---|
283 | } // end category calling |
---|
284 | |
---|
285 | if ($must_show_list) |
---|
286 | { |
---|
287 | $query = 'SELECT DISTINCT(id)'; |
---|
288 | $query .= $calendar->inner_sql.' |
---|
289 | '.$calendar->get_date_where(); |
---|
290 | if ( isset($page['super_order_by']) ) |
---|
291 | { |
---|
292 | $query .= ' |
---|
293 | '.$conf['order_by']; |
---|
294 | } |
---|
295 | else |
---|
296 | { |
---|
297 | if ( count($page['chronology_date'])==0 |
---|
298 | or in_array('any', $page['chronology_date']) ) |
---|
299 | {// selected period is very big so we show newest first |
---|
300 | $order = ' DESC, '; |
---|
301 | } |
---|
302 | else |
---|
303 | {// selected period is small (month,week) so we show oldest first |
---|
304 | $order = ' ASC, '; |
---|
305 | } |
---|
306 | $order_by = str_replace( |
---|
307 | 'ORDER BY ', |
---|
308 | 'ORDER BY '.$calendar->date_field.$order, $conf['order_by'] |
---|
309 | ); |
---|
310 | $query .= ' |
---|
311 | '.$order_by; |
---|
312 | } |
---|
313 | $page['items'] = array_from_query($query, 'id'); |
---|
314 | } |
---|
315 | pwg_debug('end initialize_calendar'); |
---|
316 | } |
---|
317 | |
---|
318 | ?> |
---|