diff --git a/ajax/documentController.php b/ajax/documentController.php index eb0c826c..af64a37c 100644 --- a/ajax/documentController.php +++ b/ajax/documentController.php @@ -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; } diff --git a/ajax/sessionController.php b/ajax/sessionController.php index 65127695..b8b715ba 100644 --- a/ajax/sessionController.php +++ b/ajax/sessionController.php @@ -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); diff --git a/lib/filter.php b/lib/filter.php new file mode 100644 index 00000000..6dea3b77 --- /dev/null +++ b/lib/filter.php @@ -0,0 +1,38 @@ + $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; + } + + } + \ No newline at end of file diff --git a/lib/genesis.php b/lib/genesis.php index bb61d70c..c038d699 100644 --- a/lib/genesis.php +++ b/lib/genesis.php @@ -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; } diff --git a/lib/storage.php b/lib/storage.php old mode 100755 new mode 100644 index 49317d0c..8944bc01 --- a/lib/storage.php +++ b/lib/storage.php @@ -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; }