/**
 * @file function.import_usetime_js.php
 * @author search(com@baidu.com)
 * @date 2014/01/16 15:16:03
 * @brief 
 *  
 **/
function smarty_function_import_usetime_js($params, $template)
{
    $tplData = $template->getTemplateVars("tplData");
    if (!empty($tplData['queryInfo']['viewConfig']['start_time']) && isset($tplData['queryInfo']['viewConfig']['start_time'])) {
        $start_time = $tplData['queryInfo']['viewConfig']['start_time'];
        $nginxUseTime = 15;
        // nginx消耗时间
        $timeUse = round(Volatile::microtime(true) * 1000 - $start_time, 2) + $nginxUseTime;
        return '<script type="text/javascript">_WWW_SRV_T =' . $timeUse . ';</script>';
    } else {
        return '';
    }
}
Ejemplo n.º 2
0
 /**
  * Class constructor, initializes basic smarty properties
  */
 public function __construct()
 {
     // selfpointer need by some other class methods
     $this->smarty = $this;
     if (is_callable('mb_internal_encoding')) {
         mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET);
     }
     $this->start_time = Volatile::microtime(true);
     // set default dirs
     $this->template_dir = array('.' . DS . 'templates' . DS);
     $this->compile_dir = '.' . DS . 'templates_c' . DS;
     $this->plugins_dir = array(SMARTY_PLUGINS_DIR);
     $this->cache_dir = '.' . DS . 'cache' . DS;
     $this->config_dir = '.' . DS . 'configs' . DS;
     $this->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl';
     if (isset($_SERVER['SCRIPT_NAME'])) {
         $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
     }
 }
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/**
 * 并行渲染
 * @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;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
 public function run(&$arrData, $arrDefConf)
 {
     $time_start = Volatile::microtime(true) * 1000;
     if (empty($arrData) || !is_array($arrData)) {
         CLog::warning("get image sid failed, param null");
         $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
         $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_PARAM_ERR;
         return false;
     }
     // 整体功能开关
     $arrConf = Util::getConf('/image_base', 'IMAGE_BASE');
     if ($arrConf['base64'] !== 'on') {
         CLog::debug("get image sid turn off");
         $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
         $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_OFF;
         return false;
     }
     // 无用代码,小流量使用
     if (!isset($arrConf['base64_tempname']) || empty($arrConf['base64_tempname'])) {
         $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
         $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_NOT_LEGAL;
         return false;
     }
     if (strcasecmp($arrData['uiControl']['templateName'], $arrConf['base64_tempname']) == 0) {
         $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
         $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_NOT_LEGAL;
         return false;
     }
     // 浏览器识别IE6、IE7
     $bolFlag = $this->recognizeUserAgent($arrData);
     if ($bolFlag !== true) {
         CLog::debug("get image sid useragent not legal");
         $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
         $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_BROWSER;
         return false;
     }
     // for small flow
     /*
     if (isset ( $arrConf ['base64_small_flow'] ) && $arrConf ['base64_small_flow'] === on) {
     	$arrSample = Util::getConf ( '/sample_variable', 'sample_variable/IMAGE_BASE64' );
     	$bolSampleExp = false;
     	$bolSampleMat = false;
     	if (is_array ( $arrSample ) && ! empty ( $arrSample ) && ! empty ( $arrSample ['Contexted'] )) {
     		if (is_array ( $arrData ['uiData'] ['queryInfo'] ['samplingId'] ) && ! empty ( $arrData ['uiData'] ['queryInfo'] ['samplingId'] )) {
     			$arrSids = $arrData ['uiData'] ['queryInfo'] ['samplingId'];
     			$arrSids = array_flip ( $arrSids );
     			foreach ( $arrSample ['Contexted'] as $arrTemp ) {
     				if (isset ( $arrSids [$arrTemp ['sampling_id']] )) {
     					if ($arrTemp ['value'] == $arrConf ['exp_value']) {
     						$bolSampleExp = true;
     						break;
     					} else if ($arrTemp ['value'] == $arrConf ['mat_value']) {
     						$bolSampleMat = true;
     						break;
     					}
     				}
     			}
     		}
     	}
     	if ($bolSampleMat === true) {
     		$GLOBALS ['logArr'] ['time_img_base64'] = round ( Volatile::microtime ( true ) * 1000 - $time_start, 2 );
     		$GLOBALS ['logArr'] ['img_base64_ret'] = self::BASE64_MAT;
     		return false;
     	}
     	if ($bolSampleExp === false) {
     		$GLOBALS ['logArr'] ['time_img_base64'] = round ( Volatile::microtime ( true ) * 1000 - $time_start, 2 );
     		$GLOBALS ['logArr'] ['img_base64_ret'] = self::BASE64_OTHER;
     		return false;
     	}
     }
     */
     // 设置左侧小流量开关
     $base64LeftOn = false;
     $leftOpenTpllist = $arrConf['base64_left_tempname'];
     $leftOpenTpllist = explode(',', $leftOpenTpllist);
     foreach ($leftOpenTpllist as $leftTplName) {
         if (strcasecmp($arrData['uiControl']['templateName'], $leftTplName) == 0) {
             $base64LeftOn = true;
         }
     }
     // 处理右侧结果队列
     $arrResult = $arrConf['result'];
     $arrResult = explode(',', $arrResult);
     $arrControlInfo =& $arrData['uiControl'];
     $arrImgIds = array();
     $arrImgIdsLeft = array();
     $strPlatform = $arrControlInfo['platform'];
     $strLanguage = $arrControlInfo['language'];
     $strType = '';
     $strTemplateName = '';
     $arrImgConf = array();
     foreach ($arrResult as $res) {
         if (is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) {
             // 处理结果队列的每条结果
             foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) {
                 $strType = empty($arrItem['dispData']['strategy']['type']) ? VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE : trim($arrItem['dispData']['strategy']['type']);
                 if (empty($arrItem['dispData']['strategy'])) {
                     CLog::debug("get tpl strategy fail");
                     continue;
                 }
                 $strTemplateName = trim($arrItem['dispData']['strategy']['tempName']);
                 if (empty($strTemplateName)) {
                     CLog::debug("get image sid template name null");
                     continue;
                 }
                 // 获取tpl.conf内容
                 $arrImgConf = $this->load_image_tpl_conf($strPlatform, $strLanguage, $strType, $strTemplateName);
                 // 从src中提取sid
                 if (is_array($arrImgConf) && !empty($arrImgConf)) {
                     if (intval($arrImgConf['open_base64']) != 1) {
                         continue;
                     }
                     if (is_array($arrImgConf['img']) && !empty($arrImgConf['img'])) {
                         if ($base64LeftOn === true && strcasecmp($res, "asResult") == 0) {
                             foreach ($arrImgConf['img'] as $arrImgData) {
                                 $this->parse_image_conf($arrItem['dispData']['resultData'], $arrImgIdsLeft, $arrImgData);
                             }
                         } else {
                             if (strcasecmp($res, "rightResult") == 0) {
                                 /* 处理 右侧展开图片的base64加载问题,控制每单个模板base64加载张数:先读取模板变量$tplData.showrow,如果读不到则默认只加载4张 */
                                 $imgCountLimit = 4;
                                 if (is_array($arrItem['dispData']['resultData'])) {
                                     $showNum = $arrItem['dispData']['resultData']['tplData']['shownums'];
                                     if (!empty($showNum) && is_numeric($showNum) && $showNum > 0 && $showNum < 13) {
                                         $imgCountLimit = $showNum;
                                     }
                                 }
                                 //记录当前数组里的图片张数
                                 $tempCount = count($arrImgIds);
                                 foreach ($arrImgConf['img'] as $arrImgData) {
                                     $this->parse_image_conf($arrItem['dispData']['resultData'], $arrImgIds, $arrImgData);
                                     //判断新增张数是否超过切分阈值
                                     if (count($arrImgIds) > $tempCount + $imgCountLimit) {
                                         //进行切分,去掉尾部图片
                                         $arrImgIds = array_slice($arrImgIds, 0, $tempCount + $imgCountLimit);
                                         //更新当前图片数量值
                                         $tempCount = count($arrImgIds);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 unset($arrImgConf);
             }
         }
     }
     // 标记base64是否开启
     $base64on = false;
     if (is_array($arrImgIds) && !empty($arrImgIds)) {
         $arrData['uiData']['queryInfo']['base64_sids_for_plugin'] = $arrImgIds;
         //该数组供Smarty插件读取,用于拼装base64形式的图片dom
         //只要右侧有图片,即开启base64开关
         $base64on = true;
     }
     //判断是否开启图片预取, 将已设置预取的图片从base64列表中去除.
     $preImageConf = Util::getConf('/image_predict', 'IMAGE_PREDICT');
     if ($preImageConf['predict_get'] === 'on' && $arrData['uiData']['queryInfo']['pageNo'] == 1) {
         $preImgList = $arrData['uiData']['queryInfo']['viewConfig']['predictImg'];
         if (!empty($preImgList)) {
             if (!empty($preImgList['right']['sidList'])) {
                 $img_diff = array_diff($arrImgIds, $preImgList['right']['sidList']);
                 #当图片预取list与实际图片list小于,配置差值时关闭base64
                 $arrImgIds = $img_diff;
             }
             if (!empty($preImgList['left']['sidList'])) {
                 $img_diff_left = array_diff($arrImgIdsLeft, $preImgList['left']['sidList']);
                 #当图片预取list与实际图片list小于,配置差值时关闭base64
                 $arrImgIdsLeft = $img_diff_left;
             }
         }
     }
     // 设置base64模板变量
     if (is_array($arrImgIds) && !empty($arrImgIds)) {
         //去重后的右侧图片
         $arrData['uiData']['queryInfo']['base64_img_sids'] = $arrImgIds;
     }
     if (is_array($arrImgIdsLeft) && !empty($arrImgIdsLeft)) {
         //左侧图片
         $arrData['uiData']['queryInfo']['base64_img_sids_left'] = $arrImgIdsLeft;
         $base64on = true;
         if ($base64LeftOn === true) {
             $arrData['uiData']['queryInfo']['base64_left_exp'] = 'on';
         }
     }
     if ($base64on) {
         $arrData['uiData']['queryInfo']['base64'] = 'on';
         $arrData['uiData']['queryInfo']['base64_domain'] = $arrConf['domain'];
         CSmarty::setQueryInfo($arrData['uiData']['queryInfo']);
         $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
         $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_OK;
         return true;
     }
     $GLOBALS['logArr']['time_img_base64'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
     $GLOBALS['logArr']['img_base64_ret'] = self::BASE64_NOT_OK;
     return false;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 public function writeLog($intLevel, $str, $errno = 0, $arrArgs = null, $depth = 0)
 {
     if ($intLevel > $this->intLevel || !isset(self::$arrLogLevels[$intLevel])) {
         return;
     }
     $strLevel = self::$arrLogLevels[$intLevel];
     $strLogFile = $this->strLogFile;
     if ($intLevel & self::LOG_LEVEL_WARNING || $intLevel & self::LOG_LEVEL_FATAL) {
         $strLogFile .= '.wf';
     }
     $trace = debug_backtrace();
     if ($depth >= count($trace)) {
         $depth = count($trace) - 1;
     }
     $file = basename($trace[$depth]['file']);
     $line = $trace[$depth]['line'];
     $strArgs = '';
     $strArgs .= "qid[" . self::$strQueryId . "] ";
     if (is_array($arrArgs) && count($arrArgs) > 0) {
         foreach ($arrArgs as $key => $value) {
             $strArgs .= $key . "[{$value}] ";
         }
     }
     $intTimeUsed = round(Volatile::microtime(true) * 1000 - $this->intStartTime, 2);
     $str = sprintf("%s: %s [%s:%d] errno[%d] ip[%s] logId[%u] uri[%s] time_used[%s] %s%s\n", $strLevel, date('m-d H:i:s:', time()), $file, $line, $errno, self::getClientIP(), $this->intLogId, isset(self::$strQueryUri) ? self::$strQueryUri : $_SERVER['REQUEST_URI'], $intTimeUsed, $strArgs, $str);
     return file_put_contents($strLogFile, $str, FILE_APPEND);
 }
Ejemplo n.º 9
0
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];
    }
}
Ejemplo n.º 10
0
 public function run(&$arrData, $arrConf)
 {
     $time_start = Volatile::microtime(true) * 1000;
     if (empty($arrData) || !is_array($arrData)) {
         return false;
     }
     $arrFilterConfs = Util::getConf('/graph_filter', 'GRAPH_FILTER');
     if (!is_array($arrFilterConfs) || empty($arrFilterConfs) || empty($arrFilterConfs['result']) || empty($arrFilterConfs['SRCID']) || empty($arrFilterConfs['defaultTplName']) || empty($arrFilterConfs['check_aladin']) || empty($arrFilterConfs['filter_result'])) {
         return false;
     }
     $sample_variable = $this->get_sample_variable($arrData, 'GENERAL_IMAGE_VUI');
     $aladin = $this->get_image_aladin($arrData, $arrFilterConfs);
     $ads = $this->get_ads_count($arrData['uiData']['ecResult']);
     $strResult = $arrFilterConfs['result'];
     $intTotalCount = isset($arrFilterConfs['count']) ? intval($arrFilterConfs['count']) : 10;
     $no_img_if_ad = isset($arrFilterConfs['no_img_if_ad']) ? intval($arrFilterConfs['no_img_if_ad']) : 1;
     $default_st = isset($arrFilterConfs['default_st']) ? intval($arrFilterConfs['default_st']) : 0;
     //< 不中抽样使用默认策略分支
     if ($sample_variable == 0) {
         $sample_variable = $default_st;
     }
     //< 获取所有结果
     $results = $this->get_all_results($arrData);
     // debug_log("results:" . var_export($results, true) );
     //< 新分支
     if ($sample_variable != 3) {
         //处理AS结果队列
         if (is_array($arrData['uiData'][$strResult]['item']) && !empty($arrData['uiData'][$strResult]['item'])) {
             $intCurCount = 0;
             foreach ($arrData['uiData'][$strResult]['item'] as $intIndex => &$arrItem) {
                 // 处理每条结果
                 $intCurCount++;
                 if ($intCurCount > $intTotalCount) {
                     return true;
                 }
                 if (isset($arrItem['dispData']['disp_image'])) {
                     switch ($arrItem['dispData']['disp_image']) {
                         case 'disp_image':
                             // if ($ads["left_top"] > 0) {
                             //     $this->disable_general_image($arrItem, false, "advertisement" );
                             // } else {
                             //     $this->disable_general_pic($arrItem);
                             // }
                             // break;
                         // if ($ads["left_top"] > 0) {
                         //     $this->disable_general_image($arrItem, false, "advertisement" );
                         // } else {
                         //     $this->disable_general_pic($arrItem);
                         // }
                         // break;
                         case 'check_aladin':
                             $keep_img = $this->keep_url_image($sample_variable, $intIndex + 1, $ads, $aladin, $no_img_if_ad);
                             if (!$keep_img['keep']) {
                                 $this->disable_general_image($arrItem, $keep_img['add_tag'], $keep_img['reason']);
                             } else {
                                 $this->disable_general_pic($arrItem);
                             }
                             break;
                         case 'no_image':
                         default:
                             $this->disable_general_image($arrItem, false, "unknown disp_image : " . $arrItem['dispData']['disp_image']);
                             break;
                     }
                 }
                 $has_image = isset($arrItem['dispData']['general_pic']['url']) && !empty($arrItem['dispData']['general_pic']['url']);
                 if ($has_image == true) {
                     $arrItem['dispData']['img'] = 1;
                 }
             }
         }
     } else {
         //< 判断出图位置
         $disable_pos = $this->calc_disp_image_pos($results);
         // debug_log("disable_pos:" . var_export($disable_pos, true) );
         //< 去掉指定位置的图片
         $this->disable_specify_pos($arrData, $results, $disable_pos);
         //< 出图与图文标不共存
         $this->disable_general_pic_if_image($arrData);
     }
     // $this->add_preload($arrData, $results);
     $keep_single_image_baike = isset($arrFilterConfs['keep_single_image_baike']) ? intval($arrFilterConfs['keep_single_image_baike']) : 0;
     if ($keep_single_image_baike == 1) {
         $this->keep_single_image_baike($arrData);
     }
     $this->group_results_proc($arrData);
     return true;
 }
Ejemplo n.º 11
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;
}