php Sabre-VObject-Component类(方法)实例源码

下面列出了php Sabre-VObject-Component 类(方法)源码代码实例,从而了解它的用法。

作者:GTAWWEKI    项目:tsiserver.u   
/**
  * Sends one or more iTip messages through email.
  *
  * @param string $originator Originator Email
  * @param array $recipients Array of email addresses
  * @param VObject\Component $vObject
  * @param string $principal Principal Url of the originator
  * @return void
  */
 public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal)
 {
     foreach ($recipients as $recipient) {
         $to = $recipient;
         $replyTo = $originator;
         $subject = 'SabreDAV iTIP message';
         switch (strtoupper($vObject->METHOD)) {
             case 'REPLY':
                 $subject = 'Response for: ' . $vObject->VEVENT->SUMMARY;
                 break;
             case 'REQUEST':
                 $subject = 'Invitation for: ' . $vObject->VEVENT->SUMMARY;
                 break;
             case 'CANCEL':
                 $subject = 'Cancelled event: ' . $vObject->VEVENT->SUMMARY;
                 break;
         }
         $headers = array();
         $headers[] = 'Reply-To: ' . $replyTo;
         $headers[] = 'From: ' . $this->senderEmail;
         $headers[] = 'Content-Type: text/calendar; method=' . (string) $vObject->method . '; charset=utf-8';
         if (DAV\Server::$exposeVersion) {
             $headers[] = 'X-Sabre-Version: ' . DAV\Version::VERSION . '-' . DAV\Version::STABILITY;
         }
         $vcalBody = $vObject->serialize();
         $this->mail($to, $subject, $vcalBody, $headers);
     }
 }

作者:Theodi    项目:theodia.or   
private function getValueOrEmpty(\Sabre\VObject\Component $component, $property)
 {
     $value = $component->__get($property);
     if ($value) {
         return $value->getValue();
     } else {
         return '';
     }
 }

作者:TamirA    项目:hubzill   
/**
  * Constructor
  *
  * The splitter should receive an readable file stream as it's input.
  *
  * @param resource $input
  */
 public function __construct($input)
 {
     $data = VObject\Reader::read(stream_get_contents($input));
     $vtimezones = array();
     $components = array();
     foreach ($data->children as $component) {
         if (!$component instanceof VObject\Component) {
             continue;
         }
         // Get all timezones
         if ($component->name === 'VTIMEZONE') {
             $this->vtimezones[(string) $component->TZID] = $component;
             continue;
         }
         // Get component UID for recurring Events search
         if ($component->UID) {
             $uid = (string) $component->UID;
         } else {
             // Generating a random UID
             $uid = sha1(microtime()) . '-vobjectimport';
         }
         // Take care of recurring events
         if (!array_key_exists($uid, $this->objects)) {
             $this->objects[$uid] = VObject\Component::create('VCALENDAR');
         }
         $this->objects[$uid]->add(clone $component);
     }
 }

作者:ZerGabrie    项目:friendica-addon   
/**
  * Different bug, also likely an infinite loop.
  */
 function testYearlyByMonthLoop()
 {
     $ev = Component::create('VEVENT');
     $ev->UID = 'uuid';
     $ev->DTSTART = '20120101T154500';
     $ev->DTSTART['TZID'] = 'Europe/Berlin';
     $ev->RRULE = 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA';
     $ev->DTEND = '20120101T164500';
     $ev->DTEND['TZID'] = 'Europe/Berlin';
     // This recurrence rule by itself is a yearly rule that should happen
     // every february.
     //
     // The BYDAY part expands this to every day of the month, but the
     // BYSETPOS limits this to only the 1st day of the month. Very crazy
     // way to specify this, and could have certainly been a lot easier.
     $cal = Component::create('VCALENDAR');
     $cal->add($ev);
     $it = new RecurrenceIterator($cal, 'uuid');
     $it->fastForward(new DateTime('2012-01-29 23:00:00', new DateTimeZone('UTC')));
     $collect = array();
     while ($it->valid()) {
         $collect[] = $it->getDTSTART();
         if ($it->getDTSTART() > new DateTime('2013-02-05 22:59:59', new DateTimeZone('UTC'))) {
             break;
         }
         $it->next();
     }
     $this->assertEquals(array(new DateTime('2012-02-01 15:45:00', new DateTimeZone('Europe/Berlin'))), $collect);
 }

