function search($query) { $addressbooks = Addressbook::all(\OCP\USER::getUser(), 1); if (count($addressbooks) == 0 || !\OCP\App::isEnabled('contacts')) { return array(); } $results = array(); $l = new \OC_l10n('contacts'); foreach ($addressbooks as $addressbook) { $vcards = VCard::all($addressbook['id']); foreach ($vcards as $vcard) { if (substr_count(strtolower($vcard['fullname']), strtolower($query)) > 0) { //$link = \OCP\Util::linkTo('contacts', 'index.php').'?id='.urlencode($vcard['id']); $link = 'javascript:openContact(' . $vcard['id'] . ')'; $results[] = new \OC_Search_Result($vcard['fullname'], '', $link, (string) $l->t('Contact')); //$name,$text,$link,$type } } } return $results; }
public function import() { if (is_null($this->userid)) { throw new \Exception('No user id set'); } if (!$this->isValid()) { return false; } $this->numofcomponents = count($this->vcardobject); if ($this->overwrite) { foreach (VCard::all($this->id) as $obj) { VCard::delete($obj['id']); } } foreach ($this->vcardobject as $object) { if (!$object instanceof \Sabre\VObject\Component\VCard) { //continue; } $vcard = \Sabre\VObject\Reader::read($object, \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); $importVCard = VCard::structureContact($vcard); if ($importVCard !== false) { $newVcard = $this->parseVCard($importVCard, $vcard); $insertid = VCard::add($this->id, $newVcard); $this->abscount++; } else { $this->errorCount++; } if ($this->isDuplicate($insertid)) { VCard::delete($insertid); $this->abscount--; } $this->updateProgress(intval($this->abscount / $this->numofcomponents * 100)); } \OC::$server->getCache()->remove($this->progresskey); return true; }
/** * @brief removes an address book * @param integer $id * @return boolean true on success, otherwise an exception will be thrown */ public static function delete($id) { $addressbook = self::find($id); if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(OCP\User::getUser(), 'admin')) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource('addressbook', $id); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.')); } } // First delete cards belonging to this addressbook. $cards = VCard::all($id); foreach ($cards as $card) { try { VCard::delete($card['id']); } catch (Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR); } } try { $stmt = \OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_addressbooks` WHERE `id` = ?'); $stmt->execute(array($id)); } catch (\Exception $e) { \OCP\Util::writeLog('contacts', __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR); throw new Exception(App::$l10n->t('There was an error deleting this addressbook.')); } \OCP\Share::unshareAll('addressbook', $id); if (count(self::all(\OCP\User::getUser())) == 0) { self::addDefault(); } return true; }
/** * @brief removes an address book * @param integer $id * @return boolean true on success, otherwise an exception will be thrown */ public static function delete($id) { $addressbook = self::find($id); if ($addressbook['userid'] !== \OCP\User::getUser() && !\OC_Group::inGroup(\OCP\User::getUser(), 'admin')) { $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $id); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & \OCP\PERMISSION_DELETE)) { throw new \Exception(App::$l10n->t('You do not have the permissions to delete this addressbook.')); } } // First delete cards belonging to this addressbook. $cards = VCard::all($id); foreach ($cards as $card) { try { VCard::delete($card['id']); } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception deleting vCard ' . $card['id'] . ': ' . $e->getMessage(), \OCP\Util::ERROR); } } try { $stmt = \OCP\DB::prepare('DELETE FROM `' . App::AddrBookTable . '` WHERE `id` = ?'); $stmt->execute(array($id)); } catch (\Exception $e) { \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception for ' . $id . ': ' . $e->getMessage(), \OCP\Util::ERROR); throw new \Exception(App::$l10n->t('There was an error deleting this addressbook.')); } \OCP\Share::unshareAll(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $id); \OCP\Util::emitHook('\\OCA\\ContactsPlus', 'deleteAddressbook', $id); return true; }