Example #1
0
 function process_shortcode($m)
 {
     if ('[' == $m[1] && ']' == $m[6]) {
         return substr($m[0], 1, -1);
     }
     //Extract any attributes contained in the shortcode
     extract(shortcode_atts(array('newwindow' => 'false', 'format' => '', 'limit' => '0', 'html' => 'false', 'markdown' => 'false', 'precision' => '1', 'offset' => '0', 'autolink' => 'true'), shortcode_parse_atts($m[3])));
     //Sanitize the attributes
     $newwindow = 'true' === $newwindow;
     $format = esc_attr($format);
     $limit = absint($limit);
     $html = 'true' === $html;
     $markdown = 'true' === $markdown;
     $precision = absint($precision);
     $offset = intval($offset);
     $autolink = 'true' === $autolink;
     //Do the appropriate stuff depending on which shortcode we're looking at. See valid shortcode list (above) for explanation of each shortcode
     switch ($m[2]) {
         case 'event-title':
             $title = esc_html(trim($this->title));
             if ($markdown && function_exists('Markdown')) {
                 $title = Markdown($title);
             }
             if ($html) {
                 $title = wp_kses_post(html_entity_decode($title));
             }
             return $m[1] . $title . $m[6];
         case 'start-time':
             return $m[1] . date_i18n($this->feed->time_format, $this->start_time + $offset) . $m[6];
         case 'start-date':
             return $m[1] . date_i18n($this->feed->date_format, $this->start_time + $offset) . $m[6];
         case 'start-custom':
             return $m[1] . date_i18n($format, $this->start_time + $offset) . $m[6];
         case 'start-human':
             return $m[1] . $this->gce_human_time_diff($this->start_time + $offset, $this->time_now, $precision) . $m[6];
         case 'end-time':
             return $m[1] . date_i18n($this->feed->time_format, $this->end_time + $offset) . $m[6];
         case 'end-date':
             return $m[1] . date_i18n($this->feed->date_format, $this->end_time + $offset) . $m[6];
         case 'end-custom':
             return $m[1] . date_i18n($format, $this->end_time + $offset) . $m[6];
         case 'end-human':
             return $m[1] . $this->gce_human_time_diff($this->end_time + $offset, $this->time_now, $precision) . $m[6];
         case 'location':
             $location = esc_html(trim($this->location));
             if ($markdown && function_exists('Markdown')) {
                 $location = Markdown($location);
             }
             if ($html) {
                 $location = wp_kses_post(html_entity_decode($location));
             }
             return $m[1] . $location . $m[6];
         case 'description':
             $description = trim($this->description);
             if (0 != $limit) {
                 preg_match('/([\\S]+\\s*){0,' . $limit . '}/', $this->description, $description);
                 $description = trim($description[0]);
             }
             if ($markdown || $html) {
                 if ($markdown && function_exists('Markdown')) {
                     $description = Markdown($description);
                 }
                 if ($html) {
                     $description = wp_kses_post($description);
                 }
             } else {
                 $description = nl2br(esc_html($description));
             }
             if ($autolink) {
                 $description = make_clickable($description);
             }
             return $m[1] . $description . $m[6];
         case 'link':
             $new_window = $newwindow ? ' target="_blank"' : '';
             $ctz = gce_get_wp_timezone();
             if (isset($this->feed->id)) {
                 $tz_option = esc_attr(get_post_meta($this->feed->id, '_feed_timezone_setting', true));
                 if ('use_calendar' == $tz_option) {
                     $ctz = '';
                 }
             }
             // Check if it is a hangouts link first
             if (strpos($this->link, 'plus.google.com/events/') !== false) {
                 $link = $this->link;
             } else {
                 $link = $this->link . (!empty($ctz) ? '&ctz=' . $ctz : '');
             }
             return $m[1] . '<a href="' . esc_url($link) . '"' . $new_window . '>' . $this->look_for_shortcodes($m[5]) . '</a>' . $m[6];
         case 'url':
             return $m[1] . esc_url($this->link) . $m[6];
         case 'feed-id':
             return $m[1] . intval($this->feed->id) . $m[6];
         case 'feed-title':
             return $m[1] . esc_html($this->feed->title) . $m[6];
         case 'maps-link':
             $new_window = $newwindow ? ' target="_blank"' : '';
             return $m[1] . '<a href="' . esc_url('//maps.google.com?q=' . urlencode($this->location)) . '"' . $new_window . '>' . $this->look_for_shortcodes($m[5]) . '</a>' . $m[6];
         case 'length':
             return $m[1] . $this->gce_human_time_diff($this->start_time, $this->end_time, $precision) . $m[6];
         case 'event-num':
             return $m[1] . intval($this->pos) . $m[6];
         case 'event-id':
             return $m[1] . esc_html($this->id) . $m[6];
         case 'cal-id':
             //$cal_id = explode( '/', $this->feed->feed_url );
             return $m[1] . $this->feed->calendar_id . $m[6];
         case 'if-all-day':
             if ('SWD' == $this->day_type || 'MWD' == $this->day_type) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-not-all-day':
             if ('SPD' == $this->day_type || 'MPD' == $this->day_type) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-title':
             if ('' != $this->title) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-description':
             if ('' != $this->description) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-location':
             if ('' != $this->location) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-not-location':
             if ('' == $this->location) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-tooltip':
             if ('tooltip' == $this->type) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-list':
             if ('list' == $this->type) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-now':
             if ($this->time_now >= $this->start_time && $this->time_now < $this->end_time) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-not-now':
             if ($this->end_time < $this->time_now || $this->start_time > $this->time_now) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-started':
             if ($this->start_time < $this->time_now) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-not-started':
             if ($this->start_time > $this->time_now) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-ended':
             if ($this->end_time < $this->time_now) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-not-ended':
             if ($this->end_time > $this->time_now) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-first':
             if (0 == $this->num_in_day) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-not-first':
             if (0 != $this->num_in_day) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-multi-day':
             if ('MPD' == $this->day_type || 'MWD' == $this->day_type) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
         case 'if-single-day':
             if ('SPD' == $this->day_type || 'SWD' == $this->day_type) {
                 return $m[1] . $this->look_for_shortcodes($m[5]) . $m[6];
             }
             return '';
     }
 }