作者:ddolbi    项目:sabre-vobjec   
/**
  * Serializes a xCal or xCard object.
  *
  * @param Component $component
  *
  * @return string
  */
 static function writeXml(Component $component)
 {
     $writer = new Xml\Writer();
     $writer->openMemory();
     $writer->setIndent(true);
     $writer->startDocument('1.0', 'utf-8');
     if ($component instanceof Component\VCalendar) {
         $writer->startElement('icalendar');
         $writer->writeAttribute('xmlns', Parser\Xml::XCAL_NAMESPACE);
     } else {
         $writer->startElement('vcards');
         $writer->writeAttribute('xmlns', Parser\Xml::XCARD_NAMESPACE);
     }
     $component->xmlSerialize($writer);
     $writer->endElement();
     return $writer->outputMemory();
 }

作者:floffel0    项目:pydio-cor   
/**
  * Something, somewhere produced an ics with an interval set to 0. Because
  * this means we increase the current day (or week, month) by 0, this also
  * results in an infinite loop.
  *
  * @expectedException InvalidArgumentException
  * @return void
  */
 function testZeroInterval()
 {
     $ev = Component::create('VEVENT');
     $ev->UID = 'uuid';
     $ev->DTSTART = '20120824T145700Z';
     $ev->RRULE = 'FREQ=YEARLY;INTERVAL=0';
     $cal = Component::create('VCALENDAR');
     $cal->add($ev);
     $it = new RecurrenceIterator($cal, 'uuid');
     $it->fastForward(new DateTime('2013-01-01 23:00:00', new DateTimeZone('UTC')));
     // if we got this far.. it means we are no longer infinitely looping
 }

作者:ZerGabrie    项目:friendica-addon   
function testAlarmWayBefore()
 {
     $vevent = VObject\Component::create('VEVENT');
     $vevent->DTSTART = '20120101T120000Z';
     $vevent->UID = 'bla';
     $valarm = VObject\Component::create('VALARM');
     $valarm->TRIGGER = '-P2W1D';
     $vevent->add($valarm);
     $vcalendar = VObject\Component::create('VCALENDAR');
     $vcalendar->add($vevent);
     $filter = array('name' => 'VCALENDAR', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VEVENT', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VALARM', 'is-not-defined' => false, 'prop-filters' => array(), 'comp-filters' => array(), 'time-range' => array('start' => new DateTime('2011-12-10'), 'end' => new DateTime('2011-12-20')))))));
     $validator = new Sabre_CalDAV_CalendarQueryValidator();
     $this->assertTrue($validator->validate($vcalendar, $filter));
 }

作者:ZerGabrie    项目:friendica-addon   
/**
  * Merges all calendar objects, and builds one big ics export
  *
  * @param array $nodes
  * @return string
  */
 public function generateICS(array $nodes)
 {
     $calendar = new VObject\Component('vcalendar');
     $calendar->version = '2.0';
     if (Sabre_DAV_Server::$exposeVersion) {
         $calendar->prodid = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN';
     } else {
         $calendar->prodid = '-//SabreDAV//SabreDAV//EN';
     }
     $calendar->calscale = 'GREGORIAN';
     $collectedTimezones = array();
     $timezones = array();
     $objects = array();
     foreach ($nodes as $node) {
         if (!isset($node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'])) {
             continue;
         }
         $nodeData = $node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'];
         $nodeComp = VObject\Reader::read($nodeData);
         foreach ($nodeComp->children() as $child) {
             switch ($child->name) {
                 case 'VEVENT':
                 case 'VTODO':
                 case 'VJOURNAL':
                     $objects[] = $child;
                     break;
                     // VTIMEZONE is special, because we need to filter out the duplicates
                 // VTIMEZONE is special, because we need to filter out the duplicates
                 case 'VTIMEZONE':
                     // Naively just checking tzid.
                     if (in_array((string) $child->TZID, $collectedTimezones)) {
                         continue;
                     }
                     $timezones[] = $child;
                     $collectedTimezones[] = $child->TZID;
                     break;
             }
         }
     }
     foreach ($timezones as $tz) {
         $calendar->add($tz);
     }
     foreach ($objects as $obj) {
         $calendar->add($obj);
     }
     return $calendar->serialize();
 }

作者:floffel0    项目:pydio-cor   
public function timeRangeTestData()
 {
     $tests = array();
     $vjournal = Component::create('VJOURNAL');
     $vjournal->DTSTART = '20111223T120000Z';
     $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vjournal, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vjournal2 = Component::create('VJOURNAL');
     $vjournal2->DTSTART = '20111223';
     $vjournal2->DTSTART['VALUE'] = 'DATE';
     $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vjournal2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vjournal3 = Component::create('VJOURNAL');
     $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), false);
     $tests[] = array($vjournal3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     return $tests;
 }

