new way of showing gallery covers, missing files

This commit is contained in:
Bartek Przybylski 2011-10-18 21:43:33 +02:00
parent 55e8b02a09
commit c32cce4b35
6 changed files with 33 additions and 6 deletions

View File

@ -11,7 +11,7 @@ while ($r = $result->fetchRow()) {
$album_name = $r['album_name']; $album_name = $r['album_name'];
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE `album_id` = ?');
$tmp_res = $stmt->execute(array($r['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)); OC_JSON::success(array('albums'=>$a));

View File

@ -5,6 +5,7 @@ OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery'); OC_JSON::checkAppEnabled('gallery');
require_once('../lib_scanner.php'); require_once('../lib_scanner.php');
OC_GALLERY_SCANNER::cleanUp();
OC_JSON::success(array('albums' => OC_GALLERY_SCANNER::scan(''))); OC_JSON::success(array('albums' => OC_GALLERY_SCANNER::scan('')));
//OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa'))))); //OC_JSON::success(array('albums' => array(array('name' => 'test', 'imagesCount' => 1, 'images' => array('dupa')))));

View File

@ -5,6 +5,12 @@ OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('gallery'); OC_Util::checkAppEnabled('gallery');
OC_App::setActiveNavigationEntry( 'gallery_index' ); 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'])) { if (!isset($_GET['view'])) {
$stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'); $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?');

View File

@ -4,7 +4,7 @@ $(document).ready(function() {
if (r.status == 'success') { if (r.status == 'success') {
for (var i in r.albums) { for (var i in r.albums) {
var a = r.albums[i]; 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'); var targetDiv = document.getElementById('gallery_list');
if (targetDiv) { if (targetDiv) {

View File

@ -12,13 +12,13 @@ Albums={
// album with the same name wont be insered, // album with the same name wont be insered,
// and false will be returned // and false will be returned
// true on success // true on success
add: function(album_name, num) { add: function(album_name, num, bgPath) {
for (var a in Albums.albums) { for (var a in Albums.albums) {
if (a.name == album_name) { if (a.name == album_name) {
return false; return false;
} }
} }
Albums.albums.push({name: album_name, numOfCovers: num}); Albums.albums.push({name: album_name, numOfCovers: num, backgroundPath: bgPath});
return true; return true;
}, },
// remove element with given name // remove element with given name
@ -63,7 +63,7 @@ Albums={
var local = $(displayTemplate.replace(/\*NAME\*/g, a.name)); var local = $(displayTemplate.replace(/\*NAME\*/g, a.name));
local.css('background-repeat', 'no-repeat'); local.css('background-repeat', 'no-repeat');
local.css('background-position', '0 0'); 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) { local.mousemove(function(e) {
var albumMetadata = Albums.find(this.title); var albumMetadata = Albums.find(this.title);
if (albumMetadata == undefined) { if (albumMetadata == undefined) {

View File

@ -1,6 +1,7 @@
<?php <?php
require_once('base.php'); // base lib require_once('base.php'); // base lib
require_once('lib/images_utils.php');
class OC_GALLERY_SCANNER { class OC_GALLERY_SCANNER {
@ -10,6 +11,13 @@ class OC_GALLERY_SCANNER {
return $albums; 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) { public static function scanDir($path, &$albums) {
$current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array()); $current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array());
$current_album['name'] = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $current_album['name'])); $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)) { } elseif (self::isPhoto($path.'/'.$filename)) {
$current_album['images'][] = $filepath; $current_album['images'][] = $filepath;
} }
} }
} }
$current_album['imagesCount'] = count($current_album['images']); $current_album['imagesCount'] = count($current_album['images']);
$albums[] = $current_album; $albums[] = $current_album;
@ -46,6 +54,18 @@ class OC_GALLERY_SCANNER {
$stmt->execute(array($albumId, $img)); $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) { public static function isPhoto($filename) {