?>
:<br/>
				<code>umsb0ekhivs1a2ubtq6vlqvcjk@group.calendar.google.com</code><br/>
				<a href="<?php 
echo gce_ga_campaign_url('http://wpdocs.philderksen.com/google-calendar-events/getting-started/find-calendar-id/', 'gce_lite', 'settings_link', 'docs');
?>
" target="_blank"><?php 
_e('How to find your Google Calendar ID', 'gce');
?>
</a>
			</p>
		</td>
	</tr>

	<?php 
$timezone_wordpress = gce_get_wp_timezone();
$timezone_default = $timezone_wordpress ? $timezone_wordpress : 'UTC';
$timezone_setting = esc_attr(get_post_meta($post->ID, '_feed_timezone_setting', true));
?>
	<tr>
		<th scope="row"><label for="gce_feed_url"><?php 
_e('Timezone', 'gce');
?>
</label></th>
		<td>
			<select name="_feed_timezone_setting" id="_feed_timezone_setting">
				<option value="use_calendar" <?php 
selected('use_calendar', $timezone_setting, true);
?>
><?php 
_ex('Calendar default', 'Use the calendar default setting', 'gce');
Example #3
0
 /**
  * Create the feed URL
  *
  * @since 2.0.0
  */
 private function create_feed()
 {
     //Break the feed URL up into its parts (scheme, host, path, query)
     global $gce_options;
     if (empty($this->feed_url)) {
         if (current_user_can('manage_options')) {
             echo '<p>' . __('The Google Calendar ID has not been set. Please make sure to set it correctly in the Feed settings.', 'gce') . '</p>';
         }
         return;
     }
     $args = array();
     if (!empty($gce_options['api_key'])) {
         $api_key = urlencode($gce_options['api_key']);
     } else {
         $api_key = $this->api_key;
     }
     $query = 'https://www.googleapis.com/calendar/v3/calendars/' . $this->calendar_id . '/events';
     // Set API key
     $query .= '?key=' . $api_key;
     // Timezone.
     $timezone_option = esc_attr(get_post_meta($this->id, '_feed_timezone_setting', true));
     $timezone = gce_get_wp_timezone();
     if ('use_site' == $timezone_option) {
         $args['timeZone'] = $timezone;
     }
     // Time boundaries.
     if (version_compare(PHP_VERSION, '5.3.0') === -1) {
         $ts = $this->feed_start;
         $time = new DateTime("@{$ts}");
         if ('use_site' == $timezone_option) {
             $time->setTimezone(new DateTimeZone($timezone));
         }
         $args['timeMin'] = urlencode($time->format('c'));
         $ts = $this->feed_end;
         $time = new DateTime("@{$ts}");
         if ('use_site' == $timezone_option) {
             $time->setTimezone(new DateTimeZone($timezone));
         }
         $args['timeMax'] = urlencode($time->format('c'));
     } else {
         $time = new DateTime();
         if ('use_site' == $timezone_option) {
             $time->setTimezone(new DateTimeZone($timezone));
         }
         $time->setTimestamp($this->feed_start);
         $args['timeMin'] = urlencode($time->format('c'));
         $time->setTimestamp($this->feed_end);
         $args['timeMax'] = urlencode($time->format('c'));
     }
     // Max no. of events.
     $args['maxResults'] = 2500;
     // Google search query terms.
     if (!empty($this->search_query)) {
         $args['q'] = rawurlencode($this->search_query);
     }
     // Show recurring.
     if (!empty($this->expand_recurring)) {
         $args['singleEvents'] = 'true';
     }
     $query = esc_url_raw(add_query_arg($args, $query));
     $this->display_url = $query;
     if (isset($_GET['gce_debug']) && $_GET['gce_debug'] == true) {
         echo '<pre>' . $this->display_url . '</pre><br>';
     }
     $this->get_feed_data($query);
 }