Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty plugin
Chris PeBenito 696b41
 * @package Smarty
Chris PeBenito 696b41
 * @subpackage plugins
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
Chris PeBenito 696b41
Chris PeBenito 696b41
/**
Chris PeBenito 696b41
 * Smarty {eval} function plugin
Chris PeBenito 696b41
 *
Chris PeBenito 696b41
 * Type:     function
Chris PeBenito 696b41
 * Name:     eval
Chris PeBenito 696b41
 * Purpose:  evaluate a template variable as a template
Chris PeBenito 696b41
 * @link http://smarty.php.net/manual/en/language.function.eval.php {eval}
Chris PeBenito 696b41
 *       (Smarty online manual)
Chris PeBenito 696b41
 * @param array
Chris PeBenito 696b41
 * @param Smarty
Chris PeBenito 696b41
 */
Chris PeBenito 696b41
function smarty_function_eval($params, &$smarty)
Chris PeBenito 696b41
{
Chris PeBenito 696b41
Chris PeBenito 696b41
    if (!isset($params['var'])) {
Chris PeBenito 696b41
        $smarty->trigger_error("eval: missing 'var' parameter");
Chris PeBenito 696b41
        return;
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
Chris PeBenito 696b41
    if($params['var'] == '') {
Chris PeBenito 696b41
        return;
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
Chris PeBenito 696b41
    $smarty->_compile_source('evaluated template', $params['var'], $_var_compiled);
Chris PeBenito 696b41
Chris PeBenito 696b41
    ob_start();
Chris PeBenito 696b41
    $smarty->_eval('?>' . $_var_compiled);
Chris PeBenito 696b41
    $_contents = ob_get_contents();
Chris PeBenito 696b41
    ob_end_clean();
Chris PeBenito 696b41
Chris PeBenito 696b41
    if (!empty($params['assign'])) {
Chris PeBenito 696b41
        $smarty->assign($params['assign'], $_contents);
Chris PeBenito 696b41
    } else {
Chris PeBenito 696b41
        return $_contents;
Chris PeBenito 696b41
    }
Chris PeBenito 696b41
}
Chris PeBenito 696b41
Chris PeBenito 696b41
/* vim: set expandtab: */
Chris PeBenito 696b41
Chris PeBenito 696b41
?>