function import() { switch ($this->appinfo->version) { default: // All versions of the app have had the same db structure, so all can use the same import function $query = $this->content->prepare('SELECT * FROM `contacts_addressbooks` WHERE `userid` LIKE ?'); $results = $query->execute(array($this->olduid)); $idmap = array(); while ($row = $results->fetchRow()) { // Import each addressbook $addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)'); $addressbookquery->execute(array($this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag'])); // Map the id $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks'); // Make the addressbook active OCA\Contacts\Addressbook::setActive($idmap[$row['id']], true); } // Now tags foreach ($idmap as $oldid => $newid) { $query = $this->content->prepare('SELECT * FROM `contacts_cards` WHERE `addressbookid` LIKE ?'); $results = $query->execute(array($oldid)); while ($row = $results->fetchRow()) { // Import the contacts $contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)'); $contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified'])); } } // All done! break; } return true; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $createprincipal = $this->getOwner(); $deleteprincipal = $this->getOwner(); $uid = OCA\Contacts\Addressbook::extractUserID($this->getOwner()); $readWriteACL = array(array('privilege' => '{DAV:}read', 'principal' => 'principals/' . OCP\User::getUser(), 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => 'principals/' . OCP\User::getUser(), 'protected' => true)); if ($uid != OCP\USER::getUser()) { $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']); if ($sharedAddressbook) { if ($sharedAddressbook['permissions'] & OCP\PERMISSION_CREATE && $sharedAddressbook['permissions'] & OCP\PERMISSION_UPDATE && $sharedAddressbook['permissions'] & OCP\PERMISSION_DELETE) { return $readWriteACL; } if ($sharedAddressbook['permissions'] & OCP\PERMISSION_CREATE) { $createprincipal = 'principals/' . OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & OCP\PERMISSION_READ) { $readprincipal = 'principals/' . OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . OCP\USER::getUser(); } if ($sharedAddressbook['permissions'] & OCP\PERMISSION_DELETE) { $deleteprincipal = 'principals/' . OCP\USER::getUser(); } } } else { return parent::getACL(); } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write-content', 'principal' => $writeprincipal, 'protected' => true), array('privilege' => '{DAV:}bind', 'principal' => $createprincipal, 'protected' => true), array('privilege' => '{DAV:}unbind', 'principal' => $deleteprincipal, 'protected' => true)); }
function import() { $existingURIs = array(); $existingNames = array(); $query = $this->content->prepare('SELECT `displayname`, `uri` FROM *PREFIX*contacts_addressbooks WHERE userid = ?'); $results = $query->execute(array($this->uid)); while ($row = $results->fetchRow()) { \OCP\Util::writeLog('contacts', __METHOD__ . ', row: ' . print_r($row, true), \OCP\Util::DEBUG); $existingURIs[] = $row['uri']; $existingNames[] = $row['displayname']; } switch ($this->appinfo->version) { default: // All versions of the app have had the same db structure, so all can use the same import function $query = $this->content->prepare('SELECT * FROM contacts_addressbooks WHERE userid = ?'); $results = $query->execute(array($this->olduid)); $idmap = array(); while ($row = $results->fetchRow()) { // Import each addressbook $addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)'); $uriSuffix = ''; $nameSuffix = ''; while (in_array($row['uri'] . $uriSuffix, $existingURIs)) { $uriSuffix++; } while (in_array($row['displayname'] . $nameSuffix, $existingNames)) { $nameSuffix++; } $addressbookquery->execute(array($this->uid, $row['displayname'] . $nameSuffix, $row['uri'] . $uriSuffix, $row['description'], $row['ctag'])); // Map the id $idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks'); // Make the addressbook active OCA\Contacts\Addressbook::setActive($idmap[$row['id']], true); } // Now tags foreach ($idmap as $oldid => $newid) { $query = $this->content->prepare('SELECT * FROM contacts_cards WHERE addressbookid = ?'); $results = $query->execute(array($oldid)); while ($row = $results->fetchRow()) { // Import the contacts $contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)'); $contactquery->execute(array($newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified'])); } } // All done! break; } return true; }
/** * Returns a list of ACE's for this node. * * Each ACE has the following properties: * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are * currently the only supported privileges * * 'principal', a url to the principal who owns the node * * 'protected' (optional), indicating that this ACE is not allowed to * be updated. * * @return array */ public function getACL() { $readprincipal = $this->getOwner(); $writeprincipal = $this->getOwner(); $uid = OCA\Contacts\Addressbook::extractUserID($this->getOwner()); if ($uid != OCP\USER::getUser()) { $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $this->addressBookInfo['id']); if ($sharedAddressbook && $sharedAddressbook['permissions'] & OCP\PERMISSION_READ) { $readprincipal = 'principals/' . OCP\USER::getUser(); } if ($sharedAddressbook && $sharedAddressbook['permissions'] & OCP\PERMISSION_UPDATE) { $writeprincipal = 'principals/' . OCP\USER::getUser(); } } return array(array('privilege' => '{DAV:}read', 'principal' => $readprincipal, 'protected' => true), array('privilege' => '{DAV:}write', 'principal' => $writeprincipal, 'protected' => true)); }
<?php $tmpl = new OCP\Template('contacts', 'settings'); $tmpl->assign('addressbooks', OCA\Contacts\Addressbook::all(OCP\USER::getUser())); $tmpl->printPage();
"> <input type="hidden" id="path" value="<?php echo $_['path']; ?> "> <input type="hidden" id="progresskey" value="<?php echo rand(); ?> "> <p class="bold" style="text-align:center;"><?php echo $l->t('Please choose the addressbook'); ?> </p> <select style="width:100%;" id="contacts" name="contacts"> <?php $contacts_options = OCA\Contacts\Addressbook::all(OCP\USER::getUser()); $contacts_options[] = array('id' => 'newaddressbook', 'displayname' => $l->t('create a new addressbook')); echo OCP\html_select_options($contacts_options, $contacts_options[0]['id'], array('value' => 'id', 'label' => 'displayname')); ?> </select> <div id="newaddressbookform" style="display: none;"> <input type="text" style="width: 97%;" placeholder="<?php echo $l->t('Name of new addressbook'); ?> " id="newaddressbook" name="newaddressbook"> </div> <input type="button" value="<?php echo $l->t("Import"); ?> !" id="startimport"> </div>
/** * @author Victor Dubiniuk * Copyright (c) 2012 Victor Dubiniuk <*****@*****.**> * Copyright (c) 2012 Thomas Tanghus <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); $id = intval($_POST['id']); $aid = intval($_POST['aid']); $isaddressbook = isset($_POST['isaddressbook']) ? true : false; // Ownership checking try { OCA\Contacts\Addressbook::find($id); // is owner access check } catch (Exception $e) { OCP\JSON::error(array('data' => array('message' => $e->getMessage()))); exit; } try { OCA\Contacts\VCard::moveToAddressBook($aid, $id, $isaddressbook); } catch (Exception $e) { $msg = $e->getMessage(); OCP\Util::writeLog('contacts', 'Error moving contacts "' . implode(',', $id) . '" to addressbook "' . $aid . '"' . $msg, OCP\Util::ERROR); OC_JSON::error(array('data' => array('message' => $msg))); exit; } OC_JSON::success(array('data' => array('ids' => $id)));
/** * Deletes an entire addressbook and all its contents * * @param int $addressbookid * @return void */ public function deleteAddressBook($addressbookid) { OCA\Contacts\Addressbook::delete($addressbookid); }
<?php /** * Copyright (c) 2011 Thomas Tanghus <*****@*****.**> * Copyright (c) 2011 Bart Visscher <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); $id = $_POST['id']; try { $book = OCA\Contacts\Addressbook::find($id); // is owner access check } catch (Exception $e) { OCP\JSON::error(array('data' => array('message' => $e->getMessage(), 'file' => $_POST['file']))); exit; } if (!OCA\Contacts\Addressbook::setActive($id, $_POST['active'])) { OCP\Util::writeLog('contacts', 'ajax/activation.php: Error activating addressbook: ' . $id, OCP\Util::ERROR); OCP\JSON::error(array('data' => array('message' => OCA\Contacts\App::$l10n->t('Error (de)activating addressbook.')))); exit; } OCP\JSON::success(array('active' => OCA\Contacts\Addressbook::isActive($id), 'id' => $id, 'addressbook' => $book));
* This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); 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']); }
<?php $tmpl = new OCP\Template('contacts', 'settings'); $tmpl->assign('addressbooks', OCA\Contacts\Addressbook::all(\OC::$server->getUserSession()->getUser()->getUId())); $tmpl->printPage();
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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/>. * */ // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); require_once __DIR__ . '/../loghandler.php'; $aid = isset($_POST['aid']) ? $_POST['aid'] : null; if (!$aid) { $addressbooks = OCA\Contacts\Addressbook::all(OCP\User::getUser(), true, false); if (count($addressbooks) === 0) { bailOut(OCA\Contacts\App::$l10n->t('You have no addressbooks.')); } else { $aid = $addressbooks[0]['id']; } } $isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false; $vcard = Sabre\VObject\Component::create('VCARD'); $uid = substr(md5(rand() . time()), 0, 10); $vcard->add('UID', $uid); $id = null; try { $id = OCA\Contacts\VCard::add($aid, $vcard, null, $isnew); } catch (Exception $e) { bailOut($e->getMessage());
<?php /** * Copyright (c) 2012 Thomas Tanghus <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $catmgr = OCA\Contacts\App::getVCategories(); $categories = $catmgr->categories(OC_VCategories::FORMAT_MAP); foreach ($categories as &$category) { $ids = array(); $contacts = $catmgr->itemsForCategory($category['name'], array('tablename' => '*PREFIX*contacts_cards', 'fields' => array('id'))); foreach ($contacts as $contact) { $ids[] = $contact['id']; } $category['contacts'] = $ids; } $favorites = $catmgr->getFavorites(); // workaround for https://github.com/owncloud/core/issues/2814 $sharedAddressbooks = array(); $maybeSharedAddressBook = OCP\Share::getItemsSharedWith('addressbook', OCA\Contacts\Share_Backend_Addressbook::FORMAT_ADDRESSBOOKS); foreach ($maybeSharedAddressBook as $sharedAddressbook) { if (isset($sharedAddressbook['id']) && OCA\Contacts\Addressbook::find($sharedAddressbook['id'])) { $sharedAddressbooks[] = $sharedAddressbook; } } OCP\JSON::success(array('data' => array('categories' => $categories, 'favorites' => $favorites, 'shared' => $sharedAddressbooks, 'lastgroup' => OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'lastgroup', 'all'), 'sortorder' => OCP\Config::getUserValue(OCP\User::getUser(), 'contacts', 'groupsort', ''))));
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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/>. * */ // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); require_once __DIR__ . '/../loghandler.php'; $aid = isset($_POST['aid']) ? $_POST['aid'] : null; if (!$aid) { $aid = min(OCA\Contacts\Addressbook::activeIds()); // first active addressbook. } debug('Adding new contact to: ' . $aid); $isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false; $vcard = Sabre\VObject\Component::create('VCARD'); $uid = substr(md5(rand() . time()), 0, 10); $vcard->add('UID', $uid); debug('vobject: ', print_r($vcard->serialize(), true)); $id = null; try { $id = OCA\Contacts\VCard::add($aid, $vcard, null, $isnew); } catch (Exception $e) { bailOut($e->getMessage()); } if (!$id) {
<?php require_once __DIR__ . '/bootstrap.php'; OCP\App::addNavigationEntry(array('id' => 'contacts_index', 'order' => 10, 'href' => OCP\Util::linkTo('contacts', 'index.php'), 'icon' => OCP\Util::imagePath('contacts', 'contacts.svg'), 'name' => OC_L10N::get('contacts')->t('Contacts'))); OCP\Util::addscript('contacts', 'loader'); OC_Search::registerProvider('OCA\\Contacts\\SearchProvider'); if (OCP\User::isLoggedIn()) { foreach (OCA\Contacts\Addressbook::all(OCP\USER::getUser()) as $addressbook) { OCP\Contacts::registerAddressBook(new OCA\Contacts\AddressbookProvider($addressbook['id'])); } }
if ($a['fullname'] == $b['fullname']) { return 0; } return $a['fullname'] < $b['fullname'] ? -1 : 1; } OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $offset = isset($_GET['offset']) ? $_GET['offset'] : 0; $aid = isset($_GET['aid']) ? $_GET['aid'] : null; $active_addressbooks = array(); if (is_null($aid)) { // Called initially to get the active addressbooks. $active_addressbooks = OCA\Contacts\Addressbook::active(OCP\USER::getUser()); } else { // called each time more contacts has to be shown. $active_addressbooks = array(OCA\Contacts\Addressbook::find($aid)); } $lastModified = OCA\Contacts\App::lastModified(); if (!is_null($lastModified)) { OCP\Response::enableCaching(); OCP\Response::setLastModifiedHeader($lastModified); OCP\Response::setETagHeader(md5($lastModified->format('U'))); } session_write_close(); // create the addressbook associate array $contacts_addressbook = array(); $ids = array(); foreach ($active_addressbooks as $addressbook) { $ids[] = $addressbook['id']; /*if(!isset($contacts_addressbook[$addressbook['id']])) { $contacts_addressbook[$addressbook['id']]
/** * Copyright (c) 2011-2012 Thomas Tanghus <*****@*****.**> * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. */ OCP\User::checkLoggedIn(); OCP\App::checkAppEnabled('contacts'); $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)) {
* @copyright 2011 Jakob Sack mail@jakobsack.de * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE * License as published by the Free Software Foundation; either * version 3 of the License, or any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 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/>. * */ // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); require_once __DIR__ . '/../loghandler.php'; $id = $_POST['id']; if (!$id) { bailOut(OCA\Contacts\App::$l10n->t('id is not set.')); } try { OCA\Contacts\Addressbook::delete($id); } catch (Exception $e) { bailOut($e->getMessage()); } OCP\JSON::success(array('data' => array('id' => $id)));