/** * Method for exporting event in vCalendar format * * @param org_openpsa_calendar_event_dba $event The event we're working on * @param array compatibility options to override * @return string vCalendar data */ public function export_event(org_openpsa_calendar_event_dba $event, $compatibility = array()) { $encoder = new org_openpsa_helpers_vxparser(); $encoder->merge_compatibility($compatibility); // Simple key/value pairs, for multiple occurrences of same key use array as value $vcal_keys = array(); // For extended key data, like charset $vcal_key_parameters = array(); // TODO: handle UID smarter $vcal_keys['UID'] = "{$event->guid}-midgardGuid"; $revised = $event->metadata->revised; $created = $event->metadata->created; $vcal_keys['LAST-MODIFIED'] = $encoder->vcal_stamp($revised, array('TZID' => 'UTC')) . 'Z'; $vcal_keys['CREATED'] = $encoder->vcal_stamp($created, array('TZID' => 'UTC')) . 'Z'; /** * The real meaning of the DTSTAMP is fuzzy at best * http://www.kanzaki.com/docs/ical/dtstamp.html is less than helpful * http://lists.osafoundation.org/pipermail/ietf-calsify/2007-July/001750.html * seems to suggest that using the revision would be best */ $vcal_keys['DTSTAMP'] =& $vcal_keys['LAST-MODIFIED']; // Type handling switch ($event->orgOpenpsaAccesstype) { case org_openpsa_core_acl::ACCESS_PUBLIC: $vcal_keys['CLASS'] = 'PUBLIC'; break; default: case org_openpsa_core_acl::ACCESS_PRIVATE: $vcal_keys['CLASS'] = 'PRIVATE'; break; } // "busy" or "transparency" as vCalendar calls it if ($event->busy) { $vcal_keys['TRANSP'] = 'OPAQUE'; } else { $vcal_keys['TRANSP'] = 'TRANSPARENT'; } // tentative vs confirmed $vcal_keys['STATUS'] = 'CONFIRMED'; // we don't categorize events, at least yet $vcal_keys['CATEGORIES'] = 'MEETING'; // we don't handle priorities $vcal_keys['PRIORITY'] = 1; // Basic fields $vcal_keys['SUMMARY'] = $encoder->escape_separators($event->title); $vcal_keys['DESCRIPTION'] = $encoder->escape_separators($event->description); $vcal_keys['LOCATION'] = $encoder->escape_separators($event->location); // Start & End in UTC $vcal_keys['DTSTART'] = $encoder->vcal_stamp($event->start, array('TZID' => 'UTC')) . 'Z'; $vcal_keys['DTEND'] = $encoder->vcal_stamp($event->end, array('TZID' => 'UTC')) . 'Z'; // Participants $vcal_keys['ATTENDEE'] = array(); $vcal_key_parameters['ATTENDEE'] = array(); // Safety, otherwise the notice will make output invalid if (!is_array($event->participants)) { $event->participants = array(); } foreach ($event->participants as $uid => $bool) { // Just a safety if (!$bool) { continue; } $person = midcom_db_person::get_cached($uid); if (empty($person->email)) { // Attendee must have email address of valid format, these must also be unique. $person->email = preg_replace('/[^0-9_\\x61-\\x7a]/i', '_', strtolower($person->name)) . '*****@*****.**'; } $vcal_keys['ATTENDEE'][] = "mailto:{$person->email}"; $vcal_key_parameters['ATTENDEE'][] = array('ROLE' => 'REQ-PARTICIPANT', 'CUTYPE' => 'INDIVIDUAL', 'PARTSTAT' => 'ACCEPTED', 'CN' => $encoder->escape_separators($person->rname, true)); } $ret = "BEGIN:VEVENT{$this->_newline}"; $ret .= $encoder->export_vx_variables_recursive($vcal_keys, $vcal_key_parameters, false, $this->_newline); $ret .= "END:VEVENT{$this->_newline}"; return $ret; }
/** * Encode value to escape newlines */ function vx_encode_nl($str, $nl = "\r\n") { //Convert and escape linebreaks $str = preg_replace("/\r\n|\n\r|\r|\n/", '\\n', $str); if ($this->_check_folding()) { // "Fold" data if necessary/allowed to do so org_openpsa_helpers_vxparser::_vx_encode_fold($str, $nl); } return $str; }