Use filters
This commit is contained in:
parent
0c5bcbdd61
commit
5c59a2d374
@ -26,7 +26,7 @@ class DocumentController extends Controller{
|
|||||||
$content = base64_decode(self::ODT_TEMPLATE);
|
$content = base64_decode(self::ODT_TEMPLATE);
|
||||||
if (class_exists('\OC\Files\Type\TemplateManager')){
|
if (class_exists('\OC\Files\Type\TemplateManager')){
|
||||||
$manager = \OC_Helper::getFileTemplateManager();
|
$manager = \OC_Helper::getFileTemplateManager();
|
||||||
$templateContent = $manager->getTemplate('application/vnd.oasis.opendocument.text');
|
$templateContent = $manager->getTemplate(Storage::MIMETYPE_LIBREOFFICE_WORDPROCESSOR);
|
||||||
if ($templateContent){
|
if ($templateContent){
|
||||||
$content = $templateContent;
|
$content = $templateContent;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,6 @@ class SessionController extends Controller{
|
|||||||
|
|
||||||
if ($view->file_exists($path)){
|
if ($view->file_exists($path)){
|
||||||
|
|
||||||
|
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
\OC_FileProxy::$enabled = false;
|
\OC_FileProxy::$enabled = false;
|
||||||
$currentHash = sha1($view->file_get_contents($path));
|
$currentHash = sha1($view->file_get_contents($path));
|
||||||
@ -127,14 +126,21 @@ class SessionController extends Controller{
|
|||||||
// Original file was modified externally. Save to a new one
|
// Original file was modified externally. Save to a new one
|
||||||
$path = Helper::getNewFileName($view, $path, '-conflict');
|
$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
|
// Not a last user
|
||||||
if ($memberCount>0){
|
if ($memberCount>0){
|
||||||
// Update genesis hash to prevent conflicts
|
// Update genesis hash to prevent conflicts
|
||||||
Helper::debugLog('Update hash');
|
Helper::debugLog('Update hash');
|
||||||
$session->updateGenesisHash($esId, sha1($content));
|
|
||||||
|
$session->updateGenesisHash($esId, sha1($data['content']));
|
||||||
} else {
|
} else {
|
||||||
// Last user. Kill session data
|
// Last user. Kill session data
|
||||||
Db_Session::cleanUp($esId);
|
Db_Session::cleanUp($esId);
|
||||||
|
38
lib/filter.php
Normal file
38
lib/filter.php
Normal file
@ -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
|
//copy new genesis to /user/documents/{hash}.odt
|
||||||
// get decrypted content
|
// get decrypted content
|
||||||
$content = $view->file_get_contents($path);
|
$content = $view->file_get_contents($path);
|
||||||
|
$mimetype = $view->getMimeType($path);
|
||||||
|
|
||||||
|
$data = Filter::read($content, $mimetype);
|
||||||
|
|
||||||
$proxyStatus = \OC_FileProxy::$enabled;
|
$proxyStatus = \OC_FileProxy::$enabled;
|
||||||
\OC_FileProxy::$enabled = false;
|
\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;
|
\OC_FileProxy::$enabled = $proxyStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
lib/storage.php
Executable file → Normal file
5
lib/storage.php
Executable file → Normal file
@ -25,10 +25,11 @@
|
|||||||
namespace OCA\Documents;
|
namespace OCA\Documents;
|
||||||
|
|
||||||
class Storage {
|
class Storage {
|
||||||
|
const MIMETYPE_LIBREOFFICE_WORDPROCESSOR = 'application/vnd.oasis.opendocument.text';
|
||||||
|
|
||||||
public static function getDocuments() {
|
public static function getDocuments() {
|
||||||
$list = array_filter(
|
$list = array_filter(
|
||||||
\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'),
|
\OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR),
|
||||||
function($item){
|
function($item){
|
||||||
//filter Deleted
|
//filter Deleted
|
||||||
if (strpos($item['path'], '_trashbin')===0){
|
if (strpos($item['path'], '_trashbin')===0){
|
||||||
@ -43,7 +44,7 @@ class Storage {
|
|||||||
|
|
||||||
public static function resolvePath($fileId){
|
public static function resolvePath($fileId){
|
||||||
$list = array_filter(
|
$list = array_filter(
|
||||||
\OCP\Files::searchByMime('application/vnd.oasis.opendocument.text'),
|
\OCP\Files::searchByMime(self::MIMETYPE_LIBREOFFICE_WORDPROCESSOR),
|
||||||
function($item) use ($fileId){
|
function($item) use ($fileId){
|
||||||
return intval($item['fileid'])==$fileId;
|
return intval($item['fileid'])==$fileId;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user