summaryrefslogtreecommitdiffstats
path: root/app/classes/PlanetConfig.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/classes/PlanetConfig.php')
-rw-r--r--app/classes/PlanetConfig.php66
1 files changed, 66 insertions, 0 deletions
diff --git a/app/classes/PlanetConfig.php b/app/classes/PlanetConfig.php
index 257d1b9..179e25b 100644
--- a/app/classes/PlanetConfig.php
+++ b/app/classes/PlanetConfig.php
@@ -8,6 +8,9 @@ class PlanetConfig
protected $conf = [];
+ private ?string $opmlFile = null;
+ private ?string $cacheDir = null;
+
public static $defaultConfig = [
'url' => 'http://www.example.com/',
'name' => '',
@@ -36,6 +39,43 @@ class PlanetConfig
}
/**
+ * @return static
+ */
+ public static function load(string $dir)
+ {
+ $config = new PlanetConfig;
+ $configFile = realpath($dir . '/../custom/config.yml');
+
+ if (self::isInstalled()) {
+ $conf = Spyc::YAMLLoad($configFile);
+
+ // this is a check to upgrade older config file without l10n
+ if (!isset($conf['locale'])) {
+ $resetPlanetConfig = new PlanetConfig($conf);
+ file_put_contents($configFile, $resetPlanetConfig->toYaml());
+ $conf = Spyc::YAMLLoad($configFile);
+
+ return $resetPlanetConfig;
+ }
+
+ $config = new PlanetConfig($conf);
+ }
+
+ return $config;
+ }
+
+ /**
+ * Is moonmoon installed?
+ *
+ * @return bool
+ */
+ public static function isInstalled() : bool
+ {
+ return file_exists(custom_path('config.yml')) &&
+ file_exists(custom_path('people.opml'));
+ }
+
+ /**
* Merge the configuration of the user in the default one.
*
* @param array $default
@@ -67,6 +107,22 @@ class PlanetConfig
return $this->conf['refresh'];
}
+ public function getCacheDir()
+ {
+ if (is_null($this->cacheDir)) {
+ $this->cacheDir = realpath(__DIR__ . '/../../'.$this->conf['cachedir']);
+ }
+ return $this->cacheDir;
+ }
+
+ public function getOpmlFile()
+ {
+ if (is_null($this->opmlFile)) {
+ $this->opmlFile = realpath(__DIR__ . '/../../custom/people.opml');
+ }
+ return $this->opmlFile;
+ }
+
public function getOutputTimeout()
{
return $this->conf['cache'];
@@ -127,6 +183,16 @@ class PlanetConfig
return $this->conf['debug'];
}
+ public function checkCertificates()
+ {
+ return $this->conf['checkcerts'];
+ }
+
+ public function getLocale()
+ {
+ return $this->conf['locale'];
+ }
+
/**
* @return array
*/