コード例 #1
0
ファイル: function.widget.php プロジェクト: drehere/shenmegui
/**
 *
 *
 * @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
ファイル: ClkEncryption.php プロジェクト: drehere/shenmegui
 public function run(&$arrData, $arrConf)
 {
     if (empty($arrData) || !is_array($arrData)) {
         return false;
     }
     $arrPublicInfo = array();
     $intPageNo = intval($arrData['uiData']['queryInfo']['pageNo']);
     $intRstNum = intval($arrData['uiData']['queryInfo']['resNum']);
     $arrPublicInfo['word_enc'] = $arrData['uiData']['queryInfo']['wordEnc'];
     //query_come_from
     $arrPublicInfo['come_from'] = intval($arrData['uiData']['queryInfo']['pUrlConfig']['f']);
     $arrPublicInfo['time'] = Volatile::gettimeofday();
     //T参数
     $arrData['uiData']['queryInfo']['listTime'] = $arrPublicInfo['time']['sec'];
     $arrNewQueryInfo = CSmarty::getQueryInfo();
     $arrNewQueryInfo['listTime'] = $arrPublicInfo['time']['sec'];
     //CSmarty::setQueryInfo($arrData['uiData']['queryInfo']);
     CSmarty::setQueryInfo($arrNewQueryInfo);
     if (!empty($arrData['uiData']['asResult']['item']) && is_array($arrData['uiData']['asResult']['item'])) {
         foreach ($arrData['uiData']['asResult']['item'] as $intIndex => &$arrItem) {
             if (!in_array($arrItem['comeFrome'], array('SP', 'AS'))) {
                 continue;
             }
             $arrStrategys = array();
             $strUrl = $arrItem['offsetInfo']['urlEncoded'];
             //$arrPublicInfo['url'] = iconv('utf-8','gbk',$arrItem['offsetInfo']['url']);
             $arrPublicInfo['url'] = urldecode($strUrl);
             $arrPublicInfo['id'] = $intIndex + ($intPageNo - 1) * $intRstNum + 1;
             if (!empty($arrItem['comeFrome']) && $arrItem['comeFrome'] == 'AS') {
                 $arrStrategys = $arrItem['urls']['asUrls']['strategys'];
             } else {
                 $arrStrategys = $arrItem['strategyS'];
             }
             $arrStrategys = array_slice($arrStrategys, 0, 4);
             $arrRst = getClkEncryption($arrStrategys, $arrPublicInfo);
             //加密串
             if (!empty($arrRst['clkencryption'])) {
                 $arrItem['encryptionClick'] = trim($arrRst['clkencryption']);
             }
             //F,F1,F2,F3参数
             if (!empty($arrRst['strategyStr']) && is_array($arrRst['strategyStr'])) {
                 $arrItem['strategyStr'] = $arrRst['strategyStr'];
             }
             //Y参数
             if (!empty($arrRst['identifyStr'])) {
                 $arrItem['identifyStr'] = trim($arrRst['identifyStr']);
             }
         }
     }
     $intSearchIdentifyStr = getSeClkencryption($arrPublicInfo);
     if ($intSearchIdentifyStr !== false) {
         $arrData['uiData']['asResult']['searchIdentifyStr'] = $intSearchIdentifyStr;
     }
     return true;
 }
コード例 #3
0
ファイル: CssHeadJsFoot.php プロジェクト: drehere/shenmegui
 public static function getCssJs($type, $arrTplNames, $arrCSSUI)
 {
     $cssStr = '';
     $jsStr = '';
     $cssUI = '';
     $strLog = '';
     $uiArr = array();
     // 必须去重
     $arrTplNames = array_keys(array_flip($arrTplNames));
     $arrSmartyConf = CSmarty::getConf();
     // 预处理CSS、JS合并,读取文件
     foreach ($arrTplNames as $tpl) {
         $cssjsPath = CSmarty::getHeadCssFootJsPath(VUI_TEMPLATE_PATH, $arrSmartyConf['platform'], $arrSmartyConf['language'], $type, $tpl);
         if (!file_exists($cssjsPath)) {
             continue;
         }
         require "{$cssjsPath}";
         $strLog .= $tpl . '(';
         $className = 'CssJs_Util_' . $tpl;
         if (class_exists($className) && method_exists($className, 'getHeadCss')) {
             $cssStr .= call_user_func(array($className, 'getHeadCss'));
             if (!empty($cssStr)) {
                 $strLog .= 'css,';
             }
         }
         if (class_exists($className) && method_exists($className, 'getFootJs')) {
             $jsStr .= call_user_func(array($className, 'getFootJs'));
             if (!empty($jsStr)) {
                 $strLog .= 'js,';
             }
         }
         if (class_exists($className) && method_exists($className, 'getCssUI')) {
             $arrUis = call_user_func(array($className, 'getCssUI'));
             if (!empty($arrUis) && is_array($arrUis)) {
                 $uiArr = array_merge($uiArr, $arrUis);
                 $strLog .= implode('_', $arrUis);
             }
         }
         $strLog .= ')';
     }
     $uiArr = array_unique($uiArr);
     if (!empty($uiArr)) {
         // 通用组件的位置放在大搜索目录下
         foreach ($uiArr as $ui) {
             if (empty($arrCSSUI[$ui]['common'])) {
                 CLog::warning("Invalid UiCss:{$ui}");
             } else {
                 $cssUI .= $arrCSSUI[$ui]['common'];
             }
         }
     }
     $GLOBALS['logArr']['merge'] = $strLog;
     return array('cssMerge' => $cssUI . ' ' . $cssStr, 'jsMerge' => $jsStr);
 }
コード例 #4
0
ファイル: TrafficFilter.php プロジェクト: drehere/shenmegui
 public function run(&$arrData, $arrConf)
 {
     if (empty($arrData) || !is_array($arrData)) {
         return false;
     }
     if (!isset($arrData['uiData']['queryInfo']['personalData']) || empty($arrData['uiData']['queryInfo']['personalData'])) {
         return false;
     }
     $arrPersonalData = json_decode($arrData['uiData']['queryInfo']['personalData'], true);
     if (!is_array($arrPersonalData) || empty($arrPersonalData)) {
         return false;
     }
     if (!isset($arrPersonalData[TrafficFilter::TRAFFIC_KEY])) {
         return false;
     }
     // 处理违章多车信息
     $arrTrafficInfo = $arrPersonalData[TrafficFilter::TRAFFIC_KEY];
     unset($arrPersonalData[TrafficFilter::TRAFFIC_KEY]);
     $arrData['uiData']['queryInfo']['personalData'] = json_encode($arrPersonalData);
     $arrTrafficValue = json_decode($arrTrafficInfo['value'], true);
     $arrTrafficData = array();
     $arrExisted = array();
     if (is_array($arrTrafficValue) && !empty($arrTrafficValue)) {
         foreach ($arrTrafficValue as $intIndex => $arrItem) {
             $arrItem['city'] = strtolower($arrItem['city']);
             // 城市
             $arrItem['hphm'] = mb_strtoupper($arrItem['hphm'], 'utf-8');
             // 车牌号
             $arrItem['engineno'] = strtoupper($arrItem['engineno']);
             // 发动机
             $arrItem['classno'] = strtoupper($arrItem['classno']);
             // 车架号
             $strTemp = md5($arrItem['city'] . $arrItem['hphm']);
             if (isset($arrExisted[$arrItem['hphm']])) {
                 if (in_array($strTemp, $arrExisted[$arrItem['hphm']])) {
                     continue;
                 } else {
                     $arrExisted[$arrItem['hphm']][] = $strTemp;
                     $arrTrafficData[] = $arrItem;
                 }
             } else {
                 $arrExisted[$arrItem['hphm']][] = $strTemp;
                 $arrTrafficData[] = $arrItem;
             }
             unset($strTemp);
         }
     }
     if (is_array($arrTrafficData) && !empty($arrTrafficData)) {
         $arrTrafficData = array_reverse($arrTrafficData);
         $arrData['uiData']['queryInfo']['trafficData'] = $arrTrafficData;
     }
     CSmarty::setQueryInfo($arrData['uiData']['queryInfo']);
     return true;
 }
コード例 #5
0
/**
 *
 *
 * @file modifier.encryptUrl.php
 * @package plugins
 * @author fengfei02@baidu.com
 * @date 2012-08-30 01:40
 */
