]> source.dussan.org Git - nextcloud-server.git/commitdiff
automatic adding of photo to album, feedback for user while scanning, general cleanup
authorBartek Przybylski <bart.p.pl@gmail.com>
Sat, 7 Jan 2012 23:14:34 +0000 (00:14 +0100)
committerBartek Przybylski <bart.p.pl@gmail.com>
Sat, 7 Jan 2012 23:14:34 +0000 (00:14 +0100)
apps/gallery/ajax/galleryOp.php
apps/gallery/ajax/scanForAlbums.php
apps/gallery/appinfo/app.php
apps/gallery/appinfo/database.xml
apps/gallery/css/styles.css
apps/gallery/js/album_cover.js
apps/gallery/lib/album.php
apps/gallery/lib/hooks_handlers.php [new file with mode: 0644]
apps/gallery/lib/photo.php
apps/gallery/lib/scanner.php
apps/gallery/templates/index.php

index cd7cab202b118eda196ccc00532116943d8fe73c..8a006dda63700923886c192d44fc7e6d87292f75 100644 (file)
@@ -1,6 +1,6 @@
 <?
 require_once('../../../lib/base.php');
-require_once('../lib/album.php');
+require_once(OC::$CLASSPATH['OC_Gallery_Album']);
 OC_JSON::checkLoggedIn();
 OC_JSON::checkAppEnabled('gallery');
 
@@ -26,4 +26,4 @@ if ($_GET['operation']) {
      OC_JSON::error(array('cause' => "Unknown operation"));
   }
 }
-?>
\ No newline at end of file
+?>
index f603cbb497173b95f02123f188db511552590494..b1f0a433a42c6906d1352a105df07b8162aca917 100644 (file)
@@ -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('/')));
 
 ?>
index 2b1ab857afcdacbe24dc0ef5f8d75582c0966160..3a2dbcb43adca1d5e10f7e1739d80715804d5de7 100644 (file)
@@ -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');
 ?>
index fd55b3a6fb4cd320e8b3d8b34d11415185671d85..db88e4c1b5a875d0130894a16643806db423b1a4 100644 (file)
                                <notnull>true</notnull>
                                <length>100</length>
                        </field>
+      <field>
+        <name>album_path</name>
+        <type>text</type>
+        <notnull>true</notnull>
+        <length>100</length>
+      </field>
                </declaration>
        </table>
        <table>
index 53c3c0901d96c6cf4f4ed82c78aa2596052bf6fb..cc343ba0d08515ffe3eff87cde109d03cc2433a4 100644 (file)
@@ -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;
-}
index 619aa391c564cbea90e8a75b0cdca337e7c7e5da..f6cb2da3103fb739049240f1e8804a46f9eb5b91 100644 (file)
@@ -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 {
index 0999429c5d5ca40f3487952cac9a496c2cb1112f..98876b891c592b57c3505a60bee0f06495c49960 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 
 class OC_Gallery_Album {
-       public static function create($owner, $name){
-               $stmt = OC_DB::prepare('INSERT INTO *PREFIX*gallery_albums (uid_owner, album_name) VALUES (?, ?)');
-               $stmt->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 (file)
index 0000000..5d1e750
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+OC_Hook::connect("OC_Filesystem", "post_write", "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
+
+require_once(OC::$CLASSPATH['OC_Gallery_Album']);
+require_once(OC::$CLASSPATH['OC_Gallery_Photo']);
+
+class OC_Gallery_Hooks_Handlers {
+  private static $APP_TAG = "Gallery";
+
+  private static function isPhoto($filename) {
+    if (substr(OC_Filesystem::getMimeType($filename), 0, 6) == "image/")
+      return 1;
+    return 0;
+  }
+
+  public static function addPhotoFromPath($params) {
+    if (!self::isPhoto($params['path'])) return;
+    $fullpath = $params['path'];
+    OC_Log::write(self::$APP_TAG, 'Adding file with path '. $fullpath, OC_Log::DEBUG);
+    $path = substr($fullpath, 0, strrpos($fullpath, '/'));
+    $album = OC_Gallery_Album::find(OC_User::getUser(), null, $path);
+    if ($album->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);
+
+  }
+}
+
+?>
index 97d159935f543028aac257efb1cefed0e5dcf91e..a89a56981f506826ebb3675255b61196693e250e 100644 (file)
@@ -25,4 +25,6 @@ class OC_Gallery_Photo{
                                .' AND photos.album_id = albums.album_id');
                return $stmt->execute(array($owner, $album_name));
        }
+
 }
+
index 59c34b8e69a075953c34e3c605890d7a2ae19db7..f754f913001ccd06bc1de010f0bfd591596fcb3c 100644 (file)
@@ -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();
index 0e89e448768bfab117352aa774b6b41bf95db968..7c6e91a468eab23b3ea3212b55fc43b74f007cc0 100644 (file)
@@ -4,9 +4,10 @@ OC_Util::addScript('gallery', 'albums');
 OC_Util::addScript('gallery', 'album_cover');
 ?>
 
+<div id="notification"><div id="gallery_notification_text">Creating thumbnails</div></div>
 <div id="controls">
-  <!--  <input type="button" value="New album" onclick="javascript:createNewAlbum();" />-->
-  <input type="button" value="Rescan" onclick="javascript:scanForAlbums();" /><br/>
+  <input type="button" value="Rescan" onclick="javascript:scanForAlbums();" />
+  <br/>
 </div>
 <div id="gallery_list">
 </div>