예제 #1
0
 /**
  * @param bool $keep_original_index
  */
 private function sort_sequence($keep_original_index = true)
 {
     if ($this->has_sorted_sequence) {
         return;
     }
     // determine the parent event timezone to use for same day comparison between events
     $timezone = Tribe__Events__Timezones::get_event_timezone_string($this->parent_event_id);
     $this->timezone_string = Tribe__Events__Timezones::generate_timezone_string_from_utc_offset($timezone);
     //add the original key to entry array in the sequence
     if ($keep_original_index) {
         array_walk($this->sequence, array($this, 'set_original_index'));
     }
     // sort the dates to create by starting time
     usort($this->sequence, array($this, 'sort_by_start_date'));
     $this->has_sorted_sequence = true;
 }
 public function save()
 {
     $parent = get_post($this->parent_id);
     $post_to_save = get_object_vars($parent);
     unset($post_to_save['ID']);
     unset($post_to_save['guid']);
     $post_to_save['post_parent'] = $parent->ID;
     $post_to_save['post_name'] = $parent->post_name . '-' . $this->start_date->format('Y-m-d');
     $duration = $this->get_duration();
     $this->end_date = $this->get_end_date();
     $this->timezone = Tribe__Events__Timezones::get_event_timezone_string($this->parent_id);
     if (!empty($this->post_id)) {
         // update the existing post
         $post_to_save['ID'] = $this->post_id;
         if (get_post_status($this->post_id) == 'trash') {
             $post_to_save['post_status'] = get_post_status($this->post_id);
         }
         $this->post_id = wp_update_post($post_to_save);
         update_post_meta($this->post_id, '_EventStartDate', $this->db_formatted_start_date());
         update_post_meta($this->post_id, '_EventStartDateUTC', $this->db_formatted_start_date_utc());
         update_post_meta($this->post_id, '_EventEndDate', $this->db_formatted_end_date());
         update_post_meta($this->post_id, '_EventEndDateUTC', $this->db_formatted_end_date_utc());
         update_post_meta($this->post_id, '_EventDuration', $duration);
     } else {
         // add a new post
         $post_to_save['guid'] = esc_url(add_query_arg(array('eventDate' => $this->start_date->format('Y-m-d')), $parent->guid));
         $this->post_id = wp_insert_post($post_to_save);
         // save several queries by calling add_post_meta when we have a new post
         add_post_meta($this->post_id, '_EventStartDate', $this->db_formatted_start_date());
         add_post_meta($this->post_id, '_EventStartDateUTC', $this->db_formatted_start_date_utc());
         add_post_meta($this->post_id, '_EventEndDate', $this->db_formatted_end_date());
         add_post_meta($this->post_id, '_EventEndDateUTC', $this->db_formatted_end_date_utc());
         add_post_meta($this->post_id, '_EventDuration', $duration);
     }
     $this->copy_meta();
     // everything else
     $this->set_terms();
 }
