/** * 模板回退,重新加载相应的模板配置 * @param unknown_type $data * @param unknown_type $strBakTemplateType 需要回退到的模板类型 默认baidu * @param unknown_type $strBakTemplateName 需要回退到的模板名字 默认baidu */ public static function templateBack(&$data, $strBakTemplateType = 'baidu', $strBakTemplateName = 'baidu') { $data['uiControl']['templateType'] = $strBakTemplateType; $data['uiControl']['templateName'] = $strBakTemplateName; $data['uiControl']['oriTplName'] = $strBakTemplateName; $GLOBALS['logArr']['templateType'] = $data['uiControl']['templateType']; $GLOBALS['logArr']['templateName'] = $data['uiControl']['templateName']; $objTemplateSelector = new TemplateSelector(); $bolRet = $objTemplateSelector->getUserInfo($data); if ($bolRet == false) { $status = $GLOBALS['STATUS_CODE']['TPL_SELECT_FAIL']; CLog::fatal($GLOBALS['STATUS_MSG'][$status], $status, $GLOBALS['logArr']); $result['status'] = $status; return false; } $arrTplConfig = $objTemplateSelector->getTplConfig($data['uiControl']['tplConfigPath']); if (!is_array($arrTplConfig) || empty($arrTplConfig) || count($arrTplConfig) <= 0) { $status = $GLOBALS['STATUS_CODE']['TPL_SELECT_FAIL']; CLog::fatal($GLOBALS['STATUS_MSG'][$status], $status, $GLOBALS['logArr']); return $status; } // 处理首页模板 if ($data['uiControl']['templateSwitch'] == 2) { $arrFrontPage = Bd_Conf::getConf('/baidu/'); if (!empty($arrFrontPage) && is_array($arrFrontPage)) { foreach ($arrFrontPage as $key => $value) { $arrTplConfig[$key] = $value; } } } // 解析模板配置项 $objTemplateSelector->parseTplConfig($data, $arrTplConfig); unset($arrData['uiControl']['tplConfigPath']); unset($arrData['uiControl']['tplConfigName']); unset($arrData['uiControl']['tplConfigType']); return true; }
public function queryFromUs($arrData) { $arrQueryInfo = $arrData['uiData']['queryInfo']; $arrSessionInfo = $arrData['uiData']['passport']; $arrControlInfo = $arrData['uiControl']; // 传递给us的数据结构 $objQuery = new QueryUSInfo(); $objQuery->time = time(); $objQuery->word = $arrQueryInfo['queryWord']; $objQuery->wordNoSyntax = $arrQueryInfo['wordNoSyntax']; $objQuery->otherResultQuery = $arrQueryInfo['otherResultQuery']; $objQuery->ip = $arrQueryInfo['ip']; if ($arrQueryInfo['interPage'] > 0) { $objQuery->isInterPage = 1; } else { $objQuery->isInterPage = 0; } if ($arrQueryInfo['bwsRetry'] > 0) { $objQuery->isBwsRetry = 1; } else { $objQuery->isBwsRetry = 0; } $objQuery->preference = $arrQueryInfo['preference']; $objQuery->passportUserName = $arrSessionInfo['passportUserName']; if (!empty($arrQueryInfo['JpAlaPre'])) { $objQuery->JpAlaPre = $arrQueryInfo['JpAlaPre']; } $objQuery->codeType = $arrQueryInfo['originCodeType'] & ~(DICT_SEARCH_BIT | MON_BIT | NEWS_SEARCH_BIT | BAIDU_REFER_BIT | TITLE_SEARCH_BIT | AUTHOR_SEARCH_BIT); if (($arrQueryInfo['isDebug'] && intval($arrData['uiData']['templateConfig']['debug'])) > 0) { $objQuery->isDebug = 1; } else { $objQuery->isDebug = 0; } $objQuery->strategyName = $arrQueryInfo['strategyName']; $objQuery->siteName = $arrQueryInfo['siteName']; $objQuery->lastModified = $arrQueryInfo['lastModified']; $strTemplateNameMod = null; if (!empty($arrControlInfo['templateName']) && $arrControlInfo['platform'] !== $GLOBALS['DEFAULT_PLATFORM']) { $strTemplateNameMod = 'baidu' . $arrQueryInfo['dspName']; } if (empty($strTemplateNameMod)) { $objQuery->templateName = $arrControlInfo['templateName']; } else { $objQuery->templateName = $strTemplateNameMod; } $objQuery->sid = $arrQueryInfo['samplingId']; $objQuery->cookie = $arrQueryInfo['baiduId']; $objQuery->needsp = $arrQueryInfo['needSp']; $objQuery->pageNo = $arrQueryInfo['pageNo']; $objQuery->queryId = $arrQueryInfo['queryIdInt']; $objQuery->beforeQueryId = $arrQueryInfo['beforeQueryId']; $objQuery->beforeUrl = $arrQueryInfo['beforeUrl']; $objQuery->accountName = $arrQueryInfo['accountName']; $objQuery->isContCluster = $arrQueryInfo['isContMirror']; $objQuery->isSiteCluster = $arrQueryInfo['isSiteCluster']; $intPageNum = 0; if ($arrQueryInfo['pageNo'] == 1 || $arrQueryInfo['pageNo'] == 2 && $arrQueryInfo['resNum'] == 10) { $intPageNum = $arrQueryInfo['pageNum']; } else { $intPageNum = $arrQueryInfo['pageNum'] - $arrQueryInfo['usm']; } if ($intPageNum < 0) { $intPageNum = 0; } if ($intPageNum >= MAX_OUTPUT_NUM) { $intPageNum = 750; } $objQuery->pageNum = $intPageNum; $objQuery->resNum = $arrQueryInfo['resNum']; $objQuery->resultLang = $arrQueryInfo['resultLang']; $objQuery->resultLocale = $arrQueryInfo['resultLocale']; $strUrlParam = self::filterParamFromUrl($arrQueryInfo['urlParam'], WENKU_WAP_PC_KEY); if (!empty($strUrlParam) && !empty($arrQueryInfo['wenkuUrlPara'])) { $strUrlParam .= '&' . $arrQueryInfo['wenkuUrlPara']; } $objQuery->urlParam = $strUrlParam; $objQuery->requestCode = $arrQueryInfo['requestCode']; $objQuery->usm = $arrQueryInfo['usm']; $objQuery->UrlParaPack = self::packUrlParam($strUrlParam, $arrQueryInfo['postData'], $strTemplateNameMod, $arrQueryInfo['cookieInfo']); if (PROTECTPP_SWITCH_OPEN == $arrQueryInfo['resLimitSwitch']) { $objQuery->enalbeModifyUsm = 1; } else { $objQuery->enalbeModifyUsm = 0; } $intCommand = 0; for ($intI = 0; $intI < DA_RES_COUNT; $intI++) { $intCommand |= $arrQueryInfo['daResource'][$intI]; } $objQuery->template_rsse_command = $intCommand; $objQuery->need_open_disphilight = $arrQueryInfo['need_open_disphilight']; $objQuery->need_RsSE_result = $arrQueryInfo['needRsSeResult']; $objQuery->need_ers_result = $arrQueryInfo['needERSResult']; $objQuery->need_asp_result = $arrQueryInfo['needASPResult']; $objQuery->need_as_result = $arrQueryInfo['need_as_result']; $objQuery->preQueryWord = $arrQueryInfo['preQueryWord']; $objQuery->querySource = $arrQueryInfo['querySource']; $objQuery->isInternalFlow = $arrQueryInfo['isInternalFlow']; $objQuery->srcId = $arrQueryInfo['srcId']; $objQuery->templateForRs = $arrQueryInfo['templateForRs']; $objQuery->beforeQueryId = $arrQueryInfo['beforeQueryId']; $objQuery->noscript = $arrQueryInfo['noscript']; $objQuery->cookieNoscript = $arrQueryInfo['cookieNoscript']; $objQuery->channel = $arrQueryInfo['channel']; $objQuery->rsPos = $arrQueryInfo['rsPos']; $objQuery->platformName = $arrControlInfo['platform']; $objQuery->is_bws_re = $arrQueryInfo['is_bws_re']; $objQuery->useragent_full = $arrQueryInfo['useragent_full']; $objQuery->confuse_Switch = $arrQueryInfo['confuse_Switch']; $objQuery->protectNum = $arrQueryInfo['protectNum']; $objQuery->ec_src = $arrQueryInfo['ec_src']; $objQuery->php_default_platform = $GLOBALS['DEFAULT_PLATFORM']; $objQuery->dspName = $arrQueryInfo['dspName']; $objQuery->ipv6Address = $arrQueryInfo['ipv6Address']; $objQuery->refer = $arrQueryInfo['refer']; $objQuery->needProtect = $arrQueryInfo['needProtect']; $objQuery->protectPPSwitch = $arrQueryInfo['protectPPSwitch']; $objQuery->nojc = $arrQueryInfo['nojc']; $objQuery->super_se_flag = $arrQueryInfo['superSeFlag']; $objQuery->isContainPunc = $arrQueryInfo['isContainPunc']; $objQuery->wordNoPunc = $arrQueryInfo['wordNoPunc']; $objQuery->clusterMod = $arrQueryInfo['clusterMod']; $objQuery->wordEnc = $arrQueryInfo['wordEnc']; $objQuery->extraStr = $arrQueryInfo['extraStr']; $objQuery->strategy_state = $arrQueryInfo['strategyState']; $objQuery->prompt_flag = $arrQueryInfo['promptUsOpen']; $objQuery->passport_user_id = $arrSessionInfo['passportUserId']; $objQuery->need_interleaving = $arrQueryInfo['need_interleaving']; $objQuery->comeFrom = $arrQueryInfo['comeFrom']; if (!empty($arrQueryInfo['country'])) { $objQuery->country_str = $arrQueryInfo['country']; } $objQuery->is_sample_template = isset($arrQueryInfo['is_sample_template']) ? intval($arrQueryInfo['is_sample_template']) : 0; $objQuery->superseSwitch = isset($arrQueryInfo['superseSwitch']) ? intval($arrQueryInfo['superseSwitch']) : 1; $objQuery->query_lang = $arrQueryInfo['query_lang']; $objQuery->displayLang = $arrControlInfo['language']; if (isset($arrQueryInfo['isParams'])) { if ($arrQueryInfo['isParams']['mod'] === IS_PRE_DICT_REQ) { if (!empty($arrQueryInfo['isParams']['hsug'])) { $objQuery->hsug = $arrQueryInfo['isParams']['hsug']; } if (!empty($arrQueryInfo['isParams']['sug'])) { $objQuery->sug = $arrQueryInfo['isParams']['sug']; } if (!empty($arrQueryInfo['isParams']['clist'])) { $objQuery->clist = $arrQueryInfo['isParams']['clist']; } } $objQuery->mod = $arrQueryInfo['isParams']['mod']; $objQuery->cqid = empty($arrQueryInfo['isParams']['cqid']) ? '0' : $arrQueryInfo['isParams']['cqid']; $objQuery->isid = empty($arrQueryInfo['isParams']['isid']) ? '0' : $arrQueryInfo['isParams']['isid']; $objQuery->chk = empty($arrQueryInfo['isParams']['chk']) ? '0' : $arrQueryInfo['isParams']['chk']; if (in_array($objQuery->mod, array(IS_PRE_REQ, IS_PRE_DICT_REQ)) && in_array($objQuery->word, array('baidu', '百度'))) { $objQuery->f4s = 1; } else { $objQuery->f4s = $arrQueryInfo['isParams']['f4s']; } $objQuery->isbd = $arrQueryInfo['isParams']['isbd']; $objQuery->csq = intval($arrQueryInfo['isParams']['csq']); $objQuery->pstg = intval($arrQueryInfo['isParams']['pstg']); $objQuery->isDebugSwitch = intval($arrQueryInfo['isDebugSwitch']); } // User Agent相关字段, by chenjinsheng@baidu.com, 2013-07-08 if (!empty($arrQueryInfo['userAgent'])) { list($resx, $resy) = @explode('x', $arrQueryInfo['userAgent']['resolution']); $arrUaInfo = array('ua_os' => $arrQueryInfo['userAgent']['os'], 'ua_browser' => $arrQueryInfo['userAgent']['browser'], 'ua_modal' => $arrQueryInfo['userAgent']['modal'], 'ua_measure' => $arrQueryInfo['userAgent']['measure'], 'ua_res_x' => $resx, 'ua_res_y' => $resy); $arrExpFields = Bd_Conf::getConf('tpl_uaadaptation/UA_DICT_EXPLICIT'); $arrExpFields = array_keys($arrExpFields); foreach ($arrExpFields as $filed) { unset($arrQueryInfo['userAgent'][$filed]); } if (!empty($arrQueryInfo['userAgent'])) { $objUaFields = Util::mcpack_normal($arrQueryInfo['userAgent']); $strUaFields = mc_pack_array2pack($objUaFields); $arrUaInfo['ua_ext'] = $strUaFields; } $objQuery->uaInfo = $arrUaInfo; } $arrQuery = $objQuery->toArray(); $arrQuery = Util::mcpack_normal($arrQuery); foreach ($arrQuery as $key => $value) { if (in_array($key, array('cookie', 'beforeUrl', 'UrlParaPack', 'JpAlaPre'))) { $arrQuery['(raw)' . $key] = $value; unset($arrQuery[$key]); } } if (!isset($_ENV['HHVM'])) { ral_set_logid(CLog::logId()); $ret = ral('us', 'us', $arrQuery, Volatile::rand()); if ($ret === false) { $intErrno = ral_get_errno(); CLog::fatal('Fail to connect us, errNo:' . $intErrno, $GLOBALS['logArr']); } } else { $ral = new RalClass(); $ral->ral_set_logid(CLog::logId()); $ret = $ral->ral('us', 'us', $arrQuery, Volatile::rand()); if ($ret === false) { $intErrno = $ral->ral_get_errno(); $strErrmsg = $ral->ral_get_error($intErrno); CLog::fatal('Fail to connect us, errNo:' . $intErrno . 'errMsg: ' . $strErrmsg, $GLOBALS['logArr']); } } return $ret; }
/** * load configure file */ function load_conf($dir) { /** * load configure file */ //if (Util::getConf('/feature', 'FEATURE_LIST/CONFIG2BDCONF/TURN') !== 'ON') { // $conf = config_load($dir, "vui-global.conf", "view-ui.range"); //} else { $conf = Bd_Conf::getConf('/vui-global'); //} if (false === $conf) { /** * default log config */ $GLOBALS['LOG'] = array('intLevel' => 0x4, 'strLogFile' => VUI_LOG_PATH . '/view-ui.log'); return false; } /** * assign configure value */ foreach ($conf as $key => $value) { $GLOBALS[$key] = $value; } /** * strLogName */ if (empty($GLOBALS['LOG']['strLogName'])) { $GLOBALS['LOG']['strLogName'] = "view-ui.log"; } $GLOBALS['LOG']['strLogFile'] = VUI_LOG_PATH . "/" . $GLOBALS['LOG']['strLogName']; /** * ui encoding */ if (empty($GLOBALS['UI_ENCODING'])) { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; CLog::fatal($GLOBALS['STATUS_MSG'][$status] . ", UI_ENCODING cannot be empty", $status); return false; } /** * request type */ if (empty($GLOBALS['REQUEST_TYPE']) || !is_array($GLOBALS['REQUEST_TYPE'])) { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; CLog::fatal($GLOBALS['STATUS_MSG'][$status] . ", REQUEST_TYPE cannot be empty", $status); return false; } /** * badiu page's mini size */ if (empty($GLOBALS['MINI_BAIDU_PSIZE']) || intval($GLOBALS['MINI_BAIDU_PSIZE']) <= 0) { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; $invalid_mini_psize = $GLOBALS['MINI_BAIDU_PSIZE']; $default_mini_psize = 10; $GLOBALS['MINI_BAIDU_PSIZE'] = $default_mini_psize; CLog::warning($GLOBALS['STATUS_MSG'][$status] . ", MINI_BAIDU_PSIZE[{$invalid_mini_psize}] is not valid, and set to " . $GLOBALS['MINI_BAIDU_PSIZE'], $status); } /** * aladdin template type */ if (empty($GLOBALS['ALADDIN_TEMPLATE_TYPE'])) { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; CLog::fatal($GLOBALS['STATUS_MSG'][$status] . ", ALADDIN_TEMPLATE_TYPE cannot be empty", $status); return false; } if (!defined("VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE")) { define("VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE", $GLOBALS['ALADDIN_TEMPLATE_TYPE']); } else { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; CLog::warning($GLOBALS['STATUS_MSG'][$status] . ", ALADDIN_TEMPLATE_TYPE is already defined:" . ALADDIN_TEMPLATE_TYPE, $status, $GLOBALS['logArr']); return false; } //load STRATEGY if (!empty($GLOBALS['STRATEGY']['USE_STRATEGY'])) { $strategys = explode(',', $GLOBALS['STRATEGY']['USE_STRATEGY']); $use_strategys = array(); foreach ($strategys as $key => $value) { $strategy = "STRATEGY" . $value; if (!empty($GLOBALS[$strategy]['STRATEGY_NAME']) && !empty($GLOBALS[$strategy]['STRATEGY_FUNCTION'])) { if (!strncmp($GLOBALS[$strategy]['STRATEGY_FUNCTION'], "strategy_function", strlen("strategy_function")) && function_exists($GLOBALS[$strategy]['STRATEGY_FUNCTION'])) { //load STRATEGY1 if ($value == 1) { if (!empty($GLOBALS[$strategy])) { $template_interfere = array(); if (!empty($GLOBALS[$strategy]['TEMPLATE_INTERFERE']) && is_array($GLOBALS[$strategy]['TEMPLATE_INTERFERE'])) { foreach ($GLOBALS[$strategy]['TEMPLATE_INTERFERE'] as $k => $v) { $interfere_pair = explode("->", $v); $template_interfere[$k]['left'] = $interfere_pair[0]; $template_interfere[$k]['right'] = $interfere_pair[1]; $template_interfere[$k]['default'] = $interfere_pair[2]; } } $GLOBALS[$strategy]['TEMPLATE_INTERFERE'] = $template_interfere; $use_strategys[] = $value; } else { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; CLog::warning($GLOBALS['STATUS_MSG'][$status] . ", USE_STRATEGY {$value} cannot be empty", $status); } } else { if (!empty($GLOBALS[$strategy])) { $use_strategys[] = $value; } else { $status = $GLOBALS['STATUS_CODE']['INIT_FAIL']; CLog::debug($GLOBALS['STATUS_MSG'][$status] . ", USE_STRATEGY {$value} is empty", $status); } } } } } $GLOBALS['STRATEGY']['USE_STRATEGY'] = $use_strategys; } // get multi rendering conf here recently, avoid loading conf when rendering... // by chenjinsheng@baidu.com, 2013/12/02 $GLOBALS['globalConf']['compileCheck'] = Util::getConf('/smarty', 'group1/compile_check'); $GLOBALS['globalConf']['FEATURE_LIST'] = Util::getConf('/feature', 'FEATURE_LIST'); $GLOBALS['globalConf']['MULTI_RENDER'] = Util::getConf('/multi_render', 'MULTI_RENDER'); return true; }