소스 검색

Fix get_config() function #13.

Gilbert Pellegrom 12 년 전
부모
커밋
ac055a715a
3개의 변경된 파일9개의 추가작업 그리고 8개의 파일을 삭제
  1. 2 2
      config.php
  2. 0 1
      index.php
  3. 7 5
      lib/pico.php

+ 2 - 2
config.php

@@ -1,14 +1,14 @@
 <?php 
 
 /*
-Override any of the default settings below:
+// Override any of the default settings below:
 
 $config['site_title'] = 'Pico';			// Site title
 $config['base_url'] = ''; 				// Override base URL (e.g. http://example.com)
 $config['theme'] = 'default'; 			// Set the theme (defaults to "default")
 $config['enable_cache'] = false; 		// Enable caching
 
-To add a custom config setting:
+// To add a custom config setting:
 
 $config['custom_setting'] = 'Hello'; 	// Can be accessed by {{ config.custom_setting }} in a theme
 

+ 0 - 1
index.php

@@ -6,7 +6,6 @@ define('LIB_DIR', ROOT_DIR .'lib/');
 define('THEMES_DIR', ROOT_DIR .'themes/');
 define('CACHE_DIR', LIB_DIR .'cache/');
 
-require('config.php');
 require(ROOT_DIR .'vendor/autoload.php');
 require(LIB_DIR .'markdown.php');
 require(LIB_DIR .'pico.php');

+ 7 - 5
lib/pico.php

@@ -105,11 +105,14 @@ class Pico {
 	/**
 	 * Loads the config
 	 *
-	 * @return array $defaults an array of config values
+	 * @return array $config an array of config values
 	 */
 	function get_config()
 	{
+		if(!file_exists(ROOT_DIR .'config.php')) return array();
+		
 		global $config;
+		require_once(ROOT_DIR .'config.php');
 
 		$defaults = array(
 			'site_title' => 'Pico',
@@ -118,11 +121,10 @@ class Pico {
 			'enable_cache' => false
 		);
 
-		foreach($defaults as $key=>$val){
-			if(isset($config[$key]) && $config[$key]) $defaults[$key] = $config[$key];
-		}
+		if(is_array($config)) $config = array_merge($defaults, $config);
+		else $config = $defaults;
 
-		return $defaults;
+		return $config;
 	}
 
 	/**