diff options
author | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-06-08 20:26:17 +0200 |
---|---|---|
committer | Bartek Przybylski <bart.p.pl@gmail.com> | 2012-06-08 21:44:31 +0200 |
commit | 9e434dea605b029d56f1bed01d87c26a0c7f4ebb (patch) | |
tree | 05cdcf3ea3bdace08989aade3e1ada0e99c76bc1 /apps/gallery/lib | |
parent | ac365121022f8b03ac47c41f8b3e32f9ba3f90e6 (diff) | |
download | nextcloud-server-9e434dea605b029d56f1bed01d87c26a0c7f4ebb.tar.gz nextcloud-server-9e434dea605b029d56f1bed01d87c26a0c7f4ebb.zip |
tabs for spaces, removing thumbnail on file removal
Diffstat (limited to 'apps/gallery/lib')
-rw-r--r-- | apps/gallery/lib/hooks_handlers.php | 224 | ||||
-rw-r--r-- | apps/gallery/lib/managers.php | 2 | ||||
-rw-r--r-- | apps/gallery/lib/tiles.php | 4 |
3 files changed, 107 insertions, 123 deletions
diff --git a/apps/gallery/lib/hooks_handlers.php b/apps/gallery/lib/hooks_handlers.php index 6391e9f4e54..30c4b50577d 100644 --- a/apps/gallery/lib/hooks_handlers.php +++ b/apps/gallery/lib/hooks_handlers.php @@ -13,136 +13,120 @@ * * 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/>. * */ -OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OC_Gallery_Hooks_Handlers", "addPhotoFromPath"); OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto"); //OCP\Util::connectHook(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_rename, "OC_Gallery_Hooks_Handlers", "renamePhoto"); -require_once(OC::$CLASSPATH['OC_Gallery_Album']); -require_once(OC::$CLASSPATH['OC_Gallery_Photo']); +require_once(OC::$CLASSPATH['Pictures_Managers']); class OC_Gallery_Hooks_Handlers { - private static $APP_TAG = "Gallery"; - - private static function isPhoto($filename) { - $ext = strtolower(substr($filename, strrpos($filename, '.')+1)); - return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif'; - } - - private static function directoryContainsPhotos($dirpath) { - $dirhandle = OC_Filesystem::opendir($dirpath.'/'); - if ($dirhandle != FALSE) { - while (($filename = readdir($dirhandle)) != FALSE) { - if ($filename[0] == '.') continue; - if (self::isPhoto($dirpath.'/'.$filename)) return true; - } - } - return false; - } - - private static function createAlbum($path) { - $new_album_name = trim(str_replace('/', '.', $path), '.'); - if ($new_album_name == '') - $new_album_name = 'main'; - - OCP\Util::writeLog(self::$APP_TAG, 'Creating new album '.$new_album_name, OCP\Util::DEBUG); - OC_Gallery_Album::create(OCP\USER::getUser(), $new_album_name, $path); - - return OC_Gallery_Album::find(OCP\USER::getUser(), null, $path); - } - - public static function pathInRoot($path) { - $root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/'); - return substr($path, 0, strlen($path)>strlen($root)?strlen($root):strlen($path)) == $root; - } - - public static function addPhotoFromPath($params) { - $fullpath = $params[OC_Filesystem::signal_param_path]; - $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath); - - if (!self::isPhoto($fullpath)) return; - - $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, dirname($fullpath)); - if (!($r = $a->fetchRow())) { - OC_Gallery_Album::create(OCP\USER::getUser(), basename(dirname($fullpath)), dirname($fullpath)); - $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, dirname($fullpath)); - $r = $a->fetchRow(); - } - $albumId = $r['album_id']; - $p = OC_Gallery_Album::find($albumId, $fullpath); - if (!($p->fetchRow())) - OC_Gallery_Photo::create($albumId, $fullpath); - } - - public static function removePhoto($params) { - $fullpath = $params[OC_Filesystem::signal_param_path]; - $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath); - - if (OC_Filesystem::is_dir($fullpath)) { - OC_Gallery_Album::remove(OCP\USER::getUser(), null, $fullpath); - } elseif (self::isPhoto($fullpath)) { - $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, rtrim(dirname($fullpath),'/')); - if (($r = $a->fetchRow())) { - OC_Gallery_Photo::removeByPath($fullpath, $r['album_id']); - $p = OC_Gallery_Photo::findForAlbum(OCP\USER::getUser(), $r['album_name']); - if (!($p->fetchRow())) { - OC_Gallery_Album::remove(OCP\USER::getUser(), null, dirname($fullpath)); - } - } - } - } - - public static function renamePhoto($params) { - $oldpath = $params[OC_Filesystem::signal_param_oldpath]; - $newpath = $params[OC_Filesystem::signal_param_newpath]; - if (OC_Filesystem::is_dir($newpath.'/') && self::directoryContainsPhotos($newpath)) { - OC_Gallery_Album::changePath($oldpath, $newpath, OCP\USER::getUser()); - } elseif (self::isPhoto($newpath)) { - $olddir = dirname($oldpath); - $newdir = dirname($newpath); - if ($olddir == '') $olddir = '/'; - if ($newdir == '') $newdir = '/'; - if (!self::isPhoto($newpath)) return; - OCP\Util::writeLog(self::$APP_TAG, 'Moving photo from '.$oldpath.' to '.$newpath, OCP\Util::DEBUG); - $album; - $newAlbumId; - $oldAlbumId; - if ($olddir == $newdir) { - // album changing is not needed - $albums = OC_Gallery_Album::find(OCP\USER::getUser(), null, $olddir); - $album = $albums->fetchRow(); - if (!$album) { - $albums = self::createAlbum($newdir); - $album = $albums->fetchRow(); - } - $newAlbumId = $oldAlbumId = $album['album_id']; - } else { - $newalbum = OC_Gallery_Album::find(OCP\USER::getUser(), null, $newdir); - $oldalbum = OC_Gallery_Album::find(OCP\USER::getUser(), null, $olddir); - - if (!($newalbum = $newalbum->fetchRow())) { - $newalbum = self::createAlbum($newdir); - $newalbum = $newalbum->fetchRow(); - } - $oldalbum = $oldalbum->fetchRow(); - if (!$oldalbum) { - OC_Gallery_Photo::create($newalbum['album_id'], $newpath); - return; - } - $newAlbumId = $newalbum['album_id']; - $oldAlbumId = $oldalbum['album_id']; - - } - OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath); - } - } + private static $APP_TAG = "Gallery"; + + private static function isPhoto($filename) { + $ext = strtolower(substr($filename, strrpos($filename, '.')+1)); + return $ext=='png' || $ext=='jpeg' || $ext=='jpg' || $ext=='gif'; + } + + private static function directoryContainsPhotos($dirpath) { + $dirhandle = OC_Filesystem::opendir($dirpath.'/'); + if ($dirhandle != FALSE) { + while (($filename = readdir($dirhandle)) != FALSE) { + if ($filename[0] == '.') continue; + if (self::isPhoto($dirpath.'/'.$filename)) return true; + } + } + return false; + } + + private static function createAlbum($path) { + $new_album_name = trim(str_replace('/', '.', $path), '.'); + if ($new_album_name == '') + $new_album_name = 'main'; + + OCP\Util::writeLog(self::$APP_TAG, 'Creating new album '.$new_album_name, OCP\Util::DEBUG); + OC_Gallery_Album::create(OCP\USER::getUser(), $new_album_name, $path); + + return OC_Gallery_Album::find(OCP\USER::getUser(), null, $path); + } + + public static function pathInRoot($path) { + $root = OCP\Config::getUserValue(OCP\USER::getUser(), 'gallery', 'root', '/'); + return substr($path, 0, strlen($path)>strlen($root)?strlen($root):strlen($path)) == $root; + } + + public static function addPhotoFromPath($params) { + $fullpath = $params[OC_Filesystem::signal_param_path]; + $fullpath = rtrim(dirname($fullpath),'/').'/'.basename($fullpath); + + if (!self::isPhoto($fullpath)) return; + + $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, dirname($fullpath)); + if (!($r = $a->fetchRow())) { + OC_Gallery_Album::create(OCP\USER::getUser(), basename(dirname($fullpath)), dirname($fullpath)); + $a = OC_Gallery_Album::find(OCP\USER::getUser(), null, dirname($fullpath)); + $r = $a->fetchRow(); + } + $albumId = $r['album_id']; + $p = OC_Gallery_Album::find($albumId, $fullpath); + if (!($p->fetchRow())) + OC_Gallery_Photo::create($albumId, $fullpath); + } + + public static function removePhoto($params) { + \OC\Pictures\ThumbnailsManager::getInstance()->delete($params[OC_Filesystem::signal_param_path]); + } + + public static function renamePhoto($params) { + $oldpath = $params[OC_Filesystem::signal_param_oldpath]; + $newpath = $params[OC_Filesystem::signal_param_newpath]; + if (OC_Filesystem::is_dir($newpath.'/') && self::directoryContainsPhotos($newpath)) { + OC_Gallery_Album::changePath($oldpath, $newpath, OCP\USER::getUser()); + } elseif (self::isPhoto($newpath)) { + $olddir = dirname($oldpath); + $newdir = dirname($newpath); + if ($olddir == '') $olddir = '/'; + if ($newdir == '') $newdir = '/'; + if (!self::isPhoto($newpath)) return; + OCP\Util::writeLog(self::$APP_TAG, 'Moving photo from '.$oldpath.' to '.$newpath, OCP\Util::DEBUG); + $album; + $newAlbumId; + $oldAlbumId; + if ($olddir == $newdir) { + // album changing is not needed + $albums = OC_Gallery_Album::find(OCP\USER::getUser(), null, $olddir); + $album = $albums->fetchRow(); + if (!$album) { + $albums = self::createAlbum($newdir); + $album = $albums->fetchRow(); + } + $newAlbumId = $oldAlbumId = $album['album_id']; + } else { + $newalbum = OC_Gallery_Album::find(OCP\USER::getUser(), null, $newdir); + $oldalbum = OC_Gallery_Album::find(OCP\USER::getUser(), null, $olddir); + + if (!($newalbum = $newalbum->fetchRow())) { + $newalbum = self::createAlbum($newdir); + $newalbum = $newalbum->fetchRow(); + } + $oldalbum = $oldalbum->fetchRow(); + if (!$oldalbum) { + OC_Gallery_Photo::create($newalbum['album_id'], $newpath); + return; + } + $newAlbumId = $newalbum['album_id']; + $oldAlbumId = $oldalbum['album_id']; + + } + OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath); + } + } } ?> diff --git a/apps/gallery/lib/managers.php b/apps/gallery/lib/managers.php index 2444659d0a4..2d2bdd2734b 100644 --- a/apps/gallery/lib/managers.php +++ b/apps/gallery/lib/managers.php @@ -88,7 +88,7 @@ class ThumbnailsManager { } public function delete($path) { - unlink(\OC::$CONFIG_DATADIRECTORY_ROOT.'/'.\OC_User::getUser()."/gallery".$path); + unlink(\OCP\Config::getSystemValue('datadirectory').'/'.\OC_User::getUser()."/gallery".$path); } private function __construct() {} diff --git a/apps/gallery/lib/tiles.php b/apps/gallery/lib/tiles.php index ff9519142ac..f1961cb72e5 100644 --- a/apps/gallery/lib/tiles.php +++ b/apps/gallery/lib/tiles.php @@ -156,11 +156,11 @@ class TileStack extends TileBase { } public function getOnHoverAction() { - return 'javascript:t(this);return false;'; + return 'javascript:explode(this);return false;'; } public function getOnOutAction() { - return 'javascript:o(this);return false;'; + return 'javascript:deplode(this);return false;'; } public function getCount() { |