Exemplo n.º 1
0
    /**
     * This method should return a list of default property values.
     *
     * @return array
     */
    protected function getDefaults() {

        return array(
            'UID'     => 'sabre-vobject-' . VObject\UUIDUtil::getUUID(),
            'DTSTAMP' => date('Ymd\\THis\\Z'),
        );

    }
Exemplo n.º 2
0
 public static function createVCalendarFromRequest($request)
 {
     $vcalendar = new \Sabre\VObject\Component\VCalendar();
     $vcalendar->PRODID = 'ownCloud Calendar';
     $vcalendar->VERSION = '2.0';
     $vtodo = $vcalendar->createComponent('VTODO');
     $vcalendar->add($vtodo);
     $vtodo->CREATED = new \DateTime('now', new \DateTimeZone('UTC'));
     $vtodo->UID = \Sabre\VObject\UUIDUtil::getUUID();
     return self::updateVCalendarFromRequest($request, $vcalendar);
 }
Exemplo n.º 3
0
	/**
	 * @param int $iUserId
	 * @param \Sabre\VObject\Component\VCard $oVCardObject
	 */
	public function InitFromVCardObject($iUserId, $oVCardObject)
	{
		if ($oVCardObject)
		{
			$sUid = (isset($oVCardObject->UID)) ? (string)$oVCardObject->UID . '.vcf' : \Sabre\VObject\UUIDUtil::getUUID() . '.vcf';
			
			$this->IdUser = $iUserId;
			$this->UseFriendlyName = true;
			$this->IdContact = $sUid;
			$this->IdContactStr = $this->IdContact;

			$aResultGroupsIds = $this->GroupsIds;
			if (isset($oVCardObject->CATEGORIES))
			{
				$aGroupsIds = $oVCardObject->CATEGORIES->getParts();
				foreach($aGroupsIds as $sGroupsId)
				{
					if (!empty($sGroupsId))
					{
						$aResultGroupsIds[] = (string) $sGroupsId;
					}
				}
			}
			$this->GroupsIds = $aResultGroupsIds;

			if (isset($oVCardObject->FN))
			{
				$this->FullName = (string)$oVCardObject->FN;
			}

			if (isset($oVCardObject->N))
			{
				$aNames = $oVCardObject->N->getParts();

				if (!empty($aNames[0]))
				{
					$this->LastName = $aNames[0];
				}
				if (!empty($aNames[1]))
				{
					$this->FirstName = $aNames[1];
				}
				if (!empty($aNames[3]))
				{
					$this->Title = $aNames[3];
				}
			}

			if (isset($oVCardObject->NICKNAME))
			{
				$this->NickName = (string) $oVCardObject->NICKNAME;
			}

			if (isset($oVCardObject->NOTE))
			{
				$this->Notes = (string) $oVCardObject->NOTE;
			}

			if (isset($oVCardObject->BDAY))
			{
				$aDateTime = explode('T', (string)$oVCardObject->BDAY);
				if (isset($aDateTime[0]))
				{
					$aDate = explode('-', $aDateTime[0]);
					$this->BirthdayYear = $aDate[0];
					$this->BirthdayMonth = $aDate[1];
					$this->BirthdayDay = $aDate[2];
				}
			}

			if (isset($oVCardObject->ORG))
			{
				$aOrgs = $oVCardObject->ORG->getParts();
				if (!empty($aOrgs[0]))
				{
					$this->BusinessCompany = $aOrgs[0];
				}
				if (!empty($aOrgs[1]))
				{
					$this->BusinessDepartment = $aOrgs[1];
				}
			}

			if (isset($oVCardObject->TITLE))
			{
				$this->BusinessJobTitle = (string)$oVCardObject->TITLE;
			}

			if (isset($oVCardObject->ADR))
			{
				foreach($oVCardObject->ADR as $oAdr)
				{
					$aAdrs = $oAdr->getParts();
					if ($oTypes = $oAdr['TYPE'])
					{
						if ($oTypes->has('WORK'))
						{
							$this->BusinessStreet = isset($aAdrs[2]) ? $aAdrs[2] : '';
							$this->BusinessCity = isset($aAdrs[3]) ? $aAdrs[3] : '';
							$this->BusinessState = isset($aAdrs[4]) ? $aAdrs[4] : '';
							$this->BusinessZip = isset($aAdrs[5]) ? $aAdrs[5] : '';
							$this->BusinessCountry = isset($aAdrs[6]) ? $aAdrs[6] : '';
						}
						if ($oTypes->has('HOME'))
						{
							$this->HomeStreet = isset($aAdrs[2]) ? $aAdrs[2] : '';
							$this->HomeCity = isset($aAdrs[3]) ? $aAdrs[3] : '';
							$this->HomeState = isset($aAdrs[4]) ? $aAdrs[4] : '';
							$this->HomeZip = isset($aAdrs[5]) ? $aAdrs[5] : '';
							$this->HomeCountry = isset($aAdrs[6]) ? $aAdrs[6] : '';
						}
					}
				}
			}

			if (isset($oVCardObject->EMAIL))
			{
				$bHasOtherEmail = false;
				foreach($oVCardObject->EMAIL as $oEmail)
				{
					if ($oType = $oEmail['TYPE'])
					{
						if ($oType->has('WORK'))
						{
							$this->BusinessEmail = (string)$oEmail;
							if ($oType->has('PREF'))
							{
								$this->PrimaryEmail = EPrimaryEmailType::Business;
							}
						}
						else if ($oType->has('HOME'))
						{
							$this->HomeEmail = (string)$oEmail;
							if ($oType->has('PREF'))
							{
								$this->PrimaryEmail = EPrimaryEmailType::Home;
							}
						}
						else if (!$bHasOtherEmail)
						{
							if (isset($oVCardObject->{'X-ABLabel'}))
							{
								$aABLabels = $oVCardObject->{'X-ABLabel'};
								foreach ($aABLabels as $oABLabel)
								{
									if ($oEmail->group == $oABLabel->group && (string)$oABLabel == '_$!<Other>!$_')
									{
										$bHasOtherEmail = true;
										break;
									}
								}
							}
							else
							{
								$bHasOtherEmail = true;
							}
							
							$this->OtherEmail = (string)$oEmail;
							if ($oType->has('PREF'))
							{
								$this->PrimaryEmail = EPrimaryEmailType::Other;
							}
						}
					}
				}
				if (empty($this->PrimaryEmail))
				{
					if (!empty($this->HomeEmail))
					{
						$this->PrimaryEmail = EPrimaryEmailType::Home;
					}
					else if (!empty($this->BusinessEmail))
					{
						$this->PrimaryEmail = EPrimaryEmailType::Business;
					}
					else if (!empty($this->OtherEmail))
					{
						$this->PrimaryEmail = EPrimaryEmailType::Other;
					}
				}
			}

			if (isset($oVCardObject->URL))
			{
				foreach($oVCardObject->URL as $oUrl)
				{
					if ($oTypes = $oUrl['TYPE'])
					{
						if ($oTypes->has('HOME'))
						{
							$this->HomeWeb = (string)$oUrl;
						}
						else if ($oTypes->has('WORK'))
						{
							$this->BusinessWeb = (string)$oUrl;
						}
					}
				}
			}

			if (isset($oVCardObject->TEL))
			{
				foreach($oVCardObject->TEL as $oTel)
				{
					if ($oTypes = $oTel['TYPE'])
					{
						if ($oTypes->has('FAX'))
						{
							if ($oTypes->has('HOME'))
							{
								$this->HomeFax = (string)$oTel;
							}
							if ($oTypes->has('WORK'))
							{
								$this->BusinessFax = (string)$oTel;
							}
						}
						else
						{
							if ($oTypes->has('CELL'))
							{
								$this->HomeMobile = (string)$oTel;
							}
							else if ($oTypes->has('HOME'))
							{
								$this->HomePhone = (string)$oTel;
							}
							else if ($oTypes->has('WORK'))
							{
								$this->BusinessPhone = (string)$oTel;
							}
						}
					}
				}
			}

			if (isset($oVCardObject->{'X-AFTERLOGIC-OFFICE'}))
			{
				$this->BusinessOffice = (string)$oVCardObject->{'X-AFTERLOGIC-OFFICE'};
			}

			if (isset($oVCardObject->{'X-AFTERLOGIC-USE-FRIENDLY-NAME'}))
			{
				$this->UseFriendlyName = '1' === (string)$oVCardObject->{'X-AFTERLOGIC-USE-FRIENDLY-NAME'};
			}
		}
	}
