';
+ $('div#gallery_list').append(v);
+ }
+ });
+ }
+}
+
+function scanForAlbums() {
+ $.getJSON('ajax/scanForAlbums.php', function(r) {
+ if (r.status == 'success') {
+ window.location.reload(true);
+ } else {
+ alert('Error occured: ' + r.message);
+ }
+ });
+}
diff --git a/apps/gallery/js/albums.js b/apps/gallery/js/albums.js
new file mode 100644
index 0000000000..7ab243eded
--- /dev/null
+++ b/apps/gallery/js/albums.js
@@ -0,0 +1,80 @@
+Albums={
+ // album item in this array should look as follow
+ // {name: string,
+ // numOfCovers: int}
+ //
+ // previews array should be an array of base64 decoded images
+ // to display to user as preview picture when scrolling throught
+ // the album cover
+ albums:new Array(),
+ // add simply adds new album to internal structure
+ // however albums names must be unique so other
+ // album with the same name wont be insered,
+ // and false will be returned
+ // true on success
+ add: function(album_name, num) {
+ for (var a in Albums.albums) {
+ if (a.name == album_name) {
+ return false;
+ }
+ }
+ Albums.albums.push({name: album_name, numOfCovers: num});
+ return true;
+ },
+ // remove element with given name
+ // returns remove element or undefined if no such element was present
+ remove: function(name) {
+ var i = -1, tmp = 0;
+ for (var a in Albums.albums) {
+ if (a.name == name) {
+ i = tmp;
+ break;
+ }
+ tmp++;
+ }
+ if (i != -1) {
+ return Albums.albums.splice(i,1);
+ }
+ return undefined;
+ },
+ // return element which match given name
+ // of undefined if such element do not exist
+ find: function(name) {
+ var i = -1, tmp = 0;
+ for (var k in Albums.albums) {
+ var a = Albums.albums[k];
+ if (a.name == name) {
+ i = tmp;
+ break;
+ }
+ tmp++;
+ }
+ if (i != -1) {
+ return Albums.albums[i];
+ }
+ return undefined;
+ },
+ // displays gallery in linear representation
+ // on given element, and apply default styles for gallery
+ display: function(element) {
+ var displayTemplate = '
*NAME*
';
+ for (var i in Albums.albums) {
+ var a = Albums.albums[i];
+ 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.mousemove(function(e) {
+ var albumMetadata = Albums.find(this.title);
+ if (albumMetadata == undefined) {
+ return;
+ }
+ var x = Math.min(Math.floor((e.clientX - this.offsetLeft)/(this.offsetWidth/albumMetadata.numOfCovers)), albumMetadata.numOfCovers-1);
+ x *= this.offsetWidth;
+ $(this).css('background-position', -x+'px 0');
+ });
+ $(element).append(local);
+ }
+ }
+
+}
diff --git a/apps/gallery/lib_scanner.php b/apps/gallery/lib_scanner.php
new file mode 100644
index 0000000000..fe14b68add
--- /dev/null
+++ b/apps/gallery/lib_scanner.php
@@ -0,0 +1,57 @@
+ $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':$current_album['name'];
+
+ if ($dh = OC_Filesystem::opendir($path)) {
+ while (($filename = readdir($dh)) !== false) {
+ $filepath = $path.'/'.$filename;
+ if (substr($filename, 0, 1) == '.') continue;
+ if (OC_Filesystem::is_dir($filepath)) {
+ self::scanDir($filepath, $albums);
+ } elseif (self::isPhoto($path.'/'.$filename)) {
+ $current_album['images'][] = $filepath;
+ }
+ }
+ }
+ $current_album['imagesCount'] = count($current_album['images']);
+ $albums[] = $current_album;
+ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE "uid_owner" = ? AND "album_name" = ?');
+ $result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+ if ($result->numRows() == 0 && count($current_album['images'])) {
+ $stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_albums ("uid_owner", "album_name") VALUES (?, ?)');
+ $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+ }
+ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_albums WHERE "uid_owner" = ? AND "album_name" = ?');
+ $result = $stmt->execute(array(OC_User::getUser(), $current_album['name']));
+ $albumId = $result->fetchRow();
+ $albumId = $albumId['album_id'];
+ foreach ($current_album['images'] as $img) {
+ $stmt = OC_DB::prepare('SELECT * FROM *PREFIX*gallery_photos WHERE "album_id" = ? AND "file_path" = ?');
+ $result = $stmt->execute(array($albumId, $img));
+ if ($result->numRows() == 0) {
+ $stmt = OC_DB::prepare('INSERT OR REPLACE INTO *PREFIX*gallery_photos ("album_id", "file_path") VALUES (?, ?)');
+ $stmt->execute(array($albumId, $img));
+ }
+ }
+ }
+
+ public static function isPhoto($filename) {
+ if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/")
+ return 1;
+ return 0;
+ }
+}
+?>
diff --git a/apps/gallery/templates/index.php b/apps/gallery/templates/index.php
new file mode 100644
index 0000000000..0e89e44876
--- /dev/null
+++ b/apps/gallery/templates/index.php
@@ -0,0 +1,12 @@
+
+
+