]> source.dussan.org Git - nextcloud-server.git/commitdiff
small fixes in merge request 104, use OCP\Files::getStorage
authorJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 11 Jul 2012 00:32:17 +0000 (02:32 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Wed, 11 Jul 2012 00:33:11 +0000 (02:33 +0200)
apps/gallery/ajax/viewImage.php
apps/gallery/lib/managers.php
apps/gallery/lib/photo.php
apps/gallery/lib/tiles.php

index 4f7af1496fcd5d3d8157d1820c371e91694792f8..daf0ab741f052546e253c53cc13a3c2b6b1d2155 100644 (file)
@@ -20,8 +20,6 @@
  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
  * 
  */
-
-
 OCP\JSON::checkLoggedIn();
 OCP\JSON::checkAppEnabled('gallery');
 
@@ -29,6 +27,6 @@ $img = $_GET['img'];
 
 $image = OC_Gallery_Photo::getViewImage($img);
 if ($image) {
-    OCP\Response::enableCaching(3600 * 24); // 24 hour
-    $image->show();
+       OCP\Response::enableCaching(3600 * 24); // 24 hour
+       $image->show();
 }
index 3b6f754fc2d3bd960a010477ee8aeef65d20745d..b6ade3d1b1e4091bbc6dadb63898dbe1df74ed2e 100644 (file)
@@ -71,9 +71,9 @@ class ThumbnailsManager {
        }
 
        public function getThumbnail($path) {
-               $gallery_path = \OCP\Config::getSystemValue( 'datadirectory' ).'/'.\OC_User::getUser().'/gallery';
-               if (file_exists($gallery_path.$path)) {
-                       return new \OC_Image($gallery_path.$path);
+               $gallery_storage = \OCP\Files::getStorage('gallery');
+               if ($gallery_storage->file_exists($path)) {
+                       return new \OC_Image($gallery_storage->getLocalFile($path));
                }
                if (!\OC_Filesystem::file_exists($path)) {
                        \OC_Log::write(self::TAG, 'File '.$path.' don\'t exists', \OC_Log::WARN);
@@ -92,8 +92,9 @@ class ThumbnailsManager {
                        unset($image);
                        return false;
                }
+               $l = $gallery_storage->getLocalFile($path);
                 
-               $image->save($gallery_path.'/'.$path);
+               $image->save($l);
                return $image;
        }
 
@@ -122,9 +123,9 @@ class ThumbnailsManager {
        }
        
        public function delete($path) {
-               $thumbnail = \OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/gallery".$path;
-               if (file_exists($thumbnail)) {
-                       unlink($thumbnail);
+               $thumbnail_storage = \OCP\Files::getStorage('gallery');
+               if ($thumbnail_storage->file_exists($path)) {
+                       $thumbnail_storage->unlink($path);
                }
        }
        
index 38a6690c63b9c9446860048ee69ff7baebd3b7a0..3b4e74641b3af70df610ddd8d62ccfb0c35c2e84 100644 (file)
@@ -1,53 +1,55 @@
 <?php
 
 /**
-* ownCloud - gallery application
-*
-* @author Bartek Przybylski
-* @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com
-* 
-* 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/>.
-* 
-*/
-
+ * ownCloud - gallery application
+ *
+ * @author Bartek Przybylski
+ * @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com
+ * 
+ * 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/>.
+ * 
+ */
 class OC_Gallery_Photo {
-       public static function create($albumId, $img){
+
+       public static function create($albumId, $img) {
                $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
                $stmt->execute(array($albumId, $img));
        }
-       public static function find($albumId, $img=null){
+
+       public static function find($albumId, $img = null) {
                $sql = 'SELECT * FROM *PREFIX*gallery_photos WHERE album_id = ?';
                $args = array($albumId);
-               if (!is_null($img)){
+               if (!is_null($img)) {
                        $sql .= ' AND file_path = ?';
                        $args[] = $img;
                }
                $stmt = OCP\DB::prepare($sql);
                return $stmt->execute($args);
        }
-       public static function findForAlbum($owner, $album_name){
+
+       public static function findForAlbum($owner, $album_name) {
                $stmt = OCP\DB::prepare('SELECT *'
-                       .' FROM *PREFIX*gallery_photos photos,'
-                               .' *PREFIX*gallery_albums albums'
-                       .' WHERE albums.uid_owner = ?'
-                               .' AND albums.album_name = ?'
-                               .' AND photos.album_id = albums.album_id');
+                                       .' FROM *PREFIX*gallery_photos photos,'
+                                               .' *PREFIX*gallery_albums albums'
+                                       .' WHERE albums.uid_owner = ?'
+                                               .' AND albums.album_name = ?'
+                                               .' AND photos.album_id = albums.album_id');
                return $stmt->execute(array($owner, $album_name));
        }
 
-  public static function removeByPath($path, $album_id) {
-    $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path LIKE ? and album_id = ?');
+       public static function removeByPath($path, $album_id) {
+               $stmt = OCP\DB::prepare('DELETE FROM *PREFIX*gallery_photos WHERE file_path LIKE ? and album_id = ?');
                $stmt->execute(array($path, $album_id));
        }
 
@@ -67,19 +69,20 @@ class OC_Gallery_Photo {
        }
 
        public static function getThumbnail($image_name, $owner = null) {
-               if (!$owner) $owner = OCP\USER::getUser();
+               if (!$owner)
+                       $owner = OCP\USER::getUser();
                $view = OCP\Files::getStorage('gallery');
                $save_dir = dirname($image_name);
                if (!$view->is_dir($save_dir)) {
                        $view->mkdir($save_dir);
                }
-               $view->chroot($view->getRoot().'/'.$save_dir);
+               $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_name);
-                       if(!file_exists($image_path)) {
+                       if (!file_exists($image_path)) {
                                return null;
                        }
                        $image = new OC_Image($image_path);
@@ -91,44 +94,45 @@ class OC_Gallery_Photo {
                }
                if ($image->valid()) {
                        return $image;
-               }else{
+               } else {
                        $image->destroy();
                }
                return null;
        }
 
-    public static function getViewImage($image_name, $owner = null) {
-        if (!$owner) $owner = OCP\USER::getUser();
-        $save_dir = OCP\Config::getSystemValue("datadirectory").'/'. $owner .'/gallery/';
-        $save_dir .= dirname($image_name). '/view/';
-        $image_path = $image_name;
-        $view_file = $save_dir . basename($image_name);
-        if (!is_dir($save_dir)) {
-            mkdir($save_dir, 0777, true);
-        }
-        if (file_exists($view_file)) {
-            $image = new OC_Image($view_file);
-        } else {
-            $image_path = OC_Filesystem::getLocalFile($image_path);
-            if(!file_exists($image_path)) {
-                return null;
-            }
-            $image = new OC_Image($image_path);
-            if ($image->valid()) {
-                $image->resize(1200);
-                $image->fixOrientation();
-                $image->save($view_file);
-            }
-        }
-        if ($image->valid()) {
-            return $image;
-        }else{
-            $image->destroy();
-        }
-        return null;
-    }
+       public static function getViewImage($image_name, $owner = null) {
+               if (!$owner) $owner = OCP\USER::getUser();
+               $save_dir = OCP\Config::getSystemValue("datadirectory") . '/' . $owner . '/gallery';
+               $save_dir .= dirname($image_name) . '/view/';
+               $image_path = $image_name;
+               $view_file = $save_dir . basename($image_name);
+               if (!is_dir($save_dir)) {
+                       mkdir($save_dir, 0777, true);
+               }
+               if (file_exists($view_file)) {
+                       $image = new OC_Image($view_file);
+               } else {
+                       $image_path = OC_Filesystem::getLocalFile($image_path);
+                       if (!file_exists($image_path)) {
+                               return null;
+                       }
+                       $image = new OC_Image($image_path);
+                       if ($image->valid()) {
+                               $image->resize(1200);
+                               $image->fixOrientation();
+                               $image->save($view_file);
+                       }
+               }
+               if ($image->valid()) {
+                       return $image;
+               } else {
+                       $image->destroy();
+               }
+               return null;
+       }
 
        public static function getGalleryRoot() {
                return OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '');
        }
+
 }
index 3ff06dfcbebc5aaa8b8ac37fe1f538730bcc9eec..754734e609e53064030c4d0f48b06fc4f882a39c 100644 (file)
@@ -95,7 +95,7 @@ class TileSingle extends TileBase {
        public function get($extra = '') {
                //      !HACK! file path needs to be encoded twice because files app decode twice url, so any special chars like + or & in filename
                //      !HACK! will result in failing of opening them 
-               return '<a rel="images" title="'.htmlentities(basename($this->getPath())).'" href="'.\OCP\Util::linkTo('files', 'download.php').'?file='.urlencode(urlencode($this->getPath())).'"><img rel="images" src="'.\OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath()).'" '.$extra.'></a>';
+               return '<a rel="images" title="'.htmlentities(basename($this->getPath())).'" href="'.\OCP\Util::linkTo('gallery','ajax/viewImage.php').'?img='.urlencode(urlencode($this->getPath())).'"><img rel="images" src="'.\OCP\Util::linkTo('gallery', 'ajax/thumbnail.php').'&filepath='.urlencode($this->getPath()).'" '.$extra.'></a>';
        }
        
        public function getMiniatureSrc() {