This commit is contained in:
flash 2015-04-01 17:06:42 +02:00
parent 0f915e8108
commit bd25993c92
11 changed files with 111 additions and 15 deletions

View file

@ -7,23 +7,26 @@ namespace Sakura;
class Configuration { class Configuration {
// Configuration data
public static $_LCNF; public static $_LCNF;
public static $_DCNF; public static $_DCNF;
// Constructor // Initialise configuration, does not contain database initialisation because explained below
public static function init($local) { public static function init($local) {
// Store $local in $_LCNF // Check if $local is an array and then store it in $_LCNF
if(is_array($local)) if(is_array($local))
self::$_LCNF = $local; self::$_LCNF = $local;
else else // Otherwise trigger an error
die('<h1>Failed to initialise configuration.</h1>'); trigger_error('Failed to load local configuration!', E_USER_ERROR);
} }
// Initialise Database configuration values. /*
// Different from init as that is called before the database connection is initially * Initialise Database configuration values.
// established * Different from init as that is called before the database connection is initially
* established.
*/
public static function initDB() { public static function initDB() {
$_DATA = Database::fetch('config', true); $_DATA = Database::fetch('config', true);
@ -39,12 +42,13 @@ class Configuration {
// Get values from the configuration on the file system // Get values from the configuration on the file system
public static function getLocalConfig($key, $subkey = null) { public static function getLocalConfig($key, $subkey = null) {
if(array_key_exists($key, self::$_LCNF)) { // Check if the key that we're looking for exists
if($subkey) if(array_key_exists($key, self::$_LCNF)) { // If we also have a subkey we check
return self::$_LCNF[$key][$subkey]; if($subkey && array_key_exists($subkey, $key)) // if that exists, else we just return
return self::$_LCNF[$key][$subkey]; // the default value.
else else
return self::$_LCNF[$key]; return self::$_LCNF[$key];
} else } else // If it doesn't exist trigger an error to avoid explosions
trigger_error('Unable to get local configuration value!', E_USER_ERROR); trigger_error('Unable to get local configuration value!', E_USER_ERROR);
} }
@ -52,24 +56,61 @@ class Configuration {
// Dynamically set local configuration values, does not update the configuration file // Dynamically set local configuration values, does not update the configuration file
public static function setLocalConfig($key, $subkey, $value) { public static function setLocalConfig($key, $subkey, $value) {
// Check if we also do a subkey
if($subkey) { if($subkey) {
// If we do we make sure that the parent key is an array
if(!isset(self::$_LCNF[$key])) if(!isset(self::$_LCNF[$key]))
self::$_LCNF[$key] = array(); self::$_LCNF[$key] = array();
// And then assign the value
self::$_LCNF[$key][$subkey] = $value; self::$_LCNF[$key][$subkey] = $value;
} else {
} else // Otherwise we just straight up assign it
self::$_LCNF[$key] = $value; self::$_LCNF[$key] = $value;
}
} }
// Get values from the configuration in the database // Get values from the configuration in the database
public static function getConfig($key) { public static function getConfig($key) {
// Check if the key that we're looking for exists
if(array_key_exists($key, self::$_DCNF)) if(array_key_exists($key, self::$_DCNF))
return self::$_DCNF[$key]; return self::$_DCNF[$key]; // Then return the value
else else // If it doesn't exist trigger an error to avoid explosions
trigger_error('Unable to get configuration value!', E_USER_ERROR); trigger_error('Unable to get configuration value!', E_USER_ERROR);
} }
// Parse .cfg files, mainly/only used for templates
public function parseCfg($data) {
// Create storage variable
$out = array();
// Remove comments and empty lines
$data = preg_replace('/#.*?\r\n/im', null, $data);
$data = preg_replace('/^\r\n/im', null, $data);
// Break line breaks up into array values
$data = explode("\r\n", $data);
foreach($data as $var) {
// Remove whitespace between key, equals sign and value
$var = preg_replace('/[\s+]=[\s+]/i', '=', $var);
// Then break this up
$var = explode('=', $var);
// And assign the value with the key to the output variable
$out[$var[0]] = $var[1];
}
// Return the output variable
return $out;
}
} }

View file

@ -0,0 +1,14 @@
<?php
/*
* Template Engine Wrapper
*/
namespace Sakura;
class Templates {
// Engine container and template options
public static $_ENG;
public static $_CFG;
}

View file

@ -27,6 +27,7 @@ require_once ROOT_DIRECTORY .'_sakura/vendor/autoload.php';
require_once ROOT_DIRECTORY .'_sakura/components/Main.php'; require_once ROOT_DIRECTORY .'_sakura/components/Main.php';
require_once ROOT_DIRECTORY .'_sakura/components/Hashing.php'; require_once ROOT_DIRECTORY .'_sakura/components/Hashing.php';
require_once ROOT_DIRECTORY .'_sakura/components/Configuration.php'; require_once ROOT_DIRECTORY .'_sakura/components/Configuration.php';
require_once ROOT_DIRECTORY .'_sakura/components/Templates.php';
require_once ROOT_DIRECTORY .'_sakura/components/Sessions.php'; require_once ROOT_DIRECTORY .'_sakura/components/Sessions.php';
require_once ROOT_DIRECTORY .'_sakura/components/Users.php'; require_once ROOT_DIRECTORY .'_sakura/components/Users.php';

View file

@ -0,0 +1,9 @@
#
# Sakura Manage Panel
#
# Sets name of this template
NAME = Manage
# Is this style intended for manage?
MANAGE = true

View file

@ -0,0 +1,10 @@
#
# Amu
# Design planned for 2016
#
# Sets name of this template
NAME = Amu
# Is this style intended for manage?
MANAGE = false

View file

@ -0,0 +1,10 @@
#
# Mio
# 2014 Flashii Design
#
# Sets name of this template
NAME = Mio
# Is this style intended for manage?
MANAGE = false

View file

@ -0,0 +1,10 @@
#
# Yuuno
# 2015 Flashii Design
#
# Sets name of this template
NAME = Yuuno
# Is this style intended for manage?
MANAGE = false

1
forum/.htaccess Normal file
View file

@ -0,0 +1 @@
# Empty .htaccess to make git realise this directory exists