From 1116c8ecd098b6400b267899c799984c30bbe175 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Mon, 31 Jul 2023 17:03:24 -0400 Subject: [PATCH] autoformat template.php --- inc/template.php | 122 +++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/inc/template.php b/inc/template.php index 4d613645..15a28b0e 100644 --- a/inc/template.php +++ b/inc/template.php @@ -9,70 +9,70 @@ defined('TINYBOARD') or exit; $twig = false; function load_twig() { - global $twig, $config; - - require_once 'vendor/autoload.php'; - Twig_Autoloader::register(); + global $twig, $config; - Twig_Autoloader::autoload('Twig_Extensions_Node_Trans'); - Twig_Autoloader::autoload('Twig_Extensions_TokenParser_Trans'); - Twig_Autoloader::autoload('Twig_Extensions_Extension_I18n'); - Twig_Autoloader::autoload('Twig_Extensions_Extension_Tinyboard'); - - $loader = new Twig_Loader_Filesystem($config['dir']['template']); - $loader->setPaths($config['dir']['template']); - $twig = new Twig_Environment($loader, array( - 'autoescape' => false, - 'cache' => is_writable('templates') || (is_dir('templates/cache') && is_writable('templates/cache')) ? - "{$config['dir']['template']}/cache" : false, - 'debug' => $config['debug'] - )); - $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); - $twig->addExtension(new Twig_Extensions_Extension_I18n()); + require_once 'vendor/autoload.php'; + Twig_Autoloader::register(); + + Twig_Autoloader::autoload('Twig_Extensions_Node_Trans'); + Twig_Autoloader::autoload('Twig_Extensions_TokenParser_Trans'); + Twig_Autoloader::autoload('Twig_Extensions_Extension_I18n'); + Twig_Autoloader::autoload('Twig_Extensions_Extension_Tinyboard'); + + $loader = new Twig_Loader_Filesystem($config['dir']['template']); + $loader->setPaths($config['dir']['template']); + $twig = new Twig_Environment($loader, array( + 'autoescape' => false, + 'cache' => is_writable('templates') || (is_dir('templates/cache') && is_writable('templates/cache')) ? + "{$config['dir']['template']}/cache" : false, + 'debug' => $config['debug'] + )); + $twig->addExtension(new Twig_Extensions_Extension_Tinyboard()); + $twig->addExtension(new Twig_Extensions_Extension_I18n()); } function Element($templateFile, array $options) { - global $config, $debug, $twig, $build_pages; - - if (!$twig) - load_twig(); - - if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) { - $options['pm'] = create_pm_header(); - } - - if (isset($options['body']) && $config['debug']) { - $_debug = $debug; - - if (isset($debug['start'])) { - $_debug['time']['total'] = '~' . round((microtime(true) - $_debug['start']) * 1000, 2) . 'ms'; - $_debug['time']['init'] = '~' . round(($_debug['start_debug'] - $_debug['start']) * 1000, 2) . 'ms'; - unset($_debug['start']); - unset($_debug['start_debug']); - } - if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages)) - $_debug['build_pages'] = $build_pages; - $_debug['included'] = get_included_files(); - $_debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB'; - $_debug['time']['db_queries'] = '~' . round($_debug['time']['db_queries'] * 1000, 2) . 'ms'; - $_debug['time']['exec'] = '~' . round($_debug['time']['exec'] * 1000, 2) . 'ms'; - $options['body'] .= - '

Debug

' .
-				str_replace("\n", '
', utf8tohtml(print_r($_debug, true))) . - '
'; - } - - // Read the template file - if (@file_get_contents("{$config['dir']['template']}/${templateFile}")) { - $body = $twig->render($templateFile, $options); - - if ($config['minify_html'] && preg_match('/\.html$/', $templateFile)) { - $body = trim(preg_replace("/[\t\r\n]/", '', $body)); - } - - return $body; - } else { - throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!"); - } + global $config, $debug, $twig, $build_pages; + + if (!$twig) + load_twig(); + + if (function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod'])) && !preg_match('!^mod/!', $templateFile)) { + $options['pm'] = create_pm_header(); + } + + if (isset($options['body']) && $config['debug']) { + $_debug = $debug; + + if (isset($debug['start'])) { + $_debug['time']['total'] = '~' . round((microtime(true) - $_debug['start']) * 1000, 2) . 'ms'; + $_debug['time']['init'] = '~' . round(($_debug['start_debug'] - $_debug['start']) * 1000, 2) . 'ms'; + unset($_debug['start']); + unset($_debug['start_debug']); + } + if ($config['try_smarter'] && isset($build_pages) && !empty($build_pages)) + $_debug['build_pages'] = $build_pages; + $_debug['included'] = get_included_files(); + $_debug['memory'] = round(memory_get_usage(true) / (1024 * 1024), 2) . ' MiB'; + $_debug['time']['db_queries'] = '~' . round($_debug['time']['db_queries'] * 1000, 2) . 'ms'; + $_debug['time']['exec'] = '~' . round($_debug['time']['exec'] * 1000, 2) . 'ms'; + $options['body'] .= + '

Debug

' .
+            str_replace("\n", '
', utf8tohtml(print_r($_debug, true))) . + '
'; + } + + // Read the template file + if (@file_get_contents("{$config['dir']['template']}/${templateFile}")) { + $body = $twig->render($templateFile, $options); + + if ($config['minify_html'] && preg_match('/\.html$/', $templateFile)) { + $body = trim(preg_replace("/[\t\r\n]/", '', $body)); + } + + return $body; + } else { + throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!"); + } }