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

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

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * (non-PHPdoc)
  * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseTel()
  */
 protected function _toTine20ModelParseTel(&$data, \Sabre\VObject\Property $property)
 {
     if (!isset($property['TYPE'])) {
         // CardDAVSync sends OTHER just as TEL:12345678 without any TYPE
         $data['tel_other'] = $property->getValue();
     }
     parent::_toTine20ModelParseTel($data, $property);
 }

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * (non-PHPdoc)
  * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseEmail()
  */
 protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard)
 {
     if ($vcard->{'X-OUTLOOK-EMAIL-2'} && $vcard->{'X-OUTLOOK-EMAIL-2'}->getValue() == $property->getValue()) {
         $data['email_home'] = $property->getValue();
     } elseif ($vcard->{'X-OUTLOOK-EMAIL-3'} && $vcard->{'X-OUTLOOK-EMAIL-3'}->getValue() == $property->getValue()) {
         // we don't map email3
     } else {
         $data['email'] = $property->getValue();
     }
 }

作者:omusic    项目:isle-web-framewor   
public function testGroupProperty()
 {
     $arr = array('Home', 'work', 'Friends, Family');
     $property = \Sabre\VObject\Property::create('CATEGORIES');
     $property->setParts($arr);
     // Test parsing and serializing
     $this->assertEquals('Home,work,Friends\\, Family', $property->value);
     $this->assertEquals('CATEGORIES:Home,work,Friends\\, Family' . "\r\n", $property->serialize());
     $this->assertEquals(3, count($property->getParts()));
     // Test add
     $property->addGroup('Coworkers');
     $this->assertTrue($property->hasGroup('coworkers'));
     $this->assertEquals(4, count($property->getParts()));
     $this->assertEquals('Home,work,Friends\\, Family,Coworkers', $property->value);
     // Test remove
     $this->assertTrue($property->hasGroup('Friends, fAmIlY'));
     $property->removeGroup('Friends, fAmIlY');
     $this->assertEquals(3, count($property->getParts()));
     $parts = $property->getParts();
     $this->assertEquals('Coworkers', $parts[2]);
     // Test rename
     $property->renameGroup('work', 'Work');
     $parts = $property->getParts();
     $this->assertEquals('Work', $parts[1]);
     //$this->assertEquals(true, false);
 }

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * (non-PHPdoc)
  * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseTel()
  */
 protected function _toTine20ModelParseTel(&$data, \Sabre\VObject\Property $property)
 {
     $telField = null;
     if (isset($property['TYPE'])) {
         // CELL
         if ($property['TYPE']->has('cell') && $property['TYPE']->has('voice') && !$property['TYPE']->has('iphone')) {
             $telField = 'tel_cell';
         } elseif ($property['TYPE']->has('cell') && $property['TYPE']->has('iphone')) {
             $telField = 'tel_cell_private';
         }
     }
     if (!empty($telField)) {
         $data[$telField] = $property->getValue();
     } else {
         parent::_toTine20ModelParseTel($data, $property);
     }
 }

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * (non-PHPdoc)
  * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseEmail()
  */
 protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard)
 {
     $type = null;
     if ($property['TYPE']) {
         if ($property['TYPE']->has('pref')) {
             $type = 'work';
         }
     }
     switch ($type) {
         case 'work':
             $data['email'] = $property->getValue();
             break;
         default:
             $data['email_home'] = $property->getValue();
             break;
     }
 }

作者: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"'));
 }

作者:pkdevbox    项目:webmail-lit   
/**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   - Node::REPAIR - If something is broken, and automatic repair may
  *                    be attempted.
  *
  * An array is returned with warnings.
  *
  * Every item in the array has the following properties:
  *    * level - (number between 1 and 3 with severity information)
  *    * message - (human readable message)
  *    * node - (reference to the offending node)
  *
  * @param int $options
  * @return array
  */
 public function validate($options = 0)
 {
     $warnings = parent::validate($options);
     if (isset($this->minimumPropertyValues[$this->name])) {
         $minimum = $this->minimumPropertyValues[$this->name];
         $parts = $this->getParts();
         if (count($parts) < $minimum) {
             $warnings[] = array('level' => 1, 'message' => 'This property must have at least ' . $minimum . ' components. It only has ' . count($parts), 'node' => $this);
             if ($options & self::REPAIR) {
                 $parts = array_pad($parts, $minimum, '');
                 $this->setParts($parts);
             }
         }
     }
     return $warnings;
 }

