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.1.1 6.5.1.4 4.6.10 6.5.1.5 4.6.10.2 6.5.1.6 4.6.11 6.5.2 4.6.11.2 6.6.0 4.6.12.1 6.6.0.1 4.6.13.1 6.6.0.2 4.6.14 6.6.1 4.6.14.2 6.6.2 4.6.15.1 6.6.3 4.6.16.1 6.6.4 4.6.17.1 6.6.4.1 4.6.18.1 6.6.4.2 4.6.19.1 6.7.0 4.6.2.1 6.7.1 4.6.20 6.8.0 4.6.20.2 6.8.1 4.6.21.1 6.8.2 4.6.22 6.8.2.1 4.6.22.2 6.8.3 4.6.23.1 6.9.0 4.6.24 6.9.1 4.6.24.2 4.6.25.1 4.6.26 4.6.26.2 4.6.3.1 4.6.4.1 4.6.5.1 4.6.6.1 4.6.7.1 4.6.8.1 4.6.9.1 4.7 4.7.0.2 4.7.1.1 4.7.2.1 4.7.3.1 4.7.4.1 4.8 4.8.0.2 4.8.1.1 4.8.2.1 4.9.0.1 4.9.0.2 4.9.0.4 4.9.1 4.9.1.2 4.9.10.1 4.9.11.1 4.9.12.1 4.9.13.1 4.9.14.1 4.9.2.1 4.9.3 4.9.3.1 4.9.3.3 4.9.4.1 4.9.5.1 4.9.6.1 4.9.7.1 4.9.8.1 4.9.9.1 5.0.0 5.0.0.1 5.0.0.3 5.0.1.1 5.0.1.2 5.0.2 5.0.2.2 5.0.2.3 5.0.3 5.0.3.2 5.0.3.3 5.1.0.1 5.1.0.2
the-events-calendar / template-tags.php
the-events-calendar Last commit date
lang 16 years ago resources 16 years ago views 16 years ago events-calendar-widget.class.php 16 years ago events-list-widget.class.php 16 years ago readme.txt 16 years ago screenshot-1.png 16 years ago screenshot-2.png 16 years ago screenshot-3.png 16 years ago screenshot-4.png 16 years ago screenshot-5.png 16 years ago screenshot-6.png 16 years ago screenshot-7.png 16 years ago template-tags.php 16 years ago the-events-calendar-exception.class.php 16 years ago the-events-calendar.class.php 16 years ago the-events-calendar.php 16 years ago uninstall.php 16 years ago
template-tags.php
771 lines
1 <?php
2
3 if( class_exists( 'The_Events_Calendar' ) && !function_exists( 'eventsGetOptionValue' ) ) {
4 // fetch the iCal file
5 if ( isset($_GET['ical']) ) add_action('init', array( $spEvents, 'iCalFeed') );
6 /**
7 * retrieve specific key from options array, optionally provide a default return value
8 */
9 function eventsGetOptionValue($optionName, $default = '') {
10 global $spEvents;
11 if($optionName) {
12 if( $spEvents->latestOptions ) return $spEvents->latestOptions[$optionName];
13 $options = $spEvents->getOptions();
14 return ( $options[$optionName] ) ? $options[$optionName] : $default;
15 }
16 }
17 /**
18 * Output function: Prints the events calendar 'grid view'
19 *
20 * @return void
21 */
22 function event_grid_view() {
23 set_query_var( 'eventDisplay', 'bydate' );
24 load_template( dirname( __FILE__ ) . '/views/table.php' );
25 }
26 /**
27 * Maps events to days
28 *
29 * @param array of events from get_events()
30 * @param string date of the
31 * @return array days of the month with events as values
32 */
33 function events_by_month( $results, $date ) {
34 if( preg_match( '/(\d{4})-(\d{2})/', $date, $matches ) ) {
35 $queryYear = $matches[1];
36 $queryMonth = $matches[2];
37 } else {
38 return false; // second argument not a date we recognize
39 }
40 $monthView = array();
41 for( $i = 1; $i <= 31; $i++ ) {
42 $monthView[$i] = array();
43 }
44 foreach ( $results as $event ) {
45 $started = false;
46 list( $startYear, $startMonth, $startDay, $garbage ) = explode( '-', $event->EventStartDate );
47 list( $endYear, $endMonth, $endDay, $garbage ) = explode( '-', $event->EventEndDate );
48 list( $startDay, $garbage ) = explode( ' ', $startDay );
49 list( $endDay, $garbage ) = explode( ' ', $endDay );
50 for( $i = 1; $i <= 31 ; $i++ ) {
51 if ( ( $i == $startDay && $startMonth == $queryMonth ) || strtotime( $startYear.'-'.$startMonth ) < strtotime( $queryYear.'-'.$queryMonth ) ) {
52 $started = true;
53 }
54 if ( $started ) {
55 $monthView[$i][] = $event;
56 }
57 if( $i == $endDay && $endMonth == $queryMonth ) {
58 continue 2;
59 }
60 }
61 }
62 return $monthView;
63 }
64 /**
65 * Output function: Prints the selected event style
66 *
67 * @param string $post_id
68 * @return void
69 */
70 function event_style( $postId = null ) {
71 echo get_event_style( $postId );
72 }
73
74 /**
75 * Template function:
76 * @return boolean
77 */
78 function is_event( $postId = null ) {
79 if ( $postId === null || !is_numeric( $postId ) ) {
80 global $post;
81 $postId = $post->ID;
82 }
83 if (get_post_meta( $postId, '_isEvent', true )) {
84 return true;
85 }
86 return false;
87 }
88 /**
89 * Returns a link to google maps for the given event
90 *
91 * @param string $postId
92 * @return string a fully qualified link to http://maps.google.com/ for this event
93 */
94 function get_event_google_map_link( $postId = null ) {
95 if ( $postId === null || !is_numeric( $postId ) ) {
96 global $post;
97 $postId = $post->ID;
98 }
99 if ( !is_event( $postId ) ) return false;
100 $locationMetaSuffixes = array( 'Address', 'City', 'State', 'Province', 'Zip', 'Country' );
101 $toUrlEncode = "";
102 foreach( $locationMetaSuffixes as $val ) {
103 $metaVal = get_post_meta( $postId, '_Event' . $val, true );
104 if( $metaVal ) $toUrlEncode .= $metaVal . " ";
105 }
106 if( $toUrlEncode ) return "http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=" . urlencode( trim( $toUrlEncode ) );
107 return "";
108 }
109 /**
110 * Displays a link to google maps for the given event
111 *
112 * @param string $postId
113 * @return void
114 */
115 function event_google_map_link( $postId = null ) {
116 echo get_event_google_map_link( $postId );
117 }
118 /**
119 * @return string formatted event address
120 */
121 function tec_get_event_address( $postId = null, $includeVenue = false ) {
122 if ( $postId === null || !is_numeric( $postId ) ) {
123 global $post;
124 $postId = $post->ID;
125 }
126 $address = '';
127 if( $includeVenue ) $address .= the_event_venue( $postId );
128 if( the_event_address( $postId ) ) {
129 if( $address ) $address .= ', ';
130 $address .= the_event_address( $postId );
131 }
132 if( the_event_city( $postId ) ) {
133 if( $address ) $address .= ', ';
134 $address .= the_event_city( $postId );
135 }
136 if( the_event_region( $postId ) ) {
137 if( $address ) $address .= ', ';
138 $address .= the_event_region( $postId );
139 }
140 if( the_event_country( $postId ) ) {
141 if( $address ) $address .= ', ';
142 $address .= the_event_country( $postId );
143 }
144 if( the_event_zip( $postId ) ) {
145 if( $address ) $address .= ', ';
146 $address .= the_event_zip( $postId );
147 }
148 $address = str_replace(' ,', ',', $address);
149 return $address;
150 }
151 /**
152 * Displays a formatted event address
153 *
154 * @param string $postId
155 * @return void
156 */
157 function tec_event_address( $postId = null ) {
158 echo tec_get_event_address( $postId );
159 }
160 /**
161 * @return boolean true if any part of an address exists
162 */
163 function tec_address_exists( $postId = null ) {
164 if ( $postId === null || !is_numeric( $postId ) ) {
165 global $post;
166 $postId = $post->ID;
167 }
168 return ( the_event_address( $postId ) || the_event_city( $postId ) || the_event_region( $postId ) || the_event_country( $postId ) || the_event_zip( $postId ) ) ? true : false;
169 }
170 /**
171 * Returns an embedded google maps for the given event
172 *
173 * @param string $postId
174 * @param int $width
175 * @param int $height
176 * @return string - an iframe pulling http://maps.google.com/ for this event
177 */
178 function get_event_google_map_embed( $postId = null, $width = '', $height = '' ) {
179 if ( $postId === null || !is_numeric( $postId ) ) {
180 global $post;
181 $postId = $post->ID;
182 }
183 if ( !is_event( $postId ) ) {
184 return false;
185 }
186 $locationMetaSuffixes = array( 'Address', 'City', 'State', 'Province', 'Zip', 'Country' );
187 $toUrlEncode = "";
188 foreach( $locationMetaSuffixes as $val ) {
189 $metaVal = get_post_meta( $postId, '_Event' . $val, true );
190 if( $metaVal ) $toUrlEncode .= $metaVal . " ";
191 }
192 if (!$height) $height = eventsGetOptionValue('embedGoogleMapsHeight','350');
193 if (!$width) $width = eventsGetOptionValue('embedGoogleMapsWidth','100%');
194 if( $toUrlEncode ) $googleaddress = urlencode( trim( $toUrlEncode ) );
195 if ($googleaddress) {
196 $google_iframe = '<div id="googlemaps"><iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://www.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q='.$googleaddress.'?>&amp;output=embed"></iframe><br /><small><a href="http://www.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q='.$googleaddress.'" style="color:#0000FF;text-align:left">View Larger Map</a></small></div>';
197 return $google_iframe;
198 }
199 else return '';
200 }
201 /**
202 * Displays an embedded google map for the given event
203 *
204 * @param string $postId
205 * @param int $width
206 * @param int $height
207 * @return void
208 */
209 function event_google_map_embed( $postId = null, $width = null, $height = null ) {
210 if (eventsGetOptionValue('embedGoogleMaps') == 'on') echo get_event_google_map_embed( $postId, $width, $height );
211 }
212 /**
213 * Prints out the javascript required to control the datepicker (onChange of the id='datepicker')
214 *
215 * @param string a prefix to add to the ID of the calendar elements. This allows you to reuse the calendar on the same page.
216 * @return void
217 */
218 function get_jump_to_date_calendar( $prefix = '' ) {
219 global $spEvents, $wp_query;
220 if ( isset ( $wp_query->query_vars['eventDate'] ) ) {
221 $date = $wp_query->query_vars['eventDate'] . "-01";
222 } else {
223 $date = date_i18n( The_Events_Calendar::DBDATEFORMAT );
224 }
225 $monthOptions = $spEvents->getMonthOptions( $date );
226 $yearOptions = $spEvents->getYearOptions( $date );
227 include('views/datepicker.php');
228 }
229 /**
230 * Returns the event start date
231 *
232 * @param int post id
233 * @param bool display time?
234 * @param string date format
235 * @return string date
236 */
237 function the_event_start_date( $postId = null, $showtime = 'true', $dateFormat = '' ) {
238 global $spEvents, $post;
239 if ( $postId === null || !is_numeric( $postId ) ) {
240 global $post;
241 $postId = $post->ID;
242 }
243 if( $dateFormat ) $format = $dateFormat;
244 else $format = get_option( 'date_format', The_Events_Calendar::DATEONLYFORMAT );
245 if( the_event_all_day( $postId ) ) {
246 $showtime = false;
247 }
248 if ( $showtime ) {
249 $format = $spEvents->getTimeFormat( $format );
250 }
251 $shortMonthNames = ( strstr( $format, 'M' ) ) ? true : false;
252 $date = date ( $format, strtotime( get_post_meta( $postId, '_EventStartDate', true ) ) );
253 return str_replace( array_keys($spEvents->monthNames( $shortMonthNames )), $spEvents->monthNames( $shortMonthNames ), $date);
254 }
255 /**
256 * Returns the event end date
257 *
258 * @param int post id
259 * @param bool display time?
260 * @param string date format
261 * @return string date
262 */
263 function the_event_end_date( $postId = null, $showtime = 'true', $dateFormat = '' ) {
264 global $spEvents, $post;
265 if ( $postId === null || !is_numeric( $postId ) ) {
266 $postId = $post->ID;
267 }
268 if( $dateFormat ) $format = $dateFormat;
269 else $format = get_option( 'date_format', The_Events_Calendar::DATEONLYFORMAT );
270 if( the_event_all_day( $postId ) ) {
271 $showtime = false;
272 }
273 if ( $showtime ) {
274 $format = $spEvents->getTimeFormat( $format );
275 }
276 $date = date ( $format, strtotime( get_post_meta( $postId, '_EventEndDate', true ) ) );
277 return str_replace( array_keys($spEvents->monthNames()), $spEvents->monthNames(), $date);
278 }
279 /**
280 * If EventBrite plugin is active
281 * If the event is registered in eventbrite, and has one ticket. Return the cost of that ticket.
282 * If the event is registered in eventbrite, and there are many tickets, return "Varies"
283 * If the event is not registered in eventbrite, and there is meta, return that.
284 * If the event is not registered in eventbrite, and there is no meta, return ""
285 *
286 * @param mixed post id or null if used in the loop
287 * @return string
288 */
289 function the_event_cost( $postId = null) {
290 global $spEvents;
291 if ( $postId === null || !is_numeric( $postId ) ) {
292 global $post;
293 $postId = $post->ID;
294 }
295 if( class_exists( 'Eventbrite_for_The_Events_Calendar' ) ) {
296 global $spEventBrite;
297 $returned = $spEventBrite->the_event_cost($postId);
298 if($returned) {
299 return esc_html($returned);
300 }
301 }
302 if ( $cost = get_post_meta( $postId, '_EventCost', true ) ) {
303 return esc_html($cost);
304 } else {
305 return "";
306 }
307 }
308 /**
309 * Returns the event venue
310 *
311 * @return string venue
312 */
313 function the_event_venue( $postId = null) {
314 if ( $postId === null || !is_numeric( $postId ) ) {
315 global $post;
316 $postId = $post->ID;
317 }
318 return esc_html(get_post_meta( $postId, '_EventVenue', true ));
319 }
320 /**
321 * Returns the event country
322 *
323 * @return string country
324 */
325 function the_event_country( $postId = null) {
326 if ( $postId === null || !is_numeric( $postId ) ) {
327 global $post;
328 $postId = $post->ID;
329 }
330 return esc_html(get_post_meta( $postId, '_EventCountry', true ));
331 }
332 /**
333 * Returns the event address
334 *
335 * @return string address
336 */
337 function the_event_address( $postId = null) {
338 if ( $postId === null || !is_numeric( $postId ) ) {
339 global $post;
340 $postId = $post->ID;
341 }
342 return esc_html(get_post_meta( $postId, '_EventAddress', true ));
343 }
344 /**
345 * Returns the event city
346 *
347 * @return string city
348 */
349 function the_event_city( $postId = null) {
350 if ( $postId === null || !is_numeric( $postId ) ) {
351 global $post;
352 $postId = $post->ID;
353 }
354 return esc_html(get_post_meta( $postId, '_EventCity', true ));
355 }
356 /**
357 * Returns the event state
358 *
359 * @return string state
360 */
361 function the_event_state( $postId = null) {
362 if ( $postId === null || !is_numeric( $postId ) ) {
363 global $post;
364 $postId = $post->ID;
365 }
366 return esc_html(get_post_meta( $postId, '_EventState', true ));
367 }
368 /**
369 * Returns the event province
370 *
371 * @return string province
372 */
373 function the_event_province( $postId = null) {
374 if ( $postId === null || !is_numeric( $postId ) ) {
375 global $post;
376 $postId = $post->ID;
377 }
378 return esc_html(get_post_meta( $postId, '_EventProvince', true ));
379 }
380 /**
381 * Returns the event zip code
382 *
383 * @return string zip code
384 */
385 function the_event_zip( $postId = null) {
386 if ( $postId === null || !is_numeric( $postId ) ) {
387 global $post;
388 $postId = $post->ID;
389 }
390 return esc_html(get_post_meta( $postId, '_EventZip', true ));
391 }
392 /**
393 * Returns the event phone number
394 *
395 * @return string phone number
396 */
397 function the_event_phone( $postId = null) {
398 if ( $postId === null || !is_numeric( $postId ) ) {
399 global $post;
400 $postId = $post->ID;
401 }
402 return esc_html(get_post_meta( $postId, '_EventPhone', true ));
403 }
404 /**
405 * Returns a list of lectures that are associated with this event
406 *
407 * @param int optional post id
408 * @return mixed array of posts or false
409 */
410 function the_event_lectures( $postId = null ) {
411 if ( $postId === null || !is_numeric( $postId ) ) {
412 global $post;
413 $postId = $post->ID;
414 }
415 if( !is_event( $postId ) ) {
416 return false;
417 }
418 global $wpdb;
419 $query = "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = '_lectureEvent' AND meta_value = '{$postId}'";
420 $results = $wpdb->get_results( $query );
421 if( empty( $results ) ) {
422 return $results;
423 }
424 $lectures = array();
425 foreach ( $results as $lecture ) {
426 $lectures[] = $lecture->post_id;
427 }
428 $lectures = array_unique( $lectures );
429 $results = array();
430 foreach ( $lectures as $lectureId ) {
431 $results[] = get_post( $lectureId );
432 }
433 return $results;
434
435 }
436
437 /**
438 * Helper function to load XML using cURL
439 *
440 * @return array with xml data
441 */
442 function load_xml($url) {
443
444 $ch = curl_init($url);
445
446 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
447 curl_setopt($ch, CURLOPT_HEADER, 0);
448
449 $data = simplexml_load_string(curl_exec($ch));
450
451 curl_close($ch);
452
453 return $data;
454 }
455
456 /**
457 * Called inside of the loop, returns true if the current post's meta_value (EventStartDate)
458 * is different than the previous post. Will always return true for the first event in the loop.
459 *
460 * @return bool
461 */
462 function is_new_event_day( ) {
463 global $spEvents, $post;
464 $retval = false;
465 $now = time();
466 $postTimestamp = strtotime( $post->EventStartDate, $now );
467 $postTimestamp = strtotime( date( The_Events_Calendar::DBDATEFORMAT, $postTimestamp ), $now); // strip the time
468 if ( $postTimestamp != $spEvents->currentPostTimestamp ) {
469 $retval = true;
470 }
471 $spEvents->currentPostTimestamp = $postTimestamp;
472 return $retval;
473 }
474 /**
475 * Call this function in a template to query the events and start the loop. Do not
476 * subsequently call the_post() in your template, as this will start the loop twice and then
477 * you're in trouble.
478 *
479 * http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query#Query_based_on_Custom_Field_and_Category
480 *
481 * @param int number of results to display for upcoming or past modes (default 10)
482 * @param string category name to pull events from, defaults to the currently displayed category
483 * @uses $wpdb
484 * @uses $wp_query
485 * @return array results
486 */
487 function get_events( $numResults = null, $catName = null ) {
488 if( !$numResults ) $numResults = get_option( 'posts_per_page', 10 );
489 global $wpdb, $spEvents;
490 $spEvents->setOptions();
491 if( $catName ) {
492 $categoryId = get_cat_id( $catName );
493 } else {
494 $categoryId = get_query_var( 'cat' );
495 }
496 $extraSelectClause ='';
497 $extraJoinEndDate ='';
498 if ( events_displaying_month() ) {
499 $extraSelectClause = ", d2.meta_value as EventEndDate ";
500 $extraJoinEndDate = " LEFT JOIN $wpdb->postmeta as d2 ON($wpdb->posts.ID = d2.post_id) ";
501 $whereClause = " AND d1.meta_key = '_EventStartDate' AND d2.meta_key = '_EventEndDate' ";
502 // does this event start in this month?
503 $whereClause .= " AND ((d1.meta_value >= '".$spEvents->date."' AND d1.meta_value < '".$spEvents->nextMonth( $spEvents->date )."') ";
504 // Or does it end in this month?
505 $whereClause .= " OR (d2.meta_value >= '".$spEvents->date."' AND d2.meta_value < '".$spEvents->nextMonth( $spEvents->date )."' ) ";
506 // Or does the event start sometime in the past and end sometime in the distant future?
507 $whereClause .= " OR (d1.meta_value <= '".$spEvents->date."' AND d2.meta_value > '".$spEvents->nextMonth( $spEvents->date )."' ) ) ";
508 $numResults = 999999999;
509 }
510 if ( events_displaying_upcoming() ) {
511 $extraSelectClause = ", d2.meta_value as EventEndDate ";
512 $extraJoinEndDate = " LEFT JOIN $wpdb->postmeta as d2 ON($wpdb->posts.ID = d2.post_id) ";
513 $whereClause = " AND d1.meta_key = '_EventStartDate' AND d2.meta_key = '_EventEndDate' ";
514 // Is the start date in the future?
515 $whereClause .= ' AND ( d1.meta_value > "'.$spEvents->date.'" ';
516 // Or is the start date in the past but the end date in the future? (meaning the event is currently ongoing)
517 $whereClause .= ' OR ( d1.meta_value < "'.$spEvents->date.'" AND d2.meta_value > "'.$spEvents->date.'" ) ) ';
518 }
519 $eventsQuery = "
520 SELECT $wpdb->posts.*, d1.meta_value as EventStartDate
521 $extraSelectClause
522 FROM $wpdb->posts
523 LEFT JOIN $wpdb->postmeta as d1 ON($wpdb->posts.ID = d1.post_id)
524 $extraJoinEndDate
525 LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
526 LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
527 WHERE $wpdb->term_taxonomy.term_id = $categoryId
528 AND $wpdb->term_taxonomy.taxonomy = 'category'
529 AND $wpdb->posts.post_status = 'publish'
530 $whereClause
531 ORDER BY d1.meta_value ".$spEvents->order."
532 LIMIT $numResults";
533 $return = $wpdb->get_results($eventsQuery, OBJECT);
534 return $return;
535 }
536 /**
537 * Returns true if the query is set for past events, false otherwise
538 *
539 * @return bool
540 */
541 function events_displaying_past() {
542 global $spEvents;
543 return ($spEvents->displaying == "past") ? true : false;
544 }
545 /**
546 * Returns true if the query is set for upcoming events, false otherwise
547 *
548 * @return bool
549 */
550 function events_displaying_upcoming() {
551 global $spEvents;
552 return ($spEvents->displaying == "upcoming") ? true : false;
553 }
554 /**
555 * Returns true if the query is set for month display (as opposed to Upcoming / Past)
556 *
557 * @return bool
558 */
559 function events_displaying_month() {
560 global $spEvents;
561 return ( $spEvents->displaying == "month" ) ? true : false;
562 }
563 /**
564 * Returns a link to the previous events in list view
565 *
566 * @return string
567 */
568 function events_get_past_link() {
569 global $spEvents;
570 $cat_id = get_query_var( 'cat' );
571 if( !$cat_id ) {
572 $cat_id = $spEvents->eventCategory();
573 }
574 $link = get_category_link( $cat_id );
575 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
576 return add_query_arg( array('eventDisplay'=>'past'), $link );
577 } else {
578 return trailingslashit( $link ) . 'past';
579 }
580 }
581 /**
582 * Returns a link to the upcoming events in list view
583 *
584 * @return string
585 */
586 function events_get_upcoming_link() {
587 global $spEvents;
588 $cat_id = get_query_var( 'cat' );
589 if( !$cat_id ) {
590 $cat_id = $spEvents->eventCategory();
591 }
592 $link = get_category_link( $cat_id );
593 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
594 return add_query_arg( array('eventDisplay'=>'upcoming'), $link );
595 } else {
596 return trailingslashit( $link ) . 'upcoming';
597 }
598 }
599 /**
600 * Returns a link to the next month's events page
601 *
602 * @return string
603 */
604 function events_get_next_month_link() {
605 global $spEvents;
606 $cat_id = get_query_var( 'cat' );
607 if( !$cat_id ) {
608 $cat_id = $spEvents->eventCategory();
609 }
610 $link = get_category_link( $cat_id );
611 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
612 return add_query_arg( array('eventDate'=>$spEvents->nextMonth( $spEvents->date )), $link );
613 } else {
614 return trailingslashit( $link ) . $spEvents->nextMonth( $spEvents->date );
615 }
616 }
617 /**
618 * Returns a link to the previous month's events page
619 *
620 * @return string
621 */
622 function events_get_previous_month_link() {
623 global $spEvents;
624 $cat_id = get_query_var( 'cat' );
625 if( !$cat_id ) {
626 $cat_id = $spEvents->eventCategory();
627 }
628 $link = get_category_link( $cat_id );
629 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
630 return add_query_arg( array('eventDate'=>$spEvents->previousMonth( $spEvents->date )), $link );
631 } else {
632 return trailingslashit( $link ) . $spEvents->previousMonth( $spEvents->date );
633 }
634 }
635 /**
636 * Returns a link to the events category
637 *
638 * @return string
639 */
640 function events_get_events_link() {
641 global $spEvents;
642 $cat_id = get_query_var( 'cat' );
643 if( !$cat_id ) {
644 $cat_id = $spEvents->eventCategory();
645 }
646 return get_category_link( $cat_id );
647 }
648
649 function events_get_gridview_link( ) {
650 global $spEvents;
651 $cat_id = get_query_var( 'cat' );
652 if( !$cat_id ) {
653 $cat_id = $spEvents->eventCategory();
654 }
655 $link = get_category_link( $cat_id );
656 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
657 return add_query_arg( array('eventDisplay'=>'month'), $link );
658 } else {
659 return trailingslashit( $link ) . 'month';
660 }
661 }
662
663 function events_get_listview_link( ) {
664 global $spEvents;
665 $cat_id = get_query_var( 'cat' );
666 if( !$cat_id ) {
667 $cat_id = $spEvents->eventCategory();
668 }
669 $link = get_category_link( $cat_id );
670 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
671 return add_query_arg( array('eventDisplay'=>'upcoming'), $link );
672 } else {
673 return trailingslashit( $link ) . 'upcoming';
674 }
675 }
676
677 function events_get_listview_past_link( ) {
678 global $spEvents;
679 $cat_id = get_query_var( 'cat' );
680 if( !$cat_id ) {
681 $cat_id = $spEvents->eventCategory();
682 }
683 $link = get_category_link( $cat_id );
684 if( '' == get_option('permalink_structure') || 'off' == eventsGetOptionValue('useRewriteRules','on') ) {
685 return add_query_arg( array('eventDisplay'=>'past'), $link );
686 } else {
687 return trailingslashit( $link ) . 'past';
688 }
689 }
690
691 /**
692 * Returns a textual description of the previous month
693 *
694 * @return string
695 */
696 function events_get_previous_month_text() {
697 global $spEvents;
698 return $spEvents->getDateString( $spEvents->previousMonth( $spEvents->date ) );
699 }
700 /**
701 * Returns a texual description of the current month
702 *
703 * @return string
704 */
705 function events_get_current_month_text( ){
706 global $spEvents;
707 return date( 'F', strtotime( $spEvents->date ) );
708 }
709 /**
710 * Returns a textual description of the next month
711 *
712 * @return string
713 */
714 function events_get_next_month_text() {
715 global $spEvents;
716 return $spEvents->getDateString( $spEvents->nextMonth( $spEvents->date ) );
717 }
718 /**
719 * Returns a formatted date string of the currently displayed month (in "jump to month" mode)
720 *
721 * @return string
722 */
723 function events_get_displayed_month() {
724 global $spEvents;
725 if ( $spEvents->displaying == "month" ) {
726 return $spEvents->getDateString( $spEvents->date );
727 }
728 return " ";
729 }
730 /**
731 * Returns a link to the currently displayed month (if in "jump to month" mode)
732 *
733 * @return string
734 */
735 function events_get_this_month_link() {
736 global $spEvents;
737 $cat_id = get_query_var( 'cat' );
738 if( !$cat_id ) {
739 $cat_id = $spEvents->eventCategory();
740 }
741 $link = get_category_link( $cat_id );
742 if ( $spEvents->displaying == "month" ) {
743 return trailingslashit( $link ) . $spEvents->date;
744 }
745 return false;
746 }
747 /**
748 * Returns the state or province for US or non-US addresses
749 *
750 * @return string
751 */
752 function the_event_region() {
753 if (get_post_meta($postId, '_EventCountry', true ) == 'United States') {
754 return the_event_state();
755 } else {
756 return the_event_province();
757 }
758 }
759 /**
760 * Returns true if the event is an all day event
761 *
762 * @return bool
763 */
764 function the_event_all_day( $postId = null ) {
765 if ( $postId === null || !is_numeric( $postId ) ) {
766 global $post;
767 $postId = $post->ID;
768 }
769 return get_post_meta( $postId, '_EventAllDay', true );
770 }
771 } // end if class_exists('The-Events-Calendar')