136
|
1 |
<?php |
|
2 |
/* |
|
3 |
Copyright (c) 2005-2008, Alex Tingle. $Revision: 287 $ |
|
4 |
|
|
5 |
This program is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU General Public License |
|
7 |
as published by the Free Software Foundation; either version 2 |
|
8 |
of the License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program; if not, write to the Free Software |
|
17 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
18 |
*/ |
|
19 |
|
|
20 |
|
|
21 |
/** Report an error if EventCalendar not yet installed. */ |
|
22 |
function ec3_check_installed($title) |
|
23 |
{ |
|
24 |
global $ec3; |
|
25 |
if(!$ec3->event_category) |
|
26 |
{?> |
|
27 |
<div style="background-color:black; color:red; border:2px solid red; padding:1em"> |
|
28 |
<div style="font-size:large"><?php echo $title; ?></div> |
|
29 |
<?php _e('You must choose an event category.','ec3'); ?> |
|
30 |
<a style="color:red; text-decoration:underline" href="<?php echo |
|
31 |
get_option('home');?>/wp-admin/options-general.php?page=ec3_admin"> |
|
32 |
<?php _e('Go to Event Calendar Options','ec3'); ?> |
|
33 |
</a> |
|
34 |
</div> |
|
35 |
<?php |
|
36 |
} |
|
37 |
return $ec3->event_category; |
|
38 |
} |
|
39 |
|
|
40 |
|
|
41 |
/** Calculate the header (days of week). */ |
|
42 |
function ec3_util_thead() |
|
43 |
{ |
|
44 |
global |
|
45 |
$ec3, |
|
46 |
$weekday, |
|
47 |
$weekday_abbrev, |
|
48 |
$weekday_initial; |
|
49 |
|
|
50 |
$result="<thead><tr>\n"; |
|
51 |
|
|
52 |
$start_of_week =intval( get_option('start_of_week') ); |
|
53 |
for($i=0; $i<7; $i++) |
|
54 |
{ |
|
55 |
$full_day_name=$weekday[ ($i+$start_of_week) % 7 ]; |
|
56 |
if(3==$ec3->day_length) |
|
57 |
$display_day_name=$weekday_abbrev[$full_day_name]; |
|
58 |
elseif($ec3->day_length<3) |
|
59 |
$display_day_name=$weekday_initial[$full_day_name]; |
|
60 |
else |
|
61 |
$display_day_name=$full_day_name; |
|
62 |
$result.="\t<th abbr='$full_day_name' scope='col' title='$full_day_name'>" |
|
63 |
. "$display_day_name</th>\n"; |
|
64 |
} |
|
65 |
|
|
66 |
$result.="</tr></thead>\n"; |
|
67 |
return $result; |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
/** Echos the event calendar navigation controls. */ |
|
72 |
/* modified by samuel huron 05/01/2010 */ |
|
73 |
function ec3_get_calendar_nav($date,$num_months) |
|
74 |
{ |
|
75 |
global $ec3; |
|
76 |
echo "<table class='nav'><tbody><tr>\n"; |
|
77 |
|
|
78 |
// Previous |
|
79 |
$prev=$date->prev_month(); |
|
80 |
echo "\t<td id='prev'><a id='ec3_prev' href='" . $prev->month_link() . "'" |
|
81 |
. '>« ' . $prev->month_abbrev() . "</a></td>\n"; |
|
82 |
|
|
83 |
// -------------------------------------------------------------------------- |
|
84 |
// start modified by sam |
|
85 |
|
|
86 |
/* |
|
87 |
// iCalendar link. |
|
88 |
$webcal=get_option('home') . "/?ec3_ical"; |
|
89 |
// Macintosh always understands webcal:// protocol. |
|
90 |
// It's hard to guess on other platforms, so stick to http:// |
|
91 |
if(strstr($_SERVER['HTTP_USER_AGENT'],'Mac OS X')) |
|
92 |
$webcal=preg_replace('/^http:/','webcal:',$webcal); |
|
93 |
echo "\t <a id='ec3_publish' href='$webcal'" |
|
94 |
. " title='" . __('Subscribe to iCalendar.','ec3') ."'>\n" |
|
95 |
. "\t <img src='$ec3->myfiles/publish.gif' alt='iCalendar' />\n" |
|
96 |
. "\t </a>\n";*/ |
|
97 |
echo "\t</td>\n"; |
|
98 |
// -------------------------------------------------------------------------- stop |
|
99 |
|
|
100 |
|
|
101 |
// Next |
|
102 |
$next=$date->plus_months($num_months); |
|
103 |
echo "\t<td id='next'><a id='ec3_next' href='" . $next->month_link() . "'" |
|
104 |
. '>' . $next->month_abbrev() . " »</a></td>\n"; |
|
105 |
|
|
106 |
echo "</tr></tbody></table>\n"; |
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
/** Generates an array of all 'ec3_Day's between the start of |
|
111 |
* begin_month & end_month. Indexed by day_id. |
|
112 |
* month_id is in the form: ec3_<year_num>_<month_num> */ |
|
113 |
function ec3_util_calendar_days($begin_month_id,$end_month_id) |
|
114 |
{ |
|
115 |
$begin_date=date('Y-m-d 00:00:00',ec3_dayid2php($begin_month_id)); |
|
116 |
$end_date =date('Y-m-d 00:00:00',ec3_dayid2php($end_month_id)); |
|
117 |
global $ec3, $wpdb; |
|
118 |
|
|
119 |
$sql= |
|
120 |
"SELECT DISTINCT |
|
121 |
id, |
|
122 |
post_title, |
|
123 |
GREATEST(start,'$begin_date') AS start_date, |
|
124 |
LEAST(end,'$end_date') AS end_date, |
|
125 |
allday, |
|
126 |
1 AS is_event |
|
127 |
FROM $wpdb->posts,$ec3->schedule |
|
128 |
WHERE post_status='publish' |
|
129 |
AND post_type='post' |
|
130 |
AND post_id=id |
|
131 |
AND end>='$begin_date' |
|
132 |
AND start<'$end_date'"; |
|
133 |
if(!$ec3->show_only_events) |
|
134 |
{ |
|
135 |
// We are interested in normal posts, as well as events. |
|
136 |
$sql="( $sql ) UNION |
|
137 |
( SELECT DISTINCT |
|
138 |
id, |
|
139 |
post_title, |
|
140 |
post_date AS start_date, |
|
141 |
post_date AS end_date, |
|
142 |
0 AS allday, |
|
143 |
0 AS is_event |
|
144 |
FROM $wpdb->posts |
|
145 |
WHERE post_status='publish' |
|
146 |
AND post_type='post' |
|
147 |
AND post_date>='$begin_date' |
|
148 |
AND post_date<'$end_date' |
|
149 |
AND post_date<NOW() |
|
150 |
)"; |
|
151 |
} |
|
152 |
$sql.=' ORDER BY id, allday DESC, start_date, is_event DESC'; |
|
153 |
$calendar_entries = $wpdb->get_results($sql); |
|
154 |
|
|
155 |
$calendar_days = array(); // result |
|
156 |
if(!$calendar_entries) |
|
157 |
return $calendar_days; |
|
158 |
|
|
159 |
// In advanced mode, we don't want to show events as blog posts in the cal. |
|
160 |
$ignore_post_ids=array(); |
|
161 |
if($ec3->advanced && !$ec3->show_only_events) |
|
162 |
{ |
|
163 |
foreach($calendar_entries as $ent) |
|
164 |
if($ent->is_event) |
|
165 |
$ignore_post_ids[] = $ent->id; |
|
166 |
} |
|
167 |
|
|
168 |
$current_post_id=0; |
|
169 |
$current_day_id =''; |
|
170 |
$time_format=get_option('time_format'); |
|
171 |
$allday=str_replace(' ',' ',__('all day','ec3')); // #160==nbsp |
|
172 |
foreach($calendar_entries as $ent) |
|
173 |
{ |
|
174 |
if(!$ent->is_event && in_array($ent->id,$ignore_post_ids)) |
|
175 |
continue; |
|
176 |
if($current_post_id!=$ent->id) |
|
177 |
{ |
|
178 |
$current_post_id=$ent->id; |
|
179 |
$current_day_id=''; |
|
180 |
} |
|
181 |
$date=ec3_mysql2date($ent->start_date); |
|
182 |
$end_date=ec3_mysql2date($ent->end_date); |
|
183 |
while(true) |
|
184 |
{ |
|
185 |
$day_id=$date->day_id(); |
|
186 |
if($current_day_id==$day_id) |
|
187 |
break; |
|
188 |
$current_day_id=$day_id; |
|
189 |
if(empty($calendar_days[$day_id])) |
|
190 |
$calendar_days[$day_id] = new ec3_Day(); |
|
191 |
|
|
192 |
if($ent->allday) |
|
193 |
$time=$allday; |
|
194 |
else |
|
195 |
$time=mysql2date($time_format,$ent->start_date); |
|
196 |
//?? Should only record start time on FIRST day. |
|
197 |
$calendar_days[$day_id]->add_post($ent->post_title,$time,$ent->is_event); |
|
198 |
if($date->to_unixdate()==$end_date->to_unixdate()) |
|
199 |
break; |
|
200 |
$date->increment_day(); |
|
201 |
} |
|
202 |
} |
|
203 |
return $calendar_days; |
|
204 |
} |
|
205 |
|
|
206 |
/** Echos one event calendar month table. */ |
|
207 |
function ec3_get_calendar_month($date,$calendar_days,$thead) |
|
208 |
{ |
|
209 |
global $ec3; |
|
210 |
// |
|
211 |
// Table start. |
|
212 |
$title= |
|
213 |
sprintf(__('View posts for %1$s %2$s'),$date->month_name(),$date->year_num); |
|
214 |
echo "<table id='" . $date->month_id() . "' >\n<caption>" |
|
215 |
. '<a href="' . $date->month_link() . '" title="' . $title . '">' |
|
216 |
. $date->month_name() . ' ' . $date->year_num . "</a></caption>\n"; |
|
217 |
echo $thead; |
|
218 |
|
|
219 |
// |
|
220 |
// Table body |
|
221 |
echo "<tbody>\n\t<tr>"; |
|
222 |
|
|
223 |
$days_in_month =$date->days_in_month(); |
|
224 |
$week_day=( $date->week_day() + 7 - intval(get_option('start_of_week')) ) % 7; |
|
225 |
$col =0; |
|
226 |
|
|
227 |
while(True) |
|
228 |
{ |
|
229 |
if($col>6) |
|
230 |
{ |
|
231 |
echo "</tr>\n\t<tr>"; |
|
232 |
$col=0; |
|
233 |
} |
|
234 |
if($col<$week_day) |
|
235 |
{ |
|
236 |
// insert padding |
|
237 |
$pad=$week_day-$col; |
|
238 |
echo "<td colspan='$pad' class='pad'> </td>"; |
|
239 |
$col=$week_day; |
|
240 |
} |
|
241 |
// insert day |
|
242 |
$day_id = $date->day_id(); |
|
243 |
echo "<td id='$day_id'"; |
|
244 |
|
|
245 |
if(array_key_exists($day_id,$calendar_days)) |
|
246 |
{ |
|
247 |
echo ' class="ec3_postday'; |
|
248 |
if($calendar_days[$day_id]->is_event) |
|
249 |
echo ' ec3_eventday'; |
|
250 |
echo '">'; |
|
251 |
echo '<a href="' . $date->day_link() |
|
252 |
. '" title="' . $calendar_days[$day_id]->get_titles() . '"'; |
|
253 |
if($calendar_days[$day_id]->is_event) |
|
254 |
echo ' class="eventday"'; |
|
255 |
echo ">$date->day_num</a>"; |
|
256 |
} |
|
257 |
else |
|
258 |
{ |
|
259 |
echo '>' . $date->day_num; |
|
260 |
} |
|
261 |
|
|
262 |
echo '</td>'; |
|
263 |
|
|
264 |
$col++; |
|
265 |
$date->increment_day(); |
|
266 |
if(1==$date->day_num) |
|
267 |
break; |
|
268 |
$week_day=($week_day+1) % 7; |
|
269 |
} |
|
270 |
// insert padding |
|
271 |
$pad=7-$col; |
|
272 |
if($pad>1) |
|
273 |
echo "<td colspan='$pad' class='pad' style='vertical-align:bottom'>" |
|
274 |
. "<a href='http://blog.firetree.net/?ec3_version=$ec3->version'" |
|
275 |
. " title='Event Calendar $ec3->version'" |
|
276 |
. ($ec3->hide_logo? " style='display:none'>": ">") |
|
277 |
. "<span class='ec3_ec'><span>EC</span></span></a></td>"; |
|
278 |
elseif($pad) |
|
279 |
echo "<td colspan='$pad' class='pad'> </td>"; |
|
280 |
|
|
281 |
echo "</tr>\n</tbody>\n</table> <!-- LA --> "; |
|
282 |
} |
|
283 |
|
|
284 |
|
|
285 |
/** Template function. Call this from your template to insert the |
|
286 |
* Event Calendar. */ |
|
287 |
function ec3_get_calendar() |
|
288 |
{ |
|
289 |
if(!ec3_check_installed(__('Event Calendar','ec3'))) |
|
290 |
return; |
|
291 |
global $ec3; |
|
292 |
|
|
293 |
// Can't cope with more than one calendar on the same page. Everything has |
|
294 |
// a unique ID, so it can't be duplicated. |
|
295 |
// Simple fix for problem: Just ignore all calls after the first. |
|
296 |
$ec3->call_count++; |
|
297 |
if($ec3->call_count>1) |
|
298 |
{ |
|
299 |
echo "<!-- You can only have one Event Calendar on each page. -->\n"; |
|
300 |
return; |
|
301 |
} |
|
302 |
|
|
303 |
echo "<div id='wp-calendar'>\n"; |
|
304 |
|
|
305 |
$this_month = new ec3_Date(); |
|
306 |
|
|
307 |
// Display navigation panel. |
|
308 |
if(0==$ec3->navigation) |
|
309 |
ec3_get_calendar_nav($this_month,$ec3->num_months); |
|
310 |
|
|
311 |
// Get entries |
|
312 |
$end_month=$this_month->plus_months($ec3->num_months); |
|
313 |
$calendar_days = |
|
314 |
ec3_util_calendar_days( |
|
315 |
$this_month->month_id(), |
|
316 |
$end_month->month_id() |
|
317 |
); |
|
318 |
|
|
319 |
// Display months. |
|
320 |
$thead=ec3_util_thead(); |
|
321 |
for($i=0; $i<$ec3->num_months; $i++) |
|
322 |
{ |
|
323 |
$next_month=$this_month->next_month(); |
|
324 |
ec3_get_calendar_month($this_month,$calendar_days,$thead); |
|
325 |
$this_month=$next_month; |
|
326 |
} |
|
327 |
|
|
328 |
// ------------------------------ |
|
329 |
//modified |
|
330 |
|
|
331 |
echo "</div>\n"; |
|
332 |
|
|
333 |
// Display navigation panel. |
|
334 |
if(1==$ec3->navigation) |
|
335 |
ec3_get_calendar_nav(new ec3_Date(),$ec3->num_months); |
|
336 |
|
|
337 |
|
|
338 |
if(!$ec3->disable_popups) |
|
339 |
echo "\t<script type='text/javascript' src='" |
|
340 |
. $ec3->myfiles . "/popup.js'></script>\n"; |
|
341 |
} |
|
342 |
|
|
343 |
|
|
344 |
/** Substitutes placeholders like '%key%' in $format with 'value' from $data |
|
345 |
* array. */ |
|
346 |
function ec3_format_str($format,$data) |
|
347 |
{ |
|
348 |
foreach($data as $k=>$v) |
|
349 |
$format=str_replace("%$k%",$v,$format); |
|
350 |
echo ("<!-- ".$k."".$v." -->"); |
|
351 |
return $format; |
|
352 |
} |
|
353 |
|
|
354 |
|
|
355 |
define('EC3_DEFAULT_TEMPLATE_EVENT','<a href="%LINK%">%TITLE% (%TIME%)</a>'); |
|
356 |
define('EC3_DEFAULT_TEMPLATE_DAY', '%DATE% :'); |
|
357 |
define('EC3_DEFAULT_DATE_FORMAT', 'j F'); |
|
358 |
define('EC3_DEFAULT_TEMPLATE_MONTH',''); |
|
359 |
define('EC3_DEFAULT_MONTH_FORMAT', 'F Y'); |
|
360 |
|
|
361 |
/** Template function. Call this from your template to insert a list of |
|
362 |
* forthcoming events. Available template variables are: |
|
363 |
* - template_day: %DATE% %SINCE% (only with Time Since plugin) |
|
364 |
* - template_event: %DATE% %TIME% %LINK% %TITLE% %AUTHOR% |
|
365 |
*/ |
|
366 |
|
|
367 |
// version racine |
|
368 |
function ec3_get_events( |
|
369 |
$limit, |
|
370 |
$template_event=EC3_DEFAULT_TEMPLATE_EVENT, |
|
371 |
$template_day =EC3_DEFAULT_TEMPLATE_DAY, |
|
372 |
$date_format =EC3_DEFAULT_DATE_FORMAT, |
|
373 |
$template_month=EC3_DEFAULT_TEMPLATE_MONTH, |
|
374 |
$month_format =EC3_DEFAULT_MONTH_FORMAT) |
|
375 |
{ |
|
376 |
if(!ec3_check_installed(__('Upcoming Events','ec3'))) |
|
377 |
return; |
|
378 |
global $ec3,$wpdb,$wp_version; |
|
379 |
|
|
380 |
// Parse $limit: |
|
381 |
// NUMBER - limits number of posts |
|
382 |
// NUMBER days - next NUMBER of days |
|
383 |
if(empty($limit)) |
|
384 |
{ |
|
385 |
$limit_numposts='LIMIT 5'; |
|
386 |
} |
|
387 |
elseif(preg_match('/^ *([0-9]+) *d(ays?)?/',$limit,$matches)) |
|
388 |
{ |
|
389 |
$secs=intval($matches[1])*24*3600; |
|
390 |
$and_before="AND start<='".ec3_strftime('%Y-%m-%d',time()+$secs)."'"; |
|
391 |
} |
|
392 |
elseif(intval($limit)<1) |
|
393 |
{ |
|
394 |
$limit_numposts='LIMIT 5'; |
|
395 |
} |
|
396 |
else |
|
397 |
{ |
|
398 |
$limit_numposts='LIMIT '.intval($limit); |
|
399 |
} |
|
400 |
|
|
401 |
if(!$date_format) |
|
402 |
$date_format=get_option('date_format'); |
|
403 |
|
|
404 |
// Find the upcoming events. |
|
405 |
$calendar_entries = $wpdb->get_results( |
|
406 |
"SELECT DISTINCT |
|
407 |
p.id AS id, |
|
408 |
post_title, |
|
409 |
start, |
|
410 |
u.$ec3->wp_user_nicename AS author, |
|
411 |
allday |
|
412 |
FROM $ec3->schedule s |
|
413 |
LEFT JOIN $wpdb->posts p ON s.post_id=p.id |
|
414 |
LEFT JOIN $wpdb->users u ON p.post_author = u.id |
|
415 |
WHERE p.post_status='publish' |
|
416 |
AND end>='$ec3->today' $and_before |
|
417 |
ORDER BY start $limit_numposts" |
|
418 |
); |
|
419 |
|
|
420 |
echo "<ul class='ec3_events'>"; |
|
421 |
echo "<!-- Generated by Event Calendar v$ec3->version -->\n"; |
|
422 |
if($calendar_entries) |
|
423 |
{ |
|
424 |
$time_format=get_option('time_format'); |
|
425 |
$current_month=false; |
|
426 |
$current_date=false; |
|
427 |
$data=array(); |
|
428 |
foreach($calendar_entries as $entry) |
|
429 |
{ |
|
430 |
// To use %SINCE%, you need Dunstan's 'Time Since' plugin. |
|
431 |
if(function_exists('time_since')) |
|
432 |
$data['SINCE']=time_since( time(), ec3_to_time($entry->start) ); |
|
433 |
|
|
434 |
// Month changed? |
|
435 |
$data['MONTH']=mysql2date($month_format,$entry->start); |
|
436 |
if((!$current_month || $current_month!=$data['MONTH']) && $template_month) |
|
437 |
{ |
|
438 |
if($current_date) |
|
439 |
echo "</ul></li>\n"; |
|
440 |
if($current_month) |
|
441 |
echo "</ul></li>\n"; |
|
442 |
echo "<li class='ec3_list ec3_list_month'>" |
|
443 |
. ec3_format_str($template_month,$data)."\n<ul>\n"; |
|
444 |
$current_month=$data['MONTH']; |
|
445 |
$current_date=false; |
|
446 |
} |
|
447 |
|
|
448 |
// Date changed? |
|
449 |
$data['DATE'] =mysql2date($date_format, $entry->start); |
|
450 |
if((!$current_date || $current_date!=$data['DATE']) && $template_day) |
|
451 |
{ |
|
452 |
if($current_date) |
|
453 |
echo "</ul></li>\n"; |
|
454 |
echo "<li class='ec3_list ec3_list_day'>" |
|
455 |
. ec3_format_str($template_day,$data)."\n<ul>\n"; |
|
456 |
$current_date=$data['DATE']; |
|
457 |
} |
|
458 |
|
|
459 |
if($entry->allday) |
|
460 |
$data['TIME']=__('all day','ec3'); |
|
461 |
else |
|
462 |
$data['TIME']=mysql2date($time_format,$entry->start); |
|
463 |
|
|
464 |
$data['TITLE'] = |
|
465 |
htmlentities( |
|
466 |
stripslashes(strip_tags($entry->post_title)), |
|
467 |
ENT_QUOTES,get_option('blog_charset') |
|
468 |
); |
|
469 |
$data['LINK'] =get_permalink($entry->id); |
|
470 |
$data['AUTHOR']= |
|
471 |
htmlentities($entry->author,ENT_QUOTES,get_option('blog_charset')); |
|
472 |
echo " <li>".ec3_format_str($template_event,$data)."</li>\n"; |
|
473 |
} |
|
474 |
if($current_date) |
|
475 |
echo "</ul></li>\n"; |
|
476 |
if($current_month) |
|
477 |
echo "</ul></li>\n"; |
|
478 |
} |
|
479 |
else |
|
480 |
{ |
|
481 |
echo "<li>".__('No events.','ec3')."</li>\n"; |
|
482 |
} |
|
483 |
echo "</ul>\n"; |
|
484 |
} |
|
485 |
|
|
486 |
|
|
487 |
// version accordeon by samuel huron |
|
488 |
function ec3_get_events_acc( |
|
489 |
$limit, |
|
490 |
$template_event=EC3_DEFAULT_TEMPLATE_EVENT, |
|
491 |
$template_day =EC3_DEFAULT_TEMPLATE_DAY, |
|
492 |
$date_format =EC3_DEFAULT_DATE_FORMAT, |
|
493 |
$template_month=EC3_DEFAULT_TEMPLATE_MONTH, |
|
494 |
$month_format =EC3_DEFAULT_MONTH_FORMAT) |
|
495 |
{ |
|
496 |
if(!ec3_check_installed(__('Upcoming Events','ec3'))) |
|
497 |
return; |
|
498 |
global $ec3,$wpdb,$wp_version; |
|
499 |
|
|
500 |
// Parse $limit: |
|
501 |
// NUMBER - limits number of posts |
|
502 |
// NUMBER days - next NUMBER of days |
|
503 |
if(empty($limit)) |
|
504 |
{ |
|
505 |
$limit_numposts='LIMIT 5'; |
|
506 |
} |
|
507 |
elseif(preg_match('/^ *([0-9]+) *d(ays?)?/',$limit,$matches)) |
|
508 |
{ |
|
509 |
$secs=intval($matches[1])*24*3600; |
|
510 |
$and_before="AND start<='".ec3_strftime('%Y-%m-%d',time()+$secs)."'"; |
|
511 |
} |
|
512 |
elseif(intval($limit)<1) |
|
513 |
{ |
|
514 |
$limit_numposts='LIMIT 5'; |
|
515 |
} |
|
516 |
else |
|
517 |
{ |
|
518 |
$limit_numposts='LIMIT '.intval($limit); |
|
519 |
} |
|
520 |
|
|
521 |
if(!$date_format) |
|
522 |
$date_format=get_option('date_format'); |
|
523 |
|
|
524 |
// Find the upcoming events. |
|
525 |
$calendar_entries = $wpdb->get_results( |
|
526 |
"SELECT DISTINCT |
|
527 |
p.id AS id, |
|
528 |
post_title, |
|
529 |
start, |
|
530 |
u.$ec3->wp_user_nicename AS author, |
|
531 |
allday |
|
532 |
FROM $ec3->schedule s |
|
533 |
LEFT JOIN $wpdb->posts p ON s.post_id=p.id |
|
534 |
LEFT JOIN $wpdb->users u ON p.post_author = u.id |
|
535 |
WHERE p.post_status='publish' |
|
536 |
AND end>='$ec3->today' $and_before |
|
537 |
ORDER BY start $limit_numposts" |
|
538 |
); |
|
539 |
|
|
540 |
echo "<!-- Generated by Event Calendar v$ec3->version Modified by samuel huron for acc integration -->\n"; |
|
541 |
echo "<ul id='accordion_nav'>"; |
|
542 |
// echo "<li id='test'>test</li>"; |
|
543 |
if($calendar_entries) |
|
544 |
{ |
|
545 |
$time_format=get_option('time_format'); |
|
546 |
$current_month=false; |
|
547 |
$current_date=false; |
|
548 |
$data=array(); |
|
549 |
foreach($calendar_entries as $entry) |
|
550 |
{ |
|
551 |
// To use %SINCE%, you need Dunstan's 'Time Since' plugin. |
|
552 |
if(function_exists('time_since')) |
|
553 |
$data['SINCE']=time_since( time(), ec3_to_time($entry->start) ); |
|
554 |
|
|
555 |
// Month changed? |
|
556 |
$data['MONTH']=mysql2date($month_format,$entry->start); |
|
557 |
if((!$current_month || $current_month!=$data['MONTH']) && $template_month) |
|
558 |
{ |
|
559 |
if($current_date) |
|
560 |
echo "</ul></li>\n"; |
|
561 |
if($current_month) |
|
562 |
$id_accordion=str_replace(" ", "_",ec3_format_str($template_month,$data)); |
|
563 |
$id_accordion=str_replace(":", "",$id_accordion); |
|
564 |
echo " </ul></li>\n"; |
|
565 |
echo "<li id='ec3_list ec3_list_month'> <a href='#".$id_accordion."' class='heading' >".ec3_format_str($template_month,$data)."</a> \n<ul id=".$id_accordion.">\n"; |
|
566 |
$current_month=$data['MONTH']; |
|
567 |
$current_date=false; |
|
568 |
} |
|
569 |
|
|
570 |
|
|
571 |
// Date changed? |
|
572 |
$data['DATE'] =mysql2date($date_format, $entry->start); |
|
573 |
if((!$current_date || $current_date!=$data['DATE']) && $template_day) |
|
574 |
{ |
|
575 |
if($current_date) |
|
576 |
echo "</ul></li>\n"; |
|
577 |
$id_accordion=str_replace(" ", "_",ec3_format_str($template_day,$data)); |
|
578 |
$id_accordion=str_replace(":", "",$id_accordion); |
|
579 |
echo "<li > <a href='#".$id_accordion."' class='heading' >".ec3_format_str($template_day,$data)."</a> \n <ul id=".$id_accordion.">\n"; |
|
580 |
$current_date=$data['DATE']; |
|
581 |
} |
|
582 |
|
|
583 |
if($entry->allday) |
|
584 |
$data['TIME']=__('all day','ec3'); |
|
585 |
else |
|
586 |
$data['TIME']=mysql2date($time_format,$entry->start); |
|
587 |
|
|
588 |
$data['TITLE'] = |
|
589 |
htmlentities( |
|
590 |
stripslashes(strip_tags($entry->post_title)), |
|
591 |
ENT_QUOTES,get_option('blog_charset') |
|
592 |
); |
|
593 |
$data['LINK'] =get_permalink($entry->id); |
|
594 |
$data['AUTHOR']= |
|
595 |
htmlentities($entry->author,ENT_QUOTES,get_option('blog_charset')); |
|
596 |
echo " <li>".ec3_format_str($template_event,$data)."</li>\n"; |
|
597 |
} |
|
598 |
if($current_date) |
|
599 |
echo "</ul></li>\n"; |
|
600 |
if($current_month) |
|
601 |
echo "</ul></li>\n"; |
|
602 |
} |
|
603 |
else |
|
604 |
{ |
|
605 |
echo "<li>".__('No events.','ec3')."</li>\n"; |
|
606 |
} |
|
607 |
echo " \n </ul> \n <div class='ui-helper-clearfix'> </div>"; |
|
608 |
} |
|
609 |
|
|
610 |
// version pour la home by samuel huron |
|
611 |
function ec3_get_events_home( |
|
612 |
$limit, |
|
613 |
$template_event=EC3_DEFAULT_TEMPLATE_EVENT, |
|
614 |
$template_day =EC3_DEFAULT_TEMPLATE_DAY, |
|
615 |
$date_format =EC3_DEFAULT_DATE_FORMAT, |
|
616 |
$template_month=EC3_DEFAULT_TEMPLATE_MONTH, |
|
617 |
$month_format =EC3_DEFAULT_MONTH_FORMAT) |
|
618 |
{ |
|
619 |
if(!ec3_check_installed(__('Upcoming Events','ec3'))) |
|
620 |
return; |
|
621 |
global $ec3,$wpdb,$wp_version; |
|
622 |
|
|
623 |
// Parse $limit: |
|
624 |
// NUMBER - limits number of posts |
|
625 |
// NUMBER days - next NUMBER of days |
|
626 |
if(empty($limit)) |
|
627 |
{ |
|
628 |
$limit_numposts='LIMIT 5'; |
|
629 |
} |
|
630 |
elseif(preg_match('/^ *([0-9]+) *d(ays?)?/',$limit,$matches)) |
|
631 |
{ |
|
632 |
$secs=intval($matches[1])*24*3600; |
|
633 |
$and_before="AND start<='".ec3_strftime('%Y-%m-%d',time()+$secs)."'"; |
|
634 |
} |
|
635 |
elseif(intval($limit)<1) |
|
636 |
{ |
|
637 |
$limit_numposts='LIMIT 5'; |
|
638 |
} |
|
639 |
else |
|
640 |
{ |
|
641 |
$limit_numposts='LIMIT '.intval($limit); |
|
642 |
} |
|
643 |
|
|
644 |
if(!$date_format) |
|
645 |
$date_format = get_option('date_format'); |
|
646 |
|
|
647 |
// echo("<!-- ".get_option('date_format')." -->"); |
|
648 |
|
|
649 |
// Find the upcoming events. |
|
650 |
$calendar_entries = $wpdb->get_results( |
|
651 |
"SELECT DISTINCT |
|
652 |
p.id AS id, |
|
653 |
post_title, |
|
654 |
post_content, |
|
655 |
start, |
|
656 |
u.$ec3->wp_user_nicename AS author, |
|
657 |
allday |
|
658 |
FROM $ec3->schedule s |
|
659 |
LEFT JOIN $wpdb->posts p ON s.post_id=p.id |
|
660 |
LEFT JOIN $wpdb->users u ON p.post_author = u.id |
|
661 |
WHERE p.post_status='publish' |
|
662 |
AND end>='$ec3->today' $and_before |
|
663 |
ORDER BY start $limit_numposts" |
|
664 |
); |
|
665 |
|
|
666 |
echo "<!-- Generated by Event Calendar v$ec3->version Modified by samuel huron for home integration -->\n"; |
|
667 |
echo "<ul>"; |
|
668 |
// echo "<li id='test'>test</li>"; |
|
669 |
if($calendar_entries) |
|
670 |
{ |
|
671 |
$time_format=get_option('time_format'); |
|
672 |
$current_month=false; |
|
673 |
$current_date=false; |
|
674 |
$data=array(); |
|
675 |
foreach($calendar_entries as $entry) |
|
676 |
{ |
|
677 |
// To use %SINCE%, you need Dunstan's 'Time Since' plugin. |
|
678 |
if(function_exists('time_since')) |
|
679 |
$data['SINCE']=time_since( time(), ec3_to_time($entry->start) ); |
|
680 |
|
|
681 |
// Month changed? |
|
682 |
$data['MONTH']=mysql2date($month_format,$entry->start); |
|
683 |
if((!$current_month || $current_month!=$data['MONTH']) && $template_month) |
|
684 |
{ |
|
685 |
if($current_date) |
|
686 |
echo "</ul></li>\n"; |
|
687 |
if($current_month) |
|
688 |
$id_accordion=str_replace(" ", "_",ec3_format_str($template_month,$data)); |
|
689 |
$id_accordion=str_replace(":", "",$id_accordion); |
|
690 |
echo " </ul></li>\n"; |
|
691 |
echo "<li id='ec3_list ec3_list_month'> ".ec3_format_str($template_month,$data)." \n<ul id=".$id_accordion.">\n"; |
|
692 |
echo "<!-- ".$data." -->"; |
|
693 |
$current_month=$data['MONTH']; |
|
694 |
$current_date=false; |
|
695 |
} |
|
696 |
|
|
697 |
|
|
698 |
// Date changed? |
|
699 |
$data['DATE'] =mysql2date($date_format, $entry->start); |
|
700 |
if((!$current_date || $current_date!=$data['DATE']) && $template_day) |
|
701 |
{ |
|
702 |
if($current_date) |
|
703 |
echo "</ul></li>\n"; |
|
704 |
$id_accordion=str_replace(" ", "_",ec3_format_str($template_day,$data)); |
|
705 |
$id_accordion=str_replace(":", "",$id_accordion); |
|
706 |
echo "<li > ".ec3_format_str($template_day,$data).$data['YEAR']." \n <ul id=".$id_accordion.">\n"; |
|
707 |
$current_date=$data['DATE']; |
|
708 |
} |
|
709 |
|
|
710 |
if($entry->allday) |
|
711 |
$data['TIME']=__('all day','ec3'); |
|
712 |
else |
|
713 |
$data['TIME']=mysql2date($time_format,$entry->start); |
|
714 |
|
|
715 |
$data['TITLE'] = |
|
716 |
htmlentities( |
|
717 |
stripslashes(strip_tags($entry->post_title)), |
|
718 |
ENT_QUOTES,get_option('blog_charset') |
|
719 |
); |
|
720 |
$data['RESUME'] = |
|
721 |
htmlentities( |
|
722 |
stripslashes(strip_tags(substr($entry->post_content,0,400)."[...]")), |
|
723 |
ENT_QUOTES,get_option('blog_charset') |
|
724 |
); |
|
725 |
$data['LINK'] =get_permalink($entry->id); |
|
726 |
$data['AUTHOR']= |
|
727 |
htmlentities($entry->author,ENT_QUOTES,get_option('blog_charset')); |
|
728 |
//echo " <li>".ec3_format_str($template_event,$data)."</li>\n"; |
|
729 |
echo " <a href='".$data['LINK']."' nicetitle='".$data['RESUME']."' >".$data['TITLE']."</a>\n"; |
|
730 |
} |
|
731 |
if($current_date) |
|
732 |
echo "</ul></li>\n"; |
|
733 |
if($current_month) |
|
734 |
echo "</ul></li>\n"; |
|
735 |
} |
|
736 |
else |
|
737 |
{ |
|
738 |
echo "<li>".__('No events.','ec3')."</li>\n"; |
|
739 |
} |
|
740 |
echo " \n </ul> \n"; |
|
741 |
} |
|
742 |
|
|
743 |
|
|
744 |
define('EC3_DEFAULT_FORMAT_SINGLE','<tr><td colspan="3">%s</td></tr>'); |
|
745 |
define('EC3_DEFAULT_FORMAT_RANGE','<tr><td class="ec3_start">%1$s</td>' |
|
746 |
. '<td class="ec3_to">%3$s</td><td class="ec3_end">%2$s</td></tr>'); |
|
747 |
define('EC3_DEFAULT_FORMAT_WRAPPER','<table class="ec3_schedule">%s</table>'); |
|
748 |
|
|
749 |
/** Formats the schedule for the current post. |
|
750 |
* Returns the HTML fragment as a string. */ |
|
751 |
function ec3_get_schedule( |
|
752 |
$format_single =EC3_DEFAULT_FORMAT_SINGLE, |
|
753 |
$format_range =EC3_DEFAULT_FORMAT_RANGE, |
|
754 |
$format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER |
|
755 |
) |
|
756 |
{ |
|
757 |
global $ec3,$post; |
|
758 |
// Should have been set by ec3_filter_the_posts() |
|
759 |
if(!$post || !$post->ec3_schedule) |
|
760 |
return ''; |
|
761 |
$result=''; |
|
762 |
$date_format=get_option('date_format'); |
|
763 |
$time_format=get_option('time_format'); |
|
764 |
$current=false; |
|
765 |
foreach($post->ec3_schedule as $s) |
|
766 |
{ |
|
767 |
$date_start=mysql2date($date_format,$s->start); |
|
768 |
$date_end =mysql2date($date_format,$s->end); |
|
769 |
$time_start=mysql2date($time_format,$s->start); |
|
770 |
$time_end =mysql2date($time_format,$s->end); |
|
771 |
|
|
772 |
if($s->allday) |
|
773 |
{ |
|
774 |
if($date_start!=$date_end) |
|
775 |
{ |
|
776 |
$result.=sprintf($format_range,$date_start,$date_end,__('to','ec3')); |
|
777 |
} |
|
778 |
elseif($date_start!=$current) |
|
779 |
{ |
|
780 |
$current=$date_start; |
|
781 |
$result.=sprintf($format_single,$date_start); |
|
782 |
} |
|
783 |
} |
|
784 |
else |
|
785 |
{ |
|
786 |
if($date_start!=$date_end) |
|
787 |
{ |
|
788 |
$current=$date_start; |
|
789 |
$result.=sprintf($format_range, |
|
790 |
"$date_start $time_start","$date_end $time_end",__('to','ec3')); |
|
791 |
} |
|
792 |
else |
|
793 |
{ |
|
794 |
if($date_start!=$current) |
|
795 |
{ |
|
796 |
$current=$date_start; |
|
797 |
$result.=sprintf($format_single,$date_start); |
|
798 |
} |
|
799 |
if($time_start==$time_end) |
|
800 |
$result.=sprintf($format_single,$time_start); |
|
801 |
else |
|
802 |
$result.=sprintf($format_range,$time_start,$time_end,__('to','ec3')); |
|
803 |
} |
|
804 |
} |
|
805 |
} |
|
806 |
return sprintf($format_wrapper,$result); |
|
807 |
} |
|
808 |
|
|
809 |
|
|
810 |
/** Echos the schedule for the current post. */ |
|
811 |
function ec3_the_schedule( |
|
812 |
$format_single =EC3_DEFAULT_FORMAT_SINGLE, |
|
813 |
$format_range =EC3_DEFAULT_FORMAT_RANGE, |
|
814 |
$format_wrapper=EC3_DEFAULT_FORMAT_WRAPPER |
|
815 |
) |
|
816 |
{ |
|
817 |
echo ec3_get_schedule($format_single,$format_range,$format_wrapper); |
|
818 |
} |
|
819 |
|
|
820 |
?> |