作者:bitExper    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * get datetime from sabredav datetime property (user TZ is fallback)
  * 
  * @param  Sabre\VObject\Property  $dateTimeProperty
  * @param  boolean                 $_useUserTZ
  * @return Tinebase_DateTime
  * 
  * @todo try to guess some common timezones
  */
 protected function _convertToTinebaseDateTime(\Sabre\VObject\Property $dateTimeProperty, $_useUserTZ = FALSE)
 {
     $defaultTimezone = date_default_timezone_get();
     date_default_timezone_set((string) Tinebase_Core::getUserTimezone());
     if ($dateTimeProperty instanceof Sabre\VObject\Property\ICalendar\DateTime) {
         $dateTime = $dateTimeProperty->getDateTime();
         $tz = $_useUserTZ || isset($dateTimeProperty['VALUE']) && strtoupper($dateTimeProperty['VALUE']) == 'DATE' ? (string) Tinebase_Core::getUserTimezone() : $dateTime->getTimezone();
         $result = new Tinebase_DateTime($dateTime->format(Tinebase_Record_Abstract::ISO8601LONG), $tz);
     } else {
         $result = new Tinebase_DateTime($dateTimeProperty->getValue());
     }
     date_default_timezone_set($defaultTimezone);
     return $result;
 }

作者:claudineyq    项目:Kolab-Roundcube-Libcalendarin   
/**
  * Build a valid iCal format block from the given event
  *
  * @param  array    Hash array with event/task properties from libkolab
  * @param  object   VCalendar object to append event to or false for directly sending data to stdout
  * @param  callable Callback function to fetch attachment contents, false if no attachment export
  * @param  object   RECURRENCE-ID property when serializing a recurrence exception
  */
 private function _to_ical($event, $vcal, $get_attachment, $recurrence_id = null)
 {
     $type = $event['_type'] ?: 'event';
     $ve = VObject\Component::create($this->type_component_map[$type]);
     $ve->add('UID', $event['uid']);
     // set DTSTAMP according to RFC 5545, 3.8.7.2.
     $dtstamp = !empty($event['changed']) && !empty($this->method) ? $event['changed'] : new DateTime();
     $ve->add($this->datetime_prop('DTSTAMP', $dtstamp, true));
     // all-day events end the next day
     if ($event['allday'] && !empty($event['end'])) {
         $event['end'] = clone $event['end'];
         $event['end']->add(new \DateInterval('P1D'));
         $event['end']->_dateonly = true;
     }
     if (!empty($event['created'])) {
         $ve->add($this->datetime_prop('CREATED', $event['created'], true));
     }
     if (!empty($event['changed'])) {
         $ve->add($this->datetime_prop('LAST-MODIFIED', $event['changed'], true));
     }
     if (!empty($event['start'])) {
         $ve->add($this->datetime_prop('DTSTART', $event['start'], false, (bool) $event['allday']));
     }
     if (!empty($event['end'])) {
         $ve->add($this->datetime_prop('DTEND', $event['end'], false, (bool) $event['allday']));
     }
     if (!empty($event['due'])) {
         $ve->add($this->datetime_prop('DUE', $event['due'], false));
     }
     // we're exporting a recurrence instance only
     if (!$recurrence_id && $event['recurrence_date'] && $event['recurrence_date'] instanceof DateTime) {
         $recurrence_id = $this->datetime_prop('RECURRENCE-ID', $event['recurrence_date'], false, (bool) $event['allday']);
         if ($event['thisandfuture']) {
             $recurrence_id->add('RANGE', 'THISANDFUTURE');
         }
     }
     if ($recurrence_id) {
         $ve->add($recurrence_id);
     }
     $ve->add('SUMMARY', $event['title']);
     if ($event['location']) {
         $ve->add($this->is_apple() ? new vobject_location_property('LOCATION', $event['location']) : new VObject\Property('LOCATION', $event['location']));
     }
     if ($event['description']) {
         $ve->add('DESCRIPTION', strtr($event['description'], array("\r\n" => "\n", "\r" => "\n")));
     }
     // normalize line endings
     if (isset($event['sequence'])) {
         $ve->add('SEQUENCE', $event['sequence']);
     }
     if ($event['recurrence'] && !$recurrence_id) {
         $exdates = $rdates = null;
         if (isset($event['recurrence']['EXDATE'])) {
             $exdates = $event['recurrence']['EXDATE'];
             unset($event['recurrence']['EXDATE']);
             // don't serialize EXDATEs into RRULE value
         }
         if (isset($event['recurrence']['RDATE'])) {
             $rdates = $event['recurrence']['RDATE'];
             unset($event['recurrence']['RDATE']);
             // don't serialize RDATEs into RRULE value
         }
         if ($event['recurrence']['FREQ']) {
             $ve->add('RRULE', libcalendaring::to_rrule($event['recurrence'], (bool) $event['allday']));
         }
         // add EXDATEs each one per line (for Thunderbird Lightning)
         if (is_array($exdates)) {
             foreach ($exdates as $ex) {
                 if ($ex instanceof \DateTime) {
                     $exd = clone $event['start'];
                     $exd->setDate($ex->format('Y'), $ex->format('n'), $ex->format('j'));
                     $exd->setTimeZone(new \DateTimeZone('UTC'));
                     $ve->add(new VObject\Property('EXDATE', $exd->format('Ymd\\THis\\Z')));
                 }
             }
         }
         // add RDATEs
         if (is_array($rdates) && !empty($rdates)) {
             $sample = $this->datetime_prop('RDATE', $rdates[0]);
             $rdprop = new VObject\Property\MultiDateTime('RDATE', null);
             $rdprop->setDateTimes($rdates, $sample->getDateType());
             $ve->add($rdprop);
         }
     }
     if ($event['categories']) {
         $cat = VObject\Property::create('CATEGORIES');
         $cat->setParts((array) $event['categories']);
         $ve->add($cat);
     }
     if (!empty($event['free_busy'])) {
         $ve->add('TRANSP', $event['free_busy'] == 'free' ? 'TRANSPARENT' : 'OPAQUE');
         // for Outlook clients we provide the X-MICROSOFT-CDO-BUSYSTATUS property
//.........这里部分代码省略.........

作者:ViTon    项目:contactsplu   
/**
  * @brief Data structure of properties
  * @param object $property
  * @return associative array
  *
  * returns an associative array with
  * ['name'] name of property
  * ['value'] htmlspecialchars escaped value of property
  * ['parameters'] associative array name=>value
  * ['checksum'] checksum of whole property
  * NOTE: $value is not escaped anymore. It shouldn't make any difference
  * but we should look out for any problems.
  */
 public static function structureProperty(\Sabre\VObject\Property $property)
 {
     if (!in_array($property->name, App::$index_properties)) {
         return;
     }
     $value = $property->getValue();
     if ($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') {
         $value = $property->getParts();
         if ($property->name == 'CATEGORIES') {
             $value = str_replace(';', ',', $value);
         }
         if ($property->name == 'N') {
             //$value = stripslashes($value);
             //	\OCP\Util::writeLog('contactsplus','NAME VAL: '.$value, \OCP\Util::DEBUG);
         }
         $value = array_map('trim', $value);
     } elseif ($property->name == 'BDAY') {
         if (strlen($value) >= 8 && is_int(substr($value, 0, 4)) && is_int(substr($value, 4, 2)) && is_int(substr($value, 6, 2))) {
             $value = substr($value, 0, 4) . '-' . substr($value, 4, 2) . '-' . substr($value, 6, 2);
         } else {
             if ($value[5] !== '-' || $value[7] !== '-') {
                 try {
                     // Skype exports as e.g. Jan 14, 1996
                     $date = new \DateTime($value);
                     $value = $date->format('Y-m-d');
                 } catch (\Exception $e) {
                     \OCP\Util::writeLog('contactsplus', __METHOD__ . ' Error parsing date: ' . $value, \OCP\Util::DEBUG);
                     return;
                 }
             }
         }
     } elseif ($property->name == 'PHOTO') {
         $value = true;
     } elseif ($property->name == 'IMPP') {
         if (strpos($value, ':') !== false) {
             $value = explode(':', $value);
             $protocol = array_shift($value);
             if (!isset($property['X-SERVICE-TYPE'])) {
                 $property['X-SERVICE-TYPE'] = strtoupper($protocol);
             }
             $value = implode('', $value);
         }
     }
     if (is_string($value)) {
         $value = strtr($value, array('\\,' => ',', '\\;' => ';'));
     }
     $temp = array('value' => $value, 'parameters' => array());
     // This cuts around a 3rd off of the json response size.
     if (in_array($property->name, App::$multi_properties)) {
         $temp['checksum'] = substr(md5($property->serialize()), 0, 8);
     }
     foreach ($property->parameters as $parameter) {
         // Faulty entries by kaddressbook
         // Actually TYPE=PREF is correct according to RFC 2426
         // but this way is more handy in the UI. Tanghus.
         if ($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') {
             $parameter->name = 'PREF';
             $parameter->setValue('1');
         }
         // NOTE: Apparently Sabre_VObject_Reader can't always deal with value list parameters
         // like TYPE=HOME,CELL,VOICE. Tanghus.
         // TODO: Check if parameter is has commas and split + merge if so.
         if ($parameter->name == 'TYPE') {
             $pvalue = $parameter->getValue();
             if (is_string($pvalue) && strpos($pvalue, ',') !== false) {
                 $pvalue = array_map('trim', explode(',', $pvalue));
             }
             $pvalue = is_array($pvalue) ? $pvalue : array($pvalue);
             if (isset($temp['parameters'][$parameter->name])) {
                 $temp['parameters'][$parameter->name][] = \OCP\Util::sanitizeHTML($pvalue);
             } else {
                 $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($pvalue);
             }
         } else {
             //$value = strtr($value, array('\,' => ',', '\;' => ';'));
             $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->getValue());
         }
     }
     return $temp;
 }

作者:CDN-Spark    项目:ownclou   
/**
  * @brief returns the vcard property corresponding to the parameter
  * creates the property if it doesn't exists yet
  * @param $vcard the vcard to get or create the properties with
  * @param $importEntry the parameter to find
  * @return the property|false
  */
 protected function getOrCreateVCardProperty(&$vcard, $importEntry)
 {
     if (isset($vcard) && isset($importEntry)) {
         // looking for a property with the same name
         $properties = $vcard->select($importEntry['property']);
         foreach ($properties as $property) {
             if ($importEntry['type'] == null && !isset($importEntry->additional_property)) {
                 return $property;
             }
             foreach ($property->parameters as $parameter) {
                 // Filtering types
                 if ($parameter->name == 'TYPE' && !strcmp($parameter->value, $importEntry['type'])) {
                     $found = 0;
                     if (isset($importEntry->additional_property)) {
                         // Filtering additional properties if necessary (I know, there are a lot of inner loops, sorry)
                         foreach ($importEntry->additional_property as $additional_property) {
                             if ((string) $parameter->name == $additional_property['name']) {
                                 $found++;
                             }
                         }
                         if ($found == count($importEntry->additional_property)) {
                             return $property;
                         }
                     }
                     return $property;
                 }
             }
             if (isset($importEntry['group']) && $property->group == $importEntry['group']) {
                 return $property;
             }
         }
         // Property not found, creating one
         $property = \Sabre\VObject\Property::create($importEntry['property']);
         $vcard->add($property);
         if ($importEntry['type'] != null) {
             $property->parameters[] = new \Sabre\VObject\Parameter('TYPE', '' . StringUtil::convertToUTF8($importEntry['type']));
             switch ($importEntry['property']) {
                 case "ADR":
                     $property->setValue(";;;;;;");
                     break;
                 case "FN":
                     $property->setValue(";;;;");
                     break;
             }
         }
         if ($importEntry['group'] != null) {
             $property->group = $importEntry['group'];
         }
         return $property;
     } else {
         return false;
     }
 }

作者:netcon-sourc    项目:app   
$vcard->add($property);
        $checksum = substr(md5($property->serialize()), 0, 8);
        try {
            VCard::edit($id, $vcard);
        } catch (Exception $e) {
            bailOut($e->getMessage());
        }
        \OCP\JSON::success(array('data' => array('checksum' => $checksum, 'oldchecksum' => $_POST['checksum'])));
        exit;
    }
} else {
    $element = $name;
    $property = $vcard->select($name);
    debug('propertylist: ' . get_class($property));
    if (count($property) === 0) {
        $property = VObject\Property::create($name);
        $vcard->add($property);
    } else {
        $property = array_shift($property);
    }
}
/* preprocessing value */
switch ($element) {
    case 'BDAY':
        $date = new \DateTime($value);
        $value = $date->format('Y-m-d');
        break;
    case 'FN':
        if (!$value) {
            // create a method thats returns an alternative for FN.
            //$value = getOtherValue();

作者:ChrisPH    项目:contact   
/**
  * 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) {
         if (strpos($parameter->getValue(), ',') === false) {
             continue;
         }
         $values = explode(',', $parameter->getValue());
         $values = array_map('trim', $values);
         $parameter->setValue(array_shift($values));
         foreach ($values as $value) {
             $property->add($parameter->name, $value);
         }
     }
 }

作者:droite    项目:openwrt-on-androi   
/**
  * @param $properties
  * @return mixed
  */
 public function createOrUpdate($properties)
 {
     $id = null;
     /**
      * @var \OCA\Contacts\VObject\VCard
      */
     $vcard = null;
     if (array_key_exists('id', $properties)) {
         // TODO: test if $id belongs to this addressbook
         $id = $properties['id'];
         // TODO: Test $vcard
         $vcard = $this->addressBook->getChild($properties['id']);
         foreach (array_keys($properties) as $name) {
             if (isset($vcard->{$name})) {
                 unset($vcard->{$name});
             }
         }
     } else {
         $vcard = \Sabre\VObject\Component::create('VCARD');
         $uid = substr(md5(rand() . time()), 0, 10);
         $vcard->add('UID', $uid);
         try {
             $id = $this->addressBook->addChild($vcard);
         } catch (\Exception $e) {
             \OCP\Util::writeLog('contacts', __METHOD__ . ' ' . $e->getMessage(), \OCP\Util::ERROR);
             return false;
         }
     }
     foreach ($properties as $name => $value) {
         switch ($name) {
             case 'ADR':
             case 'N':
                 if (is_array($value)) {
                     $property = \Sabre\VObject\Property::create($name);
                     $property->setParts($value);
                     $vcard->add($property);
                 } else {
                     $vcard->{$name} = $value;
                 }
                 break;
             case 'BDAY':
                 // TODO: try/catch
                 $date = new \DateTime($value);
                 $vcard->BDAY = $date->format('Y-m-d');
                 $vcard->BDAY->VALUE = 'DATE';
                 break;
             case 'EMAIL':
             case 'TEL':
             case 'IMPP':
                 // NOTE: We don't know if it's GTalk, Jabber etc. only the protocol
             // NOTE: We don't know if it's GTalk, Jabber etc. only the protocol
             case 'URL':
                 if (is_array($value)) {
                     foreach ($value as $val) {
                         $vcard->add($name, strip_tags($val));
                     }
                 } else {
                     $vcard->add($name, strip_tags($value));
                 }
             default:
                 $vcard->{$name} = $value;
                 break;
         }
     }
     try {
         VCard::edit($id, $vcard);
     } catch (\Exception $e) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ' ' . $e->getMessage(), \OCP\Util::ERROR);
         return false;
     }
     $asarray = VCard::structureContact($vcard);
     $asarray['id'] = $id;
     return $asarray;
 }