Exemplo n.º 4
0
 /**
  * Validates the node for correctness.
  *
  * The following options are supported:
  *   Node::REPAIR - May attempt to automatically repair the problem.
  *
  * This method returns an array with detected problems.
  * Every element has the following properties:
  *
  *  * level - problem level.
  *  * message - A human-readable string describing the issue.
  *  * node - A reference to the problematic node.
  *
  * The level means:
  *   1 - The issue was repaired (only happens if REPAIR was turned on)
  *   2 - An inconsequential issue
  *   3 - A severe issue.
  *
  * @param int $options
  * @return array
  */
 function validate($options = 0)
 {
     $warnings = array();
     $versionMap = array(self::VCARD21 => '2.1', self::VCARD30 => '3.0', self::VCARD40 => '4.0');
     $version = $this->select('VERSION');
     if (count($version) === 1) {
         $version = (string) $this->VERSION;
         if ($version !== '2.1' && $version !== '3.0' && $version !== '4.0') {
             $warnings[] = array('level' => 3, 'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.', 'node' => $this);
             if ($options & self::REPAIR) {
                 $this->VERSION = $versionMap[self::DEFAULT_VERSION];
             }
         }
         if ($version === '2.1' && $options & self::PROFILE_CARDDAV) {
             $warnings[] = array('level' => 3, 'message' => 'CardDAV servers are not allowed to accept vCard 2.1.', 'node' => $this);
         }
     }
     $uid = $this->select('UID');
     if (count($uid) === 0) {
         if ($options & self::PROFILE_CARDDAV) {
             // Required for CardDAV
             $warningLevel = 3;
             $message = 'vCards on CardDAV servers MUST have a UID property.';
         } else {
             // Not required for regular vcards
             $warningLevel = 2;
             $message = 'Adding a UID to a vCard property is recommended.';
         }
         if ($options & self::REPAIR) {
             $this->UID = VObject\UUIDUtil::getUUID();
             $warningLevel = 1;
         }
         $warnings[] = array('level' => $warningLevel, 'message' => $message, 'node' => $this);
     }
     $fn = $this->select('FN');
     if (count($fn) !== 1) {
         $repaired = false;
         if ($options & self::REPAIR && count($fn) === 0) {
             // We're going to try to see if we can use the contents of the
             // N property.
             if (isset($this->N)) {
                 $value = explode(';', (string) $this->N);
                 if (isset($value[1]) && $value[1]) {
                     $this->FN = $value[1] . ' ' . $value[0];
                 } else {
                     $this->FN = $value[0];
                 }
                 $repaired = true;
                 // Otherwise, the ORG property may work
             } elseif (isset($this->ORG)) {
                 $this->FN = (string) $this->ORG;
                 $repaired = true;
             }
         }
         $warnings[] = array('level' => $repaired ? 1 : 3, 'message' => 'The FN property must appear in the VCARD component exactly 1 time', 'node' => $this);
     }
     return array_merge(parent::validate($options), $warnings);
 }
