gallery migration to events system
This commit is contained in:
parent
92221e98de
commit
f6075cc1fe
|
@ -21,6 +21,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
header('Content-type: text/html; charset=UTF-8') ;
|
||||||
require_once('../../../lib/base.php');
|
require_once('../../../lib/base.php');
|
||||||
|
|
||||||
OC_JSON::checkLoggedIn();
|
OC_JSON::checkLoggedIn();
|
||||||
|
@ -47,28 +48,21 @@ function handleGetThumbnails($albumname) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGalleryScanning() {
|
function handleGalleryScanning() {
|
||||||
OC_Gallery_Scanner::cleanup();
|
OC_DB::beginTransaction();
|
||||||
OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('/')));
|
set_time_limit(0);
|
||||||
|
$eventSource = new OC_EventSource();
|
||||||
|
OC_Gallery_Scanner::scan($eventSource);
|
||||||
|
$eventSource->close();
|
||||||
|
OC_DB::commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleFilescan($cleanup) {
|
function handleFilescan($cleanup) {
|
||||||
if ($cleanup) OC_Gallery_Album::cleanup();
|
if ($cleanup) OC_Gallery_Album::cleanup();
|
||||||
$root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '').'/';
|
$pathlist = OC_Gallery_Scanner::find_paths();
|
||||||
$pathlist = OC_Gallery_Scanner::find_paths($root);
|
|
||||||
sort($pathlist);
|
sort($pathlist);
|
||||||
OC_JSON::success(array('paths' => $pathlist));
|
OC_JSON::success(array('paths' => $pathlist));
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePartialCreate($path) {
|
|
||||||
if (empty($path)) OC_JSON::error(array('cause' => 'No path specified'));
|
|
||||||
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 = array();
|
|
||||||
OC_Gallery_Scanner::scanDir($path, $albums);
|
|
||||||
OC_JSON::success(array('album_details' => $albums));
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleStoreSettings($root, $order) {
|
function handleStoreSettings($root, $order) {
|
||||||
if (!OC_Filesystem::file_exists($root)) {
|
if (!OC_Filesystem::file_exists($root)) {
|
||||||
OC_JSON::error(array('cause' => 'No such file or directory'));
|
OC_JSON::error(array('cause' => 'No such file or directory'));
|
||||||
|
@ -80,7 +74,8 @@ function handleStoreSettings($root, $order) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$current_root = OC_Preferences::getValue(OC_User::getUser(),'gallery', 'root', '/');
|
$current_root = OC_Preferences::getValue(OC_User::getUser(),'gallery', 'root', '/');
|
||||||
$root = trim(rtrim($root, '/'));
|
$root = trim($root);
|
||||||
|
$root = rtrim($root, '/').'/';
|
||||||
$rescan = $current_root==$root?'no':'yes';
|
$rescan = $current_root==$root?'no':'yes';
|
||||||
OC_Preferences::setValue(OC_User::getUser(), 'gallery', 'root', $root);
|
OC_Preferences::setValue(OC_User::getUser(), 'gallery', 'root', $root);
|
||||||
OC_Preferences::setValue(OC_User::getUser(), 'gallery', 'order', $order);
|
OC_Preferences::setValue(OC_User::getUser(), 'gallery', 'order', $order);
|
||||||
|
@ -90,11 +85,9 @@ function handleStoreSettings($root, $order) {
|
||||||
function handleGetGallery($path) {
|
function handleGetGallery($path) {
|
||||||
$a = array();
|
$a = array();
|
||||||
$root = OC_Preferences::getValue(OC_User::getUser(),'gallery', 'root', '/');
|
$root = OC_Preferences::getValue(OC_User::getUser(),'gallery', 'root', '/');
|
||||||
if (strlen($root) > 1)
|
$path = utf8_decode(rtrim($root.$path,'/'));
|
||||||
$path = $root.'/'.trim($path, '/');
|
if($path == '') $path = '/';
|
||||||
else
|
$pathLen = strlen($path);
|
||||||
$path = '/'.ltrim($path, '/');
|
|
||||||
if (strlen($path) > 1) $path = rtrim($path, '/');
|
|
||||||
$result = OC_Gallery_Album::find(OC_User::getUser(), null, $path);
|
$result = OC_Gallery_Album::find(OC_User::getUser(), null, $path);
|
||||||
$album_details = $result->fetchRow();
|
$album_details = $result->fetchRow();
|
||||||
|
|
||||||
|
@ -104,7 +97,7 @@ function handleGetGallery($path) {
|
||||||
$album_name = $r['album_name'];
|
$album_name = $r['album_name'];
|
||||||
$size=OC_Gallery_Album::getAlbumSize($r['album_id']);
|
$size=OC_Gallery_Album::getAlbumSize($r['album_id']);
|
||||||
|
|
||||||
$a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($size, 10),'path'=>$r['album_path']);
|
$a[] = array('name' => utf8_encode($album_name), 'numOfItems' => min($size, 10),'path'=>substr($r['album_path'], $pathLen));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = OC_Gallery_Photo::find($album_details['album_id']);
|
$result = OC_Gallery_Photo::find($album_details['album_id']);
|
||||||
|
@ -134,18 +127,9 @@ if ($_GET['operation']) {
|
||||||
case 'scan':
|
case 'scan':
|
||||||
handleGalleryScanning();
|
handleGalleryScanning();
|
||||||
break;
|
break;
|
||||||
case 'filescan':
|
|
||||||
handleFilescan($_GET['cleanup']);
|
|
||||||
break;
|
|
||||||
case 'partial_create':
|
|
||||||
handlePartialCreate(urldecode($_GET['path']));
|
|
||||||
break;
|
|
||||||
case 'store_settings':
|
case 'store_settings':
|
||||||
handleStoreSettings($_GET['root'], $_GET['order']);
|
handleStoreSettings($_GET['root'], $_GET['order']);
|
||||||
break;
|
break;
|
||||||
case 'get_galleries':
|
|
||||||
handleGetGalleries($_GET['path']);
|
|
||||||
break;
|
|
||||||
case 'get_gallery':
|
case 'get_gallery':
|
||||||
handleGetGallery($_GET['path']);
|
handleGetGallery($_GET['path']);
|
||||||
break;
|
break;
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
|
@ -10,17 +10,24 @@ function returnToElement(num) {
|
||||||
crumbCount--;
|
crumbCount--;
|
||||||
paths.pop();
|
paths.pop();
|
||||||
}
|
}
|
||||||
path=paths[paths.length-1];
|
var p='';
|
||||||
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: path }, albumClickHandler);
|
for (var i in paths) p += paths[i]+'/';
|
||||||
|
$('#g-album-loading').show();
|
||||||
|
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: p }, albumClickHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
function albumClick(title,path) {
|
function albumClick(title) {
|
||||||
paths.push(path);
|
paths.push(title);
|
||||||
crumbCount++;
|
crumbCount++;
|
||||||
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: path }, albumClickHandler);
|
var p = '';
|
||||||
|
for (var i in paths) p += paths[i]+'/';
|
||||||
|
$('#g-album-loading').show();
|
||||||
|
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'get_gallery', path: p }, function(r) {
|
||||||
|
albumClickHandler(r);
|
||||||
if ($('#g-album-navigation :last-child'))
|
if ($('#g-album-navigation :last-child'))
|
||||||
$('#g-album-navigation :last-child').removeClass('last');
|
$('#g-album-navigation :last-child').removeClass('last');
|
||||||
$('#g-album-navigation').append('<div class="crumb last real" style="background-image:url(\''+OC.imagePath('core','breadcrumb')+'\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+title+'</a></div>');
|
$('#g-album-navigation').append('<div class="crumb last real" style="background-image:url(\''+OC.imagePath('core','breadcrumb')+'\')"><a href=\"javascript:returnToElement('+crumbCount+');\">'+decodeURIComponent(escape(title))+'</a></div>');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function albumClickHandler(r) {
|
function albumClickHandler(r) {
|
||||||
|
@ -40,7 +47,7 @@ function albumClickHandler(r) {
|
||||||
Albums.display(targetDiv);
|
Albums.display(targetDiv);
|
||||||
//$('#gallery_list').sortable({revert:true});
|
//$('#gallery_list').sortable({revert:true});
|
||||||
$('.album').each(function(i, el) {
|
$('.album').each(function(i, el) {
|
||||||
$(el).click(albumClick.bind(null,$(el).attr('title'),$(el).data('path')));
|
$(el).click(albumClick.bind(null,$(el).attr('title')));
|
||||||
//$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
|
//$(el).draggable({connectToSortable: '#gallery_list', handle: '.dummy'});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -49,100 +56,15 @@ function albumClickHandler(r) {
|
||||||
} else {
|
} else {
|
||||||
OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error'));
|
OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error'));
|
||||||
}
|
}
|
||||||
}
|
$('#g-album-loading').hide();
|
||||||
|
|
||||||
function createNewAlbum() {
|
|
||||||
var name = prompt("album name", "");
|
|
||||||
if (name != null && name != "") {
|
|
||||||
$.getJSON(OC.filePath('gallery','ajax','createAlbum.php'), {album_name: name}, function(r) {
|
|
||||||
if (r.status == "success") {
|
|
||||||
var v = '<div class="gallery_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
|
|
||||||
$('div#gallery_list').append(v);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var albumCounter = 0;
|
var albumCounter = 0;
|
||||||
var totalAlbums = 0;
|
var totalAlbums = 0;
|
||||||
|
|
||||||
function scanForAlbums(cleanup) {
|
function scanForAlbums(cleanup) {
|
||||||
cleanup = cleanup?true:false;
|
Scanner.scanAlbums();
|
||||||
var albumCounter = 0;
|
|
||||||
var totalAlbums = 0;
|
|
||||||
$('#g-scan-button').attr('disabled', 'true');
|
|
||||||
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {cleanup: cleanup,operation:'filescan'}, function(r) {
|
|
||||||
|
|
||||||
if (r.status == 'success') {
|
|
||||||
totalAlbums = r.paths.length;
|
|
||||||
if (totalAlbums == 0) {
|
|
||||||
$('#notification').text(t('gallery', "No photos found")).fadeIn().slideDown().delay(3000).fadeOut().slideUp();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
$('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 }).fadeIn();
|
|
||||||
for(var a in r.paths) {
|
|
||||||
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'),{operation:'partial_create','path':r.paths[a]}, function(r) {
|
|
||||||
|
|
||||||
albumCounter++;
|
|
||||||
$('#scanprogressbar').progressbar({ value: (albumCounter/totalAlbums)*100 });
|
|
||||||
if (albumCounter == totalAlbums) {
|
|
||||||
$('#scanprogressbar').fadeOut();
|
|
||||||
var targetDiv = document.getElementById('gallery_list');
|
|
||||||
if (targetDiv) {
|
|
||||||
targetDiv.innerHTML = '';
|
|
||||||
Albums.photos = [];
|
|
||||||
Albums.albums = [];
|
|
||||||
returnToElement(0);
|
|
||||||
} else {
|
|
||||||
alert('Error occured: no such layer `gallery_list`');
|
|
||||||
}
|
|
||||||
$('#g-scan-button').attr('disabled', null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alert('Error occured: ' + r.message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function galleryRemove(albumName) {
|
|
||||||
OC.dialogs.confirm(t('gallery', 'Do you want to remove album ') + decodeURIComponent(escape(albumName)),
|
|
||||||
t('gallery', 'Remove confirmation'),
|
|
||||||
function(decision) {
|
|
||||||
if (decision) {
|
|
||||||
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: "remove", name: decodeURIComponent(escape(albumName))}, function(r) {
|
|
||||||
if (r.status == "success") {
|
|
||||||
$(".gallery_box").filterAttr('data-album',albumName).remove();
|
|
||||||
Albums.remove(albumName);
|
|
||||||
} else {
|
|
||||||
OC.dialogs.alert(r.cause, "Error");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function galleryRename(name) {
|
|
||||||
OC.dialogs.prompt(t('gallery', 'New album name'),
|
|
||||||
t('gallery', 'Change name'),
|
|
||||||
name,
|
|
||||||
function(newname) {
|
|
||||||
if (newname == name || newname == '') return;
|
|
||||||
if (Albums.find(newname)) {
|
|
||||||
OC.dialogs.alert('Album ' + newname + ' exists', 'Alert');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$.getJSON(OC.filePath('gallery','ajax','galleryOp.php'), {operation: 'rename', oldname: name, newname: newname}, function(r) {
|
|
||||||
if (r.status == 'success') {
|
|
||||||
Albums.rename($(".gallery_box").filterAttr('data-album',name), newname);
|
|
||||||
} else {
|
|
||||||
OC.dialogs.alert('Error: ' + r.cause, 'Error');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function settings() {
|
function settings() {
|
||||||
|
|
|
@ -42,7 +42,7 @@ Albums={
|
||||||
// displays gallery in linear representation
|
// displays gallery in linear representation
|
||||||
// on given element, and apply default styles for gallery
|
// on given element, and apply default styles for gallery
|
||||||
display: function(element) {
|
display: function(element) {
|
||||||
var displayTemplate = '<div class="gallery_box album"><div class="dummy"></div><a class="view"><div class="gallery_album_cover"></div></a><h1></h1><div class="gallery_album_decoration"><a><img src="img/share.png" title="Share"></a><a class="rename"><img src="img/rename.png" title="Rename"></a><a class="remove"><img src="img/delete.png" title="Delete"></a></div></div>';
|
var displayTemplate = '<div class="gallery_box album"><div class="dummy"></div><a class="view"><div class="gallery_album_cover"></div></a><h1></h1></div>';
|
||||||
for (var i in Albums.albums) {
|
for (var i in Albums.albums) {
|
||||||
var a = Albums.albums[i];
|
var a = Albums.albums[i];
|
||||||
var local=$(displayTemplate);
|
var local=$(displayTemplate);
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
Scanner={
|
||||||
|
albumsFound:0,
|
||||||
|
eventSource:null,
|
||||||
|
albumsScanned:0,
|
||||||
|
scanAlbums:function(callback){
|
||||||
|
$('#scanprogressbar').progressbar({value:0});
|
||||||
|
$('#scanprogressbar').fadeIn();
|
||||||
|
$('#scan input.start').hide();
|
||||||
|
$('#scan input.stop').show();
|
||||||
|
Scanner.albumsScanned=0;
|
||||||
|
Scanner.eventSource=new OC.EventSource(OC.linkTo('gallery', 'ajax/galleryOp.php'),{operation:'scan'});
|
||||||
|
Scanner.eventSource.listen('count', function(total){Scanner.albumsFound=total;});
|
||||||
|
Scanner.eventSource.listen('scanned', function(data) {
|
||||||
|
Scanner.albumsScanned++;
|
||||||
|
var progress=(Scanner.albumsScanned/Scanner.albumsFound)*100;
|
||||||
|
$('#scanprogressbar').progressbar('value',progress);
|
||||||
|
});
|
||||||
|
Scanner.eventSource.listen('done', function(count){
|
||||||
|
$('#scan input.start').show();
|
||||||
|
$('#scan input.stop').hide();
|
||||||
|
$('#scanprogressbar').fadeOut();
|
||||||
|
returnToElement(0);
|
||||||
|
});
|
||||||
|
if (callback)
|
||||||
|
callback();
|
||||||
|
},
|
||||||
|
stop:function() {
|
||||||
|
Scanner.eventSource.close();
|
||||||
|
$('#scan input.start').show();
|
||||||
|
$('#scan input.stop').hide();
|
||||||
|
$('#scanprogressbar').fadeOut();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class OC_Gallery_Album {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getParentPath($path) {
|
public static function getParentPath($path) {
|
||||||
return dirname($path);
|
return $path === '/' ? '' : dirname($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function remove($owner, $name=null, $path=null, $parent=null) {
|
public static function remove($owner, $name=null, $path=null, $parent=null) {
|
||||||
|
@ -103,7 +103,6 @@ class OC_Gallery_Album {
|
||||||
$result=$stmt->execute(array($id))->fetchRow();
|
$result=$stmt->execute(array($id))->fetchRow();
|
||||||
return $result['size'];
|
return $result['size'];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -69,11 +69,12 @@ class OC_Gallery_Photo {
|
||||||
public static function getThumbnail($image_name) {
|
public static function getThumbnail($image_name) {
|
||||||
$save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/';
|
$save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/';
|
||||||
$save_dir .= dirname($image_name). '/';
|
$save_dir .= dirname($image_name). '/';
|
||||||
$thumb_file = $save_dir . $image_name;
|
$image_path = self::getGalleryRoot().$image_name;
|
||||||
|
$thumb_file = $save_dir . basename($image_name);
|
||||||
if (file_exists($thumb_file)) {
|
if (file_exists($thumb_file)) {
|
||||||
$image = new OC_Image($thumb_file);
|
$image = new OC_Image($thumb_file);
|
||||||
} else {
|
} else {
|
||||||
$imagePath = OC_Filesystem::getLocalFile($image_name);
|
$imagePath = OC_Filesystem::getLocalFile($image_path);
|
||||||
if(!file_exists($imagePath)) {
|
if(!file_exists($imagePath)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -93,4 +94,8 @@ class OC_Gallery_Photo {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getGalleryRoot() {
|
||||||
|
return OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,18 +21,13 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once('../../../lib/base.php');
|
|
||||||
|
|
||||||
class OC_Gallery_Scanner {
|
class OC_Gallery_Scanner {
|
||||||
|
|
||||||
public static function getScanningRoot() {
|
public static function getGalleryRoot() {
|
||||||
return OC_Filesystem::getRoot().OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/');
|
return OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/');
|
||||||
}
|
}
|
||||||
|
public static function getScanningRoot() {
|
||||||
public static function scan($root) {
|
return OC_Filesystem::getRoot().self::getGalleryRoot();
|
||||||
$albums = array();
|
|
||||||
self::scanDir($root, $albums);
|
|
||||||
return $albums;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cleanUp() {
|
public static function cleanUp() {
|
||||||
|
@ -40,46 +35,41 @@ class OC_Gallery_Scanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createName($name) {
|
public static function createName($name) {
|
||||||
return basename($name);
|
$name = basename($name);
|
||||||
|
return $name == '.' ? '' : $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function scanDir($path, &$albums) {
|
// Scan single dir relative to gallery root
|
||||||
$current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array());
|
public static function scan($eventSource) {
|
||||||
$current_album['name'] = self::createName($current_album['name']);
|
$paths = self::findPaths();
|
||||||
|
$eventSource->send('count', count($paths));
|
||||||
|
$owner = OC_User::getUser();
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
$name = self::createName($path);
|
||||||
|
$images = self::findFiles($path);
|
||||||
|
|
||||||
if ($dh = OC_Filesystem::opendir($path.'/')) {
|
$result = OC_Gallery_Album::find($owner, null, $path);
|
||||||
while (($filename = readdir($dh)) !== false) {
|
// don't duplicate galleries with same path
|
||||||
$filepath = ($path[strlen($path)-1]=='/'?$path:$path.'/').$filename;
|
if (!($albumId = $result->fetchRow())) {
|
||||||
if (substr($filename, 0, 1) == '.') continue;
|
OC_Gallery_Album::create($owner, $name, $path);
|
||||||
if (self::isPhoto($path.'/'.$filename)) {
|
$result = OC_Gallery_Album::find($owner, $name);
|
||||||
$current_album['images'][] = $filepath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$current_album['imagesCount'] = count($current_album['images']);
|
|
||||||
$albums['imagesCount'] = $current_album['imagesCount'];
|
|
||||||
$albums['albumName'] = utf8_encode($current_album['name']);
|
|
||||||
|
|
||||||
$result = OC_Gallery_Album::find(OC_User::getUser(), /*$current_album['name']*/ null, $path);
|
|
||||||
// don't duplicate galleries with same path (bug oc-33)
|
|
||||||
if (!($albumId = $result->fetchRow()) && count($current_album['images'])) {
|
|
||||||
OC_Gallery_Album::create(OC_User::getUser(), $current_album['name'], $path);
|
|
||||||
$result = OC_Gallery_Album::find(OC_User::getUser(), $current_album['name']);
|
|
||||||
$albumId = $result->fetchRow();
|
$albumId = $result->fetchRow();
|
||||||
}
|
}
|
||||||
$albumId = $albumId['album_id'];
|
$albumId = $albumId['album_id'];
|
||||||
foreach ($current_album['images'] as $img) {
|
foreach ($images as $img) {
|
||||||
$result = OC_Gallery_Photo::find($albumId, $img);
|
$result = OC_Gallery_Photo::find($albumId, $img);
|
||||||
if (!$result->fetchRow()) {
|
if (!$result->fetchRow())
|
||||||
OC_Gallery_Photo::create($albumId, $img);
|
OC_Gallery_Photo::create($albumId, $img);
|
||||||
}
|
}
|
||||||
|
if (count($images))
|
||||||
|
self::createThumbnails($name, $images);
|
||||||
|
$eventSource->send('scanned', '');
|
||||||
}
|
}
|
||||||
if (count($current_album['images'])) {
|
$eventSource->send('done', 1);
|
||||||
self::createThumbnail($current_album['name'],$current_album['images']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function createThumbnail($albumName, $files) {
|
public static function createThumbnails($albumName, $files) {
|
||||||
|
// create gallery thumbnail
|
||||||
$file_count = min(count($files), 10);
|
$file_count = min(count($files), 10);
|
||||||
$thumbnail = imagecreatetruecolor($file_count*200, 200);
|
$thumbnail = imagecreatetruecolor($file_count*200, 200);
|
||||||
for ($i = 0; $i < $file_count; $i++) {
|
for ($i = 0; $i < $file_count; $i++) {
|
||||||
|
@ -96,15 +86,27 @@ class OC_Gallery_Scanner {
|
||||||
return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif';
|
return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function find_paths($path) {
|
public static function findFiles($path) {
|
||||||
|
$images = OC_FileCache::searchByMime('image','', OC_Filesystem::getRoot().$path);
|
||||||
|
$new = array();
|
||||||
|
foreach ($images as $i)
|
||||||
|
if (strpos($i, '/',1) === FALSE)
|
||||||
|
$new[] = $path.$i;
|
||||||
|
return $new;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function findPaths() {
|
||||||
$images=OC_FileCache::searchByMime('image','', self::getScanningRoot());
|
$images=OC_FileCache::searchByMime('image','', self::getScanningRoot());
|
||||||
$paths=array();
|
$paths=array();
|
||||||
foreach($images as $image){
|
foreach($images as $image){
|
||||||
$path=substr(dirname($image), strlen(self::getScanningRoot()));;
|
$path=dirname($image);
|
||||||
|
$path = self::getGalleryRoot().($path=='.'?'':$path);
|
||||||
|
if ($path !== '/') $path=rtrim($path,'/');
|
||||||
if(array_search($path,$paths)===false){
|
if(array_search($path,$paths)===false){
|
||||||
$paths[]=$path;
|
$paths[]=$path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort($paths);
|
||||||
return $paths;
|
return $paths;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
OC_Util::addStyle('gallery', 'styles');
|
OC_Util::addStyle('gallery', 'styles');
|
||||||
OC_Util::addScript('gallery', 'albums');
|
OC_Util::addScript('gallery', 'albums');
|
||||||
|
OC_Util::addScript('gallery', 'scanner');
|
||||||
OC_Util::addScript('gallery', 'album_cover');
|
OC_Util::addScript('gallery', 'album_cover');
|
||||||
OC_Util::addStyle('files', 'files');
|
OC_Util::addStyle('files', 'files');
|
||||||
OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
|
OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack');
|
||||||
|
@ -12,7 +13,8 @@ $l = new OC_L10N('gallery');
|
||||||
<div id="controls">
|
<div id="controls">
|
||||||
<div id="scan">
|
<div id="scan">
|
||||||
<div id="scanprogressbar"></div>
|
<div id="scanprogressbar"></div>
|
||||||
<input type="button" id="g-scan-button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
|
<input type="button" class="start" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" />
|
||||||
|
<input type="button" class="stop" style="display:none" value="<?php echo $l->t('Stop');?>" onclick="javascript:Scanner.stop();" />
|
||||||
<input type="button" id="g-settings-button" value="<?php echo $l->t('Settings');?>" onclick="javascript:settings();"/>
|
<input type="button" id="g-settings-button" value="<?php echo $l->t('Settings');?>" onclick="javascript:settings();"/>
|
||||||
</div>
|
</div>
|
||||||
<div id="g-album-navigation">
|
<div id="g-album-navigation">
|
||||||
|
@ -20,6 +22,9 @@ $l = new OC_L10N('gallery');
|
||||||
<a href="javascript:returnToElement(0);">main</a>
|
<a href="javascript:returnToElement(0);">main</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="g-album-loading" class="crumb" style="display:none">
|
||||||
|
<img src="img/loading.gif">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="gallery_list">
|
<div id="gallery_list">
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -216,7 +216,7 @@ class OC_Image {
|
||||||
OC_Log::write('core','OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG);
|
OC_Log::write('core','OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$exif = exif_read_data($this->filepath, 'IFD0');
|
$exif = @exif_read_data($this->filepath, 'IFD0');
|
||||||
if(!$exif) {
|
if(!$exif) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue