function exportar($aObj = array(), $directo_a_browser = 1) { if (is_array($aObj)) { $v = new vcalendar(); $v->setConfig('DIRECTORY', sfConfig::get('sf_cache_dir')); foreach ($aObj as $link_evento) { if ($link_evento->getEvento()) { $e = new vevent(); $e->setProperty('DESCRIPTION', ''); $e->setProperty('SUMMARY', $link_evento->getEvento()->getTitulo()); $e->setProperty('class', 'PUBLIC'); $aFechaInicio = getdate(strtotime($link_evento->getEvento()->getFechaInicio())); $e->setProperty('dtstart', $aFechaInicio['year'], $aFechaInicio['mon'], $aFechaInicio['mday'], $aFechaInicio['hours'], $aFechaInicio['minutes'], 0); $aFechaFin = getdate(strtotime($link_evento->getEvento()->getFechaFin())); $e->setProperty('dtend', $aFechaFin['year'], $aFechaFin['mon'], $aFechaFin['mday'], $aFechaFin['hours'], $aFechaFin['minutes'], 0); $e->setProperty('dtstamp', gmdate('Ymd\\THi00\\Z')); if ($link_evento->getEvento()->getFrecuencia()) { $freq = $this->aFreq[$link_evento->getEvento()->getFrecuencia()]; $interval = $link_evento->getEvento()->getFrecuenciaIntervalo(); $aRrule = array(); $aRrule['FREQ'] = $freq; $aRrule['INTERVAL'] = $interval; if ($freq == "WEEKLY") { $aRrule['BYDAY'] = array_chunk(explode(",", $link_evento->getEvento()->getRecurrenciaDiasIcal()), 1); } if ($link_evento->getEvento()->getRecurrenciaFin() != "") { if (is_numeric($link_evento->getEvento()->getRecurrenciaFin())) { $aRrule['COUNT'] = $link_evento->getEvento()->getRecurrenciaFin(); } else { $aRrule['UNTIL'] = gmdate('Ymd\\THi00\\Z', strtotime($link_evento->getEvento()->getRecurrenciaFin())); } } $e->setProperty('rrule', $aRrule); } $v->addComponent($e); } } if ($directo_a_browser == 1) { $v->returnCalendar(); } else { $v->saveCalendar(); return $v->getConfig('filename'); } } else { $error = 'No envío un array para la exportación'; throw new Exception($error); } }
public function ical($params) { $this->setView('ical.php'); $official = isset($params['official']); $group_name = isset($params['group']) ? $params['group'] : null; $event_model = new Event_Model(); $events = $event_model->getUpcoming($group_name, $official, false); // Creation of the iCal content $cache_entry = 'ical-' . (isset($group_name) ? $group_name : '') . '-' . ($official ? 'official' : 'non-official'); $content = Cache::read($cache_entry); if (!$content) { require_once APP_DIR . 'classes/class.iCalcreator.php'; $cal = new vcalendar(); $cal->setConfig('unique_id', $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); $cal->setProperty('method', 'PUBLISH'); $cal->setProperty('x-wr-calname', $official ? __('EVENTS_TITLE_OFFICIAL') : __('EVENTS_TITLE_NONOFFICIAL')); $cal->setProperty('X-WR-CALDESC', ''); $cal->setProperty('X-WR-TIMEZONE', date('e')); foreach ($events as $event) { $vevent = new vevent(); $vevent->setProperty('dtstart', array('year' => (int) date('Y', $event['date_start']), 'month' => (int) date('n', $event['date_start']), 'day' => (int) date('j', $event['date_start']), 'hour' => (int) date('G', $event['date_start']), 'min' => (int) date('i', $event['date_start']), 'sec' => (int) date('s', $event['date_start']))); $vevent->setProperty('dtend', array('year' => (int) date('Y', $event['date_end']), 'month' => (int) date('n', $event['date_end']), 'day' => (int) date('j', $event['date_end']), 'hour' => (int) date('G', $event['date_end']), 'min' => (int) date('i', $event['date_end']), 'sec' => (int) date('s', $event['date_end']))); $vevent->setProperty('summary', $event['title']); $vevent->setProperty('description', $event['message']); $cal->setComponent($vevent); } $content = $cal->createCalendar(); Cache::write($cache_entry, $content, 2 * 3600); } $this->set('content', $content); }
function update($data) { $uid = substr($data['uid'], strlen('event-')); $oldCalName = $data['oldCalName']; $calName = $data['calName']; $eventStart = $data['eventStart']; $eventEnd = $data['eventEnd']; $eventText = $data['eventText']; if ($calName == null) { throw new Exception("no calendar name"); } if ($uid == '' && ($eventStart == null || $eventEnd == null)) { throw new Exception("no start/end date"); } if ($uid == '' && $eventText == '') { throw new Exception("haven't created event because text is empty"); } if ($oldCalName != null) { // we have an old calendar, so move event from that cal to $calName // possibly updating event summary as well $this->moveEvent($uid, $eventText, $oldCalName, $calName); } else { if ($uid == '') { // No UID so create a new event $event = new vevent(); $event->setProperty('summary', $eventText); $event->setProperty('dtstart', $eventStart, array('VALUE' => 'DATE')); $event->setProperty('dtend', $eventEnd, array('VALUE' => 'DATE')); $uid = $event->getProperty('uid'); $cal = new Calendar($calName); $cal->setComponent($event); $cal->save(); return $uid; } else { if ($eventText === '') { // Event text is now empty, so delete event $cal = new Calendar($calName); $cal->deleteComponent($uid); $cal->save(); } else { // Update the event $cal = new Calendar($calName); $event = $cal->getComponent($uid); if ($eventText != null) { $event->setProperty('summary', $eventText); } if ($eventStart != null) { $event->setProperty('dtstart', $eventStart, array('VALUE' => 'DATE')); } if ($eventEnd != null) { $event->setProperty('dtend', $eventEnd, array('VALUE' => 'DATE')); } $cal->setComponent($event, $uid); $cal->save(); } } } }
function display($tpl = null) { $mainframe = JFactory::getApplication(); $option = JRequest::getCmd('option'); $model = $this->getModel(); $results = $model->getResults(JRequest::getVar('p', 0, '', 'int')); $project = $model->getProject(JRequest::getVar('p', 0, '', 'int')); $document = JFactory::getDocument(); $v = new vcalendar(); // initiate new CALENDAR $v->setConfig('project' . $project->id, $mainframe->getCfg('live_site')); // config with site domain $v->setProperty('X-WR-CALNAME', $project->name); // set some X-properties, name, content.. . $v->setProperty('X-WR-CALDESC', JText::_('COM_TRACKS_Project_calendar')); $v->setConfig("filename", 'project_' . $project->id . '.ics'); foreach ((array) $results as $result) { if (!ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})', $result->start_date, $start_date)) { continue; } $e = new vevent(); // initiate a new EVENT $e->setProperty('categories', $project->name); // catagorize $e->setProperty('dtstart', $start_date[1], $start_date[2], $start_date[3], $start_date[4], $start_date[5], $start_date[6]); if (ereg('([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})', $result->end_date, $end_date)) { $e->setProperty('dtend', $end_date[1], $end_date[2], $end_date[3], $end_date[4], $end_date[5], $end_date[6]); } $description = array(); $description[] = $result->round_name; if ($result->winner && $result->winner->last_name) { $winner = JText::_('COM_TRACKS_Winner') . $result->winner->first_name . ' ' . $result->winner->last_name; if ($result->winner->team_name) { $winner .= ' (' . $result->winner->team_name . ')'; } $description[] = $winner; } $description = implode('\\n', $description); $e->setProperty('description', $description); // describe the event $e->setProperty('location', $result->round_name); // locate the event $v->addComponent($e); // add component to calendar } /* alt. production */ // $v->returnCalendar(); // generate and redirect output to user browser /* alt. dev. and test */ $str = $v->createCalendar(); // generate and get output in string, for testing? // echo $str;return; $v->returnCalendar(); }
public function onPreInit($param) { if (isset($_GET['idtm_termin'])) { $TerminRecord = TerminRecord::finder()->findByPK($_GET['idtm_termin']); } else { echo "Kein Termin"; exit; } date_default_timezone_set('Europe/Berlin'); $v = new vcalendar(); // initiate new CALENDAR $v->setConfig('pliq_hpartner', 'planlogiq.com'); // config with site domain $e = new vevent(); // initiate a new EVENT $SDateArray = explode('-', $TerminRecord->ter_startdate); $EDateArray = explode('-', $TerminRecord->ter_enddate); $STimeArray = explode(':', $TerminRecord->ter_starttime); $ETimeArray = explode(':', $TerminRecord->ter_endtime); $e->setProperty('categories', ActivityRecord::finder()->findByPK($TerminRecord->idtm_activity)->act_name); // catagorize $e->setProperty('dtstart', $SDateArray[0], $SDateArray[1], $SDateArray[2], $STimeArray[0], $STimeArray[1], 00); // 24 dec 2006 19.30 $e->setProperty('dtend', $EDateArray[0], $EDateArray[1], $EDateArray[2], $ETimeArray[0], $ETimeArray[1], 00); // 24 dec 2006 19.30 //$e->setProperty( 'duration' // , 0, 0, 3 ); // 3 hours $e->setProperty('summary', $TerminRecord->ter_betreff); // describe the event $e->setProperty('description', $TerminRecord->ter_descr); // describe the event $e->setProperty('location', $TerminRecord->ter_ort); // locate the event $v->addComponent($e); // add component to calendar /* alt. production */ // $v->returnCalendar(); // generate and redirect output to user browser /* alt. dev. and test */ $str = $v->createCalendar(); // generate and get output in string, for testing? $this->getResponse()->appendHeader("Content-Type:" . $this->header); $this->getResponse()->appendHeader("Content-Disposition:inline;filename=" . $this->docName . '.' . $this->ext); echo $str; $writer->save('php://output'); exit; }
function addEvent($start, $end = false, $summary, $description = '', $extra = false) { $start = strtotime($start); $vevent = new vevent(); if (!$end) { $end = $start + 24 * 60 * 60; $vevent->setProperty('dtstart', date('Ymd', $start), array('VALUE' => 'DATE')); $vevent->setProperty('dtend', date('Ymd', $end), array('VALUE' => 'DATE')); } else { $end = strtotime($end); $start = getdate($start); $a_start['year'] = $start['year']; $a_start['month'] = $start['mon']; $a_start['day'] = $start['mday']; $a_start['hour'] = $start['hours']; $a_start['min'] = $start['minutes']; $a_start['sec'] = $start['seconds']; $end = getdate($end); $a_end['year'] = $end['year']; $a_end['month'] = $end['mon']; $a_end['day'] = $end['mday']; $a_end['sec'] = $end['seconds']; $a_end['hour'] = $end['hours']; $a_end['min'] = $end['minutes']; $vevent->setProperty('dtstart', $a_start); $vevent->setProperty('dtend', $a_end); } $vevent->setProperty('summary', $summary); $vevent->setProperty('description', $description); if (is_array($extra)) { foreach ($extra as $key => $value) { $vevent->setProperty($key, $value); } } $this->calendar->setComponent($vevent); }
/** * toICS() * * Outputs group schedules in ICS format */ function toICS() { require_once BPSP_PLUGIN_DIR . '/schedules/iCalcreator.class.php'; global $bp; define('ICAL_LANG', get_bloginfo('language')); $cal = new vcalendar(); $cal->setConfig('unique_id', str_replace('http://', '', get_bloginfo('siteurl'))); $cal->setConfig('filename', $bp->groups->current_group->slug); $cal->setProperty('X-WR-CALNAME', __('Calendar for: ', 'bpsp') . $bp->groups->current_group->name); $cal->setProperty('X-WR-CALDESC', $bp->groups->current_group->description); $cal->setProperty('X-WR-TIMEZONE', get_option('timezone_string')); $schedules = $this->has_schedules(); $assignments = BPSP_Assignments::has_assignments(); $entries = array_merge($assignments, $schedules); foreach ($entries as $entry) { setup_postdata($entry); $e = new vevent(); if ($entry->post_type == "schedule") { $date = getdate(strtotime($entry->start_date)); } elseif ($entry->post_type == "assignment") { $date = getdate(strtotime($entry->post_date)); } $dtstart['year'] = $date['year']; $dtstart['month'] = $date['mon']; $dtstart['day'] = $date['mday']; $dtstart['hour'] = $date['hours']; $dtstart['min'] = $date['minutes']; $dtstart['sec'] = $date['seconds']; $e->setProperty('dtstart', $dtstart); $e->setProperty('description', get_the_content() . "\n\n" . $entry->permalink); if (!empty($entry->location)) { $e->setProperty('location', $entry->location); } if ($entry->post_type == "assignment") { $entry->end_date = $entry->due_date; } // make assignments compatible with schedule parser if (!empty($entry->end_date)) { $date = getdate(strtotime($entry->end_date)); $dtend['year'] = $date['year']; $dtend['month'] = $date['mon']; $dtend['day'] = $date['mday']; $dtend['hour'] = $date['hours']; $dtend['min'] = $date['minutes']; $dtend['sec'] = $date['seconds']; $e->setProperty('dtend', $dtend); } else { $e->setProperty('duration', 0, 1, 0); } // Assume it's an one day event $e->setProperty('summary', get_the_title($entry->ID)); $e->setProperty('status', 'CONFIRMED'); $cal->setComponent($e); } header("HTTP/1.1 200 OK"); die($cal->returnCalendar()); }
$v = new vcalendar(); // create a new calendar instance $v->setConfig( 'unique_id', 'icaldomain.com' ); // set Your unique id $v->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $v->setProperty( "x-wr-calname", "Calendar Sample" ); // required of some calendar software $v->setProperty( "X-WR-CALDESC", "Calendar Description" ); // required of some calendar software $v->setProperty( "X-WR-TIMEZONE", "Europe/Stockholm" ); // required of some calendar software /**/ $vevent = new vevent(); // create an event calendar component $start = array( 'year'=>getLeadInfo("YEAR(targetdate)"), 'month'=>getLeadInfo("MONTH(targetdate)"), 'day'=>getLeadInfo("DAY(targetdate)")); $vevent->setProperty( 'dtstart', $start ); //$end = array( 'year'=>2007, 'month'=>4, 'day'=>1, 'hour'=>22, 'min'=>30, 'sec'=>0 ); //$vevent->setProperty( 'dtend', $end ); $vevent->setProperty( 'LOCATION', 'Central Placa' ); // property name - case independent $vevent->setProperty( 'summary', getLeadInfo("jobname") ); $vevent->setProperty( 'description', getItemDesc() ); $vevent->setProperty( 'comment', 'This \n\n is a comment' ); //$vevent->setProperty( 'attendee', '*****@*****.**' ); $v->setComponent ( $vevent ); // add event to calendar
public function generate_ical() { $eventdata = $this->pdh->get('calendar_events', 'data', array($this->url_id)); require $this->root_path . 'libraries/icalcreator/iCalcreator.class.php'; $v = new vcalendar(); $v->setConfig('unique_id', $this->config->get('server_name')); $v->setProperty('x-wr-calname', sprintf(registry::fetch('user')->lang('icalfeed_name'), registry::register('config')->get('guildtag'))); $v->setProperty('X-WR-CALDESC', registry::fetch('user')->lang('icalfeed_description')); // set the timezone - required by some clients $timezone = registry::register('config')->get('timezone'); $v->setProperty("X-WR-TIMEZONE", $timezone); iCalUtilityFunctions::createTimezone($v, $timezone, array("X-LIC-LOCATION" => $timezone)); // Generate the vevents... $e = new vevent(); $e->setProperty('dtstart', array("timestamp" => $eventdata['timestamp_start'] . 'Z')); $e->setProperty('dtend', array("timestamp" => $eventdata['timestamp_end'] . 'Z')); $e->setProperty('dtstamp', array("timestamp" => $this->time->time)); $e->setProperty('summary', $this->pdh->get('event', 'name', array($eventdata['extension']['raid_eventid']))); $e->setProperty('description', $eventdata['notes']); $e->setProperty('class', 'PUBLIC'); $e->setProperty('categories', 'PERSONAL'); $v->setComponent($e); // Save or Output the ICS File.. if ($icsfile == true) { $v->setConfig('filename', $icsfile); $v->saveCalendar(); } else { header('Content-type: text/calendar; charset=utf-8;'); header('Content-Disposition: filename=raidevent-' . $eventdata['timestamp_start'] . '.ics'); echo $v->createCalendar(); exit; } }
$agenda->type = $type; //course,admin or personal if (isset($_GET['course_id'])) { $course_info = api_get_course_info_by_id($_GET['course_id']); if (!empty($course_info)) { $agenda->set_course($course_info); } } $event = $agenda->get_event($id); if (!empty($event)) { define('ICAL_LANG', api_get_language_isocode()); $ical = new vcalendar(); $ical->setConfig('unique_id', api_get_path(WEB_PATH)); $ical->setProperty('method', 'PUBLISH'); $ical->setConfig('url', api_get_path(WEB_PATH)); $vevent = new vevent(); switch ($_GET['class']) { case 'public': $vevent->setClass('PUBLIC'); break; case 'private': $vevent->setClass('PRIVATE'); break; case 'confidential': $vevent->setClass('CONFIDENTIAL'); break; default: $vevent->setClass('PRIVATE'); break; } $event['start_date'] = api_get_local_time($event['start_date']);
/** * Generate ical file content * * @param $who user ID * @param $who_group group ID * * @return icalendar string **/ static function generateIcal($who, $who_group) { global $CFG_GLPI, $LANG; if ($who == 0 && $who_group == 0) { return false; } include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php"; $v = new vcalendar(); if (!empty($CFG_GLPI["version"])) { $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"])); } else { $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion"); } $v->setConfig('filename', "glpi.ics"); $v->setProperty("method", "PUBLISH"); $v->setProperty("version", "2.0"); $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group); $v->setProperty("calscale", "GREGORIAN"); $interv = array(); $begin = time() - MONTH_TIMESTAMP * 12; $end = time() + MONTH_TIMESTAMP * 12; $begin = date("Y-m-d H:i:s", $begin); $end = date("Y-m-d H:i:s", $end); // ---------------Tracking $interv = TicketPlanning::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end)); // ---------------Reminder $data = Reminder::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end)); $interv = array_merge($interv, $data); // ---------------Plugin $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group)); if (isset($data["items"]) && count($data["items"])) { $interv = array_merge($data["items"], $interv); } if (count($interv) > 0) { foreach ($interv as $key => $val) { $vevent = new vevent(); //initiate EVENT if (isset($val["tickettasks_id"])) { $vevent->setProperty("uid", "Job#" . $val["tickettasks_id"]); } else { if (isset($val["reminders_id"])) { $vevent->setProperty("uid", "Event#" . $val["reminders_id"]); } else { if (isset($val['planningID'])) { // Specify the ID (for plugins) $vevent->setProperty("uid", "Plugin#" . $val['planningID']); } else { $vevent->setProperty("uid", "Plugin#" . $key); } } } $vevent->setProperty("dstamp", $val["begin"]); $vevent->setProperty("dtstart", $val["begin"]); $vevent->setProperty("dtend", $val["end"]); if (isset($val["tickets_id"])) { $vevent->setProperty("summary", $LANG['planning'][8] . " # " . $val["tickets_id"] . " " . $LANG['document'][14] . " # " . $val["device"]); } else { if (isset($val["name"])) { $vevent->setProperty("summary", $val["name"]); } } if (isset($val["content"])) { $vevent->setProperty("description", html_clean($val["content"])); } else { if (isset($val["name"])) { $vevent->setProperty("description", $val["name"]); } } if (isset($val["tickets_id"])) { $vevent->setProperty("url", $CFG_GLPI["url_base"] . "/index.php?redirect=tracking_" . $val["tickets_id"]); } $v->setComponent($vevent); } } $v->sort(); //$v->parse(); return $v->returnCalendar(); }
} } } // get the status counts $counts = ''; foreach ($raidstatus as $statusid => $statusname) { $counts[$statusid] = isset($attendees[$statusid]) ? count($attendees[$statusid]) : 0; } // build the description data $description_data = registry::register('plus_datahandler')->get('calendar_events', 'notes', array($calid)); $description_data .= !empty($description_data) ? '\\n\\n' : ''; foreach ($counts as $countid => $countdata) { $description_data .= $raidstatus[$countid] . ' (' . $countdata . '): ' . (isset($attendees[$countid]) && count($attendees[$countid]) > 0 ? implode(', ', $attendees[$countid]) : '--') . '\\n'; } // generate the ical output $e = new vevent(); $e->setProperty('dtstart', array("timestamp" => registry::register('plus_datahandler')->get('calendar_events', 'time_start', array($calid)) . 'Z')); $e->setProperty('dtend', array("timestamp" => registry::register('plus_datahandler')->get('calendar_events', 'time_end', array($calid)) . 'Z')); $e->setProperty('summary', registry::register('plus_datahandler')->get('calendar_events', 'name', array($calid))); $e->setProperty('description', $description_data); $e->setProperty('class', 'PUBLIC'); $e->setProperty('categories', 'PERSONAL'); $v->setComponent($e); } } break; } // Save or Output the ICS File..(for future usage, not used atm) if ($icsfile == true) { $v->setConfig('filename', $icsfile); $v->saveCalendar();
/** * Export all tasks of a user via iCal * * @param int $user User ID * @param bool $show_long * @return bool */ function getIcal($user, $show_long = true) { $user = (int) $user; $show_long = (bool) $show_long; $username = $_SESSION["username"]; $project = new project(); $myprojects = $project->getMyProjects($user); $tasks = array(); if (!empty($myprojects)) { foreach ($myprojects as $proj) { $task = $this->getAllMyProjectTasks($proj["ID"], 10000); if (!empty($task)) { array_push($tasks, $task); } } } $etasks = reduceArray($tasks); require "class.ical.php"; $heute = date("d-m-y"); $cal = new vcalendar(); $fname = "tasks_" . $username . ".ics"; $cal->setConfig('directory', CL_ROOT . '/files/' . CL_CONFIG . '/ics'); $cal->setConfig('filename', $fname); $cal->setConfig('unique_id', ''); $cal->setProperty('X-WR-CALNAME', "Collabtive Aufgaben für " . $username); $cal->setProperty('X-WR-CALDESC', ''); $cal->setProperty('CALSCALE', 'GREGORIAN'); $cal->setProperty('METHOD', 'PUBLISH'); foreach ($etasks as $etask) { // split date in Y / M / D / h / min / sek variables $jahr = date("Y", $etask["start"]); $monat = date("m", $etask["start"]); $tag = date("d", $etask["start"]); $std = date("h", $etask["start"]); $min = date("i", $etask["start"]); $sek = date("s", $etask["start"]); // split date in Y / M / D / h / min / sek variables $ejahr = date("Y", $etask['end']); $emonat = date("m", $etask['end']); $etag = date("d", $etask['end']); $estd = date("h", $etask['end']); $emin = date("i", $etask['end']); $esek = date("s", $etask['end']); $e = new vevent(); $e->setProperty('categories', $etask['list']); if ($show_long) { // if we have a task lasting 10 month, normally it will be displayed every day within this time span. $e->setProperty('dtstart', $jahr, $monat, $tag, $std, $min); // 24 dec 2007 19.30 } else { // if the show_long flag is set, it will only be shown at the due date $e->setProperty('dtstart', $ejahr, $emonat, $etag, $estd, $emin); } $e->setProperty('due', $ejahr, $emonat, $etag, $estd, $emin); // 24 dec 2007 19.30 $e->setProperty('dtend', $ejahr, $emonat, $etag, $estd, $emin); $e->setProperty('description', $etask["text"]); $e->setProperty('status', "NEEDS-ACTION"); // $e->setProperty('comment' , $etask[text]); $e->setProperty('summary', $etask["title"]); $e->setProperty('location', 'Work'); $cal->setComponent($e); } $cal->returnCalendar(); return true; }
function icalAddEvent(&$calendartool, $event) { require_once JPATH_SITE . DS . 'components' . DS . 'com_redevent' . DS . 'classes' . DS . 'iCalcreator.class.php'; $mainframe =& JFactory::getApplication(); $params = $mainframe->getParams('com_redevent'); $offset = $params->get('ical_timezone', 1); $timezone_name = self::getTimeZone($offset); // get categories names $categories = array(); foreach ($event->categories as $c) { $categories[] = $c->catname; } if (!$event->dates || $event->dates == '0000-00-00') { // no start date... return false; } // make end date same as start date if not set if (!$event->enddates || $event->enddates == '0000-00-00') { $event->enddates = $event->dates; } // start if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $event->dates, $start_date)) { JError::raiseError(0, JText::_('COM_REDEVENT_ICAL_EXPORT_WRONG_STARTDATE_FORMAT')); } $date = array('year' => (int) $start_date[1], 'month' => (int) $start_date[2], 'day' => (int) $start_date[3]); // all day event if start time is not set if (!$event->times || $event->times == '00:00:00') { $dateparam = array('VALUE' => 'DATE'); // for ical all day events, dtend must be send to the next day $event->enddates = strftime('%Y-%m-%d', strtotime($event->enddates . ' +1 day')); if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $event->enddates, $end_date)) { JError::raiseError(0, JText::_('COM_REDEVENT_ICAL_EXPORT_WRONG_ENDDATE_FORMAT')); } $date_end = array('year' => $end_date[1], 'month' => $end_date[2], 'day' => $end_date[3]); $dateendparam = array('VALUE' => 'DATE'); } else { if (!preg_match('/([0-9]{2}):([0-9]{2}):([0-9]{2})/', $event->times, $start_time)) { JError::raiseError(0, JText::_('COM_REDEVENT_ICAL_EXPORT_WRONG_STARTTIME_FORMAT')); } $date['hour'] = $start_time[1]; $date['min'] = $start_time[2]; $date['sec'] = $start_time[3]; $dateparam = array('VALUE' => 'DATE-TIME'); if (!$params->get('ical_no_timezone', 0)) { $dateparam['TZID'] = $timezone_name; } if (!$event->endtimes || $event->endtimes == '00:00:00') { $event->endtimes = $event->times; } // if same day but end time < start time, change end date to +1 day if ($event->enddates == $event->dates && strtotime($event->dates . ' ' . $event->endtimes) < strtotime($event->dates . ' ' . $event->times)) { $event->enddates = strftime('%Y-%m-%d', strtotime($event->enddates . ' +1 day')); } if (!preg_match('/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/', $event->enddates, $end_date)) { JError::raiseError(0, JText::_('COM_REDEVENT_ICAL_EXPORT_WRONG_ENDDATE_FORMAT')); } $date_end = array('year' => $end_date[1], 'month' => $end_date[2], 'day' => $end_date[3]); if (!preg_match('/([0-9]{2}):([0-9]{2}):([0-9]{2})/', $event->endtimes, $end_time)) { JError::raiseError(0, JText::_('COM_REDEVENT_ICAL_EXPORT_WRONG_STARTTIME_FORMAT')); } $date_end['hour'] = $end_time[1]; $date_end['min'] = $end_time[2]; $date_end['sec'] = $end_time[3]; $dateendparam = array('VALUE' => 'DATE-TIME'); if (!$params->get('ical_no_timezone', 0)) { $dateendparam['TZID'] = $timezone_name; } } $title = isset($event->full_title) ? $event->full_title : $event->title; // item description text $description = $title . '\\n'; $description .= JText::_('COM_REDEVENT_CATEGORY') . ': ' . implode(', ', $categories) . '\\n'; // if (isset($event->summary) && $event->summary) { // $description .= $event->summary.'\\n'; // } // url link to event $link = JURI::base() . RedeventHelperRoute::getDetailsRoute($event->slug, $event->xref); $link = JRoute::_($link); $description .= JText::_('COM_REDEVENT_ICS_LINK') . ': ' . $link . '\\n'; if (!empty($event->icaldetails)) { $description .= $event->icaldetails; } // location $location = array(); if (isset($event->icalvenue) && !empty($event->icalvenue)) { $location[] = $event->icalvenue; } else { $location[] = $event->venue; if (isset($event->street) && !empty($event->street)) { $location[] = $event->street; } if (isset($event->city) && !empty($event->city)) { $location[] = $event->city; } if (isset($event->countryname) && !empty($event->countryname)) { $exp = explode(",", $event->countryname); $location[] = $exp[0]; } } $location = implode(",", $location); $e = new vevent(); // initiate a new EVENT $e->setProperty('summary', $title); // title $e->setProperty('categories', implode(', ', $categories)); // categorize $e->setProperty('dtstart', $date, $dateparam); if (count($date_end)) { $e->setProperty('dtend', $date_end, $dateendparam); } $e->setProperty('description', $description); // describe the event $e->setProperty('location', $location); // locate the event $e->setProperty('url', $link); $e->setProperty('uid', 'event' . $event->id . '-' . $event->xref . '@' . $mainframe->getCfg('sitename')); $calendartool->addComponent($e); // add component to calendar return true; }
//knowledge of the CeCILL-B license and that you accept its terms. You can //find a copy of this license in the file LICENSE. // //========================================================================== // TODO: no easy way to retrieve the best(s) choice(s) header('Location: studs.php'); $meilleursujet = $_SESSION["meilleursujet"]; session_start(); require_once 'iCalcreator/iCalcreator.class.php'; $v = new vcalendar(); // create a new calendar instance $v->setConfig('unique_id', $_SESSION["numsondage"]); // set Your unique id $v->setProperty('method', 'PUBLISH'); // required of some calendar software $vevent = new vevent(); // create an event calendar component /* tested with : $test = array( '1275818164@12h-15h', '1275818164@12h15-15h57', '1275818164@12:15-15:57', '1275818164@8:30', '1275818164@8h30'); foreach($test as $meilleursujet) { */ $adate = strtok($meilleursujet, "@"); $dtstart = $dtend = array('year' => intval(date("Y", $adate)), 'month' => intval(date("n", $adate)), 'day' => intval(date("j", $adate)), 'hour' => 0, 'min' => 0, 'sec' => 0); $double_time = false; if (strpos($meilleursujet, '-') !== false) { $double_time = true; } $dtstart['hour'] = intval(strtok(":Hh")); $a = intval(strtok(":Hh-")); $b = intval(strtok(":Hh-"));
function display($tpl = null) { // Get a reference of the page instance in joomla $document = JFactory::getDocument(); $model = $this->getModel(); $project = $model->getProject(); //$config = $model->getTemplateConfig($this->getName()); if (isset($project)) { $this->project = $project; } $this->overallconfig = $model->getOverallConfig(); $this->config = $this->overallconfig; $this->matches = $model->getMatches(); $this->teams = $model->getTeamsFromMatches($this->matches); // load a class that handles ical formats. require_once JLG_PATH_SITE . DS . 'helpers' . DS . 'iCalcreator.class.php'; // create a new calendar instance $v = new vcalendar(); foreach ($this->matches as $match) { $hometeam = $this->teams[$match->team1]; $home = sprintf('%s', $hometeam->name); $guestteam = $this->teams[$match->team2]; $guest = sprintf('%s', $guestteam->name); $summary = $match->project_name . ': ' . $home . ' - ' . $guest; // check if match gots a date, if not it will not be included in ical if ($match->match_date) { $totalMatchTime = isset($project) ? $project->halftime * ($project->game_parts - 1) + $project->game_regular_time : 90; $start = JoomleagueHelper::getMatchStartTimestamp($match, 'Y-m-d H:i:s'); $end = JoomleagueHelper::getMatchEndTimestamp($match, $totalMatchTime, 'Y-m-d H:i:s'); // check if exist a playground in match or team or club $stringlocation = ''; $stringname = ''; if (!empty($match->playground_id)) { $stringlocation = $match->playground_address . ", " . $match->playground_zipcode . " " . $match->playground_city; $stringname = $match->playground_name; } elseif (!empty($match->team_playground_id)) { $stringlocation = $match->team_playground_address . ", " . $match->team_playground_zipcode . " " . $match->team_playground_city; $stringname = $match->team_playground_name; } elseif (!empty($match->club_playground_id)) { $stringlocation = $match->club_playground_address . ", " . $match->club_playground_zipcode . " " . $match->club_playground_city; $stringname = $match->club_playground_name; } $location = $stringlocation; //if someone want to insert more in description here is the place $description = $stringname; // create an event and insert it in calendar $vevent = new vevent(); $timezone = JoomleagueHelper::getMatchTimezone($match); $vevent->setProperty("dtstart", $start, array("TZID" => $timezone)); $vevent->setProperty("dtend", $end, array("TZID" => $timezone)); $vevent->setProperty('LOCATION', $location); $vevent->setProperty('summary', $summary); $vevent->setProperty('description', $description); $v->setComponent($vevent); } } $v->setProperty("X-WR-TIMEZONE", $timezone); $xprops = array("X-LIC-LOCATION" => $timezone); iCalUtilityFunctions::createTimezone($v, $timezone, $xprops); $v->returnCalendar(); //$debugstr = $v->createCalendar(); //echo "<pre>"; //echo $debugstr; // exit before display // parent::display( $tpl ); }
/** * @param array $start * @param array $end * @param bool $allday * @return vevent */ function dav_create_vevent($start, $end, $allday) { if ($end["year"] < $start["year"] || $end["year"] == $start["year"] && $end["month"] < $start["month"] || $end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] < $start["day"] || $end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] == $start["day"] && $end["hour"] < $start["hour"] || $end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] == $start["day"] && $end["hour"] == $start["hour"] && $end["minute"] < $start["minute"] || $end["year"] == $start["year"] && $end["month"] == $start["month"] && $end["day"] == $start["day"] && $end["hour"] == $start["hour"] && $end["minute"] == $start["minute"] && $end["second"] < $start["second"]) { $end = $start; } // DTEND muss <= DTSTART $vevent = new vevent(); if ($allday) { $vevent->setDtstart($start["year"], $start["month"], $start["day"], FALSE, FALSE, FALSE, FALSE, array("VALUE" => "DATE")); $end = IntVal(mktime(0, 0, 0, $end["month"], $end["day"], $end["year"]) + 3600 * 24); // If a DST change occurs on the current day $end += IntVal(date("Z", $end - 3600 * 24) - date("Z", $end)); $vevent->setDtend(date("Y", $end), date("m", $end), date("d", $end), FALSE, FALSE, FALSE, FALSE, array("VALUE" => "DATE")); } else { $vevent->setDtstart($start["year"], $start["month"], $start["day"], $start["hour"], $start["minute"], $start["second"], FALSE, array("VALUE" => "DATE-TIME")); $vevent->setDtend($end["year"], $end["month"], $end["day"], $end["hour"], $end["minute"], $end["second"], FALSE, array("VALUE" => "DATE-TIME")); } return $vevent; }
// create a new calendar instance $v->setConfig('unique_id', $data['link']); // set your unique id $v->setProperty('method', 'PUBLISH'); // required of some calendar software $v->setConfig('filename', "danaevents-" . $v->getConfig('filename')); $v->setXprop("X-WR-CALNAME", $data['title']); $v->setXprop("X-WR-CALDESC", $data['description']); foreach ($data['items'] as $item) { $lines = explode("\n", $item['description']); //<p>28/05/2008, 19:00 - 20:30</p> //print $lines[count($lines)-1]; preg_match("/(\\d+)\\/(\\d+)\\/(\\d+), (\\d+):(\\d+) - (\\d+):(\\d+)/", $lines[count($lines) - 1], $matches); //print_r($matches); //exit; $vevent = new vevent(); // create an event calendar component $vevent->setProperty('dtstart', array('year' => $matches[3], 'month' => $matches[2], 'day' => $matches[1], 'hour' => $matches[4], 'min' => $matches[5], 'sec' => 0)); $vevent->setProperty('dtend', array('year' => $matches[3], 'month' => $matches[2], 'day' => $matches[1], 'hour' => $matches[6], 'min' => $matches[7], 'sec' => 0)); $vevent->setProperty('LOCATION', '165 Queen\'s Gate, South Kensington, London, SW7 5HD'); // property name - case independent $vevent->setProperty('summary', $item['title']); preg_match("/href=\"([^\"]+)/", $lines[0], $matches); array_pop($lines); array_pop($lines); $desc = trim(strip_tags(html_entity_decode(implode("\n", $lines)))); $desc = str_replace("’", "'", $desc); $desc = str_replace("‘", "'", $desc); $desc .= "\n\n<a href=\"" . $matches[1] . "\">More info</a>"; $vevent->setProperty('description', $desc); $v->setComponent($vevent);
<?php /** * Create a ical for the upcoming recordings * * @license GPL * * @package MythWeb * @subpackage TV * **/ $calendar = new vcalendar(); $calendar->setConfig($_SERVER['SERVER_SIGNATURE'], $_SERVER['HTTP_HOST']); $calendar->setProperty('method', 'PUBLISH'); foreach ($all_shows as $show) { $event = new vevent(); $event->setProperty('dtstart', array('year' => date('Y', $show->starttime), 'month' => date('m', $show->starttime), 'day' => date('d', $show->starttime), 'hour' => date('H', $show->starttime), 'min' => date('i', $show->starttime), 'sec' => date('s', $show->starttime))); $event->setProperty('dtend', array('year' => date('Y', $show->endtime), 'month' => date('m', $show->endtime), 'day' => date('d', $show->endtime), 'hour' => date('H', $show->endtime), 'min' => date('i', $show->endtime), 'sec' => date('s', $show->endtime))); $event->setProperty('summary', $show->title . ($show->subtitle ? ' - ' . $show->subtitle : '')); $event->setProperty('description', $show->description . "\n\n" . preg_replace('/([A-Z]+)/', ' $1', $show->recstatus)); $event->setProperty('location', $show->channel->callsign); $calendar->setComponent($event); } $calendar->returnCalendar();
* to represent an anniversary that will occur annually. Since it takes * up no time, it will not appear as opaque in a search for busy time; * no matter what the value of the "TRANSP" property indicates: * * BEGIN:VEVENT * UID:19970901T130000Z-123403@host.com * DTSTAMP:19970901T1300Z * DTSTART:19971102 * SUMMARY:Our Blissful Anniversary * CLASS:CONFIDENTIAL * CATEGORIES:ANNIVERSARY,PERSONAL,SPECIAL OCCASION * RRULE:FREQ=YEARLY * END:VEVENT */ $c = new vcalendar(); $e = new vevent(); $e->setProperty('dtstart', '19971102'); $e->setProperty('summary', 'Our Blissful Anniversary'); $e->setProperty('class', 'CONFIDENTIAL'); $e->setProperty('categories', 'ANNIVERSARY'); $e->setProperty('categories', 'PERSONAL'); $e->setProperty('categories', 'SPECIAL OCCASION'); $e->setProperty('rrule', array('FREQ' => 'YEARLY')); $c->setComponent($e); $str = $c->createCalendar(); echo $str; echo "<br />\n\n"; /* * BEGIN:VTODO * UID:19970901T130000Z-123404@host.com * DTSTAMP:19970901T1300Z
/** * Export an event as iCalendar (ics) */ public function generateIcal($eventID) { $ical = new \vcalendar(); $ical->setConfig('ical_' . $this->id); $ical->setProperty('method', 'PUBLISH'); $ical->setProperty("X-WR-TIMEZONE", $GLOBALS['TL_CONFIG']['timeZone']); $time = time(); // Get event $objEvent = \CalendarEventsModel::findByPk($eventID); $vevent = new \vevent(); if ($objEvent->addTime) { $vevent->setProperty('dtstart', array('year' => date('Y', $objEvent->startTime), 'month' => date('m', $objEvent->startTime), 'day' => date('d', $objEvent->startTime), 'hour' => date('H', $objEvent->startTime), 'min' => date('i', $objEvent->startTime), 'sec' => 0)); $vevent->setProperty('dtend', array('year' => date('Y', $objEvent->endTime), 'month' => date('m', $objEvent->endTime), 'day' => date('d', $objEvent->endTime), 'hour' => date('H', $objEvent->endTime), 'min' => date('i', $objEvent->endTime), 'sec' => 0)); } else { $vevent->setProperty('dtstart', date('Ymd', $objEvent->startDate), array('VALUE' => 'DATE')); if (!strlen($objEvent->endDate) || $objEvent->endDate == 0) { $vevent->setProperty('dtend', date('Ymd', $objEvent->startDate + 24 * 60 * 60), array('VALUE' => 'DATE')); } else { $vevent->setProperty('dtend', date('Ymd', $objEvent->endDate + 24 * 60 * 60), array('VALUE' => 'DATE')); } } $vevent->setProperty('summary', $objEvent->title, ENT_QUOTES, 'UTF-8'); $vevent->setProperty('description', strip_tags($objEvent->details ? $objEvent->details : $objEvent->teaser)); if ($objEvent->recurring) { $count = 0; $arrRepeat = deserialize($objEvent->repeatEach); $arg = $arrRepeat['value']; $unit = $arrRepeat['unit']; if ($arg == 1) { $unit = substr($unit, 0, -1); } $strtotime = '+ ' . $arg . ' ' . $unit; $newstart = strtotime($strtotime, $objEvent->startTime); $newend = strtotime($strtotime, $objEvent->endTime); $freq = 'YEARLY'; switch ($arrRepeat['unit']) { case 'days': $freq = 'DAILY'; break; case 'weeks': $freq = 'WEEKLY'; break; case 'months': $freq = 'MONTHLY'; break; case 'years': $freq = 'YEARLY'; break; } $rrule = array('FREQ' => $freq); if ($objEvent->recurrences > 0) { $rrule['count'] = $objEvent->recurrences; } if ($arg > 1) { $rrule['INTERVAL'] = $arg; } $vevent->setProperty('rrule', $rrule); } /* * begin module event_recurrences handling */ if ($objEvent->repeatExecptions) { $arrSkipDates = deserialize($objEvent->repeatExecptions); foreach ($arrSkipDates as $skipDate) { $exTStamp = strtotime($skipDate); $exdate = array(array(date('Y', $exTStamp), date('m', $exTStamp), date('d', $exTStamp), date('H', $objEvent->startTime), date('i', $objEvent->startTime), date('s', $objEvent->startTime))); $vevent->setProperty('exdate', $exdate); } } /* * end module event_recurrences handling */ $ical->setComponent($vevent); $ical->setConfig("FILENAME", urlencode($objEvent->title) . ".ics"); $ical->returnCalendar(); }
/** * Prepare output in icalendar format a la RFC2445 * http://www.ietf.org/rfc/rfc2445.txt * * @return string */ public function icalendar() { $s = 'EJURI3ia8aj#912IKa'; $r = '#'; $e = 'aAEah38a;a33'; // ------------------------------------- // Some dummy tagdata we'll hand off to events() // ------------------------------------- $vars = array('event_title' => 'title', 'event_id' => 'id', 'event_summary' => 'summary', 'event_location' => 'location', 'event_start_date format="%Y"' => 'start_year', 'event_start_date format="%m"' => 'start_month', 'event_start_date format="%d"' => 'start_day', 'event_start_date format="%H"' => 'start_hour', 'event_start_date format="%i"' => 'start_minute', 'event_end_date format="%Y"' => 'end_year', 'event_end_date format="%m"' => 'end_month', 'event_end_date format="%d"' => 'end_day', 'event_end_date format="%H"' => 'end_hour', 'event_end_date format="%i"' => 'end_minute', 'event_calendar_tz_offset' => 'tz_offset', 'event_calendar_timezone' => 'timezone'); $rvars = array('rule_type', 'rule_start_date', 'rule_repeat_years', 'rule_repeat_months', 'rule_repeat_days', 'rule_repeat_weeks', 'rule_days_of_week', 'rule_relative_dow', 'rule_days_of_month', 'rule_months_of_year', 'rule_stop_by', 'rule_stop_after'); $evars = array('exception_start_date format="%Y%m%dT%H%i00"'); $ovars = array('occurrence_start_date format="%Y%m%dT%H%i00"', 'occurrence_end_date format="%Y%m%dT%H%i00"'); //ee()->TMPL->log_item('Calendar: Preparing tagdata'); $summary_field = ee()->TMPL->fetch_param('summary_field', 'event_title'); ee()->TMPL->tagdata = implode($s, array(LD . $summary_field . RD, LD . 'event_id' . RD, LD . 'if event_summary' . RD . LD . 'event_summary' . RD . LD . '/if' . RD, LD . 'if event_location' . RD . LD . 'event_location' . RD . LD . '/if' . RD, LD . 'event_start_date format="%Y"' . RD, LD . 'event_start_date format="%m"' . RD, LD . 'event_start_date format="%d"' . RD, LD . 'event_start_date format="%H"' . RD, LD . 'event_start_date format="%i"' . RD, LD . 'event_end_date format="%Y"' . RD, LD . 'event_end_date format="%m"' . RD, LD . 'event_end_date format="%d"' . RD, LD . 'event_end_date format="%H"' . RD, LD . 'event_end_date format="%i"' . RD, LD . 'event_calendar_tz_offset' . RD, LD . 'event_calendar_timezone' . RD, 'RULES' . LD . 'if event_has_rules' . RD . LD . 'rules' . RD . LD . implode(RD . $r . LD, $rvars) . RD . '|' . LD . T_SLASH . 'rules' . RD . LD . '/if' . RD, 'OCCURRENCES' . LD . 'if event_has_occurrences' . RD . LD . 'occurrences' . RD . LD . implode(RD . $r . LD, $ovars) . RD . '|' . LD . T_SLASH . 'occurrences' . RD . LD . '/if' . RD, 'EXCEPTIONS' . LD . 'if event_has_exceptions' . RD . LD . 'exceptions' . RD . LD . implode(RD . $r . LD, $evars) . RD . '|' . LD . T_SLASH . 'exceptions' . RD . LD . '/if' . RD, $e)); $tvars = ee()->functions->assign_variables(ee()->TMPL->tagdata); ee()->TMPL->var_single = $tvars['var_single']; ee()->TMPL->var_pair = $tvars['var_pair']; ee()->TMPL->tagdata = ee()->functions->prep_conditionals(ee()->TMPL->tagdata, array_keys($vars)); // ------------------------------------- // Fire up events() // ------------------------------------- //ee()->TMPL->log_item('Calendar: Firing up Events()'); $tagdata = ee()->TMPL->advanced_conditionals($this->events()); // ------------------------------------- // Collect the events // ------------------------------------- //ee()->TMPL->log_item('Calendar: Collecting events'); $events = explode($e, $tagdata); // ------------------------------------- // Fire up iCalCreator // ------------------------------------- //ee()->TMPL->log_item('Calendar: Starting iCalCreator'); if (!class_exists('vcalendar')) { require_once 'libraries/icalcreator/iCalcreator.class.php'; } $ICAL = new vcalendar(); //we are setting this manually because we need individual ones for each event for this to work //$ICAL->setConfig('unique_id', parse_url(ee()->config->item('site_url'), PHP_URL_HOST)); $host = parse_url(ee()->config->item('site_url'), PHP_URL_HOST); $vars = array_values($vars); //ee()->TMPL->log_item('Calendar: Iterating through the events'); foreach ($events as $key => $event) { if (trim($event) == '') { continue; } $E = new vevent(); $event = explode($s, $event); $rules = ''; $occurrences = ''; $exceptions = ''; foreach ($event as $k => $v) { if (isset($vars[$k])) { //-------------------------------------------- // Makes the local vars from above, if available: // $title, $summary, $location, // $start_year, $start_month, $start_day, // $start_hour, $start_minute, $end_year, // $end_month, $end_day, $end_hour, // $end_minute, $tz_offset, $timezone //-------------------------------------------- ${$vars}[$k] = $v; } elseif (substr($v, 0, 5) == 'RULES') { $rules = substr($v, 5); } elseif (substr($v, 0, 11) == 'OCCURRENCES') { $occurrences = substr($v, 11); } elseif (substr($v, 0, 10) == 'EXCEPTIONS') { $exceptions = substr($v, 10); } } // ------------------------------------- // Set the timezone for this calendar based on the first event's info // ------------------------------------- if ($key == 0) { // ------------------------------------- // Convert calendar_name to calendar_id // ------------------------------------- if ($this->P->value('calendar_id') == '' and $this->P->value('calendar_name') != '') { $ids = $this->data->get_calendar_id_from_name($this->P->value('calendar_name'), NULL, $this->P->params['calendar_name']['details']['not']); $this->P->set('calendar_id', implode('|', $ids)); } //-------------------------------------------- // lets try to get the timezone from the // passed calendar ID if there is one //-------------------------------------------- $cal_timezone = FALSE; $cal_tz_offset = FALSE; if ($this->P->value('calendar_id') != '') { $sql = "SELECT \ttz_offset, timezone\n\t\t\t\t\t\t\tFROM\texp_calendar_calendars\n\t\t\t\t\t\t\tWHERE \tcalendar_id\n\t\t\t\t\t\t\tIN \t\t(" . ee()->db->escape_str(implode(',', explode('|', $this->P->value('calendar_id')))) . ")\n\t\t\t\t\t\t\tLIMIT\t1"; $cal_tz_query = ee()->db->query($sql); if ($cal_tz_query->num_rows() > 0) { $cal_timezone = $cal_tz_query->row('timezone'); $cal_tz_offset = $cal_tz_query->row('tz_offset'); } } //last resort, we get it from the current event $T = new vtimezone(); $T->setProperty('tzid', $cal_timezone ? $cal_timezone : $timezone); $T->setProperty('tzoffsetfrom', '+0000'); $tzoffsetto = $cal_tz_offset ? $cal_tz_offset : $tz_offset; if ($tzoffsetto === '0000') { $tzoffsetto = '+0000'; } $T->setProperty('tzoffsetto', $tzoffsetto); $ICAL->setComponent($T); } $title = strip_tags($title); $description = strip_tags(trim($summary)); $location = strip_tags(trim($location)); // ------------------------------------- // Occurrences? // ------------------------------------- $occurrences = explode('|', rtrim($occurrences, '|')); $odata = array(); foreach ($occurrences as $k => $occ) { $occ = trim($occ); if ($occ == '') { continue; } $occ = explode($r, $occ); $odata[$k][] = $occ[0]; $odata[$k][] = $occ[1]; } // ------------------------------------- // Exceptions? // ------------------------------------- $exceptions = explode('|', rtrim($exceptions, '|')); $exdata = array(); foreach ($exceptions as $k => $exc) { $exc = trim($exc); if ($exc == '') { continue; } $exdata[] = $exc; } // ------------------------------------- // Rules? // ------------------------------------- $add_rules = FALSE; $erules = array(); $rules = explode('|', rtrim($rules, '|')); foreach ($rules as $rule) { $temp = explode($r, $rule); $rule = array(); foreach ($temp as $k => $v) { if ($v != FALSE) { $add_rules = TRUE; } $rule[substr($rvars[$k], 5)] = $v; } if ($add_rules === TRUE) { $temp = array(); if ($rule['repeat_years'] > 0) { $temp['FREQ'] = 'YEARLY'; if ($rule['repeat_years'] > 1) { $temp['INTERVAL'] = $rule['repeat_years']; } } elseif ($rule['repeat_months'] > 0) { $temp['FREQ'] = 'MONTHLY'; if ($rule['repeat_months'] > 1) { $temp['INTERVAL'] = $rule['repeat_months']; } } elseif ($rule['repeat_weeks'] > 0) { $temp['FREQ'] = 'WEEKLY'; if ($rule['repeat_weeks'] > 1) { $temp['INTERVAL'] = $rule['repeat_weeks']; } } elseif ($rule['repeat_days'] > 0) { $temp['FREQ'] = 'DAILY'; if ($rule['repeat_days'] > 1) { $temp['INTERVAL'] = $rule['repeat_days']; } } if ($rule['months_of_year'] > 0) { //this flips keys to make 'c' => 12, etc $m = array_flip(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C')); if (strlen($rule['months_of_year'] > 1)) { $months = str_split($rule['months_of_year']); foreach ($months as $month) { $temp['BYMONTH'][] = $m[$month] + 1; } } else { $temp['BYMONTH'] = $m[$month] + 1; } } if ($rule['days_of_month'] > '') { //this flips keys to make 'v' => 30, etc $d = array_flip(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V')); if (strlen($rule['days_of_month']) > 1) { $days = str_split($rule['days_of_month']); foreach ($days as $day) { $temp['BYMONTHDAY'][] = $d[$day] + 1; } } else { $temp['BYMONTHDAY'] = $d[$rule['days_of_month']] + 1; } } if ($rule['days_of_week'] != '' or $rule['days_of_week'] > 0) { $d = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'); $d_letter = array('U', 'M', 'T', 'W', 'R', 'F', 'S'); $dows = str_split($rule['days_of_week']); if ($rule['relative_dow'] > 0) { $rels = str_split($rule['relative_dow']); foreach ($dows as $dow) { foreach ($rels as $rel) { if ($rel == 6) { $rel = -1; } $temp['BYDAY'][] = $rel . $d[array_search($dow, $d_letter)]; } } } else { foreach ($dows as $dow) { $temp['BYDAY'][] = $d[array_search($dow, $d_letter)]; } } } if ($rule['stop_after'] > 0) { $temp['COUNT'] = $rule['stop_after']; } elseif ($rule['stop_by'] > 0) { // TODO: Add time // TODO: The "+1" below is because the ical standard treats // UNTIL as "less than", not "less than or equal to" (which // is how Calendar treats stop_by). Double check that a simple // "+1" accurately addresses this difference. $temp['UNTIL'] = $rule['stop_by'] + 1; } $erules[] = $temp; } } // ------------------------------------- // Put it together // ------------------------------------- //if this is all day we need to add the dates as params to the dstart and end items if ($this->_is_all_day($start_hour, $start_minute, $end_hour, $end_minute)) { $E->setProperty("dtstart", array('year' => $start_year, 'month' => $start_month, 'day' => $start_day), array('VALUE' => 'DATE')); //-------------------------------------------- // we need CDT so we can add a day // gcal, and ical are ok with this being the same day // stupid damned outlook barfs, hence the +1 // the +1 doesnt affect g/ical //-------------------------------------------- if (!isset($this->CDT) or !is_object($this->CDT)) { $this->load_calendar_datetime(); } $this->CDT->change_date($end_year, $end_month, $end_day); $this->CDT->add_day(); $E->setProperty("dtend", array('year' => $this->CDT->year, 'month' => $this->CDT->month, 'day' => $this->CDT->day), array('VALUE' => 'DATE')); } else { $E->setProperty('dtstart', $start_year, $start_month, $start_day, $start_hour, $start_minute, 00); $E->setProperty('dtend', $end_year, $end_month, $end_day, $end_hour, $end_minute, 00); } $E->setProperty('summary', $title); if (!empty($erules)) { foreach ($erules as $rule) { $E->setProperty('rrule', $rule); } } $extras = array(); $edits = array(); if (!empty($odata)) { $query = ee()->db->query("SELECT *\n\t\t\t\t\t FROM\texp_calendar_events_occurrences\n\t\t\t\t\t WHERE\tevent_id = " . ee()->db->escape_str($id)); foreach ($query->result_array() as $row) { //fix blank times $row['start_time'] = $row['start_time'] == 0 ? '0000' : $row['start_time']; $row['end_time'] = $row['end_time'] == 0 ? '2400' : $row['end_time']; //looks like an edited occurrence //edits without rules arent really edits. if ($row['event_id'] != $row['entry_id'] and empty($rules)) { $edits[] = $row; } else { $extras[] = $row; } } } if (!empty($exdata)) { $E->setProperty('exdate', $exdata); } if ($description != '') { $E->setProperty('description', $description); } if ($location != '') { $E->setProperty('location', $location); } $E->setProperty("uid", $this->make_uid() . '@' . $host); $ICAL->setComponent($E); //-------------------------------------------- // remove rules for subsequent items //-------------------------------------------- while ($E->deleteProperty("RRULE")) { continue; } //edits must come right after if (!empty($edits)) { foreach ($edits as $edit) { $edit_date = array("year" => $edit['start_year'], "month" => $edit['start_month'], "day" => $edit['start_day'], "hour" => substr($edit['start_time'], 0, 2), "min" => substr($edit['start_time'], 2, 2)); //if this is all day we need to add the dates as params to the dstart and end items if ($this->_is_all_day(substr($edit['start_time'], 0, 2), substr($edit['start_time'], 2, 2), substr($edit['end_time'], 0, 2), substr($edit['end_time'], 2, 2))) { $E->setProperty("dtstart", array('year' => $edit['start_year'], 'month' => $edit['start_month'], 'day' => $edit['start_day']), array('VALUE' => 'DATE')); //-------------------------------------------- // we need CDT so we can add a day // gcal, and ical are ok with this being the same day // stupid damned outlook barfs, hence the +1 // the +1 doesnt affect g/ical //-------------------------------------------- if (!isset($this->CDT) or !is_object($this->CDT)) { $this->load_calendar_datetime(); } $this->CDT->change_date($edit['end_year'], $edit['end_month'], $edit['end_day']); $this->CDT->add_day(); $E->setProperty("dtend", array('year' => $this->CDT->year, 'month' => $this->CDT->month, 'day' => $this->CDT->day), array('VALUE' => 'DATE')); } else { $E->setProperty('dtstart', $edit_date['year'], $edit_date['month'], $edit_date['day'], $edit_date['hour'], $edit_date['min'], 00); $E->setProperty('dtend', $edit['end_year'], $edit['end_month'], $edit['end_day'], substr($edit['end_time'], 0, 2), substr($edit['end_time'], 2, 2), 00); } $E->setProperty("RECURRENCE-ID", $edit_date); $E->setProperty("uid", $this->make_uid() . '@' . $host); $ICAL->setComponent($E); } //cleanup $E->deleteProperty("RECURRENCE-ID"); $E->setProperty('dtstart', $start_year, $start_month, $start_day, $start_hour, $start_minute, 00); $E->setProperty('dtend', $end_year, $end_month, $end_day, $end_hour, $end_minute, 00); } // these random ass add-in dates are non-standard to most cal creation // and need to be treated seperately as lumping don't work, dog if (!empty($extras)) { foreach ($extras as $extra) { //if this is all day we need to add the dates as params to the dstart and end items if ($this->_is_all_day(substr($extra['start_time'], 0, 2), substr($extra['start_time'], 2, 2), substr($extra['end_time'], 0, 2), substr($extra['end_time'], 2, 2))) { $E->setProperty("dtstart", array('year' => $extra['start_year'], 'month' => $extra['start_month'], 'day' => $extra['start_day']), array('VALUE' => 'DATE')); //-------------------------------------------- // we need CDT so we can add a day // gcal, and ical are ok with this being the same day // stupid damned outlook barfs, hence the +1 // the +1 doesnt affect g/ical //-------------------------------------------- if (!isset($this->CDT) or !is_object($this->CDT)) { $this->load_calendar_datetime(); } $this->CDT->change_date($extra['end_year'], $extra['end_month'], $extra['end_day']); $this->CDT->add_day(); $E->setProperty("dtend", array('year' => $this->CDT->year, 'month' => $this->CDT->month, 'day' => $this->CDT->day), array('VALUE' => 'DATE')); } else { $E->setProperty('dtstart', $extra['start_year'], $extra['start_month'], $extra['start_day'], substr($extra['start_time'], 0, 2), substr($extra['start_time'], 2, 2), 00); $E->setProperty('dtend', $extra['end_year'], $extra['end_month'], $extra['end_day'], substr($extra['end_time'], 0, 2), substr($extra['end_time'], 2, 2), 00); } $E->setProperty("uid", $this->make_uid() . '@' . $host); $ICAL->setComponent($E); } //clean in case we need to add more later $E->setProperty('dtstart', $start_year, $start_month, $start_day, $start_hour, $start_minute, 00); $E->setProperty('dtend', $end_year, $end_month, $end_day, $end_hour, $end_minute, 00); } } //return $ICAL->createCalendar(); return $ICAL->returnCalendar(); }
echo "<pre>"; print_r($matches); echo "</pre>"; */ foreach ($matches as $val) { /* Find a valid date in the 87 chars. */ if (preg_match('/([0-9]{2})\\.([0-9]{2})\\.([0-9]{4})/', $val[2], $date_match)) { $tsY = $date_match[3]; $tsm = $date_match[2]; $tsd = $date_match[1]; $tsH = 20; $tsi = 0; $tss = 0; $title = $val[1]; /* If found, put a ne event with the actual date und movie title together. */ $e = new vevent(); $e->setProperty('categories', 'FAMILY'); $e->setProperty('dtstart', $tsY, $tsm, $tsd, $tsH, $tsi, $tss, "Europe/Berlin"); $e->setProperty('location', 'Kino'); $e->setProperty('duration', 0, 0, 3); //$e->setProperty( 'description', 'blablabla' ); $e->setProperty('SUMMARY', $title); $e->setProperty("transp", "TRANSPARENT"); $e->setProperty("sequence"); $e->setProperty("dtstamp", $tsY, $tsm, $tsd, $tsH, $tsi, $tss); $v->addComponent($e); /* Delete variables. */ unset($e); unset($tsY); unset($tsm); unset($tsd);
* version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ require_once 'iCalcreator.class.php'; echo "Use browser function to show source!<br />\n<br />\n"; $v = new vcalendar(); // initiate new CALENDAR $e = new vevent(); // initiate a new EVENT $e->setProperty('categories', 'FAMILY'); // catagorize $e->setProperty('dtstart', 2006, 12, 24, 19, 30, 00); // 24 dec 2006 19.30 $e->setProperty('duration', 0, 0, 3); // 3 hours $e->setProperty('description', 'x-mas evening - diner'); // describe the event $e->setProperty('location', 'Jeffikus'); // locate the event $v->addComponent($e); // add component to calendar /* alt. production */ // $v->returnCalendar(); // generate and redirect output to user browser
function display($tpl = null) { // Get a reference of the page instance in joomla $document = JFactory::getDocument(); $model = $this->getModel(); $project =& $model->getProject(); $config = $model->getTemplateConfig($this->getName()); if (isset($project)) { $this->assignRef('project', $project); $this->assignRef('overallconfig', $model->getOverallConfig()); $this->assignRef('config', $this->overallconfig); $this->assignRef('teams', $model->getTeamsIndexedByPtid()); $this->assignRef('matches', $model->getMatches($config)); } // load a class that handles ical formats. require_once JLG_PATH_SITE . DS . 'helpers' . DS . 'iCalcreator.class.php'; // create a new calendar instance $v = new vcalendar(); foreach ($this->matches as $match) { $hometeam = $this->teams[$match->projectteam1_id]; $home = sprintf('%s', $hometeam->name); $guestteam = $this->teams[$match->projectteam2_id]; $guest = sprintf('%s', $guestteam->name); $summary = $project->name . ': ' . $home . ' - ' . $guest; // check if match gots a date, if not it will not be included // in ical if (!strstr($match->match_date, "0000-00-00")) { $syear = JHTML::date($match->match_date, "%Y"); $sday = JHTML::date($match->match_date, "%d"); $smonth = JHTML::date($match->match_date, "%m"); $shour = JHTML::date($match->match_date, "%H"); $smin = JHTML::date($match->match_date, "%M"); //$start = JHTML::date($match->match_date, "%Y-%m-%d %H:%M:%S" ); $start = strftime("%Y-%m-%d %H:%M:%S", strtotime($match->match_date)); $start_oldphpversion = array('year' => $syear, 'month' => $smonth, 'day' => $sday, 'hour' => $shour, 'min' => $smin, 'sec' => 0); $time_to_ellapse = $project->halftime * ($project->game_parts - 1) + $project->game_regular_time; $endtime = JoomleagueHelper::getTimestamp($match->match_date) + $time_to_ellapse * 60; $year = JHTML::date($endtime, "%Y"); $day = JHTML::date($endtime, "%d"); $month = JHTML::date($endtime, "%m"); $hour = JHTML::date($endtime, "%H"); $min = JHTML::date($endtime, "%M"); //$end = JHTML::date($endtime, "%Y-%m-%d %H:%M:%S" ); $end = strftime("%Y-%m-%d %H:%M:%S", $endtime); $end_oldphpversion = array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'min' => $min, 'sec' => 0); // check if exist a playground in match or team or club if ($match->playground_id != "") { $stringlocation = $match->playground_address . ", " . $match->playground_zipcode . " " . $match->playground_city; $stringname = $match->playground_name; } else { if ($match->team_playground_id != "") { $stringlocation = $match->team_playground_address . ", " . $match->team_playground_zipcode . " " . $match->team_playground_city; $stringname = $match->team_playground_name; } elseif ($match->club_playground_id != "") { $stringlocation = $match->club_playground_address . ", " . $match->club_playground_zipcode . " " . $match->club_playground_city; $stringname = $match->club_playground_name; } } $location = $stringlocation; //if someone want to insert more in description here is the place $description = $stringname; // create an event and insert it in calendar $vevent = new vevent(); $vevent->setProperty("dtstart", $start, array("TZID" => $project->timezone)); $vevent->setProperty("dtend", $end, array("TZID" => $project->timezone)); $vevent->setProperty('LOCATION', $location); $vevent->setProperty('summary', $summary); $vevent->setProperty('description', $description); $v->setComponent($vevent); } } $v->returnCalendar(); // exit before display // parent::display( $tpl ); }
$tpl->assign("calendar", $calendar); $tpl->assign("rss", $rss); $show_detail = false; } } else { $calendar = new vcalendar(); $calsql = $data->select_query("calendar_items", "WHERE allowed = 1 AND trash=0"); while ($temp = $data->fetch_array($calsql)) { $groups = unserialize($temp['groups']); if (is_array($groups)) { $allowed = in_group($groups); } else { $allowed = true; } if ($allowed) { $e = new vevent(); $e->setProperty('categories', $config['troopname'] . " Calendar"); $date = getdate($temp['startdate']); $e->setProperty('dtstart', $date['year'], $date['mon'], $date['mday'], $date['hours'], $date['minutes'], 00); $date = getdate($temp['enddate']); $e->setProperty('dtend', $date['year'], $date['mon'], $date['mday'], $date['hours'], $date['minutes'], 00); $e->setProperty('summary', censor($temp['summary'])); $e->setProperty('description', $temp['detail'] != NULL ? truncate(strip_tags(censor($temp['detail']))) : "No details"); $calendar->addComponent($e); } } header('Content-type: text/calendar'); header('Content-Disposition: attachment; filename="calendar.ics"'); echo $calendar->createCalendar(); exit; }
/** * Generate ical file content * * @param $who user ID * @param $who_group group ID * @param $limititemtype itemtype only display this itemtype (default '') * * @return icalendar string **/ static function generateIcal($who, $who_group, $limititemtype = '') { global $CFG_GLPI; if ($who === 0 && $who_group === 0) { return false; } include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php"; $v = new vcalendar(); if (!empty($CFG_GLPI["version"])) { $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"])); } else { $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion"); } $tz = date_default_timezone_get(); $v->setConfig('TZID', $tz); $v->setProperty("method", "PUBLISH"); $v->setProperty("version", "2.0"); $v->setProperty("X-WR-TIMEZONE", $tz); $xprops = array("X-LIC-LOCATION" => $tz); iCalUtilityFunctions::createTimezone($v, $tz, $xprops); $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group); $v->setProperty("calscale", "GREGORIAN"); $interv = array(); $begin = time() - MONTH_TIMESTAMP * 12; $end = time() + MONTH_TIMESTAMP * 12; $begin = date("Y-m-d H:i:s", $begin); $end = date("Y-m-d H:i:s", $end); $params = array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end); $interv = array(); if (empty($limititemtype)) { foreach ($CFG_GLPI['planning_types'] as $itemtype) { $interv = array_merge($interv, $itemtype::populatePlanning($params)); } } else { $interv = $limititemtype::populatePlanning($params); } if (count($interv) > 0) { foreach ($interv as $key => $val) { $vevent = new vevent(); //initiate EVENT if (isset($val['itemtype'])) { if (isset($val[getForeignKeyFieldForItemType($val['itemtype'])])) { $vevent->setProperty("uid", $val['itemtype'] . "#" . $val[getForeignKeyFieldForItemType($val['itemtype'])]); } else { $vevent->setProperty("uid", "Other#" . $key); } } else { $vevent->setProperty("uid", "Other#" . $key); } $vevent->setProperty("dstamp", $val["begin"]); $vevent->setProperty("dtstart", $val["begin"]); $vevent->setProperty("dtend", $val["end"]); if (isset($val["tickets_id"])) { $vevent->setProperty("summary", sprintf(__('Ticket #%1$s %2$s'), $val["tickets_id"], $val["name"])); } else { if (isset($val["name"])) { $vevent->setProperty("summary", $val["name"]); } } if (isset($val["content"])) { $text = $val["content"]; // be sure to replace nl by \r\n $text = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $text); $text = Html::clean($text); $vevent->setProperty("description", $text); } else { if (isset($val["name"])) { $text = $val["name"]; // be sure to replace nl by \r\n $text = preg_replace("/<br( [^>]*)?" . ">/i", "\r\n", $text); $text = Html::clean($text); $vevent->setProperty("description", $text); } } if (isset($val["url"])) { $vevent->setProperty("url", $val["url"]); } $v->setComponent($vevent); } } $v->sort(); // $v->parse(); return $v->returnCalendar(); }
/** * Returns modified ical uid for google recurring edited events. * * @param vevent $e Vevent object. * * @return string ICAL uid. */ protected function _get_ical_uid($e) { $ical_uid = $e->getProperty('uid'); $recurrence_id = $e->getProperty('recurrence-id'); if (false !== $recurrence_id) { $ical_uid = implode('', array_values($recurrence_id)) . '-' . $ical_uid; } return $ical_uid; }
/** * Export the Event with calendar and stop excuting script * * @return null */ function export() { global $_CONFIG; //create new calendar $objVCalendar = new \vcalendar(); $objVCalendar->setConfig('unique_id', $_CONFIG['coreGlobalPageTitle']); $objVCalendar->setConfig('filename', urlencode($this->title) . '.ics'); // set Your unique id //$v->setProperty('X-WR-CALNAME', 'Calendar Sample'); //$v->setProperty('X-WR-CALDESC', 'Calendar Description'); //$v->setProperty('X-WR-TIMEZONE', 'America/Los_Angeles'); $objVCalendar->setProperty('X-MS-OLK-FORCEINSPECTOROPEN', 'TRUE'); $objVCalendar->setProperty('METHOD', 'PUBLISH'); // create an event calendar component $objVEvent = new \vevent(); // start $startYear = date("Y", $this->startDate); $startMonth = date("m", $this->startDate); $startDay = date("d", $this->startDate); $startHour = date("H", $this->startDate); $startMinute = date("i", $this->startDate); $objVEvent->setProperty('dtstart', array('year' => $startYear, 'month' => $startMonth, 'day' => $startDay, 'hour' => $startHour, 'min' => $startMinute, 'sec' => 0)); // end $endYear = date("Y", $this->endDate); $endMonth = date("m", $this->endDate); $endDay = date("d", $this->endDate); $endHour = date("H", $this->endDate); $endMinute = date("i", $this->endDate); $objVEvent->setProperty('dtend', array('year' => $endYear, 'month' => $endMonth, 'day' => $endDay, 'hour' => $endHour, 'min' => $endMinute, 'sec' => 0)); // place if (!empty($this->place)) { $objVEvent->setProperty('location', html_entity_decode($this->place, ENT_QUOTES, CONTREXX_CHARSET)); } // title $objVEvent->setProperty('summary', html_entity_decode($this->title, ENT_QUOTES, CONTREXX_CHARSET)); // description $objVEvent->setProperty('description', html_entity_decode(strip_tags($this->description), ENT_QUOTES, CONTREXX_CHARSET)); // organizer $objVEvent->setProperty('organizer', $_CONFIG['coreGlobalPageTitle'] . ' <' . $_CONFIG['coreAdminEmail'] . '>'); // comment //$objVEvent->setProperty( 'comment', 'This is a comment' ); // attendee //$objVEvent->setProperty( 'attendee', '*****@*****.**' ); // ressourcen //$objVEvent->setProperty( 'resources', 'COMPUTER PROJECTOR' ); // series type //$objVEvent->setProperty( 'rrule', array( 'FREQ' => 'WEEKLY', 'count' => 4));// weekly, four occasions // add event to calendar $objVCalendar->setComponent($objVEvent); $objVCalendar->returnCalendar(); exit; }
function cs_event_calendar($post_id = '') { if (!isset($post_id) && $post_id == '') { global $post; $post_id = $post->ID; } $cal_post = get_post($post_id); if ($cal_post) { $event_from_date = get_post_meta($post_id, "cs_event_from_date", true); $cs_event_to_date = get_post_meta($post_id, "cs_event_to_date", true); $cs_event_meta = get_post_meta($post_id, "cs_event_meta", true); if ($cs_event_meta != "") { $cs_event_meta = new SimpleXMLElement($cs_event_meta); if ($cs_event_meta->event_address != '') { $address_map = get_the_title("{$cs_event_meta->event_address}"); } else { $address_map = ''; } } $cs_event_loc = get_post_meta($cs_event_meta->event_address, "cs_event_loc_meta", true); if ($cs_event_loc != "") { $cs_xmlObject = new SimpleXMLElement($cs_event_loc); $loc_address = $cs_xmlObject->loc_address; $event_loc_lat = $cs_xmlObject->event_loc_lat; $event_loc_long = $cs_xmlObject->event_loc_long; $event_loc_zoom = $cs_xmlObject->event_loc_zoom; $loc_city = $cs_xmlObject->loc_city; $loc_postcode = $cs_xmlObject->loc_postcode; $loc_country = $cs_xmlObject->loc_country; $location = $loc_address . ', ' . $loc_city . ', ' . $loc_postcode . ', ' . $loc_country; } else { $loc_address = ''; $event_loc_lat = ''; $event_loc_long = ''; $event_loc_zoom = ''; $loc_city = ''; $loc_postcode = ''; $loc_country = ''; $location = ''; } $start_year = date('Y', strtotime($event_from_date)); $start_month = date('m', strtotime($event_from_date)); $start_day = date('d', strtotime($event_from_date)); $end_year = date('Y', strtotime($cs_event_to_date)); $end_month = date('m', strtotime($cs_event_to_date)); $end_day = date('d', strtotime($cs_event_to_date)); if ($cs_event_meta->event_all_day != "on") { $start_time = calender_time($cs_event_meta->event_start_time); $end_time = calender_time($cs_event_meta->event_end_time); } else { $start_time = $end_time = ''; } if ($start_time != '' && $start_time != ':') { $event_start_time = explode(":", $start_time); } if ($end_time != '' && $end_time != ':') { $event_end_time = explode(":", $end_time); } $post_title = get_the_title($post_id); $cs_vcalendar = new vcalendar(); $cs_vevent = new vevent(); $site_info = get_bloginfo('name') . 'Events'; $cs_vevent->setProperty('categories', $site_info); if (isset($event_start_time)) { @$cs_vevent->setProperty('dtstart', @$start_year, @$start_month, @$start_day, @$event_start_time[0], @$event_start_time[1], 00); } else { $cs_vevent->setProperty('dtstart', $start_year, $start_month, $start_day); } // YY MM dd hh mm ss if (isset($event_end_time)) { @$cs_vevent->setProperty('dtend', $end_year, $end_month, $end_day, $event_end_time[0], $event_end_time[1], 00); } else { $cs_vevent->setProperty('dtend', $end_year, $end_month, $end_day); } // YY MM dd hh mm ss $cs_vevent->setProperty('description', strip_tags($cal_post->post_excerpt)); if (isset($location)) { $cs_vevent->setProperty('location', $location); } $cs_vevent->setProperty('summary', $post_title); $cs_vcalendar->addComponent($cs_vevent); $templateurl = get_template_directory_uri() . '/cache/'; //makeDir(get_bloginfo('template_directory').'/cache/'); $home = home_url(); $dir = str_replace($home, '', $templateurl); $dir = str_replace('/wp-content/', 'wp-content/', $dir); $directory_url = get_template_directory_uri(); $directorypath = explode('/', $directory_url); $themefolderName = $directorypath[count($directorypath) - 1]; $cs_vcalendar->setConfig('directory', ABSPATH . 'wp-content/themes/' . $themefolderName . '/cache'); $cs_vcalendar->setConfig('filename', 'event-' . $post_id . '.ics'); $cs_vcalendar->saveCalendar(); ////OUT LOOK & iCAL URL// $output_calendar_url['ical'] = $templateurl . 'event-' . $post_id . '.ics'; ////GOOGLE URL// $google_url = "http://www.google.com/calendar/event?action=TEMPLATE"; $google_url .= "&text=" . urlencode($post_title); if (isset($event_start_time) && isset($event_end_time)) { $google_url .= "&dates=" . @$start_year . @$start_month . @$start_day . "T" . str_replace('.', '', @$event_start_time[0]) . str_replace('.', '', @$event_start_time[1]) . "00/" . @$end_year . @$end_month . @$end_day . "T" . str_replace('.', '', @$event_end_time[0]) . str_replace('.', '', @$event_end_time[1]) . "00"; } else { $google_url .= "&dates=" . $start_year . $start_month . $start_day . "/" . $end_year . $end_month . $end_day; } $google_url .= "&sprop=website:" . get_permalink($post_id); $google_url .= "&details=" . strip_tags($cal_post->post_excerpt); if (isset($location)) { $google_url .= "&location=" . $location; } else { $google_url .= "&location=Unknown"; } $google_url .= "&trp=true"; $output_calendar_url['google'] = $google_url; ////YAHOO CALENDAR URL/// $yahoo_url = "http://calendar.yahoo.com/?v=60&view=d&type=20"; $yahoo_url .= "&title=" . str_replace(' ', '+', $post_title); if (isset($event_start_time)) { $yahoo_url .= "&st=" . @$start_year . @$start_month . @$start_day . "T" . @$event_start_time[0] . @$event_start_time[1] . "00"; } else { $yahoo_url .= "&st=" . $start_year . $start_month . $start_day; } if (isset($event_end_time)) { //$yahoo_url .= "&dur=".$event_start_time[0].$event_start_time[1]; } $yahoo_url .= "&desc=" . str_replace(' ', '+', strip_tags($cal_post->post_excerpt)) . ' -- ' . get_permalink($post_id); $yahoo_url .= "&in_loc=" . str_replace(' ', '+', $location); $output_calendar_url['yahoo'] = $yahoo_url; } return $output_calendar_url; }