Use filters

pull/1/head
VicDeo 11 years ago
parent 0c5bcbdd61
commit 5c59a2d374

@ -26,7 +26,7 @@ class DocumentController extends Controller{
$content = base64_decode(self::ODT_TEMPLATE);
if (class_exists('\OC\Files\Type\TemplateManager')){
$manager = \OC_Helper::getFileTemplateManager();
$templateContent = $manager->getTemplate('application/vnd.oasis.opendocument.text');
$templateContent = $manager->getTemplate(Storage::MIMETYPE_LIBREOFFICE_WORDPROCESSOR);
if ($templateContent){
$content = $templateContent;
}

@ -115,8 +115,7 @@ class SessionController extends Controller{
// Active users except current user
$memberCount = count($memberIds) - 1;
if ($view->file_exists($path)){
if ($view->file_exists($path)){
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
@ -127,14 +126,21 @@ class SessionController extends Controller{
// Original file was modified externally. Save to a new one
$path = Helper::getNewFileName($view, $path, '-conflict');
}
$mimetype = $view->getMimeType($path);
} else {
$mimetype = Storage::MIMETYPE_LIBREOFFICE_WORDPROCESSOR;
}
if ($view->file_put_contents($path, $content)){
$data = Filter::write($content, $mimetype);
if ($view->file_put_contents($path, $data['content'])){
// Not a last user
if ($memberCount>0){
// Update genesis hash to prevent conflicts
Helper::debugLog('Update hash');
$session->updateGenesisHash($esId, sha1($content));
$session->updateGenesisHash($esId, sha1($data['content']));
} else {
// Last user. Kill session data
Db_Session::cleanUp($esId);

@ -0,0 +1,38 @@
<?php
/**
* ownCloud - Documents App
*
* @author Victor Dubiniuk
* @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
namespace OCA\Documents;
class Filter {
public static function read($content, $mimetype){
$data = array(
'mimetype' => $mimetype,
'content' => $content
);
\OCP\Util::emitHook('\OCA\Documents\Filter', 'read', $data);
return $data;
}
public static function write($content, $mimetype){
$data = array(
'mimetype' => $mimetype,
'content' => $content
);
\OCP\Util::emitHook('\OCA\Documents\Filter', 'write', $data);
return $data;
}
}

@ -52,11 +52,14 @@ class Genesis {
//copy new genesis to /user/documents/{hash}.odt
// get decrypted content
$content = $view->file_get_contents($path);
$mimetype = $view->getMimeType($path);
$data = Filter::read($content, $mimetype);
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
$this->view->file_put_contents($this->path, $content);
$this->view->file_put_contents($this->path, $data['content']);
\OC_FileProxy::$enabled = $proxyStatus;
}

@ -25,10 +25,11 @@
namespace OCA\Documents;
class Storage {
const MIMETYPE_LIBREOFFICE_WORDPROCESSOR = 'application/vnd.oasis.opendocument.text';
public static function getDocuments() {
$list = array_filter(
\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'),
\OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR),
function($item){
//filter Deleted
if (strpos($item['path'], '_trashbin')===0){
@ -43,7 +44,7 @@ class Storage {
public static function resolvePath($fileId){
$list = array_filter(
\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'),
\OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR),
function($item) use ($fileId){
return intval($item['fileid'])==$fileId;
}

Loading…
Cancel
Save