From 74712f96fbe5a099eb47ce7b40fe6395f2f991b1 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 19 Oct 2018 23:38:32 +0200 Subject: [PATCH] Templating wrapper updates. --- misuzu.php | 49 +++++++++++++++++++++++-------------------- src/tpl.php | 13 ++++++------ templates/master.twig | 3 ++- utility.php | 5 +++++ 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/misuzu.php b/misuzu.php index d92e3b44..e620c39f 100644 --- a/misuzu.php +++ b/misuzu.php @@ -260,6 +260,9 @@ MIG; 'cache' => MSZ_DEBUG ? false : create_directory(build_path(sys_get_temp_dir(), 'msz-tpl-cache-' . md5(MSZ_ROOT))), ]); + // Remove this when the new style is kinda ready + use_legacy_style(); + tpl_var('globals', [ 'site_name' => config_get_default('Misuzu', 'Site', 'name'), 'site_description' => config_get('Site', 'description'), @@ -267,35 +270,35 @@ MIG; 'site_url' => config_get('Site', 'url'), ]); - tpl_add_function('json_decode', true); - tpl_add_function('byte_symbol', true); - tpl_add_function('html_link', true); - tpl_add_function('html_colour', true); - tpl_add_function('url_construct', true); - tpl_add_function('country_name', true, 'get_country_name'); - tpl_add_function('flip', true, 'array_flip'); - tpl_add_function('first_paragraph', true); - tpl_add_function('colour_get_css', true); - tpl_add_function('colour_get_css_contrast', true); - tpl_add_function('colour_get_inherit', true); - tpl_add_function('colour_get_red', true); - tpl_add_function('colour_get_green', true); - tpl_add_function('colour_get_blue', true); - tpl_add_function('parse_line', true); - tpl_add_function('parse_text', true); - tpl_add_function('asset_url', true); - tpl_add_function('vsprintf', true); - tpl_add_function('perms_check', true); - tpl_add_function('bg_settings', true, 'user_background_settings_strings'); - tpl_add_function('csrf', true, 'csrf_html'); + tpl_add_filter('json_decode'); + tpl_add_filter('byte_symbol'); + tpl_add_filter('html_link'); + tpl_add_filter('html_colour'); + tpl_add_filter('url_construct'); + tpl_add_filter('country_name', 'get_country_name'); + tpl_add_filter('flip', 'array_flip'); + tpl_add_filter('first_paragraph'); + tpl_add_filter('colour_get_css'); + tpl_add_filter('colour_get_css_contrast'); + tpl_add_filter('colour_get_inherit'); + tpl_add_filter('colour_get_red'); + tpl_add_filter('colour_get_green'); + tpl_add_filter('colour_get_blue'); + tpl_add_filter('parse_line'); + tpl_add_filter('parse_text'); + tpl_add_filter('asset_url'); + tpl_add_filter('vsprintf'); + tpl_add_filter('perms_check'); + tpl_add_filter('bg_settings', 'user_background_settings_strings'); + tpl_add_filter('csrf', 'csrf_html'); tpl_add_function('git_commit_hash'); tpl_add_function('git_tag'); tpl_add_function('csrf_token'); - tpl_add_function('startup_time', false, function (float $time = MSZ_STARTUP) { + tpl_add_function('startup_time', function (float $time = MSZ_STARTUP) { return microtime(true) - $time; }); - tpl_add_function('sql_query_count', false, 'db_query_count'); + tpl_add_function('sql_query_count', 'db_query_count'); tpl_add_path(MSZ_ROOT . '/templates'); diff --git a/src/tpl.php b/src/tpl.php index ad10bf0c..e195f29d 100644 --- a/src/tpl.php +++ b/src/tpl.php @@ -45,15 +45,14 @@ function tpl_sanitise_path(string $path): string return str_replace('.', '/', $path) . MSZ_TPL_FILE_EXT; } -function tpl_add_function(string $name, bool $isFilter = false, callable $callable = null): void +function tpl_add_function(string $name, callable $callable = null): void { - $twig = Twig::instance(); + Twig::instance()->addFunction(new Twig_SimpleFunction($name, $callable === null ? $name : $callable)); +} - if ($isFilter) { - $twig->addFilter(new Twig_SimpleFilter($name, $callable === null ? $name : $callable)); - } else { - $twig->addFunction(new Twig_SimpleFunction($name, $callable === null ? $name : $callable)); - } +function tpl_add_filter(string $name, callable $callable = null): void +{ + Twig::instance()->addFilter(new Twig_SimpleFilter($name, $callable === null ? $name : $callable)); } function tpl_exists(string $path): bool diff --git a/templates/master.twig b/templates/master.twig index 91459af7..fd485290 100644 --- a/templates/master.twig +++ b/templates/master.twig @@ -14,7 +14,8 @@ {% endif %} - + + {% include '_layout/header.twig' %}
diff --git a/utility.php b/utility.php index 945d3215..70fea7b6 100644 --- a/utility.php +++ b/utility.php @@ -1,4 +1,9 @@