summaryrefslogtreecommitdiffstats
path: root/apps/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gallery')
-rw-r--r--apps/gallery/ajax/galleryOp.php41
-rw-r--r--apps/gallery/ajax/thumbnail.php59
-rw-r--r--apps/gallery/css/styles.css3
-rw-r--r--apps/gallery/js/album_cover.js52
-rw-r--r--apps/gallery/js/albums.js20
-rw-r--r--apps/gallery/lib/album.php11
-rw-r--r--apps/gallery/lib/hooks_handlers.php10
-rw-r--r--apps/gallery/lib/photo.php33
-rw-r--r--apps/gallery/lib/scanner.php23
-rw-r--r--apps/gallery/templates/index.php28
10 files changed, 193 insertions, 87 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 0c2674f8859..8df692c7735 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -45,6 +45,11 @@ function handleGetThumbnails($albumname) {
OC_JSON::checkLoggedIn();
$photo = new OC_Image();
$photo->loadFromFile(OC::$CONFIG_DATADIRECTORY.'/../gallery/'.$albumname.'.png');
+ $offset = 3600 * 24; // 24 hour
+ // calc the string in GMT not localtime and add the offset
+ header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
+ header('Cache-Control: max-age='.$offset.', must-revalidate');
+ header('Pragma: public');
$photo->show();
}
@@ -54,9 +59,11 @@ function handleGalleryScanning() {
OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('/')));
}
-function handleFilescan() {
+function handleFilescan($cleanup) {
OC_JSON::checkLoggedIn();
- $pathlist = OC_Gallery_Scanner::find_paths('/');
+ if ($cleanup) OC_Gallery_Album::cleanup();
+ $root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '').'/';
+ $pathlist = OC_Gallery_Scanner::find_paths($root);
sort($pathlist);
OC_JSON::success(array('paths' => $pathlist));
}
@@ -67,11 +74,30 @@ function handlePartialCreate($path) {
if (!OC_Filesystem::is_dir($path)) OC_JSON::error(array('cause' => 'Invalid path given'));
$album = OC_Gallery_Album::find(OC_User::getUser(), null, $path);
- $albums;
+ $albums = array();
OC_Gallery_Scanner::scanDir($path, $albums);
OC_JSON::success(array('album_details' => $albums));
}
+function handleStoreSettings($root, $order) {
+ OC_JSON::checkLoggedIn();
+ if (!OC_Filesystem::file_exists($root)) {
+ OC_JSON::error(array('cause' => 'No such file or directory'));
+ return;
+ }
+ if (!OC_Filesystem::is_dir($root)) {
+ OC_JSON::error(array('cause' => $root . ' is not a directory'));
+ return;
+ }
+
+ $current_root = OC_Preferences::getValue(OC_User::getUser(),'gallery', 'root', '/');
+ $root = trim(rtrim($root, '/'));
+ $rescan = $current_root==$root?'no':'yes';
+ OC_Preferences::setValue(OC_User::getUser(), 'gallery', 'root', $root);
+ OC_Preferences::setValue(OC_User::getUser(), 'gallery', 'order', $order);
+ OC_JSON::success(array('rescan' => $rescan));
+}
+
if ($_GET['operation']) {
switch($_GET['operation']) {
case 'rename':
@@ -83,16 +109,19 @@ if ($_GET['operation']) {
OC_JSON::success();
break;
case 'get_covers':
- handleGetThumbnails($_GET['albumname']);
+ handleGetThumbnails(urldecode($_GET['albumname']));
break;
case 'scan':
handleGalleryScanning();
break;
case 'filescan':
- handleFilescan();
+ handleFilescan($_GET['cleanup']);
break;
case 'partial_create':
- handlePartialCreate($_GET['path']);
+ handlePartialCreate(urldecode($_GET['path']));
+ break;
+ case 'store_settings':
+ handleStoreSettings($_GET['root'], $_GET['order']);
break;
default:
OC_JSON::error(array('cause' => 'Unknown operation'));
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
index 6d25c7a2536..2dfe936d9dd 100644
--- a/apps/gallery/ajax/thumbnail.php
+++ b/apps/gallery/ajax/thumbnail.php
@@ -25,65 +25,14 @@ require_once('../../../lib/base.php');
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
-function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
- //getting the image dimensions
- if(! function_exists('imagecreatefromjpeg'))
- OC_Log::write('gallery','GD module not installed',OC_Log::ERROR);
-
- 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();
- }
- if(!$myImage) 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);
- $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
- imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
-
- imagedestroy($process);
- imagedestroy($myImage);
- return $thumb;
-}
-
-$box_size = 200;
$img = $_GET['img'];
-$imagePath = OC_Filesystem::getLocalFile($img);
-
-if(file_exists($imagePath))
-{
- $image = CroppedThumbnail($imagePath, $box_size, $box_size);
-
- header('Content-Type: image/png');
- $offset = 3600 * 24;
+$image = OC_Gallery_Photo::getThumbnail($img);
+if ($image) {
+ $offset = 3600 * 24; // 24 hour
// calc the string in GMT not localtime and add the offset
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
header('Cache-Control: max-age='.$offset.', must-revalidate');
header('Pragma: public');
-
- imagepng($image);
- imagedestroy($image);
+ $image->show();
}
diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css
index 7872b6445ca..c039cd5ec02 100644
--- a/apps/gallery/css/styles.css
+++ b/apps/gallery/css/styles.css
@@ -12,3 +12,6 @@ div.gallery_control_overlay a { color:white; }
#gallery_images.rightcontent { padding:10px 5px; bottom: 0px; overflow: auto; right:0px}
#scan { position:absolute; right:13.5em; top:0em; }
#scan #scanprogressbar { position:relative; display:inline-block; width:10em; height:1.5em; top:.4em; }
+#g-settings {position: absolute; left 13.5em; top: 0;}
+input[type=button] { -webkit-transition: opacity 0.5s ease-in-out; -moz-transition: opacity 0.5s ease-in-out; -o-transition: opacity 0.5s ease-in-out; opacity: 1}
+input[type=button]:disabled { opacity: 0.5 }
diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js
index e78db221cff..4ddac2f2111 100644
--- a/apps/gallery/js/album_cover.js
+++ b/apps/gallery/js/album_cover.js
@@ -38,10 +38,12 @@ function createNewAlbum() {
var albumCounter = 0;
var totalAlbums = 0;
-function scanForAlbums() {
+function scanForAlbums(cleanup) {
+ cleanup = cleanup?true:false;
var albumCounter = 0;
var totalAlbums = 0;
- $.getJSON('ajax/galleryOp.php?operation=filescan', function(r) {
+ $('#g-scan-button').attr('disabled', 'true');
+ $.getJSON('ajax/galleryOp.php?operation=filescan', {cleanup: cleanup}, function(r) {
if (r.status == 'success') {
totalAlbums = r.paths.length;
@@ -68,6 +70,7 @@ function scanForAlbums() {
} else {
alert('Error occured: no such layer `gallery_list`');
}
+ $('#g-scan-button').attr('disabled', null);
}
});
}
@@ -125,13 +128,13 @@ function galleryRename(name) {
$(this).dialog("close");
return;
}
- $.getJSON("ajax/galleryOp.php", {operation: "rename", oldname: name, newname: newname}, function(r) {
+ $.getJSON('ajax/galleryOp.php', {operation: 'rename', oldname: name, newname: newname}, function(r) {
if (r.status == "success") {
Albums.rename($(".gallery_album_box").filterAttr('data-album',name), newname);
} else {
alert("Error: " + r.cause);
}
- $('#dialog-form').dialog("close");
+ $('#dialog-form').dialog('close');
});
}
@@ -139,10 +142,49 @@ function galleryRename(name) {
{
text: t('gallery', 'Cancel'),
click: function() {
- $( this ).dialog( "close" );
+ $( this ).dialog('close');
}
}
],
});
}
+function settings() {
+ $( '#g-dialog-settings' ).dialog({
+ height: 180,
+ width: 350,
+ modal: false,
+ buttons: [{
+ text: t('gallery', 'Apply'),
+ click: function() {
+ var scanning_root = $('#g-scanning-root').val();
+ var disp_order = $('#g-display-order option:selected').val();
+ if (scanning_root == '') {
+ alert('Scanning root cannot be empty');
+ return;
+ }
+ $.getJSON('ajax/galleryOp.php', {operation: 'store_settings', root: scanning_root, order: disp_order}, function(r) {
+ if (r.status == 'success') {
+ if (r.rescan == 'yes') {
+ $('#g-dialog-settings').dialog('close');
+ Albums.clear(document.getElementById('gallery_list'));
+ scanForAlbums(true);
+ return;
+ }
+ } else {
+ alert('Error: ' + r.cause);
+ return;
+ }
+ $('#g-dialog-settings').dialog('close');
+ });
+ }
+ },
+ {
+ text: t('gallery', 'Cancel'),
+ click: function() {
+ $(this).dialog('close');
+ }
+ }
+ ],
+ });
+}
diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js
index 59efb5b5659..987412f28e0 100644
--- a/apps/gallery/js/albums.js
+++ b/apps/gallery/js/albums.js
@@ -46,20 +46,20 @@ Albums={
var a = Albums.albums[i];
var local=$(displayTemplate);
local.attr('data-album',a.name);
- $(".gallery_album_decoration a.rename", local).click(function(name,event){
+ $(".gallery_album_decoration a.rename", local).bind('click', {name: a.name},function(event){
event.preventDefault();
- galleryRename(name);
- }.bind(null,a.name));
- $(".gallery_album_decoration a.remove", local).click(function(name,event){
+ galleryRename(event.data.name);
+ });
+ $(".gallery_album_decoration a.remove", local).bind('click', {name: a.name},function(event){
event.preventDefault();
- galleryRemove(name);
- }.bind(null,a.name));
- $("a.view", local).attr('href','?view='+a.name);
+ galleryRemove(event.data.name);
+ });
+ $("a.view", local).attr('href','?view='+escape(a.name));
$('h1',local).text(a.name);
$(".gallery_album_cover", local).attr('title',a.name);
$(".gallery_album_cover", local).css('background-repeat', 'no-repeat');
$(".gallery_album_cover", local).css('background-position', '0');
- $(".gallery_album_cover", local).css('background-image','url("ajax/galleryOp.php?operation=get_covers&albumname='+a.name+'")');
+ $(".gallery_album_cover", local).css('background-image','url("ajax/galleryOp.php?operation=get_covers&albumname='+escape(a.name)+'")');
$(".gallery_album_cover", local).mousemove(function(e) {
var albumMetadata = Albums.find(this.title);
@@ -80,6 +80,10 @@ Albums={
$("a.view", element).attr("href", "?view="+new_name);
$("h1", element).text(new_name);
}
+ },
+ clear: function(element) {
+ Albums.albums = new Array();
+ element.innerHTML = '';
}
}
diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php
index 4eb12cc0b81..d1405333ac7 100644
--- a/apps/gallery/lib/album.php
+++ b/apps/gallery/lib/album.php
@@ -31,6 +31,14 @@ class OC_Gallery_Album {
$stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_albums SET album_name=? WHERE uid_owner=? AND album_name=?');
$stmt->execute(array($newname, $owner, $oldname));
}
+
+ public static function cleanup() {
+ $albums = self::find(OC_User::getUser());
+ while ($r = $albums->fetchRow()) {
+ OC_Gallery_Photo::removeByAlbumId($r['album_id']);
+ self::remove(OC_User::getUser(), $r['album_name']);
+ }
+ }
public static function remove($owner, $name=null) {
$sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner = ?';
@@ -69,7 +77,8 @@ class OC_Gallery_Album {
$sql .= ' AND album_path = ?';
$args[] = $path;
}
- $sql .= ' ORDER BY album_name ASC';
+ $order = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'order', 'ASC');
+ $sql .= ' ORDER BY album_name ' . $order;
$stmt = OC_DB::prepare($sql);
return $stmt->execute($args);
diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php
index 236a4b96a07..046866e5c5d 100644
--- a/apps/gallery/lib/hooks_handlers.php
+++ b/apps/gallery/lib/hooks_handlers.php
@@ -58,12 +58,18 @@ class OC_Gallery_Hooks_Handlers {
return OC_Gallery_Album::find(OC_User::getUser(), null, $path);
}
+ public static function pathInRoot($path) {
+ $root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/');
+ return substr($path, 0, strlen($path)>strlen($root)?strlen($root):strlen($path)) == $root;
+ }
+
public static function addPhotoFromPath($params) {
$fullpath = $params[OC_Filesystem::signal_param_path];
if (!self::isPhoto($fullpath)) return;
$path = substr($fullpath, 0, strrpos($fullpath, '/'));
+ if (!self::pathInRoot($path)) return;
OC_Gallery_Scanner::scanDir($path, $albums);
}
@@ -71,8 +77,8 @@ class OC_Gallery_Hooks_Handlers {
public static function removePhoto($params) {
$path = $params[OC_Filesystem::signal_param_path];
if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
- OC_Gallery_Album::removeByPath($path, OC_User::getUser());
- OC_Gallery_Photo::removeByPath($path.'/%');
+ if(!self::pathInRoot($path)) return;
+ OC_Gallery_Album::removeByPath($path.'/', OC_User::getUser());
} elseif (self::isPhoto($path)) {
OC_Gallery_Photo::removeByPath($path);
}
diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php
index d1fb166aee9..15783cb341a 100644
--- a/apps/gallery/lib/photo.php
+++ b/apps/gallery/lib/photo.php
@@ -21,7 +21,7 @@
*
*/
-class OC_Gallery_Photo{
+class OC_Gallery_Photo {
public static function create($albumId, $img){
$stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_photos (album_id, file_path) VALUES (?, ?)');
$stmt->execute(array($albumId, $img));
@@ -65,5 +65,34 @@ class OC_Gallery_Photo{
$stmt = OC_DB::prepare("UPDATE *PREFIX*gallery_photos SET file_path = ?, album_id = ? WHERE album_id = ? and file_path = ?");
$stmt->execute(array($newpath, $newAlbumId, $oldAlbumId, $oldpath));
}
-}
+ public static function getThumbnail($image_name) {
+ $imagePath = OC_Filesystem::getLocalFile($image_name);
+ if(!file_exists($imagePath)) {
+ return null;
+ }
+ $save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/';
+ $save_dir .= dirname($image_name). '/';
+ $image_name = basename($image_name);
+ $thumb_file = $save_dir . $image_name;
+ if (file_exists($thumb_file)) {
+ $image = new OC_Image($thumb_file);
+ } else {
+ $image = new OC_Image($imagePath);
+ if ($image->valid()) {
+ $image->centerCrop();
+ $image->resize(200);
+ $image->fixOrientation();
+ if (!is_dir($save_dir)) {
+ mkdir($save_dir, 0777, true);
+ }
+ $image->save($thumb_file);
+ }
+ }
+ if ($image->valid()) {
+ //var_dump($image, $image->resource());
+ return $image;
+ }
+ return null;
+ }
+}
diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php
index dfb9edebfea..64efb006ad1 100644
--- a/apps/gallery/lib/scanner.php
+++ b/apps/gallery/lib/scanner.php
@@ -39,12 +39,19 @@ class OC_Gallery_Scanner {
$stmt->execute(array());
}
+ public static function createName($name) {
+ $root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/');
+ $name = str_replace('/', '.', str_replace(OC::$CONFIG_DATADIRECTORY, '', $name));
+ if (substr($name, 0, strlen($root)) == str_replace('/','.',$root)) {
+ $name = substr($name, strlen($root));
+ }
+ $name = ($name==='.') ? 'main' : trim($name,'.');
+ return $name;
+ }
+
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']));
- $current_album['name'] = ($current_album['name']==='.') ?
- 'main' :
- trim($current_album['name'],'.');
+ $current_album['name'] = self::createName($current_album['name']);
if ($dh = OC_Filesystem::opendir($path)) {
while (($filename = readdir($dh)) !== false) {
@@ -82,8 +89,10 @@ class OC_Gallery_Scanner {
$file_count = min(count($files), 10);
$thumbnail = imagecreatetruecolor($file_count*200, 200);
for ($i = 0; $i < $file_count; $i++) {
- $imagePath = OC_Filesystem::getLocalFile($files[$i]);
- CroppedThumbnail($imagePath, 200, 200, $thumbnail, $i*200);
+ $image = OC_Gallery_Photo::getThumbnail($files[$i]);
+ if ($image && $image->valid()) {
+ imagecopyresampled($thumbnail, $image->resource(), $i*200, 0, 0, 0, 200, 200, 200, 200);
+ }
}
imagepng($thumbnail, OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/' . $albumName.'.png');
}
@@ -106,7 +115,7 @@ class OC_Gallery_Scanner {
if (self::isPhoto($path.$file)) $addpath = TRUE;
}
- if ($addpath) $ret[] = $path;
+ if ($addpath) $ret[] = urlencode($path);
return $ret;
}
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
index 4c2fbcfe6c6..7cc7dad3ac6 100644
--- a/apps/gallery/templates/index.php
+++ b/apps/gallery/templates/index.php
@@ -9,7 +9,10 @@ $l = new OC_L10N('gallery');
<div id="controls">
<div id="scan">
<div id="scanprogressbar"></div>
- <input type="button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
+ <input type="button" id="g-scan-button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
+ </div>
+ <div id="g-settings">
+ <input type="button" id="g-settings-button" value="<?php echo $l->t('Settings');?>" onclick="javascript:settings();"/>
</div>
</div>
<div id="gallery_list">
@@ -28,3 +31,26 @@ $l = new OC_L10N('gallery');
</form>
</div>
+<div id="g-dialog-settings" title="<?php echo $l->t('Settings');?>" style="display:none">
+ <form>
+ <fieldset><?php $root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/'); $order = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'order', 'ASC');?>
+ <label for="name"><?php echo $l->t('Scanning root');?></label>
+ <input type="text" name="g-scanning-root" id="g-scanning-root" class="text ui-widget-content ui-corner-all" value="<?php echo $root;?>" /><br/>
+
+ <label for="sort"><?php echo $l->t('Default sorting'); ?></label>
+ <select id="g-display-order">
+ <option value="ASC"<?php echo $order=='ASC'?'selected':'';?>><?php echo $l->t('Ascending'); ?></option>
+ <option value="DESC"<?php echo $order=='DESC'?'selected':'';?>><?php echo $l->t('Descending'); ?></option>
+ </select><br/>
+<!--
+ <label for="sort"><?php echo $l->t('Thumbnails size'); ?></label>
+ <select>
+ <option value="100">100px</option>
+ <option value="150">150px</option>
+ <option value="200">200px</option>
+ </select>
+ -->
+ </fieldset>
+ </form>
+</div>
+