/** * Creates an event in an iCalendar * * @param vcalendar $cal * @return vevent */ public function createVevent($cal) { $event = $cal->newComponent('vevent'); $event->setProperty('dtstart', $this->makeDateArray()); // End date must be the day after to make it an all-day event $endDate = clone $this; $endDate->addDays(1); $event->setProperty('dtend', $endDate->makeDateArray()); return $event; }
$e->setProperty('categories', 'PERSONAL'); $e->setProperty('categories', 'SPECIAL OCCASION'); $e->setProperty('rrule', array('FREQ' => 'YEARLY')); echo nl2br($v->createCalendar()); // generate and get output in string, for testing? echo "<br />\n\n"; /* * BEGIN:VTODO * UID:19970901T130000Z-123404@host.com * DTSTAMP:19970901T1300Z * DTSTART:19970415T133000Z * DUE:19970416T045959Z * SUMMARY:1996 Income Tax Preparation * CLASS:CONFIDENTIAL * CATEGORIES:FAMILY,FINANCE * PRIORITY:1 * STATUS:NEEDS-ACTION * END:VTODO */ $c = new vcalendar(array('unique_id' => 'kigkonsult.se')); $t =& $c->newComponent('vtodo'); $t->setProperty('dtstart', '19970415T133000 GMT'); $t->setProperty('due', '19970416T045959 GMT'); $t->setProperty('summary', '1996 Income Tax Preparation'); $t->setProperty('class', 'CONFIDENTIAL'); $t->setProperty('categories', 'FAMILY'); $t->setProperty('categories', 'FINANCE'); $t->setProperty('priority', 1); $t->setProperty('status', 'NEEDS-ACTION'); echo nl2br($v->createCalendar()); // generate and get output in string, for testing?
/** * Export to the specified format * @param array $input - ATutor dates to be exported * @param int $mode - Mode of operation of export [ 0 | 1 ] * * mode 0 - returns the exported dates as a string * * mode 1 - returns the name of the file that has the exported dates * @param string $format - Export Format DEFAULT 'ical' * @return string * @author Anurup Raveendran * */ function cal_export($input = null, $mode, $format = 'ical') { $cal = ""; //output $user = ""; if ($input == null) { $time_zone = ""; } else { $time_zone = $input['timezone']; } global $db; require_once 'iCalcreator.class.php'; require_once 'html_parser.inc.php'; $v = new vcalendar(array('unique_id' => 'Inclusive Design Insitute')); //create an instance of the ical obj // ADD EXTRA DETAILS if (isset($_SESSION['member_id'])) { // GET USER DETAILS $m_id = $_SESSION['member_id']; // GET TIME ZONE // CHECK USER TABLE FOR PREF_TIMEZONE $sql = "SELECT first_name,last_name,preferences FROM " . TABLE_PREFIX . "members WHERE member_id='" . $m_id . "'"; $result = mysql_query($sql, $db) or die(mysql_error()); $row = mysql_fetch_assoc($result); $user = $row['first_name'] . ' ' . $row['last_name']; if ($time_zone == "") { $prefs = unserialize($row['preferences']); $time_zone_offset = $prefs['PREF_TIMEZONE']; if ($time_zone_offset == "") { // CHECK CONFIG TABLE SET BY ADMIN $sql = "SELECT value \n\t\t\t\t\tFROM " . TABLE_PREFIX . "config\n\t\t\t\t\tWHERE name='pref_defaults'"; $result = mysql_query($sql, $db) or die(mysql_error()); if (mysql_num_rows($result) > 0) { //pref_defaults is set $row = mysql_fetch_row($result); $prefs = unserialize($row[0]); $time_zone_offset = $prefs['PREF_TIMEZONE']; } } if ($time_zone_offset != "") { $sql = "SELECT time_zone \n\t\t\t\t\t\tFROM " . TABLE_PREFIX . "calendar_timezone_offset \n\t\t\t\t\t\tWHERE offset='" . $time_zone_offset . "'"; $result = mysql_query($sql, $db) or die(mysql_error()); $row = mysql_fetch_row($result); $time_zone = $row[0]; } else { // GET TIMEZONE FROM SERVER $version = phpversion(); $version = str_replace('Current PHP version: ', '', $version); $version = explode('.', $version); if ($version[0] > 4) { $time_zone = date_default_timezone_get(); } else { // get from ini file $time_zone = ini_get('date.timezone'); } $sql = "SELECT offset \n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "calendar_timezone_offset \n\t\t\t\t\t\t\tWHERE time_zone='" . $time_zone . "'"; $result = mysql_query($sql, $db) or die(mysql_error()); $row = mysql_fetch_row($result); $time_zone_offset = $row[0]; } } else { $sql = "SELECT offset \n\t\t\t\t\t\t\tFROM " . TABLE_PREFIX . "calendar_timezone_offset \n\t\t\t\t\t\t\tWHERE time_zone='" . $time_zone . "'"; $result = mysql_query($sql, $db) or die(mysql_error()); $row = mysql_fetch_row($result); $time_zone_offset = $row[0]; } } /** HEADER **/ $v->setProperty('X-WR-CALNAME', $user); $v->setProperty('X-WR-CALDESC', 'ATutor Dates'); $v->setProperty('X-WR-TIMEZONE', $time_zone); // set the ical timezone component $e =& $v->newComponent('vtimezone'); $e->setProperty('TZID', $time_zone); $e->setProperty('X-LIC-LOCATION', $time_zone); $t =& $e->newComponent('standard'); $t->setProperty('tzoffsetfrom', $this->get_tz_offset($time_zone_offset)); $t->setProperty('tzoffsetto', $this->get_tz_offset($time_zone_offset)); $t->setProperty('dtstart', 1970, 1, 1, 0, 0, 00); /** HEADER **/ // NOW LOAD THE EVENTS global $moduleFactory; $coursesmod = $moduleFactory->getModule("_core/courses"); $assignmentsmod = $moduleFactory->getModule("_standard/assignments"); $testsmod = $moduleFactory->getModule("_standard/tests"); // GET ALL THE COURSES THE USER IS ENROLLED IN $sql = "SELECT course_id\n \tFROM " . TABLE_PREFIX . "course_enrollment \n \tWHERE member_id = '" . $_SESSION['member_id'] . "'"; $course_result = mysql_query($sql, $db) or die(mysql_error()); while ($row = mysql_fetch_row($course_result)) { $course = $coursesmod->extend_date($row[0]); $course = $course[0]; // get the dates $course_start_unix_ts = $course[0]['unixts']; $course_end_unix_ts = $course[1]['unixts']; $cs =& $v->newComponent('vevent'); // initiate COURSE_START event $cs->setProperty('dtstart', date("Y", $course_start_unix_ts), date("n", $course_start_unix_ts), date("j", $course_start_unix_ts), date("G", $course_start_unix_ts), date("m", $course_start_unix_ts), date("i", $course_start_unix_ts)); // COURSE_START DTSTART $cs->setProperty('dtend', date("Y", $course_start_unix_ts), date("n", $course_start_unix_ts), date("j", $course_start_unix_ts), date("G", $course_start_unix_ts), date("m", $course_start_unix_ts), date("i", $course_start_unix_ts)); // COURSE_START DTEND $cs->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i")); // CALENDAR TS //parse the html content to get the summary $html = str_get_html($course[0]['content']); foreach ($html->find('div.content') as $d) { $div = $d; } foreach ($div->find('span.module') as $m) { $module = $m->innertext; } foreach ($div->find('span.title') as $tl) { $title = $tl->innertext; } foreach ($div->find('span.content') as $c) { $content = $c->innertext; } unset($html); unset($div); $summary = $module . $title . $content; $cs->setProperty('summary', $summary); // SUMMARY $cs->setProperty('sequence', 0); // SEQUENCE NUMBER $cs->setProperty('status', 'CONFIRMED'); // STATUS $cs->setProperty('transp', 'TRANSPARENT'); // TRANSPARENCY $ce =& $v->newComponent('vevent'); // initiate COURSE_END event $ce->setProperty('dtstart', date("Y", $course_end_unix_ts), date("n", $course_end_unix_ts), date("j", $course_end_unix_ts), date("G", $course_end_unix_ts), date("m", $course_end_unix_ts), date("i", $course_end_unix_ts)); // COURSE_END DTSTART $ce->setProperty('dtend', date("Y", $course_end_unix_ts), date("n", $course_end_unix_ts), date("j", $course_end_unix_ts), date("G", $course_end_unix_ts), date("m", $course_end_unix_ts), date("i", $course_end_unix_ts)); // COURSE_END DTEND $ce->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i")); // CALENDAR TS //parse the html content to get the summary $html = str_get_html($course[1]['content']); foreach ($html->find('div.content') as $d) { $div = $d; } foreach ($div->find('span.module') as $m) { $module = $m->innertext; } foreach ($div->find('span.title') as $tl) { $title = $tl->innertext; } foreach ($div->find('span.content') as $c) { $content = $c->innertext; } unset($html); unset($div); $summary = $module . $title . $content; $ce->setProperty('summary', $summary); // SUMMARY $ce->setProperty('sequence', 0); // SEQUENCE NUMBER $ce->setProperty('status', 'CONFIRMED'); // STATUS $ce->setProperty('transp', 'TRANSPARENT'); // TRANSPARENCY //GET THE ASSIGNMENTS FOR THIS COURSE $assignments = $assignmentsmod->extend_date($row[0]); foreach ($assignments as $key => $assignment) { // get the dates $assignment_due_unix_ts = $assignment[0]['unixts']; $assignment_cutoff_unix_ts = $assignment[1]['unixts']; $ad =& $v->newComponent('vevent'); // initiate ASSIGNMENT_DUE event $ad->setProperty('dtstart', date("Y", $assignment_due_unix_ts), date("n", $assignment_due_unix_ts), date("j", $assignment_due_unix_ts), date("G", $assignment_due_unix_ts), date("m", $assignment_due_unix_ts), date("i", $assignment_due_unix_ts)); // ASSIGNMENT_DUE DTSTART $ad->setProperty('dtend', date("Y", $assignment_due_unix_ts), date("n", $assignment_due_unix_ts), date("j", $assignment_due_unix_ts), date("G", $assignment_due_unix_ts), date("m", $assignment_due_unix_ts), date("i", $assignment_due_unix_ts)); // ASSIGNMENT_DUE DTEND $ad->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i")); // WHEN THE CAL WAS EXPORTED //parse the html content to get the summary $html = str_get_html($assignment[0]['content']); foreach ($html->find('div.content') as $d) { $div = $d; } foreach ($div->find('span.module') as $m) { $module = $m->innertext; } foreach ($div->find('span.title') as $tl) { $title = $tl->innertext; } foreach ($div->find('span.content') as $c) { $content = $c->innertext; } unset($html); unset($div); $summary = $module . $title . $content; $ad->setProperty('summary', $summary); // SUMMARY $ad->setProperty('sequence', 0); $ad->setProperty('status', 'CONFIRMED'); // STATUS $ad->setProperty('transp', 'TRANSPARENT'); // TRANSPARENCY $ac =& $v->newComponent('vevent'); // initiate ASSIGNMENT_CUTOFF event $ac->setProperty('dtstart', date("Y", $assignment_cutoff_unix_ts), date("n", $assignment_cutoff_unix_ts), date("j", $assignment_cutoff_unix_ts), date("G", $assignment_cutoff_unix_ts), date("m", $assignment_cutoff_unix_ts), date("i", $assignment_cutoff_unix_ts)); // ASSIGNMENT_CUTOFF DTSTART $ac->setProperty('dtend', date("Y", $assignment_cutoff_unix_ts), date("n", $assignment_cutoff_unix_ts), date("j", $assignment_cutoff_unix_ts), date("G", $assignment_cutoff_unix_ts), date("m", $assignment_cutoff_unix_ts), date("i", $assignment_cutoff_unix_ts)); // ASSIGNMENT_CUTOFF DTEND $ac->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i")); // WHEN THE CAL WAS EXPORTED //parse the html content to get the summary $html = str_get_html($assignment[1]['content']); foreach ($html->find('div.content') as $d) { $div = $d; } foreach ($div->find('span.module') as $m) { $module = $m->innertext; } foreach ($div->find('span.title') as $tl) { $title = $tl->innertext; } foreach ($div->find('span.content') as $c) { $content = $c->innertext; } unset($html); unset($div); $summary = $module . $title . $content; $ac->setProperty('summary', $summary); // SUMMARY $ac->setProperty('sequence', 0); $ac->setProperty('status', 'CONFIRMED'); // STATUS $ac->setProperty('transp', 'TRANSPARENT'); // TRANSPARENCY } //GET THE TESTS FOR THIS COURSE $tests = $testsmod->extend_date($row[0]); foreach ($tests as $test) { // get the dates $test_start_unix_ts = $test[0]['unixts']; $test_end_unix_ts = $test[1]['unixts']; $ts =& $v->newComponent('vevent'); // initiate TEST_START event $ts->setProperty('dtstart', date("Y", $test_start_unix_ts), date("n", $test_start_unix_ts), date("j", $test_start_unix_ts), date("G", $test_start_unix_ts), date("m", $test_start_unix_ts), date("i", $test_start_unix_ts)); // TEST_START DTSTART $ts->setProperty('dtend', date("Y", $test_start_unix_ts), date("n", $test_start_unix_ts), date("j", $test_start_unix_ts), date("G", $test_start_unix_ts), date("m", $test_start_unix_ts), date("i", $test_start_unix_ts)); // TEST_START DTEND $ts->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i")); // CALENDAR TS //parse the html content to get the summary $html = str_get_html($test[0]['content']); foreach ($html->find('div.content') as $d) { $div = $d; } foreach ($div->find('span.module') as $m) { $module = $m->innertext; } foreach ($div->find('span.title') as $tl) { $title = $tl->innertext; } foreach ($div->find('span.content') as $c) { $content = $c->innertext; } unset($html); unset($div); $summary = $module . $title . $content; $ts->setProperty('summary', $summary); // SUMMARY $ts->setProperty('sequence', 0); // SEQUENCE NUMBER $ts->setProperty('status', 'CONFIRMED'); // STATUS $ts->setProperty('transp', 'TRANSPARENT'); // TRANSPARENCY $te =& $v->newComponent('vevent'); // initiate TEST_END EVENT $te->setProperty('dtstart', date("Y", $test_end_unix_ts), date("n", $test_end_unix_ts), date("j", $test_end_unix_ts), date("G", $test_end_unix_ts), date("m", $test_end_unix_ts), date("i", $test_end_unix_ts)); // TEST_END DTSTART $te->setProperty('dtend', date("Y", $test_end_unix_ts), date("n", $test_end_unix_ts), date("j", $test_end_unix_ts), date("G", $test_end_unix_ts), date("m", $test_end_unix_ts), date("i", $test_end_unix_ts)); // TEST_END DTEND $te->setProperty('dtstamp', date("Y"), date("n"), date("j"), date("G"), date("m"), date("i")); // CALENDAR TS //parse the html content to get the summary $html = str_get_html($test[1]['content']); foreach ($html->find('div.content') as $d) { $div = $d; } foreach ($div->find('span.module') as $m) { $module = $m->innertext; } foreach ($div->find('span.title') as $tl) { $title = $tl->innertext; } foreach ($div->find('span.content') as $c) { $content = $c->innertext; } unset($html); unset($div); $summary = $module . $title . $content; $te->setProperty('summary', $summary); // SUMMARY $te->setProperty('sequence', 0); // SEQUENCE NUMBER $te->setProperty('status', 'CONFIRMED'); // STATUS $te->setProperty('transp', 'TRANSPARENT'); // TRANSPARENCY } } $str = $v->createCalendar(); return $str; }
/** * Convert an event from a feed into a new Ai1ec_Event object and add it to * the calendar. * * @param Ai1ec_Event $event Event object. * @param vcalendar $calendar Calendar object. * @param bool $export States whether events are created for export. * @param array $params Additional parameters for export. * * @return void */ protected function _insert_event_in_calendar(Ai1ec_Event $event, vcalendar $calendar, $export = false, array $params = array()) { $tz = $this->_registry->get('date.timezone')->get_default_timezone(); $e =& $calendar->newComponent('vevent'); $uid = ''; if ($event->get('ical_uid')) { $uid = addcslashes($event->get('ical_uid'), "\\;,\n"); } else { $uid = $event->get_uid(); $event->set('ical_uid', $uid); $event->save(true); } $e->setProperty('uid', $this->_sanitize_value($uid)); $e->setProperty('url', get_permalink($event->get('post_id'))); // ========================= // = Summary & description = // ========================= $e->setProperty('summary', $this->_sanitize_value(html_entity_decode(apply_filters('the_title', $event->get('post')->post_title), ENT_QUOTES, 'UTF-8'))); $content = apply_filters('the_content', $event->get('post')->post_content); $content = str_replace(']]>', ']]>', $content); $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8'); // Prepend featured image if available. $size = null; $avatar = $this->_registry->get('view.event.avatar'); if ($img_url = $avatar->get_post_thumbnail_url($event, $size)) { $content = '<div class="ai1ec-event-avatar alignleft timely"><img src="' . esc_attr($img_url) . '" width="' . $size[0] . '" height="' . $size[1] . '" /></div>' . $content; } if (isset($params['no_html']) && $params['no_html']) { $e->setProperty('description', $this->_sanitize_value(strip_tags(strip_shortcodes($content)))); if (!empty($content)) { $html_content = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">\\n' . '<HTML>\\n<HEAD>\\n<TITLE></TITLE>\\n</HEAD>\\n<BODY>' . $content . '</BODY></HTML>'; $e->setProperty('X-ALT-DESC', $this->_sanitize_value($html_content), array('FMTTYPE' => 'text/html')); unset($html_content); } } else { $e->setProperty('description', $this->_sanitize_value($content)); } $revision = (int) current(array_keys(wp_get_post_revisions($event->get('post_id')))); $e->setProperty('sequence', $revision); // ===================== // = Start & end times = // ===================== $dtstartstring = ''; $dtstart = $dtend = array(); if ($event->is_allday()) { $dtstart['VALUE'] = $dtend['VALUE'] = 'DATE'; // For exporting all day events, don't set a timezone if ($tz && !$export) { $dtstart['TZID'] = $dtend['TZID'] = $tz; } // For exportin' all day events, only set the date not the time if ($export) { $e->setProperty('dtstart', $this->_sanitize_value($event->get('start')->format('Ymd')), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format('Ymd')), $dtend); } else { $e->setProperty('dtstart', $this->_sanitize_value($event->get('start')->format("Ymd\\T")), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format("Ymd\\T")), $dtend); } } else { if ($tz) { $dtstart['TZID'] = $dtend['TZID'] = $tz; } // This is used later. $dtstartstring = $event->get('start')->format("Ymd\\THis"); $e->setProperty('dtstart', $this->_sanitize_value($dtstartstring), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format("Ymd\\THis")), $dtend); } // ======================== // = Latitude & longitude = // ======================== if (floatval($event->get('latitude')) || floatval($event->get('longitude'))) { $e->setProperty('geo', $event->get('latitude'), $event->get('longitude')); } // =================== // = Venue & address = // =================== if ($event->get('venue') || $event->get('address')) { $location = array($event->get('venue'), $event->get('address')); $location = array_filter($location); $location = implode(' @ ', $location); $e->setProperty('location', $this->_sanitize_value($location)); } $categories = array(); $language = get_bloginfo('language'); foreach ($this->_taxonomy_model->get_post_categories($event->get('post_id')) as $cat) { $categories[] = $cat->name; } $e->setProperty('categories', implode(',', $categories), array("LANGUAGE" => $language)); $tags = array(); foreach ($this->_taxonomy_model->get_post_tags($event->get('post_id')) as $tag) { $tags[] = $tag->name; } if (!empty($tags)) { $e->setProperty('X-TAGS', implode(',', $tags), array("LANGUAGE" => $language)); } // ================== // = Cost & tickets = // ================== if ($event->get('cost')) { $e->setProperty('X-COST', $this->_sanitize_value($event->get('cost'))); } if ($event->get('ticket_url')) { $e->setProperty('X-TICKETS-URL', $this->_sanitize_value($event->get_nonloggable_url($event->get('ticket_url')))); } // ==================================== // = Contact name, phone, e-mail, URL = // ==================================== $contact = array($event->get('contact_name'), $event->get('contact_phone'), $event->get('contact_email'), $event->get_nonloggable_url($event->get('contact_url'))); $contact = array_filter($contact); $contact = implode('; ', $contact); $e->setProperty('contact', $this->_sanitize_value($contact)); // ==================== // = Recurrence rules = // ==================== $rrule = array(); $recurrence = $event->get('recurrence_rules'); if (!empty($recurrence)) { $rules = array(); foreach (explode(';', $event->get('recurrence_rules')) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $rrule[$k] = $v; } } // =================== // = Exception rules = // =================== $exceptions = $event->get('exception_rules'); $exrule = array(); if (!empty($exceptions)) { $rules = array(); foreach (explode(';', $exceptions) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $exrule[$k] = $v; } } // add rrule to exported calendar if (!empty($rrule)) { $e->setProperty('rrule', $this->_sanitize_value($rrule)); } // add exrule to exported calendar if (!empty($exrule)) { $e->setProperty('exrule', $this->_sanitize_value($exrule)); } // =================== // = Exception dates = // =================== // For all day events that use a date as DTSTART, date must be supplied // For other other events which use DATETIME, we must use that as well // We must also match the exact starting time $exception_dates = $event->get('exception_dates'); if (!empty($exception_dates)) { $params = array('VALUE' => 'DATE-TIME', 'TZID' => $tz); $dt_suffix = $event->get('start')->format('\\THis'); foreach (explode(',', $exception_dates) as $exdate) { $exdate = $this->_registry->get('date.time', $exdate)->format('Ymd'); $e->setProperty('exdate', array($exdate . $dt_suffix), $params); } } return $calendar; }
//echo "<br />"; $iduser = $_SESSION['do_User']->iduser; //echo $user; //$time = time(); //$key = "$iduser"."$time"; $e_set_api = new Event("do_User->eventGenerateAPIKey"); $e_set_api->addParam("goto", $_SERVER['PHP_SELF']); if ($_SESSION['do_User']->api_key != '') { $apikey = $_SESSION['do_User']->api_key; $c->setConfig(array("directory" => "Calevents", "filename" => "{$iduser}.ics")); $vivek->getAllTaskByuser($iduser); while ($vivek->fetch()) { $stdt = explode('-', $vivek->getData("due_date_dateformat")); $startdate = "{$stdt['0']}" . "{$stdt['1']}" . "{$stdt['2']}"; $enddate = $startdate; $e =& $c->newComponent('vevent'); //$e->setProperty( 'dtstart', $startdate ); //$e->setProperty( 'dtend', $enddate ); $e->setProperty("dtstart", "{$startdate}", array("VALUE" => "DATE")); $e->setProperty('description', $vivek->getData("task_description")); $e->setProperty('summary', $vivek->getData("task_description")); $e->setProperty('class', 'PUBLIC'); } $c->createCalendar(); $str = $c->saveCalendar(); $tt = $_SERVER["SERVER_NAME"]; $path = "http://" . "{$tt}" . "/" . "Calevents/" . "{$iduser}.ics"; $ff = "Calevents/{$iduser}.ics"; system("chmod 0777 {$ff}"); echo _('Your iCal URL is : ' . $path . ' '); } else {
/** * Convert an event from a feed into a new Ai1ec_Event object and add it to * the calendar. * * @param Ai1ec_Event $event Event object * @param vcalendar $calendar Calendar object * @param bool $export States whether events are created for export * * @return void */ function insert_event_in_calendar(Ai1ec_Event $event, vcalendar &$calendar, $export = false) { global $ai1ec_events_helper; $tz = Ai1ec_Meta::get_option('timezone_string'); $e =& $calendar->newComponent('vevent'); $uid = ''; if ($event->ical_uid) { $uid = addcslashes($event->ical_uid, "\\;,\n"); } else { $uid = sprintf($this->get_uid_format(), $event->post->ID); } $e->setProperty('uid', $this->_sanitize_value($uid)); $e->setProperty('url', get_permalink($event->post_id)); // ========================= // = Summary & description = // ========================= $e->setProperty('summary', $this->_sanitize_value(html_entity_decode(apply_filters('the_title', $event->post->post_title), ENT_QUOTES, 'UTF-8'))); $content = apply_filters('the_content', $event->post->post_content); $content = str_replace(']]>', ']]>', $content); $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8'); // Prepend featured image if available. $size = null; if ($img_url = $event->get_post_thumbnail_url($size)) { $content = '<div class="ai1ec-event-avatar alignleft timely"><img src="' . esc_attr($img_url) . '" width="' . $size[0] . '" height="' . $size[1] . '" /></div>' . $content; } $e->setProperty('description', $this->_sanitize_value($content)); // ===================== // = Start & end times = // ===================== $dtstartstring = ''; $dtstart = $dtend = array(); if ($event->allday) { $dtstart["VALUE"] = $dtend["VALUE"] = 'DATE'; // For exporting all day events, don't set a timezone if ($tz && !$export) { $dtstart["TZID"] = $dtend["TZID"] = $tz; } // For exportin' all day events, only set the date not the time if ($export) { $e->setProperty('dtstart', $this->_sanitize_value(gmdate("Ymd", $ai1ec_events_helper->gmt_to_local($event->start))), $dtstart); $e->setProperty('dtend', $this->_sanitize_value(gmdate("Ymd", $ai1ec_events_helper->gmt_to_local($event->end))), $dtend); } else { $e->setProperty('dtstart', $this->_sanitize_value(gmdate("Ymd\\T", $ai1ec_events_helper->gmt_to_local($event->start))), $dtstart); $e->setProperty('dtend', $this->_sanitize_value(gmdate("Ymd\\T", $ai1ec_events_helper->gmt_to_local($event->end))), $dtend); } } else { if ($tz) { $dtstart["TZID"] = $dtend["TZID"] = $tz; } // This is used later. $dtstartstring = gmdate("Ymd\\THis", $ai1ec_events_helper->gmt_to_local($event->start)); $e->setProperty('dtstart', $this->_sanitize_value($dtstartstring), $dtstart); $e->setProperty('dtend', $this->_sanitize_value(gmdate("Ymd\\THis", $ai1ec_events_helper->gmt_to_local($event->end))), $dtend); } // ======================== // = Latitude & longitude = // ======================== if (floatval($event->latitude) || floatval($event->longitude)) { $e->setProperty('geo', $event->latitude, $event->longitude); } // =================== // = Venue & address = // =================== if ($event->venue || $event->address) { $location = array($event->venue, $event->address); $location = array_filter($location); $location = implode(' @ ', $location); $e->setProperty('location', $this->_sanitize_value($location)); } $categories = array(); $language = get_bloginfo('language'); foreach (wp_get_post_terms($event->post_id, 'events_categories') as $cat) { $categories[] = $cat->name; } $e->setProperty('categories', implode(',', $categories), array("LANGUAGE" => $language)); $tags = array(); foreach (wp_get_post_terms($event->post_id, 'events_tags') as $tag) { $tags[] = $tag->name; } if (!empty($tags)) { $e->setProperty('X-TAGS', implode(',', $tags), array("LANGUAGE" => $language)); } // ================== // = Cost & tickets = // ================== if ($event->cost) { $e->setProperty('X-COST', $this->_sanitize_value($event->cost)); } if ($event->ticket_url) { $e->setProperty('X-TICKETS-URL', $this->_sanitize_value($event->ticket_url)); } // ==================================== // = Contact name, phone, e-mail, URL = // ==================================== $contact = array($event->contact_name, $event->contact_phone, $event->contact_email, $event->contact_url); $contact = array_filter($contact); $contact = implode('; ', $contact); $e->setProperty('contact', $this->_sanitize_value($contact)); // ==================== // = Recurrence rules = // ==================== $rrule = array(); if (!empty($event->recurrence_rules)) { $rules = array(); foreach (explode(';', $event->recurrence_rules) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $rrule[$k] = $v; } } // =================== // = Exception rules = // =================== $exrule = array(); if (!empty($event->exception_rules)) { $rules = array(); foreach (explode(';', $event->exception_rules) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $exrule[$k] = $v; } } // add rrule to exported calendar if (!empty($rrule)) { $e->setProperty('rrule', $this->_sanitize_value($rrule)); } // add exrule to exported calendar if (!empty($exrule)) { $e->setProperty('exrule', $this->_sanitize_value($exrule)); } // =================== // = Exception dates = // =================== // For all day events that use a date as DTSTART, date must be supplied // For other other events which use DATETIME, we must use that as well // We must also match the exact starting time if (!empty($event->exception_dates)) { foreach (explode(',', $event->exception_dates) as $exdate) { if ($event->allday) { // the local date will be always something like 20121122T000000Z // we just need the date $exdate = substr($ai1ec_events_helper->exception_dates_to_local($exdate), 0, 8); $e->setProperty('exdate', array($exdate), array('VALUE' => 'DATE')); } else { $params = array(); if ($tz) { $params["TZID"] = $tz; } $exdate = $ai1ec_events_helper->exception_dates_to_local($exdate); // get only the date + T $exdate = substr($exdate, 0, 9); // Take the time from $exdate .= substr($dtstartstring, 9); $e->setProperty('exdate', array($exdate), $params); } } } }
function test_add_date() { $tests = array('2011-01-20' => array('params' => array('VALUE' => 'DATE'), 'value' => array('year' => '2011', 'month' => '01', 'day' => '20')), '2011-01-20 17:30:15' => array('params' => '', 'value' => array('year' => '2011', 'month' => '01', 'day' => '20', 'hour' => '17', 'min' => '30', 'sec' => '15'))); $calendar = new vcalendar(array('unique_id' => 'test')); $event =& $calendar->newComponent('vevent'); foreach ($tests as $test => $expected) { $this->formatter->add_date($event, 'dtstart', $test); $this->assertEqual($event->dtstart, $expected); } }
public function getIcal($studio = null) { error_reporting(0); sfProjectConfiguration::getActive()->loadHelpers(array("Number","Url","Date")); require_once sfConfig::get('sf_lib_dir').'/vendor/icalcreator/iCalcreator.class.php'; error_reporting(E_ALL ^ E_NOTICE); $config = array( "unique_id" => "downtownswing.rockstep.ch" ); $v = new vcalendar( $config ); $v->setProperty( "method", "PUBLISH" ); $v->setProperty( "X-WR-CALNAME", "Downtownswing Kurse" ); $v->setProperty( "X-WR-CALDESC", "" ); //$vcalendar->setProperty( "X-WR-RELCALID", $uuid ); $v->setProperty( "X-WR-TIMEZONE", "Europe/Zurich" ); // TODO // - filter für kommende, publizierte artikel (model) // - verarbeitung von gecancelten events // - event uuid in db speichern und hier einsetzen (model, on publish, für updates + cancels) $lessons = Doctrine_Core::getTable('dsLesson') ->createQuery('a') ->execute(); // todo // join dance, teachers, .. foreach( $lessons as $lesson ) { $e = & $v->newComponent( 'vevent' ); $e->setUid( $lesson->getIcalUID() ); $e->setSequence( $lesson->getIcalSequence() ); $e->setProperty( 'categories' , $lesson->getDance() ); // $e->setProperty( 'dtstart', '2012-01-06 20:00:00' ); $e->setProperty( 'dtstart', $lesson->getDateTimeObject('date')->format('Y'), // date("Y", $lesson->getDate()), // date("Y", $lesson->getDateTimeObject('date')->format('Y') ), $lesson->getDateTimeObject('date')->format('m'), // date("m", $lesson->getDate()), //date("m", $lesson->getDateTimeObject('date')->format('m') ), $lesson->getDateTimeObject('date')->format('d'), // date("d", $lesson->getDate()), //date("d", $lesson->getDateTimeObject('date')->format('d') ), date('H', strtotime($lesson->getTime())), date('i', strtotime($lesson->getTime())), 00); $e->setProperty( 'duration', array( "min" => $lesson->getDuration() )); // summary $summary = $lesson->getName() ; $e->setProperty( "summary", strip_tags($summary)); // description $description = $lesson->getClass()->getDance().", ". $lesson->getClass()->getTrack()->getType()."\r\n". $lesson->getClass()."\r\n". $lesson->getTeachersAsString(); $e->setProperty( 'description', $description ); // location /* $e->setProperty( 'location', strip_tags($lesson->getStudio()) ); */ /* $request = sfContext::getInstance()->getRequest(); $url = 'http'.($request->isSecure() ? 's' : '').'://'. $request->getHost(); $url .= url_for('event_show',$event); $e->setProperty( "url", strip_tags($url )); */ /* $e->setProperty( "contact", strip_tags($concert->getContact() )); //$e->setProperty( "organizer", strip_tags($concert->getContact() )); //$e->setProperty( "geo", 11.23456, -23.45678 ); */ $e->setProperty( 'last-modified' , $this->datestring2icalArr( $lesson->getCreatedAt() )); /* if($lesson->getUpdatedAt()) $e->setProperty( 'last-modified' , $this->datestring2icalArr( $event->getUpdatedAt() )); else $e->setProperty( 'last-modified' , $this->datestring2icalArr( $event->getCreatedAt() )); } */ } /* alt. production */ //$v->returnCalendar(); // generate and redirect output to user browser /* alt. dev. and test */ //$this->ical = $v->createCalendar(); // generate and get output in string, for testing? //** //return sfView::NONE; return $v; }
$v->setProperty("method", "PUBLISH"); // required of some calendar software $v->setProperty("x-wr-calname", $tables[0]['stuname'] . "的课表 " . $tables[0]['year'] . '-' . $tables[0]['term']); // required of some calendar software $v->setProperty("X-WR-CALDESC", ""); // required of some calendar software $v->setProperty("X-WR-TIMEZONE", "Asia/Shanghai"); // required of some calendar software foreach ($t1 as $o) { $odata = array('name' => $o->name, 'credit' => $o->credit, 'tutor' => $o->tutor, 'schedule' => $o->schedule); if (count($o->schedule)) { foreach ($o->schedule as $os) { $startTimeTrans = array([], ['8', '00'], ['8', '50'], ['9', '50'], ['10', '40'], ['11', '30'], ['13', '20'], ['14', '10'], ['15', '10'], ['16', '00'], ['16', '50'], ['18', '30'], ['19', '20'], ['20', '10']); $endTimeTrans = array([], ['8', '45'], ['9', '35'], ['10', '35'], ['11', '25'], ['12', '15'], ['14', '05'], ['14', '55'], ['15', '55'], ['16', '45'], ['17', '35'], ['19', '15'], ['20', '05'], ['20', '55']); $dateArr = $school->getSchoolCalendar2Date($tables[0]['year'], $tables[0]['term'], $os->week[0], $os->day); $vevent = $v->newComponent("vevent"); // create an event calendar component $vevent->setProperty("dtstart", array("year" => $dateArr[0], "month" => $dateArr[1], "day" => $dateArr[2], "hour" => $startTimeTrans[$os->startTime][0], "min" => $startTimeTrans[$os->startTime][1], "sec" => 0)); $vevent->setProperty("dtend", array("year" => $dateArr[0], "month" => $dateArr[1], "day" => $dateArr[2], "hour" => $endTimeTrans[$os->startTime][0], "min" => $endTimeTrans[$os->startTime + $os->durationTime - 1][1], "sec" => 0)); $vevent->setProperty("LOCATION", $os->location); // property name - case independent $vevent->setProperty("summary", $o->name); $vevent->setProperty("description", $o->tutor); if (count($os->week) > 1) { // Set recurrence rule $endWeek = $os->week[count($os->week) - 1]; $iWeek = $os->week[0]; $weekdayTrans = array('', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'); $vevent->setProperty("RRULE", array("FREQ" => "WEEKLY", "COUNT" => $endWeek - $iWeek + 1, "INTERVAL" => 1, "WKST" => $weekdayTrans[$os->day])); for (; $iWeek < $endWeek; $iWeek++) { if (!in_array($iWeek, $os->week)) {
} if (isset($_GET["debug"])) { echo "<pre>"; foreach ($listeEvt as $evt) { echo $evt; } echo "</pre>"; } else { // sortie au format iCalendar $sourcesEnteteICal = array(); foreach (array_keys($listeSourcesAAnalyser) as $src) { array_push($sourcesEnteteICal, $SOURCES[$src]["nomSite"]); } $vcal = new vcalendar(array("unique_id" => "[" . implode(',', $sourcesEnteteICal) . "]")); foreach ($listeEvt as $evmt) { $event =& $vcal->newComponent("vevent"); // si la date de fin n'est pas positionnée if ($evmt->dateFin == 0) { // on déclare l'évènement comme un évènement à la journée $event->setProperty("dtstart", array("timestamp" => $evmt->dateDebut, "tz" => "Europe/Paris"), array("VALUE" => "DATE")); } else { // on déclare l'évènement entre deux dates $event->setProperty("dtstart", array("timestamp" => $evmt->dateDebut, "tz" => "Europe/Paris"), array("VALUE" => "DATE-TIME")); $event->setProperty("dtend", array("timestamp" => $evmt->dateFin, "tz" => "Europe/Paris"), array("VALUE" => "DATE-TIME")); } $event->setProperty("summary", '[' . $evmt->lieu . '] ' . $evmt->description); $event->setProperty("description", $evmt->description . '\\n' . $evmt->lien); $event->setProperty("location", $evmt->lieu); } echo $vcal->createCalendar(); }
/** * Convert an event from a feed into a new Ai1ec_Event object and add it to * the calendar. * * @param Ai1ec_Event $event Event object. * @param vcalendar $calendar Calendar object. * @param bool $export States whether events are created for export. * @param array $params Additional parameters for export. * * @return void */ protected function _insert_event_in_calendar(Ai1ec_Event $event, vcalendar $calendar, $export = false, array $params = array()) { $tz = $this->_registry->get('date.timezone')->get_default_timezone(); $e =& $calendar->newComponent('vevent'); $uid = ''; if ($event->get('ical_uid')) { $uid = addcslashes($event->get('ical_uid'), "\\;,\n"); } else { $uid = $event->get_uid(); $event->set('ical_uid', $uid); $event->save(true); } $e->setProperty('uid', $this->_sanitize_value($uid)); $e->setProperty('url', get_permalink($event->get('post_id'))); // ========================= // = Summary & description = // ========================= $e->setProperty('summary', $this->_sanitize_value(html_entity_decode(apply_filters('the_title', $event->get('post')->post_title), ENT_QUOTES, 'UTF-8'))); $content = apply_filters('ai1ec_the_content', apply_filters('the_content', $event->get('post')->post_content)); $post_meta_values = get_post_meta($event->get('post_id'), '', false); $cost_type = null; if ($post_meta_values) { foreach ($post_meta_values as $key => $value) { if ('_ai1ec_cost_type' === $key) { $cost_type = $value[0]; } if (isset($params['xml']) && $params['xml'] && false !== preg_match('/^x\\-meta\\-/i', $key)) { $e->setProperty($key, $this->_sanitize_value($value)); } } } if (false === ai1ec_is_blank($cost_type)) { $e->setProperty('X-COST-TYPE', $this->_sanitize_value($cost_type)); } $url = ''; $api = $this->_registry->get('model.api.api-ticketing'); $api_event_id = $api->get_api_event_id($event->get('post_id')); if ($api_event_id) { //getting all necessary informations that will be necessary on imported ticket events $e->setProperty('X-API-EVENT-ID', $api_event_id); $e->setProperty('X-API-URL', $api->get_api_event_url($event->get('post_id'))); $e->setProperty('X-CHECKOUT-URL', $api->get_api_event_checkout_url($event->get('post_id'))); $e->setProperty('X-API-EVENT-CURRENCY', $api->get_api_event_currency($event->get('post_id'))); } else { if ($event->get('ticket_url')) { $url = $event->get('ticket_url'); } } //Adding Ticket URL to the Description field if (false === ai1ec_is_blank($url)) { $content = $this->_remove_ticket_url($content); $content = $content . '<p>' . __('Tickets: ', AI1EC_PLUGIN_NAME) . '<a class="ai1ec-ticket-url-exported" href="' . $url . '">' . $url . '</a>.</p>'; } $content = str_replace(']]>', ']]>', $content); $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8'); // Prepend featured image if available. $size = null; $avatar = $this->_registry->get('view.event.avatar'); $matches = $avatar->get_image_from_content($content); // if no img is already present - add thumbnail if (empty($matches)) { $post_id = get_post_thumbnail_id($event->get('post_id')); $images = null; $added = null; foreach (array('thumbnail', 'medium', 'large', 'full') as $_size) { $attributes = wp_get_attachment_image_src($post_id, $_size); if (false !== $attributes) { $key_str = sprintf('%d_%d', $attributes[1], $attributes[2]); if (null === $added || false === isset($added[$key_str])) { $added[$key_str] = true; array_unshift($attributes, $_size); $images[] = implode(';', $attributes); } } } if (null !== $images) { $e->setProperty('X-WP-IMAGES-URL', $this->_sanitize_value(implode(',', $images))); } if ($img_url = $avatar->get_post_thumbnail_url($event, $size)) { $content = '<div class="ai1ec-event-avatar alignleft timely"><img src="' . esc_attr($img_url) . '" width="' . $size[0] . '" height="' . $size[1] . '" /></div>' . $content; } } if (isset($params['no_html']) && $params['no_html']) { $e->setProperty('description', $this->_sanitize_value(strip_tags(strip_shortcodes($content)))); if (!empty($content)) { $html_content = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">\\n' . '<HTML>\\n<HEAD>\\n<TITLE></TITLE>\\n</HEAD>\\n<BODY>' . $content . '</BODY></HTML>'; $e->setProperty('X-ALT-DESC', $this->_sanitize_value($html_content), array('FMTTYPE' => 'text/html')); unset($html_content); } } else { $e->setProperty('description', $this->_sanitize_value($content)); } $revision = (int) current(array_keys(wp_get_post_revisions($event->get('post_id')))); $e->setProperty('sequence', $revision); // ===================== // = Start & end times = // ===================== $dtstartstring = ''; $dtstart = $dtend = array(); if ($event->is_allday()) { $dtstart['VALUE'] = $dtend['VALUE'] = 'DATE'; // For exporting all day events, don't set a timezone if ($tz && !$export) { $dtstart['TZID'] = $dtend['TZID'] = $tz; } // For exportin' all day events, only set the date not the time if ($export) { $e->setProperty('dtstart', $this->_sanitize_value($event->get('start')->format('Ymd')), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format('Ymd')), $dtend); } else { $e->setProperty('dtstart', $this->_sanitize_value($event->get('start')->format("Ymd\\T")), $dtstart); $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format("Ymd\\T")), $dtend); } } else { if ($tz) { $dtstart['TZID'] = $dtend['TZID'] = $tz; } // This is used later. $dtstartstring = $event->get('start')->format("Ymd\\THis"); $e->setProperty('dtstart', $this->_sanitize_value($dtstartstring), $dtstart); if (false === (bool) $event->get('instant_event')) { $e->setProperty('dtend', $this->_sanitize_value($event->get('end')->format("Ymd\\THis")), $dtend); } } // ======================== // = Latitude & longitude = // ======================== if (floatval($event->get('latitude')) || floatval($event->get('longitude'))) { $e->setProperty('geo', $event->get('latitude'), $event->get('longitude')); } // =================== // = Venue & address = // =================== if ($event->get('venue') || $event->get('address')) { $location = array($event->get('venue'), $event->get('address')); $location = array_filter($location); $location = implode(' @ ', $location); $e->setProperty('location', $this->_sanitize_value($location)); } $categories = array(); $language = get_bloginfo('language'); foreach ($this->_taxonomy_model->get_post_categories($event->get('post_id')) as $cat) { if ('events_categories' === $cat->taxonomy) { $categories[] = $cat->name; } } $e->setProperty('categories', implode(',', $categories), array("LANGUAGE" => $language)); $tags = array(); foreach ($this->_taxonomy_model->get_post_tags($event->get('post_id')) as $tag) { $tags[] = $tag->name; } if (!empty($tags)) { $e->setProperty('X-TAGS', implode(',', $tags), array("LANGUAGE" => $language)); } // ================== // = Cost & tickets = // ================== if ($event->get('cost')) { $e->setProperty('X-COST', $this->_sanitize_value($event->get('cost'))); } if ($event->get('ticket_url')) { $e->setProperty('X-TICKETS-URL', $this->_sanitize_value($event->get('ticket_url'))); } // ================= // = Instant Event = // ================= if ($event->is_instant()) { $e->setProperty('X-INSTANT-EVENT', $this->_sanitize_value($event->is_instant())); } // ==================================== // = Contact name, phone, e-mail, URL = // ==================================== $contact = array($event->get('contact_name'), $event->get('contact_phone'), $event->get('contact_email'), $event->get('contact_url')); $contact = array_filter($contact); $contact = implode('; ', $contact); $e->setProperty('contact', $this->_sanitize_value($contact)); // ==================== // = Recurrence rules = // ==================== $rrule = array(); $recurrence = $event->get('recurrence_rules'); $recurrence = $this->_filter_rule($recurrence); if (!empty($recurrence)) { $rules = array(); foreach (explode(';', $recurrence) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $rrule[$k] = $v; } } // =================== // = Exception rules = // =================== $exceptions = $event->get('exception_rules'); $exceptions = $this->_filter_rule($exceptions); $exrule = array(); if (!empty($exceptions)) { $rules = array(); foreach (explode(';', $exceptions) as $v) { if (strpos($v, '=') === false) { continue; } list($k, $v) = explode('=', $v); $k = strtoupper($k); // If $v is a comma-separated list, turn it into array for iCalcreator switch ($k) { case 'BYSECOND': case 'BYMINUTE': case 'BYHOUR': case 'BYDAY': case 'BYMONTHDAY': case 'BYYEARDAY': case 'BYWEEKNO': case 'BYMONTH': case 'BYSETPOS': $exploded = explode(',', $v); break; default: $exploded = $v; break; } // iCalcreator requires a more complex array structure for BYDAY... if ($k == 'BYDAY') { $v = array(); foreach ($exploded as $day) { $v[] = array('DAY' => $day); } } else { $v = $exploded; } $exrule[$k] = $v; } } // add rrule to exported calendar if (!empty($rrule) && !isset($rrule['RDATE'])) { $e->setProperty('rrule', $this->_sanitize_value($rrule)); } // add exrule to exported calendar if (!empty($exrule) && !isset($exrule['EXDATE'])) { $e->setProperty('exrule', $this->_sanitize_value($exrule)); } // =================== // = Exception dates = // =================== // For all day events that use a date as DTSTART, date must be supplied // For other other events which use DATETIME, we must use that as well // We must also match the exact starting time $recurrence_dates = $event->get('recurrence_dates'); $recurrence_dates = $this->_filter_rule($recurrence_dates); if (!empty($recurrence_dates)) { $params = array('VALUE' => 'DATE-TIME', 'TZID' => $tz); $dt_suffix = $event->get('start')->format('\\THis'); foreach (explode(',', $recurrence_dates) as $exdate) { // date-time string in EXDATES is formatted as 'Ymd\THis\Z', that // means - in UTC timezone, thus we use `format_to_gmt` here. $exdate = $this->_registry->get('date.time', $exdate)->format_to_gmt('Ymd'); $e->setProperty('rdate', array($exdate . $dt_suffix), $params); } } $exception_dates = $event->get('exception_dates'); $exception_dates = $this->_filter_rule($exception_dates); if (!empty($exception_dates)) { $params = array('VALUE' => 'DATE-TIME', 'TZID' => $tz); $dt_suffix = $event->get('start')->format('\\THis'); foreach (explode(',', $exception_dates) as $exdate) { // date-time string in EXDATES is formatted as 'Ymd\THis\Z', that // means - in UTC timezone, thus we use `format_to_gmt` here. $exdate = $this->_registry->get('date.time', $exdate)->format_to_gmt('Ymd'); $e->setProperty('exdate', array($exdate . $dt_suffix), $params); } } return $calendar; }
public function save(Doctrine_Connection $conn = null) { if ($this->isNew() || !$this->getIcalUID()) # && !$this->getIcalUID() { require_once sfConfig::get('sf_lib_dir').'/vendor/icalcreator/iCalcreator.class.php'; $config = array( "unique_id" => "downtownswing.rockstep.ch" ); $v = new vcalendar( $config ); $e = & $v->newComponent( 'vevent' ); $e->createUid(); #var_dump( $e->uid ); $this->setIcalUID($e->uid['value']); #$now = $this->getCreatedAt() ? $this->getDateTimeObject('created_at')->format('U') : time(); #$this->setExpiresAt(date('Y-m-d H:i:s', $now + 86400 * 30)); } else { $this->setIcalSequence( $this->getIcalSequence()+1 ); } return parent::save($conn); }
function setCourseEvent(Course $course, vcalendar $ical, array $info) { $startTime = semInfo($info['year'], $info['sem']); $lessons = $course->lessons; //add lessons foreach ($lessons as $lesson) { $lessonEvent =& $ical->newComponent('vevent'); //set summary(name) $lessonEvent->setProperty('summary', $lesson->summary); //set start and end time. //start $start = fewDaysNextOrBefore($startTime, '+' . ($lesson->time->wkDay - 1) . ' days'); $shour = $lesson->time->startTime / 100; $smin = $lesson->time->startTime % 100; $start['hour'] = $shour; $start['min'] = $smin; $start['sec'] = 0; $lessonEvent->setProperty('dtstart', $start); //end $end = fewDaysNextOrBefore($startTime, '+' . ($lesson->time->wkDay - 1) . ' days'); $ehour = $lesson->time->endTime / 100; $emin = intval($lesson->time->endTime) % 100; $end['hour'] = $ehour; $end['min'] = $emin; $end['sec'] = 0; $lessonEvent->setProperty('dtend', $end); //set location $lessonEvent->setProperty('LOCATION', $lesson->venue); //set description $lessonEvent->setProperty('description', $lesson->description); //set week repeat if (!$lesson->wkRepeatValid) { continue; } $endTime = fewDaysNextOrBefore($startTime, '+14 weeks'); $rule = array('FREQ' => 'WEEKLY', 'UNTIL' => $endTime['year'] . '/' . $endTime['month'] . '/' . $endTime['day']); $lessonEvent->setProperty("rrule", $rule); $exdate = array('year' => $start['year'], 'month' => $start['month'], 'day' => $start['day']); $recess = fewDaysNextOrBefore($exdate, '+7 weeks'); $recess['hour'] = $shour; $recess['min'] = $smin; $recess['sec'] = 0; $wk = $lesson->time->wkRepeat; $exdates = array(); array_push($exdates, $recess); for ($i = 0; $i < 13; $i++) { if ($i < 7) { $j = $i; } else { $j = $i + 1; } if (!$wk[$i]) { $w = fewDaysNextOrBefore($exdate, '+' . $j . ' weeks'); $w['hour'] = $shour; $w['min'] = $smin; $w['sec'] = 0; array_push($exdates, $w); } } $lessonEvent->setProperty('exdate', $exdates, array('TZID' => $info['tz'])); } //add examtime $examtime = $course->examTime; if ($examtime == null) { return; } $start = array('year' => $examtime->year, 'month' => $examtime->month, 'day' => $examtime->day, 'hour' => $examtime->startTime / 100, 'min' => $examtime->startTime % 100, 'sec' => 0); $end = array('year' => $examtime->year, 'month' => $examtime->month, 'day' => $examtime->day, 'hour' => $examtime->endTime / 100, 'min' => $examtime->endTime % 100, 'sec' => 0); $exam =& $ical->newComponent('vevent'); $exam->setProperty('dtstart', $start); $exam->setProperty('dtend', $end); $exam->setProperty('summary', $course->code . ' EXAM!'); $exam->setProperty('description', $course->code . ', ' . $course->name . ', ' . $course->au); return; }