作者:WYSA    项目:oregon-ownclou   
/**
  * @brief transform a ldap entry into an VCard object
  *	for each ldap entry which is like "property: value"
  *	to a VCard entry which is like "PROPERTY[;PARAMETER=param]:value"
  * @param array $ldap_entry
  * @return OC_VCard
  */
 public function ldapToVCard($ldapEntry)
 {
     $vcard = \Sabre\VObject\Component::create('VCARD');
     $vcard->REV = $this->convertDate($ldapEntry['modifytimestamp'][0])->format(\DateTime::W3C);
     //error_log("modifytimestamp: ".$vcard->REV);
     $vcard->{'X-LDAP-DN'} = base64_encode($ldapEntry['dn']);
     // OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' vcard is '.$vcard->serialize(), \OCP\Util::DEBUG);
     for ($i = 0; $i < $ldapEntry["count"]; $i++) {
         // ldap property name : $ldap_entry[$i]
         $lProperty = $ldapEntry[$i];
         for ($j = 0; $j < $ldapEntry[$lProperty]["count"]; $j++) {
             // What to do :
             // convert the ldap property into vcard property, type and position (if needed)
             // $v_params format: array('property' => property, 'type' => array(types), 'position' => position)
             $v_params = $this->getVCardProperty($lProperty);
             foreach ($v_params as $v_param) {
                 if (isset($v_param['unassigned'])) {
                     // if the value comes from the unassigned entry, it's a vcard property dumped
                     try {
                         $property = \Sabre\VObject\Reader::read($ldapEntry[$lProperty][$j]);
                         $vcard->add($property);
                     } catch (exception $e) {
                     }
                 } else {
                     // Checks if a same kind of property already exists in the VCard (property and parameters)
                     // if so, sets a property variable with the current data
                     // else, creates a property variable
                     $v_property = $this->getOrCreateVCardProperty($vcard, $v_param, $j);
                     // modify the property with the new data
                     if (strcasecmp($v_param['image'], 'true') == 0) {
                         $this->updateVCardImageProperty($v_property, $ldapEntry[$lProperty][$j], $vcard->VERSION);
                     } else {
                         $this->updateVCardProperty($v_property, $ldapEntry[$lProperty][$j], $v_param['position']);
                     }
                 }
             }
         }
     }
     if (!isset($vcard->UID)) {
         $vcard->UID = base64_encode($ldapEntry['dn']);
     }
     return $vcard;
 }

