2019-10-20 12:09:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Typemill;
|
|
|
|
|
|
|
|
class Settings
|
|
|
|
{
|
|
|
|
public static function loadSettings()
|
|
|
|
{
|
|
|
|
$defaultSettings = self::getDefaultSettings();
|
|
|
|
$userSettings = self::getUserSettings();
|
|
|
|
|
|
|
|
$settings = $defaultSettings;
|
|
|
|
|
|
|
|
if($userSettings)
|
|
|
|
{
|
|
|
|
$settings = array_merge($defaultSettings, $userSettings);
|
|
|
|
}
|
2019-11-24 07:25:04 +01:00
|
|
|
|
|
|
|
# We know the used theme now so create the theme path
|
|
|
|
$settings['themePath'] = $settings['rootPath'] . $settings['themeFolder'] . DIRECTORY_SEPARATOR . $settings['theme'];
|
|
|
|
|
|
|
|
# if there are no theme settings yet (e.g. no setup yet) use default theme settings
|
|
|
|
if(!isset($settings['themes']))
|
|
|
|
{
|
|
|
|
$themeSettings = self::getObjectSettings('themes', $settings['theme']);
|
|
|
|
$settings['themes'][$settings['theme']] = isset($themeSettings['settings']) ? $themeSettings['settings'] : false;
|
|
|
|
}
|
|
|
|
|
2019-10-20 12:09:45 +02:00
|
|
|
return array('settings' => $settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getDefaultSettings()
|
|
|
|
{
|
|
|
|
$rootPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
|
|
|
|
|
|
|
|
return [
|
|
|
|
'determineRouteBeforeAppMiddleware' => true,
|
|
|
|
'displayErrorDetails' => false,
|
|
|
|
'title' => 'TYPEMILL',
|
|
|
|
'author' => 'Unknown',
|
|
|
|
'copyright' => 'Copyright',
|
|
|
|
'language' => 'en',
|
|
|
|
'startpage' => true,
|
|
|
|
'rootPath' => $rootPath,
|
2019-11-24 07:25:04 +01:00
|
|
|
'theme' => 'typemill',
|
|
|
|
'themeFolder' => 'themes',
|
2019-10-20 12:09:45 +02:00
|
|
|
'themeBasePath' => $rootPath,
|
2019-11-24 07:25:04 +01:00
|
|
|
'themePath' => '',
|
2019-10-20 12:09:45 +02:00
|
|
|
'settingsPath' => $rootPath . 'settings',
|
|
|
|
'userPath' => $rootPath . 'settings' . DIRECTORY_SEPARATOR . 'users',
|
|
|
|
'authorPath' => __DIR__ . DIRECTORY_SEPARATOR . 'author' . DIRECTORY_SEPARATOR,
|
2019-11-24 07:25:04 +01:00
|
|
|
'editor' => 'visual',
|
|
|
|
'formats' => ['markdown', 'headline', 'ulist', 'olist', 'table', 'quote', 'image', 'video', 'toc', 'hr', 'definition', 'code'],
|
2019-10-20 12:09:45 +02:00
|
|
|
'contentFolder' => 'content',
|
|
|
|
'cache' => true,
|
|
|
|
'cachePath' => $rootPath . 'cache',
|
2020-01-09 09:42:48 +01:00
|
|
|
'version' => '1.3.1',
|
2019-10-20 12:09:45 +02:00
|
|
|
'setup' => true,
|
|
|
|
'welcome' => true,
|
|
|
|
'images' => ['live' => ['width' => 820], 'mlibrary' => ['width' => 50, 'height' => 50]],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getUserSettings()
|
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
|
|
|
$userSettings = $yaml->getYaml('settings', 'settings.yaml');
|
|
|
|
|
|
|
|
return $userSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getObjectSettings($objectType, $objectName)
|
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
|
|
|
$objectFolder = $objectType . DIRECTORY_SEPARATOR . $objectName;
|
|
|
|
$objectFile = $objectName . '.yaml';
|
|
|
|
$objectSettings = $yaml->getYaml($objectFolder, $objectFile);
|
|
|
|
|
|
|
|
return $objectSettings;
|
|
|
|
}
|
2019-12-31 15:57:45 +01:00
|
|
|
|
2019-10-20 12:09:45 +02:00
|
|
|
public static function createSettings()
|
|
|
|
{
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
|
|
|
|
# create initial settings file with only setup false
|
|
|
|
if($yaml->updateYaml('settings', 'settings.yaml', array('setup' => false)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function updateSettings($settings)
|
|
|
|
{
|
|
|
|
# only allow if usersettings already exists (setup has been done)
|
|
|
|
$userSettings = self::getUserSettings();
|
|
|
|
|
|
|
|
if($userSettings)
|
|
|
|
{
|
|
|
|
# whitelist settings that can be stored in usersettings (values are not relevant here, only keys)
|
|
|
|
$allowedUserSettings = ['displayErrorDetails' => false,
|
|
|
|
'title' => false,
|
|
|
|
'copyright' => false,
|
|
|
|
'language' => false,
|
|
|
|
'startpage' => false,
|
|
|
|
'author' => false,
|
|
|
|
'year' => false,
|
|
|
|
'theme' => false,
|
|
|
|
'editor' => false,
|
2019-11-24 07:25:04 +01:00
|
|
|
'formats' => false,
|
2019-10-20 12:09:45 +02:00
|
|
|
'setup' => false,
|
|
|
|
'welcome' => false,
|
|
|
|
'images' => false,
|
|
|
|
'plugins' => false,
|
|
|
|
'themes' => false,
|
|
|
|
'latestVersion' => false
|
|
|
|
];
|
|
|
|
|
|
|
|
# cleanup the existing usersettings
|
|
|
|
$userSettings = array_intersect_key($userSettings, $allowedUserSettings);
|
|
|
|
|
|
|
|
# cleanup the new settings passed as an argument
|
|
|
|
$settings = array_intersect_key($settings, $allowedUserSettings);
|
|
|
|
|
|
|
|
# merge usersettings with new settings
|
|
|
|
$settings = array_merge($userSettings, $settings);
|
|
|
|
|
|
|
|
/* write settings to yaml */
|
|
|
|
$yaml = new Models\WriteYaml();
|
|
|
|
$yaml->updateYaml('settings', 'settings.yaml', $settings);
|
|
|
|
}
|
|
|
|
}
|
2017-11-19 17:44:42 +01:00
|
|
|
}
|