/** * @covers makinuk\ICalendar\ICalendar::saveToFile */ public function testSaveToFile() { $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . "icalOut.ics"; if (file_exists($file)) { unlink($file); } $event = new ICalEvent(); $event->setUId(1234)->setSummary("Summary")->setOrganizer(new ICalPerson("Mustafa AKIN", "*****@*****.**"))->setLocation("Istanbul")->setEndDate(strtotime("+26 hours"))->setStartDate(strtotime("+24 hours"))->setDescription("Description"); $this->object->addEvent($event); $this->object->saveToFile($file); $this->assertFileExists($file); }
protected function contentline($line) { $contentline = array('name' => '', 'value' => '', 'params' => array()); if (preg_match('/([^":]*(?:"[^"]*"[^":]*)*):(.*)/', $line, $parts)) { $params = explode(';', $parts[1]); $contentline['name'] = array_shift($params); $contentline['value'] = trim(ICalendar::ical_unescape_text($parts[2])); $contentline['params'] = array(); foreach ($params as $param) { if (preg_match("/(.*?)=(.*)/", $param, $param_bits)) { $contentline['params'][$param_bits[1]] = str_replace("\"", "", $param_bits[2]); } } } else { Kurogo::log(LOG_WARNING, "Found an invalid ICS line: {$line}", 'data'); } return $contentline; }
public function parseData($data) { $calendar = new ICalendar(); $data = json_decode($data, true); $items = isset($data['data']['items']) ? $data['data']['items'] : array(); $total = 0; foreach ($items as $item) { if (!isset($item['when'])) { //probably an orphaned event. continue; } $event = new $this->eventClass(); $event->setUID($item['id']); $event->setSummary($item['title']); $event->setDescription($item['details']); if (isset($item['location'])) { $event->setLocation($item['location']); } if (count($item['when']) > 1) { throw new KurogoDataException("Need to handle multiple when values. Please report this as a bug including calendar and event used"); } $start = new DateTime($item['when'][0]['start']); $end = new DateTime($item['when'][0]['end']); if (stripos($item['when'][0]['start'], 'T') !== false) { $range = new TimeRange($start->format('U'), $end->format('U')); } else { //make all day events last until 11:59 of the end day $range = new DayRange($start->format('U'), $end->format('U') - 1); } $event->setRange($range); $calendar->add_event($event); $total++; } $this->setTotalItems($total); return $calendar; }
public function getEventText() { $VEVENT = "BEGIN:VEVENT\n"; $VEVENT .= "CLASS:PUBLIC\n"; $VEVENT .= "CREATED:" . date("Ymd\\THis\\Z", ICalendar::ConvertUTC()) . "\n"; $VEVENT .= "DTSTAMP:" . date("Ymd\\THis\\Z", ICalendar::ConvertUTC($this->_StartDate)) . "\n"; $VEVENT .= "DTSTART:" . date("Ymd\\THis\\Z", ICalendar::ConvertUTC($this->_StartDate)) . "\n"; $VEVENT .= "DTEND:" . date("Ymd\\THis\\Z", ICalendar::ConvertUTC($this->_EndDate)) . "\n"; $VEVENT .= "LOCATION:" . $this->_Location . "\n"; $VEVENT .= "ORGANIZER;CN=" . $this->_Organizer . "\n"; foreach ($this->_Attendee as $Attendee) { $VEVENT .= $Attendee; } $VEVENT .= "DESCRIPTION;LANGUAGE=tr:" . $this->_Description . "\n"; $VEVENT .= "PRIORITY:5\n"; $VEVENT .= "SEQUENCE:0\n"; $VEVENT .= "SUMMARY;LANGUAGE=tr:" . $this->_Summary . "\n"; $VEVENT .= "TRANSP:OPAQUE\n"; $VEVENT .= "UID:" . $this->_UId . "\n"; $VEVENT .= $this->_Alarm; return $VEVENT .= "END:VEVENT\n"; }
<?php /* * ©2013 Croce Rossa Italiana */ paginaPrivata(); $parametri = array('turno', 'v'); controllaParametri($parametri, 'utente.me&err'); $turno = Turno::id($_GET['turno']); $attivita = $turno->attivita(); paginaAttivita($attivita); $v = Volontario::id($_GET['v']); $p = Partecipazione::filtra([['turno', $turno], ['volontario', $v]]); $aut = Autorizzazione::by('partecipazione', $p[0]); $aut->concedi(); $cal = new ICalendar(); $cal->genera($attivita->id, $turno->id); $m = new Email('autorizzazioneConcessa', "Autorizzazione CONCESSA: {$a->nome}, {$turno->nome}"); $m->a = $v; $m->da = $attivita->referente(); $m->_NOME = $aut->partecipazione()->volontario()->nome; $m->_ATTIVITA = $attivita->nome; $m->_TURNO = $turno->nome; $m->_DATA = $turno->inizio()->format('d-m-Y H:i'); $m->_LUOGO = $attivita->luogo; $m->_REFERENTE = $attivita->referente()->nomeCompleto(); $m->_CELLREFERENTE = $attivita->referente()->cellulare(); $m->allega($cal); $m->invia(); redirect("attivita.scheda&id={$attivita->id}&turno={$turno->id}&riapri={$turno->id}");
public function parseData($contents) { $calendar = new ICalendar(); $nesting = array(); $contents = str_replace("\r\n", "\n", $contents); $lines = explode("\n", $this->unfold($contents)); foreach ($lines as $line) { $contentline = $this->contentline($line); $contentname = $contentline['name']; $value = $contentline['value']; $params = $contentline['params']; switch($contentname) { case 'BEGIN': switch ($value) { case 'VEVENT': $nesting[] = new $this->eventClass; break; case 'VCALENDAR': $nesting[] = $calendar; break; case 'VTIMEZONE': $nesting[] = new ICalTimeZone(); break; case 'DAYLIGHT': $nesting[] = new ICalDaylight(); break; case 'STANDARD': $nesting[] = new ICalStandard(); break; case 'VTODO': $nesting[] = new ICalTodo(); break; case 'VJOURNAL': $nesting[] = new ICalJournal(); break; case 'VFREEBUSY': $nesting[] = new ICalFreeBusy(); break; case 'VALARM': $nesting[] = new ICalAlarm(); break; default: throw new ICalendarException('unknown component type ' . $value); break; } break; case 'END': $last_object = array_pop($nesting); $last_obj_name = $last_object->get_name(); if ($last_obj_name != $value) { throw new ICalendarException("BEGIN $last_obj_name ended by END $value"); } switch ($value) { case 'VEVENT': if ($calendar->timezone) { $last_object->set_attribute('TZID', $calendar->timezone->tzid); } $calendar->add_event($last_object); break; case 'VTIMEZONE': $calendar->timezone = $last_object; break; case 'VCALENDAR': break 3; } break; default: end($nesting)->set_attribute($contentname, $value, $params); break; } } return $calendar; }
/** * Export a DateTime field. */ function _exportDateTime($value) { $temp = array(); if (!is_object($value) && !is_array($value)) { $tz = date('O', $value); $TZOffset = 3600 * substr($tz, 0, 3) + 60 * substr(date('O', $value), 3, 2); $value -= $TZOffset; $temp['zone'] = 'UTC'; $temp['year'] = date('Y', $value); $temp['month'] = date('n', $value); $temp['mday'] = date('j', $value); $temp['hour'] = date('G', $value); $temp['minute'] = date('i', $value); $temp['second'] = date('s', $value); } else { $dateOb = new \TYPO3\CMS\Cal\Model\CalDate($value); return ICalendar::_exportDateTime($dateOb->timestamp()); } return ICalendar::_exportDate($temp) . 'T' . ICalendar::_exportTime($temp); }
private function add_rrule($rrule_string) { $rules = explode(';', $rrule_string); $this->recur = TRUE; if ($this->occurrences === NULL) { $this->occurrences = Array(); } // read attributes from rrule_string $limit_type = ''; $limit = ''; $incrementors = Array( 'SECONDLY' => 'increment_second', 'MINUTELY' => 'increment_minute', 'HOURLY' => 'increment_hour', 'DAILY' => 'increment_day', 'WEEKLY' => 'increment_week', 'MONTHLY' => 'increment_month', 'YEARLY' => 'increment_year', ); $occurs_by_list = Array(); foreach ($rules as $rule) { $namevalue = explode('=', $rule); $rulename = $namevalue[0]; $rulevalue = $namevalue[1]; switch ($rulename) { case 'FREQ': // always present $this->incrementor = $incrementors[$rulevalue]; break; case 'INTERVAL': $this->interval = $rulevalue; case 'UNTIL': $limit_type = 'UNTIL'; $this->until = ICalendar::ical2unix($rulevalue); break; case 'COUNT': $limit_type = 'COUNT'; $limit = $rulevalue; break; case (substr($rulename, 0, 2) == 'BY'): $occurs_by_list[$rulename] = explode(',', $rulevalue); break; } } // finished reading attributes from rrule_string $occursByTypes = Array( 'BYMONTH' => Array('func' => 'increment_month', 'format' => 'n'), 'BYWEEKNO' => Array('func' => 'increment_week', 'format' => 'W'), 'BYYEARDAY' => Array('func' => 'increment_day', 'format' => 'z'), 'BYMONTHDAY' => Array('func'=> 'increment_day', 'format' => 'j'), 'BYDAY' => Array('func' => 'increment_day', 'format' => 'w'), 'BYHOUR' => Array('func' => 'increment_hour', 'format' => 'G'), 'BYMINUTE' => Array('func' => 'increment_minute', 'format' => 'i'), 'BYSECOND' => Array('func' => 'increment_second', 'format' => 's'), ); // create the first occurrence set $occur_unit = Array($this->range->get_start()); foreach ($occursByTypes as $byfreq => $attribs) { // we loop through occurByTypes so we can be sure to // act on each "by frequency" rule in order of decreasing grain size if (array_key_exists($byfreq, $occurs_by_list)) { $new_occur_unit = Array(); // every "when" within the "by frequency" // e.g. MO,TU,WE for BYDAY // needs to be a separate element of the occurrence set foreach($occurs_by_list[$byfreq] as $when) { $occurs_when = ($byfreq == 'BYDAY') ? ICalendar::$dayIndex[$when] : $when; // if the set of occurrences already has multiple elements // they will be multiplied // e.g. MO,TU for BYDAY and 1,2,3 for BYMONTH // yields 6 elements in the occurence set foreach ($occur_unit as $start) { $count = 0; // for debugging below while (intval(date($attribs['format'], $start)) != $occurs_when) { $start = call_user_func($attribs['func'], $start); // haven't seen this happen yet but who knows if ($count > 366) { throw new ICalendarException("maximum loop count exceeded"); } $count += 1; } $new_occur_unit[] = $start; } } $occur_unit = $new_occur_unit; } } // BYSETPOS limits us to particular indices of the occurrence set if (array_key_exists('BYSETPOS', $occurs_by_list)) { $new_occur_unit = Array(); $setposlist = $occurs_by_list['BYSETPOS']; foreach ($setposlist as $setpos) { if ($setpos < 0) { $setpos = count($occur_unit) + $setpos; } else { $setpos = $setpos - 1; } $new_occur_unit[] = $occur_unit[$setpos]; } $occur_unit = $new_occur_unit; } $this->occurrences = $occur_unit; // duplicate the occurrence set for COUNT limits // this is approximate if ($limit_type == 'COUNT') { $num_increments = $limit / count($this_occurrences); $end = end($occur_unit); while ($num_increments > 0) { $end = $this->incrementor($end); $num_increments -= 1; } $this->until = $end; } }
public function updateCalendar(ICalendar $calendar) { try { $dbHandler = $this->getConnection(); $data = array(CalendarManager::CALENDAR_KEY_ID => $calendar->getId(), CalendarManager::CALENDAR_KEY_NAME => $calendar->getName(), CalendarManager::CALENDAR_KEY_DESCRIPTION => $calendar->getDescription(), CalendarManager::CALENDAR_KEY_TIMEZONE => $calendar->getTimezone(), CalendarManager::CALENDAR_KEY_OWNERID => $calendar->getOwnerId()); $sqlQuery = 'UPDATE ' . self::CALENDAR_TABLE_NAME . ' SET '; foreach ($data as $key => $value) { if ($key != CalendarManager::CALENDAR_KEY_ID) { $sqlQuery .= $key . ' = :' . $key . ', '; } } $sqlQuery = substr($sqlQuery, 0, -2); $sqlQuery .= ' WHERE ' . CalendarManager::CALENDAR_KEY_ID . ' = :' . CalendarManager::CALENDAR_KEY_ID; $stmt = $dbHandler->prepare($sqlQuery); $stmt->execute($data); } catch (Exception $e) { $this->destroyConnection(); throw new EyeDBException('An error occured while attempting to update calendar with ID "' . $calendar->getId() . '".', 0, $e); } $this->destroyConnection(); }
private function api_corsobase_accetta() { $this->richiedi(['id']); $me = $this->richiediLogin(); $part = PartecipazioneBase::id($this->par['id']); $corsoBase = $part->corsoBase(); if (!$corsoBase->modificabileDa($me)) { return ['ok' => false]; } if ($part->stato == ISCR_RICHIESTA) { if ($this->par['iscr']) { $part->concedi($this->par['com'], $me); $cal = new ICalendar(); $cal->generaCorsoBase($corsoBase); $m = new Email('corsoBaseAmmesso', "Ammesso al {$corsoBase->nome()}"); $m->a = $part->utente(); $m->da = $corsoBase->direttore(); $m->_NOME = $part->utente()->nome; $m->_CORSO = $corsoBase->nome(); $m->_DATA = $corsoBase->inizio()->inTesto(false, true); $m->_DIRETTORE = $corsoBase->direttore()->nomeCompleto(); $m->_CELLDIRETTORE = $corsoBase->direttore()->cellulare(); $m->allega($cal); $m->invia(); } else { $part->nega($me); $motivo = $this->par['motivo']; $m = new Email('corsoBaseNonAmmesso', "Non ammesso al {$corsoBase->nome()}"); $m->a = $part->utente(); $m->da = $corsoBase->direttore(); $m->_NOME = $part->utente()->nome; $m->_MOTIVO = $motivo; $m->_CORSO = $corsoBase->nome(); $m->_DIRETTORE = $corsoBase->direttore()->nomeCompleto(); $m->invia(); } } return ['id' => $corsoBase->id]; }
public function retrieveAllEventsFromCalendar(ICalendar $calendar, $timeFrom = null, $timeTo = null) { $filter = array(CalendarManager::CALENDAR_KEY_ID => $calendar->getId()); if ($timeFrom !== null) { $filter[CalendarManager::EVENT_KEY_TIMESTART] = array('>', $timeFrom); } if ($timeTo !== null) { $filter[CalendarManager::EVENT_KEY_TIMEEND] = array('<', $timeTo); } return self::convertResultsToEventObjects($this->retrieveAllEventsWithFilter($filter)); }
public function saveCalendar(ICalendar $calendar) { try { try { $this->getProvider()->retrieveCalendarById($calendar->getId()); } catch (EyeCalendarNotFoundException $e) { $this->getProvider()->createCalendar($calendar); self::$Logger->info('Calendar created: ' . $calendar); return; } $this->getProvider()->updateCalendar($calendar); self::$Logger->info('Calendar updated: ' . $calendar); } catch (Exception $e) { throw new EyeCalendarException('An error occured while saving calendar with ID ' . $calendar->getId() . ' (' . $calendar->getName() . ').', 0, $e); } }
public function parseData($contents) { $calendar = new ICalendar(); $nesting = array(); $contents = str_replace("\r\n", "\n", $contents); $lines = explode("\n", $this->unfold($contents)); foreach ($lines as $line) { $contentline = $this->contentline($line); $contentname = $contentline['name']; $value = $contentline['value']; $params = $contentline['params']; switch ($contentname) { case 'BEGIN': switch ($value) { case 'VEVENT': $addEvent = true; $nesting[] = new $this->eventClass(); break; case 'VCALENDAR': $nesting[] = $calendar; break; case 'VTIMEZONE': $nesting[] = new ICalTimeZone(); break; case 'DAYLIGHT': $nesting[] = new ICalDaylight(); break; case 'STANDARD': $nesting[] = new ICalStandard(); break; case 'VTODO': $nesting[] = new ICalTodo(); break; case 'VJOURNAL': $nesting[] = new ICalJournal(); break; case 'VFREEBUSY': $nesting[] = new ICalFreeBusy(); break; case 'VALARM': $nesting[] = new ICalAlarm(); break; default: if ($this->haltOnParseErrors) { throw new ICalendarException('unknown component type ' . $value); } else { Kurogo::log(LOG_WARNING, "Unknown ICS type {$value}", 'data'); } break; } break; case 'END': $last_object = array_pop($nesting); $last_obj_name = $last_object->get_name(); if ($last_obj_name != $value) { if ($this->haltOnParseErrors) { throw new ICalendarException("BEGIN {$last_obj_name} ended by END {$value}"); } else { Kurogo::log(LOG_WARNING, "BEGIN {$last_obj_name} ended by END {$value}", 'data'); $value = null; //throw it away } } switch ($value) { case 'VEVENT': if ($calendar->timezone) { $last_object->set_attribute('TZID', $calendar->timezone->tzid); } if ($addEvent) { $calendar->add_event($last_object); } break; case 'VTIMEZONE': $calendar->timezone = $last_object; break; case 'VCALENDAR': break 3; } break; default: try { end($nesting)->set_attribute($contentname, $value, $params); } catch (ICalendarException $e) { if ($this->haltOnParseErrors) { throw $e; } Kurogo::log(LOG_WARNING, $e->getMessage(), 'data'); $addEvent = false; } break; } } $events = $calendar->getEvents(); Kurogo::log(LOG_DEBUG, "Found " . count($events) . " events", 'data'); $this->setTotalItems(count($events)); return $calendar; }
array_unshift($this->content, "BEGIN:" . $this->name); array_push($this->content, "END:" . $this->name); foreach ($this->content as &$pValue) { if (!$pValue instanceof ICalendarItem) { continue; } $pValue = $pValue->render(); } return implode(self::CRLF, $this->content); } } define('TARGET', 'CSM EAUBONNE'); $items = file_get_contents('http://www.arnaud-nicolas.fr/projects/Volley/src/php/proxy.ffvb.php?gzip=0'); $data = json_decode($items, true); $agenda = $data["agenda"]; $ic = new ICalendar("-//arnaud-nicolas.fr/Volley/LIIDF", "1.0"); foreach ($agenda as $day) { $name = $day['label']; foreach ($day['matches'] as $match) { if ($match['home']['name'] == TARGET || $match['guest']['name'] == TARGET) { $vs = $match['home']['name'] . " - " . $match['guest']['name']; $d = explode('/', $match['date']); $h = explode(':', $match['hour']); if (count($h) < 2) { $h = array("12", "0"); } $ic->addEvent("Volley : " . $vs, time(), mktime($h[0], $h[1], 0, $d[1], $d[0], "20" . $d[2]))->setDTEnd(mktime($h[0] + 2, $h[1], 0, $d[1], $d[0], "20" . $d[2]))->setCategories("Volley")->setDescription($name . " : " . $vs); } } } header("Content-Type:text/plain;charset=UTF-8");