diff options
author | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-03-11 16:49:21 +0100 |
---|---|---|
committer | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-03-11 16:49:42 +0100 |
commit | f6075cc1fe516c3eb553b6b28380b133b7da8dda (patch) | |
tree | 6305c9c8c2cc90e213eea52bef780dffef3e8f34 | |
parent | 92221e98de38fe26a3aa2b2b722ebc218664ab7d (diff) | |
download | nextcloud-server-f6075cc1fe516c3eb553b6b28380b133b7da8dda.tar.gz nextcloud-server-f6075cc1fe516c3eb553b6b28380b133b7da8dda.zip |
gallery migration to events system
-rw-r--r-- | apps/gallery/ajax/galleryOp.php | 44 | ||||
-rw-r--r-- | apps/gallery/img/loading.gif | bin | 0 -> 1849 bytes | |||
-rw-r--r-- | apps/gallery/js/album_cover.js | 112 | ||||
-rw-r--r-- | apps/gallery/js/albums.js | 2 | ||||
-rw-r--r-- | apps/gallery/js/scanner.js | 34 | ||||
-rw-r--r-- | apps/gallery/lib/album.php | 103 | ||||
-rw-r--r-- | apps/gallery/lib/photo.php | 9 | ||||
-rw-r--r-- | apps/gallery/lib/scanner.php | 156 | ||||
-rw-r--r-- | apps/gallery/templates/index.php | 59 | ||||
-rw-r--r-- | lib/image.php | 2 |
10 files changed, 236 insertions, 285 deletions
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index 64f1b1697ba..1f280623ce9 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -21,6 +21,7 @@ * */ +header('Content-type: text/html; charset=UTF-8') ; require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); @@ -47,28 +48,21 @@ function handleGetThumbnails($albumname) { } function handleGalleryScanning() { - OC_Gallery_Scanner::cleanup(); - OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('/'))); + OC_DB::beginTransaction(); + set_time_limit(0); + $eventSource = new OC_EventSource(); + OC_Gallery_Scanner::scan($eventSource); + $eventSource->close(); + OC_DB::commit(); } function handleFilescan($cleanup) { if ($cleanup) OC_Gallery_Album::cleanup(); - $root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '').'/'; - $pathlist = OC_Gallery_Scanner::find_paths($root); + $pathlist = OC_Gallery_Scanner::find_paths(); sort($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) { if (!OC_Filesystem::file_exists($root)) { 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', '/'); - $root = trim(rtrim($root, '/')); + $root = trim($root); + $root = 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); @@ -90,11 +85,9 @@ function handleStoreSettings($root, $order) { function handleGetGallery($path) { $a = array(); $root = OC_Preferences::getValue(OC_User::getUser(),'gallery', 'root', '/'); - if (strlen($root) > 1) - $path = $root.'/'.trim($path, '/'); - else - $path = '/'.ltrim($path, '/'); - if (strlen($path) > 1) $path = rtrim($path, '/'); + $path = utf8_decode(rtrim($root.$path,'/')); + if($path == '') $path = '/'; + $pathLen = strlen($path); $result = OC_Gallery_Album::find(OC_User::getUser(), null, $path); $album_details = $result->fetchRow(); @@ -104,7 +97,7 @@ function handleGetGallery($path) { $album_name = $r['album_name']; $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']); @@ -134,18 +127,9 @@ if ($_GET['operation']) { case 'scan': handleGalleryScanning(); break; - case 'filescan': - handleFilescan($_GET['cleanup']); - break; - case 'partial_create': - handlePartialCreate(urldecode($_GET['path'])); - break; case 'store_settings': handleStoreSettings($_GET['root'], $_GET['order']); break; - case 'get_galleries': - handleGetGalleries($_GET['path']); - break; case 'get_gallery': handleGetGallery($_GET['path']); break; diff --git a/apps/gallery/img/loading.gif b/apps/gallery/img/loading.gif Binary files differnew file mode 100644 index 00000000000..5b33f7e54f4 --- /dev/null +++ b/apps/gallery/img/loading.gif diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js index 71de1adae11..8cafce35f98 100644 --- a/apps/gallery/js/album_cover.js +++ b/apps/gallery/js/album_cover.js @@ -10,17 +10,24 @@ function returnToElement(num) { crumbCount--; paths.pop(); } - path=paths[paths.length-1]; - $.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 }, albumClickHandler); } -function albumClick(title,path) { - paths.push(path); +function albumClick(title) { + paths.push(title); 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')) $('#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) { @@ -40,7 +47,7 @@ function albumClickHandler(r) { Albums.display(targetDiv); //$('#gallery_list').sortable({revert:true}); $('.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'}); }); } else { @@ -49,100 +56,15 @@ function albumClickHandler(r) { } else { OC.dialogs.alert(t('gallery', 'Error: ') + r.message, t('gallery', 'Internal error')); } -} - -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); - } - }); - } + $('#g-album-loading').hide(); } var albumCounter = 0; var totalAlbums = 0; function scanForAlbums(cleanup) { - cleanup = cleanup?true:false; - 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; - } - $('#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'); - } - }); - } - ); + Scanner.scanAlbums(); + return; } function settings() { diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js index afdfbd3cc83..d3326841cc7 100644 --- a/apps/gallery/js/albums.js +++ b/apps/gallery/js/albums.js @@ -42,7 +42,7 @@ Albums={ // displays gallery in linear representation // on given element, and apply default styles for gallery 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) { var a = Albums.albums[i]; var local=$(displayTemplate); diff --git a/apps/gallery/js/scanner.js b/apps/gallery/js/scanner.js new file mode 100644 index 00000000000..804ee9d229b --- /dev/null +++ b/apps/gallery/js/scanner.js @@ -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(); + } +} + diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php index 6f492440ea1..e8698590e6d 100644 --- a/apps/gallery/lib/album.php +++ b/apps/gallery/lib/album.php @@ -13,11 +13,11 @@ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ @@ -26,84 +26,83 @@ require_once('base.php'); class OC_Gallery_Album { public static function create($owner, $name, $path){ $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name, album_path, parent_path) VALUES (?, ?, ?, ?)'); - $stmt->execute(array($owner, $name, $path, self::getParentPath($path))); + $stmt->execute(array($owner, $name, $path, self::getParentPath($path))); } - 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 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 getParentPath($path) { - return dirname($path); - } + public static function getParentPath($path) { + return $path === '/' ? '' : dirname($path); + } - public static function remove($owner, $name=null, $path=null, $parent=null) { - $sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner LIKE ?'; + public static function remove($owner, $name=null, $path=null, $parent=null) { + $sql = 'DELETE FROM *PREFIX*gallery_albums WHERE uid_owner LIKE ?'; $args = array($owner); if (!is_null($name)){ - $sql .= ' AND album_name LIKE ?'; + $sql .= ' AND album_name LIKE ?'; $args[] = $name; - } - if (!is_null($path)){ - $sql .= ' AND album_path LIKE ?'; - $args[] = $path; - } - if (!is_null($parent)){ - $sql .= ' AND parent_path LIKE ?'; - $args[] = $parent; - } + } + if (!is_null($path)){ + $sql .= ' AND album_path LIKE ?'; + $args[] = $path; + } + if (!is_null($parent)){ + $sql .= ' AND parent_path LIKE ?'; + $args[] = $parent; + } $stmt = OC_DB::prepare($sql); return $stmt->execute($args); } - public static function removeByName($owner, $name) { self::remove($ownmer, $name); } - public static function removeByPath($owner, $path) { self::remove($owner, null, $path); } - public static function removeByParentPath($owner, $parent) { self::remove($owner, null, null, $parent); } + public static function removeByName($owner, $name) { self::remove($ownmer, $name); } + public static function removeByPath($owner, $path) { self::remove($owner, null, $path); } + public static function removeByParentPath($owner, $parent) { self::remove($owner, null, null, $parent); } - public static function find($owner, $name=null, $path=null, $parent=null){ + public static function find($owner, $name=null, $path=null, $parent=null){ $sql = 'SELECT * FROM *PREFIX*gallery_albums WHERE uid_owner = ?'; $args = array($owner); if (!is_null($name)){ $sql .= ' AND album_name = ?'; $args[] = $name; - } - if (!is_null($path)){ - $sql .= ' AND album_path = ?'; - $args[] = $path; - } - if (!is_null($parent)){ - $sql .= ' AND parent_path = ?'; - $args[] = $parent; - } - $order = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'order', 'ASC'); - $sql .= ' ORDER BY album_name ' . $order; + } + if (!is_null($path)){ + $sql .= ' AND album_path = ?'; + $args[] = $path; + } + if (!is_null($parent)){ + $sql .= ' AND parent_path = ?'; + $args[] = $parent; + } + $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); } - public static function changePath($oldname, $newname, $owner) { - $stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_albums SET album_path=? WHERE uid_owner=? AND album_path=?'); - $stmt->execute(array($newname, $owner, $oldname)); - } + public static function changePath($oldname, $newname, $owner) { + $stmt = OC_DB::prepare('UPDATE *PREFIX*gallery_albums SET album_path=? WHERE uid_owner=? AND album_path=?'); + $stmt->execute(array($newname, $owner, $oldname)); + } - public static function changeThumbnailPath($oldname, $newname) { - require_once('../../../lib/base.php'); - $thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/'; - rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png'); - } + public static function changeThumbnailPath($oldname, $newname) { + require_once('../../../lib/base.php'); + $thumbpath = OC::$CONFIG_DATADIRECTORY.'/../gallery/'; + rename($thumbpath.$oldname.'.png', $thumbpath.$newname.'.png'); + } - public static function getAlbumSize($id){ + public static function getAlbumSize($id){ $sql = 'SELECT COUNT(*) as size FROM *PREFIX*gallery_photos WHERE album_id = ?'; $stmt = OC_DB::prepare($sql); $result=$stmt->execute(array($id))->fetchRow(); return $result['size']; - } - + } } ?> diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index 872ecc9488a..463df2b5f4b 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -69,11 +69,12 @@ class OC_Gallery_Photo { public static function getThumbnail($image_name) { $save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/'; $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)) { $image = new OC_Image($thumb_file); } else { - $imagePath = OC_Filesystem::getLocalFile($image_name); + $imagePath = OC_Filesystem::getLocalFile($image_path); if(!file_exists($imagePath)) { return null; } @@ -93,4 +94,8 @@ class OC_Gallery_Photo { } return null; } + + public static function getGalleryRoot() { + return OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', ''); + } } diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php index 00ab7cf7181..1d74b1fb503 100644 --- a/apps/gallery/lib/scanner.php +++ b/apps/gallery/lib/scanner.php @@ -13,100 +13,102 @@ * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* +* * You should have received a copy of the GNU Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ -require_once('../../../lib/base.php'); - class OC_Gallery_Scanner { - public static function getScanningRoot() { - return OC_Filesystem::getRoot().OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/'); - } - - public static function scan($root) { - $albums = array(); - self::scanDir($root, $albums); - return $albums; - } + public static function getGalleryRoot() { + return OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '/'); + } + public static function getScanningRoot() { + return OC_Filesystem::getRoot().self::getGalleryRoot(); + } - public static function cleanUp() { - OC_Gallery_Album::cleanup(); - } + public static function cleanUp() { + OC_Gallery_Album::cleanup(); + } - public static function createName($name) { - return basename($name); - } + public static function createName($name) { + $name = basename($name); + return $name == '.' ? '' : $name; + } - public static function scanDir($path, &$albums) { - $current_album = array('name'=> $path, 'imagesCount' => 0, 'images' => array()); - $current_album['name'] = self::createName($current_album['name']); + // Scan single dir relative to gallery root + public static function scan($eventSource) { + $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.'/')) { - while (($filename = readdir($dh)) !== false) { - $filepath = ($path[strlen($path)-1]=='/'?$path:$path.'/').$filename; - if (substr($filename, 0, 1) == '.') continue; - if (self::isPhoto($path.'/'.$filename)) { - $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($owner, null, $path); + // don't duplicate galleries with same path + if (!($albumId = $result->fetchRow())) { + OC_Gallery_Album::create($owner, $name, $path); + $result = OC_Gallery_Album::find($owner, $name); + $albumId = $result->fetchRow(); + } + $albumId = $albumId['album_id']; + foreach ($images as $img) { + $result = OC_Gallery_Photo::find($albumId, $img); + if (!$result->fetchRow()) + OC_Gallery_Photo::create($albumId, $img); + } + if (count($images)) + self::createThumbnails($name, $images); + $eventSource->send('scanned', ''); + } + $eventSource->send('done', 1); + } - $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 = $albumId['album_id']; - foreach ($current_album['images'] as $img) { - $result = OC_Gallery_Photo::find($albumId, $img); - if (!$result->fetchRow()) { - OC_Gallery_Photo::create($albumId, $img); - } - } - if (count($current_album['images'])) { - self::createThumbnail($current_album['name'],$current_album['images']); - } - } + public static function createThumbnails($albumName, $files) { + // create gallery thumbnail + $file_count = min(count($files), 10); + $thumbnail = imagecreatetruecolor($file_count*200, 200); + for ($i = 0; $i < $file_count; $i++) { + $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'); + } - 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++) { - $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'); - } + public static function isPhoto($filename) { + $ext = strtolower(substr($filename, strrpos($filename, '.')+1)); + return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif'; + } - public static function isPhoto($filename) { - $ext = strtolower(substr($filename, strrpos($filename, '.')+1)); - return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif'; - } + 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 find_paths($path) { - $images=OC_FileCache::searchByMime('image','', self::getScanningRoot()); - $paths=array(); - foreach($images as $image){ - $path=substr(dirname($image), strlen(self::getScanningRoot()));; - if(array_search($path,$paths)===false){ - $paths[]=$path; + public static function findPaths() { + $images=OC_FileCache::searchByMime('image','', self::getScanningRoot()); + $paths=array(); + foreach($images as $image){ + $path=dirname($image); + $path = self::getGalleryRoot().($path=='.'?'':$path); + if ($path !== '/') $path=rtrim($path,'/'); + if(array_search($path,$paths)===false){ + $paths[]=$path; + } } + sort($paths); + return $paths; } - return $paths; - } } ?> diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 7f0281e6a39..54fbcfd0154 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -1,6 +1,7 @@ <?php OC_Util::addStyle('gallery', 'styles'); OC_Util::addScript('gallery', 'albums'); +OC_Util::addScript('gallery', 'scanner'); OC_Util::addScript('gallery', 'album_cover'); OC_Util::addStyle('files', 'files'); OC_Util::addScript('files_imageviewer', 'jquery.mousewheel-3.0.4.pack'); @@ -10,28 +11,32 @@ $l = new OC_L10N('gallery'); ?> <div id="controls"> - <div id="scan"> - <div id="scanprogressbar"></div> - <input type="button" id="g-scan-button" value="<?php echo $l->t('Rescan');?>" onclick="javascript:scanForAlbums();" /> - <input type="button" id="g-settings-button" value="<?php echo $l->t('Settings');?>" onclick="javascript:settings();"/> - </div> - <div id="g-album-navigation"> - <div class="crumb last" style="background-image:url('/owncloud/core/img/breadcrumb.png')"> - <a href="javascript:returnToElement(0);">main</a> - </div> - </div> + <div id="scan"> + <div id="scanprogressbar"></div> + <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();"/> + </div> + <div id="g-album-navigation"> + <div class="crumb last" style="background-image:url('/owncloud/core/img/breadcrumb.png')"> + <a href="javascript:returnToElement(0);">main</a> + </div> + </div> + <div id="g-album-loading" class="crumb" style="display:none"> + <img src="img/loading.gif"> + </div> </div> <div id="gallery_list"> </div> <div id="dialog-confirm" title="<?php echo $l->t('Remove confirmation');?>" style="display: none"> - <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo $l->t('Do you want to remove album');?> <span id="albumName"></span>?</p> + <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo $l->t('Do you want to remove album');?> <span id="albumName"></span>?</p> </div> <div id="dialog-form" title="<?php echo $l->t('Change album name');?>" style="display:none"> <form> <fieldset> - <label for="name"><?php echo $l->t('New album name');?></label> + <label for="name"><?php echo $l->t('New album name');?></label> <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" /> </fieldset> </form> @@ -39,23 +44,23 @@ $l = new OC_L10N('gallery'); <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/> + <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('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> - --> + <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> diff --git a/lib/image.php b/lib/image.php index fe8349be543..60a714880d0 100644 --- a/lib/image.php +++ b/lib/image.php @@ -216,7 +216,7 @@ class OC_Image { OC_Log::write('core','OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG); return false; } - $exif = exif_read_data($this->filepath, 'IFD0'); + $exif = @exif_read_data($this->filepath, 'IFD0'); if(!$exif) { return false; } |