作者: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;
	}

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * parse birthday
  * 
  * @param array $data
  * @param Sabre\VObject\Property $property
  */
 protected function _toTine20ModelParseBday(&$_data, \Sabre\VObject\Property $_property)
 {
     $tzone = new DateTimeZone(Tinebase_Core::getUserTimezone());
     $_data['bday'] = new Tinebase_DateTime($_property->getValue(), $tzone);
     $_data['bday']->setTimezone(new DateTimeZone('UTC'));
 }

作者:ingoratsdor    项目:Tine-2.0-Open-Source-Groupware-and-CR   
/**
  * (non-PHPdoc)
  * @see Addressbook_Convert_Contact_VCard_Abstract::_toTine20ModelParseEmail()
  */
 protected function _toTine20ModelParseEmail(&$data, \Sabre\VObject\Property $property, \Sabre\VObject\Component\VCard $vcard)
 {
     /*
      *  eM Client supports three types of mail
      */
     if ($property['TYPE']->has('home')) {
         $data['email_home'] = $property->getValue();
     } elseif ($property['TYPE']->has('work') && $data['email'] == '') {
         $data['email'] = $property->getValue();
     } elseif ($property['TYPE']->has('pref') || $data['email'] == '') {
         $data['email'] = $property->getValue();
     }
 }

