diff --git a/_sakura/components/Configuration.php b/_sakura/components/Configuration.php index af36e93..8127359 100644 --- a/_sakura/components/Configuration.php +++ b/_sakura/components/Configuration.php @@ -86,35 +86,4 @@ class Configuration { } - // Parse .cfg files, mainly/only used for templates - public static 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; - - } - } diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index cb8af92..e1470db 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -9,6 +9,7 @@ class Main { public static $_TPL; public static $_MD; + public static $_IN_MANAGE = false; // Constructor public static function init($config) { @@ -30,38 +31,13 @@ class Main { Session::init(); // Templating engine - self::initTpl(); + Templates::init(Configuration::getLocalConfig('etc', 'design')); // Markdown Parser self::initMD(); } - // Initialise Twig - private static function initTpl() { - - // Initialise Twig Filesystem Loader - $twigLoader = new \Twig_Loader_Filesystem(Configuration::getLocalConfig('etc', 'templatesPath') .'/'. Configuration::getLocalConfig('etc', 'design')); - - // And now actually initialise the templating engine - self::$_TPL = new \Twig_Environment($twigLoader, array( - - // 'cache' => SATOKO_ROOT_DIRECTORY. self::getConfig('path', 'cache') // Set cache directory - - )); - - // Load String template loader - self::$_TPL->addExtension(new \Twig_Extension_StringLoader()); - - } - - // Render template - public static function tplRender($file, $tags) { - - return self::$_TPL->render($file, $tags); - - } - // Initialise Parsedown private static function initMD() { diff --git a/_sakura/components/Templates.php b/_sakura/components/Templates.php index 7e71daf..f4ee791 100644 --- a/_sakura/components/Templates.php +++ b/_sakura/components/Templates.php @@ -1,14 +1,102 @@ - SATOKO_ROOT_DIRECTORY. self::getConfig('path', 'cache') // Set cache directory + + )); + + // Load String template loader + self::$_ENG->addExtension(new \Twig_Extension_StringLoader()); + + } + + // Parse .cfg files + public static 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 = str_replace("\r\n", "\n", $data); + $data = explode("\n", $data); + + foreach($data as $var) { + + // Make sure no whitespaces escaped the check + if(empty($var)) + continue; + + // 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; + + } + + // Render template + public static function render($file, $tags) { + + return self::$_ENG->render($file, $tags); + + } + +} diff --git a/_sakura/templates/yuuno/template.cfg b/_sakura/templates/yuuno/template.cfg index e722848..a38ba1b 100644 --- a/_sakura/templates/yuuno/template.cfg +++ b/_sakura/templates/yuuno/template.cfg @@ -1,10 +1,10 @@ -# -# Yuuno -# 2015 Flashii Design -# - -# Sets name of this template -NAME = Yuuno - -# Is this style intended for manage? -MANAGE = false +# +# Yuuno +# 2015 Flashii Design +# + +# Sets name of this template +NAME = Yuuno + +# Is this style intended for manage? +MANAGE = false diff --git a/main/authenticate.php b/main/authenticate.php index 7bcfc2a..0a9ebb4 100644 --- a/main/authenticate.php +++ b/main/authenticate.php @@ -30,4 +30,4 @@ $renderData['auth'] = [ ]; // Print page contents -print Main::tplRender('main/authenticate.tpl', $renderData); +print Templates::render('main/authenticate.tpl', $renderData); diff --git a/main/credits.php b/main/credits.php index 7c1661e..7d22416 100644 --- a/main/credits.php +++ b/main/credits.php @@ -26,4 +26,4 @@ $renderData['thirdParty'] = [ ]; // Print page contents -print Main::tplRender('main/credits.tpl', $renderData); +print Templates::render('main/credits.tpl', $renderData); diff --git a/main/index.php b/main/index.php index 44c86ac..985e4e5 100644 --- a/main/index.php +++ b/main/index.php @@ -23,4 +23,4 @@ $renderData['stats'] = [ ]; // Print page contents -print Main::tplRender('main/index.tpl', $renderData); +print Templates::render('main/index.tpl', $renderData); diff --git a/main/infopage.php b/main/infopage.php index e56c472..ac6348b 100644 --- a/main/infopage.php +++ b/main/infopage.php @@ -27,4 +27,4 @@ if($ipData = Main::loadInfoPage(isset($_GET['r']) ? strtolower($_GET['r']) : '') } // Print page contents -print Main::$_TPL->render('main/infopage.tpl', $renderData); +print Templates::render('main/infopage.tpl', $renderData); diff --git a/main/news.php b/main/news.php index 162afa7..778b1fd 100644 --- a/main/news.php +++ b/main/news.php @@ -55,4 +55,4 @@ if(isset($_GET['xml'])) { } // Print page contents -print Main::tplRender('main/news.tpl', $renderData); +print Templates::render('main/news.tpl', $renderData);