예제 #3
0
 public function save()
 {
     $parent = get_post($this->parent_id);
     $post_to_save = get_object_vars($parent);
     unset($post_to_save['ID']);
     unset($post_to_save['guid']);
     $post_to_save['post_parent'] = $parent->ID;
     $post_to_save['post_name'] = $parent->post_name . '-' . $this->start_date->format('Y-m-d');
     $this->end_date = $this->get_end_date();
     $this->timezone = Tribe__Events__Timezones::get_event_timezone_string($this->parent_id);
     if (!empty($this->post_id)) {
         // update the existing post
         $post_to_save['ID'] = $this->post_id;
         if (get_post_status($this->post_id) == 'trash') {
             $post_to_save['post_status'] = get_post_status($this->post_id);
         }
         $this->post_id = wp_update_post($post_to_save);
         update_post_meta($this->post_id, '_EventStartDate', $this->db_formatted_start_date());
         update_post_meta($this->post_id, '_EventStartDateUTC', $this->db_formatted_start_date_utc());
         update_post_meta($this->post_id, '_EventEndDate', $this->db_formatted_end_date());
         update_post_meta($this->post_id, '_EventEndDateUTC', $this->db_formatted_end_date_utc());
         update_post_meta($this->post_id, '_EventDuration', $this->duration);
         /**
          * Triggers when a recurring event instance is updated due to the whole series being edited.
          * This action will not fire if a recurring event instance is broken out of the series (e.g. using the "Edit Single" link).
          *
          * @param int $post_id   The updated recurring event instance post ID.
          * @param int $parent_id The updated recurring event instance `post_parent` post ID.
          */
         do_action('tribe_events_pro_recurring_event_instance_updated', $this->post_id, $this->parent_id);
     } else {
         // add a new post
         $query_args = array('eventDate' => $this->start_date->format('Y-m-d'));
         // if an event is the first in a sequence do not append the sequence var
         if (!empty($this->sequence_number) && 1 !== $this->sequence_number) {
             $query_args['eventSequence'] = $this->sequence_number;
         }
         $post_to_save['guid'] = esc_url(add_query_arg($query_args, $parent->guid));
         $this->post_id = wp_insert_post($post_to_save);
         // save several queries by calling add_post_meta when we have a new post
         add_post_meta($this->post_id, '_EventStartDate', $this->db_formatted_start_date());
         add_post_meta($this->post_id, '_EventStartDateUTC', $this->db_formatted_start_date_utc());
         add_post_meta($this->post_id, '_EventEndDate', $this->db_formatted_end_date());
         add_post_meta($this->post_id, '_EventEndDateUTC', $this->db_formatted_end_date_utc());
         add_post_meta($this->post_id, '_EventDuration', $this->duration);
         if (!empty($this->sequence_number) && 1 !== $this->sequence_number) {
             add_post_meta($this->post_id, '_EventSequence', $this->sequence_number);
         }
         /**
          * Triggers when a recurring event instance is inserted due to the whole series being created.
          *
          * @param int $post_id   The updated recurring event instance post ID.
          * @param int $parent_id The updated recurring event instance `post_parent` post ID.
          */
         do_action('tribe_events_pro_recurring_event_instance_inserted', $this->post_id, $this->parent_id);
     }
     $this->copy_meta();
     // everything else
     $this->set_terms();
     /**
      * Triggers when a recurring event instance is inserted due to the whole series being created or updated.
      * This action will not fire if a recurring event instance is broken out of the series (e.g. using the "Edit Single" link).
      *
      * @param int $post_id The updated recurring event instance post ID.
      * @param int $parent_id The updated recurring event instance `post_parent` post ID.
      */
     do_action('tribe_events_pro_recurring_event_save_after', $this->post_id, $this->parent_id);
 }
예제 #4
0
파일: Main.php 프로젝트: TakenCdosG/chefs
 /**
  * Returns the GCal export link for a given event id.
  *
  * @param int|WP_Post|null $post The Event Post Object or ID, if left empty will give get the current post.
  *
  * @return string The URL for the GCal export link.
  */
 public function googleCalendarLink($post = null)
 {
     if (is_null($post)) {
         $post = self::postIdHelper($post);
     }
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     if (!$post instanceof WP_Post) {
         return false;
     }
     // After this point we know that we have a safe WP_Post object
     // Fetch if the Event is a Full Day Event
     $is_all_day = Tribe__Date_Utils::is_all_day(get_post_meta($post->ID, '_EventAllDay', true));
     // Fetch the required Date TimeStamps
     $start_date = Tribe__Events__Timezones::event_start_timestamp($post->ID);
     // Google Requires that a Full Day event end day happens on the next Day
     $end_date = Tribe__Events__Timezones::event_end_timestamp($post->ID) + ($is_all_day ? DAY_IN_SECONDS : 0);
     if ($is_all_day) {
         $dates = date('Ymd', $start_date) . '/' . date('Ymd', $end_date);
     } else {
         $dates = date('Ymd', $start_date) . 'T' . date('Hi00', $start_date) . '/' . date('Ymd', $end_date) . 'T' . date('Hi00', $end_date);
     }
     // Fetch the
     $location = trim($this->fullAddressString($post->ID));
     $event_details = apply_filters('the_content', get_the_content($post->ID));
     // Hack: Add space after paragraph
     // Normally Google Cal understands the newline character %0a
     // And that character will automatically replace newlines on urlencode()
     $event_details = str_replace('</p>', '</p> ', $event_details);
     $event_details = strip_tags($event_details);
     //Truncate Event Description and add permalink if greater than 996 characters
     if (strlen($event_details) > 996) {
         $event_url = get_permalink($post->ID);
         $event_details = substr($event_details, 0, 996);
         //Only add the permalink if it's shorter than 900 characters, so we don't exceed the browser's URL limits
         if (strlen($event_url) < 900) {
             $event_details .= sprintf(esc_html__(' (View Full %1$s Description Here: %2$s)', 'the-events-calendar'), $this->singular_event_label, $event_url);
         }
     }
     $params = array('action' => 'TEMPLATE', 'text' => urlencode(strip_tags($post->post_title)), 'dates' => $dates, 'details' => urlencode($event_details), 'location' => urlencode($location), 'trp' => 'false', 'sprop' => 'website:' . home_url());
     $timezone = Tribe__Events__Timezones::get_event_timezone_string($post->ID);
     $timezone = Tribe__Events__Timezones::maybe_get_tz_name($timezone);
     // If we have a good timezone string we setup it; UTC doesn't work on Google
     if (false !== $timezone) {
         $params['ctz'] = urlencode($timezone);
     }
     /**
      * Allow users to Filter our Google Calendar Link params
      * @var array Params used in the add_query_arg
      * @var int   Event ID
      */
     $params = apply_filters('tribe_google_calendar_parameters', $params, $post->ID);
     $base_url = 'http://www.google.com/calendar/event';
     $url = add_query_arg($params, $base_url);
     return $url;
 }
