Révision b720ea3e
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/date/date_repeat/date_repeat.module | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
/** |
3 | 3 |
* @file |
4 |
* |
|
5 | 4 |
* This module creates a form element that allows users to select |
6 | 5 |
* repeat rules for a date, and reworks the result into an iCal |
7 | 6 |
* RRULE string that can be stored in the database. |
... | ... | |
11 | 10 |
* |
12 | 11 |
* Other modules can use this API to add self-validating form elements |
13 | 12 |
* to their dates, and identify dates that meet the RRULE criteria. |
14 |
* |
|
15 | 13 |
*/ |
14 |
|
|
16 | 15 |
/** |
17 | 16 |
* Implements hook_element_info(). |
18 | 17 |
*/ |
... | ... | |
35 | 34 |
return $type; |
36 | 35 |
} |
37 | 36 |
|
37 |
/** |
|
38 |
* Implements hook_theme(). |
|
39 |
*/ |
|
38 | 40 |
function date_repeat_theme() { |
39 | 41 |
return array( |
40 | 42 |
'date_repeat_current_exceptions' => array('render element' => 'element'), |
... | ... | |
55 | 57 |
); |
56 | 58 |
} |
57 | 59 |
|
60 |
/** |
|
61 |
* Helper function for interval options. |
|
62 |
*/ |
|
58 | 63 |
function date_repeat_interval_options() { |
59 | 64 |
$options = range(0, 366); |
60 | 65 |
unset($options[0]); |
... | ... | |
92 | 97 |
case 1: |
93 | 98 |
$context = 'day_abbr1'; |
94 | 99 |
break; |
100 |
|
|
95 | 101 |
case 2: |
96 | 102 |
$context = 'day_abbr2'; |
97 | 103 |
break; |
104 |
|
|
98 | 105 |
default: |
99 | 106 |
$context = ''; |
100 | 107 |
break; |
... | ... | |
105 | 112 |
return $return; |
106 | 113 |
} |
107 | 114 |
|
115 |
/** |
|
116 |
* Helper function for weekdays translated. |
|
117 |
*/ |
|
108 | 118 |
function date_repeat_dow_day_untranslated() { |
109 | 119 |
static $date_repeat_weekdays; |
110 | 120 |
if (empty($date_repeat_weekdays)) { |
111 |
$date_repeat_weekdays = array('SU' => 'Sunday', 'MO' => 'Monday', 'TU' => 'Tuesday', |
|
112 |
'WE' => 'Wednesday', 'TH' => 'Thursday', 'FR' => 'Friday', |
|
113 |
'SA' => 'Saturday'); |
|
121 |
$date_repeat_weekdays = array( |
|
122 |
'SU' => 'Sunday', |
|
123 |
'MO' => 'Monday', |
|
124 |
'TU' => 'Tuesday', |
|
125 |
'WE' => 'Wednesday', |
|
126 |
'TH' => 'Thursday', |
|
127 |
'FR' => 'Friday', |
|
128 |
'SA' => 'Saturday' |
|
129 |
); |
|
114 | 130 |
} |
115 | 131 |
return $date_repeat_weekdays; |
116 | 132 |
} |
117 | 133 |
|
134 |
/** |
|
135 |
* Helper function for weekdays order. |
|
136 |
*/ |
|
118 | 137 |
function date_repeat_dow_day_options_ordered($weekdays) { |
119 | 138 |
$day_keys = array_keys($weekdays); |
120 | 139 |
$day_values = array_values($weekdays); |
... | ... | |
164 | 183 |
} |
165 | 184 |
|
166 | 185 |
/** |
167 |
* Shift the array of iCal day names into the right order |
|
168 |
* for a specific week start day. |
|
186 |
* Shift the array of iCal day names into the right order for a specific week start day. |
|
169 | 187 |
*/ |
170 | 188 |
function date_repeat_days_ordered($week_start_day) { |
171 | 189 |
$days = array_flip(array_keys(date_repeat_dow_day_options(FALSE))); |
... | ... | |
212 | 230 |
'!except' => '', |
213 | 231 |
'!additional' => '', |
214 | 232 |
'!week_starts_on' => '', |
215 |
);
|
|
233 |
); |
|
216 | 234 |
$interval = date_repeat_interval_options(); |
217 | 235 |
switch ($rrule['FREQ']) { |
218 | 236 |
case 'WEEKLY': |
219 | 237 |
$description['!interval'] = format_plural($rrule['INTERVAL'], 'every week', 'every @count weeks') . ' '; |
220 | 238 |
break; |
239 |
|
|
221 | 240 |
case 'MONTHLY': |
222 | 241 |
$description['!interval'] = format_plural($rrule['INTERVAL'], 'every month', 'every @count months') . ' '; |
223 | 242 |
break; |
243 |
|
|
224 | 244 |
case 'YEARLY': |
225 | 245 |
$description['!interval'] = format_plural($rrule['INTERVAL'], 'every year', 'every @count years') . ' '; |
226 | 246 |
break; |
247 |
|
|
227 | 248 |
default: |
228 | 249 |
$description['!interval'] = format_plural($rrule['INTERVAL'], 'every day', 'every @count days') . ' '; |
229 | 250 |
break; |
... | ... | |
240 | 261 |
if (!empty($count)) { |
241 | 262 |
// See if there is a 'pretty' option for this count, i.e. +1 => First. |
242 | 263 |
$order = array_key_exists($count, $counts) ? strtolower($counts[$count]) : $count; |
243 |
$results[] = trim(t('!repeats_every_interval on the !date_order !day_of_week', array('!repeats_every_interval ' => '', '!date_order' => $order, '!day_of_week' => $days[$day]))); |
|
264 |
$results[] = trim(t('!repeats_every_interval on the !date_order !day_of_week', |
|
265 |
array( |
|
266 |
'!repeats_every_interval ' => '', |
|
267 |
'!date_order' => $order, |
|
268 |
'!day_of_week' => $days[$day] |
|
269 |
))); |
|
244 | 270 |
} |
245 | 271 |
else { |
246 |
$results[] = trim(t('!repeats_every_interval every !day_of_week', array('!repeats_every_interval ' => '', '!day_of_week' => $days[$day]))); |
|
272 |
$results[] = trim(t('!repeats_every_interval every !day_of_week', |
|
273 |
array('!repeats_every_interval ' => '', '!day_of_week' => $days[$day]))); |
|
247 | 274 |
} |
248 | 275 |
} |
249 | 276 |
$description['!byday'] = implode(' ' . t('and') . ' ', $results); |
250 | 277 |
} |
251 | 278 |
if (!empty($rrule['BYMONTH'])) { |
252 |
if (sizeof($rrule['BYMONTH']) < 12) {
|
|
279 |
if (count($rrule['BYMONTH']) < 12) {
|
|
253 | 280 |
$results = array(); |
254 | 281 |
$months = date_month_names(); |
255 | 282 |
foreach ($rrule['BYMONTH'] as $month) { |
256 | 283 |
$results[] = $months[$month]; |
257 | 284 |
} |
258 | 285 |
if (!empty($rrule['BYMONTHDAY'])) { |
259 |
$description['!bymonth'] = trim(t('!repeats_every_interval on the !month_days of !month_names', array('!repeats_every_interval ' => '', '!month_days' => implode(', ', $rrule['BYMONTHDAY']), '!month_names' => implode(', ', $results)))); |
|
286 |
$description['!bymonth'] = trim(t('!repeats_every_interval on the !month_days of !month_names', |
|
287 |
array( |
|
288 |
'!repeats_every_interval ' => '', |
|
289 |
'!month_days' => implode(', ', $rrule['BYMONTHDAY']), |
|
290 |
'!month_names' => implode(', ', $results) |
|
291 |
))); |
|
260 | 292 |
} |
261 | 293 |
else { |
262 |
$description['!bymonth'] = trim(t('!repeats_every_interval on !month_names', array('!repeats_every_interval ' => '', '!month_names' => implode(', ', $results)))); |
|
294 |
$description['!bymonth'] = trim(t('!repeats_every_interval on !month_names', |
|
295 |
array( |
|
296 |
'!repeats_every_interval ' => '', |
|
297 |
'!month_names' => implode(', ', $results) |
|
298 |
))); |
|
263 | 299 |
} |
264 | 300 |
} |
265 | 301 |
} |
... | ... | |
267 | 303 |
$rrule['INTERVAL'] = 1; |
268 | 304 |
} |
269 | 305 |
if (!empty($rrule['COUNT'])) { |
270 |
$description['!count'] = trim(t('!repeats_every_interval !count times', array('!repeats_every_interval ' => '', '!count' => $rrule['COUNT']))); |
|
306 |
$description['!count'] = trim(t('!repeats_every_interval !count times', |
|
307 |
array('!repeats_every_interval ' => '', '!count' => $rrule['COUNT']))); |
|
271 | 308 |
} |
272 | 309 |
if (!empty($rrule['UNTIL'])) { |
273 | 310 |
$until = date_ical_date($rrule['UNTIL'], 'UTC'); |
274 | 311 |
date_timezone_set($until, date_default_timezone_object()); |
275 |
$description['!until'] = trim(t('!repeats_every_interval until !until_date', array('!repeats_every_interval ' => '', '!until_date' => date_format_date($until, 'custom', $format)))); |
|
312 |
$description['!until'] = trim(t('!repeats_every_interval until !until_date', |
|
313 |
array( |
|
314 |
'!repeats_every_interval ' => '', |
|
315 |
'!until_date' => date_format_date($until, 'custom', $format) |
|
316 |
))); |
|
276 | 317 |
} |
277 | 318 |
if ($exceptions) { |
278 | 319 |
$values = array(); |
... | ... | |
281 | 322 |
date_timezone_set($except, date_default_timezone_object()); |
282 | 323 |
$values[] = date_format_date($except, 'custom', $format); |
283 | 324 |
} |
284 |
$description['!except'] = trim(t('!repeats_every_interval except !except_dates', array('!repeats_every_interval ' => '', '!except_dates' => implode(', ', $values)))); |
|
325 |
$description['!except'] = trim(t('!repeats_every_interval except !except_dates', |
|
326 |
array( |
|
327 |
'!repeats_every_interval ' => '', |
|
328 |
'!except_dates' => implode(', ', $values) |
|
329 |
))); |
|
285 | 330 |
} |
286 | 331 |
if (!empty($rrule['WKST'])) { |
287 | 332 |
$day_names = date_repeat_dow_day_options(); |
288 |
$description['!week_starts_on'] = trim(t('!repeats_every_interval where the week start on !day_of_week', array('!repeats_every_interval ' => '', '!day_of_week' => $day_names[trim($rrule['WKST'])]))); |
|
333 |
$description['!week_starts_on'] = trim(t('!repeats_every_interval where the week start on !day_of_week', |
|
334 |
array('!repeats_every_interval ' => '', '!day_of_week' => $day_names[trim($rrule['WKST'])]))); |
|
289 | 335 |
} |
290 | 336 |
if ($additions) { |
291 | 337 |
$values = array(); |
... | ... | |
294 | 340 |
date_timezone_set($add, date_default_timezone_object()); |
295 | 341 |
$values[] = date_format_date($add, 'custom', $format); |
296 | 342 |
} |
297 |
$description['!additional'] = trim(t('Also includes !additional_dates.', array('!additional_dates' => implode(', ', $values)))); |
|
343 |
$description['!additional'] = trim(t('Also includes !additional_dates.', |
|
344 |
array('!additional_dates' => implode(', ', $values)))); |
|
298 | 345 |
} |
299 |
return t('Repeats !interval !bymonth !byday !count !until !except. !additional', $description); |
|
346 |
$output = t('Repeats !interval !bymonth !byday !count !until !except. !additional', $description); |
|
347 |
// Removes double whitespaces from Repeat tile. |
|
348 |
$output = preg_replace('/\s+/', ' ', $output); |
|
349 |
// Removes whitespace before full stop ".", at the end of the title. |
|
350 |
$output = str_replace(' .', '.', $output); |
|
351 |
return $output; |
|
300 | 352 |
} |
301 | 353 |
|
302 | 354 |
/** |
... | ... | |
310 | 362 |
$additions = array(); |
311 | 363 |
foreach ($parts as $part) { |
312 | 364 |
if (strstr($part, 'RRULE')) { |
313 |
$RRULE = str_replace('RRULE:', '', $part);
|
|
314 |
$rrule = (array) date_ical_parse_rrule('RRULE:', $RRULE);
|
|
365 |
$cleanded_part = str_replace('RRULE:', '', $part);
|
|
366 |
$rrule = (array) date_ical_parse_rrule('RRULE:', $cleanded_part);
|
|
315 | 367 |
} |
316 | 368 |
elseif (strstr($part, 'EXDATE')) { |
317 |
$EXDATE = str_replace('EXDATE:', '', $part);
|
|
318 |
$exceptions = (array) date_ical_parse_exceptions('EXDATE:', $EXDATE);
|
|
369 |
$exdate = str_replace('EXDATE:', '', $part);
|
|
370 |
$exceptions = (array) date_ical_parse_exceptions('EXDATE:', $exdate);
|
|
319 | 371 |
unset($exceptions['DATA']); |
320 | 372 |
} |
321 | 373 |
elseif (strstr($part, 'RDATE')) { |
322 |
$RDATE = str_replace('RDATE:', '', $part);
|
|
323 |
$additions = (array) date_ical_parse_exceptions('RDATE:', $RDATE);
|
|
374 |
$rdate = str_replace('RDATE:', '', $part);
|
|
375 |
$additions = (array) date_ical_parse_exceptions('RDATE:', $rdate);
|
|
324 | 376 |
unset($additions['DATA']); |
325 | 377 |
} |
326 | 378 |
} |
... | ... | |
372 | 424 |
'#title_display' => 'invisible', |
373 | 425 |
'#return_value' => $key, |
374 | 426 |
'#default_value' => isset($element['#default_value']) ? |
375 |
$element['#default_value'] : NULL,
|
|
427 |
$element['#default_value'] : NULL, |
|
376 | 428 |
'#attributes' => $element['#attributes'], |
377 | 429 |
'#parents' => $element['#parents'], |
378 | 430 |
'#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)), |
Formats disponibles : Unified diff
Weekly update of contrib modules