summaryrefslogtreecommitdiffstats
path: root/utility
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-09-02 02:43:25 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-09-02 02:43:32 +0200
commit38297af11f458b30af3cbdc42cf3407d6aff44ab (patch)
tree6c61f09234182c78fe291bcd439284c8e77e7ffe /utility
parent1b144268cbb49854aaba1c04c773dcf2f9cf0b7a (diff)
move configuration values into a config file, fix #167
Diffstat (limited to 'utility')
-rw-r--r--utility/config.php147
1 files changed, 147 insertions, 0 deletions
diff --git a/utility/config.php b/utility/config.php
new file mode 100644
index 000000000..e00ad940f
--- /dev/null
+++ b/utility/config.php
@@ -0,0 +1,147 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Utility;
+
+use \OCA\AppFramework\Core\API;
+
+
+class Config {
+
+ private $fileSystem;
+ private $autoPurgeMinimumInterval; // seconds, used to define how
+ // long deleted folders and feeds
+ // should still be kept for an
+ // undo actions
+ private $autoPurgeCount; // number of allowed unread articles per feed
+ private $simplePieCacheDuration; // seconds
+ private $feedFetcherTimeout; // seconds
+ private $useCronUpdates; // turn off updates run by owncloud cronjob
+ private $api;
+
+
+ public function __construct($fileSystem, API $api) {
+ $this->fileSystem = $fileSystem;
+ $this->autoPurgeMinimumInterval = 60;
+ $this->autoPurgeCount = 200;
+ $this->simplePieCacheDuration = 30*60;
+ $this->feedFetcherTimeout = 60;
+ $this->useCronUpdates = true;
+ $this->api = $api;
+ }
+
+
+ public function getAutoPurgeMinimumInterval() {
+ return $this->autoPurgeMinimumInterval;
+ }
+
+
+ public function getAutoPurgeCount() {
+ return $this->autoPurgeCount;
+ }
+
+
+ public function getSimplePieCacheDuration() {
+ return $this->simplePieCacheDuration;
+ }
+
+
+ public function getFeedFetcherTimeout() {
+ return $this->feedFetcherTimeout;
+ }
+
+
+ public function getUseCronUpdates() {
+ return $this->useCronUpdates;
+ }
+
+
+ public function setAutoPurgeMinimumInterval($value) {
+ $this->autoPurgeMinimumInterval = $value;
+ }
+
+
+ public function setAutoPurgeCount($value) {
+ $this->autoPurgeCount = $value;
+ }
+
+
+ public function setSimplePieCacheDuration($value) {
+ $this->simplePieCacheDuration = $value;
+ }
+
+
+ public function setFeedFetcherTimeout($value) {
+ $this->feedFetcherTimeout = $value;
+ }
+
+
+ public function setUseCronUpdates($value) {
+ $this->useCronUpdates = $value;
+ }
+
+
+ public function read($configPath, $createIfNotExists=false) {
+ if($createIfNotExists && !$this->fileSystem->file_exists($configPath)) {
+
+ $this->write($configPath);
+
+ } else {
+
+ $content = $this->fileSystem->file_get_contents($configPath);
+ $configValues = json_decode($content, true);
+
+ if($configValues === null) {
+ $this->api->log('Configuration contains invalid JSON' , 'warn');
+ } else {
+
+ foreach($configValues as $key => $value) {
+ if(property_exists($this, $key)) {
+ $this->$key = $value;
+ } else {
+ $this->api->log('Configuration value "' . $key .
+ '" does not exist. Ignored value.' , 'warn');
+ }
+ }
+
+ }
+ }
+ }
+
+
+ public function write($configPath) {
+ $json = json_encode(array(
+ "autoPurgeMinimumInterval" => $this->autoPurgeMinimumInterval,
+ "autoPurgeCount" => $this->autoPurgeCount,
+ "simplePieCacheDuration" => $this->simplePieCacheDuration,
+ "feedFetcherTimeout" => $this->feedFetcherTimeout,
+ "useCronUpdates" => $this->useCronUpdates,
+ ), JSON_PRETTY_PRINT);
+
+ $this->fileSystem->file_put_contents($configPath, $json);
+ }
+
+
+} \ No newline at end of file