From: Bartek Przybylski Date: Sat, 7 Jan 2012 23:14:34 +0000 (+0100) Subject: automatic adding of photo to album, feedback for user while scanning, general cleanup X-Git-Tag: v3.0~60^2~12^2~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9ed3c31fc99fbd33576363a79d51f5be66dc2969;p=nextcloud-server.git automatic adding of photo to album, feedback for user while scanning, general cleanup --- diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index cd7cab202b1..8a006dda637 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -1,6 +1,6 @@ "Unknown operation")); } } -?> \ No newline at end of file +?> diff --git a/apps/gallery/ajax/scanForAlbums.php b/apps/gallery/ajax/scanForAlbums.php index f603cbb4971..b1f0a433a42 100644 --- a/apps/gallery/ajax/scanForAlbums.php +++ b/apps/gallery/ajax/scanForAlbums.php @@ -5,6 +5,6 @@ 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' => OC_Gallery_Scanner::scan('/'))); ?> diff --git a/apps/gallery/appinfo/app.php b/apps/gallery/appinfo/app.php index 2b1ab857afc..3a2dbcb43ad 100644 --- a/apps/gallery/appinfo/app.php +++ b/apps/gallery/appinfo/app.php @@ -2,6 +2,7 @@ OC::$CLASSPATH['OC_Gallery_Album'] = 'apps/gallery/lib/album.php'; OC::$CLASSPATH['OC_Gallery_Photo'] = 'apps/gallery/lib/photo.php'; OC::$CLASSPATH['OC_Gallery_Scanner'] = 'apps/gallery/lib/scanner.php'; +OC::$CLASSPATH['OC_Gallery_Hooks_Handlers'] = 'apps/gallery/lib/hooks_handlers.php'; OC_App::register(array( 'order' => 20, @@ -28,4 +29,6 @@ OC_App::addNavigationEntry( array( } new OC_GallerySearchProvider(); + +require_once('apps/gallery/lib/hooks_handlers.php'); ?> diff --git a/apps/gallery/appinfo/database.xml b/apps/gallery/appinfo/database.xml index fd55b3a6fb4..db88e4c1b5a 100644 --- a/apps/gallery/appinfo/database.xml +++ b/apps/gallery/appinfo/database.xml @@ -27,6 +27,12 @@ true 100 + + album_path + text + true + 100 + diff --git a/apps/gallery/css/styles.css b/apps/gallery/css/styles.css index 53c3c0901d9..cc343ba0d08 100644 --- a/apps/gallery/css/styles.css +++ b/apps/gallery/css/styles.css @@ -1,60 +1,11 @@ -div#gallery_list { - margin: 90pt 20pt; -} -div#gallery_list.leftcontent { - padding-top: 15px; - margin: 0; - text-align: center; -} +div#gallery_list { margin: 90pt 20pt; } +div#gallery_list.leftcontent { padding-top: 15px; margin: 0; text-align: center; } +div#gallery_album_box { width: 200px; text-align: center; border: 0; display: inline-block; margin: 5pt; vertical-align: top; padding: 10px; border: solid 1px black; position: relative; overflow: hidden; color: #999; } +div#gallery_album_box:hover { color: black; } +.leftcontent div#gallery_album_box { margin: 5px; } +div#gallery_album_box h1 { font-size: 12pt; font-family: Verdana; } +div#gallery_album_cover { width: 199px; height: 199px; border: solid 1pt #999; padding: 0; } +div#gallery_control_overlay { border: 0; position:absolute; right: 10pt; background-color: #333; opacity: 0.5; visibility:hidden; padding: 0 5pt; } +div#gallery_control_overlay a { color:white; } +#gallery_images { padding:10px 5px; } -div#gallery_album_box { - width: 200px; - text-align: center; - border: 0; - display: inline-block; - margin: 5pt; - vertical-align: top; - padding: 10px; - border: solid 1px black; - position: relative; - overflow: hidden; - color: #999; -} - -div#gallery_album_box:hover { - color: black; -} - -.leftcontent div#gallery_album_box { - margin: 5px; -} - -div#gallery_album_box h1 { - font-size: 12pt; - font-family: Verdana; -} - -div#gallery_album_cover { - width: 199px; - height: 199px; - border: solid 1pt #999; - padding: 0; -} - -div#gallery_control_overlay { - border: 0; - position:absolute; - right: 10pt; - background-color: #333; - opacity: 0.5; - visibility:hidden; - padding: 0 5pt; -} - -div#gallery_control_overlay a { - color:white; -} - -#gallery_images { -padding:10px 5px; -} diff --git a/apps/gallery/js/album_cover.js b/apps/gallery/js/album_cover.js index 619aa391c56..f6cb2da3103 100644 --- a/apps/gallery/js/album_cover.js +++ b/apps/gallery/js/album_cover.js @@ -31,7 +31,11 @@ function createNewAlbum() { } function scanForAlbums() { + $("#notification").fadeIn(); + $("#notification").slideDown(); $.getJSON('ajax/scanForAlbums.php', function(r) { + $("#notification").fadeOut(); + $("#notification").slideUp(); if (r.status == 'success') { window.location.reload(true); } else { diff --git a/apps/gallery/lib/album.php b/apps/gallery/lib/album.php index 0999429c5d5..98876b891c5 100644 --- a/apps/gallery/lib/album.php +++ b/apps/gallery/lib/album.php @@ -1,9 +1,9 @@ execute(array($owner, $name)); + public static function create($owner, $name, $path){ + $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name, album_path) VALUES (?, ?, ?)'); + $stmt->execute(array($owner, $name, $path)); } public static function rename($oldname, $newname, $owner) { @@ -22,14 +22,21 @@ class OC_Gallery_Album { return $stmt->execute($args); } - public static function find($owner, $name=null){ + public static function find($owner, $name=null, $path=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; + } $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 new file mode 100644 index 00000000000..5d1e7502aa3 --- /dev/null +++ b/apps/gallery/lib/hooks_handlers.php @@ -0,0 +1,36 @@ +numRows() == 0) { + $new_album_name = trim(str_replace('/', '.', $fullpath)); + if ($new_album_name == '.') $new_album_name = 'main'; + OC_Gallery_Album::create(OC_User::getUser(), $new_album_name, $path); + $album = OC_Gallery_Album::find(OC_User::getUser(), null, $path); + } + $album = $album->fetchRow(); + $albumId = $album['album_id']; + OC_Gallery_Photo::create($albumId, $fullpath); + + } +} + +?> diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php index 97d159935f5..a89a56981f5 100644 --- a/apps/gallery/lib/photo.php +++ b/apps/gallery/lib/photo.php @@ -25,4 +25,6 @@ class OC_Gallery_Photo{ .' AND photos.album_id = albums.album_id'); return $stmt->execute(array($owner, $album_name)); } + } + diff --git a/apps/gallery/lib/scanner.php b/apps/gallery/lib/scanner.php index 59c34b8e69a..f754f913001 100644 --- a/apps/gallery/lib/scanner.php +++ b/apps/gallery/lib/scanner.php @@ -21,13 +21,13 @@ class OC_Gallery_Scanner { 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']==='') ? + $current_album['name'] = ($current_album['name']==='.') ? 'main' : trim($current_album['name'],'.'); if ($dh = OC_Filesystem::opendir($path)) { while (($filename = readdir($dh)) !== false) { - $filepath = $path.'/'.$filename; + $filepath = ($path[strlen($path)-1]=='/'?$path:$path.'/').$filename; if (substr($filename, 0, 1) == '.') continue; if (OC_Filesystem::is_dir($filepath)) { self::scanDir($filepath, $albums); @@ -41,7 +41,7 @@ class OC_Gallery_Scanner { $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']); + 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(); diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php index 0e89e448768..7c6e91a468e 100644 --- a/apps/gallery/templates/index.php +++ b/apps/gallery/templates/index.php @@ -4,9 +4,10 @@ OC_Util::addScript('gallery', 'albums'); OC_Util::addScript('gallery', 'album_cover'); ?> +
- -
+ +