作者:tchern    项目:LabD   
/**
  * Create online calendar for user
  *
  * @Route("/{username}.ics")
  *
  * @param  string                                    $username User to create the calendar for
  * @return Symfony\Component\HttpFoundation\Response
  */
 public function calendarAction($username)
 {
     $user = $this->get('user_provider')->loadUserByUsername($username);
     $om = $this->getObjectManager('VIB\\FliesBundle\\Entity\\Vial');
     $calendar = VObject\Component::create('VCALENDAR');
     $calendar->VERSION = '2.0';
     $field = 'X-WR-CALNAME';
     $calendar->{$field} = $user->getShortName() . '\'s flywork';
     $stockDates = $om->getRepository('VIB\\FliesBundle\\Entity\\StockVial')->getFlipDates($user);
     foreach ($stockDates as $stockDate) {
         $event = VObject\Component::create('VEVENT');
         $calendar->add($event);
         $event->SUMMARY = 'Transfer stocks';
         $dtstart = VObject\Property::create('DTSTART');
         $dtstart->setDateTime($stockDate, VObject\Property\DateTime::DATE);
         $event->DTSTART = $dtstart;
         $alarm = VObject\Component::create('VALARM');
         $event->add($alarm);
         $alarm->TRIGGER = 'PT8H';
         $alarm->ACTION = 'DISPLAY';
     }
     $crossDates = $om->getRepository('VIB\\FliesBundle\\Entity\\CrossVial')->getFlipDates($user);
     foreach ($crossDates as $crossDate) {
         $crossDates[] = $crossDate;
         $event = VObject\Component::create('VEVENT');
         $calendar->add($event);
         $event->SUMMARY = 'Check crosses';
         $dtstart = VObject\Property::create('DTSTART');
         $dtstart->setDateTime($crossDate, VObject\Property\DateTime::DATE);
         $event->DTSTART = $dtstart;
         $alarm = VObject\Component::create('VALARM');
         $event->add($alarm);
         $alarm->TRIGGER = 'PT8H';
         $alarm->ACTION = 'DISPLAY';
     }
     return new Response($calendar->serialize(), 200, array('Content-Type' => 'text/calendar; charset=utf-8', 'Content-Disposition' => 'inline; filename="calendar.ics"'));
 }

作者:rbrdev    项目:pydio-cor   
public function timeRangeTestData()
 {
     $tests = array();
     $vtodo = Component::create('VTODO');
     $vtodo->DTSTART = '20111223T120000Z';
     $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo2 = clone $vtodo;
     $vtodo2->DURATION = 'P1D';
     $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo3 = clone $vtodo;
     $vtodo3->DUE = '20111225';
     $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo4 = Component::create('VTODO');
     $vtodo4->DUE = '20111225';
     $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo5 = Component::create('VTODO');
     $vtodo5->COMPLETED = '20111225';
     $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo6 = Component::create('VTODO');
     $vtodo6->CREATED = '20111225';
     $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo7 = Component::create('VTODO');
     $vtodo7->CREATED = '20111225';
     $vtodo7->COMPLETED = '20111226';
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
     $vtodo7 = Component::create('VTODO');
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
     $tests[] = array($vtodo7, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), true);
     return $tests;
 }

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * add photo data to VCard
  * 
  * @param  Addressbook_Model_Contact $record
  * @param  \Sabre\VObject\Component  $card
  */
 protected function _fromTine20ModelAddPhoto(Addressbook_Model_Contact $record, \Sabre\VObject\Component $card)
 {
     if (!empty($record->jpegphoto)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__);
         try {
             $jpegData = $record->getSmallContactImage($this->_maxPhotoSize);
             $card->add('PHOTO', $jpegData, array('TYPE' => 'JPEG', 'ENCODING' => 'b'));
         } catch (Exception $e) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . " Image for contact {$record->getId()} not found or invalid: {$e->getMessage()}");
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());
             }
         }
     }
 }

作者:pombredann    项目:ArcherSy   
/**
	 * @brief converts a ldif into a owncloud VCard
	 * @param $element the VCard element to convert
	 * @return VCard
	 */
	public function convertElementToVCard($element) {
		$dest = \Sabre\VObject\Component::create('VCARD');
		
		foreach ($element as $ldifProperty) {
			$importEntry = $this->getImportEntry($ldifProperty[0]);
			if ($importEntry) {
				$value = $ldifProperty[1];
				if (isset($importEntry['remove'])) {
					$value = str_replace($importEntry['remove'], '', $ldifProperty[1]);
				}
				$values = array($value);
				if (isset($importEntry['separator'])) {
					$values = explode($importEntry['separator'], $value);
				}
				
				foreach ($values as $oneValue) {
					$this->convertElementToProperty($oneValue, $importEntry, $dest);
				}
			} else {
				$property = \Sabre\VObject\Property::create("X-Unknown-Element", ''.StringUtil::convertToUTF8($ldifProperty[1]));
				$property->parameters[] = new \Sabre\VObject\Parameter('TYPE', ''.StringUtil::convertToUTF8($ldifProperty[0]));
				$dest->add($property);
			}
		}
		
		$dest->validate(\Sabre\VObject\Component\VCard::REPAIR);
		return $dest;
	}

