本文整理汇总了PHP中Sabre\VObject\Property类的典型用法代码示例。如果您正苦于以下问题:PHP Property类的具体用法?PHP Property怎么用?PHP Property使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Property类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _toTine20ModelParseTel
/**
* (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);
}
示例2: _toTine20ModelParseEmail
/**
* (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();
}
}
示例3: testGroupProperty
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);
}
示例4: _toTine20ModelParseTel
/**
* (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);
}
}
示例5: _toTine20ModelParseEmail
/**
* (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;
}
}
示例6: calendarAction
/**
* 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"'));
}
示例7: validate
/**
* 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;
}
示例8: _convertToTinebaseDateTime
/**
* 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;
}
示例9: _to_ical
/**
* 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
//.........这里部分代码省略.........
示例10: structureProperty
/**
* @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;
}
示例11: getOrCreateVCardProperty
/**
* @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;
}
}
示例12: substr
$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();
示例13: fixPropertyParameters
/**
* 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);
}
}
}
示例14: createOrUpdate
/**
* @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;
}
示例15: setXmlValue
/**
* Hydrate data from a XML subtree, as it would appear in a xCard or xCal
* object.
*
* @param array $value
*
* @return void
*/
function setXmlValue(array $value)
{
$value = array_map(function ($value) {
return 'true' === $value;
}, $value);
parent::setXmlValue($value);
}