Пример #1
0
 /**
  * @coversNothing
  */
 public function testExample3()
 {
     $timeZone = new \DateTimeZone('Europe/Berlin');
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     // 2. Create an event
     $vEvent = new \Eluceo\iCal\Component\Event('123456');
     $vEvent->setDtStart(new \DateTime('2012-12-31', $timeZone));
     $vEvent->setDtEnd(new \DateTime('2012-12-31', $timeZone));
     $vEvent->setNoTime(true);
     $vEvent->setIsPrivate(true);
     $vEvent->setSummary('New Year’s Eve');
     // Set recurrence rule
     $recurrenceRule = new \Eluceo\iCal\Property\Event\RecurrenceRule();
     $recurrenceRule->setFreq(\Eluceo\iCal\Property\Event\RecurrenceRule::FREQ_YEARLY);
     $recurrenceRule->setInterval(1);
     $vEvent->setRecurrenceRule($recurrenceRule);
     // Adding Timezone (optional)
     $vEvent->setUseTimezone(true);
     // 3. Add event to calendar
     $vCalendar->addComponent($vEvent);
     $lines = array('/BEGIN:VCALENDAR/', '/VERSION:2\\.0/', '/PRODID:www\\.example\\.com/', '/X-PUBLISHED-TTL:P1W/', '/BEGIN:VEVENT/', '/UID:123456/', '/DTSTART;TZID=Europe\\/Berlin;VALUE=DATE:20121231/', '/SEQUENCE:0/', '/TRANSP:OPAQUE/', '/DTEND;TZID=Europe\\/Berlin;VALUE=DATE:20121231/', '/SUMMARY:New Year’s Eve/', '/CLASS:PRIVATE/', '/RRULE:FREQ=YEARLY;INTERVAL=1/', '/X-MICROSOFT-CDO-ALLDAYEVENT:TRUE/', '/DTSTAMP:20\\d{6}T\\d{6}Z/', '/END:VEVENT/', '/END:VCALENDAR/');
     foreach (explode("\n", $vCalendar->render()) as $key => $line) {
         $this->assertTrue(isset($lines[$key]), 'Too many lines... ' . $line);
         $this->assertRegExp($lines[$key], $line);
     }
 }
Пример #2
0
 /**
  * @param Organizer $vOrganizer
  * @return \Eluceo\iCal\Component\Calendar
  */
 private function createCalendarWithOrganizer(\Eluceo\iCal\Property\Event\Organizer $vOrganizer)
 {
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     $vEvent = new \Eluceo\iCal\Component\Event('123456');
     $vEvent->setOrganizer($vOrganizer);
     $vCalendar->addComponent($vEvent);
     return $vCalendar;
 }
Пример #3
0
 public function testDescriptionWithNewLines()
 {
     $input = "new string \n new line \n new line \n new string";
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     $vEvent = new \Eluceo\iCal\Component\Event();
     $vEvent->setDtStart(new \DateTime('2014-12-24'));
     $vEvent->setDtEnd(new \DateTime('2014-12-24'));
     $vEvent->setDescription($input);
     $vCalendar->addComponent($vEvent);
     $output = $vCalendar->render();
     $this->assertContains($input, $output);
 }
 public function write()
 {
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     $erb = new EventRepositoryBuilder($this->siteContainer);
     // TODO up to one month old!
     foreach ($erb->fetchAll() as $event) {
         $vEvent = new \Eluceo\iCal\Component\Event();
         $vEvent->setDtStart($event->getStart())->setDtEnd($event->getEnd())->setSummary($event->getTitle())->setDescription($event->getDescription())->setUrl($this->twigHelper->getTwig()->getExtension('openacalendar_internallink')->internalLinkToDir('/event/' . $event->getSlug()));
         $vCalendar->addComponent($vEvent);
     }
     $this->outFolder->addFileContents('api1', 'events.ics', $vCalendar->render());
 }
Пример #5
0
 /**
  * Add a new calendar event.
  *
  * @param Request $request
  *
  *
  * @Route("/download", name="event_download")
  * @Method("GET")
  */
 public function downloadAction()
 {
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     $vEvent = new \Eluceo\iCal\Component\Event();
     $vEvent->setDtStart(new \DateTime('2012-12-24'))->setDtEnd(new \DateTime('2012-12-24'))->setNoTime(true)->setSummary('Christmas');
     $vCalendar->addComponent($vEvent);
     $response = new Response();
     $response->setContent($vCalendar->render())->setCharset('ISO-8859-1')->setStatusCode(Response::HTTP_OK);
     $response->headers->set('Content-Type', 'multipart/alternative');
     $response->headers->set('Content-Disposition', 'attachment; filename="cal.ics"');
     return $response;
 }