作者:noble8    项目:proyectos-UL   
/**
  * 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 VObject\Component $request
  * @return array
  */
 protected function getFreeBusyForEmail($email, \DateTime $start, \DateTime $end, VObject\Component $request)
 {
     $caldavNS = '{' . Plugin::NS_CALDAV . '}';
     $aclPlugin = $this->server->getPlugin('acl');
     if (substr($email, 0, 7) === 'mailto:') {
         $email = substr($email, 7);
     }
     $result = $aclPlugin->principalSearch(array('{http://sabredav.org/ns}email-address' => $email), array('{DAV:}principal-URL', $caldavNS . 'calendar-home-set', '{http://sabredav.org/ns}email-address'));
     if (!count($result)) {
         return array('request-status' => '3.7;Could not find principal', 'href' => 'mailto:' . $email);
     }
     if (!isset($result[0][200][$caldavNS . 'calendar-home-set'])) {
         return array('request-status' => '3.7;No calendar-home-set property found', 'href' => 'mailto:' . $email);
     }
     $homeSet = $result[0][200][$caldavNS . 'calendar-home-set']->getHref();
     // Grabbing the calendar list
     $objects = array();
     foreach ($this->server->tree->getNodeForPath($homeSet)->getChildren() as $node) {
         if (!$node instanceof ICalendar) {
             continue;
         }
         $aclPlugin->checkPrivileges($homeSet . $node->getName(), $caldavNS . 'read-free-busy');
         // Getting the list of object uris within the time-range
         $urls = $node->calendarQuery(array('name' => 'VCALENDAR', 'comp-filters' => array(array('name' => 'VEVENT', 'comp-filters' => array(), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => array('start' => $start, 'end' => $end))), 'prop-filters' => array(), 'is-not-defined' => false, 'time-range' => null));
         $calObjects = array_map(function ($url) use($node) {
             $obj = $node->getChild($url)->get();
             return $obj;
         }, $urls);
         $objects = array_merge($objects, $calObjects);
     }
     $vcalendar = VObject\Component::create('VCALENDAR');
     $vcalendar->VERSION = '2.0';
     $vcalendar->METHOD = 'REPLY';
     $vcalendar->CALSCALE = 'GREGORIAN';
     $vcalendar->PRODID = '-//SabreDAV//SabreDAV ' . DAV\Version::VERSION . '//EN';
     $generator = new VObject\FreeBusyGenerator();
     $generator->setObjects($objects);
     $generator->setTimeRange($start, $end);
     $generator->setBaseObject($vcalendar);
     $result = $generator->getResult();
     $vcalendar->VFREEBUSY->ATTENDEE = 'mailto:' . $email;
     $vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID;
     $vcalendar->VFREEBUSY->ORGANIZER = clone $request->VFREEBUSY->ORGANIZER;
     return array('calendar-data' => $result, 'request-status' => '2.0;Success', 'href' => 'mailto:' . $email);
 }

