summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.htaccess1
-rw-r--r--apps/gallery/ajax/getAlbums.php3
-rw-r--r--apps/gallery/ajax/scanForAlbums.php2
-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/images_utils.php43
-rw-r--r--apps/gallery/lib/scanner.php24
8 files changed, 81 insertions, 6 deletions
diff --git a/.htaccess b/.htaccess
index 0d334503d07..b181f8b8452 100644
--- a/.htaccess
+++ b/.htaccess
@@ -2,6 +2,7 @@ ErrorDocument 404 /core/templates/404.php
<IfModule mod_php5.c>
php_value upload_max_filesize 512M
php_value post_max_size 512M
+php_value memory_limit 512M
SetEnv htaccessWorking true
</IfModule>
RewriteEngine on
diff --git a/apps/gallery/ajax/getAlbums.php b/apps/gallery/ajax/getAlbums.php
index 856f29344d7..7454b18edab 100644
--- a/apps/gallery/ajax/getAlbums.php
+++ b/apps/gallery/ajax/getAlbums.php
@@ -9,7 +9,8 @@ $result = OC_Gallery_Album::find(OC_User::getUser());
while ($r = $result->fetchRow()) {
$album_name = $r['album_name'];
$tmp_res = OC_Gallery_Photo::find($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 ff696804b00..f603cbb4971 100644
--- a/apps/gallery/ajax/scanForAlbums.php
+++ b/apps/gallery/ajax/scanForAlbums.php
@@ -4,7 +4,7 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
+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 2c409089ebe..0cd795bac01 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'])) {
$result = OC_Gallery_Album::find(OC_User::getUser());
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 fb091698a76..387cc611d5f 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/images_utils.php b/apps/gallery/lib/images_utils.php
new file mode 100644
index 00000000000..cb46bf3f160
--- /dev/null
+++ b/apps/gallery/lib/images_utils.php
@@ -0,0 +1,43 @@
+<?php
+require_once('../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('gallery');
+
+function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height, $tgtImg, $shift) {
+ //getting the image dimensions
+ list($width_orig, $height_orig) = getimagesize($imgSrc);
+ switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
+ case "jpeg":
+ case "jpg":
+ case "tiff":
+ $myImage = imagecreatefromjpeg($imgSrc);
+ break;
+ case "png":
+ $myImage = imagecreatefrompng($imgSrc);
+ break;
+ default:
+ exit();
+ }
+ $ratio_orig = $width_orig/$height_orig;
+
+ if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
+ $new_height = $thumbnail_width/$ratio_orig;
+ $new_width = $thumbnail_width;
+ } else {
+ $new_width = $thumbnail_height*$ratio_orig;
+ $new_height = $thumbnail_height;
+ }
+
+ $x_mid = $new_width/2; //horizontal middle
+ $y_mid = $new_height/2; //vertical middle
+
+ $process = imagecreatetruecolor(round($new_width), round($new_height));
+
+ imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
+ imagecopyresampled($tgtImg, $process, $shift, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
+
+ imagedestroy($process);
+ imagedestroy($myImage);
+}
+
+?>
diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php
index 1590051c48d..ef210327966 100644
--- a/apps/gallery/lib/scanner.php
+++ b/apps/gallery/lib/scanner.php
@@ -1,12 +1,23 @@
<?php
+require_once('base.php'); // base lib
+require_once('images_utils.php');
+
class OC_Gallery_Scanner {
+
public static function scan($root) {
$albums = array();
self::scanDir($root, $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) {
$current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array());
$current_album['name'] = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $current_album['name']));
@@ -25,6 +36,7 @@ class OC_Gallery_Scanner {
}
$current_album['imagesCount'] = count($current_album['images']);
$albums[] = $current_album;
+
$result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
if ($result->numRows() == 0 && count($current_album['images'])) {
OC_Gallery_Album::create(OC_User::getUser(), $current_album['name']);
@@ -38,6 +50,18 @@ class OC_Gallery_Scanner {
OC_Gallery_Photo::create($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) {