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 = ?'); $results = $query->execute(array($this->olduid)); $idmap = array(); $app = new \OCA\Contacts\App($this->uid); 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 $addressbook = $app->getAddressBook('local', $idmap[$row['id']]); $addressbook->setActive(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; }
<?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'); $id = isset($_GET['id']) ? $_GET['id'] : null; if (is_null($id)) { OCP\JSON::error(array('data' => array('message' => OCA\Contacts\App::$l10n->t('No ID provided')))); exit; } $vcard = OCA\Contacts\App::getContactVCard($id); foreach ($vcard->children as $property) { if ($property->name == 'CATEGORIES') { $checksum = md5($property->serialize()); OCP\JSON::success(array('data' => array('value' => $property->value, 'checksum' => $checksum))); exit; } } OCP\JSON::error(array('data' => array('message' => OCA\Contacts\App::$l10n->t('Error setting checksum.'))));
<?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'); OCP\JSON::callCheck(); require_once __DIR__ . '/../loghandler.php'; $categoryid = isset($_POST['categoryid']) ? $_POST['categoryid'] : null; $contactids = isset($_POST['contactids']) ? $_POST['contactids'] : null; if (is_null($categoryid)) { bailOut(OCA\Contacts\App::$l10n->t('Group ID missing from request.')); } if (is_null($contactids)) { bailOut(OCA\Contacts\App::$l10n->t('Contact ID missing from request.')); } $catmgr = OCA\Contacts\App::getVCategories(); foreach ($contactids as $contactid) { debug('id: ' . $contactid . ', categoryid: ' . $categoryid); $catmgr->removeFromCategory($contactid, $categoryid); } OCP\JSON::success();
/** * Returns information from a single calendar object, based on it's object * uri. * * The returned array must have the same keys as getCalendarObjects. The * 'calendardata' object is required here though, while it's not required * for getCalendarObjects. * * @param string $calendarId * @param string $objectUri * @return array */ public function getCalendarObject($calendarId, $objectUri) { if ($calendarId === 'contact_birthdays') { $objectUri = substr($objectUri, 0, strlen($objectUri) - 4); $objectUriArray = explode('::', $objectUri); if (count($objectUriArray) === 3) { $app = new \OCA\Contacts\App(); list($backend, $addressBookId, $contactId) = $objectUriArray; $contact = $app->getContact($backend, $addressBookId, $contactId); $vevent = $contact->getBirthdayEvent(); if (is_null($vevent)) { return false; } return $this->OCAddETag(array('id' => 0, 'calendarid' => 'contact_birthdays', 'uri' => $contact->getBackend()->name . '::' . $contact->getParent()->getId() . '::' . $contact->getId() . '.ics', 'lastmodified' => $contact->lastModified(), 'calendardata' => $vevent->serialize())); } } $data = OC_Calendar_Object::findWhereDAVDataIs($calendarId, $objectUri); if (is_array($data)) { $data = $this->OCAddETag($data); $object = \Sabre\VObject\Reader::read($data['calendardata']); if (!$object) { return false; } $object = OC_Calendar_Object::cleanByAccessClass($data['id'], $object); $data['calendardata'] = $object->serialize(); } return $data; }
} 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']] = array('contacts' => array('type' => 'book',)); $contacts_addressbook[$addressbook['id']]['displayname']
* 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/>. * */ // Firefox and Konqueror tries to download application/json for me. --Arthur OCP\JSON::setContentTypeHeader('text/plain'); OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); require_once 'loghandler.php'; if (!isset($_GET['id'])) { bailOut(OCA\Contacts\App::$l10n->t('No contact ID was submitted.')); } $contact = OCA\Contacts\App::getContactVCard($_GET['id']); // invalid vcard if (is_null($contact)) { bailOut(OCA\Contacts\App::$l10n->t('Error reading contact photo.')); } else { $image = new OC_Image(); if (!isset($contact->PHOTO) || !$image->loadFromBase64((string) $contact->PHOTO)) { if (isset($contact->LOGO)) { $image->loadFromBase64((string) $contact->LOGO); } } if ($image->valid()) { $tmpkey = 'contact-photo-' . $contact->UID; if (OC_Cache::set($tmpkey, $image->data(), 600)) { OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpkey))); exit;
* 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');
/** * Copyright (c) 2011 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'); $id = $_GET['id']; $checksum = isset($_GET['checksum']) ? $_GET['checksum'] : ''; $vcard = OCA\Contacts\App::getContactVCard($id); $adr_types = OCA\Contacts\App::getTypesOfProperty('ADR'); $tmpl = new OCP\Template("contacts", "part.edit_address_dialog"); if ($checksum) { $line = OCA\Contacts\App::getPropertyLineByChecksum($vcard, $checksum); $element = $vcard->children[$line]; $adr = OCA\Contacts\VCard::structureProperty($element); $types = array(); if (isset($adr['parameters']['TYPE'])) { if (is_array($adr['parameters']['TYPE'])) { $types = array_map('htmlspecialchars', $adr['parameters']['TYPE']); $types = array_map('strtoupper', $types); } else { $types = array(strtoupper(htmlspecialchars($adr['parameters']['TYPE']))); } } $tmpl->assign('types', $types, false); $adr = array_map('htmlspecialchars', $adr['value']); $tmpl->assign('adr', $adr, false); }
$property->parameters[] = new Sabre\VObject\Parameter('ENCODING', 'b'); $property->parameters[] = new Sabre\VObject\Parameter('TYPE', $image->mimeType()); $vcard->__set('PHOTO', $property); } else { OCP\Util::writeLog('contacts', 'savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG); // For vCard 3.0 the type must be e.g. JPEG or PNG // For version 4.0 the full mimetype should be used. // https://tools.ietf.org/html/rfc2426#section-3.1.4 $type = $vcard->VERSION == '4.0' ? $image->mimeType() : strtoupper(array_pop(explode('/', $image->mimeType()))); $vcard->add('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $type)); } $now = new DateTime(); $vcard->{'REV'} = $now->format(DateTime::W3C); if (!OCA\Contacts\VCard::edit($id, $vcard)) { bailOut(OCA\Contacts\App::$l10n->t('Error saving contact.')); } OCA\Contacts\App::cacheThumbnail($id, $image); OCP\JSON::success(array('data' => array('id' => $id, 'width' => $image->width(), 'height' => $image->height(), 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U')))); } else { bailOut(OCA\Contacts\App::$l10n->t('Error resizing image')); } } else { bailOut(OCA\Contacts\App::$l10n->t('Error cropping image')); } } else { bailOut(OCA\Contacts\App::$l10n->t('Error creating temporary image')); } } else { bailOut(OCA\Contacts\App::$l10n->t('Error finding image: ') . $tmpkey); } OC_Cache::remove($tmpkey);
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']; } $categories = OCA\Contacts\App::getCategories(); $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = min($upload_max_filesize, $post_max_size); $freeSpace = OC_Filesystem::free_space('/'); $freeSpace = max($freeSpace, 0); $maxUploadFilesize = min($maxUploadFilesize, $freeSpace); OCP\Util::addscript('contacts', 'multiselect'); OCP\Util::addscript('', 'oc-vcategories'); OCP\Util::addscript('contacts', 'app'); OCP\Util::addscript('contacts', 'contacts'); OCP\Util::addscript('contacts', 'modernizr'); OCP\Util::addscript('contacts', 'placeholder.polyfill.jquery'); OCP\Util::addscript('contacts', 'expanding'); OCP\Util::addscript('contacts', 'jquery.combobox'); OCP\Util::addscript('files', 'jquery.fileupload');
if (is_null($contact)) { OCP\Util::writeLog('contacts', 'photo.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR); } else { // Photo :-) if (isset($contact->PHOTO) && $image->loadFromBase64((string) $contact->PHOTO)) { // OK $etag = md5($contact->PHOTO); } else { // Logo :-/ if (isset($contact->LOGO) && $image->loadFromBase64((string) $contact->LOGO)) { // OK $etag = md5($contact->LOGO); } } if ($image->valid()) { $modified = OCA\Contacts\App::lastModified($contact); // Force refresh if modified within the last minute. if (!is_null($modified)) { $caching = time() - $modified->format('U') > 60 ? null : 0; } OCP\Response::enableCaching($caching); if (!is_null($modified)) { OCP\Response::setLastModifiedHeader($modified); } if ($etag) { OCP\Response::setETagHeader($etag); } if ($image->width() > $max_size || $image->height() > $max_size) { $image->resize($max_size); } }
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()); } if (!$id) { bailOut('There was an error adding the contact.'); } $lastmodified = OCA\Contacts\App::lastModified($vcard); if (!$lastmodified) { $lastmodified = new DateTime(); } OCP\JSON::success(array('data' => array('id' => $id, 'aid' => $aid, 'details' => OCA\Contacts\VCard::structureContact($vcard), 'lastmodified' => $lastmodified->format('U'))));
$name = isset($_POST['name']) ? $_POST['name'] : null; $checksum = isset($_POST['checksum']) ? $_POST['checksum'] : null; $l10n = OCA\Contacts\App::$l10n; $multi_properties = array('EMAIL', 'TEL', 'IMPP', 'ADR', 'URL'); if (!$id) { bailOut(OCA\Contacts\App::$l10n->t('id is not set.')); } if (!$name) { bailOut(OCA\Contacts\App::$l10n->t('element name is not set.')); } if (!$checksum && in_array($name, $multi_properties)) { bailOut(OCA\Contacts\App::$l10n->t('checksum is not set.')); } $vcard = OCA\Contacts\App::getContactVCard($id); if (!is_null($checksum)) { $line = OCA\Contacts\App::getPropertyLineByChecksum($vcard, $checksum); if (is_null($line)) { bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.')); exit; } unset($vcard->children[$line]); } else { unset($vcard->{$name}); } try { OCA\Contacts\VCard::edit($id, $vcard); } catch (Exception $e) { bailOut($e->getMessage()); } OCP\JSON::success(array('data' => array('id' => $id, 'lastmodified' => OCA\Contacts\App::lastModified($vcard)->format('U'))));
//OCP\Util::writeLog('contacts', OCP\Util::getRequestUri(), OCP\Util::DEBUG); function getStandardImage() { OCP\Response::enableCaching(); OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person.png')); exit; } if (!extension_loaded('gd') || !function_exists('gd_info')) { OCP\Util::writeLog('contacts', 'thumbnail.php. GD module not installed', OCP\Util::DEBUG); getStandardImage(); } $id = $_GET['id']; $caching = null; $image = OCA\Contacts\App::cacheThumbnail($id); if ($image !== false) { try { $modified = OCA\Contacts\App::lastModified($id); } catch (Exception $e) { getStandardImage(); } // Force refresh if modified within the last minute. if (!is_null($modified)) { $caching = time() - $modified->format('U') > 60 ? null : 0; OCP\Response::setLastModifiedHeader($modified); } OCP\Response::enableCaching($caching); header('Content-Type: image/png'); echo $image; } else { getStandardImage(); }