From 829b2b77b977102c4df0c1657b1bd7bc68c876ba Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Sat, 7 Jan 2017 21:21:21 +0100 Subject: [PATCH 1/5] add rtf and txt as supported file formats --- js/viewer/viewer.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/viewer/viewer.js b/js/viewer/viewer.js index 590801fe..88363694 100644 --- a/js/viewer/viewer.js +++ b/js/viewer/viewer.js @@ -12,6 +12,9 @@ var odfViewer = { 'application/vnd.wordperfect', 'application/msonenote', 'application/msword', + 'application/rtf', + 'text/rtf', + 'text/plain', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'application/vnd.ms-word.document.macroEnabled.12', @@ -244,4 +247,4 @@ $(document).ready(function() { $('#content').removeClass('loading'); } }, false); -}); \ No newline at end of file +}); From b565415e1c223afd690ce62aa9604aabe86b31a2 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Wed, 18 Jan 2017 10:08:18 +0100 Subject: [PATCH 2/5] set the correct language tag expected by JS --- lib/Controller/DocumentController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 731f10bc..43f1836a 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -233,12 +233,13 @@ class DocumentController extends Controller { if ($content && $view->file_put_contents($path, $content)) { $info = $view->getFileInfo($path); $ret = $this->wopiParser->getUrlSrc($mimetype); + $lolang = strtolower(str_replace('_', '-', $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'))); $response = array( 'status' => 'success', 'fileid' => $info['fileid'] . '_' . $this->settings->getSystemValue('instanceid'), 'urlsrc' => $ret['urlsrc'], 'action' => $ret['action'], - 'lolang' => $this->settings->getUserValue($this->uid, 'core', 'lang', 'en'), + 'lolang' => $lolang; 'data' => \OCA\Files\Helper::formatFileInfo($info) ); } else { From e5eb15cbc56baad720e1cc2a5a76346cc0368168 Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Wed, 18 Jan 2017 10:16:34 +0100 Subject: [PATCH 3/5] set the correct language tag expected by JS (typo fix) --- lib/Controller/DocumentController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 43f1836a..70580962 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -239,7 +239,7 @@ class DocumentController extends Controller { 'fileid' => $info['fileid'] . '_' . $this->settings->getSystemValue('instanceid'), 'urlsrc' => $ret['urlsrc'], 'action' => $ret['action'], - 'lolang' => $lolang; + 'lolang' => $lolang, 'data' => \OCA\Files\Helper::formatFileInfo($info) ); } else { From 86fb4ead721e8b50db3315e97bf5d2502ef88dfd Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Tue, 14 Mar 2017 11:59:37 +0100 Subject: [PATCH 4/5] '==' and '!=' are discouraged --- lib/db.php | 54 ++++++++++++++++++++++++------------------------- lib/db/wopi.php | 4 ++-- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/db.php b/lib/db.php index 10035714..11efefb3 100644 --- a/lib/db.php +++ b/lib/db.php @@ -12,23 +12,23 @@ namespace OCA\Richdocuments; /** - * Generic DB class + * Generic DB class */ abstract class Db { - + protected $data; - + protected $tableName; - + protected $insertStatement; - + protected $loadStatement; - + public function __construct($data = array()){ $this->setData($data); } - + /** * Insert current object data into database * @return mixed @@ -37,7 +37,7 @@ abstract class Db { $result = $this->execute($this->insertStatement); return $result; } - + /** * Get id of the recently inserted record * @return mixed @@ -45,7 +45,7 @@ abstract class Db { public function getLastInsertId(){ return \OC::$server->getDatabaseConnection()->lastInsertId($this->tableName); } - + /** * Get single record by primary key * @param int $value primary key value @@ -55,7 +55,7 @@ abstract class Db { if (!is_array($value)){ $value = array($value); } - + $result = $this->execute($this->loadStatement, $value); $data = $result->fetch(); if (!is_array($data)){ @@ -64,7 +64,7 @@ abstract class Db { $this->data = $data; return $this; } - + /** * Get single record matching condition * @param string $field for WHERE condition @@ -80,12 +80,12 @@ abstract class Db { $data = $result->fetchAll(); if (!is_array($data) || !count($data)){ $this->data = array(); - } elseif (count($data)!=1) { + } elseif (count($data) !== 1) { throw new Exception('Duplicate ' . $value . ' for the filed ' . $field); } else { $this->data = $data[0]; } - + return $this; } @@ -108,7 +108,7 @@ abstract class Db { $this->execute('DELETE FROM ' . $this->tableName . ' WHERE ' . $stmt, $value); } } - + /** * Get all records from the table * @return array @@ -121,7 +121,7 @@ abstract class Db { } return $data; } - + /** * Get array of matching records * @param string $field for WHERE condition @@ -141,14 +141,14 @@ abstract class Db { $stmt = $this->buildInQuery($field, $value); $result = $this->execute('SELECT * FROM ' . $this->tableName . ' WHERE '. $stmt , $value); } - + $data = $result->fetchAll(); if (!is_array($data)){ $data = array(); } return $data; } - + /** * Get object data * @return Array @@ -156,7 +156,7 @@ abstract class Db { public function getData(){ return $this->data; } - + /** * Set object data * @param array $data @@ -164,17 +164,17 @@ abstract class Db { public function setData($data){ $this->data = $data; } - + /** * Check if there are any data in current object - * @return bool + * @return bool */ public function hasData(){ return count($this->data)>0; } - + /** - * Build placeholders for the query with variable input data + * Build placeholders for the query with variable input data * @param string $field field name * @param Array $array data * @return String `field` IN (?, ?...) placeholders matching the number of elements in array @@ -185,17 +185,17 @@ abstract class Db { $stmt = implode(', ', $placeholders); return '`' . $field . '` IN (' . $stmt . ')'; } - + /** * Execute a query on database * @param string $statement query to be executed - * @param mixed $args value(s) for the query. + * @param mixed $args value(s) for the query. * If omited the query will be run on the current object $data * @return mixed (array/false) */ protected function execute($statement, $args = null){ $query = \OC::$server->getDatabaseConnection()->prepare($statement); - + if (!is_null($args)){ $result = $query->execute($args); } elseif (count($this->data)){ @@ -203,10 +203,10 @@ abstract class Db { } else { $result = $query->execute(); } - + return $result ? $query : false; } - + public function __call($name, $arguments){ if (substr($name, 0, 3) === 'get'){ $requestedProperty = substr($name, 3); diff --git a/lib/db/wopi.php b/lib/db/wopi.php index d7467659..0eded59d 100644 --- a/lib/db/wopi.php +++ b/lib/db/wopi.php @@ -61,7 +61,7 @@ class Wopi extends \OCA\Richdocuments\Db{ $wopi = new Wopi(); $row = $wopi->loadBy('token', $token)->getData(); \OC::$server->getLogger()->debug('Loaded WOPI Token record: {row}.', [ 'row' => $row ]); - if (count($row) == 0) + if (count($row) === 0) { // Invalid token. http_response_code(401); @@ -75,7 +75,7 @@ class Wopi extends \OCA\Richdocuments\Db{ //$wopi->deleteBy('id', $row['id']); //return false; } - if ($row['fileid'] != $fileId || $row['version'] != $version){ + if ($row['fileid'] !== $fileId || $row['version'] !== $version){ // File unknown / user unauthorized (for the requested file). http_response_code(404); return false; From 6d49e2d003b1c724bbc1e9958b2eb5946b75e2eb Mon Sep 17 00:00:00 2001 From: Andras Timar Date: Sun, 19 Mar 2017 00:27:05 +0100 Subject: [PATCH 5/5] replace trailing slash of wopi url --- js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/admin.js b/js/admin.js index e460218c..884e2512 100644 --- a/js/admin.js +++ b/js/admin.js @@ -4,7 +4,7 @@ var documentsSettings = { save : function() { $('#wopi_apply').attr('disabled', true); var data = { - wopi_url : $('#wopi_url').val() + wopi_url : $('#wopi_url').val().replace(/\/$/, '') }; OC.msg.startAction('#documents-admin-msg', t('richdocuments', 'Saving...'));