/** * Returns all cards for a specific addressbook id. * * @param mixed $addressbookid * @return array */ public function getCards($addressbookid) { $data = OCA\Contacts\VCard::all($addressbookid); $cards = array(); foreach ($data as $i) { //OCP\Util::writeLog('contacts', __METHOD__.', uri: ' . $i['uri'], OCP\Util::DEBUG); $cards[] = array('id' => $i['id'], 'size' => strlen($i['carddata']), 'etag' => md5($i['carddata']), 'uri' => $i['uri'], 'lastmodified' => $i['lastmodified']); } return $cards; }
$bookid = isset($_GET['bookid']) ? $_GET['bookid'] : null; $contactid = isset($_GET['contactid']) ? $_GET['contactid'] : null; $selectedids = isset($_GET['selectedids']) ? $_GET['selectedids'] : null; $nl = "\n"; if (!is_null($bookid)) { try { $addressbook = OCA\Contacts\Addressbook::find($bookid); } catch (Exception $e) { OCP\JSON::error(array('data' => array('message' => $e->getMessage()))); exit; } header('Content-Type: text/directory'); header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf'); $start = 0; $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20); while ($cardobjects = OCA\Contacts\VCard::all($bookid, $start, $batchsize, array('carddata'))) { foreach ($cardobjects as $card) { echo $card['carddata'] . $nl; } $start += $batchsize; } } elseif (!is_null($contactid)) { try { $data = OCA\Contacts\VCard::find($contactid); } catch (Exception $e) { OCP\JSON::error(array('data' => array('message' => $e->getMessage()))); exit; } header('Content-Type: text/vcard'); header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf'); echo $data['carddata'];
require_once __DIR__ . '/../loghandler.php'; $categories = isset($_POST['categories']) ? $_POST['categories'] : null; $fromobjects = isset($_POST['fromobjects']) && ($_POST['fromobjects'] === 'true' || $_POST['fromobjects'] === '1') ? true : false; if (is_null($categories)) { bailOut(OCA\Contacts\App::$l10n->t('No categories selected for deletion.')); } debug(print_r($categories, true)); if ($fromobjects) { $addressbooks = OCA\Contacts\Addressbook::all(OCP\USER::getUser()); if (count($addressbooks) == 0) { bailOut(OCA\Contacts\App::$l10n->t('No address books found.')); } $addressbookids = array(); foreach ($addressbooks as $addressbook) { $addressbookids[] = $addressbook['id']; } $contacts = OCA\Contacts\VCard::all($addressbookids); if (count($contacts) == 0) { bailOut(OCA\Contacts\App::$l10n->t('No contacts found.')); } $cards = array(); foreach ($contacts as $contact) { $cards[] = array($contact['id'], $contact['carddata']); } } $catman = new OC_VCategories('contact'); $catman->delete($categories, $cards); if ($fromobjects) { OCA\Contacts\VCard::updateDataByID($cards); } OCP\JSON::success();
/*if(!isset($contacts_addressbook[$addressbook['id']])) { $contacts_addressbook[$addressbook['id']] = array('contacts' => array('type' => 'book',)); $contacts_addressbook[$addressbook['id']]['displayname'] = $addressbook['displayname']; $contacts_addressbook[$addressbook['id']]['description'] = $addressbook['description']; $contacts_addressbook[$addressbook['id']]['permissions'] = $addressbook['permissions']; $contacts_addressbook[$addressbook['id']]['owner'] = $addressbook['userid']; }*/ } $contacts_alphabet = array(); // get next 50 for each addressbook. $contacts_alphabet = array_merge($contacts_alphabet, OCA\Contacts\VCard::all($ids)); /*foreach($ids as $id) { if($id) { $contacts_alphabet = array_merge( $contacts_alphabet, OCA\Contacts\VCard::all($id, $offset, 50) ); } }*/ uasort($contacts_alphabet, 'cmp'); $contacts = array(); // Our new array for the contacts sorted by addressbook if ($contacts_alphabet) { foreach ($contacts_alphabet as $contact) { try { $vcard = Sabre\VObject\Reader::read($contact['carddata']);
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ /** * @brief Index vCard properties for easier searching */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); require_once 'loghandler.php'; $addressbooks = OCA\Contacts\Addressbook::all(OCP\USER::getUser()); $ids = array(); foreach ($addressbooks as $addressbook) { $ids[] = $addressbook['id']; } $user = OCP\User::getUser(); session_write_close(); $start = 0; $batchsize = 10; while ($contacts = OCA\Contacts\VCard::all($ids, $start, $batchsize)) { OCP\Util::writeLog('contacts', 'Indexing contacts: ' . $batchsize . ' starting from ' . $start, OCP\Util::DEBUG); foreach ($contacts as $contact) { $vcard = OC_VObject::parse($contact['carddata']); OCA\Contacts\App::updateDBProperties($contact['id'], $vcard); } $start += $batchsize; } OCP\Config::setUserValue($user, 'contacts', 'contacts_indexed', 'yes');
<?php /** * Copyright (c) 2012 Thomas Tanghus <*****@*****.**> * Copyright (c) 2011 Jakob Sack mail@jakobsack.de * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ // Check if we are a user OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('contacts'); // Get active address books. This creates a default one if none exists. $ids = OCA\Contacts\Addressbook::activeIds(OCP\USER::getUser()); $has_contacts = count(OCA\Contacts\VCard::all($ids, 0, 1)) > 0 ? true : false; // just to check if there are any contacts. if ($has_contacts === false) { OCP\Util::writeLog('contacts', 'index.html: No contacts found.', OCP\Util::DEBUG); } // Load the files we need OCP\App::setActiveNavigationEntry('contacts_index'); // Load a specific user? $id = isset($_GET['id']) ? $_GET['id'] : null; $impp_types = OCA\Contacts\App::getTypesOfProperty('IMPP'); $adr_types = OCA\Contacts\App::getTypesOfProperty('ADR'); $phone_types = OCA\Contacts\App::getTypesOfProperty('TEL'); $email_types = OCA\Contacts\App::getTypesOfProperty('EMAIL'); $ims = OCA\Contacts\App::getIMOptions(); $im_protocols = array(); foreach ($ims as $name => $values) { $im_protocols[$name] = $values['displayname'];
$contactid = isset($_GET['contactid']) ? $_GET['contactid'] : null; $nl = "\n"; if (!is_null($bookid)) { try { $addressbook = OCA\Contacts\Addressbook::find($bookid); // is owner access check } catch (Exception $e) { OCP\JSON::error(array('data' => array('message' => $e->getMessage()))); exit; } //$cardobjects = OCA\Contacts\VCard::all($bookid); header('Content-Type: text/directory'); header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $addressbook['displayname']) . '.vcf'); $start = 0; $batchsize = OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'export_batch_size', 20); while ($cardobjects = OCA\Contacts\VCard::all($bookid, $start, $batchsize)) { foreach ($cardobjects as $card) { echo $card['carddata'] . $nl; } $start += $batchsize; } } elseif (!is_null($contactid)) { try { $data = OCA\Contacts\VCard::find($contactid); } catch (Exception $e) { OCP\JSON::error(array('data' => array('message' => $e->getMessage()))); exit; } header('Content-Type: text/vcard'); header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf'); echo $data['carddata'];