Search cache for all filter available
This commit is contained in:
parent
5c59a2d374
commit
36b7d19e01
@ -13,6 +13,11 @@
|
||||
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){
|
||||
$data = array(
|
||||
@ -20,7 +25,16 @@ namespace OCA\Documents;
|
||||
'content' => $content
|
||||
);
|
||||
|
||||
\OCP\Util::emitHook('\OCA\Documents\Filter', 'read', $data);
|
||||
if (isset(self::$filters[$mimetype])){
|
||||
$data = call_user_func(
|
||||
array(
|
||||
self::$filters[$mimetype],
|
||||
'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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user