diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-08-26 12:07:44 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-08-30 17:52:19 +0300 |
commit | befa1ce66ee14971fba6cf3e4a9ce017e0565f98 (patch) | |
tree | d092bbff0c9ae029c112f9a0d7c568eecbc73c02 /lib | |
parent | c52596c187fc04fed32b89d3814a0c14ef38c5ee (diff) |
Store watermark settings in a generic way
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppConfig.php | 29 | ||||
-rw-r--r-- | lib/Controller/WopiController.php | 22 |
2 files changed, 35 insertions, 16 deletions
diff --git a/lib/AppConfig.php b/lib/AppConfig.php index 0f5e1129..af89df52 100644 --- a/lib/AppConfig.php +++ b/lib/AppConfig.php @@ -14,7 +14,8 @@ namespace OCA\Richdocuments; use OCA\Richdocuments\AppInfo\Application; use \OCP\IConfig; -class AppConfig{ +class AppConfig { + private $defaults = [ 'wopi_url' => 'https://localhost:9980', 'watermark_text' => '{userId}', @@ -24,6 +25,8 @@ class AppConfig{ ]; + const WATERMARK_APP_NAMESPACE = 'files'; + const APP_SETTING_TYPES = [ 'watermark_allGroupsList' => 'array', 'watermark_allTagsList' => 'array', @@ -37,6 +40,13 @@ class AppConfig{ $this->config = $config; } + public function getAppNamespace($key) { + if (strpos($key, 'watermark_') === 0) { + return self::WATERMARK_APP_NAMESPACE; + } + return Application::APPNAME; + } + /** * Get a value by key * @param string $key @@ -47,7 +57,7 @@ class AppConfig{ if (array_key_exists($key, $this->defaults)){ $defaultValue = $this->defaults[$key]; } - return $this->config->getAppValue(Application::APPNAME, $key, $defaultValue); + return $this->config->getAppValue($this->getAppNamespace($key), $key, $defaultValue); } /** @@ -55,7 +65,7 @@ class AppConfig{ * @return array */ public function getAppValueArray($key) { - $value = $this->config->getAppValue(Application::APPNAME, $key, []); + $value = $this->config->getAppValue($this->getAppNamespace($key), $key, []); if (self::APP_SETTING_TYPES[$key] === 'array') { $value = $value !== '' ? explode(',', $value) : []; } @@ -69,7 +79,7 @@ class AppConfig{ * @return void */ public function setAppValue($key, $value) { - $this->config->setAppValue(Application::APPNAME, $key, $value); + $this->config->setAppValue($this->getAppNamespace($key), $key, $value); } /** @@ -78,12 +88,21 @@ class AppConfig{ */ public function getAppSettings() { $result = []; - $keys = $this->config->getAppKeys('richdocuments'); + $keys = $this->config->getAppKeys(Application::APPNAME); foreach ($keys as $key) { $value = $this->getAppValueArray($key); $value = $value === 'yes' ? true : $value; $result[$key] = $value === 'no' ? false : $value; } + + $keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE); + foreach ($keys as $key) { + if (strpos($key, 'watermark_') === 0) { + $value = $this->getAppValueArray($key); + $value = $value === 'yes' ? true : $value; + $result[$key] = $value === 'no' ? false : $value; + } + } return $result; } diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 76a0cc12..48b2e0ec 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -194,9 +194,9 @@ class WopiController extends Controller { 'userId' => $wopi->getEditorUid(), 'date' => (new \DateTime())->format('Y-m-d H:i:s'), 'themingName' => \OC::$server->getThemingDefaults()->getName(), - 'themingName' => \OC::$server->getThemingDefaults()->getName(), + ]; - $watermarkTemplate = $this->config->getAppValue('richdocuments', 'watermark_text', '{userId}'); + $watermarkTemplate = $this->appConfig->getAppValue('watermark_text'); $response['WatermarkText'] = preg_replace_callback('/{(.+?)}/', function($matches) use ($replacements) { return $replacements[$matches[1]]; @@ -236,21 +236,21 @@ class WopiController extends Controller { } private function shouldWatermark($isPublic, $userId, $fileId, Wopi $wopi) { - if ($this->config->getAppValue('richdocuments', 'watermark_enabled', 'no') === 'no') { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_enabled', 'no') === 'no') { return false; } if ($isPublic) { - if ($this->config->getAppValue('richdocuments', 'watermark_linkAll', 'no') === 'yes') { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkAll', 'no') === 'yes') { return true; } - if ($this->config->getAppValue('richdocuments', 'watermark_linkRead', 'no') === 'yes' && !$wopi->getCanwrite()) { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkRead', 'no') === 'yes' && !$wopi->getCanwrite()) { return true; } - if ($this->config->getAppValue('richdocuments', 'watermark_linkSecure', 'no') === 'yes' && $wopi->getHideDownload()) { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkSecure', 'no') === 'yes' && $wopi->getHideDownload()) { return true; } - if ($this->config->getAppValue('richdocuments', 'watermark_linkTags', 'no') === 'yes') { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_linkTags', 'no') === 'yes') { $tags = $this->appConfig->getAppValueArray('watermark_linkTagsList'); $fileTags = \OC::$server->getSystemTagObjectMapper()->getTagIdsForObjects([$fileId], 'files')[$fileId]; foreach ($fileTags as $tagId) { @@ -260,14 +260,14 @@ class WopiController extends Controller { } } } else { - if ($this->config->getAppValue('richdocuments', 'watermark_shareAll', 'no') === 'yes') { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_shareAll', 'no') === 'yes') { return true; } - if ($this->config->getAppValue('richdocuments', 'watermark_shareRead', 'no') === 'yes' && !$wopi->getCanwrite()) { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_shareRead', 'no') === 'yes' && !$wopi->getCanwrite()) { return true; } } - if ($this->config->getAppValue('richdocuments', 'watermark_allGroups', 'no') === 'yes') { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_allGroups', 'no') === 'yes') { $groups = $this->appConfig->getAppValueArray('watermark_allGroupsList'); foreach ($groups as $group) { if (\OC::$server->getGroupManager()->isInGroup($userId, $group)) { @@ -275,7 +275,7 @@ class WopiController extends Controller { } } } - if ($this->config->getAppValue('richdocuments', 'watermark_allTags', 'no') === 'yes') { + if ($this->config->getAppValue(AppConfig::WATERMARK_APP_NAMESPACE, 'watermark_allTags', 'no') === 'yes') { $tags = $this->appConfig->getAppValueArray('watermark_allTagsList'); $fileTags = \OC::$server->getSystemTagObjectMapper()->getTagIdsForObjects([$fileId], 'files'); foreach ($fileTags as $tagId) { |