Example #1
0
 /**
  * Convert an event object to be used on the client
  */
 private function _client_event($event, $addcss = false)
 {
     // compose a human readable strings for alarms_text and recurrence_text
     if ($event['valarms']) {
         $event['alarms_text'] = libcalendaring::alarms_text($event['valarms']);
         $event['valarms'] = libcalendaring::to_client_alarms($event['valarms']);
     }
     if ($event['recurrence']) {
         $event['recurrence_text'] = $this->lib->recurrence_text($event['recurrence']);
         $event['recurrence'] = $this->lib->to_client_recurrence($event['recurrence'], $event['allday']);
         unset($event['recurrence_date']);
     }
     foreach ((array) $event['attachments'] as $k => $attachment) {
         $event['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
     }
     // convert link URIs references into structs
     if (array_key_exists('links', $event)) {
         foreach ((array) $event['links'] as $i => $link) {
             if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) {
                 $event['links'][$i] = $msgref;
             }
         }
     }
     // check for organizer in attendees list
     $organizer = null;
     foreach ((array) $event['attendees'] as $i => $attendee) {
         if ($attendee['role'] == 'ORGANIZER') {
             $organizer = $attendee;
         }
         if ($attendee['status'] == 'DELEGATED' && $attendee['rsvp'] == false) {
             $event['attendees'][$i]['noreply'] = true;
         } else {
             unset($event['attendees'][$i]['noreply']);
         }
     }
     if ($organizer === null && !empty($event['organizer'])) {
         $organizer = $event['organizer'];
         $organizer['role'] = 'ORGANIZER';
         if (!is_array($event['attendees'])) {
             $event['attendees'] = array();
         }
         array_unshift($event['attendees'], $organizer);
     }
     // Convert HTML description into plain text
     if ($this->is_html($event)) {
         $h2t = new rcube_html2text($event['description'], false, true, 0);
         $event['description'] = trim($h2t->get_text());
     }
     // mapping url => vurl because of the fullcalendar client script
     $event['vurl'] = $event['url'];
     unset($event['url']);
     return array('_id' => $event['calendar'] . ':' . $event['id'], 'start' => $this->lib->adjust_timezone($event['start'], $event['allday'])->format('c'), 'end' => $this->lib->adjust_timezone($event['end'], $event['allday'])->format('c'), 'changed' => $event['changed'] ? $this->lib->adjust_timezone($event['changed'])->format('c') : null, 'created' => $event['created'] ? $this->lib->adjust_timezone($event['created'])->format('c') : null, 'title' => strval($event['title']), 'description' => strval($event['description']), 'location' => strval($event['location']), 'className' => ($addcss ? 'fc-event-cal-' . asciiwords($event['calendar'], true) . ' ' : '') . 'fc-event-cat-' . asciiwords(strtolower(join('-', (array) $event['categories'])), true) . rtrim(' ' . $event['className']), 'allDay' => $event['allday'] == 1) + $event;
 }
