aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartek Przybylski <bart.p.pl@gmail.com>2011-10-18 21:43:33 +0200
committerBartek Przybylski <bart.p.pl@gmail.com>2011-10-18 21:43:33 +0200
commitc32cce4b35919c255089922abe64f5fe833ecb27 (patch)
tree565ed0f9592c5f929b80f3509c431c4d594fe9bd
parent55e8b02a0923ed33c2c3a17c21d2e6c5e1692192 (diff)
downloadnextcloud-server-c32cce4b35919c255089922abe64f5fe833ecb27.tar.gz
nextcloud-server-c32cce4b35919c255089922abe64f5fe833ecb27.zip
new way of showing gallery covers, missing files
-rw-r--r--apps/gallery/ajax/getAlbums.php2
-rw-r--r--apps/gallery/ajax/scanForAlbums.php1
-rw-r--r--apps/gallery/index.php6
-rw-r--r--apps/gallery/js/album_cover.js2
-rw-r--r--apps/gallery/js/albums.js6
-rw-r--r--apps/gallery/lib_scanner.php22
6 files changed, 33 insertions, 6 deletions
diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php
index 38bea74636f..60d3d42866d 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 de0b141a367..bdd591d0422 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 87fdafcf13c..cb567e3c8f6 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 776feae32cc..c475c60d5da 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 7ab243ededf..a8e317159d5 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 5490c4a55ad..30a86b7405d 100644
--- a/apps/gallery/lib_scanner.php
+++ b/apps/gallery/lib_scanner.php
@@ -1,6 +1,7 @@
<?php
require_once('base.php'); // base lib
+require_once('lib/images_utils.php');
class OC_GALLERY_SCANNER {
@@ -10,6 +11,13 @@ class OC_GALLERY_SCANNER {
return $albums;
}
+ public static function cleanUp() {
+ $stmt = OC_DB::prepare('DELETE FROM *PREFIX*gallery_albums');
+ $stmt->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) {