$smarty->template_dir = _PS_THEME_DIR_ . 'tpl';
$smarty->compile_dir = _PS_SMARTY_DIR_ . 'compile';
$smarty->cache_dir = _PS_SMARTY_DIR_ . 'cache';
$smarty->config_dir = _PS_SMARTY_DIR_ . 'configs';
$smarty->caching = false;
$smarty->force_compile = (bool) Configuration::get('PS_SMARTY_FORCE_COMPILE');
$smarty->compile_check = false;
$smarty->debugging = false;
$smarty->debugging_ctrl = 'URL';
// 'NONE' on production
$smarty->deprecation_notices = false;
// so many depreciated yet not migrated smarty calls
if (Configuration::get('PS_FORCE_SMARTY_2')) {
    $smarty->debug_tpl = _PS_ALL_THEMES_DIR_ . 'debug.tpl';
    if (Configuration::get('PS_HTML_THEME_COMPRESSION')) {
        $smarty->register_outputfilter('smartyMinifyHTML');
    }
    if (Configuration::get('PS_JS_HTML_THEME_COMPRESSION')) {
        $smarty->register_outputfilter('smartyPackJSinHTML');
    }
} else {
    if (Configuration::get('PS_HTML_THEME_COMPRESSION')) {
        $smarty->registerFilter('output', 'smartyMinifyHTML');
    }
    if (Configuration::get('PS_JS_HTML_THEME_COMPRESSION')) {
        $smarty->registerFilter('output', 'smartyPackJSinHTML');
    }
}
smartyRegisterFunction($smarty, 'modifier', 'truncate', 'smarty_modifier_truncate');
smartyRegisterFunction($smarty, 'modifier', 'secureReferrer', array('Tools', 'secureReferrer'));
smartyRegisterFunction($smarty, 'function', 't', 'smartyTruncate');
Example #2
0
 /**
  * Register an output filter function to apply
  * to a template output
  *
  * When the template is invoked via display() or fetch(), its output can be sent through one or more
  * output filters. This differs from postfilters because postfilters operate on compiled templates before
  * they are saved to the disk, and output filters operate on the template output when it is executed.
  *  
  * @param callback $function
  * @return void
  */
 function registerOutputfilter($function)
 {
     $this->_smarty->register_outputfilter($function);
 }
