Example #1
0
 /**
  * 
  * @param string $query
  * @return \OCP\Search\Result
  */
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = ContactsApp::searchProperties($query);
     $l = \OC::$server->getL10N(ContactsApp::$appname);
     foreach ($results as $result) {
         $vcard = VCard::find($result['id']);
         $link = \OC::$server->getURLGenerator()->linkToRoute(ContactsApp::$appname . '.page.index') . '#' . urlencode($vcard['id']);
         $props = array();
         foreach (array('EMAIL', 'NICKNAME', 'ORG') as $searchvar) {
             if (isset($result[$searchvar]) && count($result[$searchvar]) > 0 && strlen($result[$searchvar][0]) > 3) {
                 $props = array_merge($props, $result[$searchvar]);
             }
         }
         $props = array_map($unescape, $props);
         $returnData['id'] = $vcard['id'];
         $returnData['description'] = $vcard['fullname'] . ' ' . implode(', ', $props);
         $returnData['link'] = $link;
         $results[] = new Result($returnData);
     }
     return $results;
 }
Example #2
0
 /**
  * 
  * @param string $query
  * @return \OCP\Search\Result
  */
 function search($query)
 {
     $unescape = function ($value) {
         return strtr($value, array('\\,' => ',', '\\;' => ';'));
     };
     $searchresults = array();
     $results = ContactsApp::searchProperties($query);
     $l = \OC::$server->getL10N(ContactsApp::$appname);
     foreach ($results as $result) {
         $vcard = VCard::find($result['id']);
         $link = '#' . intval($vcard['id']);
         $props = '';
         foreach (array('EMAIL', 'NICKNAME', 'ORG', 'TEL') as $searchvar) {
             if (isset($result['name']) && $searchvar == $result['name']) {
                 //\OCP\Util::writeLog(ContactsApp::$appname,'FOUND id: ' . $result['value'], \OCP\Util::DEBUG);
                 $props .= $searchvar . ':' . $result['value'] . ' ';
             }
         }
         $returnData['id'] = $vcard['id'];
         $returnData['description'] = $vcard['fullname'] . ' ' . $props;
         $returnData['link'] = $link;
         $results[] = new Result($returnData);
     }
     return $results;
 }
Example #3
0
 /**
  * @brief deletes a card
  * @param integer $id id of card
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function delete($id)
 {
     $contact = self::find($id);
     if (!$contact) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', id: ' . $id . ' not found.', \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('Could not find the vCard with ID: ' . $id, 404));
     }
     $addressbook = Addressbook::find($contact['addressbookid']);
     if (!$addressbook) {
         throw new \Exception(App::$l10n->t('Could not find the Addressbook with ID: ' . $contact['addressbookid'], 404));
     }
     if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(\OCP\User::getUser(), 'admin')) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', ' . $addressbook['userid'] . ' != ' . \OCP\User::getUser(), \OCP\Util::DEBUG);
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $contact['addressbookid'], \OCP\Share::FORMAT_NONE, null, true);
         $sharedContact = \OCP\Share::getItemSharedWithBySource(App::SHARECONTACT, App::SHARECONTACTPREFIX . $id, \OCP\Share::FORMAT_NONE, null, true);
         $addressbook_permissions = 0;
         $contact_permissions = 0;
         if ($sharedAddressbook) {
             $addressbook_permissions = $sharedAddressbook['permissions'];
         }
         if ($sharedContact) {
             $contact_permissions = $sharedEvent['permissions'];
         }
         $permissions = max($addressbook_permissions, $contact_permissions);
         if (!($permissions & \OCP\PERMISSION_DELETE)) {
             throw new \Exception(App::$l10n->t('You do not have the permissions to delete this contact.', 403));
         }
     }
     $aid = $contact['addressbookid'];
     //	\OC_Hook::emit('\OCA\ContactsPlus\VCard', 'pre_deleteVCard',
     //		array('aid' => null, 'id' => $id, 'uri' => null)
     //	);
     $favorites = \OC::$server->getTagManager()->load(App::$appname)->getFavorites();
     if (count($favorites) > 0) {
         $favorites = \OC::$server->getTagManager()->load(App::$appname)->removeFromFavorites($id);
     }
     $stmt = \OCP\DB::prepare('DELETE FROM `' . App::ContactsTable . '` WHERE `id` = ?');
     try {
         $stmt->execute(array($id));
     } catch (\Exception $e) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('There was an error deleting this contact.'));
     }
     App::updateDBProperties($id);
     //App::getVCategories()->purgeObject($id);
     Addressbook::touch($addressbook['id']);
     \OCP\Share::unshareAll(App::SHARECONTACT, $id);
     return true;
 }
Example #4
0
<?php

namespace OCA\ContactsPlus;

use Sabre\VObject;
App::$appname = 'contactsplus';
App::$l10n = \OC::$server->getL10N('contactsplus');
class App
{
    public static $l10n;
    public static $appname;
    const THUMBNAIL_PREFIX = 'kontakte-photo-';
    const THUMBNAIL_SIZE = 28;
    const ContactsTable = '*PREFIX*conplus_cards';
    const AddrBookTable = '*PREFIX*conplus_addressbooks';
    const ContactsProbTable = '*PREFIX*conplus_cards_properties';
    const SHAREADDRESSBOOK = 'cpladdrbook';
    const SHAREADDRESSBOOKPREFIX = '';
    const SHARECONTACT = 'cplcontact';
    const SHARECONTACTPREFIX = '';
    /**
     * @brief categories of the user
     */
    protected static $categories = null;
    /**
     * Properties there can be more than one of.
     */
    public static $multi_properties = array('EMAIL', 'TEL', 'IMPP', 'ADR', 'URL', 'CLOUD');
    /**
     * Properties to index.
     */
