2009-03-22 16:09:05 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-07-30 13:09:52 +00:00
|
|
|
* Smarty Internal Plugin Compile Config Load
|
|
|
|
* Compiles the {config load} tag
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2010-07-30 13:09:52 +00:00
|
|
|
* @subpackage Compiler
|
2014-06-06 02:40:04 +00:00
|
|
|
* @author Uwe Tews
|
2010-07-30 13:09:52 +00:00
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-30 13:09:52 +00:00
|
|
|
* Smarty Internal Plugin Compile Config Load Class
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Compiler
|
2010-07-30 13:09:52 +00:00
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
2010-11-11 21:34:36 +00:00
|
|
|
public $required_attributes = array('file');
|
2015-08-17 21:52:32 +02:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
2014-06-06 02:40:04 +00:00
|
|
|
public $shorttag_order = array('file', 'section');
|
2015-08-17 21:52:32 +02:00
|
|
|
|
2011-09-16 14:19:56 +00:00
|
|
|
/**
|
|
|
|
* Attribute definition: Overwrites base class.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @see Smarty_Internal_CompileBase
|
|
|
|
*/
|
2015-11-01 02:58:27 +01:00
|
|
|
public $optional_attributes = array('section', 'scope', 'bubble_up');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Valid scope names
|
2016-02-09 01:27:15 +01:00
|
|
|
*
|
2015-11-01 02:58:27 +01:00
|
|
|
* @var array
|
|
|
|
*/
|
2016-02-09 01:27:15 +01:00
|
|
|
public $valid_scopes = array('local' => true, 'parent' => true, 'root' => true, 'tpl_root' => true);
|
2010-11-11 21:34:36 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
/**
|
2010-07-30 13:09:52 +00:00
|
|
|
* Compiles code for the {config_load} tag
|
2011-09-16 14:19:56 +00:00
|
|
|
*
|
2015-08-17 21:52:32 +02:00
|
|
|
* @param array $args array with attributes from parser
|
2015-08-06 01:19:11 +02:00
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2010-07-30 13:09:52 +00:00
|
|
|
* @return string compiled code
|
2015-08-06 01:19:11 +02:00
|
|
|
* @throws \SmartyCompilerException
|
2010-07-30 13:09:52 +00:00
|
|
|
*/
|
2015-08-06 01:19:11 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
2009-03-22 16:09:05 +00:00
|
|
|
{
|
|
|
|
// check and get attributes
|
2011-09-16 14:19:56 +00:00
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
|
2016-02-09 01:27:15 +01:00
|
|
|
if ($_attr[ 'nocache' ] === true) {
|
2015-08-06 01:19:11 +02:00
|
|
|
$compiler->trigger_template_error('nocache option not allowed', null, true);
|
2010-11-11 21:34:36 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 02:40:04 +00:00
|
|
|
// save possible attributes
|
2016-02-09 01:27:15 +01:00
|
|
|
$conf_file = $_attr[ 'file' ];
|
|
|
|
if (isset($_attr[ 'section' ])) {
|
|
|
|
$section = $_attr[ 'section' ];
|
2009-03-22 16:09:05 +00:00
|
|
|
} else {
|
|
|
|
$section = 'null';
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2015-11-01 02:58:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_LOCAL;
|
2016-02-09 01:27:15 +01:00
|
|
|
if (isset($_attr[ 'scope' ])) {
|
|
|
|
$_attr[ 'scope' ] = trim($_attr[ 'scope' ], "'\"");
|
|
|
|
if (!isset($this->valid_scopes[ $_attr[ 'scope' ] ])) {
|
|
|
|
$compiler->trigger_template_error("illegal value '{$_attr['scope']}' for \"scope\" attribute", null,
|
|
|
|
true);
|
2015-11-01 02:58:27 +01:00
|
|
|
}
|
2016-02-09 01:27:15 +01:00
|
|
|
if ($_attr[ 'scope' ] != 'local') {
|
|
|
|
if ($_attr[ 'scope' ] == 'parent') {
|
2015-11-01 02:58:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_PARENT;
|
2016-02-09 01:27:15 +01:00
|
|
|
} elseif ($_attr[ 'scope' ] == 'root') {
|
2015-11-01 02:58:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_ROOT;
|
2016-02-09 01:27:15 +01:00
|
|
|
} elseif ($_attr[ 'scope' ] == 'tpl_root') {
|
2015-11-01 02:58:27 +01:00
|
|
|
$_scope = Smarty::SCOPE_TPL_ROOT;
|
|
|
|
}
|
2016-02-09 01:27:15 +01:00
|
|
|
$_scope += (isset($_attr[ 'bubble_up' ]) && $_attr[ 'bubble_up' ] == 'false') ? 0 :
|
|
|
|
Smarty::SCOPE_BUBBLE_UP;
|
2014-06-06 02:40:04 +00:00
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2015-11-01 02:58:27 +01:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
// create config object
|
2015-11-01 02:58:27 +01:00
|
|
|
$_output =
|
|
|
|
"<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
|
2013-07-14 22:15:45 +00:00
|
|
|
|
2009-03-22 16:09:05 +00:00
|
|
|
return $_output;
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|