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 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); }
/** * @return array */ private function getICalPeriods() { $response = []; $iCalLink = $this->checkForICalHref(); if ($this->checkAccessToFile($iCalLink)) { $startArray = array(); $endArray = array(); require_once 'iCalcreator.php'; $v = new \vcalendar(); // initiate new CALENDAR $config = array("unique_id" => "ukrapts.com", "url" => "{$iCalLink}"); $v->setConfig($config); $v->parse(); $v->sort(); $i = 0; while ($comp = $v->getComponent("VEVENT")) { $dtstart_array = $comp->getProperty("DTSTART", 1, TRUE); $dtstart = $dtstart_array["value"]; $startDate = "{$dtstart["year"]}-{$dtstart["month"]}-{$dtstart["day"]}"; $dtend_array = $comp->getProperty("dtend", 1, TRUE); $dtend = $dtend_array["value"]; $endDate = "{$dtend["year"]}-{$dtend["month"]}-{$dtend["day"]}"; if ($endDate >= $this->DBQueries()->currentDate()) { $startArray[] = $startDate; $endArray[] = $endDate; } $i++; } sort($startArray); sort($endArray); $response['start'] = $startArray; $response['end'] = $endArray; } return $response; }
private static function row2array($row, $timezone, $hostname, $uid, $namespace_id) { $v = new vcalendar(); $v->setConfig('unique_id', $hostname); $v->setProperty('method', 'PUBLISH'); $v->setProperty("x-wr-calname", "AnimexxCal"); $v->setProperty("X-WR-CALDESC", "Animexx Calendar"); $v->setProperty("X-WR-TIMEZONE", $timezone); if ($row["adjust"]) { $start = datetime_convert('UTC', date_default_timezone_get(), $row["start"]); $finish = datetime_convert('UTC', date_default_timezone_get(), $row["finish"]); } else { $start = $row["start"]; $finish = $row["finish"]; } $allday = strpos($start, "00:00:00") !== false && strpos($finish, "00:00:00") !== false; /* if ($allday) { $dat = Datetime::createFromFormat("Y-m-d H:i:s", $finish_tmp); $dat->sub(new DateInterval("P1D")); $finish = datetime_convert("UTC", date_default_timezone_get(), $dat->format("Y-m-d H:i:s")); var_dump($finish); } */ $subject = substr(preg_replace("/\\[[^\\]]*\\]/", "", $row["desc"]), 0, 100); $description = preg_replace("/\\[[^\\]]*\\]/", "", $row["desc"]); $vevent = dav_create_vevent(wdcal_mySql2icalTime($row["start"]), wdcal_mySql2icalTime($row["finish"]), false); $vevent->setLocation(icalendar_sanitize_string($row["location"])); $vevent->setSummary(icalendar_sanitize_string($subject)); $vevent->setDescription(icalendar_sanitize_string($description)); $v->setComponent($vevent); $ical = $v->createCalendar(); return array("uid" => $uid, "namespace" => CALDAV_NAMESPACE_FRIENDICA_NATIVE, "namespace_id" => $namespace_id, "date" => $row["edited"], "data_uri" => "friendica-" . $namespace_id . "-" . $row["id"] . "@" . $hostname, "data_subject" => $subject, "data_location" => $row["location"], "data_description" => $description, "data_start" => $start, "data_end" => $finish, "data_allday" => $allday, "data_type" => $row["type"], "ical" => $ical, "ical_size" => strlen($ical), "ical_etag" => md5($ical)); }
function create($name, $description = '', $tz = 'US/Pacific') { $v = new vcalendar(); $v->setConfig('unique_id', $name . '.' . 'yourdomain.com'); $v->setProperty('method', 'PUBLISH'); $v->setProperty('x-wr-calname', $name . ' Calendar'); $v->setProperty("X-WR-CALDESC", $description); $v->setProperty("X-WR-TIMEZONE", $tz); $this->calendar = $v; }
/** * The file contents is looked at and events are created here. * @param string $fileContents * @return integer The number of events saved. */ public function setEventsFromICal($fullDir, $fullFileName, $personId) { //start parse of local file $v = new vcalendar(); // set directory $v->setConfig('directory', $fullDir); // set file name $v->setConfig('filename', $fullFileName); $v->parse(); $count = 0; foreach ($v->components as $component => $info) { # get first vevent $comp = $v->getComponent("VEVENT"); $summary_array = $comp->getProperty("summary", 1, TRUE); //echo "Event: ", $summary_array["value"], "\n"; $dtstart_array = $comp->getProperty("dtstart", 1, TRUE); $dtstart = $dtstart_array["value"]; $startDate = "{$dtstart["year"]}-{$dtstart["month"]}-{$dtstart["day"]}"; $startTime = "{$dtstart["hour"]}:{$dtstart["min"]}:{$dtstart["sec"]}"; $dtend_array = $comp->getProperty("dtend", 1, TRUE); $dtend = $dtend_array["value"]; $endDate = "{$dtend["year"]}-{$dtend["month"]}-{$dtend["day"]}"; $endTime = "{$dtend["hour"]}:{$dtend["min"]}:{$dtend["sec"]}"; //echo "start: ", $startDate,"T",$startTime, "\n"; //echo "end: ", $endDate,"T",$endTime, "\n"; $location_array = $comp->getProperty("location", 1, TRUE); //echo "Location: ", $location_array["value"], "\n <br>"; //TODO: Check that this event does not already exist. $event = new Event(); $event->setPersonId($personId); $event->setName($summary_array["value"]); $event->setStartTime($startDate . "T" . $startTime); $event->setEndTime($endDate . "T" . $endTime); $event->setLocation($location_array["value"]); $event->save(); $count++; } return $count; }
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 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; }
/** * @param DBClass_friendica_calendars $calendar * @param DBClass_friendica_calendarobjects $calendarobject */ function renderCalDavEntry_data(&$calendar, &$calendarobject) { $a = get_app(); $v = new vcalendar(); $v->setConfig('unique_id', $a->get_hostname()); $v->parse($calendarobject->calendardata); $v->sort(); $eventArray = $v->selectComponents(2009, 1, 1, date("Y") + 2, 12, 30); $start_min = $end_max = ""; $allday = $summary = $vevent = $rrule = $color = $start = $end = null; $location = $description = ""; foreach ($eventArray as $yearArray) { foreach ($yearArray as $monthArray) { foreach ($monthArray as $day => $dailyEventsArray) { foreach ($dailyEventsArray as $vevent) { /** @var $vevent vevent */ $start = ""; $rrule = "NULL"; $allday = 0; $dtstart = $vevent->getProperty('X-CURRENT-DTSTART'); if (is_array($dtstart)) { $start = "'" . $dtstart[1] . "'"; if (strpos($dtstart[1], ":") === false) { $allday = 1; } } else { $dtstart = $vevent->getProperty('dtstart'); if (isset($dtstart["day"]) && $dtstart["day"] == $day) { // Mehrtägige Events nur einmal rein if (isset($dtstart["hour"])) { $start = "'" . $dtstart["year"] . "-" . $dtstart["month"] . "-" . $dtstart["day"] . " " . $dtstart["hour"] . ":" . $dtstart["minute"] . ":" . $dtstart["secont"] . "'"; } else { $start = "'" . $dtstart["year"] . "-" . $dtstart["month"] . "-" . $dtstart["day"] . " 00:00:00'"; $allday = 1; } } } $dtend = $vevent->getProperty('X-CURRENT-DTEND'); if (is_array($dtend)) { $end = "'" . $dtend[1] . "'"; if (strpos($dtend[1], ":") === false) { $allday = 1; } } else { $dtend = $vevent->getProperty('dtend'); if (isset($dtend["hour"])) { $end = "'" . $dtend["year"] . "-" . $dtend["month"] . "-" . $dtend["day"] . " " . $dtend["hour"] . ":" . $dtend["minute"] . ":" . $dtend["second"] . "'"; } else { $end = "'" . $dtend["year"] . "-" . $dtend["month"] . "-" . $dtend["day"] . " 00:00:00' - INTERVAL 1 SECOND"; $allday = 1; } } $summary = $vevent->getProperty('summary'); $description = $vevent->getProperty('description'); $location = $vevent->getProperty('location'); $rrule_prob = $vevent->getProperty('rrule'); if ($rrule_prob != null) { $rrule = $vevent->createRrule(); $rrule = "'" . dbesc($rrule) . "'"; } $color_ = $vevent->getProperty("X-ANIMEXX-COLOR"); $color = is_array($color_) ? $color_[1] : "NULL"; if ($start_min == "" || preg_replace("/[^0-9]/", "", $start) < preg_replace("/[^0-9]/", "", $start_min)) { $start_min = $start; } if ($end_max == "" || preg_replace("/[^0-9]/", "", $end) > preg_replace("/[^0-9]/", "", $start_min)) { $end_max = $end; } } } } } if ($start_min != "") { if ($allday && mb_strlen($end_max) == 12) { $x = explode("-", str_replace("'", "", $end_max)); $time = mktime(0, 0, 0, IntVal($x[1]), IntVal($x[2]), IntVal($x[0])); $end_max = date("'Y-m-d H:i:s'", $time - 1); } q("INSERT INTO %s%sjqcalendar (`uid`, `namespace`, `namespace_id`, `ical_uri`, `Subject`, `Location`, `Description`, `StartTime`, `EndTime`, `IsAllDayEvent`, `RecurringRule`, `Color`)\n\t\t\tVALUES (%d, %d, %d, '%s', '%s', '%s', '%s', %s, %s, %d, '%s', '%s')", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($calendar->uid), IntVal($calendarobject->namespace), IntVal($calendarobject->namespace_id), dbesc($calendarobject->uri), dbesc($summary), dbesc($location), dbesc(str_replace("\\n", "\n", $description)), $start_min, $end_max, IntVal($allday), dbesc($rrule), dbesc($color)); foreach ($vevent->components as $comp) { /** @var $comp calendarComponent */ $trigger = $comp->getProperty("TRIGGER"); $sql_field = $trigger["relatedStart"] ? $start : $end; $sql_op = $trigger["before"] ? "DATE_SUB" : "DATE_ADD"; $num = ""; $rel_type = ""; $rel_value = 0; if (isset($trigger["second"])) { $num = IntVal($trigger["second"]) . " SECOND"; $rel_type = "second"; $rel_value = IntVal($trigger["second"]); } if (isset($trigger["minute"])) { $num = IntVal($trigger["minute"]) . " MINUTE"; $rel_type = "minute"; $rel_value = IntVal($trigger["minute"]); } if (isset($trigger["hour"])) { $num = IntVal($trigger["hour"]) . " HOUR"; $rel_type = "hour"; $rel_value = IntVal($trigger["hour"]); } if (isset($trigger["day"])) { $num = IntVal($trigger["day"]) . " DAY"; $rel_type = "day"; $rel_value = IntVal($trigger["day"]); } if (isset($trigger["week"])) { $num = IntVal($trigger["week"]) . " WEEK"; $rel_type = "week"; $rel_value = IntVal($trigger["week"]); } if (isset($trigger["month"])) { $num = IntVal($trigger["month"]) . " MONTH"; $rel_type = "month"; $rel_value = IntVal($trigger["month"]); } if (isset($trigger["year"])) { $num = IntVal($trigger["year"]) . " YEAR"; $rel_type = "year"; $rel_value = IntVal($trigger["year"]); } if ($trigger["before"]) { $rel_value *= -1; } if ($rel_type != "") { $not_date = "{$sql_op}({$sql_field}, INTERVAL {$num})"; q("INSERT INTO %s%snotifications (`uid`, `ical_uri`, `rel_type`, `rel_value`, `alert_date`, `notified`) VALUES ('%s', '%s', '%s', '%s', %s, IF(%s < NOW(), 1, 0))", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($calendar->uid), dbesc($calendarobject->uri), dbesc($rel_type), IntVal($rel_value), $not_date, $not_date); } } } }
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>jhgjghjg</title> <meta name="generator" content="TextMate http://macromates.com/"> <meta name="author" content="John Lunn"> <!-- Date: 2010-05-08 --> </head> <body> <?php ini_set('display_errors', 1); require_once 'iCalcreator.class.php'; $v = new vcalendar(); /* start parse of local file */ $v->setConfig('directory', 'uploads'); // set directory $v->setConfig('filename', 'basic.ics'); // set file name $v->parse(); foreach ($v->components as $component => $info) { # get first vevent $comp = $v->getComponent("VEVENT"); //print_r($comp); $summary_array = $comp->getProperty("summary", 1, TRUE); //$summary_array = $vevent->getProperty("summary", 1, TRUE); echo "Event: ", $summary_array["value"], "\n"; $dtstart_array = $comp->getProperty("dtstart", 1, TRUE); //$dtstart_array = $vevent->getProperty("dtstart", 1, TRUE); $dtstart = $dtstart_array["value"]; $startDate = "{$dtstart["year"]}-{$dtstart["month"]}-{$dtstart["day"]}";
<?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();
/** * 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(); }
function _get_events_url(&$events, $url, $date) { $v = new vcalendar(); $v->setConfig('unique_id', 'barchat'); $v->setProperty('method', 'PUBLISH'); $v->setProperty("x-wr-calname", "Calendar Sample"); $v->setProperty("X-WR-CALDESC", "Calendar Description"); $v->setProperty("X-WR-TIMEZONE", "America/New_York"); $v->setConfig('url', $url); try { $v->parse(); } catch (exception $e) { } $v->sort(); $m = $date->format('n'); $d = $date->format('j'); $y = $date->format('Y'); $eventArray = $v->selectComponents($y, $m, 1, $y, $m, 31); foreach ((array) $eventArray as $yearkey => $yeararray) { foreach ((array) $yeararray as $monthkey => $montharray) { foreach ((array) $montharray as $daykey => $dayarray) { foreach ((array) $dayarray as $eventnumber => $event) { //echo "{$y}-{$m}-{$daykey} [{$eventnumber}]: "; $time = $event->dtstart['value']; $tz = $event->dtstart['params']['TZID'] == '' ? 'America/New_York' : $event->dtstart['params']['TZID']; if ($time['tz'] == 'Z') { $tz = 'GMT'; } if (isset($event->dtstart['params']['VALUE']) && $event->dtstart['params']['VALUE'] == 'DATE') { $allday = new DateTime("{$time['year']}-{$time['month']}-{$time['day']}", new DateTimeZone($tz)); $allday->setTimezone(new DateTimeZone('America/New_York')); $d = sprintf('%04d-%02d-%02d', $y, $m, $daykey); if (!is_array($events[$d])) { $events[$d] = array(); } $alldayint = intval($allday->format('U')); while (isset($events[$d][$alldayint])) { $alldayint++; } $events[$d][$alldayint] = '<span class="calendartime">All Day</span> ' . trim($event->summary['value']); //var_dump(date('r', $allday) . ' = ' . $allday); //var_dump($event->summary['value']); } else { if (isset($event->xprop['X-CURRENT-DTSTART'])) { $dt = new DateTime($event->xprop['X-CURRENT-DTSTART']['value'], new DateTimeZone($tz)); } else { $dt = new DateTime("{$time['year']}-{$time['month']}-{$time['day']} {$time['hour']}:{$time['min']}:{$time['sec']}", new DateTimeZone($tz)); } $dt->setTimezone(new DateTimeZone('America/New_York')); if (isset($event->xprop['X-CURRENT-DTEND'])) { $dte = new DateTime($event->xprop['X-CURRENT-DTEND']['value'], new DateTimeZone($tz)); } else { $timee = $event->dtstart['value']; $dte = new DateTime("{$timee['year']}-{$timee['month']}-{$timee['day']} {$timee['hour']}:{$timee['min']}:{$timee['sec']}", new DateTimeZone($tz)); } $dte->setTimezone(new DateTimeZone('America/New_York')); if (!is_array($events[$d])) { $events[$d] = array(); } $d = sprintf('%04d-%02d-%02d', $y, $m, $daykey); $daytime = $dt->format('U'); while (isset($events[$d][$daytime])) { $daytime++; } if ($dt->format('g:ia') != $dte->format('g:ia')) { $events[$d][$daytime] = '<span class="calendartime">' . $dt->format('g:ia') . ' - ' . $dte->format('g:ia') . '</span> ' . trim($event->summary['value']); } else { $events[$d][$daytime] = '<span class="calendartime">' . $dt->format('g:ia') . '</span> ' . trim($event->summary['value']); } //var_dump($event->dtstart); //var_dump($event->summary['value']); //var_dump($dt->format('r')); //var_dump($event); } } } } } }
/** * 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(); }
$myOut = registry::register('file_handler')->FileLink('rss/' . $data['url'], 'eqdkp', 'relative'); } } break; // generate an ical feed // generate an ical feed case 'icalfeed': // the permissions for the single modules $permissions = array('calendar' => 'po_calendarevent'); $modulename = registry::register('input')->get('module', ''); // check for permission $userid = registry::fetch('user')->getUserIDfromExchangeKey(registry::register('input')->get('key', '')); if (isset($permissions[$modulename]) && registry::fetch('user')->check_auth($permissions[$modulename], false, $userid)) { require $eqdkp_root_path . 'libraries/icalcreator/iCalcreator.class.php'; $v = new vcalendar(); $v->setConfig('unique_id', registry::register('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)); switch ($modulename) { case 'calendar': $eventtypes = registry::register('input')->get('type', 'raids'); switch ($eventtypes) { case 'raids': $eventsfilter = true; break; case 'all': $eventsfilter = false;
// describe the event $e->setProperty('location', 'Home'); // 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; echo "<br />\n\n"; /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ $v = new vcalendar(); // initiate new CALENDAR $v->setConfig('unique_id', 'testdomain.com'); // config with site domain $v->setProperty('X-WR-CALNAME', 'Sample calendar'); // set some X-properties, name, content.. . $v->setProperty('X-WR-CALDESC', 'Description of the calendar'); $v->setProperty('X-WR-TIMEZONE', 'Europe/Stockholm'); $e = new vevent(); // initiate EVENT $e->setProperty('categories', 'FAMILY'); // catagorize $e->setProperty('dtstart', 2007, 12, 24, 19, 30, 00); // 24 dec 2007 19.30 $e->setProperty('duration', 0, 0, 3); // 3 hours $e->setProperty('description', 'x-mas evening - diner'); // describe the event
//$c->setProperty( 'X-WR-CALDESC', 'Description of the calendar' ); //echo "<br />"; $vivek = new task(); //echo $_SESSION['do_User']->iduser."<br /><br />"; //$users=$vivek->getAllTaskuser(); //print_r($users); //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();
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, see <http://www.gnu.org/licenses/>. */ require_once 'lastRSS.php'; require_once 'iCalcreator.class.php'; $lr = new lastRSS(); $data = $lr->Get("http://feeds.feedburner.com/danaevents"); /*print_r($data); exit;*/ $v = new vcalendar(); // 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
/** * 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()); }
//license as circulated by CEA, CNRS and INRIA at the following URL //"http://www.cecill.info". // //The fact that you are presently reading this means that you have had //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;
/** * 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(); }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, see <http://www.gnu.org/licenses/>. */ error_reporting(E_ERROR); require_once( 'iCalcreator.class.php' ); require_once( 'tz.php' ); $out = new vcalendar(); $v = new vcalendar(); // create a new calendar instance $out->setXprop("X-WR-CALNAME","Facebook events"); $out->setConfig( 'unique_id', 'tevp.net-projects-calendars-fbevents' ); // set Your unique id, required if property UID is missing $out->setProperty( 'method', 'PUBLISH' ); // required of some calendar software $uid = $_GET["uid"]; $key = $_GET["key"]; $timezone = $_GET["timezone"]; $fb_url = $_GET["fb_url"]; if (!isset($timezone)) $timezone = "Europe/London"; if (isset($action) && $action == "generate") { preg_match("/fbcalendar.com\/cal\/(\d+)\/([\da-z]+)-\d+\/events\/ics/", $fb_url, $matches); if (count($matches) == 3) {
/** * function iCal2xls * * Convert iCal file to xls format and send file to browser (default) or save xls file to disk * Definition iCal : rcf2445, http://kigkonsult.se/downloads/index.php#rfc * Using iCalcreator: http://kigkonsult.se/downloads/index.php#iCalcreator * Based on PEAR Spreadsheet_Excel_Writer-0.9.1 (and OLE-1.0.0RC1) * to be installed as * pear install channel://pear.php.net/OLE-1.0.0RC1 * pear install channel://pear.php.net/Spreadsheet_Excel_Writer-0.9.1 * * @author Kjell-Inge Gustafsson <*****@*****.**> * @since 3.0 - 2011-12-21 * @param object $calendar opt. iCalcreator calendar instance * @return bool returns FALSE when error */ public function iCal2xls($calendar = FALSE) { $timeexec = array('start' => microtime(TRUE)); if ($this->log) { $this->log->log(' ********** START **********', PEAR_LOG_NOTICE); } /** check input/output directory and filename */ $inputdirFile = $outputdirFile = ''; $inputFileParts = $outputFileParts = array(); $remoteInput = $remoteOutput = FALSE; if ($calendar) { $inputdirFile = $calendar->getConfig('DIRFILE'); $inputFileParts = pathinfo($inputdirFile); $inputFileParts['dirname'] = realpath($inputFileParts['dirname']); if ($this->log) { $this->log->log('fileParts:' . var_export($inputFileParts, TRUE), PEAR_LOG_DEBUG); } } elseif (FALSE === $this->_fixIO('input', 'ics', $inputdirFile, $inputFileParts, $remoteInput)) { if ($this->log) { $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_ERR); $this->log->log("ERROR 2, invalid input ({$inputdirFile})", PEAR_LOG_ERR); $this->log->flush(); } return FALSE; } if (FALSE === $this->_fixIO('output', FALSE, $outputdirFile, $outputFileParts, $remoteOutput)) { if (FALSE === $this->setConfig('outputfilename', $inputFileParts['filename'] . '.xls')) { if ($this->log) { $this->log->log(number_format(microtime(TRUE) - $timeexec['start'], 5) . ' sec', PEAR_LOG_ERR); $this->log->log('ERROR 3, invalid output (' . $inputFileParts['filename'] . '.csv)', PEAR_LOG_ERR); $this->log->flush(); } return FALSE; } $outputdirFile = $this->getConfig('outputdirectory') . DIRECTORY_SEPARATOR . $inputFileParts['filename'] . '.xls'; $outputFileParts = pathinfo($outputdirFile); if ($this->log) { $this->log->log("output set to '{$outputdirFile}'", PEAR_LOG_INFO); } } if ($this->log) { $this->log->log("INPUT..FILE:{$inputdirFile}", PEAR_LOG_NOTICE); $this->log->log("OUTPUT.FILE:{$outputdirFile}", PEAR_LOG_NOTICE); } $save = $this->getConfig('save'); if ($calendar) { $calnl = $calendar->getConfig('nl'); } else { /** iCalcreator set config, read and parse input iCal file */ $calendar = new vcalendar(); if (FALSE !== ($unique_id = $this->getConfig('unique_id'))) { $calendar->setConfig('unique_id', $unique_id); } $calnl = $calendar->getConfig('nl'); if ($remoteInput) { if (FALSE === $calendar->setConfig('url', $inputdirFile)) { if ($this->log) { $this->log->log("ERROR 3 INPUT FILE:'{$inputdirFile}' iCalcreator: invalid url", 3); } return FALSE; } } else { if (FALSE === $calendar->setConfig('directory', $inputFileParts['dirname'])) { if ($this->log) { $this->log->log("ERROR 4 INPUT FILE:'{$inputdirFile}' iCalcreator: invalid directory: '" . $inputFileParts['dirname'] . "'", 3); $this->log->flush(); } return FALSE; } if (FALSE === $calendar->setConfig('filename', $inputFileParts['basename'])) { if ($this->log) { $this->log->log("ERROR 5 INPUT FILE:'{$inputdirFile}' iCalcreator: invalid filename: '" . $inputFileParts['basename'] . "'", 3); $this->log->flush(); } return FALSE; } } if (FALSE === $calendar->parse()) { if ($this->log) { $this->log->log("ERROR 6 INPUT FILE:'{$inputdirFile}' iCalcreator parse error", 3); $this->log->flush(); } return FALSE; } } // end if( !$calendar ) $timeexec['fileOk'] = microtime(TRUE); if (!function_exists('iCaldate2timestamp')) { function iCaldate2timestamp($d) { if (6 > count($d)) { return mktime(0, 0, 0, $d['month'], $d['day'], $d['year']); } else { return mktime($d['hour'], $d['min'], $d['sec'], $d['month'], $d['day'], $d['year']); } } } if (!function_exists('fixiCalString')) { function fixiCalString($s) { global $calnl; $s = str_replace('\\,', ',', $s); $s = str_replace('\\;', ';', $s); $s = str_replace('\\n ', chr(10), $s); $s = str_replace('\\\\', '\\', $s); $s = str_replace("{$calnl}", chr(10), $s); return utf8_decode($s); } } /** Creating a workbook */ require_once 'Spreadsheet/Excel/Writer.php'; if ($save) { $workbook = new Spreadsheet_Excel_Writer($outputdirFile); } else { $workbook = new Spreadsheet_Excel_Writer(); } $workbook->setVersion(8); // Use Excel97/2000 Format /** opt. sending HTTP headers */ if (!$save) { $workbook->send($outputFileParts['basename']); } /** Creating a worksheet */ $worksheet =& $workbook->addWorksheet($inputFileParts['filename']); /** fix formats */ $format_bold =& $workbook->addFormat(); $format_bold->setBold(); $timeexec['wrkbkOk'] = microtime(TRUE); /** info rows */ $row = -1; $worksheet->writeString(++$row, 0, 'kigkonsult.se', $format_bold); $worksheet->writeString($row, 1, ICALCREATOR_VERSION, $format_bold); $worksheet->writeString($row, 2, ICALCNVVERSION . ' iCal2xls', $format_bold); $worksheet->writeString($row, 3, date('Y-m-d H:i:s')); $filename = $remoteInput ? $inputdirFile : $inputFileParts['basename']; $worksheet->writeString(++$row, 0, 'iCal input', $format_bold); $worksheet->writeString($row, 1, $filename); $worksheet->writeString($row, 2, 'xls output', $format_bold); $worksheet->writeString($row, 3, $outputFileParts['basename']); if (FALSE !== ($prop = $calendar->getProperty('CALSCALE'))) { $worksheet->writeString(++$row, 0, 'CALSCALE', $format_bold); $worksheet->writeString($row, 1, $prop); } if (FALSE !== ($prop = $calendar->getProperty('METHOD'))) { $worksheet->writeString(++$row, 0, 'METHOD', $format_bold); $worksheet->writeString($row, 1, $prop); } while (FALSE !== ($xprop = $calendar->getProperty())) { $worksheet->writeString(++$row, 0, $xprop[0], $format_bold); $worksheet->writeString($row, 1, $xprop[1]); } $timeexec['infoOk'] = microtime(TRUE); if (FALSE === ($propsToSkip = $this->getConfig('skip'))) { $propsToSkip = array(); } /** fix property order list */ $proporderOrg = array(); for ($key = 2; $key < 99; $key++) { if (FALSE !== ($value = $this->getConfig($key))) { $proporderOrg[$value] = $key; if ($this->log) { $this->log->log("{$value} in column {$key}", 7); } } } /** fix vtimezone property order list */ $proporder = $proporderOrg; $proporder['TYPE'] = 0; $proporder['ORDER'] = 1; $props = array('TZID', 'LAST-MODIFIED', 'TZURL', 'DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM', 'COMMENT', 'RRULE', 'RDATE', 'TZNAME'); $pix = 2; foreach ($props as $prop) { if (isset($proporder[$prop])) { continue; } if (in_array($prop, $propsToSkip)) { if ($this->log) { $this->log->log("'{$prop}' removed from output", 7); } continue; } while (in_array($pix, $proporder)) { $pix++; } $proporder[$prop] = $pix++; } /** remove unused properties from and add x-props to property order list */ $maxpropix = 11; if ($maxpropix != count($proporder) - 1) { $maxpropix = count($proporder) - 1; } $compsinfo = $calendar->getConfig('compsinfo'); $potmp = array(); $potmp[0] = 'TYPE'; $potmp[1] = 'ORDER'; foreach ($compsinfo as $cix => $compinfo) { if ('vtimezone' != $compinfo['type']) { continue; } $comp = $calendar->getComponent($compinfo['ordno']); foreach ($compinfo['props'] as $propName => $propcnt) { if (!in_array($propName, $potmp) && isset($proporder[$propName])) { $potmp[$proporder[$propName]] = $propName; } elseif ('X-PROP' == $propName) { while ($xprop = $comp->getProperty()) { if (!in_array($xprop[0], $potmp)) { $maxpropix += 1; $potmp[$maxpropix] = $xprop[0]; } // end if } // end while xprop } // end X-PROP } // end $compinfo['props'] if (isset($compinfo['sub'])) { foreach ($compinfo['sub'] as $compinfo2) { foreach ($compinfo2['props'] as $propName => $propcnt) { if (!in_array($propName, $potmp) && isset($proporder[$propName])) { $potmp[$proporder[$propName]] = $propName; } elseif ('X-PROP' == $propName) { $scomp = $comp->getComponent($compinfo2['ordno']); while ($xprop = $scomp->getProperty()) { if (!in_array($xprop[0], $potmp)) { $maxpropix += 1; $potmp[$maxpropix] = $xprop[0]; } // end if } // end while xprop } // end X-PROP } // end $compinfo['sub']['props'] } // end foreach( $compinfo['sub'] } // end if( isset( $compinfo['sub'] } // end foreach compinfo - vtimezone ksort($potmp, SORT_NUMERIC); $proporder = array_flip(array_values($potmp)); if ($this->log) { $this->log->log("timezone proporder=" . implode(',', array_flip($proporder)), 7); } /** create vtimezone info */ if (2 < count($proporder)) { $row += 1; /** create vtimezone header row */ foreach ($proporder as $propName => $col) { if (isset($this->config[$propName])) { $worksheet->writeString($row, $col, $this->config[$propName], $format_bold); // check map of userfriendly name to iCal property name if ($this->log) { $this->log->log("header row, col={$col}: {$propName}, replaced by " . $this->config[$propName], 7); } } else { $worksheet->writeString($row, $col, $propName, $format_bold); } } $allowedProps = array('VTIMEZONE' => array('TZID', 'LAST-MODIFIED', 'TZURL'), 'STANDARD' => array('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM', 'COMMENT', 'RDATE', 'RRULE', 'TZNAME'), 'DAYLIGHT' => array('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM', 'COMMENT', 'RDATE', 'RRULE', 'TZNAME')); /** create vtimezone data rows */ foreach ($compsinfo as $cix => $compinfo) { if ('vtimezone' != $compinfo['type']) { continue; } $row += 1; $worksheet->writeString($row, $proporder['TYPE'], $compinfo['type']); $worksheet->writeString($row, $proporder['ORDER'], $compinfo['ordno']); $comp = $calendar->getComponent($compinfo['ordno']); foreach ($proporder as $propName => $col) { if ('TYPE' == $propName || 'ORDER' == $propName) { continue; } if ('X-' == substr($propName, 0, 2)) { continue; } if (!in_array($propName, $allowedProps['VTIMEZONE'])) { // check if component allows property if ($this->log) { $this->log->log("ERROR 7, INPUT FILE:'{$inputdirFile}' iCalcreator: unvalid property for component '" . $compinfo['type'] . "': '{$propName}'", PEAR_LOG_INFO); } continue; } if (isset($compinfo['props'][$propName])) { if ('LAST-MODIFIED' == $propName) { $fcn = 'createLastModified'; } else { $fcn = 'create' . strtoupper(substr($propName, 0, 1)) . strtolower(substr($propName, 1)); } if (!method_exists($comp, $fcn)) { if ($this->log) { $this->log->log('ERROR 8 INPUT FILE:"' . $filename . '" iCalcreator: unknown property: "' . $propName . '" (' . $fcn . ')', PEAR_LOG_INFO); } continue; } $output = str_replace("{$calnl} ", '', rtrim($comp->{$fcn}())); $output = str_replace($propName . ';', '', $output); $output = str_replace($propName . ':', '', $output); $worksheet->writeString($row, $proporder[$propName], fixiCalString($output)); } } // end foreach( $proporder if (isset($compinfo['props']['X-PROP'])) { while ($xprop = $comp->getProperty()) { $output = str_replace("{$calnl} ", '', rtrim($xprop[1])); $worksheet->writeString($row, $proporder[$xprop[0]], fixiCalString($output)); } } if (isset($compinfo['sub'])) { foreach ($compinfo['sub'] as $compinfo2) { $row += 1; $worksheet->writeString($row, $proporder['TYPE'], $compinfo2['type']); $worksheet->writeString($row, $proporder['ORDER'], $compinfo['ordno'] . ':' . $compinfo2['ordno']); $scomp = $comp->getComponent($compinfo2['ordno']); foreach ($proporder as $propName => $col) { if ('TYPE' == $propName || 'ORDER' == $propName) { continue; } if ('X-' == substr($propName, 0, 2)) { continue; } if (!in_array($propName, $allowedProps[strtoupper($compinfo2['type'])])) { // check if component allows property if ($this->log) { $this->log->log("ERROR 9, INPUT FILE:'{$inputdirFile}' iCalcreator: unvalid property for component '" . $compinfo2['type'] . "': '{$propName}'", PEAR_LOG_INFO); } continue; } if (isset($compinfo2['props'][$propName])) { $fcn = 'create' . strtoupper(substr($propName, 0, 1)) . strtolower(substr($propName, 1)); if (!method_exists($scomp, $fcn)) { if ($this->log) { $this->log->log('ERROR 10 INPUT FILE:"' . $filename . '" iCalcreator: unknown property: "' . $propName . '" (' . $fcn . ')', PEAR_LOG_INFO); } continue; } $output = str_replace("{$calnl} ", '', rtrim($scomp->{$fcn}())); $output = str_replace($propName . ';', '', $output); $output = str_replace($propName . ':', '', $output); $worksheet->writeString($row, $proporder[$propName], fixiCalString($output)); } } // end foreach( $proporder if (isset($compinfo2['props']['X-PROP'])) { while ($xprop = $scomp->getProperty()) { $output = str_replace("{$calnl} ", '', rtrim($xprop[1])); $worksheet->writeString($row, $proporder[$xprop[0]], fixiCalString($output)); } } } // end foreach( $compinfo['sub'] } // end if( isset( $compinfo['sub']['props'] )) } // end foreach } // end vtimezone $timeexec['zoneOk'] = microtime(TRUE); $maxColCount = count($proporder); /** fix property order list */ $proporder = $proporderOrg; $proporder['TYPE'] = 0; $proporder['ORDER'] = 1; $props = array('UID', 'DTSTAMP', 'SUMMARY', 'DTSTART', 'DURATION', 'DTEND', 'DUE', 'RRULE', 'RDATE', 'EXRULE', 'EXDATE', 'DESCRIPTION', 'CATEGORIES', 'ORGANIZER', 'LOCATION', 'RESOURCES', 'CONTACT', 'URL', 'COMMENT', 'PRIORITY', 'ATTENDEE', 'CLASS', 'TRANSP', 'SEQUENCE', 'STATUS', 'COMPLETED', 'CREATED', 'LAST-MODIFIED', 'ACTION', 'TRIGGER', 'REPEAT', 'ATTACH', 'FREEBUSY', 'RELATED-TO', 'REQUEST-STATUS', 'GEO', 'PERCENT-COMPLETE', 'RECURRENCE-ID'); $pix = 2; foreach ($props as $prop) { if (isset($proporder[$prop])) { continue; } if (in_array($prop, $propsToSkip)) { if ($this->log) { $this->log->log("'{$prop}' removed from output", 7); } continue; } while (in_array($pix, $proporder)) { $pix++; } $proporder[$prop] = $pix++; } /** remove unused properties from and add x-props to property order list */ if ($maxpropix < count($proporder) - 1) { $maxpropix = count($proporder) - 1; } $potmp = array(); $potmp[0] = 'TYPE'; $potmp[1] = 'ORDER'; // $potmp[2] = 'UID'; foreach ($compsinfo as $cix => $compinfo) { if ('vtimezone' == $compinfo['type']) { continue; } foreach ($compinfo['props'] as $propName => $propcnt) { if (!in_array($propName, $potmp) && isset($proporder[$propName])) { $potmp[$proporder[$propName]] = $propName; } elseif ('X-PROP' == $propName) { $comp = $calendar->getComponent($compinfo['ordno']); while ($xprop = $comp->getProperty()) { if (!in_array($xprop[0], $potmp)) { $maxpropix += 1; $potmp[$maxpropix] = $xprop[0]; } // end if } // while( $xprop } // end elseif( 'X-PROP' } // end foreach( $compinfo['props'] if (isset($compinfo['sub'])) { foreach ($compinfo['sub'] as $compinfo2) { foreach ($compinfo2['props'] as $propName => $propcnt) { if (!in_array($propName, $potmp) && isset($proporder[$propName])) { $potmp[$proporder[$propName]] = $propName; } elseif ('X-PROP' == $propName) { $scomp = $comp->getComponent($compinfo2['ordno']); while ($xprop = $scomp->getProperty()) { if (!in_array($xprop[0], $potmp)) { $maxpropix += 1; $potmp[$maxpropix] = $xprop[0]; } // end if } // end while xprop } // end X-PROP } // end $compinfo['sub']['props'] } // end foreach( $compinfo['sub'] } // end if( isset( $compinfo['sub'] } ksort($potmp, SORT_NUMERIC); $proporder = array_flip(array_values($potmp)); if ($this->log) { $this->log->log("comp proporder=" . implode(',', array_flip($proporder)), 7); } if ($maxColCount < count($proporder)) { $maxColCount = count($proporder); } /** create header row */ $row += 1; foreach ($proporder as $propName => $col) { if (isset($this->config[$propName])) { $worksheet->writeString($row, $col, $this->config[$propName], $format_bold); // check map of userfriendly name to iCal property name if ($this->log) { $this->log->log("header row, col={$col}: {$propName}, replaced by " . $this->config[$propName], 7); } } else { $worksheet->writeString($row, $col, $propName, $format_bold); } } $allowedProps = array('VEVENT' => array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'CLASS', 'COMMENT', 'CONTACT', 'CREATED', 'DESCRIPTION', 'DTEND', 'DTSTAMP', 'DTSTART', 'DURATION', 'EXDATE', 'RXRULE', 'GEO', 'LAST-MODIFIED', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'RDATE', 'RECURRENCE-ID', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'SEQUENCE', 'STATUS', 'SUMMARY', 'TRANSP', 'UID', 'URL'), 'VTODO' => array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'CLASS', 'COMMENT', 'COMPLETED', 'CONTACT', 'CREATED', 'DESCRIPTION', 'DTSTAMP', 'DTSTART', 'DUE', 'DURATION', 'EXDATE', 'EXRULE', 'GEO', 'LAST-MODIFIED', 'LOCATION', 'ORGANIZER', 'PERCENT', 'PRIORITY', 'RDATE', 'RECURRENCE-ID', 'RELATED-TO', 'RESOURCES', 'RRULE', 'REQUEST-STATUS', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL'), 'VJOURNAL' => array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'CLASS', 'COMMENT', 'CONTACT', 'CREATED', 'DESCRIPTION', 'DTSTAMP', 'DTSTART', 'EXDATE', 'EXRULE', 'LAST-MODIFIED', 'ORGANIZER', 'RDATE', 'RECURRENCE-ID', 'RELATED-TO', 'RRULE', 'REQUEST-STATUS', 'SEQUENCE', 'STATUS', 'SUMMARY', 'UID', 'URL'), 'VFREEBUSY' => array('ATTENDEE', 'COMMENT', 'CONTACT', 'DTEND', 'DTSTAMP', 'DTSTART', 'DURATION', 'FREEBUSY', 'ORGANIZER', 'UID', 'URL'), 'VALARM' => array('ACTION', 'ATTACH', 'ATTENDEE', 'DESCRIPTION', 'DURATION', 'REPEAT', 'SUMMARY', 'TRIGGER')); /** create data rows */ foreach ($compsinfo as $cix => $compinfo) { if ('vtimezone' == $compinfo['type']) { continue; } $row += 1; $worksheet->writeString($row, $proporder['TYPE'], $compinfo['type']); $worksheet->writeString($row, $proporder['ORDER'], $compinfo['ordno']); // $worksheet->write( $row, $proporder['UID'], $compinfo['uid'] ); $comp = $calendar->getComponent($compinfo['ordno']); foreach ($proporder as $propName => $col) { if ('TYPE' == $propName || 'ORDER' == $propName) { continue; } if ('X-' == substr($propName, 0, 2)) { continue; } if (!in_array($propName, $allowedProps[strtoupper($compinfo['type'])])) { // check if component allows property if ($this->log) { $this->log->log("ERROR 11, INPUT FILE:'{$inputdirFile}' iCalcreator: unvalid property for component '" . $compinfo['type'] . "': '{$propName}'", PEAR_LOG_INFO); } continue; } if (isset($compinfo['props'][$propName])) { switch ($propName) { case 'LAST-MODIFIED': $fcn = 'createLastModified'; break; case 'RECURRENCE-ID': $fcn = 'createRecurrenceid'; break; case 'RELATED-TO': $fcn = 'createRelatedTo'; break; case 'REQUEST-STATUS': $fcn = 'createRequestStatus'; break; case 'PERCENT-COMPLETE': $fcn = 'createPercentComplete'; break; default: $fcn = 'create' . strtoupper(substr($propName, 0, 1)) . strtolower(substr($propName, 1)); } if (!method_exists($comp, $fcn)) { if ($this->log) { $this->log->log("ERROR 12 INPUT FILE:'{$filename}' iCalcreator: unknown property: '{$propName}' ({$fcn})", PEAR_LOG_INFO); } continue; } $output = str_replace("{$calnl} ", '', rtrim($comp->{$fcn}())); $output = str_replace($propName . ';', '', $output); $output = str_replace($propName . ':', '', $output); $worksheet->writeString($row, $proporder[$propName], fixiCalString($output)); } } // end foreach( $proporder if (isset($compinfo['props']['X-PROP'])) { while ($xprop = $comp->getProperty()) { $output = str_replace("{$calnl} ", '', rtrim($xprop[1])); $worksheet->writeString($row, $proporder[$xprop[0]], fixiCalString($output)); } } if (isset($compinfo['sub'])) { foreach ($compinfo['sub'] as $compinfo2) { $row += 1; $worksheet->writeString($row, $proporder['TYPE'], $compinfo2['type']); $worksheet->writeString($row, $proporder['ORDER'], $compinfo['ordno'] . ':' . $compinfo2['ordno']); $scomp = $comp->getComponent($compinfo2['ordno']); foreach ($proporder as $propName => $col) { if ('TYPE' == $propName || 'ORDER' == $propName) { continue; } if ('X-' == substr($propName, 0, 2)) { continue; } if (!in_array($propName, $allowedProps[strtoupper($compinfo2['type'])])) { // check if component allows property if ($this->log) { $this->log->log("ERROR 13, INPUT FILE:'{$inputdirFile}' iCalcreator: unvalid property for component '" . $compinfo2['type'] . "': '{$propName}'", PEAR_LOG_INFO); } continue; } if (isset($compinfo2['props'][$propName])) { $fcn = 'create' . strtoupper(substr($propName, 0, 1)) . strtolower(substr($propName, 1)); if (!method_exists($scomp, $fcn)) { if ($this->log) { $this->log->log("ERROR 14 INPUT FILE:'{$filename}' iCalcreator: unknown property: '{$propName}' ({$fcn})", PEAR_LOG_INFO); } continue; } $output = str_replace("{$calnl} ", '', rtrim($scomp->{$fcn}())); $output = str_replace($propName . ';', '', $output); $output = str_replace($propName . ':', '', $output); $worksheet->writeString($row, $proporder[$propName], fixiCalString($output)); } // end if( isset( $compinfo2['props'][$propName] } // end foreach( $proporder if (isset($compinfo2['props']['X-PROP'])) { while ($xprop = $scomp->getProperty()) { $output = str_replace("{$calnl} ", '', rtrim($xprop[1])); $output = str_replace('\\n ', chr(10), $output); $worksheet->writeString($row, $proporder[$xprop[0]], fixiCalString($output)); } } // end if( isset( $compinfo2['props']['X-PROP'] } // end foreach( $compinfo['sub'] } // end if( isset( $compinfo['sub'] } // foreach( $compsinfo as if ($this->log) { $timeexec['exit'] = microtime(TRUE); $msg = "'{$filename}'"; $msg .= ' fileOk:' . number_format($timeexec['fileOk'] - $timeexec['start'], 5); $msg .= ' wrkbkOk:' . number_format($timeexec['wrkbkOk'] - $timeexec['fileOk'], 5); $msg .= ' infoOk:' . number_format($timeexec['infoOk'] - $timeexec['wrkbkOk'], 5); $msg .= ' zoneOk:' . number_format($timeexec['zoneOk'] - $timeexec['infoOk'], 5); $msg .= ' compOk:' . number_format($timeexec['exit'] - $timeexec['zoneOk'], 5); $msg .= ' total:' . number_format($timeexec['exit'] - $timeexec['start'], 5) . 'sec'; $msg .= ', ' . ($row + 1) . " rows, {$maxColCount} cols"; $this->log->log($msg, PEAR_LOG_DEBUG); $msg = "'{$filename}' (" . count($compsinfo) . ' components) start:' . date('H:i:s', $timeexec['start']); $msg .= ' total:' . number_format($timeexec['exit'] - $timeexec['start'], 5) . 'sec'; if ($save) { $msg .= " saved as '{$outputdirFile}'"; } else { $msg .= " redirected as '" . $outputFileParts['basename'] . "'"; } $this->log->log($msg, PEAR_LOG_NOTICE); } /** Close and, opt., send the file */ if ($this->log) { $this->log->flush(); } $workbook->close(); return TRUE; }
/** * return initialized calendar tool class for ics export * * @return object */ function getCalendarTool() { require_once JPATH_SITE . DS . 'components' . DS . 'com_redevent' . DS . 'classes' . DS . 'iCalcreator.class.php'; $mainframe =& JFactory::getApplication(); $offset = (double) $mainframe->getCfg('offset'); $timezone_name = self::getTimeZone($offset); $vcal = new vcalendar(); // initiate new CALENDAR if (!file_exists(JPATH_SITE . DS . 'cache' . DS . 'com_redevent')) { jimport('joomla.filesystem.folder'); JFolder::create(JPATH_SITE . DS . 'cache' . DS . 'com_redevent'); } $vcal->setConfig('directory', JPATH_SITE . DS . 'cache' . DS . 'com_redevent'); $vcal->setProperty('unique_id', 'events@' . $mainframe->getCfg('sitename')); $vcal->setProperty("calscale", "GREGORIAN"); $vcal->setProperty('method', 'PUBLISH'); if ($timezone_name) { $vcal->setProperty("X-WR-TIMEZONE", $timezone_name); } return $vcal; }
$type = $id[0]; $id = $id[1]; $agenda = new Agenda(); $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');
/** * 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; }
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; } }
// 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 /* alt. dev. and test */ /*$str = $v->createCalendar(); // generate and get output in string, for testing? echo $str; echo "<br />\n\n";*/ $v->setConfig('directory', ''); $v->setConfig('filename', 'calendar.ics'); $v->saveCalendar(); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ /*$v = new vcalendar(); // initiate new CALENDAR $v->setConfig( 'unique_id' , 'testdomain.com' ); // config with site domain $v->setProperty( 'X-WR-CALNAME' , 'Sample calendar' ); // set some X-properties, name, content.. . $v->setProperty( 'X-WR-CALDESC' , 'Description of the calendar' ); $v->setProperty( 'X-WR-TIMEZONE' , 'Europe/Stockholm' ); $e = new vevent(); // initiate EVENT $e->setProperty( 'categories'
/** * 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; }
/** * @param array $start * @param array $end * @param string $subject * @param bool $allday * @param string $description * @param string $location * @param null $color * @param string $timezone * @param bool $notification * @param null $notification_type * @param null $notification_value * @return array|string */ public function addItem($start, $end, $subject, $allday = false, $description = "", $location = "", $color = null, $timezone = "", $notification = true, $notification_type = null, $notification_value = null) { $a = get_app(); $v = new vcalendar(); $v->setConfig('unique_id', $a->get_hostname()); $v->setProperty('method', 'PUBLISH'); $v->setProperty("x-wr-calname", "AnimexxCal"); $v->setProperty("X-WR-CALDESC", "Animexx Calendar"); $v->setProperty("X-WR-TIMEZONE", $a->timezone); $vevent = dav_create_vevent($start, $end, $allday); $vevent->setLocation(icalendar_sanitize_string($location)); $vevent->setSummary(icalendar_sanitize_string($subject)); $vevent->setDescription(icalendar_sanitize_string($description)); if (!is_null($color) && $color >= 0) { $vevent->setProperty("X-ANIMEXX-COLOR", $color); } if ($notification && $notification_type == null) { if ($allday) { $notification_type = "hour"; $notification_value = 24; } else { $notification_type = "minute"; $notification_value = 60; } } if ($notification) { $valarm = new valarm(); $valarm->setTrigger($notification_type == "year" ? $notification_value : 0, $notification_type == "month" ? $notification_value : 0, $notification_type == "day" ? $notification_value : 0, $notification_type == "week" ? $notification_value : 0, $notification_type == "hour" ? $notification_value : 0, $notification_type == "minute" ? $notification_value : 0, $notification_type == "second" ? $notification_value : 0, true, $notification_value > 0); $valarm->setAction("DISPLAY"); $valarm->setDescription($subject); $vevent->setComponent($valarm); } $v->setComponent($vevent); $ical = $v->createCalendar(); $obj_id = trim($vevent->getProperty("UID")); $calendarBackend = new Sabre_CalDAV_Backend_Std(); $calendarBackend->createCalendarObject($this->getNamespace() . "-" . $this->namespace_id, $obj_id . ".ics", $ical); return $obj_id . ".ics"; }