Пример #6
0
 public function testFoldWithMultibyte()
 {
     $input = "x" . str_repeat("あいうえお", 5);
     $vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
     $vEvent = new \Eluceo\iCal\Component\Event();
     $vEvent->setDtStart(new \DateTime('2014-12-24'));
     $vEvent->setDtEnd(new \DateTime('2014-12-24'));
     $vEvent->setDescription($input);
     $vAlarm = new \Eluceo\iCal\Component\Alarm();
     $vAlarm->setAction(\Eluceo\iCal\Component\Alarm::ACTION_DISPLAY);
     $vAlarm->setDescription($input);
     $vAlarm->setTrigger('PT0S', true);
     $vEvent->addComponent($vAlarm);
     $vCalendar->addComponent($vEvent);
     $output = $vCalendar->render();
     $output = preg_replace('/\\r\\n /u', '', $output);
     $this->assertContains($input, $output);
 }
Пример #7
0
 public function calendar($society_id)
 {
     $events = $this->eventsForSociety($society_id)['events'];
     $vCalendar = new \Eluceo\iCal\Component\Calendar('lowdown.netsoc.co');
     foreach ($events as $event) {
         $vEvent = new \Eluceo\iCal\Component\Event();
         $eventTime = new DateTime($event->time);
         $endTime = $eventTime;
         $endTime->add(new DateInterval('PT1H'));
         $eventSummary = $event->society()->first()->name . ' Society: ' . $event->title;
         $vEvent->setDtStart($eventTime)->setDtEnd($endTime)->setSummary($eventSummary);
         if ($event->location) {
             $vEvent->setLocation($event->location);
         }
         $vCalendar->addComponent($vEvent);
     }
     header('Content-Type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="cal.ics"');
     echo $vCalendar->render();
 }
Пример #8
0
 /**
  * Renders an ical file for a specific group
  */
 public function group(Group $group)
 {
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar(config('app.url'));
     $vCalendar->setName(config('mobilizator.name') . ' : ' . $group->name);
     $vCalendar->setDescription(summary($group->body, 500));
     // returns actions started the last 60 days
     $actions = $group->actions()->where('start', '>=', Carbon::now()->subDays(60))->get();
     foreach ($actions as $action) {
         // 2. Create an event
         $vEvent = new \Eluceo\iCal\Component\Event();
         $vEvent->setDtStart($action->start);
         $vEvent->setDtEnd($action->stop);
         $vEvent->setSummary($action->name);
         $vEvent->setDescription(summary($action->body), 1000);
         $vEvent->setLocation($action->location);
         $vEvent->setUrl(action('ActionController@show', [$action->group->id, $action->id]));
         $vEvent->setUseUtc(false);
         //TODO fixme
         $vCalendar->addComponent($vEvent);
     }
     return response($vCalendar->render())->header('Content-Type', 'text/calendar; charset=utf-8')->header('Content-Disposition', 'attachment; filename="cal.ics"');
 }
Пример #9
0
<?php