Exemplo n.º 5
0
 /**
  * @return string
  */
 public static function generateUID()
 {
     return UUIDUtil::getUUID();
 }
Exemplo n.º 6
0
 /**
  * getUid is only there for testing, use createUid instead
  */
 protected function getUid()
 {
     return UUIDUtil::getUUID();
 }
Exemplo n.º 7
0
 /**
  * @return string
  */
 public static function generateUID()
 {
     $uuid = UUIDUtil::getUUID();
     return $uuid . '@' . \OCP\Util::getServerHostName();
 }
Exemplo n.º 8
0
 public function CreateLink($oAccount, $sType, $sPath, $sLink, $sName)
 {
     $iLinkType = \api_Utils::GetLinkType($sLink);
     if ($this->Init($oAccount)) {
         $oDirectory = $this->getDirectory($oAccount, $sType, $sPath);
         if ($oDirectory !== null) {
             $sFileName = \Sabre\VObject\UUIDUtil::getUUID();
             $oDirectory->createFile($sFileName);
             $oItem = $oDirectory->getChild($sFileName);
             $oItem->updateProperties(array('Owner' => $oAccount->Email, 'Name' => $sName, 'Link' => $sLink, 'LinkType' => $iLinkType));
             return true;
         }
     }
     return false;
 }
Exemplo n.º 9
0
 /**
  * This method should return a list of default property values.
  *
  * @return array
  */
 protected function getDefaults()
 {
     return ['VERSION' => '4.0', 'PRODID' => '-//Sabre//Sabre VObject ' . VObject\Version::VERSION . '//EN', 'UID' => 'sabre-vobject-' . VObject\UUIDUtil::getUUID()];
 }
Exemplo n.º 10
0
 /**
  * @brief Adds an object
  * @param integer $id Calendar id
  * @param string $data  object
  * @return insertid
  */
 public static function add($id, $data)
 {
     $calendar = OC_Calendar_Calendar::find($id);
     if ($calendar['userid'] != OCP\User::getUser()) {
         $sharedCalendar = OCP\Share::getItemSharedWithBySource('calendar', $id);
         if (!$sharedCalendar || !($sharedCalendar['permissions'] & OCP\PERMISSION_CREATE)) {
             throw new Exception(OC_Calendar_App::$l10n->t('You do not have the permissions to add events to this calendar.'));
         }
     }
     $object = Sabre\VObject\Reader::read($data);
     list($type, $startdate, $enddate, $summary, $repeating, $uid) = self::extractData($object);
     if (is_null($uid)) {
         $uid = \Sabre\VObject\UUIDUtil::getUUID();
         $object->UID = $uid;
         $data = $object->serialize();
     }
     $uri = 'owncloud-' . md5($data . rand() . time()) . '.ics';
     $stmt = OCP\DB::prepare('INSERT INTO `*PREFIX*clndr_objects` (`calendarid`,`objecttype`,`startdate`,`enddate`,`repeating`,`summary`,`calendardata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?,?,?,?,?)');
     $stmt->execute(array($id, $type, $startdate, $enddate, $repeating, $summary, $data, $uri, time()));
     $object_id = OCP\DB::insertid('*PREFIX*clndr_objects');
     OC_Calendar_App::loadCategoriesFromVCalendar($object_id, $object);
     self::addAlarmsDBFromData($object->VEVENT, $object_id);
     OC_Calendar_Calendar::touchCalendar($id);
     OCP\Util::emitHook('OC_Calendar', 'addEvent', $object_id);
     return $object_id;
 }