示例#1
0
/**
 *
 *
 * @file function.widget.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_function_widget($params, Smarty_Internal_Template $template)
{
    $logArr['smarty_function'] = "function_widget";
    $name = $params['name'];
    $tpl_path = $params['path'];
    $fn = 'smarty_template_function_' . $name;
    $type = $template->smarty->getTemplateVars('_TEMPLATE_TYPE');
    $logArr['widget_name'] = $name;
    $logArr['widget_type'] = $type;
    $logArr['widget_path'] = $tpl_path;
    if (!function_exists($fn)) {
        //$tpl_path = CSmarty::getWidgetPath($type, $name);
        if (!$template->smarty->templateExists($tpl_path)) {
            $log_str = "widget not found :{$tpl_path}";
            CSmarty::addError($log_str);
            CLog::warning($log_str, -1, $logArr, 1);
            return false;
        }
        $template->smarty->fetch($tpl_path);
    }
    if (!function_exists($fn)) {
        $log_str = "template function {$fn} not found";
        CSmarty::addError($log_str);
        CLog::warning($log_str, -1, $logArr, 1);
        return false;
    } else {
        $result = $fn($template, $params);
    }
    return $result;
}
示例#2
0
 /**
  * do rendering
  * @params array data
  * @params string template_name
  * @params int templateSwitch
  */
 function do_render($data, $template_name, $templateSwitch = 1, $templateVersion = '')
 {
     $this->_errors = array();
     $tpl_path = self::getTplPath($this->_type, $template_name, $templateSwitch, $templateVersion);
     if (!$this->_smarty->templateExists($tpl_path)) {
         $tpl_not_found = true;
         //首页兼容,如果找不到首页,就用baidu模板下的首页
         if ($templateSwitch == 2) {
             $template_name = $GLOBALS['DEFAULT_TEMPLATE_NAME'];
             $tpl_path = self::getTplPath($this->_type, $template_name, $templateSwitch);
             if (!$this->_smarty->templateExists($tpl_path)) {
                 //首页兼容,如果找不到首页,就用baidu type下的baidu模板下的首页
                 $this->_type = $GLOBALS['DEFAULT_TEMPLATE_TYPE'];
                 $page_path = self::getTplFolderPath(VUI_TEMPLATE_PATH, $this->_platform, $this->_language, $this->_type);
                 $this->set_template_dir(realpath($page_path));
                 $tpl_path = self::getTplPath($this->_type, $template_name, $templateSwitch);
             }
             if ($this->_smarty->templateExists($tpl_path)) {
                 $tpl_not_found = false;
             }
         }
         if ($tpl_not_found == true) {
             $td_path = $this->_page_dir . ":" . $this->_widget_dir . ":";
             CSmarty::addError("template not found :{$td_path}/{$tpl_path}");
             return false;
         }
     }
     /**
      * set exception/error handler
      */
     $objTplLog = TplLog::getInstance();
     //set_exception_handler("template_exception_handler");
     //set_error_handler("template_error_handler", error_reporting());
     $this->_smarty->clearAllAssign();
     $this->_smarty->assign('_TEMPLATE_TYPE', $this->_type);
     $tplData_tpl_path = $this->_platform . '/' . $this->_language . '/' . $this->_type . '/' . $tpl_path;
     if ($this->_type == VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE || $this->_type == $GLOBALS['STRUCT_TEMPLATE_TYPE'] || $this->_type == $GLOBALS['ECOM_TEMPLATE_TYPE']) {
         self::$_hi_word = $data['strategy']['hilightWord'];
         foreach ($data['resultData'] as $k => $v) {
             $this->_smarty->assign($k, $v);
         }
     } else {
         $this->_smarty->assign('tplData', $data);
         $objTplLog->addNewTplData($tpl_path, $this->getThisSmarty($this), $data);
     }
     try {
         $result = $this->_smarty->fetch($tpl_path);
     } catch (Exception $e) {
         CSmarty::addError("fail to render template :{$e->getMessage()}");
         return false;
     }
     $this->_smarty->clearAllAssign();
     return $result;
 }