2017-04-14 21:45:15 +02:00
|
|
|
<?php
|
|
|
|
|
2017-11-19 17:44:42 +01:00
|
|
|
namespace Typemill;
|
2017-04-14 21:45:15 +02:00
|
|
|
|
2017-11-19 17:44:42 +01:00
|
|
|
class Settings
|
|
|
|
{
|
|
|
|
public static function loadSettings()
|
|
|
|
{
|
|
|
|
$settings = self::getDefaultSettings();
|
2018-02-06 19:19:02 +01:00
|
|
|
$userSettings = self::getUserSettings();
|
2017-11-19 17:44:42 +01:00
|
|
|
|
|
|
|
if($userSettings)
|
|
|
|
{
|
|
|
|
$settings = array_merge($settings, $userSettings);
|
2018-02-06 19:19:02 +01:00
|
|
|
$settings['setup'] = false;
|
2017-11-19 17:44:42 +01:00
|
|
|
}
|
2018-02-06 19:19:02 +01:00
|
|
|
|
2017-11-19 17:44:42 +01:00
|
|
|
$settings['themePath'] = $settings['rootPath'] . $settings['themeFolder'] . DIRECTORY_SEPARATOR . $settings['theme'];
|
2018-02-06 19:19:02 +01:00
|
|
|
|
2017-11-19 17:44:42 +01:00
|
|
|
return array('settings' => $settings);
|
|
|
|
}
|
|
|
|
|
2018-02-25 17:29:38 +01:00
|
|
|
private static function getDefaultSettings()
|
2017-11-19 17:44:42 +01:00
|
|
|
{
|
|
|
|
$rootPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
|
|
|
|
|
|
|
|
return [
|
|
|
|
'determineRouteBeforeAppMiddleware' => true,
|
2018-06-04 23:09:26 +02:00
|
|
|
'displayErrorDetails' => false,
|
2017-11-19 17:44:42 +01:00
|
|
|
'title' => 'TYPEMILL',
|
|
|
|
'author' => 'Unknown',
|
|
|
|
'copyright' => 'Copyright',
|
2018-03-14 21:17:17 +01:00
|
|
|
'language' => 'en',
|
2017-11-19 17:44:42 +01:00
|
|
|
'startpage' => true,
|
|
|
|
'rootPath' => $rootPath,
|
|
|
|
'theme' => ($theme = 'typemill'),
|
|
|
|
'themeFolder' => ($themeFolder = 'themes'),
|
|
|
|
'themeBasePath' => $rootPath,
|
|
|
|
'themePath' => $rootPath . $themeFolder . DIRECTORY_SEPARATOR . $theme,
|
|
|
|
'settingsPath' => $rootPath . 'settings',
|
2018-04-18 19:49:12 +02:00
|
|
|
'userPath' => $rootPath . 'settings' . DIRECTORY_SEPARATOR . 'users',
|
2017-11-19 17:44:42 +01:00
|
|
|
'authorPath' => __DIR__ . DIRECTORY_SEPARATOR . 'author' . DIRECTORY_SEPARATOR,
|
|
|
|
'contentFolder' => 'content',
|
2018-05-22 23:03:27 +02:00
|
|
|
'cache' => true,
|
|
|
|
'cachePath' => $rootPath . 'cache',
|
2018-09-22 07:08:19 +02:00
|
|
|
'version' => '1.2.4',
|
2018-04-30 16:05:04 +02:00
|
|
|
'setup' => true,
|
|
|
|
'welcome' => true
|
2017-11-19 17:44:42 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-04-18 19:49:12 +02:00
|
|
|
public static function getUserSettings()
|
2017-11-19 17:44:42 +01:00
|
|
|
{
|
2018-02-06 19:19:02 +01:00
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
|
|
|
$userSettings = $yaml->getYaml('settings', 'settings.yaml');
|
|
|
|
|
|
|
|
return $userSettings;
|
|
|
|
}
|
2018-04-30 16:05:04 +02:00
|
|
|
|
|
|
|
public static function getObjectSettings($objectType, $objectName)
|
2018-02-06 19:19:02 +01:00
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
2018-04-30 16:05:04 +02:00
|
|
|
$objectFolder = $objectType . DIRECTORY_SEPARATOR . $objectName;
|
|
|
|
$objectFile = $objectName . '.yaml';
|
|
|
|
$objectSettings = $yaml->getYaml($objectFolder, $objectFile);
|
2018-02-06 19:19:02 +01:00
|
|
|
|
2018-04-30 16:05:04 +02:00
|
|
|
return $objectSettings;
|
2018-02-06 19:19:02 +01:00
|
|
|
}
|
2018-04-30 16:05:04 +02:00
|
|
|
|
|
|
|
public static function createSettings($settings)
|
2018-02-06 19:19:02 +01:00
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
2018-04-30 16:05:04 +02:00
|
|
|
/* write settings to yaml */
|
|
|
|
$yaml->updateYaml('settings', 'settings.yaml', $settings);
|
2018-02-06 19:19:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function updateSettings($settings)
|
|
|
|
{
|
2018-04-30 16:05:04 +02:00
|
|
|
$userSettings = self::getUserSettings();
|
2018-02-06 19:19:02 +01:00
|
|
|
|
2018-04-30 16:05:04 +02:00
|
|
|
if($userSettings)
|
|
|
|
{
|
|
|
|
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
$settings = array_merge($userSettings, $settings);
|
|
|
|
|
|
|
|
/* write settings to yaml */
|
|
|
|
$yaml->updateYaml('settings', 'settings.yaml', $settings);
|
|
|
|
}
|
2018-02-06 19:19:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function removePluginSettings($pluginName)
|
|
|
|
{
|
|
|
|
$userSettings = self::getUserSettings();
|
|
|
|
|
|
|
|
if($userSettings && isset($userSettings['plugins'][$pluginName]))
|
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
|
|
|
/* delete the plugin from settings */
|
|
|
|
unset($userSettings['plugins'][$pluginName]);
|
|
|
|
|
|
|
|
/* write settings to yaml */
|
|
|
|
$yaml->updateYaml('settings', 'settings.yaml', $userSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $userSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function addPluginSettings($pluginName)
|
|
|
|
{
|
|
|
|
$userSettings = self::getUserSettings();
|
|
|
|
|
|
|
|
if($userSettings)
|
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
2018-04-30 16:05:04 +02:00
|
|
|
$pluginSettings = self::getObjectSettings('plugins', $pluginName);
|
2018-02-25 17:29:38 +01:00
|
|
|
if(isset($pluginSettings['settings']))
|
2018-02-06 19:19:02 +01:00
|
|
|
{
|
|
|
|
$userSettings['plugins'][$pluginName] = $pluginSettings['settings'];
|
2017-11-19 17:44:42 +01:00
|
|
|
}
|
2018-02-06 19:19:02 +01:00
|
|
|
|
2018-02-25 17:29:38 +01:00
|
|
|
$userSettings['plugins'][$pluginName]['active'] = false;
|
2018-02-06 19:19:02 +01:00
|
|
|
|
|
|
|
/* write settings to yaml */
|
|
|
|
$yaml->updateYaml('settings', 'settings.yaml', $userSettings);
|
|
|
|
|
2017-11-19 17:44:42 +01:00
|
|
|
return $userSettings;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|