2010-11-02 06:57:33 -04:00
|
|
|
<?php
|
2011-04-13 08:21:07 -04:00
|
|
|
if($_SERVER['SCRIPT_FILENAME'] == str_replace('\\', '/', __FILE__)) {
|
|
|
|
// You cannot request this file directly.
|
|
|
|
header('Location: ../', true, 302);
|
|
|
|
exit;
|
|
|
|
}
|
2010-11-02 06:57:33 -04:00
|
|
|
|
2011-10-05 00:22:53 -04:00
|
|
|
require 'contrib/Twig/Autoloader.php';
|
|
|
|
Twig_Autoloader::register();
|
2010-11-02 06:57:33 -04:00
|
|
|
|
2011-10-11 06:49:14 -04:00
|
|
|
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');
|
2011-10-05 08:53:43 -04:00
|
|
|
|
2011-10-05 00:22:53 -04:00
|
|
|
$loader = new Twig_Loader_Filesystem($config['dir']['template']);
|
2010-11-02 06:57:33 -04:00
|
|
|
|
|
|
|
function Element($templateFile, array $options) {
|
2011-10-05 00:22:53 -04:00
|
|
|
global $config, $debug, $loader;
|
2011-03-17 01:52:43 -04:00
|
|
|
|
2011-06-25 02:03:57 -04:00
|
|
|
if(function_exists('create_pm_header') && ((isset($options['mod']) && $options['mod']) || isset($options['__mod']))) {
|
2011-03-17 01:52:43 -04:00
|
|
|
$options['pm'] = create_pm_header();
|
|
|
|
}
|
|
|
|
|
2011-05-21 01:22:10 -04:00
|
|
|
if(isset($options['body']) && $config['debug']) {
|
2011-05-25 01:22:29 -04:00
|
|
|
if(isset($debug['start'])) {
|
|
|
|
$debug['time'] = '~' . round((microtime(true) - $debug['start']) * 1000, 2) . 'ms';
|
|
|
|
unset($debug['start']);
|
|
|
|
|
|
|
|
}
|
2011-05-21 01:22:10 -04:00
|
|
|
$options['body'] .= '<h3>Debug</h3><pre style="white-space: pre-wrap;font-size: 10px;">' . print_r($debug, true) . '</pre><hr/>';
|
|
|
|
}
|
|
|
|
|
2011-10-15 02:06:22 -04:00
|
|
|
$loader->setPaths($config['dir']['template']);
|
|
|
|
|
2011-10-05 00:22:53 -04:00
|
|
|
$twig = new Twig_Environment($loader, Array(
|
|
|
|
'autoescape' => false,
|
2011-10-05 23:28:56 -04:00
|
|
|
'cache' => "{$config['dir']['template']}/cache",
|
2011-10-05 00:22:53 -04:00
|
|
|
'debug' => ($config['debug'] ? true : false),
|
|
|
|
));
|
2011-10-11 06:49:14 -04:00
|
|
|
$twig->addExtension(new Twig_Extensions_Extension_Tinyboard());
|
|
|
|
$twig->addExtension(new Twig_Extensions_Extension_I18n());
|
2011-10-05 00:22:53 -04:00
|
|
|
|
2010-11-02 06:57:33 -04:00
|
|
|
// Read the template file
|
2011-10-05 00:22:53 -04:00
|
|
|
if(@file_get_contents("{$config['dir']['template']}/${templateFile}")) {
|
|
|
|
return $twig->render($templateFile, $options);
|
2010-11-02 06:57:33 -04:00
|
|
|
} else {
|
2011-03-17 01:52:43 -04:00
|
|
|
throw new Exception("Template file '${templateFile}' does not exist or is empty in '{$config['dir']['template']}'!");
|
2010-11-02 06:57:33 -04:00
|
|
|
}
|
|
|
|
}
|
2011-06-25 02:03:57 -04:00
|
|
|
?>
|