function smarty_modifier_encryptUrl($url, $maxRandomStrLen = '', $encKeyStr = '')
{
    $URLEncryption = CSmarty::getURLEncryption();
    if (0 === intval($URLEncryption)) {
        return $url;
    }
    $result = encryptUrl($url, $maxRandomStrLen, $encKeyStr);
    if (false == $result) {
        $result = '';
    }
    return $result;
}
コード例 #6
0
ファイル: render.php プロジェクト: liuyan365/edpx-zhixin
function render($tplName, $tplItem)
{
    global $smarty;
    global $smartyConf;
    CSmarty::clearError();
    // 这里,$data有三种数据格式,第一种是我定义的最原始的数据格式,第二种是有的同学在display里面进行了细分,加了extData,第三种是平台的数据格式
    // 所以,在这里先进行一次处理
    // $data = preprocess(CJSON::decode(file_get_contents($tplItem['data'])));
    $data = preprocess(json_decode(file_get_contents($tplItem['data']), TRUE));
    $result = $smarty->do_render($data, $tplName);
    // 有错误发生
    $errors = CSmarty::getError();
    if (count($errors) > 0) {
        return $errors[0];
    }
    return $result;
}
コード例 #7
0
/**
 *
 * @param $strImgSrc unknown_type       	
 * @return boolean unknown data-src={%$ls.src%} data-b64-id={%$ls.imgkey%}>
 *         <img src={%$ls.src%}>
 *        
 */
function smarty_modifier_img_base64_render($strImgSrc)
{
    if (empty($strImgSrc)) {
        CLog::warning("fail to get img base64 src id, src null");
        return false;
    }
    $arrQueryInfo = CSmarty::getQueryInfo();
    $strPage = "";
    if (!isset($arrQueryInfo['base64']) || $arrQueryInfo['base64'] !== 'on') {
        $strPage = 'src="' . $strImgSrc . '"';
        return $strPage;
    }
    if (!isset($arrQueryInfo['base64_sids_for_plugin']) || empty($arrQueryInfo['base64_sids_for_plugin'][$strImgSrc])) {
        $strPage = 'src="' . $strImgSrc . '"';
        return $strPage;
    } else {
        $strPage = 'data-src="' . $strImgSrc . '" ' . 'data-b64-id="' . $arrQueryInfo['base64_sids_for_plugin'][$strImgSrc] . '"';
        CLog::debug("get img base64 src id OK");
        return $strPage;
    }
}
コード例 #8
0
/**
 *
 * @param $strImgSrc unknown_type       	
 * @return string "data-b64-id"
 *        
 */
function smarty_modifier_img_base64_parser($strImgSrc)
{
    if (empty($strImgSrc)) {
        return '';
    }
    $arrQueryInfo = CSmarty::getQueryInfo();
    if (!isset($arrQueryInfo['base64']) || $arrQueryInfo['base64'] !== 'on') {
        return '';
    }
    if (!isset($arrQueryInfo['base64_left_exp']) || $arrQueryInfo['base64_left_exp'] !== 'on') {
        return '';
    }
    if (isset($arrQueryInfo['base64_img_sids_left']) && !empty($arrQueryInfo['base64_img_sids_left'][$strImgSrc])) {
        return $arrQueryInfo['base64_img_sids_left'][$strImgSrc];
        CLog::debug("get img base64 src id OK");
    } else {
        if (isset($arrQueryInfo['base64_img_sids']) && !empty($arrQueryInfo['base64_img_sids'][$strImgSrc])) {
            return $arrQueryInfo['base64_img_sids'][$strImgSrc];
            CLog::debug("get img base64 src id OK");
        }
    }
    return '';
}
コード例 #9
0
/**
 *
 *
 * @file modifier.zhidaoXmlTrans.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_modifier_zhidaoXmlTrans()
{
    $logArr['smarty_modifier'] = "modifier_zhidaoXmlTrans";
    /**
     * hilight info
     * @var array
     */
    $hilight_info = CSmarty::getHilightInfo();
    $hi_word = $hilight_info['hilightInfo']['hi_word'];
    $hi_off = $hilight_info['hilightInfo']['hi_off'];
    $hi_num = $hilight_info['hilightInfo']['hi_num'];
    $status = 0;
    if (isset($hi_off[0])) {
        $hi_off[0] = 0;
    }
    $result = hilight_zhidaoXmlTrans($hi_word, $hi_off, $hi_num);
    if (false == $result) {
        $status = -1;
        CLog::warning("fail to call hilight_zhidaoXmlTrans", $status, $logArr, 1);
        return false;
    }
    CLog::debug("success to call zhidaoXmlTrans modifier", $status, $logArr, 1);
    return $result;
}
コード例 #10
0
 /**
  * 模板选择
  *
  * @param $arrData unknown_type       	
  * @return true or false
  */
 public function getUserInfo(&$arrData)
 {
     if (empty($arrData) || !is_array($arrData)) {
         CLog::warning("tpl select is wrong, param err!");
         return false;
     }
     // Flag
     if (Util::getConf('/feature', 'FEATURE_LIST/TemplateSelector/TURN') !== 'ON') {
         return true;
     }
     // 读取tn和tplName
     // $arrAccounts = Util::getConf ( '/accounts', 'ACCOUNT_TPLNAME' );
     // $arrTplTypes = Util::getConf ( '/tpl_type', 'TEMPLATE_TYPE' );
     require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
     if (!isset($arrTplTypes)) {
         CLog::warning("tpl select is wrong, require tpl type err!");
         return false;
     }
     $arrQueryInfo =& $arrData['uiData']['queryInfo'];
     $arrHilightInfo =& $arrData['uiData']['hilightInfo'];
     $arrControlInfo =& $arrData['uiControl'];
     $arrUrlConfig = $arrQueryInfo['pUrlConfig'];
     $arrTplConfig = array();
     $strTn = "";
     $strTplName = "";
     if (isset($arrControlInfo['oriAccountName']) && !empty($arrControlInfo['oriAccountName']) && isset($arrControlInfo['oriTplName']) && !empty($arrControlInfo['oriTplName'])) {
         $strTn = trim($arrControlInfo['oriAccountName']);
         $strTplName = trim($arrControlInfo['oriTplName']);
     }
     // 处理首页模板
     /* if ($arrData ['uiControl'] ['templateSwitch'] == 2) {
     			$strTn = isset ( $arrUrlConfig ['tn'] ) ? trim ( $arrUrlConfig ['tn'] ) : '';
     			$strTplName = "";
     			if (! empty ( $strTn )) {
     				$strTplName = get_value_by_key ( $strTn );
     			}
     			if (empty ( $strTplName )) {
     				$arrUrlConfig ['tn'] = trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
     			}
     			// return true;
     		} */
     /* when useing debug page. */
     if (!empty($GLOBALS['DEBUG_PAGE_TN']) && strcasecmp($GLOBALS['DEBUG_PAGE_TN'], $strTn) == 0) {
         $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
     } else {
         // tn选择模板
         /* $strTn = isset ( $arrUrlConfig ['tn'] ) ? trim ( $arrUrlConfig ['tn'] ) : trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
         			$strTplName = "";
         			if (! empty ( $strTn )) {
         				$strTplName = get_value_by_key ( $strTn );
         			}
         			if (! empty ( $strTplName )) {
         				$arrControlInfo ['templateName'] = $strTplName;
         			} else {
         				$arrUrlConfig ['tn'] = trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
         				$arrControlInfo ['templateName'] = trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
         				$arrQueryInfo ['strategyName'] = BAIDU_TEMPLATE;
         			} */
         if (!empty($strTn) && !empty($strTplName)) {
             $arrUrlConfig['tn'] = $strTn;
             $arrControlInfo['templateName'] = $strTplName;
         } else {
             $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
         }
         // 是否是站内搜索,是则选模板SITE_SEARCH_TEMP_PP
         if (isset($arrUrlConfig['sts'])) {
             $arrUrlConfig['sts'] = trim($arrUrlConfig['sts']);
             if (!empty($arrUrlConfig['sts'])) {
                 if (isset($arrQueryInfo['isHideSite']) && intval($arrQueryInfo['isHideSite']) == 1 && isset($arrTplTypes[$GLOBALS['TEMP_SITE_NOPP']])) {
                     $arrControlInfo['templateName'] = $GLOBALS['TEMP_SITE_NOPP'];
                 } else {
                     if (isset($arrTplTypes[$GLOBALS['TEMP_SITE_PP']])) {
                         $arrControlInfo['templateName'] = $GLOBALS['TEMP_SITE_PP'];
                     }
                 }
             }
         }
     }
     // 模板类型
     $arrPlatForm = array();
     if (isset($arrTplTypes[$arrControlInfo['templateName']])) {
         $arrControlInfo['templateType'] = $arrTplTypes[$arrControlInfo['templateName']]['type'];
         $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
     } else {
         $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrControlInfo['templateType'] = trim($GLOBALS['DEFAULT_TEMPLATE_TYPE']);
         $arrPlatForm[] = trim($GLOBALS['DEFAULT_PLATFORM']);
     }
     // 平台检查
     if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
         if (count($arrPlatForm) >= 2) {
             $arrControlInfo['platform'] = $arrPlatForm[1];
         } else {
             $arrControlInfo['platform'] = $arrPlatForm[0];
         }
         $arrQueryInfo['dspName'] = "";
     }
     //dsp参数处理
     if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
         if (empty($arrData['uiData']['queryInfo']['dspName'])) {
             $arrData['uiData']['queryInfo']['dspName'] = "ipad";
             CLog::warning("dspName is not ipad when using pad template.");
         }
     }
     //检查模板目录是否存在,不存在使用baidu模板
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'];
     if (!file_exists($strTplConfigPath)) {
         $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
         // 模板类型
         unset($arrPlatForm);
         $arrPlatForm = array();
         if (isset($arrTplTypes[$arrControlInfo['templateName']])) {
             $arrControlInfo['templateType'] = $arrTplTypes[$arrControlInfo['templateName']]['type'];
             $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
         } else {
             $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateType'] = trim($GLOBALS['DEFAULT_TEMPLATE_TYPE']);
             $arrPlatForm[] = trim($GLOBALS['DEFAULT_PLATFORM']);
         }
         // 平台检查
         if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
             if (count($arrPlatForm) >= 2) {
                 $arrControlInfo['platform'] = $arrPlatForm[1];
             } else {
                 $arrControlInfo['platform'] = $arrPlatForm[0];
             }
             $arrQueryInfo['dspName'] = "";
         }
     }
     // 获取模板配置信息
     unset($strTplConfigPath);
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
     if (!file_exists($strTplConfigPath)) {
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateType'] . '.cfg.php';
         if (!file_exists($strTplConfigPath)) {
             $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateType'] = trim($GLOBALS['DEFAULT_TEMPLATE_TYPE']);
             $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
             $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
             if (!file_exists($strTplConfigPath)) {
                 $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateType'] . '.cfg.php';
                 if (!file_exists($strTplConfigPath)) {
                     $arrControlInfo['platform'] = trim($GLOBALS['DEFAULT_PLATFORM']);
                     $arrControlInfo['language'] = trim($GLOBALS['DEFAULT_LANGUAGE']);
                     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
                     if (!file_exists($strTplConfigPath)) {
                         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateType'] . '.cfg.php';
                         if (!file_exists($strTplConfigPath)) {
                             CLog::warning("tpl select is wrong, cfg not existed!");
                             return false;
                         }
                     }
                 }
             }
         }
     }
     $arrQueryInfo['accountName'] = $arrUrlConfig['tn'];
     $arrData['uiControl']['tplConfigPath'] = $strTplConfigPath;
     $arrData['uiControl']['tplConfigName'] = $arrControlInfo['templateName'];
     $arrData['uiControl']['tplConfigType'] = $arrControlInfo['templateType'];
     /* $arrTplConfig = $this->getTplConfig ( $strTplConfigPath );
     		if (! is_array ( $arrTplConfig ) || empty ( $arrTplConfig ) || count ( $arrTplConfig ) <= 0) {
     			// log
     			CLog::warning ( "tpl select is wrong, getting cfg err!" );
     			return false;
     		}
     		
     		// 处理首页模板
     		if ($arrData ['uiControl'] ['templateSwitch'] == 2) {
     			$arrFrontPage = Util::getConf ( '/frontpage', 'FRONTPAGE/LOGO' );
     			if (! empty ( $arrFrontPage ) && is_array ( $arrFrontPage )) {
     				foreach ( $arrFrontPage as $key => $value ) {
     					$arrTplConfig [$key] = $value;
     				}
     			}
     		}
     		
     		// 解析模板配置项
     		$bolRet = $this->parseTplConfig ( $arrData, $arrTplConfig ); */
     return true;
 }