作者:netcon-sourc    项目:app   
public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     Addressbook::find($aid);
     foreach (VCard::all($aid) as $contact) {
         try {
             $vcard = VObject\Reader::read($contact['carddata']);
         } catch (Exception $e) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new \DateTime($birthday);
             $vevent = VObject\Component::create('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->add('DTSTART');
             $vevent->DTSTART->setDateTime($date, VObject\Property\DateTime::DATE);
             $vevent->add('DURATION', 'P1D');
             $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
             // DESCRIPTION?
             $vevent->{'RRULE'} = 'FREQ=YEARLY';
             $title = str_replace('{name}', $vcard->FN, App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . \OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }

作者:pombredann    项目:ArcherSy   
/**
	 * @brief converts a VCard into a owncloud VCard
	 * @param $element the VCard element to convert
	 * @return VCard|false
	 */
	public function convertElementToVCard($element) {
		try {
			$source = VObject\Reader::read($element, VObject\Reader::OPTION_FORGIVING);
		} catch (VObject\ParseException $error) {
			return false;
		}
		$dest = \Sabre\VObject\Component::create('VCARD');
		
		foreach ($source->children() as $sourceProperty) {
			$importEntry = $this->getImportEntry($sourceProperty, $source);
			if ($importEntry) {
				$value = $sourceProperty->value;
				if (isset($importEntry['remove'])) {
					$value = str_replace($importEntry['remove'], '', $sourceProperty->value);
				}
				$values = array($value);
				if (isset($importEntry['separator'])) {
					$values = explode($importEntry['separator'], $value);
				}
				
				foreach ($values as $oneValue) {
					if (isset($importEntry->vcard_favourites)) {
						foreach ($importEntry->vcard_favourites as $vcardFavourite) {
							if (strcasecmp((string)$vcardFavourite, trim($oneValue)) == 0) {
								$property = \Sabre\VObject\Property::create("X-FAVOURITES", 'yes');
								$dest->add($property);
							} else {
								$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
								$this->updateProperty($property, $importEntry, trim($oneValue));
							}
						}
					} else {
						$property = $this->getOrCreateVCardProperty($dest, $importEntry->vcard_entry);
						$this->updateProperty($property, $importEntry, $sourceProperty->value);
					}
				}
			} else {
				$property = clone $sourceProperty;
				$dest->add($property);
			}
		}
		
		$dest->validate(\Sabre\VObject\Component\VCard::REPAIR);
		return $dest;
	}

作者:claudineyq    项目:Kolab-Roundcube-Libcalendarin   
/**
  * Returns a VTIMEZONE component for a Olson timezone identifier
  * with daylight transitions covering the given date range.
  *
  * @param string Timezone ID as used in PHP's Date functions
  * @param integer Unix timestamp with first date/time in this timezone
  * @param integer Unix timestap with last date/time in this timezone
  *
  * @return mixed A Sabre\VObject\Component object representing a VTIMEZONE definition
  *               or false if no timezone information is available
  */
 public static function get_vtimezone($tzid, $from = 0, $to = 0)
 {
     if (!$from) {
         $from = time();
     }
     if (!$to) {
         $to = $from;
     }
     if (is_string($tzid)) {
         try {
             $tz = new \DateTimeZone($tzid);
         } catch (\Exception $e) {
             return false;
         }
     } else {
         if (is_a($tzid, '\\DateTimeZone')) {
             $tz = $tzid;
         }
     }
     if (!is_a($tz, '\\DateTimeZone')) {
         return false;
     }
     $year = 86400 * 360;
     $transitions = $tz->getTransitions($from - $year, $to + $year);
     $vt = new VObject\Component('VTIMEZONE');
     $vt->TZID = $tz->getName();
     $std = null;
     $dst = null;
     foreach ($transitions as $i => $trans) {
         $cmp = null;
         if ($i == 0) {
             $tzfrom = $trans['offset'] / 3600;
             continue;
         }
         if ($trans['isdst']) {
             $t_dst = $trans['ts'];
             $dst = new VObject\Component('DAYLIGHT');
             $cmp = $dst;
         } else {
             $t_std = $trans['ts'];
             $std = new VObject\Component('STANDARD');
             $cmp = $std;
         }
         if ($cmp) {
             $dt = new DateTime($trans['time']);
             $offset = $trans['offset'] / 3600;
             $cmp->DTSTART = $dt->format('Ymd\\THis');
             $cmp->TZOFFSETFROM = sprintf('%s%02d%02d', $tzfrom >= 0 ? '+' : '', floor($tzfrom), ($tzfrom - floor($tzfrom)) * 60);
             $cmp->TZOFFSETTO = sprintf('%s%02d%02d', $offset >= 0 ? '+' : '', floor($offset), ($offset - floor($offset)) * 60);
             if (!empty($trans['abbr'])) {
                 $cmp->TZNAME = $trans['abbr'];
             }
             $tzfrom = $offset;
             $vt->add($cmp);
         }
         // we covered the entire date range
         if ($std && $dst && min($t_std, $t_dst) < $from && max($t_std, $t_dst) > $to) {
             break;
         }
     }
     // add X-MICROSOFT-CDO-TZID if available
     $microsoftExchangeMap = array_flip(VObject\TimeZoneUtil::$microsoftExchangeMap);
     if (array_key_exists($tz->getName(), $microsoftExchangeMap)) {
         $vt->add('X-MICROSOFT-CDO-TZID', $microsoftExchangeMap[$tz->getName()]);
     }
     return $vt;
 }

作者:mirabilo    项目:sabre-vobjec   
/**
  * Repairs a VObject file
  *
  * @param Component $vObj
  * @return int
  */
 protected function repair($vObj)
 {
     $returnCode = 0;
     switch ($vObj->name) {
         case 'VCALENDAR':
             $this->log("iCalendar: " . (string) $vObj->VERSION);
             break;
         case 'VCARD':
             $this->log("vCard: " . (string) $vObj->VERSION);
             break;
     }
     $warnings = $vObj->validate(Node::REPAIR);
     if (!count($warnings)) {
         $this->log("  No warnings!");
     } else {
         $levels = [1 => 'REPAIRED', 2 => 'WARNING', 3 => 'ERROR'];
         $returnCode = 2;
         foreach ($warnings as $warn) {
             $extra = '';
             if ($warn['node'] instanceof Property) {
                 $extra = ' (property: "' . $warn['node']->name . '")';
             }
             $this->log("  [" . $levels[$warn['level']] . '] ' . $warn['message'] . $extra);
         }
     }
     fwrite($this->stdout, $vObj->serialize());
     return $returnCode;
 }

作者:linagor    项目:sabre-vobjec   
protected function serializeComponent(Component $vObj)
 {
     $this->cWrite('cyan', 'BEGIN');
     $this->cWrite('red', ':');
     $this->cWrite('yellow', $vObj->name . "\n");
     /**
      * Gives a component a 'score' for sorting purposes.
      *
      * This is solely used by the childrenSort method.
      *
      * A higher score means the item will be lower in the list.
      * To avoid score collisions, each "score category" has a reasonable
      * space to accomodate elements. The $key is added to the $score to
      * preserve the original relative order of elements.
      *
      * @param int $key
      * @param array $array
      *
      * @return int
      */
     $sortScore = function ($key, $array) {
         if ($array[$key] instanceof Component) {
             // We want to encode VTIMEZONE first, this is a personal
             // preference.
             if ($array[$key]->name === 'VTIMEZONE') {
                 $score = 300000000;
                 return $score + $key;
             } else {
                 $score = 400000000;
                 return $score + $key;
             }
         } else {
             // Properties get encoded first
             // VCARD version 4.0 wants the VERSION property to appear first
             if ($array[$key] instanceof Property) {
                 if ($array[$key]->name === 'VERSION') {
                     $score = 100000000;
                     return $score + $key;
                 } else {
                     // All other properties
                     $score = 200000000;
                     return $score + $key;
                 }
             }
         }
     };
     $children = $vObj->children();
     $tmp = $children;
     uksort($children, function ($a, $b) use($sortScore, $tmp) {
         $sA = $sortScore($a, $tmp);
         $sB = $sortScore($b, $tmp);
         return $sA - $sB;
     });
     foreach ($children as $child) {
         if ($child instanceof Component) {
             $this->serializeComponent($child);
         } else {
             $this->serializeProperty($child);
         }
     }
     $this->cWrite('cyan', 'END');
     $this->cWrite('red', ':');
     $this->cWrite('yellow', $vObj->name . "\n");
 }


问题


面经


文章

微信
公众号

扫码关注公众号