]> source.dussan.org Git - nextcloud-server.git/commitdiff
Gallery: Use App storage instead of contructing our own path
authorBart Visscher <bartv@thisnet.nl>
Wed, 9 May 2012 20:47:57 +0000 (22:47 +0200)
committerBart Visscher <bartv@thisnet.nl>
Thu, 10 May 2012 07:14:27 +0000 (09:14 +0200)
apps/gallery/ajax/galleryOp.php
apps/gallery/ajax/sharing.php
apps/gallery/index.php
apps/gallery/lib/album.php
apps/gallery/lib/photo.php
apps/gallery/lib/scanner.php

index 0cd825f3e50d938cc0b11a2cbe78ba4aafa33231..b49e52f0bd2d49c560874e87b37492eab558aea2 100755 (executable)
@@ -42,7 +42,8 @@ function handleRemove($name) {
 
 function handleGetThumbnails($albumname) {
   OCP\Response::enableCaching(3600 * 24); // 24 hour
-  $thumbnail = OC::$CONFIG_DATADIRECTORY.'/../gallery/'.urldecode($albumname).'.png';
+  $view = OCP\App::getStorage('gallery');
+  $thumbnail = $view->fopen(urldecode($albumname).'.png', 'r');
   header('Content-Type: '.OC_Image::getMimeTypeForFile($thumbnail));
   OCP\Response::sendFile($thumbnail);
 }
index 1223320120b4aa7a41150542a9afea658974ba16..304757b9e9141712eaf8b87b365d174629665fea 100755 (executable)
@@ -80,7 +80,8 @@ function handleGetThumbnail($token, $imgpath) {
 function handleGetAlbumThumbnail($token, $albumname)
 {
   $owner = OC_Gallery_Sharing::getTokenOwner($token);
-  $file = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/'.$albumname.'.png';
+  $view = OCP\App::getStorage('gallery');
+  $file = $view->fopen($albumname.'.png', 'r');
   $image = new OC_Image($file);
   if ($image->valid()) {
     $image->centerCrop();
@@ -93,7 +94,8 @@ function handleGetAlbumThumbnail($token, $albumname)
 
 function handleGetPhoto($token, $photo) {
   $owner = OC_Gallery_Sharing::getTokenOwner($token);
-  $file = OCP\Config::getSystemValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$owner.'/files'.urldecode($photo);
+  $view = OCP\App::getStorage('files');
+  $file = $view->fopen(urldecode($photo), 'r');
   header('Content-Type: '.OC_Image::getMimeTypeForFile($file));
   OCP\Response::sendFile($file);
 }
index e47fb3db5d6726275074d1b9e6dffb2057ea3fd6..a9fe200c4e4ba44e2e683c9bb0a0f53b39e347f1 100755 (executable)
@@ -27,10 +27,6 @@ OCP\User::checkLoggedIn();
 OCP\App::checkAppEnabled('gallery');
 OCP\App::setActiveNavigationEntry( 'gallery_index' );
 
-if (!file_exists(OCP\Config::getSystemValue("datadirectory").'/'. OCP\USER::getUser() .'/gallery')) {
-  mkdir(OCP\Config::getSystemValue("datadirectory").'/'. OCP\USER::getUser() .'/gallery');
-}
-
 if (!isset($_GET['view'])) {
   $result = OC_Gallery_Album::find(OCP\USER::getUser());
 
index ac6cacbe01f509e99c1aaa3f9b608e7deb3cd455..7b9036742a64a1d7b40f44d8a820e5d4bacb6f53 100755 (executable)
@@ -92,9 +92,8 @@ class OC_Gallery_Album {
        }
 
        public static function changeThumbnailPath($oldname, $newname) {
-                
-               $thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/';
-               rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png');
+               $view = OCP\App::getStorage('gallery');
+               $view->rename($oldname.'.png', $newname.'.png');
        }
 
        public static function getAlbumSize($id){
index 99384af621ac513ed384a42cb4cd5e3b545aeada..b4b37236b0e71fcec00dcbfeaa71617edf90f47c 100755 (executable)
@@ -68,17 +68,17 @@ class OC_Gallery_Photo {
 
        public static function getThumbnail($image_name, $owner = null) {
                if (!$owner) $owner = OCP\USER::getUser();
-               $save_dir = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/';
-               $save_dir .= dirname($image_name). '/';
-               $image_path = $image_name;
-               $thumb_file = $save_dir . basename($image_name);
-               if (!is_dir($save_dir)) {
-                       mkdir($save_dir, 0777, true);
+               $view = OCP\App::getStorage('gallery');
+               $save_dir = dirname($image_name);
+               if (!$view->is_dir($save_dir)) {
+                       $view->mkdir($save_dir);
                }
-               if (file_exists($thumb_file)) {
-                       $image = new OC_Image($thumb_file);
+               $view->chroot($view->getRoot().'/'.$save_dir);
+               $thumb_file = basename($image_name);
+               if ($view->file_exists($thumb_file)) {
+                       $image = new OC_Image($view->fopen($thumb_file, 'r'));
                } else {
-                       $image_path = OC_Filesystem::getLocalFile($image_path);
+                       $image_path = OC_Filesystem::getLocalFile($image_name);
                        if(!file_exists($image_path)) {
                                return null;
                        }
@@ -86,7 +86,7 @@ class OC_Gallery_Photo {
                        if ($image->valid()) {
                                $image->centerCrop(200);
                                $image->fixOrientation();
-                               $image->save($thumb_file);
+                               $image->save($view->getLocalFile($thumb_file));
                        }
                }
                if ($image->valid()) {
index 7a137cb3f508eeffdb2856e81d1df1635d43e041..e11ba1da454dc49ccefac1166e49a765c60c5c79 100755 (executable)
@@ -81,7 +81,8 @@ class OC_Gallery_Scanner {
                                $image->destroy();
                        }
                }
-               imagepng($thumbnail, OCP\Config::getSystemValue("datadirectory").'/'. OCP\USER::getUser() .'/gallery/' . $albumName.'.png');
+               $view = OCP\App::getStorage('gallery');
+               imagepng($thumbnail, $view->getLocalFile($albumName.'.png'));
                imagedestroy($thumbnail);
        }