From c32cce4b35919c255089922abe64f5fe833ecb27 Mon Sep 17 00:00:00 2001 From: Bartek Przybylski Date: Tue, 18 Oct 2011 21:43:33 +0200 Subject: [PATCH] new way of showing gallery covers, missing files --- apps/gallery/ajax/getAlbums.php | 2 +- apps/gallery/ajax/scanForAlbums.php | 1 + apps/gallery/index.php | 6 ++++++ apps/gallery/js/album_cover.js | 2 +- apps/gallery/js/albums.js | 6 +++--- apps/gallery/lib_scanner.php | 22 +++++++++++++++++++++- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php index 38bea74636..60d3d42866 100644 --- a/apps/gallery/ajax/getAlbums.php +++ b/apps/gallery/ajax/getAlbums.php @@ -11,7 +11,7 @@ while ($r = $result->fetchRow()) { $album_name = $r['album_name']; $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ?'); $tmp_res = $stmt->execute(array($r['album_id'])); - $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10)); + $a[] = array('name' => $album_name, 'numOfItems' => min($tmp_res->numRows(), 10), 'bgPath' => OC::$WEBROOT.'/data/'.OC_User::getUser().'/gallery/'.$album_name.'.png'); } OC_JSON::success(array('albums'=>$a)); diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php index de0b141a36..bdd591d042 100644 --- a/apps/gallery/ajax/scanForAlbums.php +++ b/apps/gallery/ajax/scanForAlbums.php @@ -5,6 +5,7 @@ OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('gallery'); require_once('../lib_scanner.php'); +OC_GALLERY_SCANNER::cleanUp(); OC_JSON::success(array('albums' => OC_GALLERY_SCANNER::scan(''))); //OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa'))))); diff --git a/apps/gallery/index.php b/apps/gallery/index.php index 87fdafcf13..cb567e3c8f 100644 --- a/apps/gallery/index.php +++ b/apps/gallery/index.php @@ -5,6 +5,12 @@ OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('gallery'); OC_App::setActiveNavigationEntry( 'gallery_index' ); +if (!file_exists(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery')) { + mkdir(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery'); + $f = fopen(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/.htaccess', 'w'); + fwrite($f, "allow from all"); + fclose($f); +} if (!isset($_GET['view'])) { $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'); diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js index 776feae32c..c475c60d5d 100644 --- a/apps/gallery/js/album_cover.js +++ b/apps/gallery/js/album_cover.js @@ -4,7 +4,7 @@ $(document).ready(function() { if (r.status == 'success') { for (var i in r.albums) { var a = r.albums[i]; - Albums.add(a.name, a.numOfItems); + Albums.add(a.name, a.numOfItems, a.bgPath); } var targetDiv = document.getElementById('gallery_list'); if (targetDiv) { diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js index 7ab243eded..a8e317159d 100644 --- a/apps/gallery/js/albums.js +++ b/apps/gallery/js/albums.js @@ -12,13 +12,13 @@ Albums={ // album with the same name wont be insered, // and false will be returned // true on success - add: function(album_name, num) { + add: function(album_name, num, bgPath) { for (var a in Albums.albums) { if (a.name == album_name) { return false; } } - Albums.albums.push({name: album_name, numOfCovers: num}); + Albums.albums.push({name: album_name, numOfCovers: num, backgroundPath: bgPath}); return true; }, // remove element with given name @@ -63,7 +63,7 @@ Albums={ var local = $(displayTemplate.replace(/\*NAME\*/g, a.name)); local.css('background-repeat', 'no-repeat'); local.css('background-position', '0 0'); - local.css('background-image','url("ajax/getCovers.php?album_name='+a.name+'")'); + local.css('background-image','url("'+a.backgroundPath+'")'); local.mousemove(function(e) { var albumMetadata = Albums.find(this.title); if (albumMetadata == undefined) { diff --git a/apps/gallery/lib_scanner.php b/apps/gallery/lib_scanner.php index 5490c4a55a..30a86b7405 100644 --- a/apps/gallery/lib_scanner.php +++ b/apps/gallery/lib_scanner.php @@ -1,6 +1,7 @@ execute(array()); + $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_photos'); + $stmt->execute(array()); + } + public static function scanDir($path, &$albums) { $current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array()); $current_album['name'] = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $current_album['name'])); @@ -24,7 +32,7 @@ class OC_GALLERY_SCANNER { } elseif (self::isPhoto($path.'/'.$filename)) { $current_album['images'][] = $filepath; } - } + } } $current_album['imagesCount'] = count($current_album['images']); $albums[] = $current_album; @@ -46,6 +54,18 @@ class OC_GALLERY_SCANNER { $stmt->execute(array($albumId, $img)); } } + if (count($current_album['images'])) { + self::createThumbnail($current_album['name'],$current_album['images']); + } + } + + public static function createThumbnail($albumName, $files) { + $file_count = min(count($files), 10); + $thumbnail = imagecreatetruecolor($file_count*200, 200); + for ($i = 0; $i < $file_count; $i++) { + CroppedThumbnail(OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/files/'.$files[$i], 200, 200, $thumbnail, $i*200); + } + imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png'); } public static function isPhoto($filename) {