public static function getBirthdayEvents($parameters) { $name = $parameters['calendar_id']; if (strpos($name, 'birthday_') != 0) { return; } $info = explode('_', $name); $aid = $info[1]; OC_Contacts_App::getAddressbook($aid); foreach (OC_Contacts_VCard::all($aid) as $card) { $vcard = OC_VObject::parse($card['carddata']); if (!$vcard) { continue; } $birthday = $vcard->BDAY; if ($birthday) { $date = new DateTime($birthday); $vevent = new OC_VObject('VEVENT'); //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV)); $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE); $vevent->setString('DURATION', 'P1D'); $vevent->setString('UID', substr(md5(rand() . time()), 0, 10)); // DESCRIPTION? $vevent->setString('RRULE', 'FREQ=YEARLY'); $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday')); $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR"); } } }
public static function getBirthdayEvents($parameters) { $name = $parameters['calendar_id']; if (strpos('birthday_', $name) != 0) { return; } $info = explode('_', $name); $aid = $info[1]; OC_Contacts_App::getAddressbook($aid); foreach (OC_Contacts_VCard::all($aid) as $card) { $vcard = OC_VObject::parse($card['carddata']); if (!$vcard) { continue; } $birthday = $vcard->BDAY; if ($birthday) { $date = new DateTime($birthday); $vevent = new OC_VObject('VEVENT'); $vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV)); $vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE); $vevent->setString('DURATION', 'P1D'); // DESCRIPTION? $vevent->setString('RRULE', 'FREQ=YEARLY'); $title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday')); $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title); } } }
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 = OC_Contacts_App::getTypesOfProperty('IMPP'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); $email_types = OC_Contacts_App::getTypesOfProperty('EMAIL'); $ims = OC_Contacts_App::getIMOptions(); $im_protocols = array(); foreach ($ims as $name => $values) { $im_protocols[$name] = $values['displayname']; } $categories = OC_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('', 'jquery.multiselect'); OCP\Util::addscript('', 'oc-vcategories'); OCP\Util::addscript('contacts', 'contacts'); OCP\Util::addscript('contacts', 'expanding'); OCP\Util::addscript('contacts', 'jquery.combobox'); OCP\Util::addscript('files', 'jquery.fileupload'); OCP\Util::addscript('core', 'jquery.inview'); OCP\Util::addscript('contacts', 'jquery.Jcrop'); OCP\Util::addscript('contacts', 'jquery.multi-autocomplete');
/** * @brief Move card(s) to an address book * @param integer $aid Address book id * @param $id Array or integer of cards to be moved. * @return boolean * */ public static function moveToAddressBook($aid, $id, $isAddressbook = false) { OC_Contacts_App::getAddressbook($aid); // check for user ownership. $addressbook = OC_Contacts_Addressbook::find($aid); if ($addressbook['userid'] != OCP\User::getUser()) { $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) { return false; } } if (is_array($id)) { foreach ($id as $index => $cardId) { $card = self::find($cardId); if (!$card) { unset($id[$index]); } $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != OCP\User::getUser()) { $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $cardId, OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) { unset($id[$index]); } } } $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')'; try { $stmt = OCP\DB::prepare($prep); //$aid = array($aid); $vals = array_merge((array) $aid, $id); $result = $stmt->execute($vals); } catch (Exception $e) { OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR); OCP\Util::writeLog('contacts', __METHOD__ . ', ids: ' . join(',', $vals), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', __METHOD__ . ', SQL:' . $prep, OCP\Util::DEBUG); return false; } } else { $stmt = null; if ($isAddressbook) { $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `addressbookid` = ?'); } else { $card = self::find($id); if (!$card) { return false; } $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != OCP\User::getUser()) { $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) { return false; } } $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` = ?'); } try { $result = $stmt->execute(array($aid, $id)); } catch (Exception $e) { OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id, OCP\Util::DEBUG); return false; } } OC_Hook::emit('OC_Contacts_VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id)); OC_Contacts_Addressbook::touch($aid); return true; }
OCP\Util::writeLog('contacts', 'ajax/loadcard.php: ' . $msg, OCP\Util::DEBUG); exit; } function debug($msg) { OCP\Util::writeLog('contacts', 'ajax/loadcard.php: ' . $msg, OCP\Util::DEBUG); } // foreach ($_POST as $key=>$element) { // debug('_POST: '.$key.'=>'.$element); // } // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $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); $adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); $email_types = OC_Contacts_App::getTypesOfProperty('EMAIL'); $tmpl = new OCP\Template('contacts', 'part.contact'); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('adr_types', $adr_types); $tmpl->assign('phone_types', $phone_types); $tmpl->assign('email_types', $email_types); $tmpl->assign('id', ''); $page = $tmpl->fetchPage(); OCP\JSON::success(array('data' => array('page' => $page)));
// 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(OC_Contacts_Addressbook::activeIds()); // first active addressbook. } $isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false; $fn = trim($_POST['fn']); $n = trim($_POST['n']); $vcard = new OC_VObject('VCARD'); $vcard->setUID(); $vcard->setString('FN', $fn); $vcard->setString('N', $n); $id = null; try { $id = OC_Contacts_VCard::add($aid, $vcard, null, $isnew); } catch (Exception $e) { bailOut($e->getMessage()); } if (!$id) { bailOut('There was an error adding the contact.'); } $lastmodified = OC_Contacts_App::lastModified($vcard); if (!$lastmodified) { $lastmodified = new DateTime(); } OCP\JSON::success(array('data' => array('id' => $id, 'aid' => $aid, 'lastmodified' => $lastmodified->format('U'))));
<?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' => OC_Contacts_App::$l10n->t('No ID provided')))); exit; } $vcard = OC_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' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));
protected static function getVCategories() { if (is_null(self::$categories)) { self::$categories = new OC_VCategories('contacts'); } return self::$categories; }
function bailOut($msg) { OCP\JSON::error(array('data' => array('message' => $msg))); OCP\Util::writeLog('contacts', 'ajax/addcontact.php: ' . $msg, OCP\Util::DEBUG); exit; } // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); $aid = isset($_POST['aid']) ? $_POST['aid'] : null; if (!$aid) { $aid = min(OC_Contacts_Addressbook::activeIds()); // first active addressbook. } OC_Contacts_App::getAddressbook($aid); // is owner access check $isnew = isset($_POST['isnew']) ? $_POST['isnew'] : false; $fn = trim($_POST['fn']); $n = trim($_POST['n']); $vcard = new OC_VObject('VCARD'); $vcard->setUID(); $vcard->setString('FN', $fn); $vcard->setString('N', $n); $id = OC_Contacts_VCard::add($aid, $vcard, null, $isnew); if (!$id) { OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('There was an error adding the contact.')))); OCP\Util::writeLog('contacts', 'ajax/addcontact.php: Recieved non-positive ID on adding card: ' . $id, OCP\Util::ERROR); exit; } OCP\JSON::success(array('data' => array('id' => $id)));
$vcard = OC_Contacts_App::getContactVCard($id); if (is_null($vcard)) { bailOut(OC_Contacts_App::$l10n->t('Error parsing VCard for ID: "' . $id . '"')); } $details = OC_Contacts_VCard::structureContact($vcard); // Some Google exported files have no FN field. /*if(!isset($details['FN'])) { $fn = ''; if(isset($details['N'])) { $details['FN'] = array(implode(' ', $details['N'][0]['value'])); } elseif(isset($details['EMAIL'])) { $details['FN'] = array('value' => $details['EMAIL'][0]['value']); } else { $details['FN'] = array('value' => OC_Contacts_App::$l10n->t('Unknown')); } }*/ // Make up for not supporting the 'N' field in earlier version. if (!isset($details['N'])) { $details['N'] = array(); $details['N'][0] = array($details['FN'][0]['value'], '', '', '', ''); } // Don't wanna transfer the photo in a json string. if (isset($details['PHOTO'])) { $details['PHOTO'] = true; //unset($details['PHOTO']); } else { $details['PHOTO'] = false; } $details['id'] = $id; OC_Contacts_App::setLastModifiedHeader($vcard); OCP\JSON::success(array('data' => $details));
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 ($image->loadFromBase64($contact->getAsString('PHOTO'))) { // OK $etag = md5($contact->getAsString('PHOTO')); } else { // Logo :-/ if ($image->loadFromBase64($contact->getAsString('LOGO'))) { // OK $etag = md5($contact->getAsString('LOGO')); } } if ($image->valid()) { $modified = OC_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); } $max_size = 200; if ($image->width() > $max_size || $image->height() > $max_size) { $image->resize($max_size); }
//, $parameters); break; } $line = count($vcard->children) - 1; // Apparently Sabre_VObject_Parameter doesn't do well with // multiple values or I don't know how to do it. Tanghus. foreach ($parameters as $key => $element) { if (is_array($element)) { // NOTE: Maybe this doesn't only apply for TYPE? // And it probably shouldn't be done here anyways :-/ foreach ($element as $e) { if ($e != '' && !is_null($e)) { if (trim($e)) { $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $e); } } } } else { if (trim($element)) { $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $element); } } } $checksum = md5($vcard->children[$line]->serialize()); try { OC_Contacts_VCard::edit($id, $vcard); } catch (Exception $e) { bailOut($e->getMessage()); } OCP\JSON::success(array('data' => array('checksum' => $checksum, 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'))));
<?php /** * 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'); $addressbook = OC_Contacts_App::getAddressbook($_GET['bookid']); $tmpl = new OCP\Template("contacts", "part.editaddressbook"); $tmpl->assign('new', false); $tmpl->assign('addressbook', $addressbook); $tmpl->printPage();
* 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/>. * */ function bailOut($msg) { OCP\JSON::error(array('data' => array('message' => $msg))); OCP\Util::writeLog('contacts', 'ajax/saveproperty.php: ' . $msg, OCP\Util::DEBUG); exit; } // Init owncloud // Check if we are a user OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); OCP\JSON::callCheck(); $id = isset($_POST['id']) ? $_POST['id'] : null; if (!$id) { bailOut(OC_Contacts_App::$l10n->t('id is not set.')); } $card = OC_Contacts_App::getContactObject($id); OC_Contacts_VCard::delete($id); OCP\JSON::success(array('data' => array('id' => $id)));
if (strtolower($a['name']) == strtolower($b['name'])) { return 0; } return strtolower($a['name']) < strtolower($b['name']) ? -1 : 1; } function cmpcontacts($a, $b) { if (strtolower($a['fullname']) == strtolower($b['fullname'])) { return 0; } return strtolower($a['fullname']) < strtolower($b['fullname']) ? -1 : 1; } OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); $offset = isset($_GET['offset']) ? $_GET['offset'] : null; $category = isset($_GET['category']) ? $_GET['category'] : null; $list = array(); $catmgr = OC_Contacts_App::getVCategories(); if (is_null($category)) { $categories = $catmgr->categories(OC_VCategories::FORMAT_MAP); uasort($categories, 'cmpcategories'); foreach ($categories as $category) { $list[] = array('name' => $category['name'], 'contacts' => $catmgr->itemsForCategory($category['name'], array('tablename' => '*PREFIX*contacts_cards', 'fields' => array('id')))); } uasort($list['contacts'], 'cmpcontacts'); } else { $list[$category] = $catmgr->itemsForCategory($category, '*PREFIX*contacts_cards', 50, $offset); uasort($list[$category], 'cmpcontacts'); } session_write_close(); OCP\JSON::success(array('data' => array('categories' => $list)));
/** * 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; $nl = "\n"; if (isset($bookid)) { $addressbook = OC_Contacts_App::getAddressbook($bookid); //$cardobjects = OC_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 = OC_Contacts_VCard::all($bookid, $start, $batchsize)) { foreach ($cardobjects as $card) { echo $card['carddata'] . $nl; } $start += $batchsize; } } elseif (isset($contactid)) { $data = OC_Contacts_App::getContactObject($contactid); header('Content-Type: text/vcard'); header('Content-Disposition: inline; filename=' . str_replace(' ', '_', $data['fullname']) . '.vcf'); echo $data['carddata']; }
} if (!extension_loaded('gd') || !function_exists('gd_info')) { OCP\Util::writeLog('contacts', 'photo.php. GD module not installed', OCP\Util::DEBUG); getStandardImage(); } $contact = OC_Contacts_App::getContactVCard($id); $image = new OC_Image(); if (!$image) { getStandardImage(); } // invalid vcard if (is_null($contact)) { OCP\Util::writeLog('contacts', 'photo.php. The VCard for ID ' . $id . ' is not RFC compatible', OCP\Util::ERROR); } else { OCP\Response::enableCaching($caching); OC_Contacts_App::setLastModifiedHeader($contact); // Photo :-) if ($image->loadFromBase64($contact->getAsString('PHOTO'))) { // OK OCP\Response::setETagHeader(md5($contact->getAsString('PHOTO'))); } else { // Logo :-/ if ($image->loadFromBase64($contact->getAsString('LOGO'))) { // OK OCP\Response::setETagHeader(md5($contact->getAsString('LOGO'))); } } if ($image->valid()) { $max_size = 200; if ($image->width() > $max_size || $image->height() > $max_size) { $image->resize($max_size);
debug('Adding parameter: ' . $key); if (is_array($parameter)) { foreach ($parameter as $val) { if (trim($val)) { debug('Adding parameter: ' . $key . '=>' . $val); $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($val)))); } } } else { if (trim($parameter)) { $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($parameter)))); } } } } break; default: $vcard->setString($name, $value); break; } // Do checksum and be happy $checksum = md5($vcard->children[$line]->serialize()); } //debug('New checksum: '.$checksum); try { OC_Contacts_VCard::edit($id, $vcard); } catch (Exception $e) { bailOut($e->getMessage()); } OCP\JSON::success(array('data' => array('line' => $line, 'checksum' => $checksum, 'oldchecksum' => $_POST['checksum'], 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'))));
bailOut(OC_Contacts_App::$l10n->t('checksum is not set.')); } if (is_array($value)) { $value = array_map('strip_tags', $value); ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form! //if($name == 'CATEGORIES') { // $value = OC_Contacts_VCard::escapeDelimiters($value, ','); //} else { $value = OC_Contacts_VCard::escapeDelimiters($value, ';'); //} } else { $value = trim(strip_tags($value)); } $vcard = OC_Contacts_App::getContactVCard($id); $line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum); if (is_null($line)) { bailOut(OC_Contacts_App::$l10n->t('Information about vCard is incorrect. Please reload the page: ') . $checksum); } $element = $vcard->children[$line]->name; if ($element != $name) { bailOut(OC_Contacts_App::$l10n->t('Something went FUBAR. ') . $name . ' != ' . $element); } /* preprocessing value */ switch ($element) { case 'BDAY': $date = new DateTime($value); //$vcard->setDateTime('BDAY', $date, Sabre_VObject_Element_DateTime::DATE); $value = $date->format('Y-m-d'); break; case 'FN':
<?php foreach ($_['contacts'] as $contact) { $display = trim($contact['fullname']); if (!$display) { $vcard = OC_Contacts_App::getContactVCard($contact['id']); if (!is_null($vcard)) { $struct = OC_Contacts_VCard::structureContact($vcard); $display = isset($struct['EMAIL'][0]) ? $struct['EMAIL'][0]['value'] : '[UNKNOWN]'; } } ?> <li role="button" book-id="<?php echo $contact['addressbookid']; ?> " data-id="<?php echo $contact['id']; ?> "><a href="index.php?id=<?php echo $contact['id']; ?> "><?php echo htmlspecialchars($display); ?> </a></li> <?php }
<?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(); $bookid = $_POST['bookid']; $book = OC_Contacts_App::getAddressbook($bookid); // is owner access check if (!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) { OCP\Util::writeLog('contacts', 'ajax/activation.php: Error activating addressbook: ' . $bookid, OCP\Util::ERROR); OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.')))); exit; } OCP\JSON::success(array('active' => OC_Contacts_Addressbook::isActive($bookid), 'bookid' => $bookid, 'book' => $book));
if (!$property) { OC_Cache::remove($tmpkey); bailOut(OC_Contacts_App::$l10n->t('Error getting PHOTO property.')); } $property->setValue($image->__toString()); $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); $vcard->addProperty('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType())); } $now = new DateTime(); $vcard->setString('REV', $now->format(DateTime::W3C)); if (!OC_Contacts_VCard::edit($id, $vcard)) { bailOut(OC_Contacts_App::$l10n->t('Error saving contact.')); } OCP\JSON::success(array('data' => array('id' => $id, 'width' => $image->width(), 'height' => $image->height(), 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U')))); } else { bailOut(OC_Contacts_App::$l10n->t('Error resizing image')); } } else { bailOut(OC_Contacts_App::$l10n->t('Error cropping image')); } } else { bailOut(OC_Contacts_App::$l10n->t('Error creating temporary image')); } } else { bailOut(OC_Contacts_App::$l10n->t('Error finding image: ') . $tmpkey); } OC_Cache::remove($tmpkey);
/** * @brief Move card(s) to an address book * @param integer $aid Address book id * @param $id Array or integer of cards to be moved. * @return boolean * */ public static function moveToAddressBook($aid, $id) { OC_Contacts_App::getAddressbook($aid); // check for user ownership. if (is_array($id)) { $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN (' . $id_sql . ')'; try { $stmt = OCP\DB::prepare($prep); //$aid = array($aid); $vals = array_merge((array) $aid, $id); $result = $stmt->execute($vals); } catch (Exception $e) { OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook:, exception: ' . $e->getMessage(), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook, ids: ' . join(',', $vals), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', 'SQL:' . $prep, OCP\Util::DEBUG); return false; } } else { try { $stmt = OCP\DB::prepare('UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?'); $result = $stmt->execute(array($aid, $id)); } catch (Exception $e) { OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook:, exception: ' . $e->getMessage(), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook, id: ' . $id, OCP\Util::DEBUG); return false; } } OC_Contacts_Addressbook::touch($aid); return true; }
OCP\JSON::checkAppEnabled('contacts'); function bailOut($msg) { OCP\JSON::error(array('data' => array('message' => $msg))); OCP\Util::writeLog('contacts', 'ajax/currentphoto.php: ' . $msg, OCP\Util::ERROR); exit; } function debug($msg) { OCP\Util::writeLog('contacts', 'ajax/currentphoto.php: ' . $msg, OCP\Util::DEBUG); } if (!isset($_GET['id'])) { bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.')); } $tmpfname = tempnam(get_temp_dir(), "occOrig"); $contact = OC_Contacts_App::getContactVCard($_GET['id']); $image = new OC_Image(); if (!$image) { bailOut(OC_Contacts_App::$l10n->t('Error loading image.')); } // invalid vcard if (is_null($contact)) { bailOut(OC_Contacts_App::$l10n->t('Error reading contact photo.')); } else { if (!$image->loadFromBase64($contact->getAsString('PHOTO'))) { $image->loadFromBase64($contact->getAsString('LOGO')); } if ($image->valid()) { if ($image->save($tmpfname)) { OCP\JSON::success(array('data' => array('id' => $_GET['id'], 'tmp' => $tmpfname))); exit;