2020-04-13 15:30:52 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Smarty plugin for testing scopes in config vars
|
|
|
|
|
*
|
2023-08-08 00:04:14 +02:00
|
|
|
|
|
|
|
|
|
2020-04-13 15:30:52 +02:00
|
|
|
*/
|
|
|
|
|
|
2023-08-08 00:04:14 +02:00
|
|
|
use Smarty\Template;
|
|
|
|
|
|
2020-04-13 15:30:52 +02:00
|
|
|
/**
|
|
|
|
|
* Smarty {checkconfigvar}
|
|
|
|
|
*
|
|
|
|
|
* @param array $params parameter array
|
|
|
|
|
* @param object $template template object
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function smarty_function_checkconfigvar($params, $template)
|
|
|
|
|
{
|
|
|
|
|
$output = '';
|
2023-08-08 00:04:14 +02:00
|
|
|
$types = array('template', 'data', 'global');
|
2020-04-13 15:30:52 +02:00
|
|
|
if (isset($params['types'])) {
|
|
|
|
|
$types = (array)$params['types'];
|
|
|
|
|
}
|
|
|
|
|
$var = $params['var'];
|
|
|
|
|
$ptr = $template;
|
|
|
|
|
while ($ptr) {
|
2023-08-08 00:04:14 +02:00
|
|
|
if (in_array('template', $types) && $ptr instanceof Template) {
|
|
|
|
|
$output .= "#{$ptr->getSource()->name}:\${$var} =";
|
|
|
|
|
$output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
|
2020-04-13 15:30:52 +02:00
|
|
|
$ptr = $ptr->parent;
|
2023-08-08 00:04:14 +02:00
|
|
|
} elseif (in_array('data', $types) && !($ptr instanceof Template || $ptr instanceof \Smarty\Smarty)) {
|
2020-04-13 15:30:52 +02:00
|
|
|
$output .= "#data:\${$var} =";
|
2023-08-08 00:04:14 +02:00
|
|
|
$output .= $ptr->hasConfigVariable($var) ? preg_replace('/\s/', '', var_export($ptr->getConfigVariable($var), true)) : 'null';
|
2020-04-13 15:30:52 +02:00
|
|
|
$ptr = $ptr->parent;
|
|
|
|
|
} else {
|
|
|
|
|
$ptr = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-08-08 00:04:14 +02:00
|
|
|
if (in_array('global', $types)) {
|
|
|
|
|
$output .= "#global:\${$var} =";
|
|
|
|
|
$output .= $template->getSmarty()->hasConfigVariable($var) ?
|
|
|
|
|
preg_replace('/\s/', '', var_export($template->getSmarty()->getConfigVariable($var), true)) : 'null';
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
return $output;
|
|
|
|
|
}
|