Example #5
0
 /**
  * @NoAdminRequired
  */
 public function deletePhoto()
 {
     $id = $this->params('id');
     $vcard = ContactsApp::getContactVCard($id);
     unset($vcard->PHOTO);
     VCard::edit($id, $vcard);
     $result = ['status' => 'success', 'data' => ['id' => $id]];
     $response = new JSONResponse();
     $response->setData($result);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function getCategories()
 {
     $aCountGroups = ContactsApp::getCounterGroups();
     $checkCat = ContactsApp::loadTags();
     $checkCat['tagslist'][] = array('name' => (string) $this->l10n->t('All'), 'bgcolor' => '#ccc', 'color' => '#000', 'id' => 'all');
     $checkCat['tagslist'][] = array('name' => (string) $this->l10n->t('Not in group'), 'bgcolor' => '#ccc', 'color' => '#000', 'id' => 'none');
     $checkCatTagsList = '';
     $aSortOrderGroups = '';
     if ($sortOrderGroups = $this->configInfo->getUserValue($this->userId, $this->appName, 'sortorder')) {
         $aSortOrderGroupsTmp = json_decode($sortOrderGroups, true);
         $counter = 0;
         foreach ($aSortOrderGroupsTmp as $sortInfo) {
             //	\OCP\Util::writeLog($this->appName,'SORT: '.$sortInfo, \OCP\Util::DEBUG);
             $aSortOrderGroups[$sortInfo] = $counter;
             $counter++;
         }
     }
     $counter = 0;
     foreach ($checkCat['tagslist'] as $tag) {
         $iCount = 0;
         if ($aCountGroups != '' && array_key_exists((string) $tag['name'], $aCountGroups)) {
             $iCount = $aCountGroups[$tag['name']];
         }
         if ($tag['id'] === 'fav') {
             $iCount = isset($aCountGroups['favo']) ? $aCountGroups['favo'] : 0;
         }
         $sortOrder = $tag['id'];
         if ($aSortOrderGroups != '' && array_key_exists($tag['id'], $aSortOrderGroups)) {
             $sortOrder = $aSortOrderGroups[$tag['id']];
         }
         $checkCatTagsList[$sortOrder] = array('id' => $tag['id'], 'name' => $tag['name'], 'color' => $tag['color'], 'bgcolor' => $tag['bgcolor'], 'icount' => $iCount);
         $counter++;
     }
     $params = ['status' => 'success', 'data' => ['groups' => $checkCatTagsList]];
     $response = new JSONResponse($params);
     return $response;
 }
 /**
  * @NoAdminRequired
  */
 public function getContactCards()
 {
     $grpId = $this->params('grpid');
     $addrbookId = intval($this->params('ardbid'));
     $grpId = isset($grpId) ? $grpId : 'all';
     if ($addrbookId == 0) {
         $active_addressbooks = Addressbook::all($this->userId);
         $ids = array();
         foreach ($active_addressbooks as $addressbook) {
             $ids[] = $addressbook['id'];
         }
         $addrbookId = $ids[0];
     }
     $this->configInfo->setUserValue($this->userId, $this->appName, 'currentbook', $addrbookId);
     $cardslist = ContactsApp::renderOutput($addrbookId, $grpId);
     return $cardslist;
 }