1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | branch : BSF (Best So Far) |
---|
7 | // | file : $RCSfile$ |
---|
8 | // | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $ |
---|
9 | // | last modifier : $Author: rvelices $ |
---|
10 | // | revision : $Revision: 1014 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | define('CAL_VIEW_LIST', 'l'); |
---|
28 | define('CAL_VIEW_CALENDAR', 'c'); |
---|
29 | |
---|
30 | function get_calendar_parameter($options, &$parameters ) |
---|
31 | { |
---|
32 | if ( count($parameters) and isset($options[$parameters[0]]) ) |
---|
33 | { |
---|
34 | return array_shift($parameters); |
---|
35 | } |
---|
36 | else |
---|
37 | { |
---|
38 | foreach ($options as $option => $data) |
---|
39 | { |
---|
40 | if ( empty( $data['default_link'] ) ) |
---|
41 | { |
---|
42 | break; |
---|
43 | } |
---|
44 | } |
---|
45 | return $option; |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | function initialize_calendar() |
---|
50 | { |
---|
51 | global $page, $conf, $user, $template; |
---|
52 | |
---|
53 | //------------------ initialize the condition on items to take into account --- |
---|
54 | $inner_sql = ' FROM ' . IMAGES_TABLE; |
---|
55 | |
---|
56 | if (!isset($page['cat']) or is_numeric($page['cat'])) |
---|
57 | { // we will regenerate the items by including subcats elements |
---|
58 | $page['cat_nb_images'] = 0; |
---|
59 | $page['items'] = array(); |
---|
60 | $inner_sql .= ' |
---|
61 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; |
---|
62 | |
---|
63 | if (isset($page['cat']) and is_numeric($page['cat'])) |
---|
64 | { |
---|
65 | $sub_ids = array_diff( |
---|
66 | get_subcat_ids(array($page['cat'])), |
---|
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 | } |
---|
77 | else |
---|
78 | { |
---|
79 | $inner_sql .= ' |
---|
80 | WHERE category_id NOT IN ('.$user['forbidden_categories'].')'; |
---|
81 | } |
---|
82 | } |
---|
83 | else |
---|
84 | { |
---|
85 | if ( empty($page['items']) ) |
---|
86 | { |
---|
87 | return; // nothing to do |
---|
88 | } |
---|
89 | $inner_sql .= ' |
---|
90 | WHERE id IN (' . implode(',',$page['items']) .')'; |
---|
91 | } |
---|
92 | |
---|
93 | //-------------------------------------- initialize the calendar parameters --- |
---|
94 | pwg_debug('start initialize_calendar'); |
---|
95 | // the parameters look like (FIELD)?(STYLE)?(VIEW)?(DATE COMPONENTS)? |
---|
96 | // FIELD = (created-|posted-) |
---|
97 | // STYLE = (m-|w-) |
---|
98 | // VIEW = (l-|c-) |
---|
99 | // DATE COMPONENTS= YEAR(-MONTH/WEEK)?(-DAY)? |
---|
100 | |
---|
101 | $fields = array( |
---|
102 | // Created |
---|
103 | 'created' => array( |
---|
104 | 'default_link' => 'created-', |
---|
105 | 'label' => l10n('Creation date'), |
---|
106 | 'db_field' => 'date_creation', |
---|
107 | ), |
---|
108 | // Posted |
---|
109 | 'posted' => array( |
---|
110 | 'default_link' => 'posted-', |
---|
111 | 'label' => l10n('Post date'), |
---|
112 | 'db_field' => 'date_available', |
---|
113 | ), |
---|
114 | ); |
---|
115 | |
---|
116 | $styles = array( |
---|
117 | // Monthly style |
---|
118 | 'monthly' => array( |
---|
119 | 'default_link' => '', |
---|
120 | 'include' => 'calendar_monthly.class.php', |
---|
121 | 'view_calendar' => true, |
---|
122 | ), |
---|
123 | // Weekly style |
---|
124 | 'weekly' => array( |
---|
125 | 'default_link' => 'weekly-', |
---|
126 | 'include' => 'calendar_weekly.class.php', |
---|
127 | 'view_calendar' => false, |
---|
128 | ), |
---|
129 | ); |
---|
130 | |
---|
131 | $views = array( |
---|
132 | // list view |
---|
133 | CAL_VIEW_LIST => array( |
---|
134 | 'default_link' => '', |
---|
135 | ), |
---|
136 | // calendar view |
---|
137 | CAL_VIEW_CALENDAR => array( |
---|
138 | 'default_link' => CAL_VIEW_CALENDAR.'-', |
---|
139 | ), |
---|
140 | ); |
---|
141 | |
---|
142 | $requested = explode('-', $_GET['calendar']); |
---|
143 | |
---|
144 | // Retrieve calendar field |
---|
145 | $cal_field = get_calendar_parameter($fields, $requested); |
---|
146 | |
---|
147 | // Retrieve style |
---|
148 | $cal_style = get_calendar_parameter($styles, $requested); |
---|
149 | include(PHPWG_ROOT_PATH.'include/'. $styles[$cal_style]['include']); |
---|
150 | $calendar = new Calendar(); |
---|
151 | |
---|
152 | // Retrieve view |
---|
153 | $cal_view = get_calendar_parameter($views, $requested); |
---|
154 | if ( CAL_VIEW_CALENDAR==$cal_view and !$styles[$cal_style]['view_calendar'] ) |
---|
155 | { |
---|
156 | $cal_view=CAL_VIEW_LIST; |
---|
157 | } |
---|
158 | |
---|
159 | // perform a sanity check on $requested |
---|
160 | while (count($requested) > 3) |
---|
161 | { |
---|
162 | array_pop($requested); |
---|
163 | } |
---|
164 | |
---|
165 | $any_count = 0; |
---|
166 | for ($i = 0; $i < count($requested); $i++) |
---|
167 | { |
---|
168 | if ($requested[$i] == 'any') |
---|
169 | { |
---|
170 | if ($cal_view == CAL_VIEW_CALENDAR) |
---|
171 | {// we dont allow any in calendar view |
---|
172 | while ($i < count($requested)) |
---|
173 | { |
---|
174 | array_pop($requested); |
---|
175 | } |
---|
176 | break; |
---|
177 | } |
---|
178 | $any_count++; |
---|
179 | } |
---|
180 | elseif ($requested[$i] == '') |
---|
181 | { |
---|
182 | while ($i < count($requested)) |
---|
183 | { |
---|
184 | array_pop($requested); |
---|
185 | } |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | $requested[$i] = (int)$requested[$i]; |
---|
190 | } |
---|
191 | } |
---|
192 | if ($any_count == 3) |
---|
193 | { |
---|
194 | array_pop($requested); |
---|
195 | } |
---|
196 | |
---|
197 | $calendar->initialize($fields[$cal_field]['db_field'], $inner_sql, $requested); |
---|
198 | |
---|
199 | //echo ('<pre>'. var_export($calendar, true) . '</pre>'); |
---|
200 | |
---|
201 | $url_base = get_query_string_diff(array('start', 'calendar')); |
---|
202 | $url_base = |
---|
203 | PHPWG_ROOT_PATH.'category.php' |
---|
204 | .$url_base |
---|
205 | .(empty($url_base) ? '?' : '&') |
---|
206 | .'calendar='.$cal_field.'-' |
---|
207 | ; |
---|
208 | $must_show_list = true; // true until calendar generates its own display |
---|
209 | if (basename($_SERVER["PHP_SELF"]) == 'category.php') |
---|
210 | { |
---|
211 | $template->assign_block_vars('calendar', array()); |
---|
212 | |
---|
213 | if ($calendar->generate_category_content( |
---|
214 | $url_base.$cal_style.'-'.$cal_view.'-', |
---|
215 | $cal_view |
---|
216 | ) |
---|
217 | ) |
---|
218 | { |
---|
219 | unset( |
---|
220 | $page['thumbnails_include'], |
---|
221 | $page['items'], |
---|
222 | $page['cat_nb_images'] |
---|
223 | ); |
---|
224 | |
---|
225 | $must_show_list = false; |
---|
226 | } |
---|
227 | |
---|
228 | $template->assign_block_vars( 'calendar.views', array() ); |
---|
229 | foreach ($styles as $style => $style_data) |
---|
230 | { |
---|
231 | foreach ($views as $view => $view_data) |
---|
232 | { |
---|
233 | if ( $style_data['view_calendar'] or $view != CAL_VIEW_CALENDAR) |
---|
234 | { |
---|
235 | $selected = ''; |
---|
236 | $url = $url_base.$style.'-'.$view; |
---|
237 | if ($style==$cal_style) |
---|
238 | { |
---|
239 | $url .= '-'.implode('-', $calendar->date_components); |
---|
240 | if ( $view==$cal_view ) |
---|
241 | { |
---|
242 | $selected = 'SELECTED'; |
---|
243 | } |
---|
244 | } |
---|
245 | else |
---|
246 | { |
---|
247 | if (isset($calendar->date_components[0])) |
---|
248 | { |
---|
249 | $url .= '-' . $calendar->date_components[0]; |
---|
250 | } |
---|
251 | } |
---|
252 | $template->assign_block_vars( |
---|
253 | 'calendar.views.view', |
---|
254 | array( |
---|
255 | 'VALUE' => $url, |
---|
256 | 'CONTENT' => l10n('calendar_'.$style.'_'.$view), |
---|
257 | 'SELECTED' => $selected, |
---|
258 | ) |
---|
259 | ); |
---|
260 | } |
---|
261 | } |
---|
262 | } |
---|
263 | $calendar_title = |
---|
264 | '<a href="'.$url_base.$cal_style.'-'.$cal_view.'">' |
---|
265 | .$fields[$cal_field]['label'].'</a>'; |
---|
266 | $calendar_title.= $calendar->get_display_name(); |
---|
267 | //this should be an assign_block_vars, but I need to assign 'calendar' |
---|
268 | //above and at that point I don't have the title yet. |
---|
269 | $template->_tpldata['calendar.'][0]['TITLE'] = $calendar_title; |
---|
270 | } // end category calling |
---|
271 | |
---|
272 | if ($must_show_list) |
---|
273 | { |
---|
274 | $query = 'SELECT DISTINCT(id)'; |
---|
275 | $query .= $calendar->inner_sql.' |
---|
276 | '.$calendar->get_date_where(); |
---|
277 | if ( isset($page['super_order_by']) ) |
---|
278 | { |
---|
279 | $query .= ' |
---|
280 | '.$conf['order_by']; |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | $order_by = str_replace( |
---|
285 | 'ORDER BY ', |
---|
286 | 'ORDER BY '.$calendar->date_field.' DESC,', $conf['order_by'] |
---|
287 | ); |
---|
288 | $query .= ' |
---|
289 | '.$order_by; |
---|
290 | } |
---|
291 | |
---|
292 | $page['items'] = array_from_query($query, 'id'); |
---|
293 | $page['cat_nb_images'] = count($page['items']); |
---|
294 | $page['thumbnails_include'] = 'include/category_default.inc.php'; |
---|
295 | } |
---|
296 | pwg_debug('end initialize_calendar'); |
---|
297 | } |
---|
298 | |
---|
299 | ?> |
---|