// use composer autoloader
require_once __DIR__ . '/../vendor/autoload.php';
// set default timezone (PHP 5.4)
date_default_timezone_set('Europe/Berlin');
// 1. Create new calendar
$vCalendar = new \Eluceo\iCal\Component\Calendar('www.example.com');
// 2. Create an event
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent->setDtStart(new \DateTime('2012-12-24'));
$vEvent->setDtEnd(new \DateTime('2012-12-24'));
$vEvent->setNoTime(true);
$vEvent->setSummary('Christmas');
$vEvent->setDescription('Happy Christmas!');
$vEvent->setDescriptionHTML('<b>Happy Christmas!</b>');
// add some location information for apple devices
$vEvent->setLocation("Infinite Loop\nCupertino CA 95014", 'Infinite Loop', '37.332095,-122.030743');
// 3. Add event to calendar
$vCalendar->addComponent($vEvent);
// 4. Set headers
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="cal.ics"');
// 5. Output
echo $vCalendar->render();
Пример #10
0
 public function ical($key)
 {
     switch ($key) {
         case 'public':
             $items = BookingItem::where('start_at', '>=', date('Y-m-d'))->where('booking.is_private', '=', false)->with('booking', 'ressource')->get();
             $description = '';
             break;
         default:
             $filter = true;
             if (preg_match('/^(.+)_(.+)$/', $key, $tokens)) {
                 $key = $tokens[1];
                 if ($tokens[2] != 'all') {
                     App::abort(404);
                     return false;
                 }
                 $filter = false;
             }
             $owner = User::where('booking_key', '=', $key)->first();
             if (!$owner) {
                 App::abort(404);
                 return false;
             }
             $description = $owner->fullname;
             $items = BookingItem::where('start_at', '>=', date('Y-m-d'))->join('booking', 'booking_item.booking_id', '=', 'booking.id')->join('users', 'booking.user_id', '=', 'users.id');
             if ($filter) {
                 $items = $items->where('users.booking_key', '=', $key);
             }
             $items = $items->with('booking', 'ressource')->get();
             break;
     }
     $vCalendar = new \Eluceo\iCal\Component\Calendar(Request::server('SERVER_NAME'));
     $vCalendar->setDescription($description);
     $tz = new DateTimeZone(date_default_timezone_get());
     foreach ($items as $booking_item) {
         $start = new \DateTime($booking_item->start_at);
         $start->setTimezone($tz);
         $end = new \DateTime($booking_item->start_at);
         $start->setTimezone($tz);
         $end->modify(sprintf('+%d minutes', $booking_item->duration));
         $vEvent = new \Eluceo\iCal\Component\Event();
         $vEvent->setDtStart($start)->setDtEnd($end)->setUseTimezone(true)->setSummary(sprintf('%s (%s)', $booking_item->booking->title, $booking_item->ressource->name));
         $vCalendar->addComponent($vEvent);
     }
     $response = Response::make($vCalendar->render());
     $response->header('Content-Type', 'text/calendar; charset=utf-8');
     $response->header('Content-Disposition', 'attachment; filename="cal.ics"');
     return $response;
 }
