Fix get_config() function #13.

This commit is contained in:
Gilbert Pellegrom 2013-04-27 17:17:08 +01:00
parent c88f8e7967
commit ac055a715a
3 changed files with 9 additions and 8 deletions

View file

@ -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

View file

@ -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');

View file

@ -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;
}
/**