Example #2
0
 /**
  * Convert an event object to be used on the client
  */
 private function _client_event($event, $addcss = false)
 {
     $cal_tz = $this->timezone->getName();
     if (!$event['allday'] && $event['tzname'] && $cal_tz != $event['tzname']) {
         $cal_tz = new DateTimeZone($cal_tz);
         $event_tz = new DateTimeZone($event['tzname']);
         $event['tzinfo'] = $event_tz->getLocation();
         $cal_dt = new DateTime(date('Y-m-d H:i:s', $event['start']->format('U')), $cal_tz);
         $event_dt = new DateTime(date('Y-m-d H:i:s', $event['start']->format('U')), $event_tz);
         $event['tzadjust'] = -($cal_dt->getOffset() - $event_dt->getOffset());
     } else {
         $event['tzadjust'] = 0;
     }
     // compose a human readable strings for alarms_text and recurrence_text
     if ($event['alarms']) {
         $event['alarms_text'] = libcalendaring::alarms_text($event['alarms']);
     }
     if ($event['recurrence']) {
         $event['recurrence_text'] = $this->_recurrence_text($event['recurrence']);
         if ($event['recurrence']['UNTIL']) {
             $event['recurrence']['UNTIL'] = $this->lib->adjust_timezone($event['recurrence']['UNTIL'], $event['allday'])->format('c');
         }
         unset($event['recurrence']['EXCEPTIONS']);
         // format RDATE values
         if (is_array($event['recurrence']['RDATE'])) {
             $libcal = $this->lib;
             $event['recurrence']['RDATE'] = array_map(function ($rdate) use($libcal) {
                 return $libcal->adjust_timezone($rdate, true)->format('c');
             }, $event['recurrence']['RDATE']);
         }
     }
     foreach ((array) $event['attachments'] as $k => $attachment) {
         $event['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
     }
     // check for organizer in attendees list
     $organizer = null;
     foreach ((array) $event['attendees'] as $i => $attendee) {
         if (isset($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
             $organizer = $attendee;
             break;
         }
     }
     if ($organizer === null && !empty($event['organizer'])) {
         $organizer = $event['organizer'];
         $organizer['role'] = 'ORGANIZER';
         if (!is_array($event['attendees'])) {
             $event['attendees'] = array();
         }
         array_unshift($event['attendees'], $organizer);
     }
     // mapping url => vurl because of the fullcalendar client script
     $event['vurl'] = $event['url'];
     unset($event['url']);
     // Begin mod by Rosali (https://issues.kolab.org/show_bug.cgi?id=3481)
     // Fix 1 second issue of all-day events
     if ($event['allday'] && isset($event['end'])) {
         if ($event['start'] == $event['end']) {
             $event['end']->modify('+ 1 day');
             $event['end']->modify('- 1 minute');
         }
     }
     $start = $event['start'] ? $event['start']->format('c') : null;
     $end = $event['end'] ? $event['end']->format('c') : null;
     if (!$event['allday']) {
         if (isset($event['end'])) {
             $estart = $event['start']->format('U');
             $eend = $event['end']->format('U');
             if ($eend - $estart > $this->rc->config->get('calendar_treat_as_allday', 6) * 3600) {
                 $view_start = get_input_value('start', RCUBE_INPUT_GPC);
                 $view_end = get_input_value('end', RCUBE_INPUT_GPC);
                 $event['allday'] = true;
                 $event['allDayfake'] = true;
                 if ($event['start']->format('U') >= $view_start) {
                     $event['left'] = $event['start']->format($this->rc->config->get('time_format', 'H:i'));
                 } else {
                     $event['left'] = '';
                 }
                 if ($event['end']->format('U') <= $view_end) {
                     $event['right'] = $event['end']->format($this->rc->config->get('time_format', 'H:i'));
                 } else {
                     $event['right'] = '';
                 }
             }
         }
     }
     $tempClass = $event['temp'] ? 'fc-event-temp ' : '';
     // End mod by Rosali
     // Begin mod by Rosali (advanced categories colorizing)
     if (is_string($event['categories'])) {
         $event['categories'] = explode(',', $event['categories']);
         foreach ($event['categories'] as $idx => $cat) {
             $event['categories'][$idx] = trim($cat);
         }
     }
     $readwrite_color = $this->rc->config->get('calendar_events_default_background_color', $this->defaults['calendar_events_default_background_color']);
     $readonly_color = $this->rc->config->get('calendar_readonly_events_default_background_color', $this->defaults['calendar_event_defaults_background_color']);
     $mode = $this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring']);
     $categories = $this->rc->config->get('calendar_categories', array());
     $calendars = $this->get_calendars();
     $calendar_color = $calendars[$event['calendar']]['color'];
     foreach ((array) $event['categories'] as $idx => $category) {
         $category_color = $event['readonly'] ? $readonly_color : $readwrite_color;
         if (isset($categories[$event['categories'][$idx]])) {
             $category_color = $categories[$category];
             break;
         }
     }
     switch ($mode) {
         case '0':
             $backgroundColor = $calendar_color;
             $borderColor = $calendar_color;
             break;
         case '1':
             $backgroundColor = $category_color;
             $borderColor = $category_color;
             break;
         case '2':
             $backgroundColor = $category_color;
             $borderColor = $calendar_color;
             break;
         case '3':
             $backgroundColor = $calendar_color;
             $borderColor = $category_color;
             break;
     }
     $mode = $this->rc->config->get('calendar_event_font_color', 0);
     if ($mode == 0) {
         $c_r = hexdec(substr($backgroundColor, 0, 2));
         $c_g = hexdec(substr($backgroundColor, 2, 2));
         $c_b = hexdec(substr($backgroundColor, 4, 2));
         $brightness = ($c_r * 299 + $c_g * 587 + $c_b * 114) / 1000;
         if ($brightness > 130) {
             $fontColor = '000000';
         } else {
             $fontColor = 'FFFFFF';
         }
     } else {
         if ($mode == 1) {
             $fontColor = substr(dechex(~hexdec($backgroundColor)), -6);
         } else {
             if ($mode == 2) {
                 $fontColor = 'FFFFFF';
             } else {
                 $fontColor = '000000';
             }
         }
     }
     // End mod by Rosali
     return array('_id' => $event['calendar'] . ':' . $event['id'], 'start' => $start, 'end' => $end, 'changed' => $event['changed'] ? $this->lib->adjust_timezone($event['changed'])->format('c') : null, 'created' => $event['created'] ? $this->lib->adjust_timezone($event['created'])->format('c') : null, 'title' => strval($event['title']), 'description' => strval($event['description']), 'location' => strval($event['location']), 'categories' => is_array($event['categories']) ? implode(', ', $event['categories']) : $event['categories'], 'className' => ($addcss ? 'fc-event-cal-' . asciiwords($event['calendar'], true) . ' ' : '') . $tempClass, 'calendarColor' => $calendar_color, 'categoryColor' => $category_color, 'backgroundColor' => '#' . $backgroundColor, 'borderColor' => '#' . $borderColor, 'textColor' => '#' . $fontColor, 'allDay' => $event['allday'] == 1) + $event;
 }
Example #3
0
 /**
  * Prepare the given task record before sending it to the client
  */
 private function encode_task(&$rec)
 {
     $rec['mask'] = $this->filter_mask($rec);
     $rec['flagged'] = intval($rec['flagged']);
     $rec['complete'] = floatval($rec['complete']);
     $rec['changed'] = is_object($rec['changed']) ? $rec['changed']->format('U') : null;
     if ($rec['date']) {
         try {
             $date = new DateTime($rec['date'] . ' ' . $rec['time'], $this->timezone);
             $rec['datetime'] = intval($date->format('U'));
             $rec['date'] = $date->format($this->rc->config->get('date_format', 'Y-m-d'));
             $rec['_hasdate'] = 1;
         } catch (Exception $e) {
             $rec['date'] = $rec['datetime'] = null;
         }
     } else {
         $rec['date'] = $rec['datetime'] = null;
         $rec['_hasdate'] = 0;
     }
     if ($rec['startdate']) {
         try {
             $date = new DateTime($rec['startdate'] . ' ' . $rec['starttime'], $this->timezone);
             $rec['startdatetime'] = intval($date->format('U'));
             $rec['startdate'] = $date->format($this->rc->config->get('date_format', 'Y-m-d'));
         } catch (Exception $e) {
             $rec['startdate'] = $rec['startdatetime'] = null;
         }
     }
     if ($rec['alarms']) {
         $rec['alarms_text'] = libcalendaring::alarms_text($rec['alarms']);
     }
     foreach ((array) $rec['attachments'] as $k => $attachment) {
         $rec['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
     }
     if (in_array($rec['id'], $this->collapsed_tasks)) {
         $rec['collapsed'] = true;
     }
     $this->task_titles[$rec['id']] = $rec['title'];
 }
 /**
  * Prepare the given task record before sending it to the client
  */
 private function encode_task(&$rec)
 {
     $rec['mask'] = $this->filter_mask($rec);
     $rec['flagged'] = intval($rec['flagged']);
     $rec['complete'] = floatval($rec['complete']);
     if (is_object($rec['created'])) {
         $rec['created_'] = $this->rc->format_date($rec['created']);
         $rec['created'] = $rec['created']->format('U');
     }
     if (is_object($rec['changed'])) {
         $rec['changed_'] = $this->rc->format_date($rec['changed']);
         $rec['changed'] = $rec['changed']->format('U');
     } else {
         $rec['changed'] = null;
     }
     if ($rec['date']) {
         try {
             $date = new DateTime($rec['date'] . ' ' . $rec['time'], $this->timezone);
             $rec['datetime'] = intval($date->format('U'));
             $rec['date'] = $date->format($this->rc->config->get('date_format', 'Y-m-d'));
             $rec['_hasdate'] = 1;
         } catch (Exception $e) {
             $rec['date'] = $rec['datetime'] = null;
         }
     } else {
         $rec['date'] = $rec['datetime'] = null;
         $rec['_hasdate'] = 0;
     }
     if ($rec['startdate']) {
         try {
             $date = new DateTime($rec['startdate'] . ' ' . $rec['starttime'], $this->timezone);
             $rec['startdatetime'] = intval($date->format('U'));
             $rec['startdate'] = $date->format($this->rc->config->get('date_format', 'Y-m-d'));
         } catch (Exception $e) {
             $rec['startdate'] = $rec['startdatetime'] = null;
         }
     }
     if ($rec['valarms']) {
         $rec['alarms_text'] = libcalendaring::alarms_text($rec['valarms']);
         $rec['valarms'] = libcalendaring::to_client_alarms($rec['valarms']);
     }
     if ($rec['recurrence']) {
         $rec['recurrence_text'] = $this->lib->recurrence_text($rec['recurrence']);
         $rec['recurrence'] = $this->lib->to_client_recurrence($rec['recurrence'], $rec['time'] || $rec['starttime']);
     }
     foreach ((array) $rec['attachments'] as $k => $attachment) {
         $rec['attachments'][$k]['classname'] = rcube_utils::file2class($attachment['mimetype'], $attachment['name']);
     }
     // convert link URIs references into structs
     if (array_key_exists('links', $rec)) {
         foreach ((array) $rec['links'] as $i => $link) {
             if (strpos($link, 'imap://') === 0 && ($msgref = $this->driver->get_message_reference($link))) {
                 $rec['links'][$i] = $msgref;
             }
         }
     }
     // Convert HTML description into plain text
     if ($this->is_html($rec)) {
         $h2t = new rcube_html2text($rec['description'], false, true, 0);
         $rec['description'] = $h2t->get_text();
     }
     if (!is_array($rec['tags'])) {
         $rec['tags'] = (array) $rec['tags'];
     }
     sort($rec['tags'], SORT_LOCALE_STRING);
     if (in_array($rec['id'], $this->collapsed_tasks)) {
         $rec['collapsed'] = true;
     }
     if (empty($rec['parent_id'])) {
         $rec['parent_id'] = null;
     }
     $this->task_titles[$rec['id']] = $rec['title'];
 }