Search cache for all filter available

pull/1/head
VicDeo 11 years ago
parent 5c59a2d374
commit 36b7d19e01

@ -13,6 +13,11 @@
namespace OCA\Documents; namespace OCA\Documents;
class Filter { 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( $data = array(
@ -20,7 +25,16 @@ namespace OCA\Documents;
'content' => $content '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; return $data;
} }
@ -30,9 +44,22 @@ namespace OCA\Documents;
'content' => $content '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; return $data;
} }
public static function getAll(){
return array_keys(self::$filters);
}
} }

@ -29,7 +29,7 @@ class Storage {
public static function getDocuments() { public static function getDocuments() {
$list = array_filter( $list = array_filter(
\OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), self::searchDocuments(),
function($item){ function($item){
//filter Deleted //filter Deleted
if (strpos($item['path'], '_trashbin')===0){ if (strpos($item['path'], '_trashbin')===0){
@ -44,7 +44,7 @@ class Storage {
public static function resolvePath($fileId){ public static function resolvePath($fileId){
$list = array_filter( $list = array_filter(
\OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR), self::searchDocuments(),
function($item) use ($fileId){ function($item) use ($fileId){
return intval($item['fileid'])==$fileId; return intval($item['fileid'])==$fileId;
} }
@ -83,4 +83,19 @@ class Storage {
Db_Session::cleanUp($session['es_id']); 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…
Cancel
Save