Example #3
0
 /**
  * Return smarty instance
  *
  * @return Smarty
  */
 public function getSmarty()
 {
     static $oSmarty;
     if (!$oSmarty) {
         //create smarty object
         require_once 'Smarty.class.php';
         $oSmarty = new Smarty();
         foreach ($this->_aSmartyProperties as $sName => $mValue) {
             $oSmarty->{$sName} = substr($sName, -4) == '_dir' ? Volcano_Tools::fixPath($mValue) : $mValue;
         }
         foreach ($this->_aCustomFunctions as $sType => $aItems) {
             foreach ($aItems as $aItem) {
                 if (substr($oSmarty->_version, 0, 1) != '2') {
                     //bad code, but smarty3 has version like 'Smarty3-SVN$Rev: 3286 $'
                     if ($sType == 'modifier' || $sType == 'function') {
                         $oSmarty->registerPlugin($sType, $aItem[1], $aItem[0]);
                     } elseif ($sType == 'outputfilter') {
                         $oSmarty->registerFilter('output', $aItem[0]);
                     } elseif ($sType == 'postfilter') {
                         $oSmarty->registerFilter('post', $aItem[0]);
                     } elseif ($sType == 'prefilter') {
                         $oSmarty->registerFilter('pre', $aItem[0]);
                     }
                 } else {
                     if ($sType == 'modifier') {
                         $oSmarty->register_modifier($aItem[1], $aItem[0]);
                     } elseif ($sType == 'function') {
                         $oSmarty->register_function($aItem[1], $aItem[0]);
                     } elseif ($sType == 'outputfilter') {
                         $oSmarty->register_outputfilter($aItem[0]);
                     } elseif ($sType == 'postfilter') {
                         $oSmarty->register_postfilter($aItem[0]);
                     } elseif ($sType == 'prefilter') {
                         $oSmarty->register_prefilter($aItem[0]);
                     }
                 }
             }
         }
     }
     $oSmarty->error_reporting = error_reporting() & ~E_NOTICE;
     return $oSmarty;
 }
 /**
  *	This function will parse the template and will return the parsed contents. The name of the template you need
  *	to specify is the basename of the template without the file extension. This function automatically adds some
  *	variables to the template, which you can use as well in the template: YD_FW_NAME, YD_FW_VERSION, 
  *	YD_FW_NAMEVERS, YD_FW_HOMEPAGE, YD_SELF_SCRIPT, YD_SELF_URI, YD_ACTION_PARAM, YD_ENV, YD_COOKIE, YD_GET,
  *	YD_POST, YD_FILES, YD_REQUEST, YD_SESSION, YD_GLOBALS.
  *
  *	@param $name	The name of the template you want to parse and output.
  *
  *	@returns	This function returns the output of the parsed template.
  *
  *	@todo
  *		We should add options here to cache the output.
  */
 function getOutput($name)
 {
     // Add some default variables
     $this->setVar('YD_FW_NAME', YD_FW_NAME);
     $this->setVar('YD_FW_VERSION', YD_FW_VERSION);
     $this->setVar('YD_FW_NAMEVERS', YD_FW_NAMEVERS);
     $this->setVar('YD_FW_HOMEPAGE', YD_FW_HOMEPAGE);
     $this->setVar('YD_SELF_SCRIPT', YD_SELF_SCRIPT);
     $this->setVar('YD_SELF_URI', YD_SELF_URI);
     $this->setVar('YD_ACTION_PARAM', YD_ACTION_PARAM);
     // Get the path to the template
     if (is_file($this->_templateDir . '/' . $name . YD_TPL_EXT)) {
         $tplPath = realpath($this->_templateDir . '/' . $name . YD_TPL_EXT);
     } elseif (is_file($this->_templateDir . '/' . $name)) {
         $tplPath = realpath($this->_templateDir . '/' . $name);
     } else {
         $tplPath = realpath($name);
     }
     // Check if the file exists
     if (!is_file($tplPath)) {
         trigger_error('Template not found: ' . $tplPath, YD_ERROR);
     }
     // Include smarty
     require_once YD_DIR_3RDP . '/smarty/Smarty.class.php';
     // Instantiate smarty
     $tpl = new Smarty();
     // Configure smarty
     $tpl->template_dir = dirname($tplPath);
     $tpl->compile_dir = YD_DIR_TEMP;
     $tpl->left_delimiter = '[';
     $tpl->right_delimiter = ']';
     // Trim whitespace
     $tpl->register_outputfilter('YDTemplate_outputfilter_trimwhitespace');
     // Register the custom modifiers
     $tpl->register_modifier('addslashes', 'addslashes');
     $tpl->register_modifier('lower', 'strtolower');
     $tpl->register_modifier('implode', 'YDTemplate_modifier_implode');
     $tpl->register_modifier('fmtfilesize', 'YDTemplate_modifier_fmtfileize');
     $tpl->register_modifier('date_format', 'YDTemplate_modifier_date_format');
     $tpl->register_modifier('dump', 'YDTemplate_modifier_dump');
     // Add the other modifiers
     foreach ($this->_modifiers as $name => $function) {
         $tpl->register_modifier($name, $function);
     }
     // Add the functions
     foreach ($this->_functions as $name => $function) {
         $tpl->register_function($name, $function);
     }
     // Assign the variables
     $tpl->assign($this->_vars);
     // Output the template
     $contents = $tpl->fetch(basename($tplPath), null, md5(dirname($tplPath)));
     // Returns the contents
     return $contents;
 }