Beispiel #1
0
 public static function smarty_factory()
 {
     if (!isset($_SERVER['smartybase'])) {
         $_SERVER['smartybase'] = "/var/tmp/smarty-" . md5($_SERVER['SCRIPT_FILENAME']);
     }
     if (!lib::$appvars) {
         lib::$appvars = array('filebase' => $_SERVER['filebase'], 'mediabase' => $_SERVER['mediabase'], 'uribase' => $_SERVER['uribase'], 'urirequest' => $_SERVER['urirequest']);
     }
     $smbase = $_SERVER['smartybase'];
     #@mkdir("$smbase/templates", 0777, true);
     @mkdir("{$smbase}/templates_c", 0777, true);
     @mkdir("{$smbase}/cache", 0777, true);
     $smarty = new Smarty();
     $smarty->template_dir = "./views";
     $smarty->compile_dir = "{$smbase}/templates_c";
     $smarty->cache_dir = "{$smbase}/cache";
     # we don't set config dir, we most likely won't use it initially
     $smext = array('smarty_extensions', 'smarty_custom');
     foreach ($smext as $smo) {
         $mnames = get_class_methods($smo);
         foreach ($mnames as $method) {
             if (preg_match('/^func_(\\w+)$/', $method, $m)) {
                 $smarty->register_function($m[1], array($smo, $method));
             } elseif (preg_match('/^modifier_(\\w+)$/', $method, $m)) {
                 $smarty->register_modifier($m[1], array($smo, $method));
             } elseif (preg_match('/^block_(\\w+)$/', $method, $m)) {
                 $smarty->register_block($m[1], array($smo, $method));
             }
         }
     }
     # these are order dependent
     $smarty->register_prefilter(array('smarty_extensions', 'prefilter_convert_loop_breaks'));
     $smarty->register_prefilter(array('smarty_extensions', 'prefilter_convert_loop_continue'));
     $smarty->assign_by_ref('app', lib::$appvars);
     if (file_exists("setup/template_conf.php")) {
         include "setup/template_conf.php";
     }
     return $smarty;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Register a prefilter function to apply
  * to a template before compiling
  *
  * @param callback $function
  * @return void
  */
 function registerPrefilter($function)
 {
     $this->_smarty->register_prefilter($function);
 }
Beispiel #4
0
 * Create the Smarty engine object to process the form template first
 *
 * NOTE: the form template needs to be processed separately from any other
 * page templates to prevent that the form prefilter interferes with the
 * normal processing of the other templates
 */
$smarty = new Smarty();
if ($smarty->template_exists("form.tpl")) {
    $smarty->assign_by_ref("form", $form);
    $smarty->assign("title", "Form class test");
    $smarty->assign("error_message", $error_message);
    $smarty->assign_by_ref("verify", $verify);
    $smarty->assign("doit", $doit);
    $smarty->assign("mark", "[Verify]");
    $smarty->assign("credit_card_field", "credit_card_number");
    $smarty->register_prefilter("smarty_prefilter_form");
    $smarty->fetch("form.tpl");
    $smarty->unregister_prefilter("smarty_prefilter_form");
} else {
    $form->AddDataPart("<h2><center>Please copy the template file <tt>templates/form.tpl</tt> to your Smarty <tt>templates</tt> directory.</center></h2>\n");
    $doit = 1;
}
/*
 * If the form was not submitted or was not valid, make the page ONLOAD
 * event give the focus to the first form field or the first invalid field.
 */
if (!$doit) {
    if (strlen($error_message)) {
        /*
         * If there is at least one field with invalid values, get the name of the
         * first field in error to make it get the input focus when the page is
Beispiel #5
0
 /**
  * sets properties of smarty object
  *
  * @param Smarty $smarty template processor object (smarty)
  */
 protected function _fillCommonSmartyProperties($smarty)
 {
     $config = $this->getConfig();
     $smarty->left_delimiter = '[{';
     $smarty->right_delimiter = '}]';
     $smarty->register_resource('ox', array('ox_get_template', 'ox_get_timestamp', 'ox_get_secure', 'ox_get_trusted'));
     $smartyDir = $this->getSmartyDir();
     $smarty->caching = false;
     $smarty->compile_dir = $smartyDir;
     $smarty->cache_dir = $smartyDir;
     $smarty->template_dir = $this->getTemplateDirs();
     $smarty->compile_id = $this->getTemplateCompileId();
     $smarty->default_template_handler_func = array(oxRegistry::get("oxUtilsView"), '_smartyDefaultTemplateHandler');
     array_unshift($smarty->plugins_dir, $config->getConfigParam('sShopDir') . 'Core/smarty/plugins');
     include_once dirname(__FILE__) . '/smarty/plugins/prefilter.oxblock.php';
     $smarty->register_prefilter('smarty_prefilter_oxblock');
     $debugMode = $config->getConfigParam('iDebug');
     if ($debugMode == 1 || $debugMode == 3 || $debugMode == 4) {
         $smarty->debugging = true;
     }
     if ($debugMode == 8 && !$config->isAdmin()) {
         include_once getShopBasePath() . 'Core/smarty/plugins/prefilter.oxtpldebug.php';
         $smarty->register_prefilter('smarty_prefilter_oxtpldebug');
     }
     //demo shop security
     if (!$config->isDemoShop()) {
         $smarty->php_handling = (int) $config->getConfigParam('iSmartyPhpHandling');
         $smarty->security = false;
     } else {
         $smarty->php_handling = SMARTY_PHP_REMOVE;
         $smarty->security = true;
         $smarty->security_settings['IF_FUNCS'][] = 'XML_ELEMENT_NODE';
         $smarty->security_settings['IF_FUNCS'][] = 'is_int';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'round';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'floor';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'trim';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'implode';
         $smarty->security_settings['MODIFIER_FUNCS'][] = 'is_array';
         $smarty->security_settings['ALLOW_CONSTANTS'] = true;
         $smarty->secure_dir = $smarty->template_dir;
     }
 }