예제 #5
0
					</tr>
					<tr class="event-timezone">
						<td class="label">
							<label for="event-timezone">
								<?php 
esc_html_e('Timezone:', 'the-events-calendar');
?>
							</label>
						</td>
						<td>
							<select tabindex="<?php 
tribe_events_tab_index();
?>
" name="EventTimezone" id="event-timezone" class="chosen">
								<?php 
echo wp_timezone_choice(Tribe__Events__Timezones::get_event_timezone_string());
?>
							</select>
						</td>
					</tr>
					<?php 
/**
 * Fires after the event end date field in The Events Calendar meta box
 * HTML outputted here should be wrapped in a table row (<tr>) that contains 2 cells (<td>s)
 *
 * @param int $event->ID the event currently being edited, will be 0 if creating a new event
 * @param boolean
 */
do_action('tribe_events_date_display', $event->ID, true);
?>
				</table>
예제 #6
0
 /**
  * Generates the iCal file
  *
  * @static
  *
  * @param int|null $post If you want the ical file for a single event
  */
 public static function generate_ical_feed($post = null)
 {
     $tec = Tribe__Events__Main::instance();
     $events = '';
     $blogHome = get_bloginfo('url');
     $blogName = get_bloginfo('name');
     if ($post) {
         $events_posts = is_array($post) ? $post : array($post);
     } else {
         if (tribe_is_month()) {
             $events_posts = self::get_month_view_events();
         } else {
             global $wp_query;
             $events_posts = $wp_query->posts;
         }
     }
     $event_ids = wp_list_pluck($events_posts, 'ID');
     foreach ($events_posts as $event_post) {
         // add fields to iCal output
         $item = array();
         $full_format = 'Ymd\\THis';
         $time = (object) array('start' => tribe_get_start_date($event_post->ID, false, 'U'), 'end' => tribe_get_end_date($event_post->ID, false, 'U'), 'modified' => Tribe__Date_Utils::wp_strtotime($event_post->post_modified), 'created' => Tribe__Date_Utils::wp_strtotime($event_post->post_date));
         if ('yes' == get_post_meta($event_post->ID, '_EventAllDay', true)) {
             $type = 'DATE';
             $format = 'Ymd';
         } else {
             $type = 'DATE-TIME';
             $format = $full_format;
         }
         $tzoned = (object) array('start' => date($format, $time->start), 'end' => date($format, $time->end), 'modified' => date($format, $time->modified), 'created' => date($format, $time->created));
         if ('DATE' === $type) {
             $item[] = "DTSTART;VALUE={$type}:" . $tzoned->start;
             $item[] = "DTEND;VALUE={$type}:" . $tzoned->end;
         } else {
             // Are we using the sitewide timezone or the local event timezone?
             $tz = Tribe__Events__Timezones::EVENT_TIMEZONE === Tribe__Events__Timezones::mode() ? Tribe__Events__Timezones::get_event_timezone_string($event_post->ID) : Tribe__Events__Timezones::wp_timezone_string();
             $item[] = 'DTSTART;TZID=' . $tz . ':' . $tzoned->start;
             $item[] = 'DTEND;TZID=' . $tz . ':' . $tzoned->end;
         }
         $item[] = 'DTSTAMP:' . date($full_format, time());
         $item[] = 'CREATED:' . $tzoned->created;
         $item[] = 'LAST-MODIFIED:' . $tzoned->modified;
         $item[] = 'UID:' . $event_post->ID . '-' . $time->start . '-' . $time->end . '@' . parse_url(home_url('/'), PHP_URL_HOST);
         $item[] = 'SUMMARY:' . str_replace(array(',', "\n", "\r", "\t"), array('\\,', '\\n', '', '\\t'), html_entity_decode(strip_tags($event_post->post_title), ENT_QUOTES));
         $item[] = 'DESCRIPTION:' . str_replace(array(',', "\n", "\r", "\t"), array('\\,', '\\n', '', '\\t'), html_entity_decode(strip_tags($event_post->post_content), ENT_QUOTES));
         $item[] = 'URL:' . get_permalink($event_post->ID);
         // add location if available
         $location = $tec->fullAddressString($event_post->ID);
         if (!empty($location)) {
             $str_location = str_replace(array(',', "\n"), array('\\,', '\\n'), html_entity_decode($location, ENT_QUOTES));
             $item[] = 'LOCATION:' . $str_location;
         }
         // add geo coordinates if available
         if (class_exists('Tribe__Events__Pro__Geo_Loc')) {
             $long = Tribe__Events__Pro__Geo_Loc::instance()->get_lng_for_event($event_post->ID);
             $lat = Tribe__Events__Pro__Geo_Loc::instance()->get_lat_for_event($event_post->ID);
             if (!empty($long) && !empty($lat)) {
                 $item[] = sprintf('GEO:%s;%s', $lat, $long);
                 $str_title = str_replace(array(',', "\n"), array('\\,', '\\n'), html_entity_decode(tribe_get_address($event_post->ID), ENT_QUOTES));
                 if (!empty($str_title) && !empty($str_location)) {
                     $item[] = 'X-APPLE-STRUCTURED-LOCATION;VALUE=URI;X-ADDRESS=' . str_replace('\\,', '', trim($str_location)) . ';' . 'X-APPLE-RADIUS=500;' . 'X-TITLE=' . trim($str_title) . ':geo:' . $long . ',' . $lat;
                 }
             }
         }
         // add categories if available
         $event_cats = (array) wp_get_object_terms($event_post->ID, Tribe__Events__Main::TAXONOMY, array('fields' => 'names'));
         if (!empty($event_cats)) {
             $item[] = 'CATEGORIES:' . html_entity_decode(join(',', $event_cats), ENT_QUOTES);
         }
         // add featured image if available
         if (has_post_thumbnail($event_post->ID)) {
             $thumbnail_id = get_post_thumbnail_id($event_post->ID);
             $thumbnail_url = wp_get_attachment_url($thumbnail_id);
             $thumbnail_mime_type = get_post_mime_type($thumbnail_id);
             $item[] = apply_filters('tribe_ical_feed_item_thumbnail', sprintf('ATTACH;FMTTYPE=%s:%s', $thumbnail_mime_type, $thumbnail_url), $event_post->ID);
         }
         // add organizer if available
         $organizer_email = tribe_get_organizer_email($event_post->ID);
         if ($organizer_email) {
             $organizer_id = tribe_get_organizer_id($event_post->ID);
             $organizer = get_post($organizer_id);
             if ($organizer_id) {
                 $item[] = sprintf('ORGANIZER;CN="%s":MAILTO:%s', rawurlencode($organizer->post_title), $organizer_email);
             } else {
                 $item[] = sprintf('ORGANIZER:MAILTO:%s', $organizer_email);
             }
         }
         $item = apply_filters('tribe_ical_feed_item', $item, $event_post);
         $events .= "BEGIN:VEVENT\r\n" . implode("\r\n", $item) . "\r\nEND:VEVENT\r\n";
     }
     $site = sanitize_title(get_bloginfo('name'));
     $hash = substr(md5(implode($event_ids)), 0, 11);
     /**
      * Modifies the filename provided in the Content-Disposition header for iCal feeds.
      *
      * @var string       $ical_feed_filename
      * @var WP_Post|null $post
      */
     $filename = apply_filters('tribe_events_ical_feed_filename', $site . '-' . $hash . '.ics', $post);
     header('Content-type: text/calendar; charset=UTF-8');
     header('Content-Disposition: attachment; filename="' . $filename . '"');
     $content = "BEGIN:VCALENDAR\r\n";
     $content .= "VERSION:2.0\r\n";
     $content .= 'PRODID:-//' . $blogName . ' - ECPv' . Tribe__Events__Main::VERSION . "//NONSGML v1.0//EN\r\n";
     $content .= "CALSCALE:GREGORIAN\r\n";
     $content .= "METHOD:PUBLISH\r\n";
     $content .= 'X-WR-CALNAME:' . apply_filters('tribe_ical_feed_calname', $blogName) . "\r\n";
     $content .= 'X-ORIGINAL-URL:' . $blogHome . "\r\n";
     $content .= 'X-WR-CALDESC:Events for ' . $blogName . "\r\n";
     $content = apply_filters('tribe_ical_properties', $content);
     $content .= $events;
     $content .= 'END:VCALENDAR';
     echo $content;
     exit;
 }