diff --git a/lib/filter.php b/lib/filter.php index 6dea3b77..e7ef4833 100644 --- a/lib/filter.php +++ b/lib/filter.php @@ -13,14 +13,28 @@ namespace OCA\Documents; class Filter { + protected static $filters = array(); + + public static function add($mimetype, $class){ + self::$filters[$mimetype] = $class; + } - public static function read($content, $mimetype){ + public static function read($content, $mimetype){ $data = array( 'mimetype' => $mimetype, 'content' => $content ); + + if (isset(self::$filters[$mimetype])){ + $data = call_user_func( + array( + self::$filters[$mimetype], + 'read' + ), + $data + ); + } - \OCP\Util::emitHook('\OCA\Documents\Filter', 'read', $data); return $data; } @@ -30,9 +44,22 @@ namespace OCA\Documents; 'content' => $content ); - \OCP\Util::emitHook('\OCA\Documents\Filter', 'write', $data); + if (isset(self::$filters[$mimetype])){ + $data = call_user_func( + array( + self::$filters[$mimetype], + 'write' + ), + $data + ); + } + return $data; } + public static function getAll(){ + return array_keys(self::$filters); + } + } \ No newline at end of file diff --git a/lib/storage.php b/lib/storage.php index 8944bc01..e8f8f162 100644 --- a/lib/storage.php +++ b/lib/storage.php @@ -29,7 +29,7 @@ class Storage { public static function getDocuments() { $list = array_filter( - \OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), + self::searchDocuments(), function($item){ //filter Deleted if (strpos($item['path'], '_trashbin')===0){ @@ -44,7 +44,7 @@ class Storage { public static function resolvePath($fileId){ $list = array_filter( - \OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), + self::searchDocuments(), function($item) use ($fileId){ return intval($item['fileid'])==$fileId; } @@ -83,4 +83,19 @@ class Storage { Db_Session::cleanUp($session['es_id']); } + + protected static function searchDocuments(){ + $documents = array(); + foreach (self::getSupportedMimetypes() as $mime){ + $documents = array_merge($documents, \OCP\Files::searchByMime($mime)); + } + return $documents; + } + + protected static function getSupportedMimetypes(){ + return array_merge( + array(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), + Filter::getAll() + ); + } }