/**
  * set calendar component property rrule
  *
  * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**>
  * @since 2.16.21 - 2013-06-23
  * @param array    $rruleset
  * @param array    $params
  * @param integer  $index
  * @uses calendarComponent::getConfig()
  * @uses iCalUtilityFunctions::_setMval()
  * @uses iCalUtilityFunctions::_setRexrule()
  * @return void
  */
 function setRrule($rruleset, $params = FALSE, $index = FALSE)
 {
     if (empty($rruleset)) {
         if ($this->getConfig('allowEmpty')) {
             $rruleset = '';
         } else {
             return FALSE;
         }
     }
     iCalUtilityFunctions::_setMval($this->rrule, iCalUtilityFunctions::_setRexrule($rruleset), $params, FALSE, $index);
     return TRUE;
 }
Пример #2
0
 /**
  * Create list of recurrent instances.
  *
  * @param Ai1ec_Event $event          Event to generate instances for.
  * @param array       $event_instance First instance contents.
  * @param int         $_start         Timestamp of first occurence.
  * @param int         $duration       Event duration in seconds.
  * @param string      $timezone       Target timezone.
  *
  * @return array List of event instances.
  */
 public function create_instances_by_recurrence(Ai1ec_Event $event, array $event_instance, $_start, $duration, $timezone)
 {
     $restore_timezone = date_default_timezone_get();
     $recurrence_parser = $this->_registry->get('recurrence.rule');
     $events = array();
     $start = $event_instance['start'];
     $wdate = $startdate = $enddate = $this->_parsed_date_array($_start, $timezone);
     $enddate['year'] = $enddate['year'] + 3;
     $exclude_dates = array();
     $recurrence_dates = array();
     if ($recurrence_dates = $event->get('recurrence_dates')) {
         $recurrence_dates = $this->_populate_recurring_dates($recurrence_dates, $startdate, $timezone);
     }
     if ($exception_dates = $event->get('exception_dates')) {
         $exclude_dates = $this->_populate_recurring_dates($exception_dates, $startdate, $timezone);
     }
     if ($event->get('exception_rules')) {
         // creat an array for the rules
         $exception_rules = $recurrence_parser->build_recurrence_rules_array($event->get('exception_rules'));
         unset($exception_rules['EXDATE']);
         if (!empty($exception_rules)) {
             $exception_rules = iCalUtilityFunctions::_setRexrule($exception_rules);
             $result = array();
             date_default_timezone_set($timezone);
             // The first array is the result and it is passed by reference
             iCalUtilityFunctions::_recur2date($exclude_dates, $exception_rules, $wdate, $startdate, $enddate);
             date_default_timezone_set($restore_timezone);
         }
     }
     $recurrence_rules = $recurrence_parser->build_recurrence_rules_array($event->get('recurrence_rules'));
     $recurrence_rules = iCalUtilityFunctions::_setRexrule($recurrence_rules);
     if ($recurrence_rules) {
         date_default_timezone_set($timezone);
         iCalUtilityFunctions::_recur2date($recurrence_dates, $recurrence_rules, $wdate, $startdate, $enddate);
         date_default_timezone_set($restore_timezone);
     }
     if (!is_array($recurrence_dates)) {
         $recurrence_dates = array();
     }
     $recurrence_dates = array_keys($recurrence_dates);
     // Add the instances
     foreach ($recurrence_dates as $timestamp) {
         // The arrays are in the form timestamp => true so an isset call is what we need
         if (!isset($exclude_dates[$timestamp])) {
             $event_instance['start'] = $timestamp;
             $event_instance['end'] = $timestamp + $duration;
             $events[$timestamp] = $event_instance;
         }
     }
     return $events;
 }
 /**
  * cache_event function
  *
  * Creates a new entry in the cache table for each date that the event appears
  * (and does not already have an explicit RECURRENCE-ID instance, given its
  * iCalendar UID).
  *
  * @param Ai1ec_Event $event Event to generate cache table for
  *
  * @return void
  **/
 public function cache_event(Ai1ec_Event &$event)
 {
     global $wpdb;
     // Convert event timestamps to local for correct calculations of
     // recurrence. Need to also remove PHP timezone offset for each date for
     // SG_iCal to calculate correct recurring instances.
     $event->start = $this->gmt_to_local($event->start) - date('Z', $event->start);
     $event->end = $this->gmt_to_local($event->end) - date('Z', $event->end);
     $evs = array();
     $e = array('post_id' => $event->post_id, 'start' => $event->start, 'end' => $event->end);
     $duration = $event->getDuration();
     // Timestamp of today date + 3 years (94608000 seconds)
     $tif = Ai1ec_Time_Utility::current_time(true) + 94608000;
     // Always cache initial instance
     $evs[] = $e;
     $_start = $event->start;
     $_end = $event->end;
     if ($event->recurrence_rules) {
         $start = $event->start;
         $wdate = $startdate = iCalUtilityFunctions::_timestamp2date($_start, 6);
         $enddate = iCalUtilityFunctions::_timestamp2date($tif, 6);
         $exclude_dates = array();
         $recurrence_dates = array();
         if ($event->exception_rules) {
             // creat an array for the rules
             $exception_rules = $this->build_recurrence_rules_array($event->exception_rules);
             $exception_rules = iCalUtilityFunctions::_setRexrule($exception_rules);
             $result = array();
             // The first array is the result and it is passed by reference
             iCalUtilityFunctions::_recur2date($exclude_dates, $exception_rules, $wdate, $startdate, $enddate);
         }
         $recurrence_rules = $this->build_recurrence_rules_array($event->recurrence_rules);
         $recurrence_rules = iCalUtilityFunctions::_setRexrule($recurrence_rules);
         iCalUtilityFunctions::_recur2date($recurrence_dates, $recurrence_rules, $wdate, $startdate, $enddate);
         // Add the instances
         foreach ($recurrence_dates as $date => $bool) {
             // The arrays are in the form timestamp => true so an isset call is what we need
             if (isset($exclude_dates[$date])) {
                 continue;
             }
             $e['start'] = $date;
             $e['end'] = $date + $duration;
             $excluded = false;
             // Check if exception dates match this occurence
             if ($event->exception_dates) {
                 if ($this->date_match_exdates($date, $event->exception_dates)) {
                     $excluded = true;
                 }
             }
             // Add event only if it is not excluded
             if ($excluded == false) {
                 $evs[] = $e;
             }
         }
     }
     // Make entries unique (sometimes recurrence generator creates duplicates?)
     $evs_unique = array();
     foreach ($evs as $ev) {
         $evs_unique[md5(serialize($ev))] = $ev;
     }
     foreach ($evs_unique as $e) {
         // Find out if this event instance is already accounted for by an
         // overriding 'RECURRENCE-ID' of the same iCalendar feed (by comparing the
         // UID, start date, recurrence). If so, then do not create duplicate
         // instance of event.
         $start = $this->local_to_gmt($e['start']) - date('Z', $e['start']);
         $matching_event_id = $event->ical_uid ? $this->get_matching_event_id($event->ical_uid, $event->ical_feed_url, $start, false, $event->post_id) : NULL;
         // If no other instance was found
         if (NULL === $matching_event_id) {
             $start = getdate($e['start']);
             $end = getdate($e['end']);
             $this->insert_event_in_cache_table($e);
         }
     }
     return Ai1ec_Events_List_Helper::get_instance()->clean_post_cache($event->post_id);
 }
 /**
  * cache_event function
  *
  * Creates a new entry in the cache table for each date that the event appears
  * (and does not already have an explicit RECURRENCE-ID instance, given its
  * iCalendar UID).
  *
  * @param object $event Event to generate cache table for
  *
  * @return void
  **/
 function cache_event(&$event)
 {
     global $wpdb;
     // Convert event's timestamps to local for correct calculations of
     // recurrence. Need to also remove PHP timezone offset for each date for
     // SG_iCal to calculate correct recurring instances.
     $event->start = $this->gmt_to_local($event->start) - date('Z', $event->start);
     $event->end = $this->gmt_to_local($event->end) - date('Z', $event->end);
     $evs = array();
     $e = array('post_id' => $event->post_id, 'start' => $event->start, 'end' => $event->end);
     $duration = $event->getDuration();
     // Timestamp of today's date + 3 years
     $tif = Ai1ec_Time_Utility::current_time(true) + 94608000;
     //94 608 000 = 3 years in seconds
     // Always cache initial instance
     $evs[] = $e;
     $_start = $event->start;
     $_end = $event->end;
     if ($event->recurrence_rules) {
         $start = $event->start;
         $wdate = $startdate = iCalUtilityFunctions::_timestamp2date($_start, 6);
         $enddate = iCalUtilityFunctions::_timestamp2date($tif, 6);
         $exclude_dates = array();
         $recurrence_dates = array();
         if ($event->exception_rules) {
             // creat an array for the rules
             $exception_rules = $this->build_recurrence_rules_array($event->exception_rules);
             $exception_rules = iCalUtilityFunctions::_setRexrule($exception_rules);
             $result = array();
             // The first array is the result and it's passed by reference
             iCalUtilityFunctions::_recur2date($exclude_dates, $exception_rules, $wdate, $startdate, $enddate);
         }
         $recurrence_rules = $this->build_recurrence_rules_array($event->recurrence_rules);
         $recurrence_rules = iCalUtilityFunctions::_setRexrule($recurrence_rules);
         iCalUtilityFunctions::_recur2date($recurrence_dates, $recurrence_rules, $wdate, $startdate, $enddate);
         // Add the instances
         foreach ($recurrence_dates as $date => $bool) {
             // The arrays are in the form timestamp => true so an isset call is what we need
             if (isset($exclude_dates[$date])) {
                 continue;
             }
             $e['start'] = $date;
             $e['end'] = $date + $duration;
             $excluded = false;
             // Check if exception dates match this occurence
             if ($event->exception_dates) {
                 if ($this->date_match_exdates($date, $event->exception_dates)) {
                     $excluded = true;
                 }
             }
             // Add event only if it is not excluded
             if ($excluded == false) {
                 $evs[] = $e;
             }
         }
     }
     foreach ($evs as $e) {
         // Find out if this event instance is already accounted for by an
         // overriding 'RECURRENCE-ID' of the same iCalendar feed (by comparing the
         // UID, start date, recurrence). If so, then do not create duplicate
         // instance of event.
         $matching_event_id = $event->ical_uid ? $this->get_matching_event_id($event->ical_uid, $event->ical_feed_url, $start = $this->local_to_gmt($e['start']) - date('Z', $e['start']), false, $event->post_id) : null;
         // If no other instance was found
         if (is_null($matching_event_id)) {
             $start = getdate($e['start']);
             $end = getdate($e['end']);
             /*
             // Commented out for now
             // If event spans a day and end time is not midnight, or spans more than
             // a day, then create instance for each spanning day
             if( ( $start['mday'] != $end['mday'] &&
             			( $end['hours'] || $end['minutes'] || $end['seconds'] ) )
             		|| $e['end'] - $e['start'] > 60 * 60 * 24 ) {
             	$this->create_cache_table_entries( $e );
             // Else cache single instance of event
             } else {
             	$this->insert_event_in_cache_table( $e );
             }
             */
             $this->insert_event_in_cache_table($e);
         }
     }
 }
 /**
  * Create list of recurrent instances.
  *
  * @param Ai1ec_Event $event          Event to generate instances for.
  * @param array       $event_instance First instance contents.
  * @param int         $_start         Timestamp of first occurence.
  * @param int         $tif            Timestamp of last occurence.
  * @param int         $duration       Event duration in seconds.
  * @param string      $timezone       Target timezone.
  *
  * @return array List of event instances.
  */
 public function create_instances_by_recurrence(Ai1ec_Event $event, array $event_instance, $_start, $tif, $duration, $timezone)
 {
     $recurrence_parser = $this->_registry->get('recurrence.rule');
     $evs = array();
     $startdate = array('timestamp' => $_start, 'tz' => $timezone);
     $enddate = array('timestamp' => $tif, 'tz' => $timezone);
     $start = $event_instance['start'];
     $wdate = $startdate = iCalUtilityFunctions::_timestamp2date($startdate, 6);
     $enddate = iCalUtilityFunctions::_timestamp2date($enddate, 6);
     $exclude_dates = array();
     $recurrence_dates = array();
     if ($event->get('exception_rules')) {
         // creat an array for the rules
         $exception_rules = $recurrence_parser->build_recurrence_rules_array($event->get('exception_rules'));
         $exception_rules = iCalUtilityFunctions::_setRexrule($exception_rules);
         $result = array();
         // The first array is the result and it is passed by reference
         iCalUtilityFunctions::_recur2date($exclude_dates, $exception_rules, $wdate, $startdate, $enddate);
     }
     $recurrence_rules = $recurrence_parser->build_recurrence_rules_array($event->get('recurrence_rules'));
     $recurrence_rules = iCalUtilityFunctions::_setRexrule($recurrence_rules);
     iCalUtilityFunctions::_recur2date($recurrence_dates, $recurrence_rules, $wdate, $startdate, $enddate);
     $recurrence_dates = array_keys($recurrence_dates);
     // Add the instances
     foreach ($recurrence_dates as $date) {
         // The arrays are in the form timestamp => true so an isset call is what we need
         if (isset($exclude_dates[$date])) {
             continue;
         }
         $event_instance['start'] = $date;
         $event_instance['end'] = $date + $duration;
         $excluded = false;
         // Check if exception dates match this occurence
         if ($exception_dates = $event->get('exception_dates')) {
             $match_exdates = $this->date_match_exdates($date, $exception_dates, $timezone);
             if ($match_exdates) {
                 $excluded = true;
             }
         }
         // Add event only if it is not excluded
         if (false === $excluded) {
             $evs[] = $event_instance;
         }
     }
     return $evs;
 }