<?
require_once('../../../lib/base.php');
-require_once('../lib/album.php');
+require_once(OC::$CLASSPATH['OC_Gallery_Album']);
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
OC_JSON::error(array('cause' => "Unknown operation"));
}
}
-?>
\ No newline at end of file
+?>
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('/')));
?>
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,
}
new OC_GallerySearchProvider();
+
+require_once('apps/gallery/lib/hooks_handlers.php');
?>
<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>
-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;
-}
}
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 {
<?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) {
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);
}
+
}
+
+?>
--- /dev/null
+<?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);
+
+ }
+}
+
+?>
.' AND photos.album_id = albums.album_id');
return $stmt->execute(array($owner, $album_name));
}
+
}
+
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);
$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();
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>