diff --git a/content/4_info/01-release-notes.md b/content/4_info/01-release-notes.md index 548be03..15b3992 100644 --- a/content/4_info/01-release-notes.md +++ b/content/4_info/01-release-notes.md @@ -2,6 +2,11 @@ This is the version history with some release notes. +## Version 1.0.4 (17.11.2017) + +- Bugfix: Settings file was generated after a page refresh, this is fixed now. +- Improvement: Cleaned up the load and merge process for settings, managed in a new static class now. + ## Version 1.0.3 (14.11.2017) - Bugfix: Deleted a config-file in the download-version, that broke the setup url. diff --git a/system/Controllers/PageController.php b/system/Controllers/PageController.php index bdbfdcf..a1788bb 100644 --- a/system/Controllers/PageController.php +++ b/system/Controllers/PageController.php @@ -49,16 +49,9 @@ class PageController extends Controller /* update sitemap */ $sitemap = new WriteSitemap(); $sitemap->updateSitemap('cache', 'sitemap.xml', 'lastSitemap.txt', $structure, $uri->getBaseUrl()); - - $version = new VersionCheck(); - $latestVersion = $version->checkVersion($uri->getBaseUrl()); - if($latestVersion) - { - $yaml = new WriteYaml(); - $yamlContent = $yaml->getYaml('settings', 'settings.yaml'); - $yamlContent['latestVersion'] = $latestVersion; - $yaml->updateYaml('settings', 'settings.yaml', $yamlContent); - } + + /* check and update the typemill-version in the user settings */ + $this->updateVersion($uri->getBaseUrl()); } } } @@ -155,4 +148,28 @@ class PageController extends Controller return $structure; } + + protected function updateVersion($baseUrl) + { + /* check the latest public typemill version */ + $version = new VersionCheck(); + $latestVersion = $version->checkVersion($baseUrl); + + if($latestVersion) + { + /* check, if user-settings exist */ + $yaml = new WriteYaml(); + $userSettings = $yaml->getYaml('settings', 'settings.yaml'); + if($userSettings) + { + /* if there is no version info in the settings or if the version info is outdated */ + if(!isset($userSettings['latestVersion']) || $userSettings['latestVersion'] != $latestVersion) + { + /* write the latest version into the user-settings */ + $userSettings['latestVersion'] = $latestVersion; + $yaml->updateYaml('settings', 'settings.yaml', $userSettings); + } + } + } + } } \ No newline at end of file diff --git a/system/settings.php b/system/settings.php index 16bc118..8ac3eae 100644 --- a/system/settings.php +++ b/system/settings.php @@ -1,22 +1,58 @@ 'TYPEMILL', - 'author' => 'Unknown', - 'copyright' => 'Copyright', - 'startpage' => true, - 'rootPath' => __DIR__ . DS . '..' . DS, - 'theme' => ($theme = 'typemill'), - 'themeFolder' => ($themeFolder = 'themes'), - 'themeBasePath' => __DIR__ . DS . '..' . DS, - 'themePath' => __DIR__ . DS . '..' . DS . $themeFolder . DS . $theme, - 'settingsPath' => __DIR__ . DS . '..' . DS . 'settings', - 'authorPath' => __DIR__ . DS . 'author' . DS, - 'contentFolder' => 'content', - 'displayErrorDetails' => false, - 'version' => '1.0.3' -]; +class Settings +{ + public static function loadSettings() + { + $settings = self::getDefaultSettings(); + $userSettings = self::getUserSettings($settings['settingsPath']); + + if($userSettings) + { + $settings = array_merge($settings, $userSettings); + } + $settings['themePath'] = $settings['rootPath'] . $settings['themeFolder'] . DIRECTORY_SEPARATOR . $settings['theme']; + return array('settings' => $settings); + } + + private function getDefaultSettings() + { + $rootPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR; + + return [ + 'determineRouteBeforeAppMiddleware' => true, + 'displayErrorDetails' => true, + 'title' => 'TYPEMILL', + 'author' => 'Unknown', + 'copyright' => 'Copyright', + 'startpage' => true, + 'rootPath' => $rootPath, + 'theme' => ($theme = 'typemill'), + 'themeFolder' => ($themeFolder = 'themes'), + 'themeBasePath' => $rootPath, + 'themePath' => $rootPath . $themeFolder . DIRECTORY_SEPARATOR . $theme, + 'settingsPath' => $rootPath . 'settings', + 'authorPath' => __DIR__ . DIRECTORY_SEPARATOR . 'author' . DIRECTORY_SEPARATOR, + 'contentFolder' => 'content', + 'version' => '1.0.4' + ]; + } + + private function getUserSettings($settingsPath) + { + if(file_exists($settingsPath . DIRECTORY_SEPARATOR . 'settings.yaml')) + { + $yaml = new \Symfony\Component\Yaml\Parser(); -?> \ No newline at end of file + try { + $userSettings = $yaml->parse( file_get_contents($settingsPath . DIRECTORY_SEPARATOR . 'settings.yaml' ) ); + } catch (ParseException $e) { + printf("Unable to parse the YAML string: %s", $e->getMessage()); + } + return $userSettings; + } + return false; + } +} \ No newline at end of file diff --git a/system/system.php b/system/system.php index ed590d4..e4b59be 100644 --- a/system/system.php +++ b/system/system.php @@ -10,23 +10,7 @@ session_start(); * LOAD SETTINGS * ************************/ -$settings = require_once( __DIR__ . '/settings.php'); - -if(file_exists($settings['settingsPath'] . DIRECTORY_SEPARATOR . 'settings.yaml')) -{ - $yaml = new \Symfony\Component\Yaml\Parser(); - - try { - $userSettings = $yaml->parse( file_get_contents($settings['settingsPath'] . DIRECTORY_SEPARATOR . 'settings.yaml' ) ); - } catch (ParseException $e) { - printf("Unable to parse the YAML string: %s", $e->getMessage()); - } - - $settings = array_merge($settings, $userSettings); - $settings['themePath'] = $settings['themeBasePath'] . $settings['themeFolder'] . DIRECTORY_SEPARATOR . $settings['theme']; -} - -$settings['settings'] = $settings; +$settings = Typemill\Settings::loadSettings(); /************************ * INITIATE SLIM * diff --git a/system/vendor/erusev/parsedown b/system/vendor/erusev/parsedown index 728952b..fbe3fe8 160000 --- a/system/vendor/erusev/parsedown +++ b/system/vendor/erusev/parsedown @@ -1 +1 @@ -Subproject commit 728952b90a333b5c6f77f06ea9422b94b585878d +Subproject commit fbe3fe878f4fe69048bb8a52783a09802004f548 diff --git a/zips/typemill-1.0.4.zip b/zips/typemill-1.0.4.zip new file mode 100644 index 0000000..d9c871a Binary files /dev/null and b/zips/typemill-1.0.4.zip differ