summaryrefslogtreecommitdiffstats
path: root/apps/contacts/ajax
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-04-22 20:44:11 +0200
committerThomas Tanghus <thomas@tanghus.net>2012-04-22 20:47:24 +0200
commite8f062dc935b6bd9b8047594affda491c659b79a (patch)
treed209e80d63e42459c51db7417d9c4cfb29b91aac /apps/contacts/ajax
parent8a6cb23170b95336770bc4dcd6d58583de82815e (diff)
downloadnextcloud-server-e8f062dc935b6bd9b8047594affda491c659b79a.tar.gz
nextcloud-server-e8f062dc935b6bd9b8047594affda491c659b79a.zip
Contacts:
- Added overlay toolbar to contact photo with 'Delete current', 'Edit current', 'Load from OC_Filesystem' and 'Upload' options. - Made action icons translucent instead of hiding them.
Diffstat (limited to 'apps/contacts/ajax')
-rw-r--r--apps/contacts/ajax/currentphoto.php68
-rw-r--r--apps/contacts/ajax/loadphoto.php4
-rw-r--r--apps/contacts/ajax/oc_photo.php75
-rw-r--r--apps/contacts/ajax/uploadphoto.php13
4 files changed, 147 insertions, 13 deletions
diff --git a/apps/contacts/ajax/currentphoto.php b/apps/contacts/ajax/currentphoto.php
new file mode 100644
index 00000000000..15cb6c7a083
--- /dev/null
+++ b/apps/contacts/ajax/currentphoto.php
@@ -0,0 +1,68 @@
+<?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
+require_once('../../../lib/base.php');
+
+// Check if we are a user
+// Firefox and Konqueror tries to download application/json for me. --Arthur
+OC_JSON::setContentTypeHeader('text/plain');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('contacts','ajax/currentphoto.php: '.$msg, OC_Log::ERROR);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('contacts','ajax/currentphoto.php: '.$msg, OC_Log::DEBUG);
+}
+
+if (!isset($_GET['id'])) {
+ bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
+}
+
+$tmpfname = tempnam("/tmp", "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)) {
+ OC_JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpfname)));
+ exit();
+ } else {
+ bailOut(OC_Contacts_App::$l10n->t('Error saving temporary file.'));
+ }
+ } else {
+ bailOut(OC_Contacts_App::$l10n->t('The loading photo is not valid.'));
+ }
+}
+
+?>
diff --git a/apps/contacts/ajax/loadphoto.php b/apps/contacts/ajax/loadphoto.php
index 2c8bb7bf1ed..2f95cdc9328 100644
--- a/apps/contacts/ajax/loadphoto.php
+++ b/apps/contacts/ajax/loadphoto.php
@@ -38,6 +38,7 @@ function bailOut($msg) {
$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.'));
@@ -54,6 +55,9 @@ foreach($vcard->children as $property){
$tmpl = new OC_TEMPLATE("contacts", "part.contactphoto");
$tmpl->assign('id', $id);
+if($refresh) {
+ $tmpl->assign('refresh', 1);
+}
$page = $tmpl->fetchPage();
OC_JSON::success(array('data' => array('page'=>$page, 'checksum'=>$checksum)));
?>
diff --git a/apps/contacts/ajax/oc_photo.php b/apps/contacts/ajax/oc_photo.php
new file mode 100644
index 00000000000..14d77ea50b7
--- /dev/null
+++ b/apps/contacts/ajax/oc_photo.php
@@ -0,0 +1,75 @@
+<?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
+require_once('../../../lib/base.php');
+
+// Check if we are a user
+// Firefox and Konqueror tries to download application/json for me. --Arthur
+OC_JSON::setContentTypeHeader('text/plain');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('contacts');
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('contacts','ajax/oc_photo.php: '.$msg, OC_Log::ERROR);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('contacts','ajax/oc_photo.php: '.$msg, OC_Log::DEBUG);
+}
+
+if (!isset($_GET['id'])) {
+ bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.'));
+}
+
+if (!isset($_GET['path'])) {
+ bailOut(OC_Contacts_App::$l10n->t('No photo path was submitted.'));
+}
+
+$localpath = OC_Filesystem::getLocalFile($_GET['path']);
+$tmpfname = tempnam("/tmp", "occOrig");
+
+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)) {
+ 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);
+}
+if($image->save($tmpfname)) {
+ OC_JSON::success(array('data' => array('mime'=>$_SERVER['CONTENT_TYPE'], 'name'=>$fn, 'id'=>$id, 'tmp'=>$tmpfname)));
+ exit();
+} else {
+ bailOut('Couldn\'t save temporary image: '.$tmpfname);
+}
+
+?>
diff --git a/apps/contacts/ajax/uploadphoto.php b/apps/contacts/ajax/uploadphoto.php
index 9780df46476..15d4718241e 100644
--- a/apps/contacts/ajax/uploadphoto.php
+++ b/apps/contacts/ajax/uploadphoto.php
@@ -36,19 +36,6 @@ function debug($msg) {
OC_Log::write('contacts','ajax/uploadphoto.php: '.$msg, OC_Log::DEBUG);
}
-// foreach ($_SERVER as $key=>$element) {
-// debug('$_SERVER: '.$key.'=>'.$element);
-// }
-// foreach ($_GET as $key=>$element) {
-// debug('_GET: '.$key.'=>'.$element);
-// }
-// foreach ($_POST as $key=>$element) {
-// debug('_POST: '.$key.'=>'.$element);
-// }
-// foreach ($_FILES as $key=>$element) {
-// debug('_FILES: '.$key.'=>'.$element);
-// }
-
// 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) {