summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/activation.php28
-rw-r--r--apps/contacts/ajax/addbook.php20
-rw-r--r--apps/contacts/ajax/addressbook/activate.php32
-rw-r--r--apps/contacts/ajax/addressbook/add.php37
-rw-r--r--apps/contacts/ajax/addressbook/delete.php (renamed from apps/contacts/ajax/deletebook.php)8
-rw-r--r--apps/contacts/ajax/addressbook/update.php39
-rw-r--r--apps/contacts/ajax/categories/categoriesfor.php16
-rw-r--r--apps/contacts/ajax/categories/delete.php16
-rw-r--r--apps/contacts/ajax/categories/list.php2
-rw-r--r--apps/contacts/ajax/categories/rescan.php31
-rw-r--r--apps/contacts/ajax/chooseaddressbook.php14
-rw-r--r--apps/contacts/ajax/contact/add.php (renamed from apps/contacts/ajax/addcontact.php)32
-rw-r--r--apps/contacts/ajax/contact/addproperty.php (renamed from apps/contacts/ajax/addproperty.php)76
-rw-r--r--apps/contacts/ajax/contact/delete.php (renamed from apps/contacts/ajax/deletecard.php)23
-rw-r--r--apps/contacts/ajax/contact/deleteproperty.php (renamed from apps/contacts/ajax/deleteproperty.php)25
-rw-r--r--apps/contacts/ajax/contact/details.php (renamed from apps/contacts/ajax/contactdetails.php)30
-rw-r--r--apps/contacts/ajax/contact/list.php97
-rw-r--r--apps/contacts/ajax/contact/move.php29
-rw-r--r--apps/contacts/ajax/contact/saveproperty.php (renamed from apps/contacts/ajax/saveproperty.php)104
-rw-r--r--apps/contacts/ajax/contacts.php27
-rw-r--r--apps/contacts/ajax/createaddressbook.php41
-rw-r--r--apps/contacts/ajax/cropphoto.php10
-rw-r--r--apps/contacts/ajax/currentphoto.php25
-rw-r--r--apps/contacts/ajax/editaddress.php22
-rw-r--r--apps/contacts/ajax/editaddressbook.php17
-rw-r--r--apps/contacts/ajax/editname.php23
-rw-r--r--apps/contacts/ajax/importaddressbook.php24
-rw-r--r--apps/contacts/ajax/importdialog.php1
-rw-r--r--apps/contacts/ajax/loadcard.php38
-rw-r--r--apps/contacts/ajax/loadintro.php2
-rw-r--r--apps/contacts/ajax/loadphoto.php63
-rw-r--r--apps/contacts/ajax/loghandler.php44
-rw-r--r--apps/contacts/ajax/oc_photo.php29
-rw-r--r--apps/contacts/ajax/savecrop.php130
-rw-r--r--apps/contacts/ajax/updateaddressbook.php44
-rw-r--r--apps/contacts/ajax/uploadimport.php47
-rw-r--r--apps/contacts/ajax/uploadphoto.php86
37 files changed, 646 insertions, 686 deletions
diff --git a/apps/contacts/ajax/activation.php b/apps/contacts/ajax/activation.php
deleted file mode 100644
index 74cb738ab8f..00000000000
--- a/apps/contacts/ajax/activation.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
- * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
- * 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,
-));
diff --git a/apps/contacts/ajax/addbook.php b/apps/contacts/ajax/addbook.php
deleted file mode 100644
index 70f47cc8123..00000000000
--- a/apps/contacts/ajax/addbook.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
- * 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');
-$book = array(
- 'id' => 'new',
- 'displayname' => '',
-);
-$tmpl = new OCP\Template('contacts', 'part.editaddressbook');
-$tmpl->assign('new', true);
-$tmpl->assign('addressbook', $book);
-$tmpl->printPage();
-?>
diff --git a/apps/contacts/ajax/addressbook/activate.php b/apps/contacts/ajax/addressbook/activate.php
new file mode 100644
index 00000000000..a8dec21dac7
--- /dev/null
+++ b/apps/contacts/ajax/addressbook/activate.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * 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'];
+$book = OC_Contacts_App::getAddressbook($id);// is owner access check
+
+if(!OC_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' => OC_Contacts_App::$l10n->t('Error (de)activating addressbook.'))));
+ exit();
+}
+
+OCP\JSON::success(array(
+ 'active' => OC_Contacts_Addressbook::isActive($id),
+ 'id' => $id,
+ 'addressbook' => $book,
+));
diff --git a/apps/contacts/ajax/addressbook/add.php b/apps/contacts/ajax/addressbook/add.php
new file mode 100644
index 00000000000..65077743ed5
--- /dev/null
+++ b/apps/contacts/ajax/addressbook/add.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
+ * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
+ * 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\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
+require_once __DIR__.'/../loghandler.php';
+
+debug('name: '.$_POST['name']);
+
+$userid = OCP\USER::getUser();
+$name = isset($_POST['name'])?trim(strip_tags($_POST['name'])):null;
+$description = isset($_POST['description'])
+ ? trim(strip_tags($_POST['description']))
+ : null;
+
+if(is_null($name)) {
+ bailOut('Cannot add addressbook with an empty name.');
+}
+$bookid = OC_Contacts_Addressbook::add($userid, $name, $description);
+if(!$bookid) {
+ bailOut('Error adding addressbook: '.$name);
+}
+
+if(!OC_Contacts_Addressbook::setActive($bookid, 1)) {
+ bailOut('Error activating addressbook.');
+}
+$addressbook = OC_Contacts_App::getAddressbook($bookid);
+OCP\JSON::success(array('data' => array('addressbook' => $addressbook)));
diff --git a/apps/contacts/ajax/deletebook.php b/apps/contacts/ajax/addressbook/delete.php
index 4520374a23b..f59c605f4e4 100644
--- a/apps/contacts/ajax/deletebook.php
+++ b/apps/contacts/ajax/addressbook/delete.php
@@ -20,16 +20,16 @@
*
*/
-// Init owncloud
-
-
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
+require_once __DIR__.'/../loghandler.php';
-//$id = $_GET['id'];
$id = $_POST['id'];
+if(!$id) {
+ bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+}
OC_Contacts_App::getAddressbook( $id ); // is owner access check
OC_Contacts_Addressbook::delete($id);
diff --git a/apps/contacts/ajax/addressbook/update.php b/apps/contacts/ajax/addressbook/update.php
new file mode 100644
index 00000000000..0fc66c3a3bf
--- /dev/null
+++ b/apps/contacts/ajax/addressbook/update.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
+ * 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\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+require_once __DIR__.'/../loghandler.php';
+
+$id = $_POST['id'];
+$name = trim(strip_tags($_POST['name']));
+$description = trim(strip_tags($_POST['description']));
+if(!$id) {
+ bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+}
+
+if(!$name) {
+ bailOut(OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.'));
+}
+
+if(!OC_Contacts_Addressbook::edit($id, $name, $description)) {
+ bailOut(OC_Contacts_App::$l10n->t('Error updating addressbook.'));
+}
+
+if(!OC_Contacts_Addressbook::setActive($id, $_POST['active'])) {
+ bailOut(OC_Contacts_App::$l10n->t('Error (de)activating addressbook.'));
+}
+
+OC_Contacts_App::getAddressbook($id); // is owner access check
+$addressbook = OC_Contacts_App::getAddressbook($id);
+OCP\JSON::success(array(
+ 'addressbook' => $addressbook,
+));
diff --git a/apps/contacts/ajax/categories/categoriesfor.php b/apps/contacts/ajax/categories/categoriesfor.php
index 846af300de8..8391b14b545 100644
--- a/apps/contacts/ajax/categories/categoriesfor.php
+++ b/apps/contacts/ajax/categories/categoriesfor.php
@@ -12,17 +12,23 @@ 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'))));
+ 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){
- //OCP\Util::writeLog('contacts','ajax/categories/checksumfor.php: '.$property->name, OCP\Util::DEBUG);
if($property->name == 'CATEGORIES') {
$checksum = md5($property->serialize());
- OCP\JSON::success(array('data' => array('value'=>$property->value, 'checksum'=>$checksum)));
+ 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.'))));
-?>
+OCP\JSON::error(array(
+ 'data' => array(
+ 'message' => OC_Contacts_App::$l10n->t('Error setting checksum.'))));
diff --git a/apps/contacts/ajax/categories/delete.php b/apps/contacts/ajax/categories/delete.php
index bee2dbe3f6b..bc9f3e14e87 100644
--- a/apps/contacts/ajax/categories/delete.php
+++ b/apps/contacts/ajax/categories/delete.php
@@ -9,19 +9,9 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
-foreach ($_POST as $key=>$element) {
- debug('_POST: '.$key.'=>'.print_r($element, true));
-}
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/categories/delete.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-function debug($msg) {
- OCP\Util::writeLog('contacts','ajax/categories/delete.php: '.$msg, OCP\Util::DEBUG);
-}
+require_once __DIR__.'/../loghandler.php';
$categories = isset($_POST['categories'])?$_POST['categories']:null;
@@ -56,5 +46,3 @@ $catman->delete($categories, $cards);
debug('After delete: '.print_r($catman->categories(), true));
OC_Contacts_VCard::updateDataByID($cards);
OCP\JSON::success(array('data' => array('categories'=>$catman->categories())));
-
-?>
diff --git a/apps/contacts/ajax/categories/list.php b/apps/contacts/ajax/categories/list.php
index 3ae7635390c..f234116ba8c 100644
--- a/apps/contacts/ajax/categories/list.php
+++ b/apps/contacts/ajax/categories/list.php
@@ -13,5 +13,3 @@ OCP\JSON::checkAppEnabled('contacts');
$categories = OC_Contacts_App::getCategories();
OCP\JSON::success(array('data' => array('categories'=>$categories)));
-
-?>
diff --git a/apps/contacts/ajax/categories/rescan.php b/apps/contacts/ajax/categories/rescan.php
index 84a67dec0b1..a06e7803955 100644
--- a/apps/contacts/ajax/categories/rescan.php
+++ b/apps/contacts/ajax/categories/rescan.php
@@ -9,36 +9,9 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
+OCP\JSON::callCheck();
-foreach ($_POST as $key=>$element) {
- debug('_POST: '.$key.'=>'.print_r($element, true));
-}
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-function debug($msg) {
- OCP\Util::writeLog('contacts','ajax/categories/rescan.php: '.$msg, OCP\Util::DEBUG);
-}
-
-$addressbooks = OC_Contacts_Addressbook::all(OCP\USER::getUser());
-if(count($addressbooks) == 0) {
- bailOut(OC_Contacts_App::$l10n->t('No address books found.'));
-}
-$addressbookids = array();
-foreach($addressbooks as $addressbook) {
- $addressbookids[] = $addressbook['id'];
-}
-$contacts = OC_Contacts_VCard::all($addressbookids);
-if(count($contacts) == 0) {
- bailOut(OC_Contacts_App::$l10n->t('No contacts found.'));
-}
-
-OC_Contacts_App::scanCategories($contacts);
+OC_Contacts_App::scanCategories();
$categories = OC_Contacts_App::getCategories();
OCP\JSON::success(array('data' => array('categories'=>$categories)));
-
-?>
diff --git a/apps/contacts/ajax/chooseaddressbook.php b/apps/contacts/ajax/chooseaddressbook.php
deleted file mode 100644
index 9088a4e9d7d..00000000000
--- a/apps/contacts/ajax/chooseaddressbook.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
- * 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');
-
-$output = new OCP\Template("contacts", "part.chooseaddressbook");
-$output -> printpage();
diff --git a/apps/contacts/ajax/addcontact.php b/apps/contacts/ajax/contact/add.php
index d15ad8c6216..c7cec7d9461 100644
--- a/apps/contacts/ajax/addcontact.php
+++ b/apps/contacts/ajax/contact/add.php
@@ -20,14 +20,6 @@
*
*/
-// Init owncloud
-
-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');
@@ -45,14 +37,26 @@ $n = trim($_POST['n']);
$vcard = new OC_VObject('VCARD');
$vcard->setUID();
-$vcard->setString('FN',$fn);
-$vcard->setString('N',$n);
+$vcard->setString('FN', $fn);
+$vcard->setString('N', $n);
-$id = OC_Contacts_VCard::add($aid,$vcard, null, $isnew);
+$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);
+ 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 )));
+$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')
+ )
+));
diff --git a/apps/contacts/ajax/addproperty.php b/apps/contacts/ajax/contact/addproperty.php
index be9e849be72..2b80ebd58bf 100644
--- a/apps/contacts/ajax/addproperty.php
+++ b/apps/contacts/ajax/contact/addproperty.php
@@ -20,19 +20,12 @@
*
*/
-// Init owncloud
-
-
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/addproperty.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
+require_once __DIR__.'/../loghandler.php';
$id = isset($_POST['id'])?$_POST['id']:null;
$name = isset($_POST['name'])?$_POST['name']:null;
@@ -40,22 +33,27 @@ $value = isset($_POST['value'])?$_POST['value']:null;
$parameters = isset($_POST['parameters'])?$_POST['parameters']:array();
$vcard = OC_Contacts_App::getContactVCard($id);
+$l10n = OC_Contacts_App::$l10n;
if(!$name) {
- bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
+ bailOut($l10n->t('element name is not set.'));
}
if(!$id) {
- bailOut(OC_Contacts_App::$l10n->t('id is not set.'));
+ bailOut($l10n->t('id is not set.'));
}
if(!$vcard) {
- bailOut(OC_Contacts_App::$l10n->t('Could not parse contact: ').$id);
+ bailOut($l10n->t('Could not parse contact: ').$id);
}
-if(!is_array($value)){
+if(!is_array($value)) {
$value = trim($value);
- if(!$value && in_array($name, array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))) {
- bailOut(OC_Contacts_App::$l10n->t('Cannot add empty property.'));
+ if(!$value
+ && in_array(
+ $name,
+ array('TEL', 'EMAIL', 'ORG', 'BDAY', 'URL', 'NICKNAME', 'NOTE'))
+ ) {
+ bailOut($l10n->t('Cannot add empty property.'));
}
} elseif($name === 'ADR') { // only add if non-empty elements.
$empty = true;
@@ -66,7 +64,7 @@ if(!is_array($value)){
}
}
if($empty) {
- bailOut(OC_Contacts_App::$l10n->t('At least one of the address fields has to be filled out.'));
+ bailOut($l10n->t('At least one of the address fields has to be filled out.'));
}
}
@@ -75,12 +73,14 @@ $current = $vcard->select($name);
foreach($current as $item) {
$tmpvalue = (is_array($value)?implode(';', $value):$value);
if($tmpvalue == $item->value) {
- bailOut(OC_Contacts_App::$l10n->t('Trying to add duplicate property: '.$name.': '.$tmpvalue));
+ bailOut($l10n->t('Trying to add duplicate property: '.$name.': '.$tmpvalue));
}
}
if(is_array($value)) {
- ksort($value); // NOTE: Important, otherwise the compound value will be set in the order the fields appear in the form!
+ // NOTE: Important, otherwise the compound value will
+ // be set in the order the fields appear in the form!
+ ksort($value);
$value = array_map('strip_tags', $value);
} else {
$value = strip_tags($value);
@@ -108,7 +108,17 @@ switch($name) {
$value = strtolower($value);
break;
case 'TEL':
- case 'ADR': // should I delete the property if empty or throw an error?
+ case 'ADR':
+ break;
+ case 'IMPP':
+ if(is_null($parameters) || !isset($parameters['X-SERVICE-TYPE'])) {
+ bailOut(OC_Contacts_App::$l10n->t('Missing IM parameter.'));
+ }
+ $impp = OC_Contacts_App::getIMOptions($parameters['X-SERVICE-TYPE']);
+ if(is_null($impp)) {
+ bailOut(OC_Contacts_App::$l10n->t('Unknown IM: '.$parameters['X-SERVICE-TYPE']));
+ }
+ $value = $impp['protocol'] . ':' . $value;
break;
}
@@ -123,24 +133,36 @@ switch($name) {
$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.
+// 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) && strtoupper($key) == 'TYPE') {
+ if(is_array($element) /*&& strtoupper($key) == 'TYPE'*/) {
// 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)){
- $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$e);
+ foreach($element as $e) {
+ if($e != '' && !is_null($e)) {
+ if(trim($e)) {
+ $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $e);
+ }
}
}
} else {
- $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key,$element);
+ if(trim($element)) {
+ $vcard->children[$line]->parameters[] = new Sabre_VObject_Parameter($key, $element);
+ }
}
}
$checksum = md5($vcard->children[$line]->serialize());
-if(!OC_Contacts_VCard::edit($id,$vcard)) {
- bailOut(OC_Contacts_App::$l10n->t('Error adding contact property: '.$name));
+try {
+ OC_Contacts_VCard::edit($id, $vcard);
+} catch(Exception $e) {
+ bailOut($e->getMessage());
}
-OCP\JSON::success(array('data' => array( 'checksum' => $checksum )));
+OCP\JSON::success(array(
+ 'data' => array(
+ 'checksum' => $checksum,
+ 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'))
+ )
+);
diff --git a/apps/contacts/ajax/deletecard.php b/apps/contacts/ajax/contact/delete.php
index f998185be41..e73f34f898d 100644
--- a/apps/contacts/ajax/deletecard.php
+++ b/apps/contacts/ajax/contact/delete.php
@@ -4,6 +4,7 @@
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack mail@jakobsack.de
+ * @copyright 2012 Thomas Tanghus (thomas@tanghus.net)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -19,25 +20,25 @@
* 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();
+require_once __DIR__.'/../loghandler.php';
+
$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);
+try {
+ OC_Contacts_VCard::delete($id);
+} catch(Exception $e) {
+ $msg = $e->getMessage();
+ OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$msg,
+ OCP\Util::DEBUG);
+ OCP\Util::writeLog('contacts', __METHOD__.', id'.$id, OCP\Util::DEBUG);
+ bailOut($msg);
+}
OCP\JSON::success(array('data' => array( 'id' => $id )));
diff --git a/apps/contacts/ajax/deleteproperty.php b/apps/contacts/ajax/contact/deleteproperty.php
index 95fd43e0d95..b76b6e55ede 100644
--- a/apps/contacts/ajax/deleteproperty.php
+++ b/apps/contacts/ajax/contact/deleteproperty.php
@@ -20,30 +20,35 @@
*
*/
-// Init owncloud
-
-
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
+require_once __DIR__.'/../loghandler.php';
+
$id = $_POST['id'];
$checksum = $_POST['checksum'];
+$l10n = OC_Contacts_App::$l10n;
$vcard = OC_Contacts_App::getContactVCard( $id );
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
-if(is_null($line)){
- OCP\JSON::error(array('data' => array( 'message' => OC_Contacts_App::$l10n->t('Information about vCard is incorrect. Please reload the page.'))));
+if(is_null($line)) {
+ bailOut($l10n->t('Information about vCard is incorrect. Please reload the page.'));
exit();
}
unset($vcard->children[$line]);
-if(!OC_Contacts_VCard::edit($id,$vcard)) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error deleting contact property.'))));
- OCP\Util::writeLog('contacts','ajax/deleteproperty.php: Error deleting contact property', OCP\Util::ERROR);
- exit();
+try {
+ OC_Contacts_VCard::edit($id, $vcard);
+} catch(Exception $e) {
+ bailOut($e->getMessage());
}
-OCP\JSON::success(array('data' => array( 'id' => $id )));
+OCP\JSON::success(array(
+ 'data' => array(
+ 'id' => $id,
+ 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'),
+ )
+));
diff --git a/apps/contacts/ajax/contactdetails.php b/apps/contacts/ajax/contact/details.php
index 657dc5d586c..5bf337e645e 100644
--- a/apps/contacts/ajax/contactdetails.php
+++ b/apps/contacts/ajax/contact/details.php
@@ -20,13 +20,7 @@
*
*/
-// Init owncloud
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/contactdetails.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
+require_once __DIR__.'/../loghandler.php';
// Check if we are a user
OCP\JSON::checkLoggedIn();
@@ -36,24 +30,13 @@ $id = isset($_GET['id'])?$_GET['id']:null;
if(is_null($id)) {
bailOut(OC_Contacts_App::$l10n->t('Missing ID'));
}
-$vcard = OC_Contacts_App::getContactVCard( $id );
+$card = OC_Contacts_VCard::find($id);
+$vcard = OC_VObject::parse($card['carddata']);
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();
@@ -67,6 +50,13 @@ if(isset($details['PHOTO'])) {
} else {
$details['PHOTO'] = false;
}
+$lastmodified = OC_Contacts_App::lastModified($vcard);
+if(!$lastmodified) {
+ $lastmodified = new DateTime();
+}
$details['id'] = $id;
+$details['displayname'] = $card['fullname'];
+$details['addressbookid'] = $card['addressbookid'];
+$details['lastmodified'] = $lastmodified->format('U');
OC_Contacts_App::setLastModifiedHeader($vcard);
OCP\JSON::success(array('data' => $details));
diff --git a/apps/contacts/ajax/contact/list.php b/apps/contacts/ajax/contact/list.php
new file mode 100644
index 00000000000..4e2509d8d5a
--- /dev/null
+++ b/apps/contacts/ajax/contact/list.php
@@ -0,0 +1,97 @@
+<?php
+/**
+ * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+function cmp($a, $b)
+{
+ if ($a['displayname'] == $b['displayname']) {
+ return 0;
+ }
+ return ($a['displayname'] < $b['displayname']) ? -1 : 1;
+}
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::checkAppEnabled('contacts');
+
+$start = isset($_GET['startat'])?$_GET['startat']:0;
+$aid = isset($_GET['aid'])?$_GET['aid']:null;
+
+if(is_null($aid)) {
+ // Called initially to get the active addressbooks.
+ $active_addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
+} else {
+ // called each time more contacts has to be shown.
+ $active_addressbooks = array(OC_Contacts_Addressbook::find($aid));
+}
+
+
+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']
+ = $addressbook['displayname'];
+ $contacts_addressbook[$addressbook['id']]['permissions']
+ = isset($addressbook['permissions'])
+ ? $addressbook['permissions']
+ : '0';
+ }
+}
+
+$contacts_alphabet = array();
+
+// get next 50 for each addressbook.
+foreach($ids as $id) {
+ if($id) {
+ $contacts_alphabet = array_merge(
+ $contacts_alphabet,
+ OC_Contacts_VCard::all($id, $start, 50)
+ );
+ }
+}
+// Our new array for the contacts sorted by addressbook
+if($contacts_alphabet) {
+ foreach($contacts_alphabet as $contact) {
+ // This should never execute.
+ if(!isset($contacts_addressbook[$contact['addressbookid']])) {
+ $contacts_addressbook[$contact['addressbookid']] = array(
+ 'contacts' => array('type' => 'book',)
+ );
+ }
+ $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]';
+ }
+ }
+ $contacts_addressbook[$contact['addressbookid']]['contacts'][] = array(
+ 'type' => 'contact',
+ 'id' => $contact['id'],
+ 'addressbookid' => $contact['addressbookid'],
+ 'displayname' => htmlspecialchars($display),
+ 'permissions' =>
+ isset($contacts_addressbook[$contact['addressbookid']]['permissions'])
+ ? $contacts_addressbook[$contact['addressbookid']]['permissions']
+ : '0',
+ );
+ }
+}
+unset($contacts_alphabet);
+uasort($contacts_addressbook, 'cmp');
+
+OCP\JSON::success(array('data' => array('entries' => $contacts_addressbook)));
+
diff --git a/apps/contacts/ajax/contact/move.php b/apps/contacts/ajax/contact/move.php
new file mode 100644
index 00000000000..053343c47ed
--- /dev/null
+++ b/apps/contacts/ajax/contact/move.php
@@ -0,0 +1,29 @@
+<?php
+/**
+* @author Victor Dubiniuk
+* Copyright (c) 2012 Victor Dubiniuk <victor.dubiniuk@gmail.com>
+* Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+* 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
+OC_Contacts_App::getAddressbook($aid);
+try {
+ OC_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,)));
+}
+
+OC_JSON::success(array('data' => array('ids' => $id,))); \ No newline at end of file
diff --git a/apps/contacts/ajax/saveproperty.php b/apps/contacts/ajax/contact/saveproperty.php
index a27b5489ce6..7ae183538b6 100644
--- a/apps/contacts/ajax/saveproperty.php
+++ b/apps/contacts/ajax/contact/saveproperty.php
@@ -20,37 +20,17 @@
*
*/
-// Init owncloud
-
+require_once __DIR__.'/../loghandler.php';
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/saveproperty.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-function debug($msg) {
- OCP\Util::writeLog('contacts','ajax/saveproperty.php: '.$msg, OCP\Util::DEBUG);
-}
-// foreach ($_POST as $key=>$element) {
-// debug('_POST: '.$key.'=>'.print_r($element, true));
-// }
-
$id = isset($_POST['id'])?$_POST['id']:null;
$name = isset($_POST['name'])?$_POST['name']:null;
$value = isset($_POST['value'])?$_POST['value']:null;
$parameters = isset($_POST['parameters'])?$_POST['parameters']:null;
$checksum = isset($_POST['checksum'])?$_POST['checksum']:null;
-// if(!is_null($parameters)) {
-// debug('parameters: '.count($parameters));
-// foreach($parameters as $key=>$val ) {
-// debug('parameter: '.$key.'=>'.implode('/',$val));
-// }
-// }
if(!$name) {
bailOut(OC_Contacts_App::$l10n->t('element name is not set.'));
@@ -61,9 +41,11 @@ if(!$id) {
if(!$checksum) {
bailOut(OC_Contacts_App::$l10n->t('checksum is not set.'));
}
-if(is_array($value)){
+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!
+ // NOTE: Important, otherwise the compound value will be
+ // set in the order the fields appear in the form!
+ ksort($value);
//if($name == 'CATEGORIES') {
// $value = OC_Contacts_VCard::escapeDelimiters($value, ',');
//} else {
@@ -76,19 +58,22 @@ if(is_array($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);
+ 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);
+ 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':
@@ -103,6 +88,16 @@ switch($element) {
case 'EMAIL':
$value = strtolower($value);
break;
+ case 'IMPP':
+ if(is_null($parameters) || !isset($parameters['X-SERVICE-TYPE'])) {
+ bailOut(OC_Contacts_App::$l10n->t('Missing IM parameter.'));
+ }
+ $impp = OC_Contacts_App::getIMOptions($parameters['X-SERVICE-TYPE']);
+ if(is_null($impp)) {
+ bailOut(OC_Contacts_App::$l10n->t('Unknown IM: '.$parameters['X-SERVICE-TYPE']));
+ }
+ $value = $impp['protocol'] . ':' . $value;
+ break;
}
if(!$value) {
@@ -112,28 +107,23 @@ if(!$value) {
/* setting value */
switch($element) {
case 'BDAY':
- // I don't use setDateTime() because that formats it as YYYYMMDD instead of YYYY-MM-DD
- // which is what the RFC recommends.
+ // I don't use setDateTime() because that formats it as YYYYMMDD instead
+ // of YYYY-MM-DD which is what the RFC recommends.
$vcard->children[$line]->setValue($value);
$vcard->children[$line]->parameters = array();
- $vcard->children[$line]->add(new Sabre_VObject_Parameter('VALUE', 'DATE'));
+ $vcard->children[$line]->add(
+ new Sabre_VObject_Parameter('VALUE', 'DATE')
+ );
debug('Setting value:'.$name.' '.$vcard->children[$line]);
break;
- case 'FN':
- case 'N':
- case 'ORG':
- case 'NOTE':
- case 'NICKNAME':
- debug('Setting string:'.$name.' '.$value);
- $vcard->setString($name, $value);
- break;
case 'CATEGORIES':
debug('Setting string:'.$name.' '.$value);
$vcard->children[$line]->setValue($value);
break;
case 'EMAIL':
case 'TEL':
- case 'ADR': // should I delete the property if empty or throw an error?
+ case 'ADR':
+ case 'IMPP':
debug('Setting element: (EMAIL/TEL/ADR)'.$element);
$vcard->children[$line]->setValue($value);
$vcard->children[$line]->parameters = array();
@@ -141,22 +131,46 @@ if(!$value) {
debug('Setting parameters: '.$parameters);
foreach($parameters as $key => $parameter) {
debug('Adding parameter: '.$key);
- foreach($parameter as $val) {
- debug('Adding parameter: '.$key.'=>'.$val);
- $vcard->children[$line]->add(new Sabre_VObject_Parameter($key, strtoupper(strip_tags($val))));
+ 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:
+ debug('Setting string:'.$name.' '.$value);
+ $vcard->setString($name, $value);
+ break;
}
// Do checksum and be happy
$checksum = md5($vcard->children[$line]->serialize());
}
//debug('New checksum: '.$checksum);
-if(!OC_Contacts_VCard::edit($id,$vcard)) {
- bailOut(OC_Contacts_App::$l10n->t('Error updating contact property.'));
- exit();
+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'] )));
+OCP\JSON::success(array('data' => array(
+ 'line' => $line,
+ 'checksum' => $checksum,
+ 'oldchecksum' => $_POST['checksum'],
+ 'lastmodified' => OC_Contacts_App::lastModified($vcard)->format('U'),
+)));
diff --git a/apps/contacts/ajax/contacts.php b/apps/contacts/ajax/contacts.php
deleted file mode 100644
index 45c54f90bce..00000000000
--- a/apps/contacts/ajax/contacts.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011 Thomas Tanghus <thomas@tanghus.net>
- * 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');
-
-$ids = OC_Contacts_Addressbook::activeIds(OCP\USER::getUser());
-$allcontacts = OC_Contacts_VCard::all($ids);
-$contacts = array();
-foreach($allcontacts as $contact) { // try to conserve some memory
- $contacts[] = array('id' => $contact['id'], 'addressbookid' => $contact['addressbookid'], 'fullname' => $contact['fullname']);
-}
-unset($allcontacts);
-$addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
-
-$tmpl = new OCP\Template("contacts", "part.contacts");
-$tmpl->assign('contacts', $contacts);
-$page = $tmpl->fetchPage();
-
-OCP\JSON::success(array('data' => array( 'page' => $page )));
-?>
diff --git a/apps/contacts/ajax/createaddressbook.php b/apps/contacts/ajax/createaddressbook.php
deleted file mode 100644
index 616766bb1a0..00000000000
--- a/apps/contacts/ajax/createaddressbook.php
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
- * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
- * 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\JSON::checkLoggedIn();
-OCP\JSON::checkAppEnabled('contacts');
-OCP\JSON::callCheck();
-
-$userid = OCP\USER::getUser();
-$name = trim(strip_tags($_POST['name']));
-if(!$name) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot add addressbook with an empty name.'))));
- OCP\Util::writeLog('contacts','ajax/createaddressbook.php: Cannot add addressbook with an empty name: '.strip_tags($_POST['name']), OCP\Util::ERROR);
- exit();
-}
-$bookid = OC_Contacts_Addressbook::add($userid, $name, null);
-if(!$bookid) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error adding addressbook.'))));
- OCP\Util::writeLog('contacts','ajax/createaddressbook.php: Error adding addressbook: '.$_POST['name'], OCP\Util::ERROR);
- exit();
-}
-
-if(!OC_Contacts_Addressbook::setActive($bookid, 1)) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Error activating addressbook.'))));
- OCP\Util::writeLog('contacts','ajax/createaddressbook.php: Error activating addressbook: '.$bookid, OCP\Util::ERROR);
- //exit();
-}
-$addressbook = OC_Contacts_App::getAddressbook($bookid);
-$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields');
-$tmpl->assign('addressbook', $addressbook);
-OCP\JSON::success(array(
- 'page' => $tmpl->fetchPage(),
- 'addressbook' => $addressbook,
-));
diff --git a/apps/contacts/ajax/cropphoto.php b/apps/contacts/ajax/cropphoto.php
index 7006c6fc1ff..eb9f1fcdb5d 100644
--- a/apps/contacts/ajax/cropphoto.php
+++ b/apps/contacts/ajax/cropphoto.php
@@ -20,19 +20,15 @@
*
*/
-// Init owncloud
-
-
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
-$tmp_path = strip_tags($_GET['tmp_path']);
-$requesttoken = strip_tags($_GET['requesttoken']);
+$tmpkey = $_GET['tmpkey'];
+$requesttoken = $_GET['requesttoken'];
$id = $_GET['id'];
-OCP\Util::writeLog('contacts','ajax/cropphoto.php: tmp_path: '.$tmp_path.', exists: '.file_exists($tmp_path), OCP\Util::DEBUG);
$tmpl = new OCP\Template("contacts", "part.cropphoto");
-$tmpl->assign('tmp_path', $tmp_path);
+$tmpl->assign('tmpkey', $tmpkey);
$tmpl->assign('id', $id);
$tmpl->assign('requesttoken', $requesttoken);
$page = $tmpl->fetchPage();
diff --git a/apps/contacts/ajax/currentphoto.php b/apps/contacts/ajax/currentphoto.php
index d0654b17d64..96080e661ef 100644
--- a/apps/contacts/ajax/currentphoto.php
+++ b/apps/contacts/ajax/currentphoto.php
@@ -19,43 +19,30 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
-// Init owncloud
-//require_once('../../../lib/base.php');
-// Check if we are a user
// Firefox and Konqueror tries to download application/json for me. --Arthur
OCP\JSON::setContentTypeHeader('text/plain');
OCP\JSON::checkLoggedIn();
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);
-}
+require_once 'loghandler.php';
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 {
+ $image = new OC_Image();
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)));
+ $tmpkey = 'contact-photo-'.$contact->getAsString('UID');
+ if(OC_Cache::set($tmpkey, $image->data(), 600)) {
+ OCP\JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpkey)));
exit();
} else {
bailOut(OC_Contacts_App::$l10n->t('Error saving temporary file.'));
@@ -64,5 +51,3 @@ if( is_null($contact)) {
bailOut(OC_Contacts_App::$l10n->t('The loading photo is not valid.'));
}
}
-
-?>
diff --git a/apps/contacts/ajax/editaddress.php b/apps/contacts/ajax/editaddress.php
index 9fb35a0b5f7..b5e4b72ed57 100644
--- a/apps/contacts/ajax/editaddress.php
+++ b/apps/contacts/ajax/editaddress.php
@@ -20,12 +20,22 @@ if($checksum) {
$line = OC_Contacts_App::getPropertyLineByChecksum($vcard, $checksum);
$element = $vcard->children[$line];
$adr = OC_Contacts_VCard::structureProperty($element);
- $tmpl->assign('adr',$adr);
+ $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);
}
-$tmpl->assign('id',$id);
-$tmpl->assign('adr_types',$adr_types);
+$tmpl->assign('id', $id);
+$tmpl->assign('adr_types', $adr_types);
-$tmpl->printpage();
-
-?>
+$page = $tmpl->fetchPage();
+OCP\JSON::success(array('data' => array('page'=>$page, 'checksum'=>$checksum)));
diff --git a/apps/contacts/ajax/editaddressbook.php b/apps/contacts/ajax/editaddressbook.php
deleted file mode 100644
index 7a9b757ae0d..00000000000
--- a/apps/contacts/ajax/editaddressbook.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
- * 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();
-?>
diff --git a/apps/contacts/ajax/editname.php b/apps/contacts/ajax/editname.php
index dc64eeb5101..eb55634011d 100644
--- a/apps/contacts/ajax/editname.php
+++ b/apps/contacts/ajax/editname.php
@@ -9,19 +9,12 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/editname.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-function debug($msg) {
- OCP\Util::writeLog('contacts','ajax/editname.php: '.$msg, OCP\Util::DEBUG);
-}
+require_once 'loghandler.php';
$tmpl = new OCP\Template("contacts", "part.edit_name_dialog");
$id = isset($_GET['id'])?$_GET['id']:'';
-debug('id: '.$id);
+
if($id) {
$vcard = OC_Contacts_App::getContactVCard($id);
$name = array('', '', '', '', '');
@@ -31,13 +24,11 @@ if($id) {
$name = OC_Contacts_VCard::structureProperty($property);
}
}
- $tmpl->assign('name',$name);
- $tmpl->assign('id',$id);
+ $name = array_map('htmlspecialchars', $name['value']);
+ $tmpl->assign('name', $name, false);
+ $tmpl->assign('id', $id, false);
} else {
bailOut(OC_Contacts_App::$l10n->t('Contact ID is missing.'));
- //$addressbooks = OC_Contacts_Addressbook::active(OCP\USER::getUser());
- //$tmpl->assign('addressbooks', $addressbooks);
}
-$tmpl->printpage();
-
-?>
+$page = $tmpl->fetchPage();
+OCP\JSON::success(array('data' => array('page'=>$page)));
diff --git a/apps/contacts/ajax/importaddressbook.php b/apps/contacts/ajax/importaddressbook.php
deleted file mode 100644
index 3c01e24a185..00000000000
--- a/apps/contacts/ajax/importaddressbook.php
+++ /dev/null
@@ -1,24 +0,0 @@
-<?php
-/**
- * Copyright (c) 2012 Georg Ehrke <ownclouddev at georgswebsite dot de>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-OCP\JSON::checkLoggedIn();
-OCP\App::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);
-
-$tmpl = new OCP\Template('contacts', 'part.importaddressbook');
-$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
-$tmpl->assign('requesttoken', $_SERVER['HTTP_REQUESTTOKEN']);
-$tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize));
-$tmpl->printpage();
-?>
diff --git a/apps/contacts/ajax/importdialog.php b/apps/contacts/ajax/importdialog.php
index 5f8805a6106..691522538fb 100644
--- a/apps/contacts/ajax/importdialog.php
+++ b/apps/contacts/ajax/importdialog.php
@@ -13,4 +13,3 @@ $tmpl = new OCP\Template('contacts', 'part.import');
$tmpl->assign('path', $_POST['path']);
$tmpl->assign('filename', $_POST['filename']);
$tmpl->printpage();
-?>
diff --git a/apps/contacts/ajax/loadcard.php b/apps/contacts/ajax/loadcard.php
index 09b6bbe0cf9..82501ffd2ff 100644
--- a/apps/contacts/ajax/loadcard.php
+++ b/apps/contacts/ajax/loadcard.php
@@ -20,20 +20,6 @@
*
*/
-// Init owncloud
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- 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');
@@ -41,22 +27,32 @@ 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);
+$requesttoken = $_GET['requesttoken'];
$freeSpace=OC_Filesystem::free_space('/');
-$freeSpace=max($freeSpace,0);
-$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace);
+$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');
+$impp_types = OC_Contacts_App::getTypesOfProperty('IMPP');
+$ims = OC_Contacts_App::getIMOptions();
+$im_protocols = array();
+foreach($ims as $name => $values) {
+ $im_protocols[$name] = $values['displayname'];
+}
-$tmpl = new OCP\Template('contacts','part.contact');
+$tmpl = new OCP\Template('contacts', 'part.contact');
$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize);
$tmpl->assign('requesttoken', $_SERVER['HTTP_REQUESTTOKEN']);
$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','');
+$tmpl->assign('adr_types', $adr_types);
+$tmpl->assign('phone_types', $phone_types);
+$tmpl->assign('email_types', $email_types);
+$tmpl->assign('impp_types', $impp_types, false);
+$tmpl->assign('im_protocols', $im_protocols, false);
+$tmpl->assign('requesttoken', $requesttoken);
+$tmpl->assign('id', '');
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/loadintro.php b/apps/contacts/ajax/loadintro.php
index 6e8fcc4b049..1da08950ca0 100644
--- a/apps/contacts/ajax/loadintro.php
+++ b/apps/contacts/ajax/loadintro.php
@@ -25,7 +25,7 @@ OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
-$tmpl = new OCP\Template('contacts','part.no_contacts');
+$tmpl = new OCP\Template('contacts', 'part.no_contacts');
$page = $tmpl->fetchPage();
OCP\JSON::success(array('data' => array( 'page' => $page )));
diff --git a/apps/contacts/ajax/loadphoto.php b/apps/contacts/ajax/loadphoto.php
deleted file mode 100644
index ef429e82891..00000000000
--- a/apps/contacts/ajax/loadphoto.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-/**
- * ownCloud - Addressbook
- *
- * @author Thomas Tanghus
- * @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
- *
- * 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/>.
- *
- */
-// Init owncloud
-
-// Check if we are a user
-OCP\JSON::checkLoggedIn();
-OCP\JSON::checkAppEnabled('contacts');
-
-// foreach ($_POST as $key=>$element) {
-// OCP\Util::writeLog('contacts','ajax/savecrop.php: '.$key.'=>'.$element, OCP\Util::DEBUG);
-// }
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/loadphoto.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-
-$image = null;
-
-$id = isset($_GET['id']) ? $_GET['id'] : '';
-$refresh = isset($_GET['refresh']) ? true : false;
-
-if($id == '') {
- bailOut(OC_Contacts_App::$l10n->t('Missing contact id.'));
-}
-
-$checksum = '';
-$vcard = OC_Contacts_App::getContactVCard( $id );
-foreach($vcard->children as $property){
- if($property->name == 'PHOTO') {
- $checksum = md5($property->serialize());
- break;
- }
-}
-
-$tmpl = new OCP\Template("contacts", "part.contactphoto");
-$tmpl->assign('id', $id);
-if($refresh) {
- $tmpl->assign('refresh', 1);
-}
-$page = $tmpl->fetchPage();
-OCP\JSON::success(array('data' => array('page'=>$page, 'checksum'=>$checksum)));
-?>
diff --git a/apps/contacts/ajax/loghandler.php b/apps/contacts/ajax/loghandler.php
new file mode 100644
index 00000000000..be4b98c1112
--- /dev/null
+++ b/apps/contacts/ajax/loghandler.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @author Thomas Tanghus
+ * @copyright 2012 Thomas Tanghus <thomas@tanghus.net>
+ *
+ * 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/>.
+ *
+ */
+
+function bailOut($msg, $tracelevel=1, $debuglevel=OCP\Util::ERROR)
+{
+ OCP\JSON::error(array('data' => array('message' => $msg)));
+ debug($msg, $tracelevel, $debuglevel);
+ exit();
+}
+
+function debug($msg, $tracelevel=0, $debuglevel=OCP\Util::DEBUG)
+{
+ if(PHP_VERSION >= "5.4") {
+ $call = debug_backtrace(false, $tracelevel+1);
+ } else {
+ $call = debug_backtrace(false);
+ }
+ error_log('trace: '.print_r($call, true));
+ $call = $call[$tracelevel];
+ if($debuglevel !== false) {
+ OCP\Util::writeLog('contacts',
+ $call['file'].'. Line: '.$call['line'].': '.$msg,
+ $debuglevel);
+ }
+}
diff --git a/apps/contacts/ajax/oc_photo.php b/apps/contacts/ajax/oc_photo.php
index 903d2aedfbe..fe37b530f82 100644
--- a/apps/contacts/ajax/oc_photo.php
+++ b/apps/contacts/ajax/oc_photo.php
@@ -20,19 +20,9 @@
*
*/
// Check if we are a user
-// Firefox and Konqueror tries to download application/json for me. --Arthur
-OCP\JSON::setContentTypeHeader('text/plain');
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
-OCP\JSON::callCheck();
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/oc_photo.php: '.$msg, OCP\Util::ERROR);
- exit();
-}
-function debug($msg) {
- OCP\Util::writeLog('contacts','ajax/oc_photo.php: '.$msg, OCP\Util::DEBUG);
-}
+require_once 'loghandler.php';
if(!isset($_GET['id'])) {
bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
@@ -43,31 +33,30 @@ if(!isset($_GET['path'])) {
}
$localpath = OC_Filesystem::getLocalFile($_GET['path']);
-$tmpfname = tempnam(get_temp_dir(), "occOrig");
+$tmpkey = 'contact-photo-'.$_GET['id'];
if(!file_exists($localpath)) {
bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:').$localpath);
}
-file_put_contents($tmpfname, file_get_contents($localpath));
$image = new OC_Image();
if(!$image) {
bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
-if(!$image->loadFromFile($tmpfname)) {
+if(!$image->loadFromFile($localpath)) {
bailOut(OC_Contacts_App::$l10n->t('Error loading image.'));
}
if($image->width() > 400 || $image->height() > 400) {
$image->resize(400); // Prettier resizing than with browser and saves bandwidth.
}
if(!$image->fixOrientation()) { // No fatal error so we don't bail out.
- debug('Couldn\'t save correct image orientation: '.$tmpfname);
+ OCP\Util::writeLog('contacts',
+ 'ajax/oc_photo.php: Couldn\'t save correct image orientation: '.$localpath,
+ OCP\Util::DEBUG);
}
-if($image->save($tmpfname)) {
- OCP\JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpfname)));
+if(OC_Cache::set($tmpkey, $image->data(), 600)) {
+ OCP\JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpkey)));
exit();
} else {
- bailOut('Couldn\'t save temporary image: '.$tmpfname);
+ bailOut('Couldn\'t save temporary image: '.$tmpkey);
}
-
-?>
diff --git a/apps/contacts/ajax/savecrop.php b/apps/contacts/ajax/savecrop.php
index a5517c5d843..2483d0f7128 100644
--- a/apps/contacts/ajax/savecrop.php
+++ b/apps/contacts/ajax/savecrop.php
@@ -18,23 +18,16 @@
* 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/>.
*
- * TODO: Translatable strings.
- * Remember to delete tmp file at some point.
*/
-
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/savecrop.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-
// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
// Firefox and Konqueror tries to download application/json for me. --Arthur
-OCP\JSON::setContentTypeHeader('text/plain');
+OCP\JSON::setContentTypeHeader('text/plain; charset=utf-8');
+
+require_once 'loghandler.php';
$image = null;
@@ -44,88 +37,85 @@ $y1 = (isset($_POST['y1']) && $_POST['y1']) ? $_POST['y1'] : 0;
//$y2 = isset($_POST['y2']) ? $_POST['y2'] : -1;
$w = (isset($_POST['w']) && $_POST['w']) ? $_POST['w'] : -1;
$h = (isset($_POST['h']) && $_POST['h']) ? $_POST['h'] : -1;
-$tmp_path = isset($_POST['tmp_path']) ? $_POST['tmp_path'] : '';
+$tmpkey = isset($_POST['tmpkey']) ? $_POST['tmpkey'] : '';
$id = isset($_POST['id']) ? $_POST['id'] : '';
-if($tmp_path == '') {
- bailOut('Missing path to temporary file.');
+if($tmpkey == '') {
+ bailOut('Missing key to temporary file.');
}
if($id == '') {
bailOut('Missing contact id.');
}
-OCP\Util::writeLog('contacts','savecrop.php: files: '.$tmp_path.' exists: '.file_exists($tmp_path), OCP\Util::DEBUG);
+OCP\Util::writeLog('contacts', 'savecrop.php: key: '.$tmpkey, OCP\Util::DEBUG);
-if(file_exists($tmp_path)) {
+$data = OC_Cache::get($tmpkey);
+if($data) {
$image = new OC_Image();
- if($image->loadFromFile($tmp_path)) {
+ if($image->loadFromdata($data)) {
$w = ($w != -1 ? $w : $image->width());
$h = ($h != -1 ? $h : $image->height());
- OCP\Util::writeLog('contacts','savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h, OCP\Util::DEBUG);
+ OCP\Util::writeLog('contacts',
+ 'savecrop.php, x: '.$x1.' y: '.$y1.' w: '.$w.' h: '.$h,
+ OCP\Util::DEBUG);
if($image->crop($x1, $y1, $w, $h)) {
- if(($image->width() <= 200 && $image->height() <= 200) || $image->resize(200)) {
- $tmpfname = tempnam(get_temp_dir(), "occCropped"); // create a new file because of caching issues.
- if($image->save($tmpfname)) {
- unlink($tmp_path);
- $card = OC_Contacts_App::getContactVCard($id);
- if(!$card) {
- unlink($tmpfname);
- bailOut('Error getting contact object.');
- }
- if($card->__isset('PHOTO')) {
- OCP\Util::writeLog('contacts','savecrop.php: PHOTO property exists.', OCP\Util::DEBUG);
- $property = $card->__get('PHOTO');
- if(!$property) {
- unlink($tmpfname);
- bailOut('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());
- $card->__set('PHOTO', $property);
- } else {
- OCP\Util::writeLog('contacts','savecrop.php: files: Adding PHOTO property.', OCP\Util::DEBUG);
- $card->addProperty('PHOTO', $image->__toString(), array('ENCODING' => 'b', 'TYPE' => $image->mimeType()));
- }
- $now = new DateTime;
- $card->setString('REV', $now->format(DateTime::W3C));
- if(!OC_Contacts_VCard::edit($id,$card)) {
- bailOut('Error saving contact.');
+ if(($image->width() <= 200 && $image->height() <= 200)
+ || $image->resize(200)) {
+ $vcard = OC_Contacts_App::getContactVCard($id);
+ if(!$vcard) {
+ OC_Cache::remove($tmpkey);
+ bailOut(OC_Contacts_App::$l10n
+ ->t('Error getting contact object.'));
+ }
+ if($vcard->__isset('PHOTO')) {
+ OCP\Util::writeLog('contacts',
+ 'savecrop.php: PHOTO property exists.',
+ OCP\Util::DEBUG);
+ $property = $vcard->__get('PHOTO');
+ if(!$property) {
+ OC_Cache::remove($tmpkey);
+ bailOut(OC_Contacts_App::$l10n
+ ->t('Error getting PHOTO property.'));
}
- unlink($tmpfname);
- //$result=array( "status" => "success", 'mime'=>$image->mimeType(), 'tmp'=>$tmp_path);
- $tmpl = new OCP\Template("contacts", "part.contactphoto");
- $tmpl->assign('tmp_path', $tmpfname);
- $tmpl->assign('mime', $image->mimeType());
- $tmpl->assign('id', $id);
- $tmpl->assign('refresh', true);
- $tmpl->assign('width', $image->width());
- $tmpl->assign('height', $image->height());
- $page = $tmpl->fetchPage();
- OCP\JSON::success(array('data' => array('page'=>$page, 'tmp'=>$tmpfname)));
- exit();
+ $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 {
- if(file_exists($tmpfname)) {
- unlink($tmpfname);
- }
- bailOut('Error saving temporary image');
+ 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('Error resizing image');
+ bailOut(OC_Contacts_App::$l10n->t('Error resizing image'));
}
} else {
- bailOut('Error cropping image');
+ bailOut(OC_Contacts_App::$l10n->t('Error cropping image'));
}
} else {
- bailOut('Error creating temporary image');
+ bailOut(OC_Contacts_App::$l10n->t('Error creating temporary image'));
}
} else {
- bailOut('Error finding image: '.$tmp_path);
-}
-
-if($tmp_path != '' && file_exists($tmp_path)) {
- unlink($tmp_path);
+ bailOut(OC_Contacts_App::$l10n->t('Error finding image: ').$tmpkey);
}
-?>
+OC_Cache::remove($tmpkey);
diff --git a/apps/contacts/ajax/updateaddressbook.php b/apps/contacts/ajax/updateaddressbook.php
deleted file mode 100644
index 68fe8f81211..00000000000
--- a/apps/contacts/ajax/updateaddressbook.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-/**
- * Copyright (c) 2011-2012 Thomas Tanghus <thomas@tanghus.net>
- * 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\JSON::checkLoggedIn();
-OCP\JSON::checkAppEnabled('contacts');
-OCP\JSON::callCheck();
-
-$bookid = $_POST['id'];
-OC_Contacts_App::getAddressbook($bookid); // is owner access check
-
-$name = trim(strip_tags($_POST['name']));
-if(!$name) {
- OCP\JSON::error(array('data' => array('message' => OC_Contacts_App::$l10n->t('Cannot update addressbook with an empty name.'))));
- OCP\Util::writeLog('contacts','ajax/updateaddressbook.php: Cannot update addressbook with an empty name: '.strip_tags($_POST['name']), OCP\Util::ERROR);
- exit();
-}
-
-if(!OC_Contacts_Addressbook::edit($bookid, $name, null)) {
- OCP\JSON::error(array('data' => array('message' => $l->t('Error updating addressbook.'))));
- OCP\Util::writeLog('contacts','ajax/updateaddressbook.php: Error adding addressbook: ', OCP\Util::ERROR);
- //exit();
-}
-
-if(!OC_Contacts_Addressbook::setActive($bookid, $_POST['active'])) {
- OCP\JSON::error(array('data' => array('message' => $l->t('Error (de)activating addressbook.'))));
- OCP\Util::writeLog('contacts','ajax/updateaddressbook.php: Error (de)activating addressbook: '.$bookid, OCP\Util::ERROR);
- //exit();
-}
-
-$addressbook = OC_Contacts_App::getAddressbook($bookid);
-$tmpl = new OCP\Template('contacts', 'part.chooseaddressbook.rowfields');
-$tmpl->assign('addressbook', $addressbook);
-OCP\JSON::success(array(
- 'page' => $tmpl->fetchPage(),
- 'addressbook' => $addressbook,
-));
diff --git a/apps/contacts/ajax/uploadimport.php b/apps/contacts/ajax/uploadimport.php
index 4c3f5eadf08..87032b731a5 100644
--- a/apps/contacts/ajax/uploadimport.php
+++ b/apps/contacts/ajax/uploadimport.php
@@ -24,56 +24,57 @@
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
-function bailOut($msg) {
- OCP\JSON::error(array('data' => array('message' => $msg)));
- OCP\Util::writeLog('contacts','ajax/uploadimport.php: '.$msg, OCP\Util::ERROR);
- exit();
-}
+require_once 'loghandler.php';
+
+$l10n = OC_Contacts_App::$l10n;
$view = OCP\Files::getStorage('contacts');
+if(!$view->file_exists('imports')) {
+ $view->mkdir('imports');
+}
$tmpfile = md5(rand());
// If it is a Drag'n'Drop transfer it's handled here.
$fn = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false);
if($fn) {
- if($view->file_put_contents('/'.$tmpfile, file_get_contents('php://input'))) {
- OCP\JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
+ if($view->file_put_contents('/imports/'.$fn, file_get_contents('php://input'))) {
+ OCP\JSON::success(array('data' => array('file'=>$tmpfile, 'name'=>$fn)));
exit();
} else {
- bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
+ bailOut($l10n->t('Error uploading contacts to storage.'));
}
}
// File input transfers are handled here
if (!isset($_FILES['importfile'])) {
- OCP\Util::writeLog('contacts','ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG);
- OCP\JSON::error(array('data' => array( 'message' => 'No file was uploaded. Unknown error' )));
+ OCP\Util::writeLog('contacts',
+ 'ajax/uploadphoto.php: No file was uploaded. Unknown error.',
+ OCP\Util::DEBUG);
+ OCP\JSON::error(array('
+ data' => array(
+ 'message' => 'No file was uploaded. Unknown error' )));
exit();
}
$error = $_FILES['importfile']['error'];
if($error !== UPLOAD_ERR_OK) {
$errors = array(
- 0=>OC_Contacts_App::$l10n->t("There is no error, the file uploaded with success"),
- 1=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
- 2=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
- 3=>OC_Contacts_App::$l10n->t("The uploaded file was only partially uploaded"),
- 4=>OC_Contacts_App::$l10n->t("No file was uploaded"),
- 6=>OC_Contacts_App::$l10n->t("Missing a temporary folder")
+ 0=>$l10n->t("There is no error, the file uploaded with success"),
+ 1=>$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
+ 2=>$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
+ 3=>$l10n->t("The uploaded file was only partially uploaded"),
+ 4=>$l10n->t("No file was uploaded"),
+ 6=>$l10n->t("Missing a temporary folder")
);
bailOut($errors[$error]);
}
$file=$_FILES['importfile'];
-$tmpfname = tempnam(get_temp_dir(), "occOrig");
if(file_exists($file['tmp_name'])) {
- if($view->file_put_contents('/'.$tmpfile, file_get_contents($file['tmp_name']))) {
- OCP\JSON::success(array('data' => array('path'=>'', 'file'=>$tmpfile)));
+ if($view->file_put_contents('/imports/'.$file['name'], file_get_contents($file['tmp_name']))) {
+ OCP\JSON::success(array('data' => array('file'=>$file['name'], 'name'=>$file['name'])));
} else {
- bailOut(OC_Contacts_App::$l10n->t('Error uploading contacts to storage.'));
+ bailOut($l10n->t('Error uploading contacts to storage.'));
}
} else {
bailOut('Temporary file: \''.$file['tmp_name'].'\' has gone AWOL?');
}
-
-
-?>
diff --git a/apps/contacts/ajax/uploadphoto.php b/apps/contacts/ajax/uploadphoto.php
index 52e25e4a335..34830b291d2 100644
--- a/apps/contacts/ajax/uploadphoto.php
+++ b/apps/contacts/ajax/uploadphoto.php
@@ -19,96 +19,98 @@
* 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/uploadphoto.php: '.$msg, OCP\Util::DEBUG);
- exit();
-}
-function debug($msg) {
- OCP\Util::writeLog('contacts','ajax/uploadphoto.php: '.$msg, OCP\Util::DEBUG);
-}
-OCP\JSON::setContentTypeHeader('text/plain');
+
+// Check if we are a user
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('contacts');
OCP\JSON::callCheck();
+// Firefox and Konqueror tries to download application/json for me. --Arthur
+OCP\JSON::setContentTypeHeader('text/plain; charset=utf-8');
+require_once 'loghandler.php';
+$l10n = OC_Contacts_App::$l10n;
// If it is a Drag'n'Drop transfer it's handled here.
$fn = (isset($_SERVER['HTTP_X_FILE_NAME']) ? $_SERVER['HTTP_X_FILE_NAME'] : false);
if ($fn) {
- // AJAX call
if (!isset($_GET['id'])) {
- OCP\Util::writeLog('contacts','ajax/uploadphoto.php: No contact ID was submitted.', OCP\Util::DEBUG);
- OCP\JSON::error(array('data' => array( 'message' => 'No contact ID was submitted.' )));
- exit();
+ bailOut($l10n->t('No contact ID was submitted.'));
}
$id = $_GET['id'];
- $tmpfname = tempnam(get_temp_dir(), 'occOrig');
- file_put_contents($tmpfname, file_get_contents('php://input'));
+ $tmpkey = 'contact-photo-'.md5($fn);
+ $data = file_get_contents('php://input');
$image = new OC_Image();
- if($image->loadFromFile($tmpfname)) {
+ sleep(1); // Apparently it needs time to load the data.
+ if($image->loadFromData($data)) {
if($image->width() > 400 || $image->height() > 400) {
$image->resize(400); // Prettier resizing than with browser and saves bandwidth.
}
if(!$image->fixOrientation()) { // No fatal error so we don't bail out.
- debug('Couldn\'t save correct image orientation: '.$tmpfname);
+ debug('Couldn\'t save correct image orientation: '.$tmpkey);
}
- if($image->save($tmpfname)) {
- OCP\JSON::success(array('data' => array('mime'=>$_SERVER['CONTENT_TYPE'], 'name'=>$fn, 'id'=>$id, 'tmp'=>$tmpfname)));
+ if(OC_Cache::set($tmpkey, $image->data(), 600)) {
+ OCP\JSON::success(array(
+ 'data' => array(
+ 'mime'=>$_SERVER['CONTENT_TYPE'],
+ 'name'=>$fn,
+ 'id'=>$id,
+ 'tmp'=>$tmpkey)));
exit();
} else {
- bailOut('Couldn\'t save temporary image: '.$tmpfname);
+ bailOut($l10n->t('Couldn\'t save temporary image: ').$tmpkey);
}
} else {
- bailOut('Couldn\'t load temporary image: '.$file['tmp_name']);
+ bailOut($l10n->t('Couldn\'t load temporary image: ').$tmpkey);
}
}
-
+// Uploads from file dialog are handled here.
if (!isset($_POST['id'])) {
- OCP\Util::writeLog('contacts','ajax/uploadphoto.php: No contact ID was submitted.', OCP\Util::DEBUG);
- OCP\JSON::error(array('data' => array( 'message' => 'No contact ID was submitted.' )));
- exit();
+ bailOut($l10n->t('No contact ID was submitted.'));
}
if (!isset($_FILES['imagefile'])) {
- OCP\Util::writeLog('contacts','ajax/uploadphoto.php: No file was uploaded. Unknown error.', OCP\Util::DEBUG);
- OCP\JSON::error(array('data' => array( 'message' => 'No file was uploaded. Unknown error' )));
- exit();
+ bailOut($l10n->t('No file was uploaded. Unknown error'));
}
+
$error = $_FILES['imagefile']['error'];
if($error !== UPLOAD_ERR_OK) {
$errors = array(
- 0=>OC_Contacts_App::$l10n->t("There is no error, the file uploaded with success"),
- 1=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
- 2=>OC_Contacts_App::$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
- 3=>OC_Contacts_App::$l10n->t("The uploaded file was only partially uploaded"),
- 4=>OC_Contacts_App::$l10n->t("No file was uploaded"),
- 6=>OC_Contacts_App::$l10n->t("Missing a temporary folder")
+ 0=>$l10n->t("There is no error, the file uploaded with success"),
+ 1=>$l10n->t("The uploaded file exceeds the upload_max_filesize directive in php.ini").ini_get('upload_max_filesize'),
+ 2=>$l10n->t("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"),
+ 3=>$l10n->t("The uploaded file was only partially uploaded"),
+ 4=>$l10n->t("No file was uploaded"),
+ 6=>$l10n->t("Missing a temporary folder")
);
bailOut($errors[$error]);
}
$file=$_FILES['imagefile'];
-$tmpfname = tempnam(get_temp_dir(), "occOrig");
if(file_exists($file['tmp_name'])) {
+ $tmpkey = 'contact-photo-'.md5(basename($file['tmp_name']));
$image = new OC_Image();
if($image->loadFromFile($file['tmp_name'])) {
if($image->width() > 400 || $image->height() > 400) {
$image->resize(400); // Prettier resizing than with browser and saves bandwidth.
}
if(!$image->fixOrientation()) { // No fatal error so we don't bail out.
- debug('Couldn\'t save correct image orientation: '.$tmpfname);
+ debug('Couldn\'t save correct image orientation: '.$tmpkey);
}
- if($image->save($tmpfname)) {
- OCP\JSON::success(array('data' => array('mime'=>$file['type'],'size'=>$file['size'],'name'=>$file['name'], 'id'=>$_POST['id'], 'tmp'=>$tmpfname)));
+ if(OC_Cache::set($tmpkey, $image->data(), 600)) {
+ OCP\JSON::success(array(
+ 'data' => array(
+ 'mime'=>$file['type'],
+ 'size'=>$file['size'],
+ 'name'=>$file['name'],
+ 'id'=>$_POST['id'],
+ 'tmp'=>$tmpkey,
+ )));
exit();
} else {
- bailOut('Couldn\'t save temporary image: '.$tmpfname);
+ bailOut($l10n->t('Couldn\'t save temporary image: ').$tmpkey);
}
} else {
- bailOut('Couldn\'t load temporary image: '.$file['tmp_name']);
+ bailOut($l10n->t('Couldn\'t load temporary image: ').$file['tmp_name']);
}
} else {
bailOut('Temporary file: \''.$file['tmp_name'].'\' has gone AWOL?');
}
-
-?>