protected function _addEventAttendee(Sabre_VObject_Component $_vevent, Calendar_Model_Event $_event) { if (version_compare($this->_version, '1.0b2', '>')) { parent::_addEventAttendee($_vevent, $_event); } else { // special handling for Lightning <= 1.0b2 // attendees get screwed up, if the CN contains commas Calendar_Model_Attender::resolveAttendee($_event->attendee, FALSE, $_event); foreach ($_event->attendee as $eventAttendee) { $attendeeEmail = $eventAttendee->getEmail(); if ($attendeeEmail) { $attendee = new Sabre_VObject_Property('ATTENDEE', (strpos($attendeeEmail, '@') !== false ? 'mailto:' : 'urn:uuid:') . $attendeeEmail); $attendee->add('CN', str_replace(',', null, $eventAttendee->getName())); $attendee->add('CUTYPE', Calendar_Convert_Event_VCalendar_Abstract::$cutypeMap[$eventAttendee->user_type]); $attendee->add('PARTSTAT', $eventAttendee->status); $attendee->add('ROLE', "{$eventAttendee->role}-PARTICIPANT"); $attendee->add('RSVP', 'FALSE'); if (strpos($attendeeEmail, '@') !== false) { $attendee->add('EMAIL', $attendeeEmail); } $_vevent->add($attendee); } } } }
/** * implode values with ";" after calling parent::addSlashes * * @param string|array $value * @return string */ public function addSlashes($value) { foreach ($value as &$_value) { $_value = parent::addSlashes($_value); } return implode(self::DELIMITER, $value); }
/** * Work around issue in older VObject sersions * https://github.com/fruux/sabre-vobject/issues/24 * * @param Sabre_VObject_Property $property Reference to a Sabre_VObject_Property. */ public function fixPropertyParameters(&$property) { // Work around issue in older VObject sersions // https://github.com/fruux/sabre-vobject/issues/24 foreach ($property->parameters as $key => $parameter) { $delim = ''; if (strpos($parameter->value, ',') === false) { continue; } $values = explode(',', $parameter->value); $values = array_map('trim', $values); $parameter->value = array_shift($values); foreach ($values as $value) { $property->add($parameter->name, $value); } } }
/** * converts Addressbook_Model_Contact to vcard * * @param Addressbook_Model_Contact $_record * @return string */ public function fromTine20Model(Tinebase_Record_Abstract $_record) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' contact ' . print_r($_record->toArray(), true)); } $card = new Sabre_VObject_Component('VCARD'); // required vcard fields $card->add(new Sabre_VObject_Property('VERSION', '3.0')); $card->add(new Sabre_VObject_Property('FN', $_record->n_fileas)); $card->add(new Sabre_VObject_Element_MultiValue('N', array($_record->n_family, $_record->n_given))); $card->add(new Sabre_VObject_Property('PRODID', '-//tine20.org//Tine 2.0//EN')); $card->add(new Sabre_VObject_Property('UID', $_record->getId())); // optional fields $card->add(new Sabre_VObject_Element_MultiValue('ORG', array($_record->org_name, $_record->org_unit))); $card->add(new Sabre_VObject_Property('TITLE', $_record->title)); $tel = new Sabre_VObject_Property('TEL', $_record->tel_work); $tel->add('TYPE', 'WORK'); $card->add($tel); $tel = new Sabre_VObject_Property('TEL', $_record->tel_home); $tel->add('TYPE', 'HOME'); $card->add($tel); $tel = new Sabre_VObject_Property('TEL', $_record->tel_cell); $tel->add('TYPE', 'CELL'); $card->add($tel); $tel = new Sabre_VObject_Property('TEL', $_record->tel_pager); $tel->add('TYPE', 'PAGER'); $card->add($tel); $tel = new Sabre_VObject_Property('TEL', $_record->tel_fax); $tel->add('TYPE', 'FAX'); $card->add($tel); #$tel = new Sabre_VObject_Property('TEL', $_record->tel_fax_home); #$tel->add('TYPE', 'FAX'); #$tel->add('TYPE', 'HOME'); #$card->add($tel); $adr = new Sabre_VObject_Element_MultiValue('ADR', array(null, $_record->adr_one_street2, $_record->adr_one_street, $_record->adr_one_locality, $_record->adr_one_region, $_record->adr_one_postalcode, $_record->adr_one_countryname)); $adr->add('TYPE', 'WORK'); $card->add($adr); $adr = new Sabre_VObject_Element_MultiValue('ADR', array(null, $_record->adr_two_street2, $_record->adr_two_street, $_record->adr_two_locality, $_record->adr_two_region, $_record->adr_two_postalcode, $_record->adr_two_countryname)); $adr->add('TYPE', 'HOME'); $card->add($adr); $card->add(new Sabre_VObject_Property('EMAIL;TYPE=work', $_record->email)); $card->add(new Sabre_VObject_Property('EMAIL;TYPE=home', $_record->email_home)); $card->add(new Sabre_VObject_Property('URL;TYPE=work', $_record->url)); $card->add(new Sabre_VObject_Property('URL;TYPE=home', $_record->url_home)); $card->add(new Sabre_VObject_Property('NOTE', $_record->note)); if (!empty($_record->jpegphoto)) { try { $image = Tinebase_Controller::getInstance()->getImage('Addressbook', $_record->getId()); $jpegData = $image->getBlob('image/jpeg'); $photo = new Sabre_VObject_Property('PHOTO', $jpegData); $photo->add('ENCODING', 'b'); $photo->add('TYPE', 'JPEG'); $card->add($photo); } catch (Exception $e) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Image for contact {$_record->getId()} not found or invalid"); } } if (isset($_record->tags) && count($_record->tags) > 0) { $card->add(new Sabre_VObject_Property('CATEGORIES', Sabre_VObject_Element_List((array) $_record->tags->name))); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' card ' . $card->serialize()); } return $card; }
/** * @expectedException InvalidArgumentException */ function testAddArgFail3() { $property = new Sabre_VObject_Property('EMAIL', 'value'); $property->add('hello', array()); }
/** * Using the setter method you can add properties or subcomponents * * You can either pass a Sabre_VObject_Component, Sabre_VObject_Property * object, or a string to automatically create a Property. * * If the item already exists, it will be removed. If you want to add * a new item with the same name, always use the add() method. * * @param string $name * @param mixed $value * @return void */ public function __set($name, $value) { $matches = $this->select($name); $overWrite = count($matches) ? key($matches) : null; if ($value instanceof Sabre_VObject_Component || $value instanceof Sabre_VObject_Property) { $value->parent = $this; if (!is_null($overWrite)) { $this->children[$overWrite] = $value; } else { $this->children[] = $value; } } elseif (is_scalar($value)) { $property = Sabre_VObject_Property::create($name, $value); $property->parent = $this; if (!is_null($overWrite)) { $this->children[$overWrite] = $property; } else { $this->children[] = $property; } } else { throw new InvalidArgumentException('You must pass a Sabre_VObject_Component, Sabre_VObject_Property or scalar type'); } }
/** * Helper function to set an address in vObject */ protected function setVCardAddress($vCard, $addressType, &$contactProperties, $propertyPrefix) { $this->logger->trace("setVCardAddress - {$addressType}"); $p = $this->bridge->getExtendedProperties(); $address = array(); if (isset($contactProperties[$p[$propertyPrefix . "_address"]])) { $address[] = ''; // post office box $address[] = ''; // extended address $address[] = isset($contactProperties[$p[$propertyPrefix . '_address_street']]) ? $contactProperties[$p[$propertyPrefix . '_address_street']] : ''; $address[] = isset($contactProperties[$p[$propertyPrefix . '_address_city']]) ? $contactProperties[$p[$propertyPrefix . '_address_city']] : ''; $address[] = isset($contactProperties[$p[$propertyPrefix . '_address_state']]) ? $contactProperties[$p[$propertyPrefix . '_address_state']] : ''; $address[] = isset($contactProperties[$p[$propertyPrefix . '_address_postal_code']]) ? $contactProperties[$p[$propertyPrefix . '_address_postal_code']] : ''; $address[] = isset($contactProperties[$p[$propertyPrefix . '_address_country']]) ? $contactProperties[$p[$propertyPrefix . '_address_country']] : ''; } $address = implode(';', $address); if ($address != ';;;;;;') { $this->logger->trace("Not empty address - adding {$address}"); $element = new Sabre_VObject_Property('ADR'); $element->setValue($address); $element->offsetSet('TYPE', $addressType); $vCard->add($element); } }
protected function _addEventAttendee(Sabre_VObject_Component $_vevent, Calendar_Model_Event $_event) { Calendar_Model_Attender::resolveAttendee($_event->attendee, FALSE, $_event); foreach ($_event->attendee as $eventAttendee) { $attendeeEmail = $eventAttendee->getEmail(); $attendee = new Sabre_VObject_Property('ATTENDEE', (strpos($attendeeEmail, '@') !== false ? 'mailto:' : 'urn:uuid:') . $attendeeEmail); $attendee->add('CN', $eventAttendee->getName()); $attendee->add('CUTYPE', Calendar_Convert_Event_VCalendar_Abstract::$cutypeMap[$eventAttendee->user_type]); $attendee->add('PARTSTAT', $eventAttendee->status); $attendee->add('ROLE', "{$eventAttendee->role}-PARTICIPANT"); $attendee->add('RSVP', 'FALSE'); if (strpos($attendeeEmail, '@') !== false) { $attendee->add('EMAIL', $attendeeEmail); } $_vevent->add($attendee); } }
public function testGetIteratorDefault() { $property = new Sabre_VObject_Property('propname', 'propvalue'); $it = $property->getIterator(); $this->assertTrue($it instanceof Sabre_VObject_ElementList); $this->assertEquals(1, count($it)); }
/** * Returns free-busy information for a specific address. The returned * data is an array containing the following properties: * * calendar-data : A VFREEBUSY VObject * request-status : an iTip status code. * href: The principal's email address, as requested * * The following request status codes may be returned: * * 2.0;description * * 3.7;description * * @param string $email address * @param DateTime $start * @param DateTime $end * @param Sabre_VObject_Component $request * @return Sabre_VObject_Component */ protected function getFreeBusyForEmailTine20($email, DateTime $start, DateTime $end, Sabre_VObject_Component $request) { if (substr($email, 0, 7) === 'mailto:') { $email = substr($email, 7); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' serach freebusy of ' . $email); } // resolve email address to contact $filter = new Addressbook_Model_ContactFilter(array(array('field' => 'containerType', 'operator' => 'equals', 'value' => 'all'), array('field' => 'type', 'operator' => 'equals', 'value' => Addressbook_Model_Contact::CONTACTTYPE_USER), array('field' => 'email', 'operator' => 'equals', 'value' => $email))); $contact = Addressbook_Controller_Contact::getInstance()->search($filter)->getFirstRecord(); if ($contact === null) { return array('request-status' => '3.7;Could not find principal', 'href' => 'mailto:' . $email); } $period = array(array('from' => new Tinebase_DateTime($start->format(Tinebase_Record_Abstract::ISO8601LONG), 'UTC'), 'until' => new Tinebase_DateTime($end->format(Tinebase_Record_Abstract::ISO8601LONG), 'UTC'))); $attendees = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(new Calendar_Model_Attender(array('user_id' => $contact->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_USER)))); $freeBusyInfo = Calendar_Controller_Event::getInstance()->getFreeBusyInfo($period, $attendees); $vcalendar = new Sabre_VObject_Component('VCALENDAR'); $vcalendar->VERSION = '2.0'; $vcalendar->METHOD = 'REPLY'; $vcalendar->CALSCALE = 'GREGORIAN'; $vcalendar->PRODID = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN'; $vfreebusy = new Sabre_VObject_Component('VFREEBUSY'); $vcalendar->add($vfreebusy); $vfreebusy->DTSTAMP = $request->VFREEBUSY->dtstart->value; $vfreebusy->DTSTART = $request->VFREEBUSY->dtstart->value; $vfreebusy->DTEND = $request->VFREEBUSY->dtend->value; #$attendee = new Sabre_VObject_Property('ATTENDEE', 'mailto:' . $contact->email); #$attendee->add('CN', $contact->n_fileas); #$vfreebusy->add($attendee); foreach ($freeBusyInfo as $busyInfo) { $busy = $busyInfo->dtstart->format('Ymd\\THis\\Z') . '/' . $busyInfo->dtend->format('Ymd\\THis\\Z'); $freebusy = new Sabre_VObject_Property('FREEBUSY', $busy); $freebusy->add('FBTYPE', 'BUSY'); $vfreebusy->add($freebusy); } $vcalendar->VFREEBUSY->ATTENDEE = 'mailto:' . $email; $vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID; return array('calendar-data' => $vcalendar, 'request-status' => '2.0;Success', 'href' => 'mailto:' . $email); }
/** * Reads and parses a single line. * * This method receives the full array of lines. The array pointer is used * to traverse. * * @param array $lines * @return Sabre_VObject_Element */ private static function readLine(&$lines) { $line = current($lines); $lineNr = key($lines); next($lines); // Components if (stripos($line, "BEGIN:") === 0) { $componentName = strtoupper(substr($line, 6)); $obj = Sabre_VObject_Component::create($componentName); $nextLine = current($lines); while (stripos($nextLine, "END:") !== 0) { $obj->add(self::readLine($lines)); $nextLine = current($lines); if ($nextLine === false) { throw new Sabre_VObject_ParseException('Invalid VObject. Document ended prematurely.'); } } // Checking component name of the 'END:' line. if (substr($nextLine, 4) !== $obj->name) { throw new Sabre_VObject_ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"'); } next($lines); return $obj; } // Properties //$result = preg_match('/(?P<name>[A-Z0-9-]+)(?:;(?P<parameters>^(?<!:):))(.*)$/',$line,$matches); $token = '[A-Z0-9-\\.]+'; $parameters = "(?:;(?P<parameters>([^:^\"]|\"([^\"]*)\")*))?"; $regex = "/^(?P<name>{$token}){$parameters}:(?P<value>.*)\$/i"; $result = preg_match($regex, $line, $matches); if (!$result) { throw new Sabre_VObject_ParseException('Invalid VObject, line ' . ($lineNr + 1) . ' did not follow the icalendar/vcard format'); } $propertyName = strtoupper($matches['name']); $propertyValue = preg_replace_callback('#(\\\\(\\\\|N|n|;|,))#', function ($matches) { if ($matches[2] === 'n' || $matches[2] === 'N') { return "\n"; } else { return $matches[2]; } }, $matches['value']); $obj = Sabre_VObject_Property::create($propertyName, $propertyValue); if ($matches['parameters']) { foreach (self::readParameters($matches['parameters']) as $param) { $obj->add($param); } } return $obj; }