/** * @param array $parameters * @return OC_OCS_Result */ public function getAppInfo($parameters) { $app = $parameters['appid']; $info = \OCP\App::getAppInfo($app); if (!is_null($info)) { return new OC_OCS_Result(OC_App::getAppInfo($app)); } else { return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found'); } }
/** * Generate an event to show in the calendar * * @return \Sabre\VObject\Component\VCalendar|null */ public function getBirthdayEvent() { if (!isset($this->BDAY)) { return; } $birthday = $this->BDAY; if ((string) $birthday) { $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday')); try { $date = new \DateTime($birthday); } catch (\Exception $e) { continue; } $vevent = \Sabre\VObject\Component::create('VEVENT'); $vevent->add('DTSTART'); $vevent->DTSTART->setDateTime($date, \Sabre\VObject\Property\DateTime::DATE); $vevent->add('DURATION', 'P1D'); $vevent->{'UID'} = $this->UID; $vevent->{'RRULE'} = 'FREQ=YEARLY'; $vevent->{'SUMMARY'} = $title; $vcal = \Sabre\VObject\Component::create('VCALENDAR'); $vcal->VERSION = '2.0'; $appinfo = \OCP\App::getAppInfo('contacts'); $appversion = \OCP\App::getAppVersion('contacts'); $vcal->PRODID = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $vcal->add($vevent); return $vcal; } }
<?php /** * ownCloud - gsync plugin * * @author Victor Dubiniuk * @copyright 2012-2013 Victor Dubiniuk victor.dubiniuk@gmail.com * * This file is licensed under the Affero General Public License version 3 or * later. */ namespace OCA_Gsync; App::initController(); \OCP\Util::addScript(App::APP_ID, 'settings'); $info = \OCP\App::getAppInfo(App::APP_ID); $tmpl = new \OCP\Template(App::APP_ID, 'settings'); $tmpl->assign(App::GOOGLE_CLIENT_ID, App::getClientId()); $tmpl->assign(App::GOOGLE_SECRET, App::getSecret()); $tmpl->assign(App::GOOGLE_REFRESH_TOKEN, App::getRefreshToken()); $tmpl->assign('gsync_redirect', App::getRedirectUri()); $tmpl->assign('app_version', @$info['version']); return $tmpl->fetchPage();
/** * @brief Adds a card * @param $aid integer Addressbook id * @param $card Sabre\VObject\Component vCard file * @param $uri string the uri of the card, default based on the UID * @param $isChecked boolean If the vCard should be checked for validity and version. * @return insertid on success or false. */ public static function add($aid, VObject\Component $card, $uri = null, $isChecked = false) { if (is_null($card)) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', No vCard supplied', \OCP\Util::ERROR); return null; } $addressbook = Addressbook::find($aid); if ($addressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to add contacts to this addressbook.')); } } if (!$isChecked) { //self::updateValuesFromAdd($aid, $card); } $card->{'VERSION'} = '3.0'; // Add product ID is missing. //$prodid = trim($card->getAsString('PRODID')); //if(!$prodid) { if (!isset($card->PRODID)) { $appinfo = \OCP\App::getAppInfo(App::$appname); $appversion = \OCP\App::getAppVersion(App::$appname); $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $card->add('PRODID', $prodid); } $sComponent = 'VCARD'; $fn = ''; $lastname = ''; $surename = ''; if (isset($card->N)) { $temp = explode(';', $card->N); if (!empty($temp[0])) { $lastname = $temp[0]; $surename = $temp[1]; } } $organization = ''; if (isset($card->ORG)) { $temp = explode(';', $card->ORG); $organization = $temp[0]; } $bCompany = isset($card->{'X-ABSHOWAS'}) ? 1 : 0; if ($bCompany && $organization !== '') { $card->FN = $organization; $fn = $organization; } else { if ($lastname !== '') { $card->FN = $surename . ' ' . $lastname; $fn = $surename . ' ' . $lastname; } } $bGroup = isset($card->CATEGORIES) ? 1 : 0; if ($bGroup) { $card->CATEGORIES = stripslashes($card->CATEGORIES); } $uid = $card->UID; if (!isset($card->UID)) { $uid = substr(md5(rand() . time()), 0, 10); $card->UID = $uid; } $uri = isset($uri) ? $uri : $uid . '.vcf'; $data = $card->serialize(); //\OCP\Util::writeLog(App::$appname,'XXXX: '.$fn, \OCP\Util::DEBUG); if (isset($card->{'X-ADDRESSBOOKSERVER-KIND'})) { $sComponent = 'GROUP'; } $stmt = \OCP\DB::prepare('INSERT INTO `' . App::ContactsTable . '` (`addressbookid`,`fullname`,`surename`,`lastname`,`carddata`,`uri`,`lastmodified`,`component`, `bcategory`,`organization`,`bcompany`) VALUES(?,?,?,?,?,?,?,?,?,?,?)'); try { $result = $stmt->execute(array($aid, $fn, $surename, $lastname, $data, $uri, time(), $sComponent, $bGroup, $organization, $bCompany)); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog(App::$appname, __METHOD__ . 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); \OCP\Util::writeLog(App::$appname, __METHOD__ . ', aid: ' . $aid . ' uri' . $uri, \OCP\Util::DEBUG); return false; } $newid = \OCP\DB::insertid(App::ContactsTable); App::loadCategoriesFromVCard($newid, $card); App::updateDBProperties($newid, $card); App::cacheThumbnail($newid); Addressbook::touch($aid); //Libasys if ($sComponent == 'GROUP') { //$newCardInfo=self::find($newid,array('fullname')); //$stmt = \OCP\DB::prepare('INSERT INTO `*PREFIX*vcategory` (`uid`,`type`,`category`,`color`) VALUES(?,?,?,?) '); //$stmt->execute(array(\OCP\User::getUser(),'contact',$newCardInfo['fullname'],'#cccccc')); } //\OC_Hook::emit('\OCA\Kontakts\VCard', 'post_createVCard', $newid); return $newid; }
/** * Creates a new contact * * In the Database and Shared backends contact be either a Contact object or a string * with carddata to be able to play seamlessly with the CardDAV backend. * If this method is called by the CardDAV backend, the carddata is already validated. * NOTE: It's assumed that this method is called either from the CardDAV backend, the * import script, or from the ownCloud web UI in which case either the uri parameter is * set, or the contact has a UID. If neither is set, it will fail. * * @param string $addressbookid * @param VCard|string $contact * @param array $options - Optional (backend specific options) * @return string|bool The identifier for the new contact or false on error. */ public function createContact($addressbookid, $contact, array $options = array()) { $qname = 'createcontact'; $uri = isset($options['uri']) ? $options['uri'] : null; if (!$contact instanceof VCard) { try { $contact = Reader::read($contact); } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } } try { $contact->validate(VCard::REPAIR | VCard::UPGRADE); } catch (\Exception $e) { OCP\Util::writeLog('contacts', __METHOD__ . ' ' . 'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } $uri = is_null($uri) ? $contact->UID . '.vcf' : $uri; $now = new \DateTime(); $contact->REV = $now->format(\DateTime::W3C); $appinfo = \OCP\App::getAppInfo('contacts'); $appversion = \OCP\App::getAppVersion('contacts'); $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $contact->PRODID = $prodid; $data = $contact->serialize(); if (!isset(self::$preparedQueries[$qname])) { self::$preparedQueries[$qname] = \OCP\DB::prepare('INSERT INTO `' . $this->cardsTableName . '` (`addressbookid`,`fullname`,`carddata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?)'); } try { $result = self::$preparedQueries[$qname]->execute(array($addressbookid, (string) $contact->FN, $contact->serialize(), $uri, time())); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } $newid = \OCP\DB::insertid($this->cardsTableName); $this->touchAddressBook($addressbookid); \OCP\Util::emitHook('OCA\\Contacts', 'post_createContact', array('id' => $newid, 'parent' => $addressbookid, 'contact' => $contact)); return (string) $newid; }
/** * Generate an event to show in the calendar * * @return \Sabre\VObject\Component\VCalendar|null */ public function getBirthdayEvent() { if (!isset($this->BDAY)) { return null; } $birthday = $this->BDAY; if ((string) $birthday) { $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday')); try { $date = new \DateTime($birthday); } catch (Exception $e) { return null; } $vCal = new \Sabre\VObject\Component\VCalendar(); $vCal->VERSION = '2.0'; $vEvent = $vCal->createComponent('VEVENT'); $vEvent->add('DTSTART'); $vEvent->DTSTART->setDateTime($date); $vEvent->DTSTART['VALUE'] = 'DATE'; $vEvent->add('DTEND'); $date->add(new \DateInterval('P1D')); $vEvent->DTEND->setDateTime($date); $vEvent->DTEND['VALUE'] = 'DATE'; $lm = new \DateTime('@' . $this->lastModified()); $lm->setTimeZone(new \DateTimeZone('UTC')); $vEvent->DTSTAMP->setDateTime($lm); $vEvent->{'UID'} = $this->UID; $vEvent->{'RRULE'} = 'FREQ=YEARLY'; $vEvent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')'; $vEvent->{'TRANSP'} = 'TRANSPARENT'; $alarm = $vCal->createComponent('VALARM'); $alarm->{'TRIGGER'} = '-PT0H'; $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION'])); $alarm->add($vCal->createProperty('DESCRIPTION', $title . ' (' . $date->format('Y') . ')')); $vEvent->add($alarm); $appInfo = \OCP\App::getAppInfo('contacts'); $appVersion = \OCP\App::getAppVersion('contacts'); $vCal->PRODID = '-//ownCloud//NONSGML ' . $appInfo['name'] . ' ' . $appVersion . '//EN'; $vCal->add($vEvent); return $vCal; } return null; }
public static function createVCardFromRequest($sRequest) { $uid = substr(md5(rand() . time()), 0, 10); $appinfo = \OCP\App::getAppInfo(self::$appname); $appversion = \OCP\App::getAppVersion(self::$appname); $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $vcard = new VObject\Component\VCard(array('PRODID' => $prodid, 'VERSION' => '3.0', 'UID' => $uid)); return self::updateVCardFromRequest($sRequest, $vcard); }
/** * Creates a new contact * * In the Database and Shared backends contact be either a Contact object or a string * with carddata to be able to play seamlessly with the CardDAV backend. * If this method is called by the CardDAV backend, the carddata is already validated. * NOTE: It's assumed that this method is called either from the CardDAV backend, the * import script, or from the ownCloud web UI in which case either the uri parameter is * set, or the contact has a UID. If neither is set, it will fail. * * @param string $addressBookId * @param VCard|string $contact * @param array $options - Optional (backend specific options) * @return string|bool The identifier for the new contact or false on error. */ public function createContact($addressBookId, $contact, array $options = array()) { //\OCP\Util::writeLog('contacts', __METHOD__.' addressBookId: ' . $addressBookId, \OCP\Util::DEBUG); $uri = isset($options['uri']) ? $options['uri'] : null; if (!$contact instanceof VCard) { try { $contact = Reader::read($contact); } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } } try { $contact->validate(VCard::REPAIR | VCard::UPGRADE); } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ' ' . 'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } $uri = is_null($uri) ? $this->uniqueURI($addressBookId, $contact->UID . '.vcf') : $uri; $now = new \DateTime(); $contact->REV = $now->format(\DateTime::W3C); $appinfo = \OCP\App::getAppInfo('contacts'); $appversion = \OCP\App::getAppVersion('contacts'); $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $contact->PRODID = $prodid; try { $result = $this->getPreparedQuery('createcontact')->execute(array($addressBookId, (string) $contact->FN, $contact->serialize(), $uri, time())); if (\OCP\DB::isError($result)) { \OCP\Util::writeLog('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); return false; } $newid = \OCP\DB::insertid($this->cardsTableName); $this->setModifiedAddressBook($addressBookId); \OCP\Util::emitHook('OCA\\Contacts', 'post_createContact', array('id' => $newid, 'parent' => $addressBookId, 'backend' => $this->name, 'contact' => $contact)); return (string) $newid; }
/** * @brief Adds a card * @param $aid integer Addressbook id * @param $card Sabre\VObject\Component vCard file * @param $uri string the uri of the card, default based on the UID * @param $isChecked boolean If the vCard should be checked for validity and version. * @return insertid on success or false. */ public static function add($aid, VObject\Component $card, $uri = null, $isChecked = false) { if (is_null($card)) { \OCP\Util::writeLog('contacts', __METHOD__ . ', No vCard supplied', \OCP\Util::ERROR); return null; } $addressbook = Addressbook::find($aid); if ($addressbook['userid'] != \OCP\User::getUser()) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_CREATE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to add contacts to this addressbook.')); } } if (!$isChecked) { self::updateValuesFromAdd($aid, $card); } $card->{'VERSION'} = '3.0'; // Add product ID is missing. //$prodid = trim($card->getAsString('PRODID')); //if(!$prodid) { if (!isset($card->PRODID)) { $appinfo = \OCP\App::getAppInfo('contacts'); $appversion = \OCP\App::getAppVersion('contacts'); $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $card->add('PRODID', $prodid); } $fn = isset($card->FN) ? $card->FN : ''; $uri = isset($uri) ? $uri : $card->UID . '.vcf'; $data = $card->serialize(); $stmt = \OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`,`fullname`,`carddata`,`uri`,`lastmodified`) VALUES(?,?,?,?,?)'); try { $result = $stmt->execute(array($aid, $fn, $data, $uri, time())); if (\OC_DB::isError($result)) { \OC_Log::write('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR); return false; } } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR); \OCP\Util::writeLog('contacts', __METHOD__ . ', aid: ' . $aid . ' uri' . $uri, \OCP\Util::DEBUG); return false; } $newid = \OCP\DB::insertid('*PREFIX*contacts_cards'); App::loadCategoriesFromVCard($newid, $card); App::updateDBProperties($newid, $card); App::cacheThumbnail($newid); Addressbook::touch($aid); \OC_Hook::emit('\\OCA\\Contacts\\VCard', 'post_createVCard', $newid); return $newid; }
/** * @NoAdminRequired */ public function prepareIosGroups() { $pGroups = $this->params('agroups'); $pAddrBookId = $this->params('aid'); if ($pAddrBookId > 0) { $existIosGroups = ContactsApp::getIosGroups(); $iCountExist = count($pGroups); $iCountIosExist = count($existIosGroups); if ($iCountExist < $iCountIosExist) { //Group Delete foreach ($existIosGroups as $key => $value) { if (!array_key_exists($key, $pGroups)) { VCard::delete($value['id']); } } } if ($iCountExist > $iCountIosExist) { //Group Added $newGroup = array(); foreach ($pGroups as $key => $value) { if (!array_key_exists($key, $existIosGroups)) { $newGroup[] = $key; } } foreach ($newGroup as $val) { $uid = substr(md5(rand() . time()), 0, 10); $appinfo = \OCP\App::getAppInfo($this->appName); $appversion = \OCP\App::getAppVersion($this->appName); $prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion . '//EN'; $vcard = new \Sabre\VObject\Component\VCard(array('PRODID' => $prodid, 'VERSION' => '3.0', 'UID' => $uid)); $vcard->N = $val; $vcard->FN = $val; //X-ADDRESSBOOKSERVER-KIND:group $vcard->{'X-ADDRESSBOOKSERVER-KIND'} = 'group'; $id = VCard::add($pAddrBookId, $vcard, null, true); } } $params = ['status' => 'success']; $response = new JSONResponse($params); return $response; } //END $addrBk }
/** * Generate an event to show in the calendar * * @return \Sabre\VObject\Component\VCalendar|null */ public function getBirthdayEvent() { if (!isset($this->BDAY)) { return null; } $birthday = $this->BDAY; if ((string) $birthday) { $title = str_replace('{name}', strtr((string) $this->FN, array('\\,' => ',', '\\;' => ';')), App::$l10n->t('{name}\'s Birthday')); try { $date = new \DateTime($birthday); } catch (Exception $e) { return null; } $vCal = new \Sabre\VObject\Component\VCalendar(); $vCal->VERSION = '2.0'; $vEvent = $vCal->createComponent('VEVENT'); $vEvent->add('DTSTART'); $vEvent->DTSTART->setDateTime($date); $vEvent->DTSTART['VALUE'] = 'date'; $vEvent->add('DURATION', 'P1D'); $vEvent->{'UID'} = $this->UID; $vEvent->{'RRULE'} = 'FREQ=YEARLY'; $vEvent->{'SUMMARY'} = $title . ' (' . $date->format('Y') . ')'; $vEvent->{'TRANSP'} = 'TRANSPARENT'; $appInfo = \OCP\App::getAppInfo('contacts'); $appVersion = \OCP\App::getAppVersion('contacts'); $vCal->PRODID = '-//ownCloud//NONSGML ' . $appInfo['name'] . ' ' . $appVersion . '//EN'; $vCal->add($vEvent); return $vCal; } return null; }
public function testAppMaxPhpVersion() { $appData = App::getAppInfo('galleryplus'); $this->assertSame('7', $appData['dependencies']['php']['@attributes']['max-version']); }