소스 검색

version 1.0.4 changed settings and fixed bug

Sebastian 7 년 전
부모
커밋
e0f4c884ea
6개의 변경된 파일88개의 추가작업 그리고 46개의 파일을 삭제
  1. 5 0
      content/4_info/01-release-notes.md
  2. 27 10
      system/Controllers/PageController.php
  3. 54 18
      system/settings.php
  4. 1 17
      system/system.php
  5. 1 1
      system/vendor/erusev/parsedown
  6. BIN
      zips/typemill-1.0.4.zip

+ 5 - 0
content/4_info/01-release-notes.md

@@ -2,6 +2,11 @@
 
 
 This is the version history with some release notes.
 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)
 ## Version 1.0.3 (14.11.2017)
 
 
 - Bugfix: Deleted a config-file in the download-version, that broke the setup url.
 - Bugfix: Deleted a config-file in the download-version, that broke the setup url.

+ 27 - 10
system/Controllers/PageController.php

@@ -49,16 +49,9 @@ class PageController extends Controller
 					/* update sitemap */
 					/* update sitemap */
 					$sitemap = new WriteSitemap();
 					$sitemap = new WriteSitemap();
 					$sitemap->updateSitemap('cache', 'sitemap.xml', 'lastSitemap.txt', $structure, $uri->getBaseUrl());
 					$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;
 		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);									
+				}
+			}
+		}	
+	}	
 }
 }

+ 54 - 18
system/settings.php

@@ -1,22 +1,58 @@
 <?php 
 <?php 
 
 
-DEFINE('DS', DIRECTORY_SEPARATOR);
+namespace Typemill;
 
 
-return [
-	'title'					=> '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();
 
 
-?>
+			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;
+	}
+}

+ 1 - 17
system/system.php

@@ -10,23 +10,7 @@ session_start();
 * LOAD SETTINGS			*
 * 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 		*
 * INITIATE SLIM 		*

+ 1 - 1
system/vendor/erusev/parsedown

@@ -1 +1 @@
-Subproject commit 728952b90a333b5c6f77f06ea9422b94b585878d
+Subproject commit fbe3fe878f4fe69048bb8a52783a09802004f548

BIN
zips/typemill-1.0.4.zip