*
*/
-OC_Hook::connect("OC_Filesystem", "post_write", "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
-OC_Hook::connect("OC_Filesystem", "delete", "OC_Gallery_Hooks_Handlers", "removePhoto");
-OC_Hook::connect("OC_Filesystem", "post_rename", "OC_Gallery_Hooks_Handlers", "renamePhoto");
+OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_post_write, "OC_Gallery_Hooks_Handlers", "addPhotoFromPath");
+OC_Hook::connect(OC_Filesystem::CLASSNAME, OC_Filesystem::signal_delete, "OC_Gallery_Hooks_Handlers", "removePhoto");
+OC_Hook::connect(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']);
}
public static function addPhotoFromPath($params) {
- if (!self::isPhoto($params['path'])) return;
- $fullpath = $params['path'];
+ $fullpath = $params[OC_Filesystem::signal_param_path];
+
+ if (!self::isPhoto($fullpath)) return;
+
OC_Log::write(self::$APP_TAG, 'Adding file with path '. $fullpath, OC_Log::DEBUG);
$path = substr($fullpath, 0, strrpos($fullpath, '/'));
if ($path == '') $path = '/';
}
public static function removePhoto($params) {
- $path = $params['path'];
+ $path = $params[OC_Filesystem::signal_param_path];
if (OC_Filesystem::is_dir($path) && self::directoryContainsPhotos($path)) {
OC_Gallery_Album::removeByPath($path, OC_User::getUser());
} elseif (self::isPhoto($path)) {
}
public static function renamePhoto($params) {
- if (OC_Filesystem::is_dir($params['newpath']) && self::directoryContainsPhotos($params['newpath'])) {
- OC_Gallery_Album::changePath($params['oldpath'], $params['newpath'], OC_User::getUser());
- } elseif (!self::isPhoto($params['newpath'])) {
- $olddir = substr($params['oldpath'], 0, strrpos($params['oldpath'], '/'));
- $newdir = substr($params['newpath'], 0, strrpos($params['newpath'], '/'));
+ $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, OC_User::getUser());
+ } elseif (!self::isPhoto($newpath)) {
+ $olddir = substr($oldpath, 0, strrpos($oldpath, '/'));
+ $newdir = substr($newpath, 0, strrpos($newpath, '/'));
if ($olddir == '') $olddir = '/';
if ($newdir == '') $newdir = '/';
- if (!self::isPhoto($params['newpath'])) return;
- OC_Log::write(self::$APP_TAG, 'Moving photo from '.$params['oldpath'].' to '.$params['newpath'], OC_Log::DEBUG);
+ if (!self::isPhoto($newpath)) return;
+ OC_Log::write(self::$APP_TAG, 'Moving photo from '.$oldpath.' to '.$newpath, OC_Log::DEBUG);
$album;
$newAlbumId;
$oldAlbumId;
}
$newalbum = $newalbum->fetchRow();
if ($oldalbum->numRows() == 0) {
- OC_Gallery_Photo::create($newalbum['album_id'], $params['newpath']);
+ OC_Gallery_Photo::create($newalbum['album_id'], $newpath);
return;
}
$oldalbum = $oldalbum->fetchRow();
$oldAlbumId = $oldalbum['album_id'];
}
- OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $params['oldpath'], $params['newpath']);
+ OC_Gallery_Photo::changePath($oldAlbumId, $newAlbumId, $oldpath, $newpath);
}
}
}
static private $mounts=array();
static private $fakeRoot='';
static private $storageTypes=array();
+
+ /**
+ * classname which used for hooks handling
+ * used as signalclass in OC_Hooks::emit()
+ */
+ const CLASSNAME = 'OC_Filesystem';
+
+ /**
+ * signalname emited before file renaming
+ * @param oldpath
+ * @param newpath
+ */
+ const signal_rename = 'rename';
+
+ /**
+ * signal emited after file renaming
+ * @param oldpath
+ * @param newpath
+ */
+ const signal_post_rename = 'post_rename';
+ /**
+ * signal emited before file/dir creation
+ * @param path
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_create = 'create';
+
+ /**
+ * signal emited after file/dir creation
+ * @param path
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_post_create = 'post_create';
+
+ /**
+ * signal emits before file/dir copy
+ * @param oldpath
+ * @param newpath
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_copy = 'copy';
+
+ /**
+ * signal emits after file/dir copy
+ * @param oldpath
+ * @param newpath
+ */
+ const signal_post_copy = 'post_copy';
+
+ /**
+ * signal emits before file/dir save
+ * @param path
+ * @param run changing this flag to false in hook handler will cancel event
+ */
+ const signal_write = 'write';
+
+ /**
+ * signal emits after file/dir save
+ * @param path
+ */
+ const signal_post_write = 'post_write';
+ /**
+ * signal emits when reading file/dir
+ * @param path
+ */
+ const signal_read = 'read';
+
+ /**
+ * signal emits when removing file/dir
+ * @param path
+ */
+ const signal_delete = 'delete';
+
+ /**
+ * parameters definitions for signals
+ */
+ const signal_param_path = 'path';
+ const signal_param_oldpath = 'oldpath';
+ const signal_param_newpath = 'newpath';
+
+ /**
+ * run - changing this flag to false in hook handler will cancel event
+ */
+ const signal_param_run = 'run';
+
/**
* register a storage type
* @param string type
static public function rename($path1,$path2){
if(OC_FileProxy::runPreProxies('rename',$path1,$path2) and self::is_writeable($path1) and self::isValidPath($path2)){
$run=true;
- OC_Hook::emit( 'OC_Filesystem', 'rename', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_rename, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run));
if($run){
$mp1=self::getMountPoint($path1);
$mp2=self::getMountPoint($path2);
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
$storage1->unlink(self::getInternalPath($path1));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_rename', array( 'oldpath' => $path1, 'newpath'=>$path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_rename, array( self::signal_param_oldpath => $path1, self::signal_param_newpath=>$path2));
return $result;
}
}
static public function copy($path1,$path2){
if(OC_FileProxy::runPreProxies('copy',$path1,$path2) and self::is_readable($path1) and self::isValidPath($path2)){
$run=true;
- OC_Hook::emit( 'OC_Filesystem', 'copy', array( 'oldpath' => $path1 ,'newpath'=>$path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2, self::signal_param_run => &$run));
$exists=self::file_exists($path2);
if($run and !$exists){
- OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path2, self::signal_param_run => &$run));
}
if($run){
- OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path2, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path2, self::signal_param_run => &$run));
}
if($run){
$mp1=self::getMountPoint($path1);
$tmpFile=$storage1->toTmpFile(self::getInternalPath($path1));
$result=$storage2->fromTmpFile($tmpFile,self::getInternalPath($path2));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_copy', array( 'oldpath' => $path1 ,'newpath'=>$path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_copy, array( self::signal_param_oldpath => $path1 , self::signal_param_newpath=>$path2));
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path2));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path2));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path2));
return $result;
}
}
}
static public function toTmpFile($path){
if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::isValidPath($path) and $storage=self::getStorage($path)){
- OC_Hook::emit( 'OC_Filesystem', 'read', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_read, array( self::signal_param_path => $path));
return $storage->toTmpFile(self::getInternalPath($path));
}
}
$run=true;
$exists=self::file_exists($path);
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}
if($run){
- OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}
if($run){
$result=$storage->fromTmpFile($tmpFile,self::getInternalPath($path));
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path));
return $result;
}
}
$run=true;
$exists=self::file_exists($path);
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'create', array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_create, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}
if($run){
- OC_Hook::emit( 'OC_Filesystem', 'write', array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, self::signal_write, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}
if($run){
$result=$storage->fromUploadedFile($tmpFile,self::getInternalPath($path));
if(!$exists){
- OC_Hook::emit( 'OC_Filesystem', 'post_create', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_create, array( self::signal_param_path => $path));
}
- OC_Hook::emit( 'OC_Filesystem', 'post_write', array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, self::signal_post_write, array( self::signal_param_path => $path));
return $result;
}
}
$run=true;
foreach($hooks as $hook){
if($hook!='read'){
- OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path, 'run' => &$run));
+ OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path, self::signal_param_run => &$run));
}else{
- OC_Hook::emit( 'OC_Filesystem', $hook, array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, $hook, array( self::signal_param_path => $path));
}
}
if($run){
$result=OC_FileProxy::runPostProxies($operation,$path,$result);
foreach($hooks as $hook){
if($hook!='read'){
- OC_Hook::emit( 'OC_Filesystem', 'post_'.$hook, array( 'path' => $path));
+ OC_Hook::emit( self::CLASSNAME, 'post_'.$hook, array( self::signal_param_path => $path));
}
}
return $result;