コード例 #11
0
ファイル: smarty_render.php プロジェクト: drehere/shenmegui
/**
 * 并行渲染
 * @param unknown_type $data
 * @param unknown_type $smarty
 * @param unknown_type uiData中阿拉丁的数据
 * @param unknown_type uiData中普通结果的数据
 */
function multi_render($data, $smarty, $arrAlaData, $arrAsData, $arrMultiRenderConf)
{
    $time_start = Volatile::microtime(true) * 1000;
    require VUI_APP_PATH . '/plugins/modifier.common_render.php';
    $arrNeedRenderSingleResult = array_merge($arrAlaData, $arrAsData);
    $time_multi_start = Volatile::microtime(true) * 1000;
    $mh = curl_multi_init();
    $url = $arrMultiRenderConf['MULTI_RENDER_URL'];
    $arrRenderMultiReq = array();
    $arrMultiPublicData = array();
    $arrMultiPublicData['smarty_conf'] = CSmarty::getConf();
    $arrMultiPublicData['DISPLAY'] = $GLOBALS['DISPLAY'];
    $arrMultiPublicData['LOG'] = $GLOBALS['LOG'];
    $arrMultiPublicData['DEFAULT_TEMPLATE_NAME'] = $GLOBALS['DEFAULT_TEMPLATE_NAME'];
    $arrMultiPublicData['DEFAULT_TEMPLATE_TYPE'] = $GLOBALS['DEFAULT_TEMPLATE_TYPE'];
    $arrMultiPublicData['ALADDIN_TEMPLATE_TYPE'] = $GLOBALS['ALADDIN_TEMPLATE_TYPE'];
    $arrMultiPublicData['STRUCT_TEMPLATE_TYPE'] = $GLOBALS['STRUCT_TEMPLATE_TYPE'];
    $arrMultiPublicData['ECOM_TEMPLATE_TYPE'] = $GLOBALS['ECOM_TEMPLATE_TYPE'];
    $arrMultiPublicData['randTime'] = CSmarty::getRandState();
    $arrMultiPublicData['TplLOG'] = $GLOBALS['TplLOG'];
    $arrMultiPublicData['ALADDIN_FIELD'] = $GLOBALS['ALADDIN_FIELD'];
    $arrMultiPublicData['globalConf'] = $GLOBALS['globalConf'];
    $data['uiData']['multi_public_data'] = $arrMultiPublicData;
    //使用logid来计算存放在共享内存中的key
    $intLogId = CLog::logId();
    $memsize = intval($arrMultiRenderConf['SHMOP']['MEM_SIZE']);
    // 共享内存的大小,单位byte
    $perm = 0666;
    // 共享内存访问权限,参考linux的权限
    $shmid = shmop_open($intLogId, "n", $perm, $memsize);
    // 创建一个共享内存,第二个参数c表示创建
    $shm_bytes_written = shmop_write($shmid, addslashes(serialize($data['uiData'])), 0);
    $arrShmData['id'] = $intLogId;
    $arrShmData['size'] = $shm_bytes_written;
    unset($data['uiData']['multi_public_data']);
    //若向共享内存中存放数据失败,则直接跳出并行渲染,回归正常渲染
    if ($arrShmData['id'] === false || empty($arrShmData['size'])) {
        CLog::warning("put data to shmop fail,back to nomarl render,data_size:" . strlen(addslashes(serialize($data['uiData']))), MULTI_RENDER_FAIL);
        return false;
    }
    $GLOBALS['multi_render_shmid'] = $shmid;
    //主模板加入并发队列
    $strReqKey = 'req_main';
    $arrMainPostData = array();
    $intRandTime = CSmarty::getRandState();
    $arrMainPostData['tempName'] = $data['uiControl']['templateName'];
    $arrMainPostData['tempSwitch'] = $data['uiControl']['templateSwitch'];
    $arrMainPostData['tempVersion'] = empty($data['uiControl']['templateVersion']) ? "" : $data['uiControl']['templateVersion'];
    $arrMainPostData['dataId'] = $arrShmData['id'];
    $arrMainPostData['dataSize'] = $arrShmData['size'];
    $arrMainPostData['randTime'] = $intRandTime;
    $hexQid = $data['uiData']['queryInfo']['queryId'];
    $strMainUrl = $url . '?renderType=' . $strReqKey . '&logId=' . $intLogId . '&qid=' . $hexQid;
    $intMainTplTimeout = intval($arrMultiRenderConf['MAIN_TPL_TIMEOUT_MS']);
    $arrRenderMultiReq[$strReqKey] = curl_init($strMainUrl);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HEADER, 0);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_NOSIGNAL, true);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POST, 1);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HTTPHEADER, array('Expect:'));
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POSTFIELDS, http_build_query($arrMainPostData));
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_TIMEOUT_MS, $intMainTplTimeout);
    curl_multi_add_handle($mh, $arrRenderMultiReq[$strReqKey]);
    //按时间分包(尽可能均分),时间参数来自于进生的模板耗时报表
    //分包数量,主模板单独占用一个包
    $intSplitNum = intval($arrMultiRenderConf['PACK_NUM']) - 1;
    $arrTplTime = array();
    $intTimeCount = 0;
    $arrSplitReqData = array();
    // 分阿拉丁
    if (!empty($arrAlaData) && is_array($arrAlaData)) {
        $intDefaultAladdinTime = $arrMultiRenderConf['DEFAULT_ALADDIN_TIME'];
        $bHhvm = $GLOBALS['globalConf']['FEATURE_LIST']['HHVM_BRANCH']['TURN'] === 'ON' ? true : false;
        if ($bHhvm) {
            $getDict = new GetDict();
            $getDict->init(DATA_PATH . "/shmdict/dict/tpl_time.php");
        }
        foreach ($arrAlaData as $strKey => $arrOneAlaData) {
            if ($bHhvm) {
                //hhvm 临时方案,提前手动分发tpl_time.php文件到data/shmdict/dict/下
                $intOneTplTime = $getDict->getValueFromDict($arrOneAlaData['render_template']);
            } else {
                $intOneTplTime = shmdict_getValueFromDict($arrOneAlaData['render_template'], 'tpl_time');
            }
            $intOneTplTime = empty($intOneTplTime) ? $intDefaultAladdinTime : $intOneTplTime;
            $intTimeCount += $intOneTplTime;
            $arrTplTime[$strKey] = $intOneTplTime;
        }
        arsort($arrTplTime);
        $intSplitTplTime = ceil($intTimeCount / $intSplitNum);
        $arrGroupTime = array();
        $intIndex = 0;
        foreach ($arrTplTime as $strKey => $arrOneTplTime) {
            $intIndex = $intIndex % $intSplitNum;
            $intCount = 0;
            while ($intCount < $intSplitNum) {
                if ($arrGroupTime[$intIndex] >= $intSplitTplTime) {
                    $intIndex = ($intIndex + 1) % $intSplitNum;
                } else {
                    $arrSplitReqData[$intIndex][$strKey] = $arrAlaData[$strKey];
                    $arrGroupTime[$intIndex] += $arrOneTplTime;
                    $intIndex++;
                    break;
                }
                $intCount++;
            }
        }
    }
    // 分AS结果
    if (!empty($arrAsData) && is_array($arrAsData)) {
        $intDefaultAsTime = $arrMultiRenderConf['DEFAULT_AS_TIME'];
        $intAsCount = count($arrAsData);
        $intNewTimeCount = $intTimeCount + $intAsCount * $intDefaultAsTime;
        $intNewSplitTplTime = $intNewTimeCount / $intSplitNum;
        foreach ($arrAsData as $strKey => $arrOneAsData) {
            $intIndex = $intIndex % $intSplitNum;
            $intCount = 0;
            while ($intCount < $intSplitNum) {
                if ($arrGroupTime[$intIndex] >= $intNewSplitTplTime) {
                    $intIndex = ($intIndex + 1) % $intSplitNum;
                } else {
                    $arrSplitReqData[$intIndex][$strKey] = $arrOneAsData;
                    $arrGroupTime[$intIndex] += $intDefaultAsTime;
                    $intIndex++;
                    break;
                }
                $intCount++;
            }
        }
    }
    //将单条结果包加入并行
    if (empty($arrSplitReqData) || !is_array($arrSplitReqData)) {
        CLog::warning("split pack result is empty,back to nomarl render!", MULTI_RENDER_FAIL);
        $bolDelRst = shmop_delete($shmid);
        $bolCloseRst = shmop_close($shmid);
        if ($bolDelRst && $bolCloseRst) {
            unset($GLOBALS['multi_render_shmid']);
        }
        return false;
    }
    foreach ($arrSplitReqData as $intPackIndex => $arrOneSplitReqData) {
        if (!empty($arrOneSplitReqData) && is_array($arrOneSplitReqData)) {
            $strReqKey = 'req_' . $intPackIndex;
            $arrReqPostData = array();
            $arrReqPostData['dataId'] = $arrShmData['id'];
            $arrReqPostData['dataSize'] = $arrShmData['size'];
            $arrReqPostData['randTime'] = $intRandTime;
            $arrReqPostData['dataInfo'] = $arrOneSplitReqData;
            $strReqUrl = $url . '?renderType=' . $strReqKey . '&logId=' . $intLogId . '&qid=' . $hexQid;
            $arrRenderMultiReq[$strReqKey] = curl_init($strReqUrl);
            $intReqNum = count($arrOneSplitReqData);
            $intReqNumLine = intval($arrMultiRenderConf['SINGLE_TIMEOUT_NUM_LINE']);
            $intMoreNumPackTimeout = intval($arrMultiRenderConf['SINGLE_TPL_PACK_MAX_TIMEOUT_MS']);
            $intLessNumPackTimeout = intval($arrMultiRenderConf['SINGLE_TPL_PACK_MIN_TIMEOUT_MS']);
            $intTimeOut = $intReqNum > $intReqNumLine ? $intMoreNumPackTimeout : $intLessNumPackTimeout;
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HEADER, 0);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_NOSIGNAL, true);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POST, 1);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HTTPHEADER, array('Expect:'));
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POSTFIELDS, http_build_query($arrReqPostData));
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_TIMEOUT_MS, $intTimeOut);
            curl_multi_add_handle($mh, $arrRenderMultiReq[$strReqKey]);
        }
    }
    $GLOBALS['logArr']['time_multi_render_ready'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    //执行并行渲染
    $time_exe_start = Volatile::microtime(true) * 1000;
    $mrc = curl_multi_exec($mh, $active);
    if ($mrc == CURLM_CALL_MULTI_PERFORM) {
        CLog::warning("curl_multi connect fail,back to nomarl render!", MULTI_RENDER_FAIL);
        return false;
    }
    $intMaxCurlExeTimes = intval($arrMultiRenderConf['CURL_MAX_EXE_TIMES']);
    $intCurlExeCount = 0;
    while ($active && $mrc == CURLM_OK && $intCurlExeCount < $intMaxCurlExeTimes) {
        $intCurlExeCount++;
        if (curl_multi_select($mh) != -1) {
            $mrc = curl_multi_exec($mh, $active);
            if ($mrc == CURLM_CALL_MULTI_PERFORM) {
                CLog::warning("curl_multi connect fail,back to nomarl render!", MULTI_RENDER_FAIL);
                return false;
            }
        }
    }
    $GLOBALS['logArr']['time_multi_render_exec'] = round(Volatile::microtime(true) * 1000 - $time_exe_start, 2);
    $time_start = Volatile::microtime(true) * 1000;
    //接收数据
    foreach ($arrRenderMultiReq as $key => $value) {
        $arrRenderResult[$key] = curl_multi_getcontent($arrRenderMultiReq[$key]);
        curl_close($arrRenderMultiReq[$key]);
        curl_multi_remove_handle($mh, $arrRenderMultiReq[$key]);
    }
    curl_multi_close($mh);
    $isDebug = $bolPreRenderFeature = $arrMultiRenderConf['DEBUG'] == 'ON' ? true : false;
    $arrRenderedData = array();
    $intChildLastIn = 0;
    $intChildLastOut = 0;
    $intChildFirstIn = 0;
    $intTCount = 1;
    $strAllOneTime = '';
    $arrTplLog = array();
    $arrResultTplTm = array();
    $intTimeRenderStructTpl = 0;
    $intRenderStructTplNum = 0;
    $intTimeAladdinTotal = 0;
    $intRenderAladdinNum = 0;
    $intTimeUrlencryptTotal = 0;
    $arrOtherLog = array();
    foreach ($arrRenderResult as $key => $oneResult) {
        $arrUnseriResult = unserialize($oneResult);
        if (!empty($arrUnseriResult)) {
            $arrLogInfo = $arrUnseriResult['pack_log'];
            unset($arrUnseriResult['pack_log']);
            if (!empty($arrLogInfo) && is_array($arrLogInfo)) {
                $intChildLastIn = $arrLogInfo['start_time'] > $intChildLastIn ? $arrLogInfo['start_time'] : $intChildLastIn;
                if ($key != 'req_main') {
                    $GLOBALS['logArr']['time_pack_' . $intTCount] = round($arrLogInfo['end_time'] - $arrLogInfo['start_time'], 2);
                    $intTCount++;
                } else {
                    $GLOBALS['logArr']['time_render_main_tpl'] = $arrLogInfo['time_main_tpl'];
                    $GLOBALS['logArr']['time_pack_main'] = round($arrLogInfo['end_time'] - $arrLogInfo['start_time'], 2);
                }
                $arrTplLog = empty($arrTplLog) ? $arrLogInfo['tpl_log'] : array_merge($arrTplLog, $arrLogInfo['tpl_log']);
                $arrResultTplTm = empty($arrResultTplTm) ? $arrLogInfo['result_tpl_tm'] : array_merge($arrResultTplTm, $arrLogInfo['result_tpl_tm']);
                $intTimeRenderStructTpl += $arrLogInfo['time_render_struct_tpl'];
                $intRenderStructTplNum += $arrLogInfo['render_struct_tpl_num'];
                $intTimeAladdinTotal += $arrLogInfo['time_aladdin_total'];
                $intRenderAladdinNum += $arrLogInfo['render_aladdin_num'];
                $intTimeUrlencryptTotal += $arrLogInfo['time_urlencrypt_total'];
                if (!empty($arrLogInfo['logArr'])) {
                    $arrOtherLog = array_merge($arrOtherLog, $arrLogInfo['logArr']);
                }
                // debug,更为详细的日志信息
                if ($isDebug) {
                    if ($intChildFirstIn == 0) {
                        $intChildFirstIn = $arrLogInfo['start_time'];
                    } else {
                        $intChildFirstIn = $arrLogInfo['start_time'] < $intChildFirstIn ? $arrLogInfo['start_time'] : $intChildFirstIn;
                    }
                    $intChildLastOut = $arrLogInfo['end_time'] > $intChildLastOut ? $arrLogInfo['end_time'] : $intChildLastOut;
                    foreach ($arrLogInfo['one_time'] as $key => $intOneTime) {
                        $strAllOneTime .= $key . ':' . $intOneTime . '|';
                    }
                }
            }
            $arrRenderedData = array_merge($arrRenderedData, $arrUnseriResult);
        } else {
            CLog::warning("whole pack render fail!pack name:" . $key, MULTI_RENDER_FAIL);
        }
    }
    $GLOBALS['logArr'] = array_merge($GLOBALS['logArr'], $arrOtherLog);
    $GLOBALS['logArr']['time_multi_render_web'] = round($intChildLastIn - $time_exe_start, 2);
    $GLOBALS['logArr']['time_multi_render_recdata'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    CSmarty::addStructTplRenderNumCount($intRenderStructTplNum);
    CSmarty::addStructTplRenderTimeCount($intTimeRenderStructTpl);
    $GLOBALS['time_count_temp']['time_aladdin_total'] += $intTimeAladdinTotal;
    $GLOBALS['time_count_temp']['render_aladdin_num'] += $intRenderAladdinNum;
    $GLOBALS['time_count_temp']['time_urlencrypt_total'] += $intTimeUrlencryptTotal;
    if (!empty($arrResultTplTm) && is_array($arrResultTplTm)) {
        foreach ($arrResultTplTm as $intOneTplTm) {
            CSmarty::recordResultTplRenderTime($intOneTplTm);
        }
    }
    if (!empty($arrTplLog) && is_array($arrTplLog)) {
        $objTplLog = TplLog::getInstance();
        $objTplLog->setTplData($arrTplLog);
    }
    if ($isDebug) {
        $GLOBALS['logArr']['time_one_detail_time'] = $strAllOneTime;
        $GLOBALS['logArr']['time_web_curl'] = round($intChildFirstIn - $time_exe_start, 2);
        $GLOBALS['logArr']['time_multi_recdata'] = round(Volatile::microtime(true) * 1000 - $intChildLastOut, 2);
        $GLOBALS['logArr']['time_child_max'] = round($intChildLastOut - $intChildFirstIn, 2);
    }
    $time_start = Volatile::microtime(true) * 1000;
    $bolDelRst = shmop_delete($shmid);
    shmop_close($shmid);
    if (!$bolDelRst) {
        CLog::warning("clean shmop fail!id:" . $shmid, MULTI_RENDER_FAIL);
    } else {
        unset($GLOBALS['multi_render_shmid']);
    }
    //主模板并行渲染未成功
    if ($arrRenderedData['req_main']['status'] !== 0) {
        CLog::warning("multi render main tpl fail,try local render once!", MULTI_RENDER_FAIL);
        $GLOBALS['mulit_render_flag'] = 1;
        $page = $smarty->do_render($data['uiData'], $data['uiControl']['templateName'], $data['uiControl']['templateSwitch'], $data['uiControl']['templateVersion']);
        if (empty($page)) {
            CLog::warning("local render main tpl fail too,abandon treatment,back to nomarl render", MULTI_RENDER_FAIL);
            return false;
        }
    } else {
        $page = $arrRenderedData['req_main']['content'];
    }
    unset($arrRenderedData['req_main']);
    $arrReplaceKeys = array();
    $arrReplaceValues = array();
    $intFailNum = 0;
    $strFailKeys = '';
    foreach ($arrRenderedData as $strKey => $strRenderContent) {
        //单条模板未渲染成功
        if ($strRenderContent['status'] !== 0) {
            //CLog::warning("multi render single tpl fail,try local render once!key:" . $strKey, MULTI_RENDER_FAIL);
            $intFailNum++;
            $strFailKeys = empty($strFailKeys) ? $strKey : $strFailKeys . '#' . $strKey;
            $strRenderContent['content'] = render_single_result($strKey, $arrNeedRenderSingleResult, $data);
        }
        if (empty($strRenderContent['content'])) {
            CLog::warning("local render single tpl fail too,abandon treatment,remove this single result!key:" . $strKey, MULTI_RENDER_FAIL);
        }
        $arrReplaceKeys[] = $strKey;
        $arrReplaceValues[] = empty($strRenderContent['content']) ? '' : $strRenderContent['content'];
        unset($arrNeedRenderSingleResult[$strKey]);
    }
    if (!empty($arrNeedRenderSingleResult)) {
        foreach ($arrNeedRenderSingleResult as $strKey => $arrContent) {
            //CLog::warning("multi render single tpl fail,try local render once!key:" . $strKey, MULTI_RENDER_FAIL);
            $intFailNum++;
            $strFailKeys = empty($strFailKeys) ? $strKey : $strFailKeys . '#' . $strKey;
            $rst = render_single_result($strKey, $arrNeedRenderSingleResult, $data);
            if (empty($rst)) {
                CLog::warning("local render single tpl fail too,abandon treatment,remove this single result!key:" . $strKey, MULTI_RENDER_FAIL);
            }
            $arrReplaceKeys[] = $strKey;
            $arrReplaceValues[] = empty($rst) ? '' : $rst;
        }
    }
    if ($intFailNum != 0) {
        CLog::warning("local render single tpl, num[{$intFailNum}] keys[{$strFailKeys}]", MULTI_RENDER_FAIL);
    }
    $GLOBALS['logArr']['time_multi_render_retry'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    $time_start = Volatile::microtime(true) * 1000;
    $page = Util::replace($page, $arrReplaceKeys, $arrReplaceValues, 0);
    $GLOBALS['logArr']['time_multi_render_repdata'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    return $page;
}
コード例 #12
0
/**
 *
 *
 * @file modifier.real.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_modifier_aladdin_render($data, $templateName, $curr_sort = false)
{
    $time_start = Volatile::microtime(true) * 1000;
    $logArr['smarty_modifier'] = "modifier_aladdin_render";
    /**
     * render config
     */
    $conf = CSmarty::getConf();
    /**
     * template type
     * @var string 
     */
    $type = VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE;
    $language = $conf['language'];
    $platform = $conf['platform'];
    $logArr['template_type'] = $type;
    $logArr['template_name'] = $templateName;
    $logArr['language'] = $language;
    $logArr['platform'] = $platform;
    $log_key = $data['StdStg'] . '_' . $templateName;
    /**
     * template type cannot be empty
     */
    if (strlen($type) == 0) {
        CLog::warning("template type is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * template name cannot be empty
     */
    if (empty($templateName)) {
        CLog::warning("template name is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * aladdin's tplData 
     */
    if (empty($data['resultData']['tplData']) || !is_array($data['resultData']['tplData'])) {
        CLog::warning("tplData is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * set queryInfo
     */
    $data['resultData']['queryInfo'] = CSmarty::getQueryInfo();
    /**
     * set templateConfig
     */
    $data['resultData']['templateConfig'] = CSmarty::getTemplateConfig();
    /**
     * set result current sort of result page
     */
    if ($curr_sort === false) {
        $curr_sort = 0;
    } else {
        $curr_sort += 1;
    }
    $data['resultData']['extData']['curr_sort'] = $curr_sort;
    /**
     * page renderer 
     * @var Smarty
     */
    $smarty = CSmarty::getInstance(array('language' => $language, 'type' => $type, 'platform' => $platform));
    if (false === $smarty) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        $logArr['ala_smarty_error'] = $errors_str;
        CLog::warning("fail to get instance of smarty, type: {$type}", $status, $logArr, 1);
        return false;
    }
    /**
     * encrypt page's url
     */
    backend_encrypt_url($data, $platform, $language, $type, $templateName);
    /**
     * render aladdin's page
     */
    $page = $smarty->do_render($data, $templateName, 1);
    if ($page === false) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        CLog::warning("fail to render aladdin's page, errors[{$errors_str}]", $status, $logArr, 1);
        return false;
    }
    if (strlen($page) == 0) {
        $status = -1;
        CLog::warning("aladdin's page is empty", $status, $logArr, 1);
        return false;
    }
    $GLOBALS['logArr']["aladdin_page_size_{$log_key}"] = strlen($page);
    $GLOBALS['logArr']["time_aladdin_{$log_key}"] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    return $page;
}
コード例 #13
0
ファイル: base.php プロジェクト: drehere/shenmegui
function backend_encrypt_url(&$data, $platform, $language, $type, $templateName)
{
    /**
     * encrypt page's url
     */
    $URLEncryption = CSmarty::getURLEncryption();
    if (1 === intval($URLEncryption)) {
        $time_encrypt_start = Volatile::microtime(true) * 1000;
        /**
         * encrypt page url
         */
        $conf = load_tpl_conf($platform, $language, $type, $templateName);
        /**
         * url encrypt or not
         */
        if (1 === intval($conf['is_urlencrypt'])) {
            foreach ($conf['enc'] as $key => $value) {
                process_aladdin_data($data, $value);
            }
        }
        $log_key = 'time_urlencrypt_' . $templateName;
        $GLOBALS['logArr'][$log_key] = round(Volatile::microtime(true) * 1000 - $time_encrypt_start, 2);
        $GLOBALS['time_count_temp']['time_urlencrypt_total'] += $GLOBALS['logArr'][$log_key];
    }
}
コード例 #14
0
 public function checkTemplateConfig(&$arrData)
 {
     require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
     if (!isset($arrTplTypes)) {
         CLog::warning("tpl param select is wrong, require tpl type err!");
         return false;
     }
     $arrQueryInfo =& $arrData['uiData']['queryInfo'];
     $arrControlInfo =& $arrData['uiControl'];
     $arrUrlConfig = $arrQueryInfo['pUrlConfig'];
     $strType = $arrTplTypes[$arrControlInfo['templateName']]['type'];
     $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
     // 平台检查
     if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
         CLog::warning("tpl param select is not matching");
         return false;
     }
     //dsp参数处理
     if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
         if (empty($arrData['uiData']['queryInfo']['dspName'])) {
             $arrData['uiData']['queryInfo']['dspName'] = "ipad";
             CLog::warning("dspName is not ipad when using pad template.");
         }
     }
     $strTplPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $arrControlInfo['templateName'];
     if (!file_exists($strTplPath)) {
         return false;
     }
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
     if (!file_exists($strTplConfigPath)) {
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strType . '.cfg.php';
     }
     if (!file_exists($strTplConfigPath)) {
         CLog::warning("tpl cfg is not existed, tplname : " . $strTplName);
         return false;
     }
     $arrData['uiControl']['tplSamplingPath'] = $strTplConfigPath;
     $arrControlInfo['templateType'] = $strType;
     return true;
 }
コード例 #15
0
ファイル: modifier.render.php プロジェクト: drehere/shenmegui
/**
 *
 *
 * @file modifier.render.php
 * @package plugins
 * @author fengfei02@baidu.com
 * @date 2012-10-29 10:47
 */
function smarty_modifier_render($data, $templateName, $curr_sort = false)
{
    $logArr['smarty_modifier'] = "modifier_render";
    /**
     * render config
     */
    $conf = CSmarty::getConf();
    /**
     * template type
     * @var string 
     */
    $type = $GLOBALS['STRUCT_TEMPLATE_TYPE'];
    $language = $conf['language'];
    $platform = $conf['platform'];
    $logArr['template_name'] = $templateName;
    $logArr['template_type'] = $type;
    $logArr['language'] = $language;
    $logArr['platform'] = $platform;
    /**
     * template type cannot be empty
     * 
     * 模板是否修改类型的目录?
     * 
     */
    if (strlen($type) == 0) {
        CLog::warning("template type is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * template name cannot be empty
     */
    if (empty($templateName)) {
        CLog::warning("template name is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * ac's data 
     */
    if (empty($data) || !is_array($data) || empty($data['resultData'])) {
        CLog::warning("data or resultData is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * set queryInfo,这个字段在baidu的global变量和函数有用,迁移时有用
     */
    $data['resultData']['queryInfo'] = CSmarty::getQueryInfo();
    /**
     * set templateConfig,同queryInfo
     */
    $data['resultData']['templateConfig'] = CSmarty::getTemplateConfig();
    /**
     * set result current sort of result page,同queryInfo
     */
    if ($curr_sort === false) {
        $curr_sort = 0;
    } else {
        $curr_sort += 1;
    }
    $data['resultData']['extData']['curr_sort'] = $curr_sort;
    /**
     * page renderer 
     * @var Smarty
     */
    $smarty = CSmarty::getInstance(array('language' => $language, 'type' => $type, 'platform' => $platform));
    if (false === $smarty) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        $logArr['ac_smarty_error'] = $errors_str;
        CLog::warning("fail to get instance of smarty, type: {$type}", $status, $logArr, 1);
        return false;
    }
    /**
     * render ac's page
     */
    $page = $smarty->do_render($data, $templateName, 1);
    if ($page === false) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        //CLog::warning("fail to render ac's page, errors[$errors_str]", $status, $logArr, 1);
        CLog::warning("fail to render ac's page", $status, $logArr, 1);
        return false;
    }
    if (strlen($page) == 0) {
        $status = -1;
        CLog::warning("ac's page is empty", $status, $logArr, 1);
        return false;
    }
    return $page;
}
コード例 #16
0
/**
 * 通用的单条渲染插件,可渲染aladdin、result、ecom等目录下;
 * 不能渲染midpage、xml、data和baidu下的完整页面模板
 *
 * @package plugins
 * @author jiachunxin@baidu.com
 */
function smarty_modifier_common_render($data, $type, $templateName, $curr_sort = false)
{
    if ($GLOBALS['mulit_render_flag'] === 1) {
        $key = $data['multi_render_key'];
        if (empty($key)) {
            CLog::warning("empty_key!", 1);
        }
        return $key;
    }
    $logArr['smarty_modifier'] = "common_render";
    $conf = CSmarty::getConf();
    $language = $conf['language'];
    $platform = $conf['platform'];
    $logArr['template_type'] = $type;
    $logArr['template_name'] = $templateName;
    $logArr['language'] = $language;
    $logArr['platform'] = $platform;
    $logArr['StdStg'] = $data['StdStg'];
    // result目录下的模板不统计性能
    $time_start = Volatile::microtime(true) * 1000;
    if ($type != $GLOBALS['STRUCT_TEMPLATE_TYPE']) {
        $log_key = $data['StdStg'] . '_' . $templateName;
    } else {
        CSmarty::addStructTplRenderNumCount();
    }
    if (empty($type)) {
        CLog::warning("template type is empty", -1, $logArr, 1);
        return false;
    }
    if (empty($templateName)) {
        CLog::warning("template name is empty", -1, $logArr, 1);
        return false;
    }
    if (empty($data['resultData']['tplData']) || !is_array($data['resultData']['tplData'])) {
        CLog::warning("tplData is empty", -1, $logArr, 1);
        return false;
    }
    $data['resultData']['queryInfo'] = CSmarty::getQueryInfo();
    $data['resultData']['templateConfig'] = CSmarty::getTemplateConfig();
    if ($curr_sort === false) {
        $curr_sort = 0;
    } else {
        $curr_sort += 1;
    }
    $data['resultData']['extData']['curr_sort'] = $curr_sort;
    // page renderer
    $smarty = CSmarty::getInstance(array('language' => $language, 'type' => $type, 'platform' => $platform));
    if (false === $smarty) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        $logArr[$type . '_smarty_error'] = $errors_str;
        CLog::warning("fail to get instance of smarty, type: {$type}", $status, $logArr, 1);
        return false;
    }
    // encrypt page's url
    backend_encrypt_url($data, $platform, $language, $type, $templateName);
    // render page
    $page = $smarty->do_render($data, $templateName, 1);
    if (empty($page)) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        CLog::warning("fail to render " . $type . " page, errors[{$errors_str}],info[{$log_key}]", $status, $logArr, 1);
        return false;
    }
    $tm_cost = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    // result目录下的模板不统计性能
    if ($type != $GLOBALS['STRUCT_TEMPLATE_TYPE']) {
        $GLOBALS['logArr']["aladdin_page_size_{$log_key}"] = strlen($page);
        $GLOBALS['logArr']["time_aladdin_{$log_key}"] = $tm_cost;
        $GLOBALS['time_count_temp']['time_aladdin_total'] += $tm_cost;
        $GLOBALS['time_count_temp']['render_aladdin_num']++;
    } else {
        CSmarty::addStructTplRenderTimeCount($tm_cost);
        // result模板也统计性能,合并打印
        CSmarty::recordResultTplRenderTime($tm_cost);
    }
    return $page;
}
コード例 #17
0
 /**
  * 构造
  */
 public function __construct($viewName)
 {
     $this->_viewName = $viewName;
     $viewConfigs = CConfig::getInstance()->load('TEMPLATE');
     if (!isset($viewConfigs[$viewName])) {
         trigger_error('[视图错误]使用配置中不存在的模板引擎:' . $viewName, E_USER_ERROR);
     }
     $thisViewConfig = $viewConfigs[$viewName];
     $templatePath = isset($thisViewConfig['TEMPLATE_PATH']) ? $thisViewConfig['TEMPLATE_PATH'] : '';
     $viewConfItem = isset($thisViewConfig['CONF_INFO']) ? $thisViewConfig['CONF_INFO'] : array();
     if (!file_exists($templatePath)) {
         trigger_error('[视图错误]未能找到指定模板引擎[' . $viewName . ']的主文件:' . $templatePath, E_USER_ERROR);
     }
     CLoader::importFile($templatePath);
     $viewObject = new $viewName();
     if ('smarty' == $viewName) {
         $viewObject->template_dir = $viewConfItem['template_dir'];
         //编译目录
         $compile_dir = $viewConfItem['compile_dir'];
         if (!is_dir($compile_dir)) {
             if (false == mkdir($compile_dir, true, 0755)) {
                 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]CMyFrame无法创建缓存目录,请确定服务器权限';
                 exit;
             }
             chmod($compile_dir, 0777);
         }
         $viewObject->compile_dir = $compile_dir;
         //缓存目录
         $cache_dir = $viewConfItem['cache_dir'];
         if (!is_dir($cache_dir)) {
             if (false == mkdir($cache_dir, true, 0755)) {
                 echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]CMyFrame无法创建缓存目录,请确定服务器权限';
                 exit;
             }
             chmod($cache_dir, 0777);
         }
         $viewObject->cache_dir = $cache_dir;
         //分隔符
         $viewObject->left_delimiter = $viewConfItem['left_delimiter'];
         $viewObject->right_delimiter = $viewConfItem['right_delimiter'];
         //使用PHP语法
         $viewObject->allow_php_tag = $viewConfItem['allow_php_tag'];
         //缓冲
         $viewObject->caching = $viewConfItem['caching'];
         $viewObject->cache_lifetime = $viewConfItem['cache_lifetime'];
         //注册函数
         $viewObject->register_function('url', array('CRequest', 'createUrl'));
         $viewObject->register_function('PageInfo', array('CSmarty', 'showPageData'));
         $viewObject->register_function('substr', array('CSmarty', 'cn_substr'));
         $viewObject->register_function('sayTime', array('CSmarty', 'sayTime'));
         //注册块函数
         $viewObject->register_block('checkRight', array('CSmarty', 'checkRight'));
         //设置默认数据
         CSmarty::setInitData($viewObject);
     } else {
         //设置所有配置项
         foreach ((array) $viewConfItem as $key => $val) {
             $viewObject->{$key} = $val;
         }
     }
     //第一次获取视图时
     CHooks::callHooks(HOOKS_VIEW_GET, $viewObject);
     $this->_viewObject = $viewObject;
 }
コード例 #18
0
ファイル: ItemTplSelector.php プロジェクト: drehere/shenmegui
 public function run(&$arrData, $arrConf)
 {
     if (empty($arrData) || !is_array($arrData)) {
         return false;
     }
     $arrInfos = array();
     $arrInfos['sampleId'] = $arrData['uiData']['queryInfo']['samplingId'];
     $arrInfos['tn'] = $arrData['uiData']['queryInfo']['accountName'];
     $smartyConf = CSmarty::getConf();
     $arrInfos['language'] = $smartyConf['language'];
     $arrInfos['platform'] = $smartyConf['platform'];
     $arrTplConfs = Util::getConf('/tpl', 'ITEM_TEMPLATE');
     //add by chenchen , @purpose:new_mappingData
     $bolMappingDataConf = Util::getConf('/feature', 'FEATURE_LIST/NEW_MAPPINGDATA/TURN') !== 'ON' ? 0 : 1;
     //加载开关配置
     //$strTemplatePath = VUI_TEMPLATE_PATH . "/view/" . $arrData['uiControl']['platform'] . "/" . $arrData['uiControl']['language'] . "/page" ;
     $arrQueryInfo = $arrData['uiData']['queryInfo'];
     $start_time = Volatile::microtime(true) * 1000;
     //计时,当新的数据映射功能加载时间大于1ms时,考虑下掉
     foreach ($GLOBALS['RESULT'] as $res) {
         if (!empty($arrData['uiData'][$res]['item']) && is_array($arrData['uiData'][$res]['item'])) {
             $arrInfos['result'] = $res;
             $intPosition = 0;
             foreach ($arrData['uiData'][$res]['item'] as $index => &$item) {
                 $intPosition++;
                 $arrInfos['position'] = $intPosition;
                 $intSrcId = isset($item['dispData']['StdStg_new']) ? $item['dispData']['StdStg_new'] : $item['dispData']['StdStg'];
                 $intStdStl = $item['dispData']['StdStl'];
                 $tplConfs = $arrTplConfs['SRCID_' . $intSrcId]['GROUP'];
                 if (empty($tplConfs) || !is_array($tplConfs)) {
                     continue;
                 }
                 foreach ($tplConfs as $tplConf) {
                     $bolSelectItemTpl = $this->selectItemTpl($arrInfos, $item, $tplConf);
                     if ($bolSelectItemTpl === false) {
                         continue;
                     }
                     $item['dispData']['strategy']['tempName_ori'] = $item['dispData']['strategy']['tempName'];
                     $item['dispData']['strategy']['tempName'] = $tplConf['tpl'];
                     $item['dispData']['strategy']['type'] = $tplConf['type'];
                     $item['dispData']['strategy']['mapping'] = $tplConf['mapping'];
                     break;
                 }
                 $bolDisplayWrong = $this->resultDisplayWrong($item['dispData']['strategy']['tempName'], $res);
                 if ($bolDisplayWrong === false) {
                     CLog::warning('Result display template error, result:' . $res . ',template:' . $item['dispData']['strategy']['tempName'] . ',srcID:' . $intSrcId);
                     unset($arrData['uiData'][$res]['item'][$index]);
                     continue;
                 }
                 if ($bolMappingDataConf) {
                     $this->newMappingData($item, $arrQueryInfo, $intSrcId);
                 }
                 //add by songlei 知心卡片打印展现日志
                 if (!empty($item['card_id'])) {
                     $item['dispData']['card_id'] = $item['card_id'];
                     $item['dispData']['category_id'] = $item['category_id'];
                     $item['dispData']['uri'] = urlencode($item['uri']);
                     $item['dispData']['disp_level'] = $item['disp_level'];
                     $item['dispData']['entityname'] = urlencode($item['entityname']);
                 }
                 //if empty
             }
             unset($item);
         }
     }
     $GLOBALS['logArr']['time_tpl_mappingdata'] = round(Volatile::microtime(true) * 1000 - $start_time, 2);
     return true;
 }
コード例 #19
0
 /**
  * @param unknown_type $arrData
  * @return boolean
  */
 public function get_sampling_template(&$arrData)
 {
     if ($arrData['uiControl']['templateSwitch'] == 2) {
         $arrTplSample = Util::getConf('/sample_variable', 'sample_variable/FRONT_PAGE_INDEX');
     } else {
         $arrTplSample = Util::getConf('/sample_variable', 'sample_variable/RESULT_PAGE_INDEX');
     }
     if (!is_array($arrTplSample) || empty($arrTplSample)) {
         //CLog::warning ( "tpl sampling conf is null" );
         return false;
     }
     $arrSids = $arrData['uiData']['queryInfo']['samplingId'];
     $arrSids = array_flip($arrSids);
     $strTplName = "";
     foreach ($arrTplSample['Contexted'] as $arrTemp) {
         if (isset($arrSids[$arrTemp['sampling_id']])) {
             $strTplName = $arrTemp['value'];
             break;
         }
     }
     if (!empty($strTplName)) {
         //$arrTplTypes = Util::getConf ( '/tpl_type', 'TEMPLATE_TYPE' );
         require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
         if (!isset($arrTplTypes)) {
             CLog::warning("tpl sampling is wrong, require tpl type err!");
             return false;
         }
         $arrControlInfo =& $arrData['uiControl'];
         // 模板类型
         $arrPlatForm = array();
         $strType = "";
         if (isset($arrTplTypes[$strTplName])) {
             $strType = $arrTplTypes[$strTplName]['type'];
             $arrPlatForm = $arrTplTypes[$strTplName]['platform'];
         } else {
             CLog::warning("tpl sampling is wrong, tpl type not existed!");
             return false;
             //	$strType = trim ( $GLOBALS ['DEFAULT_TEMPLATE_TYPE'] );
             //	$arrPlatForm [] = trim ( $GLOBALS ['DEFAULT_PLATFORM'] );
         }
         // 平台检查
         if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
             CLog::warning("tpl platform is not matching");
             return false;
         }
         //dsp参数处理
         if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
             if (empty($arrData['uiData']['queryInfo']['dspName'])) {
                 $arrData['uiData']['queryInfo']['dspName'] = "ipad";
                 CLog::warning("dspName is not ipad when using pad template.");
             }
         }
         // 检查模板配置
         $bolFlag = false;
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strTplName . '/' . $strTplName . '.cfg.php';
         if (file_exists($strTplConfigPath)) {
             $bolFlag = true;
         } else {
             $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strType . '.cfg.php';
             if (file_exists($strTplConfigPath)) {
                 $bolFlag = true;
             } else {
                 CLog::warning("tpl cfg is not existed, tplname : " . $strTplName);
                 return false;
             }
         }
         if ($bolFlag === true) {
             //补充
             /* $objTemplateSelector = new TemplateSelector ();
             			$arrTplConfig = $objTemplateSelector->getTplConfig ( $strTplConfigPath );
             			if (! is_array ( $arrTplConfig ) || empty ( $arrTplConfig ) || count ( $arrTplConfig ) <= 0) {
             				// log
             				CLog::warning ( "tpl sampling is wrong, getting cfg err!" );
             				return false;
             			}
             			
             			// 处理首页模板
             			if ($arrData ['uiControl'] ['templateSwitch'] == 2) {
             				$arrFrontPage = Util::getConf ( '/frontpage', 'FRONTPAGE/LOGO' );
             				if (! empty ( $arrFrontPage ) && is_array ( $arrFrontPage )) {
             					foreach ( $arrFrontPage as $key => $value ) {
             						$arrTplConfig [$key] = $value;
             					}
             				}
             			} */
             $arrData['uiControl']['tplSamplingPath'] = $strTplConfigPath;
             $arrControlInfo['templateName'] = $strTplName;
             $arrControlInfo['templateType'] = $strType;
             return true;
             // 解析模板配置项
             //	$bolRet = $objTemplateSelector->parseTplConfig ( $arrData, $arrTplConfig );
             //	CLog::debug ( "tpl sampling tplname : " . $strTplName );
             //	return $bolRet;
         }
     }
     return false;
 }
コード例 #20
0
ファイル: ImageBase64.php プロジェクト: drehere/shenmegui
 public function load_image_tpl_conf($platform, $language, $type, $templateName)
 {
     /**
      * load config
      */
     $tplConfPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $platform, $language, $type);
     /**
      * not tend to encrypt url
      */
     if (!file_exists("{$tplConfPath}/{$templateName}/tpl.conf")) {
         return false;
     }
     if (filesize("{$tplConfPath}/{$templateName}/tpl.conf") == 0) {
         return false;
     }
     /**
      * load configure file
      *
      * 这种方式不合理,考虑优化为require php文件数组方式。
      */
     $conf = TplConf::config_load("{$tplConfPath}/{$templateName}", "tpl.conf");
     /**
      * load configure file failed
      */
     if (false === $conf) {
         /**
          * default log config
          */
         $status = $GLOBALS['STATUS_CODE']['LOAD_TPLCONF_FAIL'];
         $logArr['platform'] = $platform;
         $logArr['language'] = $language;
         $logArr['type'] = $type;
         $logArr['templateName'] = $templateName;
         CLog::warning($GLOBALS['STATUS_MSG'][$status] . ", load tpl config fail", $status, $logArr, 1);
         return false;
     }
     $arrImgConf = array();
     foreach ($conf['img'] as $key => $value) {
         $temp_path = array();
         $path_array = explode('[]', $value);
         foreach ($path_array as $path) {
             $new_path = array();
             $path_item = explode('.', $path);
             foreach ($path_item as $item) {
                 $item = trim($item);
                 if (!empty($item)) {
                     $new_path[] = $item;
                 }
             }
             if (!empty($new_path)) {
                 $temp_path[] = implode('.', $new_path);
             }
         }
         if (!empty($temp_path)) {
             $arrImgConf[] = $temp_path;
         }
     }
     $conf['img'] = $arrImgConf;
     return $conf;
 }
コード例 #21
0
ファイル: CSmarty.class.php プロジェクト: drehere/shenmegui
 /**
  * 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;
 }
コード例 #22
0
/**
 *
 *
 * @file modifier.highlight.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:55
 * 
 * ======================================插件说明=====================================
 * 
 * 标题飘红
 * type=0:gss aladdin,修改type=3,在调用扩展时,会转成3
 * type=1:UI自己实现的匹配飘红
 * type=2:根据DX的标记替换飘红
 * type=3:使用DA返回的飘红词调用飘红库飘红
 * type=4:使用AC返回的飘红词调用飘红库飘红
 * 
 * 摘要飘红
 * type=5:UI自己实现的匹配飘红,在调用扩展时,会转成1
 * type=6:根据DX的标记替换飘红,在调用扩展时,会转成2
 * 
 * ======================================飘红库说明=====================================
 * Hilight_title:
 * 1、UI自己实现的匹配飘红;
 * 2、根据DX的标记替换飘红;
 * 3、使用DA返回的飘红词调用飘红库飘红;
 * 4、使用AC返回的飘红词调用飘红库飘红;
 * Hilight_abstract:
 * 1、UI自己实现的匹配飘红;
 * 2、根据DX的标记替换飘红;
 * 
 */
function smarty_modifier_highlight($string, $type = 0)
{
    // BY pengxing
    // 忽略highlight插件的效果
    return $string;
    $time_start = Volatile::microtime(true) * 1000;
    $logArr['smarty_modifier'] = "modifier_highlight";
    /**
     * hilight info
     * @var array
     */
    $hilight_info = CSmarty::getHilightInfo();
    $hilight_info['hiFixInfo']['bold_prefix'] = $GLOBALS['DISPLAY']['BOLD_PREFIX'];
    $hilight_info['hiFixInfo']['bold_postfix'] = $GLOBALS['DISPLAY']['BOLD_SUFFIX'];
    $logArr['text'] = $string;
    $logArr['type'] = $type;
    $result = false;
    $hilight_query_info = array();
    $queryInfo = CSmarty::getQueryInfo();
    $language = trim(strtolower($queryInfo['language']));
    $tempArray = explode('-', $language);
    if (strlen($queryInfo['language']) != 0) {
        if ($language == 'zh-cn' || $language == 'zh-tw') {
            $hilight_query_info['query_language'] = $language;
        } else {
            if (count($tempArray) == 2) {
                $hilight_query_info['query_language'] = $tempArray[0];
            } else {
                $hilight_query_info['query_language'] = 'zh-cn';
            }
        }
    } else {
        $hilight_query_info['query_language'] = 'zh-cn';
    }
    $hilight_query_info['query_codetype'] = empty($queryInfo['outputEncode']) ? "utf-8" : (string) $queryInfo['outputEncode'];
    $hilight_query_info['user_locale'] = empty($tempArray[1]) ? "cn" : $tempArray[1];
    switch ($type) {
        case 0:
            //hilight for aladdin's page
            $hi_word = CSmarty::getHiWord();
            if (strlen($hi_word) > 0) {
                $hilight_info['hilightInfo']['ori_hilight'] = $hi_word;
            }
            $type = 3;
        case 1:
        case 2:
        case 3:
        case 4:
            /**
             * hilight title
             */
            $logArr['hilight_type'] = 'title';
            //error_log("hiFixInfo=".var_export($hilight_info['hiFixInfo'],true)."\n", 3, '/home/work/talk.log');
            //error_log("hilightInfo=".var_export($hilight_info['hilightInfo'],true)."\n", 3, '/home/work/talk.log');
            //error_log("dynamicConfig=".var_export($hilight_info['dynamicConfig'],true)."\n", 3, '/home/work/talk.log');
            //$result = hilight_title($string, $hilight_info['hiFixInfo'],$hilight_info['hilightInfo'], $hilight_info['dynamicConfig'], $type);
            $result = hilight_title_ver2($string, $hilight_info['hiFixInfo'], $hilight_info['hilightInfo'], $hilight_info['dynamicConfig'], $type, $hilight_query_info);
            break;
        case 5:
        case 6:
            /**
             * hilight abstract
             */
            $type = $type - 4;
            $logArr['hilight_type'] = 'abstract';
            $logArr['type'] = $type;
            //$result = hilight_abstract($string, $hilight_info['hiFixInfo'],$hilight_info['hilightInfo'], $hilight_info['dynamicConfig'], $type);
            $result = hilight_abstract_ver2($string, $hilight_info['hiFixInfo'], $hilight_info['hilightInfo'], $hilight_info['dynamicConfig'], $type, $hilight_query_info);
            break;
        default:
            $type = 2;
            $logArr['type'] = $type;
            $logArr['hilight_type'] = 'title';
            //$result = hilight_title($string, $hilight_info['hiFixInfo'],$hilight_info['hilightInfo'], $hilight_info['dynamicConfig'], $type);
            $result = hilight_title_ver2($string, $hilight_info['hiFixInfo'], $hilight_info['hilightInfo'], $hilight_info['dynamicConfig'], $type, $hilight_query_info);
            break;
    }
    if (false === $result) {
        CLog::warning("fail to hilight", 0, $logArr, 1);
        return $string;
    }
    $GLOBALS['logArr']['time_highlight'] += round(Volatile::microtime(true) * 1000 - $time_start, 2);
    return $result;
}