作者:WYSA    项目:oregon-ownclou   
/**
  * @brief converts a unique element into a owncloud VCard
  * @param $element the element to convert
  * @return VCard, all unconverted elements are stored in X-Unknown-Element parameters
  */
 public function convertElementToVCard($element, $title = null)
 {
     $vcard = \Sabre\VObject\Component::create('VCARD');
     $nbElt = count($element);
     for ($i = 0; $i < $nbElt; $i++) {
         if ($element[$i] != '') {
             //$importEntry = false;
             // Look for the right import_entry
             if (isset($this->configContent->import_core->base_parsing)) {
                 if (strcasecmp((string) $this->configContent->import_core->base_parsing, 'position') == 0) {
                     $importEntry = $this->getImportEntryFromPosition((string) $i);
                 } else {
                     if (strcasecmp((string) $this->configContent->import_core->base_parsing, 'name') == 0 && isset($title[$i])) {
                         $importEntry = $this->getImportEntryFromName($title[$i]);
                     }
                 }
             }
             if ($importEntry) {
                 // Create a new property and attach it to the vcard
                 $value = $element[$i];
                 if (isset($importEntry['remove'])) {
                     $value = str_replace($importEntry['remove'], '', $element[$i]);
                 }
                 $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');
                                 $vcard->add($property);
                             } else {
                                 $property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry);
                                 $this->updateProperty($property, $importEntry, trim($oneValue));
                             }
                         }
                     } else {
                         $property = $this->getOrCreateVCardProperty($vcard, $importEntry->vcard_entry);
                         $this->updateProperty($property, $importEntry, trim($oneValue));
                     }
                 }
             } else {
                 if (isset($element[$i]) && isset($title[$i])) {
                     $property = \Sabre\VObject\Property::create("X-Unknown-Element", StringUtil::convertToUTF8($element[$i]));
                     $property->parameters[] = new \Sabre\VObject\Parameter('TYPE', '' . StringUtil::convertToUTF8($title[$i]));
                     $vcard->add($property);
                 }
             }
         }
     }
     $vcard->validate(\Sabre\VObject\Component\VCard::REPAIR);
     return $vcard;
 }

