136
|
1 |
<?php |
|
2 |
/* |
|
3 |
Plugin Name: Event Calendar |
|
4 |
Version: 3.1.4 |
|
5 |
Plugin URI: http://wpcal.firetree.net |
|
6 |
Description: Manage future events as an online calendar. Display upcoming events in a dynamic calendar, on a listings page, or as a list in the sidebar. You can subscribe to the calendar from iCal (OSX) or Sunbird. Change settings on the <a href="options-general.php?page=ec3_admin">Event Calendar Options</a> screen. |
|
7 |
Author: Alex Tingle |
|
8 |
Author URI: http://blog.firetree.net/ |
|
9 |
*/ |
|
10 |
|
|
11 |
/* |
|
12 |
Copyright (c) 2005-2008, Alex Tingle. |
|
13 |
|
|
14 |
This program is free software; you can redistribute it and/or |
|
15 |
modify it under the terms of the GNU General Public License |
|
16 |
as published by the Free Software Foundation; either version 2 |
|
17 |
of the License, or (at your option) any later version. |
|
18 |
|
|
19 |
This program is distributed in the hope that it will be useful, |
|
20 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
GNU General Public License for more details. |
|
23 |
|
|
24 |
You should have received a copy of the GNU General Public License |
|
25 |
along with this program; if not, write to the Free Software |
|
26 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
27 |
*/ |
|
28 |
|
|
29 |
require_once(dirname(__FILE__).'/options.php'); |
|
30 |
require_once(dirname(__FILE__).'/date.php'); |
|
31 |
require_once(dirname(__FILE__).'/day.php'); |
|
32 |
require_once(dirname(__FILE__).'/template-functions.php'); |
|
33 |
require_once(dirname(__FILE__).'/admin.php'); |
|
34 |
require_once(dirname(__FILE__).'/tz.php'); |
|
35 |
|
|
36 |
|
|
37 |
$ec3_today_id=str_replace('_0','_',ec3_strftime("ec3_%Y_%m_%d")); |
|
38 |
|
|
39 |
|
|
40 |
/** Read the schedule table for the posts, and add an ec3_schedule array |
|
41 |
* to each post. */ |
|
42 |
function ec3_filter_the_posts($posts) |
|
43 |
{ |
|
44 |
if('array'!=gettype($posts) || 0==count($posts)) |
|
45 |
return $posts; |
|
46 |
|
|
47 |
$post_ids=array(); |
|
48 |
// Can't use foreach, because it gets *copies* (in PHP<5) |
|
49 |
for($i=0; $i<count($posts); $i++) |
|
50 |
{ |
|
51 |
$post_ids[]=intval($posts[$i]->ID); |
|
52 |
$posts[$i]->ec3_schedule=array(); |
|
53 |
} |
|
54 |
global $ec3,$wp_query,$wpdb; |
|
55 |
$schedule=$wpdb->get_results( |
|
56 |
"SELECT post_id,start,end,allday,rpt,IF(end>='$ec3->today',1,0) AS active |
|
57 |
FROM $ec3->schedule |
|
58 |
WHERE post_id IN (".implode(',',$post_ids).") |
|
59 |
ORDER BY start" |
|
60 |
); |
|
61 |
// Flip $post_ids so that it maps post ID to position in the $posts array. |
|
62 |
$post_ids=array_flip($post_ids); |
|
63 |
if($post_ids && $schedule) |
|
64 |
foreach($schedule as $s) |
|
65 |
{ |
|
66 |
$i=$post_ids[$s->post_id]; |
|
67 |
$posts[$i]->ec3_schedule[]=$s; |
|
68 |
} |
|
69 |
return $posts; |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
function ec3_action_wp_head() |
|
74 |
{ |
|
75 |
global $ec3,$month,$month_abbrev; |
|
76 |
?> |
|
77 |
|
|
78 |
<!-- Added by EventCalendar plugin. Version <?php echo $ec3->version; ?> --> |
|
79 |
<script type='text/javascript' src='<?php echo $ec3->myfiles; ?>/xmlhttprequest.js'></script> |
|
80 |
<script type='text/javascript' src='<?php echo $ec3->myfiles; ?>/ec3.js'></script> |
|
81 |
<script type='text/javascript'><!-- |
|
82 |
ec3.start_of_week=<?php echo intval( get_option('start_of_week') ); ?>; |
|
83 |
ec3.month_of_year=new Array('<?php echo implode("','",$month); ?>'); |
|
84 |
ec3.month_abbrev=new Array('<?php echo implode("','",$month_abbrev); ?>'); |
|
85 |
ec3.myfiles='<?php echo $ec3->myfiles; ?>'; |
|
86 |
ec3.home='<?php echo get_option('home'); ?>'; |
|
87 |
ec3.hide_logo=<?php echo $ec3->hide_logo; ?>; |
|
88 |
ec3.viewpostsfor="<?php echo __('View posts for %1$s %2$s'); ?>"; |
|
89 |
// --></script> |
|
90 |
|
|
91 |
<?php if(!$ec3->nocss): ?> |
|
92 |
<style type='text/css' media='screen'> |
|
93 |
@import url(<?php echo $ec3->myfiles; ?>/ec3.css); |
|
94 |
.ec3_ec { |
|
95 |
background-image:url(<?php echo $ec3->myfiles; ?>/ec.png) !IMPORTANT; |
|
96 |
background-image:none; |
|
97 |
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='<?php echo $ec3->myfiles; ?>/ec.png'); |
|
98 |
} |
|
99 |
<?php if(!$ec3->disable_popups): ?> |
|
100 |
#ec3_shadow0 { |
|
101 |
background-image:url(<?php echo $ec3->myfiles; ?>/shadow0.png) !IMPORTANT; |
|
102 |
background-image:none; |
|
103 |
} |
|
104 |
#ec3_shadow0 div { |
|
105 |
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='<?php echo $ec3->myfiles; ?>/shadow0.png',sizingMethod='scale'); |
|
106 |
} |
|
107 |
#ec3_shadow1 { |
|
108 |
background-image:url(<?php echo $ec3->myfiles; ?>/shadow1.png) !IMPORTANT; |
|
109 |
background-image:none; |
|
110 |
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='<?php echo $ec3->myfiles; ?>/shadow1.png',sizingMethod='crop'); |
|
111 |
} |
|
112 |
#ec3_shadow2 { |
|
113 |
background-image:url(<?php echo $ec3->myfiles; ?>/shadow2.png) !IMPORTANT; |
|
114 |
background-image:none; |
|
115 |
} |
|
116 |
#ec3_shadow2 div { |
|
117 |
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='<?php echo $ec3->myfiles; ?>/shadow2.png',sizingMethod='scale'); |
|
118 |
} |
|
119 |
<?php endif; ?> |
|
120 |
</style> |
|
121 |
|
|
122 |
<?php endif; |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
/** Turn OFF advanced mode when we're in the admin screens. */ |
|
127 |
function ec3_action_admin_head() |
|
128 |
{ |
|
129 |
global $ec3; |
|
130 |
$ec3->advanced=false; |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
/** Rewrite date restrictions if the query is day- or category- specific. */ |
|
135 |
function ec3_filter_posts_where($where) |
|
136 |
{ |
|
137 |
global $ec3,$wp_query,$wpdb; |
|
138 |
|
|
139 |
// To prevent breaking prior to WordPress v2.3 |
|
140 |
if(function_exists('get_the_tags') && $wp_query->is_tag) |
|
141 |
return $where; |
|
142 |
|
|
143 |
if($wp_query->is_page || $wp_query->is_single || $wp_query->is_admin) |
|
144 |
return $where; |
|
145 |
|
|
146 |
if($wp_query->is_date): |
|
147 |
|
|
148 |
// Transfer events' 'post_date' restrictions to 'start' |
|
149 |
$df='YEAR|MONTH|DAYOFMONTH|HOUR|MINUTE|SECOND|WEEK'; // date fields |
|
150 |
$re="/ AND (($df)\($wpdb->posts\.post_date(,[^\)]+)?\) *= *('[^']+'|\d+\b))/i"; |
|
151 |
if(preg_match_all($re,$where,$matches)): |
|
152 |
$where_post_date = implode(' AND ',$matches[1]); |
|
153 |
|
|
154 |
$rdate=array(0,0,0); |
|
155 |
$rtime=array(0,0,0); |
|
156 |
for($i=0; $i<count($matches[1]); $i++) |
|
157 |
{ |
|
158 |
if( 'YEAR'==$matches[2][$i]) $rdate[0]=$matches[4][$i]; |
|
159 |
elseif( 'MONTH'==$matches[2][$i]) $rdate[1]=$matches[4][$i]; |
|
160 |
elseif('DAYOFMONTH'==$matches[2][$i]) $rdate[2]=$matches[4][$i]; |
|
161 |
elseif( 'HOUR'==$matches[2][$i]) $rtime[0]=$matches[4][$i]; |
|
162 |
elseif( 'MINUTE'==$matches[2][$i]) $rtime[1]=$matches[4][$i]; |
|
163 |
elseif( 'SECOND'==$matches[2][$i]) $rtime[2]=$matches[4][$i]; |
|
164 |
} |
|
165 |
// start either matches the date criteria, |
|
166 |
// OR the rdate/rtime is between start..end: |
|
167 |
$where_start= |
|
168 |
sprintf("(%1\$s) OR (start<='%2\$s' AND end>='%2\$s')", |
|
169 |
preg_replace("/\b$wpdb->posts\.post_date\b/",'start',$where_post_date), |
|
170 |
str_replace( "'", '', implode('-',$rdate).' '.implode(':',$rtime) ) |
|
171 |
); |
|
172 |
|
|
173 |
$where=preg_replace($re,'',$where); |
|
174 |
if(is_category($ec3->event_category)): |
|
175 |
$where.=" AND ($where_start) "; |
|
176 |
$ec3->order_by_start=true; |
|
177 |
else: |
|
178 |
$where.=" AND (($where_post_date) OR ($where_start)) "; |
|
179 |
endif; |
|
180 |
$ec3->join_ec3_sch=true; |
|
181 |
endif; |
|
182 |
|
|
183 |
elseif($ec3->is_date_range): |
|
184 |
|
|
185 |
$where_start=array(); |
|
186 |
if( !empty($ec3->range_from) ) |
|
187 |
$where_start[]="end>='$ec3->range_from'"; |
|
188 |
if( !empty($ec3->range_before) ) |
|
189 |
$where_start[]="start<='$ec3->range_before'"; |
|
190 |
|
|
191 |
if($where_start): |
|
192 |
$where_start=implode(' AND ',$where_start); |
|
193 |
$where.=" AND ($where_start AND ec3_sch.post_id IS NOT NULL) "; |
|
194 |
$ec3->order_by_start=true; |
|
195 |
$ec3->join_ec3_sch=true; |
|
196 |
endif; |
|
197 |
|
|
198 |
elseif($ec3->advanced): |
|
199 |
if(is_category($ec3->event_category)): |
|
200 |
|
|
201 |
// Hide inactive events |
|
202 |
$where.=" AND ec3_sch.post_id IS NOT NULL "; |
|
203 |
$ec3->join_ec3_sch=true; |
|
204 |
$ec3->join_only_active_events=true; |
|
205 |
$ec3->order_by_start=true; |
|
206 |
global $wp; |
|
207 |
$wp->did_permalink=false; // Allows zero results without -> 404 |
|
208 |
|
|
209 |
elseif($wp_query->is_search): |
|
210 |
|
|
211 |
$where.=' AND (ec3_sch.post_id IS NULL OR ' |
|
212 |
."ec3_sch.end>='$ec3->today')"; |
|
213 |
$ec3->join_ec3_sch=true; |
|
214 |
|
|
215 |
elseif(!$wp_query->is_category): |
|
216 |
|
|
217 |
// Hide all events |
|
218 |
$where.=" AND ec3_sch.post_id IS NULL "; |
|
219 |
$ec3->join_ec3_sch=true; |
|
220 |
|
|
221 |
endif; |
|
222 |
endif; |
|
223 |
|
|
224 |
return $where; |
|
225 |
} |
|
226 |
|
|
227 |
/** */ |
|
228 |
function ec3_filter_posts_join($join) |
|
229 |
{ |
|
230 |
global $ec3,$wpdb; |
|
231 |
// The necessary joins are decided upon in ec3_filter_posts_where(). |
|
232 |
if($ec3->join_ec3_sch || $ec3->order_by_start) |
|
233 |
{ |
|
234 |
$join.=" LEFT JOIN $ec3->schedule ec3_sch ON ec3_sch.post_id=id "; |
|
235 |
if($ec3->join_only_active_events) |
|
236 |
$join.="AND ec3_sch.end>='$ec3->today' "; |
|
237 |
} |
|
238 |
return $join; |
|
239 |
} |
|
240 |
|
|
241 |
/** Change the order of event listings (only advanced mode). */ |
|
242 |
function ec3_filter_posts_orderby($orderby) |
|
243 |
{ |
|
244 |
global $ec3, $wpdb; |
|
245 |
if($ec3->order_by_start) |
|
246 |
{ |
|
247 |
$regexp="/(?<!DATE_FORMAT[(])\b$wpdb->posts\.post_date\b( DESC\b| ASC\b)?/i"; |
|
248 |
if(preg_match($regexp,$orderby,$match)) |
|
249 |
{ |
|
250 |
if($match[1] && $match[1]==' DESC') |
|
251 |
$orderby=preg_replace($regexp,'ec3_sch.start',$orderby); |
|
252 |
else |
|
253 |
$orderby=preg_replace($regexp,'ec3_sch.start DESC',$orderby); |
|
254 |
} |
|
255 |
else |
|
256 |
{ |
|
257 |
// Someone's been playing around with the orderby - just overwrite it. |
|
258 |
$orderby='ec3_sch.start'; |
|
259 |
} |
|
260 |
} |
|
261 |
return $orderby; |
|
262 |
} |
|
263 |
|
|
264 |
|
|
265 |
/** Eliminate double-listings for posts with >1 scheduled event. */ |
|
266 |
function ec3_filter_posts_groupby($groupby) |
|
267 |
{ |
|
268 |
global $ec3,$wpdb; |
|
269 |
if($ec3->join_ec3_sch || $ec3->order_by_start) |
|
270 |
{ |
|
271 |
if(empty($groupby)) |
|
272 |
$groupby="{$wpdb->posts}.ID"; |
|
273 |
if($ec3->is_listing) |
|
274 |
$groupby.=',ec3_sch.sched_id'; |
|
275 |
} |
|
276 |
return $groupby; |
|
277 |
} |
|
278 |
|
|
279 |
|
|
280 |
/** Add a sched_id field, if we want a listing. */ |
|
281 |
function ec3_filter_posts_fields($fields) |
|
282 |
{ |
|
283 |
global $ec3; |
|
284 |
if($ec3->is_listing && ($ec3->join_ec3_sch || $ec3->order_by_start)) |
|
285 |
$fields.=',ec3_sch.sched_id'; |
|
286 |
return $fields; |
|
287 |
} |
|
288 |
|
|
289 |
|
|
290 |
function ec3_filter_query_vars($wpvarstoreset) |
|
291 |
{ |
|
292 |
if(isset($_GET['ec3_xml'])) |
|
293 |
ec3_filter_query_vars_xml(); |
|
294 |
if(isset($_GET['ec3_ical']) || isset($_GET['ec3_vcal'])) |
|
295 |
ec3_filter_query_vars_ical(); |
|
296 |
if(isset($_GET['ec3_dump'])) |
|
297 |
ec3_filter_query_vars_dump(); |
|
298 |
// else... |
|
299 |
$wpvarstoreset[]='ec3_today'; |
|
300 |
$wpvarstoreset[]='ec3_days'; |
|
301 |
$wpvarstoreset[]='ec3_from'; // ?? Deprecated |
|
302 |
$wpvarstoreset[]='ec3_after'; |
|
303 |
$wpvarstoreset[]='ec3_before'; |
|
304 |
$wpvarstoreset[]='ec3_listing'; |
|
305 |
// Turn-off broken canonical redirection when both m= & cat= are set. |
|
306 |
if(isset($_GET['m']) && isset($_GET['cat'])) |
|
307 |
remove_action('template_redirect','redirect_canonical'); |
|
308 |
return $wpvarstoreset; |
|
309 |
} |
|
310 |
|
|
311 |
|
|
312 |
/** If the parameter ec3_xml is set, then brutally hijack the page and replace |
|
313 |
* it with XML calendar data. This is used by XmlHttpRequests from the |
|
314 |
* active calendar JavaScript. */ |
|
315 |
function ec3_filter_query_vars_xml() |
|
316 |
{ |
|
317 |
$components=explode('_',$_GET['ec3_xml']); |
|
318 |
if(count($components)==2) |
|
319 |
{ |
|
320 |
$date=new ec3_Date($components[0],$components[1]); |
|
321 |
$end=$date->next_month(); |
|
322 |
$calendar_days=ec3_util_calendar_days($date->month_id(),$end->month_id()); |
|
323 |
@header('Content-type: text/xml'); |
|
324 |
echo '<?xml version="1.0" encoding="'.get_option('blog_charset') |
|
325 |
. '" standalone="yes"?>'; |
|
326 |
echo "<calendar><month id='".$date->month_id()."'>\n"; |
|
327 |
foreach($calendar_days as $day_id=>$day) |
|
328 |
{ |
|
329 |
if('today'==$day_id) |
|
330 |
$dc=explode('_', ec3_strftime(":_%Y_%m_%d") ); |
|
331 |
else |
|
332 |
$dc=explode('_',$day_id); |
|
333 |
if(count($dc)==4) |
|
334 |
{ |
|
335 |
$date->day_num=$dc[3]; |
|
336 |
$titles=$day->get_titles(); |
|
337 |
echo "<day id='$day_id' is_event='$day->is_event'" |
|
338 |
. " titles='$titles' link='" . $date->day_link() . "'/>\n"; |
|
339 |
} |
|
340 |
} |
|
341 |
echo "</month></calendar>\n"; |
|
342 |
exit(0); |
|
343 |
} |
|
344 |
} |
|
345 |
|
|
346 |
|
|
347 |
/** If the parameter ec3_ical is set, then brutally hijack the page and replace |
|
348 |
* it with iCalendar data. |
|
349 |
* (Includes fixes contributed by Matthias Tarasiewicz & Marc Schumann.)*/ |
|
350 |
function ec3_filter_query_vars_ical($wpvarstoreset=NULL) |
|
351 |
{ |
|
352 |
// |
|
353 |
// Generate the iCalendar |
|
354 |
|
|
355 |
$name=preg_replace('/([\\,;])/','\\\\$1',get_bloginfo_rss('name')); |
|
356 |
$filename=preg_replace('/[^0-9a-zA-Z]/','',$name).'.ics'; |
|
357 |
|
|
358 |
header("Content-Type: text/calendar; charset=" . get_option('blog_charset')); |
|
359 |
header("Content-Disposition: inline; filename=$filename"); |
|
360 |
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); |
|
361 |
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
362 |
header('Cache-Control: no-cache, must-revalidate, max-age=0'); |
|
363 |
header('Pragma: no-cache'); |
|
364 |
|
|
365 |
echo "BEGIN:VCALENDAR\r\n"; |
|
366 |
echo "VERSION:2.0\r\n"; |
|
367 |
echo "X-WR-CALNAME:$name\r\n"; |
|
368 |
|
|
369 |
global $ec3,$wpdb; |
|
370 |
|
|
371 |
$calendar_entries = $wpdb->get_results( |
|
372 |
"SELECT |
|
373 |
post_id, |
|
374 |
sched_id, |
|
375 |
post_title, |
|
376 |
post_excerpt, |
|
377 |
DATE_FORMAT(start,IF(allday,'%Y%m%d','%Y-%m-%d %H:%i')) AS dt_start, |
|
378 |
IF( allday, |
|
379 |
DATE_FORMAT(DATE_ADD(end, INTERVAL 1 DAY),'%Y%m%d'), |
|
380 |
DATE_FORMAT(end,'%Y-%m-%d %H:%i') |
|
381 |
) AS dt_end, |
|
382 |
$ec3->wp_user_nicename AS user_nicename, |
|
383 |
IF(allday,'TRANSPARENT','OPAQUE') AS transp, |
|
384 |
allday |
|
385 |
FROM $wpdb->posts p |
|
386 |
LEFT JOIN $wpdb->users u ON p.post_author=u.ID |
|
387 |
INNER JOIN $ec3->schedule s ON p.id=s.post_id |
|
388 |
WHERE post_status='publish' |
|
389 |
ORDER BY start" |
|
390 |
); |
|
391 |
|
|
392 |
if($calendar_entries) |
|
393 |
foreach($calendar_entries as $entry) |
|
394 |
{ |
|
395 |
// ?? Should add line folding at 75 octets at some time as per RFC 2445. |
|
396 |
$summary=preg_replace('/([\\,;])/','\\\\$1',$entry->post_title); |
|
397 |
$permalink=get_permalink($entry->post_id); |
|
398 |
|
|
399 |
echo "BEGIN:VEVENT\r\n"; |
|
400 |
echo "SUMMARY:$summary\r\n"; |
|
401 |
echo "URL;VALUE=URI:$permalink\r\n"; |
|
402 |
echo "UID:$entry->sched_id-$permalink\r\n"; |
|
403 |
$description=''; |
|
404 |
if(strlen($entry->post_excerpt)>0) |
|
405 |
{ |
|
406 |
// I can't get iCal to understand iCalendar encoding. |
|
407 |
// So just strip out newlines here: |
|
408 |
$description=preg_replace('/[ \r\n]+/',' ',$entry->post_excerpt.' '); |
|
409 |
$description=preg_replace('/([\\,;])/','\\\\$1',$description); |
|
410 |
} |
|
411 |
$description.='['.sprintf(__('by: %s'),$entry->user_nicename).']'; |
|
412 |
echo "DESCRIPTION:$description\r\n"; |
|
413 |
echo "TRANSP:$entry->transp\r\n"; // for availability. |
|
414 |
if($entry->allday) |
|
415 |
{ |
|
416 |
echo "DTSTART;VALUE=DATE:$entry->dt_start\r\n"; |
|
417 |
echo "DTEND;VALUE=DATE:$entry->dt_end\r\n"; |
|
418 |
} |
|
419 |
else |
|
420 |
{ |
|
421 |
// Convert timestamps to UTC |
|
422 |
echo sprintf("DTSTART;VALUE=DATE-TIME:%s\r\n",ec3_to_utc($entry->dt_start)); |
|
423 |
echo sprintf("DTEND;VALUE=DATE-TIME:%s\r\n",ec3_to_utc($entry->dt_end)); |
|
424 |
} |
|
425 |
echo "END:VEVENT\r\n"; |
|
426 |
} |
|
427 |
|
|
428 |
echo "END:VCALENDAR\r\n"; |
|
429 |
exit(0); |
|
430 |
} |
|
431 |
|
|
432 |
|
|
433 |
/** Test function. Helps to diagnose problems. |
|
434 |
* The output from this feature has been chosen to NOT reveal any private |
|
435 |
* information, yet be of real use for debugging. |
|
436 |
*/ |
|
437 |
function ec3_filter_query_vars_dump($wpvarstoreset=NULL) |
|
438 |
{ |
|
439 |
global $ec3, $wpdb; |
|
440 |
echo "<pre>\n"; |
|
441 |
echo "POSTS:\n"; |
|
442 |
print_r( $wpdb->get_results( |
|
443 |
"SELECT ID,post_date,post_date_gmt,post_status,post_name,post_modified, |
|
444 |
post_modified_gmt,post_type |
|
445 |
FROM $wpdb->posts ORDER BY ID" |
|
446 |
)); |
|
447 |
if($ec3->wp_have_categories) |
|
448 |
{ |
|
449 |
echo "POST2CAT:\n"; |
|
450 |
print_r($wpdb->get_results("SELECT * FROM $wpdb->post2cat ORDER BY post_id")); |
|
451 |
} |
|
452 |
echo "EC3_SCHEDULE:\n"; |
|
453 |
print_r($wpdb->get_results("SELECT * FROM $ec3->schedule ORDER BY post_id")); |
|
454 |
echo "EC3 OPTIONS:\n"; |
|
455 |
print_r($wpdb->get_results( |
|
456 |
"SELECT option_name,option_value |
|
457 |
FROM $wpdb->options WHERE option_name LIKE 'ec3_%'" |
|
458 |
)); |
|
459 |
echo "ACTIVE PLUGINS:\n"; |
|
460 |
print_r( $wpdb->get_var( |
|
461 |
"SELECT option_value |
|
462 |
FROM $wpdb->options WHERE option_name='active_plugins'" |
|
463 |
)); |
|
464 |
echo "</pre>\n"; |
|
465 |
exit(0); |
|
466 |
} |
|
467 |
|
|
468 |
|
|
469 |
/** Add support for new query vars: |
|
470 |
* |
|
471 |
* - ec3_today : sets date to today. |
|
472 |
* - ec3_days=N : Finds events for the next N days. |
|
473 |
* - ec3_after=YYYY-MM-DD : limits search to events on or after YYYY-MM-DD. |
|
474 |
* - ec3_before=YYYY-MM-DD : limits search to events on or before YYYY-MM-DD. |
|
475 |
*/ |
|
476 |
function ec3_filter_parse_query($wp_query) |
|
477 |
{ |
|
478 |
global $ec3; |
|
479 |
// query_posts() can be called multiple times. So reset all our variables. |
|
480 |
$ec3->reset_query(); |
|
481 |
// Deal with EC3-specific parameters. |
|
482 |
if( !empty($wp_query->query_vars['ec3_listing']) ) |
|
483 |
{ |
|
484 |
$ec3->is_listing=true; |
|
485 |
} |
|
486 |
if( !empty($wp_query->query_vars['ec3_today']) ) |
|
487 |
{ |
|
488 |
// Force the value of 'm' to today's date. |
|
489 |
$wp_query->query_vars['m']=ec3_strftime('%Y%m%d'); |
|
490 |
$wp_query->is_date=true; |
|
491 |
$wp_query->is_day=true; |
|
492 |
$wp_query->is_month=true; |
|
493 |
$wp_query->is_year=true; |
|
494 |
$ec3->is_today=true; |
|
495 |
return; |
|
496 |
} |
|
497 |
if( !empty($wp_query->query_vars['ec3_days']) ) |
|
498 |
{ |
|
499 |
// Show the next N days. |
|
500 |
$ec3->days=intval($wp_query->query_vars['ec3_days']); |
|
501 |
$secs=$ec3->days*24*3600; |
|
502 |
$wp_query->query_vars['ec3_after' ]=ec3_strftime('%Y_%m_%d'); |
|
503 |
$wp_query->query_vars['ec3_before']=ec3_strftime('%Y_%m_%d',time()+$secs); |
|
504 |
} |
|
505 |
|
|
506 |
// Get values (if any) for after ($a) & before ($b). |
|
507 |
if( !empty($wp_query->query_vars['ec3_after']) ) |
|
508 |
$a=$wp_query->query_vars['ec3_after']; |
|
509 |
else if( !empty($wp_query->query_vars['ec3_from']) ) |
|
510 |
$a=$wp_query->query_vars['ec3_from']; |
|
511 |
|
|
512 |
// clean by sam |
|
513 |
if(!empty($wp_query->query_vars['ec3_before'])){ |
|
514 |
$b=$wp_query->query_vars['ec3_before']; |
|
515 |
} |
|
516 |
|
|
517 |
// clean by sam |
|
518 |
if( !empty($a)){ |
|
519 |
if( $a=='today' ) |
|
520 |
{$a=ec3_strftime('%Y-%m-%d');} |
|
521 |
} |
|
522 |
// clean by sam |
|
523 |
if( !empty($a)){ |
|
524 |
if( $b=='today' ) |
|
525 |
{$b=ec3_strftime('%Y-%m-%d');} |
|
526 |
} |
|
527 |
$re='/\d\d\d\d[-_]\d?\d[-_]\d?\d/'; |
|
528 |
if( !empty($a) && preg_match($re,$a) || |
|
529 |
!empty($b) && preg_match($re,$b) ) |
|
530 |
{ |
|
531 |
// Kill any other date parameters. |
|
532 |
foreach(array('m','second','minute','hour','day','monthnum','year','w') |
|
533 |
as $param) |
|
534 |
{ |
|
535 |
unset($wp_query->query_vars[$param]); |
|
536 |
} |
|
537 |
$wp_query->is_date=false; |
|
538 |
$wp_query->is_time=false; |
|
539 |
$wp_query->is_day=false; |
|
540 |
$wp_query->is_month=false; |
|
541 |
$wp_query->is_year=false; |
|
542 |
$ec3->is_date_range=true; |
|
543 |
$ec3->range_from =$a; |
|
544 |
$ec3->range_before=$b; |
|
545 |
} |
|
546 |
} |
|
547 |
|
|
548 |
|
|
549 |
function ec3_filter_the_content(&$post_content) |
|
550 |
{ |
|
551 |
return ec3_get_schedule() . $post_content; |
|
552 |
} |
|
553 |
|
|
554 |
|
|
555 |
/** Replaces default wp_trim_excerpt filter. Fakes an excerpt if needed. |
|
556 |
* Adds a textual summary of the schedule to the excerpt.*/ |
|
557 |
function ec3_get_the_excerpt($text) |
|
558 |
{ |
|
559 |
global $post; |
|
560 |
|
|
561 |
if(empty($text)) |
|
562 |
{ |
|
563 |
$text=$post->post_content; |
|
564 |
if(!$post->ec3_schedule) |
|
565 |
$text=apply_filters('the_content', $text); |
|
566 |
$text=str_replace(']]>', ']]>', $text); |
|
567 |
$text=strip_tags($text); |
|
568 |
$excerpt_length=55; |
|
569 |
$words=explode(' ', $text, $excerpt_length + 1); |
|
570 |
if(count($words) > $excerpt_length) |
|
571 |
{ |
|
572 |
array_pop($words); |
|
573 |
array_push($words, '[...]'); |
|
574 |
$text=implode(' ', $words); |
|
575 |
} |
|
576 |
} |
|
577 |
|
|
578 |
if($post->ec3_schedule) |
|
579 |
{ |
|
580 |
$schedule=ec3_get_schedule('%s; ',"%1\$s %3\$s %2\$s. ",'[ %s] '); |
|
581 |
/* $text=$schedule.$text;*/ |
|
582 |
} |
|
583 |
|
|
584 |
return $text; |
|
585 |
} |
|
586 |
|
|
587 |
|
|
588 |
// |
|
589 |
// Hook in... |
|
590 |
if($ec3->event_category) |
|
591 |
{ |
|
592 |
add_action('wp_head', 'ec3_action_wp_head'); |
|
593 |
add_action('admin_head', 'ec3_action_admin_head'); |
|
594 |
add_filter('query_vars', 'ec3_filter_query_vars'); |
|
595 |
add_filter('parse_query', 'ec3_filter_parse_query'); |
|
596 |
add_filter('posts_where', 'ec3_filter_posts_where',11); |
|
597 |
add_filter('posts_join', 'ec3_filter_posts_join'); |
|
598 |
add_filter('posts_groupby','ec3_filter_posts_groupby'); |
|
599 |
add_filter('posts_fields', 'ec3_filter_posts_fields'); |
|
600 |
add_filter('the_posts', 'ec3_filter_the_posts'); |
|
601 |
|
|
602 |
if(!$ec3->hide_event_box) |
|
603 |
add_filter('the_content','ec3_filter_the_content',20); |
|
604 |
|
|
605 |
remove_filter('get_the_excerpt', 'wp_trim_excerpt'); |
|
606 |
add_filter('get_the_excerpt', 'ec3_get_the_excerpt'); |
|
607 |
|
|
608 |
if($ec3->advanced) |
|
609 |
add_filter('posts_orderby','ec3_filter_posts_orderby',11); |
|
610 |
} |
|
611 |
|
|
612 |
?> |