summaryrefslogtreecommitdiffstats
path: root/apps/gallery/ajax
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2012-03-24 18:35:16 +0100
committerBartek Przybylski <bart.p.pl@gmail.com>2012-03-24 18:35:42 +0100
commitcbdcb68c2b2bfed5d7ad3a1b0bf8b7f20210b258 (patch)
tree3e324ea6a3f122d9a1c32087c072d68a2d00cc2c /apps/gallery/ajax
parente0cbefc7275fa622f15dc1e57be67fd283f28056 (diff)
downloadnextcloud-server-cbdcb68c2b2bfed5d7ad3a1b0bf8b7f20210b258.tar.gz
nextcloud-server-cbdcb68c2b2bfed5d7ad3a1b0bf8b7f20210b258.zip
gallery sharing, experimental version
Diffstat (limited to 'apps/gallery/ajax')
-rw-r--r--apps/gallery/ajax/galleryOp.php44
-rw-r--r--apps/gallery/ajax/sharing.php118
2 files changed, 161 insertions, 1 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 459c30f6ac6..b0433898cda 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -111,9 +111,48 @@ function handleGetGallery($path) {
$p[] = utf8_encode($r['file_path']);
}
- OC_JSON::success(array('albums'=>$a, 'photos'=>$p));
+ $r = OC_Gallery_Sharing::getEntryByAlbumId($album_details['album_id']);
+ $shared = false;
+ $recursive = false;
+ $token = '';
+ if ($row = $r->fetchRow()) {
+ $shared = true;
+ $recursive = ($row['recursive'] == 1)? true : false;
+ $token = $row['token'];
+ }
+
+ OC_JSON::success(array('albums'=>$a, 'photos'=>$p, 'shared' => $shared, 'recursive' => $recursive, 'token' => $token));
+}
+
+function handleShare($path, $share, $recursive) {
+ $recursive = $recursive == 'true' ? 1 : 0;
+ $owner = OC_User::getUser();
+ $r = OC_Gallery_Album::find($owner, null, $path);
+ if ($row = $r->fetchRow()) {
+ $albumId = $row['album_id'];
+ } else {
+ OC_JSON::error(array('cause' => 'Couldn\'t find requested gallery'));
+ exit;
+ }
+
+ if ($share == false) {
+ OC_Gallery_Sharing::remove($albumId);
+ OC_JSON::success(array('sharing' => false));
+ } else { // share, yeah \o/
+ $r = OC_Gallery_Sharing::getEntryByAlbumId($albumId);
+ if (($row = $r->fetchRow())) { // update entry
+ OC_Gallery_Sharing::updateSharingByToken($row['token'], $recursive);
+ OC_JSON::success(array('sharing' => true, 'token' => $row['token'], 'recursive' => $recursive == 1 ? true : false ));
+ } else { // and new sharing entry
+ $date = new DateTime();
+ $token = md5($owner . $date->getTimestamp());
+ OC_Gallery_Sharing::addShared($token, intval($albumId), $recursive);
+ OC_JSON::success(array('sharing' => true, 'token' => $token, 'recursive' => $recursive == 1 ? true : false ));
+ }
+ }
}
+
if ($_GET['operation']) {
switch($_GET['operation']) {
case 'rename':
@@ -136,6 +175,9 @@ if ($_GET['operation']) {
case 'get_gallery':
handleGetGallery($_GET['path']);
break;
+ case 'share':
+ handleShare($_GET['path'], $_GET['share'] == 'true' ? true : false, $_GET['recursive']);
+ break;
default:
OC_JSON::error(array('cause' => 'Unknown operation'));
}
diff --git a/apps/gallery/ajax/sharing.php b/apps/gallery/ajax/sharing.php
new file mode 100644
index 00000000000..b737d8f6fee
--- /dev/null
+++ b/apps/gallery/ajax/sharing.php
@@ -0,0 +1,118 @@
+<?php
+
+/**
+* ownCloud - gallery application
+*
+* @author Bartek Przybylski
+* @copyright 2012 Bartek Przybylski bartek@alefzero.eu
+*
+* 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 Lesser General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+require_once('../../../lib/base.php');
+
+if (!isset($_GET['token']) || !isset($_GET['operation'])) {
+ OC_JSON::error(array('cause' => 'Not enought arguments'));
+ exit;
+}
+
+$operation = $_GET['operation'];
+$token = $_GET['token'];
+
+if (!OC_Gallery_Sharing::isTokenValid($token)) {
+ OC_JSON::error(array('cause' => 'Given token is not valid'));
+ exit;
+}
+
+function handleGetGallery($token, $path) {
+ $owner = OC_Gallery_Sharing::getTokenOwner($token);
+ $apath = OC_Gallery_Sharing::getPath($token);
+
+ if ($path == false)
+ $root = $apath;
+ else
+ $root = rtrim($apath,'/').$path;
+
+ $r = OC_Gallery_Album::find($owner, null, $root);
+ $albums = array();
+ $photos = array();
+ $albumId = -1;
+ if ($row = $r->fetchRow()) {
+ $albumId = $row['album_id'];
+ }
+ if ($albumId != -1) {
+
+ if (OC_Gallery_Sharing::isRecursive($token)) {
+ $r = OC_Gallery_Album::find($owner, null, null, $root);
+ while ($row = $r->fetchRow())
+ $albums[] = $row['album_name'];
+ }
+
+ $r = OC_Gallery_Photo::find($albumId);
+ while ($row = $r->fetchRow())
+ $photos[] = $row['file_path'];
+ }
+
+ OC_JSON::success(array('albums' => $albums, 'photos' => $photos));
+}
+
+function handleGetThumbnail($token, $imgpath) {
+ $owner = OC_Gallery_Sharing::getTokenOwner($token);
+ $image = OC_Gallery_Photo::getThumbnail($imgpath, $owner);
+ if ($image) {
+ OC_Response::enableCaching(3600 * 24); // 24 hour
+ $image->show();
+ }
+}
+
+function handleGetAlbumThumbnail($token, $albumname)
+{
+ $owner = OC_Gallery_Sharing::getTokenOwner($token);
+ $file = OC_Config::getValue("datadirectory").'/'. $owner .'/gallery/'.$albumname.'.png';
+ $image = new OC_Image($file);
+ if ($image->valid()) {
+ $image->centerCrop();
+ $image->resize(200);
+ $image->fixOrientation();
+ OC_Response::enableCaching(3600 * 24); // 24 hour
+ $image->show();
+ }
+}
+
+function handleGetPhoto($token, $photo) {
+ $owner = OC_Gallery_Sharing::getTokenOwner($token);
+ if (OC_User::isLoggedIn())
+ $file = OC::$CONFIG_DATADIRECTORY.urldecode($photo);
+ else
+ $file = OC::$CONFIG_DATADIRECTORY.'/'.$owner.'/files'.urldecode($photo);
+ header('Content-Type: '.OC_Image::getMimeTypeForFile($file));
+ OC_Response::sendFile($file);
+}
+
+switch ($operation) {
+ case 'get_gallery':
+ handleGetGallery($token, isset($_GET['path'])? $_GET['path'] : false);
+ break;
+ case 'get_thumbnail':
+ handleGetThumbnail($token, urldecode($_GET['img']));
+ break;
+ case 'get_album_thumbnail':
+ handleGetAlbumThumbnail($token, urldecode($_GET['albumname']));
+ break;
+ case 'get_photo':
+ handleGetPhoto($token, urldecode($_GET['photo']));
+ break;
+}
+