作者:mirabilo    项目:sabre-vobjec   
/**
  * Colorizes a property.
  *
  * @param Property $property
  * @return void
  */
 protected function serializeProperty(Property $property)
 {
     if ($property->group) {
         $this->cWrite('default', $property->group);
         $this->cWrite('red', '.');
     }
     $str = '';
     $this->cWrite('yellow', $property->name);
     foreach ($property->parameters as $param) {
         $this->cWrite('red', ';');
         $this->cWrite('blue', $param->serialize());
     }
     $this->cWrite('red', ':');
     if ($property instanceof Property\Binary) {
         $this->cWrite('default', 'embedded binary stripped. (' . strlen($property->getValue()) . ' bytes)');
     } else {
         $parts = $property->getParts();
         $first1 = true;
         // Looping through property values
         foreach ($parts as $part) {
             if ($first1) {
                 $first1 = false;
             } else {
                 $this->cWrite('red', $property->delimiter);
             }
             $first2 = true;
             // Looping through property sub-values
             foreach ((array) $part as $subPart) {
                 if ($first2) {
                     $first2 = false;
                 } else {
                     // The sub-value delimiter is always comma
                     $this->cWrite('red', ',');
                 }
                 $subPart = strtr($subPart, ['\\' => $this->colorize('purple', '\\\\', 'green'), ';' => $this->colorize('purple', '\\;', 'green'), ',' => $this->colorize('purple', '\\,', 'green'), "\n" => $this->colorize('purple', "\\n\n\t", 'green'), "\r" => ""]);
                 $this->cWrite('green', $subPart);
             }
         }
     }
     $this->cWrite("default", "\n");
 }