Пример #11
0
list($fp, $content) = openFiles($file);
// Open the SQLite3 database that stores levee information.
$db = new SQLite3('data/levees.sqlite');
// Initialize a counter that we can use for the GeoJSON marker-symbol property.
$counter = 1;
// Retrieve all the levees
$results = $db->query('SELECT * FROM levees order by startDate, endDate, name');
while ($row = $results->fetchArray(SQLITE3_ASSOC)) {
    // Create JSON+LD for this levee.
    $content['json+ld'][] = makeJSONLD($row);
    // Create GeoJSON for this levee.
    $content['geojson']['features'][] = makeGeoJSON($row, $counter);
    // Create HTML for this levee.
    $content['html'] .= makeHTML($row);
    // Create iCalendar for this levee.
    $vCalendar->addComponent(makeICalendar($row));
    // Increment the counter.
    $counter++;
}
// Add to the GeoJSON object to make it valid.
$content['geojson']['type'] = "FeatureCollection";
// Write the JSON+LD data
fwrite($fp['json+ld'], json_encode($content['json+ld'], JSON_PRETTY_PRINT));
// Write the GeoJSON data
fwrite($fp['geojson'], json_encode($content['geojson'], JSON_PRETTY_PRINT));
// Write the HTML data
fwrite($fp['html'], makeHTMLheader());
fwrite($fp['html'], $content['html']);
fwrite($fp['html'], "\t" . '</tbody>' . "\n" . '</table>' . "\n");
// Wrhite the iCalendar data
fwrite($fp['ics'], $vCalendar->render());
 /**
  * sendCalendarReminder method
  * Notification about the reminder is sent only
  * when the record belonds to anyone.
  * @param Cake\Event $event from the afterSave
  * @param Cake\Datasource\EntityInterface $entity from the afterSave
  * @return array|bool $sent on whether the email was sent
  */
 public function sendCalendarReminder(Event $event, EntityInterface $entity)
 {
     $sent = false;
     $currentUser = null;
     //get applications's timezone
     $timezone = Time::now()->format('e');
     $dtz = new \DateTimeZone($timezone);
     $table = $event->subject();
     //get attendees Table for the event
     if (method_exists($table, 'getConfig') && is_callable([$table, 'getConfig'])) {
         $config = $table->getConfig();
         $remindersTo = $table->getTableAllowRemindersField();
     }
     // skip if attendees Table is not defined
     if (empty($remindersTo)) {
         return $sent;
     }
     // Figure out which field is a reminder one
     $reminderField = $table->getReminderFields();
     if (empty($reminderField) || !is_array($reminderField)) {
         return $sent;
     }
     $reminderField = $reminderField[0];
     if (!is_array($reminderField) || empty($reminderField['name'])) {
         return $sent;
     }
     $reminderField = $reminderField['name'];
     // Skip sending email if reminder field is empty
     if (empty($entity->{$reminderField})) {
         return $sent;
     }
     $attendeesFields = $this->_getAttendeesFields($table, ['tables' => $remindersTo]);
     // skip if no attendees fields found
     if (empty($attendeesFields)) {
         return $sent;
     }
     // skip if none of the required fields was modified
     $requiredFields = array_merge((array) $reminderField, $attendeesFields);
     if (!$this->_requiredFieldsModified($entity, $requiredFields)) {
         return $sent;
     }
     /*
      * Figure out the subject of the email
      *
      * This should happen AFTER the `$table->getConfig()` call,
      * in case the display field of the table is changed from the
      * configuration.
      *
      * Use singular of the table name and the value of the entity's display field.
      * For example: "Call: Payment remind" or "Lead: Qobo Ltd".
      */
     $fhf = new FieldHandlerFactory();
     $emailSubjectValue = $fhf->renderValue($table, $table->displayField(), $entity->{$table->displayField()}, ['renderAs' => 'plain']);
     $eventSubject = $emailSubjectValue ?: 'reminder';
     $emailSubject = Inflector::singularize($table->alias()) . ": " . $eventSubject;
     $emailContent = Inflector::singularize($table->alias()) . " information was ";
     // If the record is being updated, prefix the above subject with "(Updated) ".
     if (!$entity->isNew()) {
         $emailSubject = '(Updated) ' . $emailSubject;
         $emailContent .= "updated";
     } else {
         $emailContent .= "created";
     }
     $emails = $this->_getAttendees($table, $entity, $attendeesFields);
     if (empty($emails)) {
         return $sent;
     }
     if (method_exists($table, 'getCurrentUser') && is_callable([$table, 'getCurrentUser'])) {
         $currentUser = $table->getCurrentUser();
         $emailContent .= " by " . $currentUser['email'];
     }
     // append changelog if entity is not new
     if (!$entity->isNew()) {
         $emailContent .= "\n\n" . $this->_getChangelog($entity);
     }
     foreach ($emails as $email) {
         $vCalendar = new \Eluceo\iCal\Component\Calendar('//EN//');
         $vAttendees = $this->_getEventAttendees($emails);
         $vEvent = $this->_getCalendarEvent($entity, ['dtz' => $dtz, 'organizer' => $email, 'subject' => $emailSubject, 'attendees' => $vAttendees, 'field' => $reminderField, 'timezone' => $timezone]);
         $vEvent->setAttendees($vAttendees);
         $vCalendar->addComponent($vEvent);
         $headers = "Content-Type: text/calendar; charset=utf-8";
         $headers .= 'Content-Disposition: attachment; filename="event.ics"';
         $emailer = new Email('default');
         $emailer->to($email)->setHeaders([$headers])->subject($emailSubject)->attachments(['event.ics' => ['contentDisposition' => true, 'mimetype' => 'text/calendar', 'data' => $vCalendar->render()]]);
         $sent = $emailer->send($emailContent);
     }
     return $sent;
 }
Пример #13
0
        //if hidden then skip it
        if (!$mod->visible) {
            continue;
        }
        $dt = new DateTime();
        $dt->setTimestamp($mod->completionexpected);
        //create an event
        $ievent = new \Eluceo\iCal\Component\Event();
        $ievent->setDtStart($dt);
        $ievent->setDtEnd($dt);
        $ievent->setNoTime(true);
        $ievent->setSummary($mod->name);
        //add Timezone (optional)
        $ievent->setUseTimezone(true);
        //add event to calendar
        $ical->addComponent($ievent);
    }
    //set headers
    $filename = preg_replace('/[^A-Za-z0-9_\\-]/', '_', $course->shortname) . '_Calendar.ics';
    header('Content-Type: text/calendar; charset=utf-8');
    header('Content-Disposition: attachment; filename="' . $filename . '"');
    //output
    echo $ical->render();
    exit;
}
//------------------------------------------------------------
// PAGE OPTIONS
//------------------------------------------------------------
//obtain the header for the page
$schedheader = get_string('schedule_header', 'block_snap');
//set the url for this page
Пример #14
0
 public function calendar($user_id)
 {
     $user_id = Crypt::decrypt($user_id);
     $soc_ids = DB::table('subscriptions')->where('user_id', $user_id)->lists('society_id');
     $events = Event::where('time', '>', date('Y-m-d H:i:s'))->whereIn('society_id', $soc_ids)->get();
     $vCalendar = new \Eluceo\iCal\Component\Calendar('lowdown.netsoc.co');
     foreach ($events as $event) {
         $vEvent = new \Eluceo\iCal\Component\Event();
         $eventTime = new DateTime($event->time);
         $endTime = $eventTime;
         $endTime->add(new DateInterval('PT1H'));
         $eventSummary = $event->society()->first()->name . ' Society: ' . $event->title;
         $vEvent->setDtStart($eventTime)->setDtEnd($endTime)->setSummary($eventSummary);
         if ($event->location) {
             $vEvent->setLocation($event->location);
         }
         $vCalendar->addComponent($vEvent);
     }
     header('Content-Type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="cal.ics"');
     echo $vCalendar->render();
 }