作者:omusic    项目:isle-web-framewor   
/**
  * @brief Get data structure of property.
  * @param \Sabre\VObject\Property $property
  * @return associative array
  *
  * returns an associative array with
  * ['name'] name of property
  * ['value'] htmlspecialchars escaped value of property
  * ['parameters'] associative array name=>value
  * ['checksum'] checksum of whole property
  * NOTE: $value is not escaped anymore. It shouldn't make any difference
  * but we should look out for any problems.
  */
 public static function serializeProperty(\Sabre\VObject\Property $property)
 {
     if (!in_array($property->name, Properties::$index_properties)) {
         return;
     }
     $value = $property->value;
     if ($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') {
         $value = $property->getParts();
         $value = array_map('trim', $value);
     } elseif ($property->name == 'BDAY') {
         if (strpos($value, '-') === false) {
             if (strlen($value) >= 8) {
                 $value = substr($value, 0, 4) . '-' . substr($value, 4, 2) . '-' . substr($value, 6, 2);
             } else {
                 return null;
                 // Badly malformed :-(
             }
         }
     } elseif ($property->name == 'PHOTO') {
         $value = true;
     } elseif ($property->name == 'IMPP') {
         if (strpos($value, ':') !== false) {
             $value = explode(':', $value);
             $protocol = array_shift($value);
             if (!isset($property['X-SERVICE-TYPE'])) {
                 $property['X-SERVICE-TYPE'] = strtoupper($protocol);
             }
             $value = implode('', $value);
         }
     }
     if (is_string($value)) {
         $value = strtr($value, array('\\,' => ',', '\\;' => ';'));
     }
     $temp = array('value' => $value, 'parameters' => array());
     // This cuts around a 3rd off of the json response size.
     if (in_array($property->name, Properties::$multi_properties)) {
         $temp['checksum'] = substr(md5($property->serialize()), 0, 8);
     }
     foreach ($property->parameters as $parameter) {
         // Faulty entries by kaddressbook
         // Actually TYPE=PREF is correct according to RFC 2426
         // but this way is more handy in the UI. Tanghus.
         if ($parameter->name == 'TYPE' && strtoupper($parameter->value) == 'PREF') {
             $parameter->name = 'PREF';
             $parameter->value = '1';
         }
         // NOTE: Apparently Sabre_VObject_Reader can't always deal with value list parameters
         // like TYPE=HOME,CELL,VOICE. Tanghus.
         // TODO: Check if parameter is has commas and split + merge if so.
         if ($parameter->name == 'TYPE') {
             $pvalue = $parameter->value;
             if (is_string($pvalue) && strpos($pvalue, ',') !== false) {
                 $pvalue = array_map('trim', explode(',', $pvalue));
             }
             $pvalue = is_array($pvalue) ? $pvalue : array($pvalue);
             if (isset($temp['parameters'][$parameter->name])) {
                 $temp['parameters'][$parameter->name][] = \OCP\Util::sanitizeHTML($pvalue);
             } else {
                 $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($pvalue);
             }
         } else {
             $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->value);
         }
     }
     return $temp;
 }


问题


面经


文章

微信
公众号

扫码关注公众号