Пример #15
0
 public function generateIcal()
 {
     // set default timezone (PHP 5.4)
     date_default_timezone_set('Europe/Berlin');
     $ical_name = 'HSG Wesel - Gesamtspielplan';
     $ical_calid = 'hsg_wesel_1516_total';
     $ics_file_name = 'hsg_wesel_1516_total.ics';
     $team_info = $this->getTeamInfo();
     if (is_array($team_info)) {
         $ical_name = 'HSG Wesel - Saison 2015/16 - ' . $team_info['team'];
         $ical_calid = 'hsg_wesel_1516_' . $team_info['liga_id'];
         $ics_file_name = 'hsg_wesel_1516_' . $this->getTeam() . '.ics';
     } else {
         switch ($this->art) {
             case '188':
                 $ical_name = 'HSG Wesel - Saison 2015/16 - Spielplan Heim';
                 $ical_calid = 'hsg_wesel_1516_1330105011_heim';
                 $ics_file_name = 'hsg_wesel_1516_spielplan_heim' . '.ics';
                 break;
             case '199':
                 $ical_name = 'HSG Wesel - Saison 2015/16 - Spielplan Auswärts';
                 $ical_calid = 'hsg_wesel_1516_1330105011_auswaerts';
                 $ics_file_name = 'hsg_wesel_1516_auswaerts' . '.ics';
                 break;
         }
     }
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar('HSG Wesel SIS-Handball ICS-Generator');
     $vCalendar->setName($ical_name);
     $vCalendar->setDescription('HSG Wesel / photominister.de');
     $vCalendar->setCalId($ical_calid);
     $vCalendar->setMethod('PUBLISH');
     // 2. Create an event
     // $this->framework->dump($this->art);
     if (count($this->xml->Spiel) > 0) {
         foreach ($this->xml->Spiel as $spiel) {
             $element = $this->getHash($spiel);
             $show_heim = substr($spiel->Heim, 0, 9) == 'HSG Wesel';
             $show_gast = substr($spiel->Gast, 0, 9) == 'HSG Wesel';
             switch ($this->art) {
                 case '188':
                     $cond = $show_heim;
                     break;
                 case '199':
                     $cond = $show_gast;
                     break;
                 default:
                     $cond = $show_heim || $show_gast;
                     break;
             }
             if ($cond) {
                 $description = $spiel->LigaName . '..... www.hsg-wesel.de ..... www.handballinwesel.de ..... www.facebook.com/hsgwesel';
                 $description = str_replace("\r\n", "\\n", $description);
                 $vEvent = new \Eluceo\iCal\Component\Event();
                 $vEvent->setDtStart(new \DateTime($spiel->SpielVon));
                 $vEvent->setDtEnd(new \DateTime($spiel->SpielBis));
                 $vEvent->setSummary($spiel->Heim . ' - ' . $spiel->Gast);
                 $vEvent->setDescription($description);
                 $vEvent->setLocation($spiel->HallenName . ', ' . $spiel->HallenStrasse . ', ' . $spiel->HallenOrt);
                 $vEvent->setUseTimezone(TRUE);
                 // 3. Add event to calendar
                 $vCalendar->addComponent($vEvent);
                 unset($vEvent);
             }
         }
     }
     // 4. Set headers
     header('Content-Type: text/calendar; charset=utf-8');
     header('Content-Disposition: attachment; filename="' . $ics_file_name . '"');
     // 5. Output
     echo $vCalendar->render();
     exit;
 }