public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrBitZoneConf = Util::getConf('/bitzone', 'BITZONE'); $arrBitZoneConf = $this->analysisConf($arrBitZoneConf); if (empty($arrBitZoneConf)) { return false; } // 遍历获得asResult->item->0/1/..->urls->asurls->strategys中的标志位数组 // 取得配置中各标志位在上述数组位置中的值 // 将最终解析出来的标志位值加入asResult->item->0/1/..->dispData->strategybits中 if (!empty($arrData['uiData']['asResult']['item']) && is_array($arrData['uiData']['asResult']['item'])) { foreach ($arrData['uiData']['asResult']['item'] as &$asResultItem) { $arrBitZoneInfo = array(); if (!empty($asResultItem['urls']['asUrls']['strategys']) && is_array($asResultItem['urls']['asUrls']['strategys'])) { foreach ($arrBitZoneConf as $strTipKey => $arrTipConfInfo) { $strTipValue = ''; foreach ($arrTipConfInfo as $intSection => $arrPos) { $intStrategySectionNum = intval($asResultItem['urls']['asUrls']['strategys'][$intSection]); foreach ($arrPos as $intPos) { $intTmp = ($intStrategySectionNum & pow(2, $intPos)) == 0 ? 0 : 1; $strTipValue = $strTipValue === '' ? $intTmp : $strTipValue . $intTmp; } } $arrBitZoneInfo[$strTipKey] = bindec($strTipValue); } } $asResultItem['dispData']['strategybits'] = $arrBitZoneInfo; } } return true; }
public static function run(&$arrData) { if (empty($arrData)) { return false; } // 策略配置 $arrStrategys = Util::getConf('/strategy', 'STRATEGY_ENGINE/STRATEGY'); if (is_array($arrStrategys)) { foreach ($arrStrategys as $arrStrategy) { if (empty($arrStrategy['STRATEGY_CLASS'])) { // 策略函数为空 continue; } if (strcasecmp($arrStrategy['TURN'], 'on') != 0) { // 当前策略关闭 continue; } // 调用对应的策略 $objStrategy = new $arrStrategy['STRATEGY_CLASS'](); // file_put_contents ( '/home/work/search/view-ui/data/data_'.$arrStrategy ['STRATEGY_CLASS'], serialize($arrData) ); // file_put_contents ( '/home/work/search/view-ui/data/data_'.$arrStrategy ['CONF'].'_conf', serialize($arrStrategy ['CONF']) ); call_user_func_array(array($objStrategy, 'run'), array(&$arrData, $arrStrategy['CONF'])); //file_put_contents ( '/home/work/search/view-ui/data/data_'.$arrStrategy ['STRATEGY_CLASS'].'_result', serialize($arrData) ); } } }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $ecResult = $arrData['uiData']['ecResult']; $arrTplConfs = Util::getConf('/tpl_style', 'STYLE_TEMPLATE'); $ecResultItem = $arrData['uiData']['ecResult']['ecResultItem']; $resultArr = array(); $tmpArr = array(); foreach ($arrTplConfs as $key => $val) { $resultArr[$key]['result'] = $val['result']; $resultArr[$key]['tpl_style'] = $val['tpl_style']; } if (!empty($ecResultItem) && is_array($ecResultItem)) { foreach ($ecResultItem as $item) { if (is_array($item)) { $src_id = 'SRCID_' . $item['id']; if (!empty($arrTplConfs[$src_id]) && is_array($arrTplConfs[$src_id])) { if (!isset($tmpArr[$arrTplConfs[$src_id]['result']])) { $this->selectTplStyle($arrData, $item, $resultArr); $tmpArr[$arrTplConfs[$src_id]['result']] = true; } } } } } return true; }
/** * type:0-读cache时 1-写cache时 */ public static function getPreImageKey($arrData, $arrConf, $type = 0) { $arrConf = Util::getConf('/image_predict', 'IMAGE_PREDICT'); $queryInfo = $arrData['uiData']['queryInfo']; //临时硬编码:先上写时,读用旧的key $version = $type == 1 ? $arrConf['version'] : "0.1"; $key = md5($queryInfo['queryWord'] . '+' . intval($queryInfo['pageNo']) . '+' . intval($queryInfo['resNum']) . '+' . $queryInfo['language'] . '+' . $arrData['uiControl']['platform'] . '+' . $arrData['uiControl']['templateType'] . '+' . $arrData['uiControl']['templateName'] . '+' . $version); return $key; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrFilterConfs = Util::getConf('/url_filter', 'URL_FILTER'); if (!is_array($arrFilterConfs) || empty($arrFilterConfs)) { return false; } $arrResultUrls = array(); // 查找对应资源 foreach ($GLOBALS['RESULT'] as $res) { if (isset($arrFilterConfs[$res]) && !empty($arrFilterConfs[$res]['src_ids'])) { $arrFilterConfs[$res]['src_ids'] = explode(',', $arrFilterConfs[$res]['src_ids']); $arrFilterConfs[$res]['src_ids'] = array_flip($arrFilterConfs[$res]['src_ids']); foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) { if (isset($arrFilterConfs[$res]['src_ids'][$arrItem['dispData']['StdStg']])) { $arrResultUrls[trim($arrItem['itemUrl'])] = trim($arrItem['itemUrl']); } } } } // 对AS结果url去重 $strResult = 'asResult'; $intTotalCount = isset($arrFilterConfs['count']) ? intval($arrFilterConfs['count']) : 0; $intCurCount = 0; $intAs = 0; $intSp = 0; $strForLog = ''; if (!empty($arrResultUrls) && is_array($arrData['uiData'][$strResult]['item']) && !empty($arrData['uiData'][$strResult]['item'])) { foreach ($arrData['uiData'][$strResult]['item'] as $intIndex => $arrItem) { if ($intTotalCount > 0 && $intCurCount >= $intTotalCount) { break; } if (isset($arrResultUrls[trim($arrItem['offsetInfo']['url'])])) { if ($arrItem['comeFrome'] == 'AS') { $intAs++; } else { if ($arrItem['comeFrome'] == 'SP') { $intSp++; } } $intCurCount++; unset($arrData['uiData'][$strResult]['item'][$intIndex]); $strForLog = 'url_filter_asResult'; } } } $arrData['uiData'][$strResult]['asResultNum'] = intval($arrData['uiData'][$strResult]['asResultNum']) - $intAs; $arrData['uiData'][$strResult]['spResutlNum'] = intval($arrData['uiData'][$strResult]['spResutlNum']) - $intSp; if (!empty($strForLog)) { $GLOBALS['logArr']['url_filter'] = $strForLog; } return true; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrSids = array(); $arrSample = Util::getConf('/sample_variable', 'sample_variable/FILTER_PROMPT'); $filter_sample = array(); $hint_sample = array(); //获取过滤条件 if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId']) && is_array($arrSample) && !empty($arrSample)) { $arrSids = $arrData['uiData']['queryInfo']['samplingId']; $arrSids = array_flip($arrSids); $filter_sample = $this->getFilterSampleVariables($arrSample, $arrSids); $hint_sample = $this->getHintSampleVariables($arrSample, $arrSids); } //过滤条件为空,直接返回 if (empty($filter_sample) && empty($hint_sample)) { return true; } $arrPromtId = array(); if (isset($arrData['uiData']['queryInfo']['promptNode']) && is_array($arrData['uiData']['queryInfo']['promptNode'])) { //通过过滤条件收集需要删除的提示 foreach ($arrData['uiData']['queryInfo']['promptNode'] as $intKey => &$arrOnePromptNode) { if (!empty($arrOnePromptNode['promptContent'])) { $arrPromptContent = json_decode($arrOnePromptNode['promptContent'], true); $arrPositionTmp = array(); if (!empty($arrPromptContent['hints']) && is_array($arrPromptContent['hints'])) { foreach ($arrPromptContent['hints'] as $strPosition => $arrOnePositionPromptContent) { //首先按id过滤 if (!empty($hint_sample["prompt_id"]) && empty($hint_sample["prompt_id"][$arrOnePositionPromptContent[0]['id']])) { $arrPromtId[] = $intKey; } //按模板过滤 if (empty($hint_sample["prompt_id"][$arrOnePositionPromptContent[0]['id']]) && !empty($filter_sample["template"][$arrOnePositionPromptContent[0]['templateName']])) { $arrPromtId[] = $intKey; } } } } } //删除对应的提示 foreach ($arrPromtId as $key) { unset($arrData['uiData']['queryInfo']['promptNode'][$key]); } } return true; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } //PP/PPIM是否存在 $intPPFlag = 0; //右侧是否有品专/地标/知心 $intPinzhuanFlag = 0; //是否存在右侧安全提示 $intRightPromptFlag = 0; $bolFlagFeature = Util::getConf('/feature', 'FEATURE_LIST/ADLEVEL/TURN') === 'ON' ? true : false; if ($bolFlagFeature && isset($arrData['uiData']['ecResult']['adlevel'])) { $intPPFlag = $arrData['uiData']['ecResult']['adlevel'] & 0x1; $intPinzhuanFlag = $arrData['uiData']['ecResult']['adlevel'] >> 2 & 0x1; } else { $arrPPIds = array(EC_FC_PP, EC_FC_PPIM_UL); $arrPinzhuanIds = array(EC_PP_ZQ, EC_PP_QTZ, EC_PP_DB, EC_PP_DB_2); foreach ($arrData['uiData']['ecResult']['ecResultItem'] as $item) { if ($intPPFlag === 0 && in_array($item['id'], $arrPPIds)) { $intPPFlag = 1; } if ($intPinzhuanFlag === 0 && in_array($item['id'], $arrPinzhuanIds)) { $intPinzhuanFlag = 1; } } } if ($intPinzhuanFlag === 0) { $intPinzhuanFlag = empty($arrData['uiData']['rightResult']['item']) ? 0 : 1; } $intRightPromptFlag = $this->bolExistRightPrompt($arrData) ? 1 : 0; if ($intPPFlag === 1) { $arrPromptContent = array(); //安全提示展现位置:RightTop-右上方 RightBottom-右下方 $strPosition = $intRightPromptFlag === 1 ? 'RightTop' : ($intPinzhuanFlag === 1 ? 'RightBottom' : 'RightTop'); $arrPositionContent = array(); //安全提示展现是否的模板 $arrPositionContent['templateName'] = 'hint_securityplan'; //安全提示展现的样式:0-普通版 1-缩略版 $arrPositionContent['style'] = $intRightPromptFlag === 1 ? 0 : ($intPinzhuanFlag === 1 ? 1 : 0); $arrPromptContent[$strPosition][] = $arrPositionContent; $arrData['uiData']['queryInfo']['promptNode'][] = array('id' => -1, 'promptContent' => json_encode(array('hints' => $arrPromptContent))); } return true; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrFilterConfs = Util::getConf('/tpl_filter', 'TEMPLATE_FILTER'); if (!is_array($arrFilterConfs) || empty($arrFilterConfs) || empty($arrFilterConfs['result']) || empty($arrFilterConfs['template_name'])) { return false; } $arrResult = explode(',', $arrFilterConfs['result']); $arrResult = array_flip($arrResult); $arrTplNames = explode(',', $arrFilterConfs['template_name']); $arrTplNames = array_flip($arrTplNames); $intTotalCount = isset($arrFilterConfs['count']) ? intval($arrFilterConfs['count']) : 0; $intCurCount = 0; $bolFlag = false; // 过滤模板对应的单条结果 $arrForLog = array(); foreach ($GLOBALS['RESULT'] as $res) { if (isset($arrResult[$res]) && is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { // 处理每条结果 foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) { if ($intTotalCount > 0 && $intCurCount >= $intTotalCount) { $bolFlag = true; break; } if (isset($arrTplNames[$arrItem['dispData']['strategy']['tempName']])) { // 待补充日志 unset($arrData['uiData'][$res]['item'][$intIndex]); $intCurCount++; $strTemp = $arrItem['dispData']['strategy']['tempName']; $arrForLog[$strTemp] = $strTemp; unset($strTemp); } } } if ($bolFlag === true) { break; } } if (!empty($arrForLog)) { $GLOBALS['logArr']['template_filter'] = implode(',', $arrForLog); } return true; }
/** * @desc 判断site语法提示是否需要避让site语法阿拉丁 **/ public function aladdin_pk_siteHint(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrAlaPkSiteHintConfs = Util::getConf('/aladdin_pk_siteHint', 'ALADDIN_PK_SITEHINT'); if (!is_array($arrAlaPkSiteHintConfs) || empty($arrAlaPkSiteHintConfs)) { return false; } foreach ($GLOBALS['RESULT'] as $res) { if (isset($arrAlaPkSiteHintConfs[$res]) && !empty($arrAlaPkSiteHintConfs[$res]['src_ids'])) { $arrAlaPkSiteHintConfs[$res]['src_ids'] = explode(',', $arrAlaPkSiteHintConfs[$res]['src_ids']); foreach ($arrData['uiData'][$res]['item'] as $arrItem) { if (in_array($arrItem['dispData']['StdStg'], $arrAlaPkSiteHintConfs[$res]['src_ids'])) { return true; } } } } return false; }
/** * 根据采样ID返回采样结果 * @param array $arrData * @param string $exp_name * * @return value 如果没有查到, 返回0 */ public function get_sample_variable($arrData, $exp_name) { $sample_variable = 0; //for small flow $arrSample = Util::getConf('/sample_variable', 'sample_variable/' . $exp_name); //判断arrData中是否存在samplingId if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId']) && is_array($arrSample) && !empty($arrSample)) { $arrSids = $arrData['uiData']['queryInfo']['samplingId']; $arrSids = array_flip($arrSids); //判断samplingId是否存在sampv_variable.conf中exp_name配置项内, 如果存在, 返回value。不存在, 返回0 foreach ($arrSample['Contexted'] as $arrTemp) { if (isset($arrSids[$arrTemp['sampling_id']])) { if ($arrTemp['value'] >= 1 && $arrTemp['value'] <= 10000) { $sample_variable = $arrTemp['value']; break; } } } } return $sample_variable; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $tempNameInfo = Util::getConf('/tempname2stdstg', 'DispTempName'); if (empty($tempNameInfo) || !is_array($tempNameInfo)) { return false; } $asResultItem =& $arrData['uiData']['asResult']['item']; foreach ($asResultItem as $key => &$item) { if ($item['comeFrome'] === 'AS') { if (!isset($item['dispData']['templateName']) || empty($item['dispData']['templateName'])) { continue; } $templateName = $item['dispData']['templateName']; if (isset($tempNameInfo[$templateName]['stdstg']) && !empty($tempNameInfo[$templateName]['stdstg'])) { $item['dispData']['StdStg_new'] = intval($tempNameInfo[$templateName]['stdstg']); } } } }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrDispConfs = Util::getConf('/advertise', 'DISP_STRATEGY'); $arrProductConfs = isset($arrDispConfs['PRODUCT']) ? $arrDispConfs['PRODUCT'] : array(); $arrGeneralConfs = isset($arrDispConfs['GENERAL']) ? $arrDispConfs['GENERAL'] : array(); $arrFilterConfs = isset($arrDispConfs['FILTER']) ? $arrDispConfs['FILTER'] : array(); $arrSampleConfs = isset($arrDispConfs['SAMPLE']) ? $arrDispConfs['SAMPLE'] : array(); // 抽样流量策略 $bolSampleFlag = false; $strEcResultKey = 'ecResult'; $arrLogZhiIds = array(); if (isset($arrFilterConfs['sample_ids']) && !empty($arrFilterConfs['sample_ids']) && is_array($arrSampleConfs['EC']) && !empty($arrSampleConfs['EC'])) { $arrFilterConfs['sample_ids'] = explode(',', $arrFilterConfs['sample_ids']); $arrFilterConfs['sample_ids'] = array_flip($arrFilterConfs['sample_ids']); $bolSampleExist = false; if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId'])) { foreach ($arrData['uiData']['queryInfo']['samplingId'] as $intSamId) { if (isset($arrFilterConfs['sample_ids'][$intSamId])) { $bolSampleExist = true; break; } } } if ($bolSampleExist === true && is_array($arrData['uiData'][$strEcResultKey]['ecResultItem']) && !empty($arrData['uiData'][$strEcResultKey]['ecResultItem'])) { // 遍历广告队列结果 foreach ($arrData['uiData'][$strEcResultKey]['ecResultItem'] as $intEcIndex => $arrEcItem) { if (isset($arrSampleConfs['EC'][$arrEcItem['id']])) { $bolSampleFlag = true; $arrTempConfs = $arrSampleConfs['EC'][$arrEcItem['id']]; foreach ($arrTempConfs as $intSrcIndex => $arrSrcInfo) { // check抽样id if (isset($arrSrcInfo['sample_ids']) && !empty($arrSrcInfo['sample_ids'])) { $arrSrcInfo['sample_ids'] = explode(',', $arrSrcInfo['sample_ids']); $arrSrcInfo['sample_ids'] = array_flip($arrSrcInfo['sample_ids']); $bolSampleExist = false; if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId'])) { foreach ($arrData['uiData']['queryInfo']['samplingId'] as $intSamId) { if (isset($arrSrcInfo['sample_ids'][$intSamId])) { $bolSampleExist = true; break; } } } if ($bolSampleExist === false) { continue; } } else { continue; } // 'src_ids' => // 'id1,leftResult;id2,rightResult;id3-id6,rightResult', // 解析src_ids串 $arrSrcInfo['src_ids'] = explode(';', $arrSrcInfo['src_ids']); $arrSrcInfoTemp = array(); $arrMinMaxInfo = array(); // 保存范围id,key为min_id,max_id,result foreach ($arrSrcInfo['src_ids'] as $intTemp => $strInfo) { $strInfo = explode(',', $strInfo); if (strpos($strInfo[0], '-') === false) { $arrSrcInfoTemp[$strInfo[0]] = $strInfo[1]; } else { $arrTemp = explode('-', $strInfo[0]); $arrMinMaxInfo[$arrTemp[0]] = array('min_id' => intval($arrTemp[0]), 'max_id' => intval($arrTemp[1]), 'result' => $strInfo[1]); unset($arrTemp); } } $arrSrcInfo['src_ids'] = $arrSrcInfoTemp; unset($arrSrcInfoTemp); // 找知心结果且flag为1,pk掉 // 循环处理leftResult,rightResult,topResult foreach ($GLOBALS['RESULT'] as $res) { if (is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { $intTotalCount = isset($arrFilterConfs[$res]) ? intval($arrFilterConfs[$res]) : 0; $intCurCount = 0; // 遍历知心队列结果,执行pk策略 foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) { if ($intTotalCount > 0 && $intCurCount >= $intTotalCount) { break; } $intCurCount++; if (isset($arrSrcInfo['src_ids'][$arrItem['dispData']['StdStg']]) && trim($arrSrcInfo['src_ids'][$arrItem['dispData']['StdStg']]) == trim($res) && 1 == intval($arrSrcInfo['flag'])) { unset($arrData['uiData'][$res]['item'][$intIndex]); $arrLogZhiIds[$arrItem['dispData']['StdStg']] = $arrItem['dispData']['StdStg']; // $bolFlag = true; } foreach ($arrMinMaxInfo as $intMinId => $arrMinInfo) { if (intval($arrItem['dispData']['StdStg']) >= $intMinId && intval($arrItem['dispData']['StdStg']) <= intval($arrMinInfo['max_id']) && trim($arrMinInfo['result']) == trim($res) && 1 == intval($arrSrcInfo['flag'])) { unset($arrData['uiData'][$res]['item'][$intIndex]); $arrLogZhiIds[$arrItem['dispData']['StdStg']] = $arrItem['dispData']['StdStg']; // $bolFlag = true; } } } } } unset($arrMinMaxInfo); } unset($arrTempConfs); } } } } // check是否有知心资源id在强需求配置中 $bolFilterFlag = false; if ($bolSampleFlag === false && isset($arrFilterConfs['src_ids']) && !empty($arrFilterConfs['src_ids'])) { $arrFilterConfs['src_ids'] = explode(',', $arrFilterConfs['src_ids']); $arrFilterConfs['src_ids'] = array_flip($arrFilterConfs['src_ids']); foreach ($GLOBALS['RESULT'] as $res) { if (is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { $intTotalCount = isset($arrFilterConfs[$res]) ? intval($arrFilterConfs[$res]) : 0; $intCurCount = 0; foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItemInfo) { if ($intTotalCount > 0 && $intCurCount >= $intTotalCount) { break; } $intCurCount++; if (isset($arrFilterConfs['src_ids'][$arrItemInfo['dispData']['StdStg']])) { $bolFilterFlag = true; break; } } } if ($bolFilterFlag === true) { break; } } } // $bolFlag = false; // $strEcResultKey = 'ecResult'; // 处理强需求策略 // 先处理知心屏蔽广告策略 $arrLogEcIds = array(); // $arrLogZhiIds = array (); if ($bolFilterFlag === true && is_array($arrProductConfs['ZHIXIN']) && !empty($arrProductConfs['ZHIXIN']) && is_array($arrData['uiData'][$strEcResultKey]['ecResultItem']) && !empty($arrData['uiData'][$strEcResultKey]['ecResultItem'])) { // 循环处理leftResult,rightResult,topResult foreach ($GLOBALS['RESULT'] as $res) { if (isset($arrProductConfs['ZHIXIN'][$res]) && !empty($arrProductConfs['ZHIXIN'][$res]) && is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { // 处理结果队列的每条结果 $intTotalCount = isset($arrFilterConfs[$res]) ? intval($arrFilterConfs[$res]) : 0; $intCurCount = 0; foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItemInfo) { if ($intTotalCount > 0 && $intCurCount >= $intTotalCount) { break; } $intCurCount++; if (isset($arrProductConfs['ZHIXIN'][$res][$arrItemInfo['dispData']['StdStg']])) { $arrTempConfs = $arrProductConfs['ZHIXIN'][$res][$arrItemInfo['dispData']['StdStg']]; // 遍历广告队列结果,执行屏蔽策略 foreach ($arrData['uiData'][$strEcResultKey]['ecResultItem'] as $intEcIndex => $arrEcItem) { foreach ($arrTempConfs as $intSrcIndex => $arrSrcInfo) { // check抽样id if (isset($arrSrcInfo['sample_ids']) && !empty($arrSrcInfo['sample_ids'])) { $arrSrcInfo['sample_ids'] = explode(',', $arrSrcInfo['sample_ids']); $arrSrcInfo['sample_ids'] = array_flip($arrSrcInfo['sample_ids']); $bolSampleExist = false; if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId'])) { foreach ($arrData['uiData']['queryInfo']['samplingId'] as $intSamId) { if (isset($arrSrcInfo['sample_ids'][$intSamId])) { $bolSampleExist = true; break; } } } if ($bolSampleExist === false) { continue; } } $arrSrcInfo['ec_ids'] = explode(',', $arrSrcInfo['ec_ids']); $arrSrcInfo['ec_ids'] = array_flip($arrSrcInfo['ec_ids']); // 找到广告且flag为1,pk掉 if (isset($arrSrcInfo['ec_ids'][$arrEcItem['id']]) && 1 == intval($arrSrcInfo['flag'])) { unset($arrData['uiData'][$strEcResultKey]['ecResultItem'][$intEcIndex]); $arrLogEcIds[$arrEcItem['id']] = $arrEcItem['id']; // $bolFlag = true; } } } unset($arrTempConfs); } } } } } // 处理广告pk知心策略 if ($bolFilterFlag === true && is_array($arrProductConfs['EC']) && !empty($arrProductConfs['EC']) && is_array($arrData['uiData'][$strEcResultKey]['ecResultItem']) && !empty($arrData['uiData'][$strEcResultKey]['ecResultItem'])) { // 遍历广告队列结果 foreach ($arrData['uiData'][$strEcResultKey]['ecResultItem'] as $intEcIndex => $arrEcItem) { if (isset($arrProductConfs['EC'][$arrEcItem['id']])) { $arrTempConfs = $arrProductConfs['EC'][$arrEcItem['id']]; foreach ($arrTempConfs as $intSrcIndex => $arrSrcInfo) { // check抽样id if (isset($arrSrcInfo['sample_ids']) && !empty($arrSrcInfo['sample_ids'])) { $arrSrcInfo['sample_ids'] = explode(',', $arrSrcInfo['sample_ids']); $arrSrcInfo['sample_ids'] = array_flip($arrSrcInfo['sample_ids']); $bolSampleExist = false; if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId'])) { foreach ($arrData['uiData']['queryInfo']['samplingId'] as $intSamId) { if (isset($arrSrcInfo['sample_ids'][$intSamId])) { $bolSampleExist = true; break; } } } if ($bolSampleExist === false) { continue; } } // 'src_ids' => // 'id1,leftResult;id2,rightResult;id3-id6,rightResult', // 解析src_ids串 $arrSrcInfo['src_ids'] = explode(';', $arrSrcInfo['src_ids']); $arrSrcInfoTemp = array(); $arrMinMaxInfo = array(); // 保存范围id,key为min_id,max_id,result foreach ($arrSrcInfo['src_ids'] as $intTemp => $strInfo) { $strInfo = explode(',', $strInfo); if (strpos($strInfo[0], '-') === false) { $arrSrcInfoTemp[$strInfo[0]] = $strInfo[1]; } else { $arrTemp = explode('-', $strInfo[0]); $arrMinMaxInfo[$arrTemp[0]] = array('min_id' => intval($arrTemp[0]), 'max_id' => intval($arrTemp[1]), 'result' => $strInfo[1]); unset($arrTemp); } } $arrSrcInfo['src_ids'] = $arrSrcInfoTemp; unset($arrSrcInfoTemp); // 找知心结果且flag为1,pk掉 // 循环处理leftResult,rightResult,topResult foreach ($GLOBALS['RESULT'] as $res) { if (is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { $intTotalCount = isset($arrFilterConfs[$res]) ? intval($arrFilterConfs[$res]) : 0; $intCurCount = 0; // 遍历知心队列结果,执行pk策略 foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) { if ($intTotalCount > 0 && $intCurCount >= $intTotalCount) { break; } $intCurCount++; if (isset($arrSrcInfo['src_ids'][$arrItem['dispData']['StdStg']]) && trim($arrSrcInfo['src_ids'][$arrItem['dispData']['StdStg']]) == trim($res) && 1 == intval($arrSrcInfo['flag'])) { unset($arrData['uiData'][$res]['item'][$intIndex]); $arrLogZhiIds[$arrItem['dispData']['StdStg']] = $arrItem['dispData']['StdStg']; // $bolFlag = true; } foreach ($arrMinMaxInfo as $intMinId => $arrMinInfo) { if (intval($arrItem['dispData']['StdStg']) >= $intMinId && intval($arrItem['dispData']['StdStg']) <= intval($arrMinInfo['max_id']) && trim($arrMinInfo['result']) == trim($res) && 1 == intval($arrSrcInfo['flag'])) { unset($arrData['uiData'][$res]['item'][$intIndex]); $arrLogZhiIds[$arrItem['dispData']['StdStg']] = $arrItem['dispData']['StdStg']; // $bolFlag = true; } } } } } unset($arrMinMaxInfo); } unset($arrTempConfs); } } } // 处理通用PK策略 // 处理知心pk广告 if (is_array($arrGeneralConfs['ZHIXIN']) && !empty($arrGeneralConfs['ZHIXIN']) && is_array($arrData['uiData'][$strEcResultKey]['ecResultItem']) && !empty($arrData['uiData'][$strEcResultKey]['ecResultItem'])) { foreach ($arrGeneralConfs['ZHIXIN'] as $intIndex => $arrEcInfos) { $bolDelFlag = false; $bolExcFlag = false; if (is_array($arrData['uiData'][$arrEcInfos['result']]['item']) && !empty($arrData['uiData'][$arrEcInfos['result']]['item'])) { $arrEcInfos['ec_ids'] = explode(',', $arrEcInfos['ec_ids']); $arrEcInfos['except_ids'] = explode(',', $arrEcInfos['except_ids']); $arrEcInfos['ec_ids'] = array_flip($arrEcInfos['ec_ids']); $arrEcInfos['except_ids'] = array_flip($arrEcInfos['except_ids']); // pk广告 foreach ($arrData['uiData'][$strEcResultKey]['ecResultItem'] as $intEcIndex => $arrEcItem) { if (isset($arrEcInfos['ec_ids'][$arrEcItem['id']])) { $bolDelFlag = true; } if (isset($arrEcInfos['except_ids'][$arrEcItem['id']])) { $bolExcFlag = true; } } if ($bolDelFlag === true && $bolExcFlag === false) { foreach ($arrData['uiData'][$strEcResultKey]['ecResultItem'] as $intEcIndex => $arrEcItem) { if (isset($arrEcInfos['ec_ids'][$arrEcItem['id']])) { unset($arrData['uiData'][$strEcResultKey]['ecResultItem'][$intEcIndex]); $arrLogEcIds[$arrEcItem['id']] = $arrEcItem['id']; } } } } } } if ($bolFilterFlag === false && $bolSampleFlag === false) { // 处理广告pk知心 if (is_array($arrGeneralConfs['EC']) && !empty($arrGeneralConfs['EC']) && is_array($arrData['uiData'][$strEcResultKey]['ecResultItem']) && !empty($arrData['uiData'][$strEcResultKey]['ecResultItem'])) { foreach ($arrGeneralConfs['EC'] as $intIndex => $arrConfInfo) { if (is_array($arrData['uiData'][$arrConfInfo['result']]['item']) && !empty($arrData['uiData'][$arrConfInfo['result']]['item'])) { $arrConfInfo['ec_ids'] = explode(',', $arrConfInfo['ec_ids']); $arrConfInfo['ec_ids'] = array_flip($arrConfInfo['ec_ids']); // pk知心 foreach ($arrData['uiData'][$strEcResultKey]['ecResultItem'] as $intEcIndex => $arrEcItem) { if (isset($arrConfInfo['ec_ids'][$arrEcItem['id']])) { unset($arrData['uiData'][$arrConfInfo['result']]); $arrLogZhiIds[$arrConfInfo['result']] = $arrConfInfo['result']; } } } } } } if (!empty($arrLogEcIds)) { $GLOBALS['logArr']['advertise_filtered'] = implode(',', $arrLogEcIds); } if (!empty($arrLogZhiIds)) { $GLOBALS['logArr']['zhixin_filtered'] = implode(',', $arrLogZhiIds); } return true; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrRightPromptStrategyConf = Util::getConf('/rightprompt', 'RIGHTPROMPT_STRATEGY'); $bolFlagFeature = Util::getConf('/feature', 'FEATURE_LIST/ADLEVEL/TURN') === 'ON' ? true : false; //避让策略时,广告标识(品专、地标) $arrCollisionEcIds = $arrRightPromptStrategyConf['COLLISION']['EC']; //共存策略时,知心资源号(攻略) $arrCoexistZhixinIds = $arrRightPromptStrategyConf['COEXIST']['ZHIXIN']; //PK策略时,知心资源号(百科、模糊推右) $arrPkZhixinIds = $arrRightPromptStrategyConf['PK']['ZHIXIN']; //命中pk策略标记 $bolPkStrategy = false; //命中共存策略标记 $bolCoexistStrategy = false; //命中避让策略标记 $bolCollisionStrategy = false; //判断是否存在右侧提示,若存在则记录其位置 $arrRightPromptIds = array(); if (isset($arrData['uiData']['queryInfo']['promptNode']) && is_array($arrData['uiData']['queryInfo']['promptNode'])) { foreach ($arrData['uiData']['queryInfo']['promptNode'] as $intKey => $arrOnePromptNode) { if (!empty($arrOnePromptNode['promptContent'])) { $arrPromptContent = json_decode($arrOnePromptNode['promptContent'], true); if (!empty($arrPromptContent) && !empty($arrPromptContent['hints']['RightTop'])) { $arrRightPromptIds[] = $intKey; } } } } //如果存在右侧提示,才进行策略PK,共存,避让 if (!empty($arrRightPromptIds)) { //如果后端有传广告标记,则按照后端标记来判断是否避让 if ($bolFlagFeature && isset($arrData['uiData']['ecResult']['adlevel'])) { $intFlag = $arrData['uiData']['ecResult']['adlevel'] >> 1 & 0x1; if ($intFlag != 0) { $bolCollisionStrategy = true; } } else { // 查找是否存在品专和地标 if (!$bolCollisionStrategy && !empty($arrCollisionEcIds) && isset($arrData['uiData']['ecResult']['ecResultItem']) && is_array($arrData['uiData']['ecResult']['ecResultItem'])) { foreach ($arrData['uiData']['ecResult']['ecResultItem'] as $arrOneEcItem) { if (!empty($arrOneEcItem['id']) && in_array($arrOneEcItem['id'], $arrCollisionEcIds)) { $bolCollisionStrategy = true; break; } } } } //未命中PK策略时,查找右侧知心 $arrPkZhixinIndexs = array(); if (!$bolCollisionStrategy && isset($arrData['uiData']['rightResult']['item']) && is_array($arrData['uiData']['rightResult']['item'])) { foreach ($arrData['uiData']['rightResult']['item'] as $intKey => $arrOneRightResultItem) { if (!empty($arrOneRightResultItem['dispData']['StdStg'])) { if (!empty($arrPkZhixinIds) && in_array($arrOneRightResultItem['dispData']['StdStg'], $arrPkZhixinIds)) { $bolPkStrategy = true; $arrPkZhixinIndexs[] = $intKey; } elseif (!empty($arrCoexistZhixinIds) && in_array($arrOneRightResultItem['dispData']['StdStg'], $arrCoexistZhixinIds)) { $bolCoexistStrategy = true; } else { $bolCollisionStrategy = true; } } } } //命中避让策略时,删除右侧提示 if ($bolCollisionStrategy && !empty($arrRightPromptIds)) { foreach ($arrRightPromptIds as $intKey) { unset($arrData['uiData']['queryInfo']['promptNode'][$intKey]); } $arrData['uiData']['queryInfo']['rightPromptStraFlag'] = 1; return true; } //命中共存策略时,直接返回 if ($bolCoexistStrategy) { $arrData['uiData']['queryInfo']['rightPromptStraFlag'] = 2; //右侧提示的展示样式(0:窄;1:宽;2:自适应) $arrData['uiData']['queryInfo']['promptStyle']['RightTop']['width'] = 2; return true; } //命中PK策略时,删除右侧百科知心和右侧模糊推右的知心 if ($bolPkStrategy && !empty($arrPkZhixinIndexs)) { foreach ($arrPkZhixinIndexs as $intKey) { unset($arrData['uiData']['rightResult']['item'][$intKey]); } $arrData['uiData']['queryInfo']['rightPromptStraFlag'] = 4; return true; } } return true; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrChallengerConf = Util::getConf('/tpl_rewrite', 'TPL_REWRITE'); // file_put_contents // ('/home/work/search/view-ui/data/data_ItemTplRewrite_conf', // serialize($arrTplConfs) ); // 防御者配置 $arrDefanderConf = array(); // 找出挑战者 foreach ($GLOBALS['RESULT'] as $res) { if (!empty($arrData['uiData'][$res]['item']) && is_array($arrData['uiData'][$res]['item'])) { // 添加队列Pk条件 $arrDefanderConf['Challenger_' . $res] = $arrChallengerConf['RESULT_PK']['Challenger_' . $res]; foreach ($arrData['uiData'][$res]['item'] as $item) { $intStdStg = $item['dispData']['StdStg']; $intStdStl = $item['dispData']['StdStl']; $strTpl = empty($item['dispData']['strategy']['tempName']) ? $item['dispData']['templateName'] : $item['dispData']['strategy']['tempName']; // 根据StdStg搜索 $arrChallengerConf_item = $arrChallengerConf['ITEM_PK']['Challenger_' . $intStdStg]; if (empty($arrChallengerConf_item)) { // 根据templateName搜索 $arrChallengerConf_item = $arrChallengerConf['ITEM_PK']['Challenger_' . $strTpl]; } if (empty($arrChallengerConf_item)) { // 没搜索到相关的配置 continue; } if (!empty($arrChallengerConf_item['tpl']) && $strTpl !== $arrChallengerConf_item['tpl']) { // 模板不匹配 continue; } if (!empty($arrChallengerConf_item['stdstg']) && $intStdStg !== $arrChallengerConf_item['stdstg']) { // stdstg不匹配 continue; } if (!empty($arrChallengerConf_item['stdstl']) && $intStdStl !== $arrChallengerConf_item['stdstl']) { // stdstl不匹配 continue; } $arrResults = explode(',', $arrChallengerConf_item['result']); if (!empty($arrChallengerConf_item['result']) && !empty($arrResults) && !in_array($res, $arrResults)) { // 队列不匹配 continue; } // 收集单条Pk条件 if (empty($arrDefanderConf['Challenger_item'])) { $arrDefanderConf['Challenger_item'] = $arrChallengerConf_item['Defander']; } else { $arrDefanderConf['Challenger_item'] = array_merge($arrDefanderConf['Challenger_item'], $arrChallengerConf_item['Defander']); } } } } // 对防御者进行惩罚 foreach ($GLOBALS['RESULT'] as $res) { if (!empty($arrData['uiData'][$res]['item']) && is_array($arrData['uiData'][$res]['item'])) { foreach ($arrData['uiData'][$res]['item'] as &$item) { $intStdStg = $item['dispData']['StdStg']; $intStdStl = $item['dispData']['StdStl']; $strTpl = empty($item['dispData']['strategy']['tempName']) ? $item['dispData']['templateName'] : $item['dispData']['strategy']['tempName']; $arrDefanderConf_item = array(); // 根据队列PK策略找到防御者进行惩罚 foreach ($GLOBALS['RESULT'] as $res_tmp) { // 根据StdStg搜索 $arrDefanderConf_item = $arrDefanderConf['Challenger_' . $res_tmp]['Defander_' . $intStdStg]; if (empty($arrDefanderConf_item)) { // 根据templateName搜索 $arrDefanderConf_item = $arrDefanderConf['Challenger_' . $res_tmp]['Defander_' . $strTpl]; } if (!empty($arrDefanderConf_item)) { // 找到了 break; } } // 根据单条PK策略找到防御者进行惩罚 if (empty($arrDefanderConf_item)) { // 根据StdStg搜索 $arrDefanderConf_item = $arrDefanderConf['Challenger_item']['Defander_' . $intStdStg]; if (empty($arrDefanderConf_item)) { // 根据templateName搜索 $arrDefanderConf_item = $arrDefanderConf['Challenger_item']['Defander_' . $strTpl]; } } if (empty($arrDefanderConf_item)) { // 没搜索到防御者惩罚配置 continue; } if (!empty($arrDefanderConf_item['tpl']) && $strTpl !== $arrDefanderConf_item['tpl']) { continue; } if (!empty($arrChallengerConf_item['stdstg']) && $intStdStg !== $arrChallengerConf_item['stdstg']) { // stdstg不匹配 continue; } if (!empty($arrDefanderConf_item['stdstl']) && $arrDefanderConf_item['stdstl'] != $intStdStl) { continue; } $arrResults = explode(',', $arrDefanderConf_item['result']); if (!empty($arrDefanderConf_item['result']) && !empty($arrResults) && !in_array($res, $arrResults)) { continue; } // 对防御者进行惩罚——修改对应的模板 if (isset($item['dispData']['strategy']['tempName'])) { $item['dispData']['strategy']['tempName'] = $arrDefanderConf_item['PunitiveAction']['tpl']; } else { $item['dispData']['templateName'] = $arrDefanderConf_item['PunitiveAction']['tpl']; } } } } return true; }
/** * 解析模板配置 * * @param $arrData unknown_type * @param $arrTplConfig unknown_type * @return boolean */ public function parseTplConfig(&$arrData, $arrTplConfig) { $arrQueryInfo =& $arrData['uiData']['queryInfo']; $arrHilightInfo =& $arrData['uiData']['hilightInfo']; $arrControlInfo =& $arrData['uiControl']; $arrUrlConfig = $arrQueryInfo['pUrlConfig']; // strategy unset($arrQueryInfo['strategyName']); $bolTnUnFeature = Util::getConf('/feature', 'FEATURE_LIST/TN_UN/TURN') === 'ON' ? true : false; if ($bolTnUnFeature) { $strTn = empty($arrData['uiData']['queryInfo']['accountName']) ? $GLOBALS['DEFAULT_TEMPLATE_NAME'] : $arrData['uiData']['queryInfo']['accountName']; $strStrategyName = shmdict_getValueFromDict($strTn, 'tn_un'); $arrQueryInfo['strategyName'] = empty($strStrategyName) ? 'baidu' : $strStrategyName; } else { if (isset($arrTplConfig['strategy'])) { $arrQueryInfo['strategyName'] = trim($arrTplConfig['strategy']); } else { if (!isset($arrQueryInfo['strategyName'])) { $arrQueryInfo['strategyName'] = DEFAULT_TEMPLATE_STRATEGY; } } } // services unset($arrControlInfo['services_ResultPage']); $arrServiceNames = explode(',', ALL_SERVICE); $arrServiceNames = array_flip($arrServiceNames); if (isset($arrTplConfig['services']) && !empty($arrTplConfig['services'])) { $arrServices = explode(',', $arrTplConfig['services']); $arrResultPage = array(); for ($i = 0; $i < MAX_SVR_NUM; $i++) { $arrResultPage[$i] = 0; } foreach ($arrServices as $key) { if (isset($arrServiceNames[$key]) && $arrServiceNames[$key] < MAX_SVR_NUM) { $arrResultPage[$arrServiceNames[$key]] = 1; } } $arrControlInfo['services_ResultPage'] = $arrResultPage; } unset($arrControlInfo['services_FrontPage']); if (isset($arrTplConfig['front_services']) && !empty($arrTplConfig['front_services'])) { $arrServices = explode(',', $arrTplConfig['front_services']); $arrResultPage = array(); for ($i = 0; $i < MAX_SVR_NUM; $i++) { $arrResultPage[$i] = 0; } foreach ($arrServices as $key) { if (isset($arrServiceNames[$key]) && $arrServiceNames[$key] < MAX_SVR_NUM) { $arrResultPage[$arrServiceNames[$key]] = 1; } } $arrControlInfo['services_FrontPage'] = $arrResultPage; } if (isset($arrTplConfig['ignore_url'])) { $arrControlInfo['ignoreUrl'] = intval($arrTplConfig['ignore_url']); } else { $arrControlInfo['ignoreUrl'] = 0; } if (isset($arrTplConfig['protectpp'])) { $arrControlInfo['protectppSwitch'] = intval($arrTplConfig['protectpp']); if ($arrControlInfo['protectppSwitch'] != PROTECTPP_SWITCH_OPEN) { $arrControlInfo['protectppSwitch'] = PROTECTPP_SWITCH_CLOSE; } } else { $arrControlInfo['protectppSwitch'] = PROTECTPP_SWITCH_CLOSE; } // 强制关闭了 $arrControlInfo['protectppSwitch'] = PROTECTPP_SWITCH_CLOSE; if (isset($arrTplConfig['needsp'])) { $arrQueryInfo['needSp'] = intval($arrTplConfig['needsp']); if ($arrQueryInfo['needSp'] < 0 || $arrQueryInfo['needSp'] > 1) { $arrQueryInfo['needSp'] = 0; } } else { $arrQueryInfo['needSp'] = 0; } if (isset($arrTplConfig['inter_page'])) { $arrQueryInfo['interPage'] = intval($arrTplConfig['inter_page']); } else { $arrQueryInfo['interPage'] = 0; } if (isset($arrTplConfig['resLimit'])) { $arrQueryInfo['resLimitSwitch'] = intval($arrTplConfig['resLimit']); if ($arrQueryInfo['resLimitSwitch'] != PROTECTPP_SWITCH_OPEN) { $arrQueryInfo['resLimitSwitch'] = PROTECTPP_SWITCH_CLOSE; } } else { $arrQueryInfo['resLimitSwitch'] = PROTECTPP_SWITCH_CLOSE; } unset($arrQueryInfo['wenkuUrlPara']); if (isset($arrTplConfig['special_pagetype_para'])) { $strTemp = $arrTplConfig['special_pagetype_para']; $arrTemp = str_split($strTemp); $bolFlag = true; foreach ($arrTemp as $char) { if (is_numeric($char) && $char >= 0 && $char <= 9) { continue; } else { if ($char == ',' || $char == '|') { continue; } else { $bolFlag = false; break; } } } if ($bolFlag === true) { $arrQueryInfo['wenkuUrlPara'] = WENKU_WAP_PC_KEY . '=' . $strTemp; } } /* * da所需资源号 */ unset($arrQueryInfo['daResource']); if (isset($arrTplConfig['da_resource'])) { $arrResource = explode(',', $arrTplConfig['da_resource']); $arrDaResource = array(); for ($i = 0; $i < DA_RES_COUNT; $i++) { if (isset($arrResource[$i])) { $arrDaResource[$i] = intval($arrResource[$i]); } else { $arrDaResource[$i] = 0; } } $arrQueryInfo['daResource'] = $arrDaResource; } // RS服务请求参数 $arrQueryInfo['needRsSeResult'] = isset($arrControlInfo['services_ResultPage'][SvrType_RS]) ? $arrControlInfo['services_ResultPage'][SvrType_RS] : 0; // ERS服务请求参数 $intEcomrsOpen = isset($arrQueryInfo['ecomrsOpen']) ? intval($arrQueryInfo['ecomrsOpen']) : 1; $intNeedERSResult = isset($arrControlInfo['services_ResultPage'][SvrType_ERS]) ? $arrControlInfo['services_ResultPage'][SvrType_ERS] : 0; if ($intEcomrsOpen == 1 && $intNeedERSResult == 1) { $arrQueryInfo['needERSResult'] = 1; } else { $arrQueryInfo['needERSResult'] = 0; } /* * 区分是否为内部流量 */ unset($arrQueryInfo['isInternalFlow']); if (isset($arrTplConfig['is_internal_flow'])) { $intFlowFlag = intval($arrTplConfig['is_internal_flow']); if ($intFlowFlag != 0 && $intFlowFlag != 1) { $intFlowFlag = 0; } $arrQueryInfo['isInternalFlow'] = $intFlowFlag; } if ($arrUrlConfig['f'] == FROM_RS && isset($arrTplConfig['pp_template_for_rs'])) { $arrQueryInfo['templateForRs'] = $arrTplConfig['pp_template_for_rs']; } else { $arrQueryInfo['templateForRs'] = $arrUrlConfig['tn']; } $arrEcSrc = array(); $intEcNum = 0; if (isset($arrTplConfig['ec_serial']) && !empty($arrTplConfig['ec_serial'])) { $arrTemp = explode(',', $arrTplConfig['ec_serial']); $count = 0; foreach ($arrTemp as $index => $value) { if ($count >= MAX_EC_SRC_NUM) { break; } $arrEcSrc[$index]['id'] = intval($value); $count++; } $intEcNum = $count; } if (isset($arrTplConfig['ec_templates']) && !empty($arrTplConfig['ec_templates'])) { $arrTemp = explode(',', $arrTplConfig['ec_templates']); $count = 0; foreach ($arrTemp as $index => $value) { if ($count >= MAX_EC_SRC_NUM) { break; } $arrEcSrc[$index]['template_name'] = trim($value); $count++; } if ($count < $intEcNum) { $intEcNum = $count; } } if ($intEcNum <= 0) { $intEcNum = 1; $arrEcSrc[0]['id'] = 2; $arrEcSrc[0]['template_name'] = "baidufsheadps"; } $arrSrcId = array(); $arrEcSrcs = array(); for ($i = 0; $i < $intEcNum; $i++) { $arrSrcId[] = $arrEcSrc[$i]['id']; $arrEcSrcs[$i]['id'] = isset($arrEcSrc[$i]['id']) ? intval($arrEcSrc[$i]['id']) : 0; $arrEcSrcs[$i]['req_num'] = isset($arrEcSrc[$i]['req_num']) ? intval($arrEcSrc[$i]['req_num']) : 0; $arrEcSrcs[$i]['ad_offset'] = isset($arrEcSrc[$i]['ad_offset']) ? intval($arrEcSrc[$i]['ad_offset']) : 0; $arrEcSrcs[$i]['charge_name'] = isset($arrEcSrc[$i]['charge_name']) ? $arrEcSrc[$i]['charge_name'] : ''; $arrEcSrcs[$i]['template_name'] = isset($arrEcSrc[$i]['template_name']) ? $arrEcSrc[$i]['template_name'] : 0; $arrEcSrcs[$i]['user_def'] = isset($arrEcSrc[$i]['user_def']) ? $arrEcSrc[$i]['user_def'] : ''; $arrEcSrcs[$i]['printInfo'] = isset($arrEcSrc[$i]['printInfo']) ? $arrEcSrc[$i]['printInfo'] : ''; } $arrQueryInfo['srcId'] = $arrSrcId; $arrQueryInfo['ec_src'] = $arrEcSrcs; // ASP服务迁移 $arrQueryInfo['needASPResult'] = isset($arrControlInfo['services_ResultPage'][SvrType_EC]) ? $arrControlInfo['services_ResultPage'][SvrType_EC] : 0; // confuse 广告和大搜索一致 // if (isset ( $arrTplConfig ['confuseResult'] )) { // $arrQueryInfo ['confuse_Switch'] = intval ( $arrTplConfig ['confuseResult'] ); // if ($arrQueryInfo ['confuse_Switch'] != PROTECTPP_SWITCH_OPEN) { // $arrQueryInfo ['confuse_Switch'] = PROTECTPP_SWITCH_CLOSE; // } // } else { // $arrQueryInfo ['confuse_Switch'] = PROTECTPP_SWITCH_CLOSE; // } /*****************************anti360 临时逻辑***************************************/ /** * 0-关闭 1-全开启 2-部分开启 非法或没传时默认0 */ if (isset($arrTplConfig['confuseResult'])) { $intConfuseResult = intval($arrTplConfig['confuseResult']); if ($intConfuseResult == PROTECTPP_SWITCH_OPEN || $intConfuseResult == PROTECTPP_SWITCH_PART_OPEN) { $arrQueryInfo['confuse_Switch'] = $intConfuseResult; } else { $arrQueryInfo['confuse_Switch'] = PROTECTPP_SWITCH_CLOSE; } } else { $arrQueryInfo['confuse_Switch'] = PROTECTPP_SWITCH_CLOSE; } /*********************************************************************************/ // 是否需要AS结果,包括AC和阿拉丁以及至知心 $arrQueryInfo['need_as_result'] = isset($arrControlInfo['services_ResultPage'][SvrType_AS]) ? $arrControlInfo['services_ResultPage'][SvrType_AS] : 0; // 结构化和阿拉丁飘红 $arrQueryInfo['protectPPSwitch'] = $arrControlInfo['protectppSwitch']; // 设置templateConfig $arrData['uiData']['templateConfig'] = $arrTplConfig; var_dump($arrData); // 设置hilight信息 unset($arrHilightInfo['hiFixInfo']['hilight_prefix']); if (isset($arrTplConfig['hilight_prefix'])) { $arrHilightInfo['hiFixInfo']['hilight_prefix'] = trim($arrTplConfig['hilight_prefix']); } unset($arrHilightInfo['hiFixInfo']['hilight_postfix']); if (isset($arrTplConfig['hilight_postfix'])) { $arrHilightInfo['hiFixInfo']['hilight_postfix'] = trim($arrTplConfig['hilight_postfix']); } unset($arrHilightInfo['hiFixInfo']['bold_prefix']); if (isset($arrTplConfig['bold_prefix'])) { $arrHilightInfo['hiFixInfo']['bold_prefix'] = trim($arrTplConfig['bold_prefix']); } unset($arrHilightInfo['hiFixInfo']['bold_postfix']); if (isset($arrTplConfig['bold_postfix'])) { $arrHilightInfo['hiFixInfo']['bold_postfix'] = trim($arrTplConfig['bold_postfix']); } return true; }
private function __construct() { $this->arrParaTemplateSelectorConf = Util::getConf('/template_choose', 'template_choose'); }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $arrRequeryConfs = Util::getConf('/requery', 'REQUERY_STRATEGY'); if (!is_array($arrRequeryConfs) || empty($arrRequeryConfs)) { return false; } // 超时重查处理策略,根据返回码做不同的处理,1表示超时重查 if (isset($arrData['uiControl']['retryCode']) && intval($arrRequeryConfs['timeout_code']) == intval($arrData['uiControl']['retryCode'])) { $strForLog = ''; $arrTimeoutRequery = $arrRequeryConfs['TIMEOUT_REQUERY']; if (!is_array($arrTimeoutRequery) || empty($arrTimeoutRequery['del_result']) && (empty($arrTimeoutRequery['result']) || empty($arrTimeoutRequery['come_from']) || empty($arrTimeoutRequery['count']))) { return false; } $arrDelResult = isset($arrTimeoutRequery['del_result']) ? explode(',', $arrTimeoutRequery['del_result']) : array(); $arrResult = isset($arrTimeoutRequery['result']) ? explode(',', $arrTimeoutRequery['result']) : array(); $arrComeFrom = isset($arrTimeoutRequery['come_from']) ? explode(',', $arrTimeoutRequery['come_from']) : array(); // 删除队列,待打印日志 if (is_array($arrDelResult) && !empty($arrDelResult)) { $arrDelResult = array_flip($arrDelResult); foreach ($GLOBALS['RESULT'] as $res) { if (isset($arrDelResult[$res]) && is_array($arrData['uiData'][$res]) && !empty($arrData['uiData'][$res])) { unset($arrData['uiData'][$res]); $strForLog .= $res . ','; } } } // 根据来源删除单条结果,待打印日志 $intDefaultCount = 20; $strForLogSingle = ''; $intCount = isset($arrTimeoutRequery['count']) ? intval($arrTimeoutRequery['count']) : $intDefaultCount; $intCurCount = 0; if (is_array($arrResult) && !empty($arrResult) && is_array($arrComeFrom) && !empty($arrComeFrom)) { $arrResult = array_flip($arrResult); $arrComeFrom = array_flip($arrComeFrom); foreach ($GLOBALS['RESULT'] as $res) { if (isset($arrResult[$res]) && is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { // 处理每条结果 $intCurCount = 0; $arrTempItem = array(); foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) { if ($intCurCount >= $intCount) { break; } if (!isset($arrComeFrom[$arrItem['comeFrome']])) { $arrTempItem[$intIndex] = $arrItem; $intCurCount++; // unset ( $arrData ['uiData'] [$res] ['item'] // [$intIndex] ); } } $arrData['uiData'][$res]['item'] = $arrTempItem; unset($arrTempItem); if (empty($strForLogSingle)) { $strForLogSingle = 'single'; } } } } $GLOBALS['logArr']['timeout_requery'] = $strForLog . $strForLogSingle; } return true; }
/** * @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; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } // 1. 获取图片限制策略相关配置,主要是行数和每行展现的个数, 区分pc和pad $picConf = Util::getConf('/right_pic_limit', 'PICTURE_FIELD'); $picCountPerLine = 0; $maxLineCount = 0; $platForm = $arrData['uiControl']['platform']; if ($platForm == 'pc') { $picCountPerLine = $picConf['PC']['PICTURE_COUNT_PERLINE']; $maxLineCount = $picConf['PC']['MAX_PICTURE_LINE']; } else { $picCountPerLine = $picConf['PAD']['PICTURE_COUNT_PERLINE']; $maxLineCount = $picConf['PAD']['MAX_PICTURE_LINE']; } // 2. get picture regex,这个功能本版暂不实现 //$picReg = $picConf['reg']; // 3. traverse all results, caculating pictures $rightResult =& $arrData['uiData']['rightResult']['item']; //var_dump($rightResult); if (is_array($rightResult) && !empty($rightResult)) { $totalLoop = 0; $totalLine = 0; do { $totalLine = 0; $maxIdx = 0; $maxCount = 0; $maxLine = 0; foreach ($rightResult as $itemIdx => &$arrItem) { if (empty($arrItem['multi_pic'])) { // has no picture continue; } $picCount = 0; $tplData =& $arrItem['dispData']['resultData']['tplData']; //this->count_pictures($tplData, $picReg, $picCount); // 获取图片个数 if (!isset($tplData['list#num#baidu'])) { $picCount = 1 * $picCountPerLine; } else { if (isset($tplData['showrow'])) { $picCount = $tplData['showrow'] * $picCountPerLine; } else { $picCount = $tplData['list#num#baidu']; } } // 计算图片行数 $picLineNum = ceil($picCount / $picCountPerLine); if ($picCount >= $maxCount) { $maxIdx = $itemIdx; $maxCount = $picCount; $maxLine = $picLineNum; } $totalLine += $picLineNum; } //echo $maxLineCount."\t".$totalLine; // 判断是否超出行数限制 if ($totalLine > $maxLineCount) { //echo "totalline".$totalLine."\tmaxCount:".$maxCount."\t"."maxline:".$maxLine."\n"; $tpl =& $rightResult[$maxIdx]['dispData']['resultData']['tplData']; if (isset($tpl['showrow'])) { // 增加隐藏的行 if ($tpl['showrow'] > 1) { $tpl['showrow'] = $tpl['showrow'] - 1; } } else { for ($index = $maxCount - 1; $index >= ($maxLine - 1) * $picCountPerLine; $index--) { // 更新图片个数 unset($tpl['list'][$index]); $tpl['list#num#baidu'] = count($tpl['list']); } } $totalLine -= 1; } $totalLoop += 1; } while ($totalLine > $maxLineCount && $totalLoop < self::MAXLOOPNUM); //var_dump($rightResult); } return true; }
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; }
/** * 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; }
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; }
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; }
public function run(&$arrData, $arrConf) { $arrControlInfo =& $arrData['uiControl']; $strPlatform = $arrControlInfo['platform']; $strLanguage = $arrControlInfo['language']; $strType = ''; $strTemplateName = ''; $arrConf = Util::getConf('/image_predict', 'IMAGE_PREDICT'); $arrResult = $arrConf['result']; $arrResult = explode(',', $arrResult); //图片列表改为左右区分 by lizhouq $imgListLeft = array(); $imgListRight = array(); $arrImgConf = array(); $arrDebugImgList = array(); foreach ($arrResult as $res) { if (is_array($arrData['uiData'][$res]['item']) && !empty($arrData['uiData'][$res]['item'])) { $imgList = array(); // 处理结果队列的每条结果 foreach ($arrData['uiData'][$res]['item'] as $intIndex => $arrItem) { $intRawCountImgNum = count($imgList); if (!empty($arrItem['dispData']['strategy']['type'])) { $strType = trim($arrItem['dispData']['strategy']['type']); } elseif ($arrItem['comeFrome'] == 'AS') { $strType = 'result'; } else { $strType = VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE; } $strTemplateName = !empty($arrItem['dispData']['strategy']['tempName']) ? trim($arrItem['dispData']['strategy']['tempName']) : trim($arrItem['dispData']['templateName']); // 获取tpl.conf内容 $arrImgConf = Util::load_image_tpl_conf($strPlatform, $strLanguage, $strType, $strTemplateName); if (is_array($arrImgConf) && !empty($arrImgConf)) { if (intval($arrImgConf['open_img_predict']) != 1) { continue; } if (is_array($arrImgConf['img']) && !empty($arrImgConf['img'])) { foreach ($arrImgConf['img'] as $arrImgData) { if (isset($arrItem['dispData']['ImageAladdinResult'])) { Util::parse_image_conf($arrItem['dispData'], $imgList, $arrImgData); } else { if (empty($arrItem['dispData']['resultData'])) { Util::parse_image_conf($arrItem['dispData'], $imgList, $arrImgData); } else { Util::parse_image_conf($arrItem['dispData']['resultData'], $imgList, $arrImgData); } } } } } //如果单条结果中图片数量超过了限制,则只取配置中的条数 $intLimitImgNum = intval($arrImgConf['img_num']); if ($intLimitImgNum > 0) { $intCurImgNum = count($imgList); if ($intCurImgNum - $intRawCountImgNum > $intLimitImgNum) { $imgList = array_slice($imgList, 0, $intRawCountImgNum + $intLimitImgNum); } } if ($GLOBALS['pre_img_debug'] === 1) { $intCurImgNum = count($imgList); if ($intCurImgNum > $intRawCountImgNum) { $arrAddImgList = array_slice($imgList, $intRawCountImgNum, $intCurImgNum - $intRawCountImgNum); if (empty($arrDebugImgList[$strTemplateName])) { $arrDebugImgList[$strTemplateName] = $arrAddImgList; } else { $arrDebugImgList[$strTemplateName][] = $arrAddImgList; } } } } //将取出的图片数组传入左/右侧队列 by lizhouq if (strcasecmp($res, "rightResult") === 0) { $imgListRight = array_merge($imgList, $imgListRight); } else { $imgListLeft = array_merge($imgList, $imgListLeft); } unset($imgList); } } //左右侧加起来不超过图片设定总数,右侧优先。 by lizhouq $intTotalLimitImgNum = intval($arrConf['img_num']); if ($intTotalLimitImgNum > 0) { $imgCurImgNumRight = count($imgListRight); if (count($imgListRight) > $intTotalLimitImgNum) { $imgListRight = array_slice($imgListRight, 0, $intTotalLimitImgNum); $imgListLeft = array(); } else { if (count($imgListLeft) + count($imgListRight) > $intTotalLimitImgNum) { $imgListLeft = array_slice($imgListLeft, 0, $intTotalLimitImgNum - $imgCurImgNumRight); } } } if ($GLOBALS['pre_img_debug'] === 1) { $GLOBALS['logArr']['pidug_set_imglist'] = json_encode($arrDebugImgList); } $imgSidListLeft = array(); $imgSidListRight = array(); //将url转为sid,供base64加载使用 foreach ($imgListLeft as $url) { $sid = Util::parse_image_urlToId($url); if ($sid !== false) { $imgSidListLeft[] = $sid; } } foreach ($imgListRight as $url) { $sid = Util::parse_image_urlToId($url); if ($sid !== false) { $imgSidListRight[] = $sid; } } //以下为创建新版图片预取缓存结构。 by lizhouq $arrData['uiData']['queryInfo']['viewConfig']['normalImgList']['left']['urlList'] = $imgListLeft; $arrData['uiData']['queryInfo']['viewConfig']['normalImgList']['left']['sidList'] = $imgSidListLeft; $arrData['uiData']['queryInfo']['viewConfig']['normalImgList']['right']['urlList'] = $imgListRight; $arrData['uiData']['queryInfo']['viewConfig']['normalImgList']['right']['sidList'] = $imgSidListRight; unset($imgListLeft); unset($imgListRight); unset($imgSidListLeft); unset($imgSidListRight); }
private function __construct() { $this->arrInstantSearchConf = Util::getConf('/instant_search', 'IS'); }
/** * @desc * render for hhvm branch * @author * chenjinsheng/ 2013/11/22 * @param * data - render data * result - result page ... * smarty - smarty object instance */ function render_hhvm($data, $smarty, &$result) { $start = $start0 = Volatile::microtime(true) * 1000; // if hhvm turned on, disable multi-renderer temporarily $featurePrerender = $GLOBALS['globalConf']['FEATURE_LIST']['PREDATA']['TURN']; $featureMultirender = $GLOBALS['globalConf']['FEATURE_LIST']['MULTI_RENDER']['TURN']; # $GLOBALS['globalConf']['FEATURE_LIST']['PREDATA']['TURN'] = 'OFF'; $GLOBALS['globalConf']['FEATURE_LIST']['MULTI_RENDER']['TURN'] = 'OFF'; $arrMultiRenderConf = $GLOBALS['globalConf']['MULTI_RENDER']; $memsize = intval($arrMultiRenderConf['SHMOP']['MEM_SIZE']); if (($arrShmData = put_data_into_shm_once($data, $memsize)) === false) { $tempresult = redo_render($data, $smarty, $featurePrerender, $featureMultirender, "put data into shm failed"); $result['page'] .= $tempresult['page']; $result['status'] = $tempresult['status']; $result['msg'] = $tempresult['msg']; return $result['status']; } $GLOBALS['logArr']['time_hhvm_shm'] = round(1000 * Volatile::microtime(true) - $start, 2); $url = Util::getConf('/hhvm', 'HHVM_RENDER_URL'); $start = Volatile::microtime(true) * 1000; $strReqKey = 'hhvm'; $intLogId = $arrShmData['id']; $hexQid = $data['uiData']['queryInfo']['queryId']; $strMainUrl = $url . '?renderType=' . $strReqKey . '&logId=' . $intLogId . '&qid=' . $hexQid; $intMainTplTimeout = intval(Util::getConf('/hhvm', 'HHVM_RENDER_TIMEOUT')); $arrMainPostData = array(); $intRandTime = CSmarty::getRandState(); $arrMainPostData['tempName'] = $data['uiControl']['templateName']; $arrMainPostData['tempSwitch'] = $data['uiControl']['templateSwitch']; $arrMainPostData['tempVersion'] = $data['uiControl']['templateVersion']; $arrMainPostData['platform'] = $data['uiControl']['platform']; $arrMainPostData['dataId'] = $arrShmData['id']; $arrMainPostData['dataSize'] = $arrShmData['size']; $arrMainPostData['randTime'] = $intRandTime; $obj = curl_init($strMainUrl); curl_setopt($obj, CURLOPT_HEADER, 0); curl_setopt($obj, CURLOPT_NOSIGNAL, true); curl_setopt($obj, CURLOPT_RETURNTRANSFER, 1); curl_setopt($obj, CURLOPT_POST, 1); curl_setopt($obj, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($obj, CURLOPT_POSTFIELDS, http_build_query($arrMainPostData)); curl_setopt($obj, CURLOPT_TIMEOUT_MS, $intMainTplTimeout); $GLOBALS['logArr']['time_hhvm_curl_init'] = round(1000 * Volatile::microtime(true) - $start, 2); $start = Volatile::microtime(true) * 1000; $ret = curl_exec($obj); $GLOBALS['logArr']['time_hhvm_curl_exec'] = round(1000 * Volatile::microtime(true) - $start, 2); if ($ret === false) { $tempresult = redo_render($data, $smarty, $featurePrerender, $featureMultirender, "curl time out"); $result['page'] .= $tempresult['page']; $result['status'] = $tempresult['status']; $result['msg'] = $tempresult['msg']; return $result['status']; } $start = Volatile::microtime(true) * 1000; $arrRst = unserialize($ret); $GLOBALS['logArr']['time_hhvm_unserialize'] = round(1000 * Volatile::microtime(true) - $start, 2); if (empty($arrRst)) { $tempresult = redo_render($data, $smarty, $featurePrerender, $featureMultirender, "render failed"); $result['page'] .= $tempresult['page']; $result['status'] = $tempresult['status']; $result['msg'] = $tempresult['msg']; return $result['status']; } if ($arrRst[$strReqKey]['page'] === false) { CLog::warning("hhvm render page error"); } else { $result['page'] .= $arrRst[$strReqKey]['page']; } $result['status'] = $arrRst[$strReqKey]['status']; // Logging... $arrLogInfo = $arrRst['pack_log']; $GLOBALS['logArr'] = array_merge($GLOBALS['logArr'], $arrLogInfo['logArr']); $GLOBALS['logArr']['time_hhvm_render'] = $arrLogInfo['time_main_tpl']; $GLOBALS['time_count_temp']['time_aladdin_total'] += $arrLogInfo['time_aladdin_total']; $GLOBALS['time_count_temp']['render_aladdin_num'] += $arrLogInfo['render_aladdin_num']; $GLOBALS['time_count_temp']['time_urlencrypt_total'] += $arrLogInfo['time_urlencrypt_total']; CSmarty::addStructTplRenderNumCount($arrLogInfo['render_struct_tpl_num']); CSmarty::addStructTplRenderTimeCount($arrLogInfo['time_render_struct_tpl']); $arrResultTplTm = $arrLogInfo['result_tpl_tm']; if (!empty($arrResultTplTm) && is_array($arrResultTplTm)) { foreach ($arrResultTplTm as $intOneTplTm) { CSmarty::recordResultTplRenderTime($intOneTplTm); } } curl_close($obj); $GLOBALS['logArr']['time_hhvm_total'] = round(1000 * Volatile::microtime(true) - $start0, 2); return $result['status']; }
/** * 将url、post中的参数打包起来传给us * 我只是从ui移植到vui * * @param $strUrlParam unknown_type * @param $strPostData unknown_type * @param $strTemplateNameMod unknown_type */ public function packUrlParam($strUrlParam, $strPostData, $strTemplateNameMod, $arrCookieInfo) { $intOpenAdvancedModify = Util::getConf('/view-ui', 'GLOBAL/OPEN_ADVANCED_MODIFY'); if ($intOpenAdvancedModify < 1) { $intOpenAdvancedModify = OPEN_ADVANCED_MODIFY; } $arrQueryPart = array(); if (!empty($strUrlParam)) { $intSplit = strpos($strUrlParam, '?'); if ($intSplit !== false) { $strQueryInfo = substr($strUrlParam, $intSplit + 1); $arrQueryPart = self::URLRewiteAdvance($strQueryInfo, $intOpenAdvancedModify); } } $arrPostData = array(); parse_str($strPostData, $arrPostData); unset($arrPostData['f']); if (!empty($strTemplateNameMod) && !empty($arrPostData['tn'])) { $arrPostData['tn'] = $strTemplateNameMod; } if (!is_array($arrQueryPart)) { $arrQueryPart = array(); } //加入对safe参数的校验 // if(isset($arrQueryPart['baidu_safe'])){ // if($arrQueryPart['baidu_safe'] == 1|| $arrQueryPart['baidu_safe'] == 0){ // $arrQueryPart['baidu_safe'] = intval($arrQueryPart['baidu_safe']); // }else{ // unset($arrQueryPart['baidu_safe']); // } // } if (!is_array($arrPostData)) { $arrPostData = array(); } $arr = array_merge($arrQueryPart, $arrPostData); if (!empty($arrCookieInfo)) { $arr = array_merge($arr, $arrCookieInfo); } foreach ($arr as $key => $value) { if ($value == '') { //value类型均为string,包括0 unset($arr[$key]); } } $arr = Util::mcpack_normal($arr); $str = mc_pack_array2pack($arr); return $str; }
public function get_sample_variable($arrData, $exp_name, $default) { $sample_variable = $default; //for small flow $arrSample = Util::getConf('/sample_variable', 'sample_variable/' . $exp_name); if (is_array($arrData['uiData']['queryInfo']['samplingId']) && !empty($arrData['uiData']['queryInfo']['samplingId']) && is_array($arrSample) && !empty($arrSample)) { $arrSids = $arrData['uiData']['queryInfo']['samplingId']; $arrSids = array_flip($arrSids); foreach ($arrSample['Contexted'] as $arrTemp) { if (isset($arrSids[$arrTemp['sampling_id']])) { $sample_variable = $arrTemp['value']; break; } } } return $sample_variable; }
public static function chunked($data, $bolSplitTpl, $arrHeader, $arrUrlConfig) { $templateName = $data['uiControl']['templateName']; $templateType = $data['uiControl']['templateType']; $templateSwitch = $data['uiControl']['templateSwitch']; $platform = $data['uiControl']['platform']; $requestType = $data['uiControl']['type']; $nginxMainPage = $data['uiControl']['isNginxMainPage']; $accountName = $data['uiControl']['oriAccountName']; //模板拆分开关 if (!$bolSplitTpl) { return false; } if ($GLOBALS['PS-ISASYNCFLAG'] == 1) { return false; } //chunked 开关 $bolChunked = Util::getConf('/feature', 'FEATURE_LIST/CHUNKED/TURN') === 'ON' ? true : false; if (!$bolChunked) { return false; } //url 开关 if ($arrUrlConfig['bd_ck'] != '1') { return false; } //判断是否单包渲染 && head 请求不chunked if ($_SERVER['REQUEST_METHOD'] == 'HEAD' || $_SERVER['DOCUMENT_URI'] == '/chunked_retry') { return false; } $templateInfo = Util::getConf('/chunked', 'ChunkedTpl'); //tn 目前暂时不判断 /* $tnInfo = $templateInfo['tn']; $tnArr = explode(',',$tnInfo); if(!in_array($accountName,$tnArr)){ return false; } */ //兼容代码 if (isset($_COOKIE['BD_CK'])) { return false; } //黑名单机制,在黑名单中的不走chunked if (!empty($templateInfo[$templateType])) { $templateNameInfo = $templateInfo[$templateType]['templateName']; if (!empty($templateNameInfo)) { $templateNameArr = explode(',', $templateNameInfo); if (!empty($templateNameArr) && is_array($templateNameArr) && in_array($templateName, $templateNameArr)) { return false; } } } //判断是否支持GZIP $encodeArr = explode(',', $arrHeader['ACCEPT-ENCODING']); if (!in_array('gzip', $encodeArr)) { return false; } if ($platform === 'pc' && $templateSwitch != 2 && $requestType != 'detect' && $nginxMainPage == 2) { //抽样处理 $bolSample = Util::getConf('/feature', 'FEATURE_LIST/CHUNKED_SAMPLE/TURN') === 'ON' ? true : false; if ($bolSample) { $chunkedSimpleId = 4460; if (is_array($data['uiData']['queryInfo']['samplingId']) && !empty($data['uiData']['queryInfo']['samplingId'])) { $arrSids = $data['uiData']['queryInfo']['samplingId']; $arrSids = array_flip($arrSids); if (isset($arrSids[$chunkedSimpleId])) { return true; } } return false; } else { $chunkedSimpleId = 4461; if (is_array($data['uiData']['queryInfo']['samplingId']) && !empty($data['uiData']['queryInfo']['samplingId'])) { $arrSids = $data['uiData']['queryInfo']['samplingId']; $arrSids = array_flip($arrSids); if (isset($arrSids[$chunkedSimpleId])) { return false; } } return true; } } return false; }
public function run(&$arrData, $arrConf) { if (empty($arrData) || !is_array($arrData)) { return false; } $bolFlagFeature = Util::getConf('/feature', 'FEATURE_LIST/ADLEVEL/TURN') === 'ON' ? true : false; if ($bolFlagFeature) { // 右侧安全提示存在,且后端传入的adlevel最低位为1时,展现消保提示 $bolRightPromptExist = false; if (isset($arrData['uiData']['queryInfo']['promptNode']) && is_array($arrData['uiData']['queryInfo']['promptNode'])) { foreach ($arrData['uiData']['queryInfo']['promptNode'] as $intKey => $arrOnePromptNode) { if (!empty($arrOnePromptNode['promptContent'])) { $arrPromptContent = json_decode($arrOnePromptNode['promptContent'], true); if (!empty($arrPromptContent) && !empty($arrPromptContent['hints']['RightTop'])) { $bolRightPromptExist = true; break; } } } } if ($bolRightPromptExist && isset($arrData['uiData']['ecResult']['adlevel'])) { $intFlag = $arrData['uiData']['ecResult']['adlevel'] & 0x1; $intPinzhuanFlag = $arrData['uiData']['ecResult']['adlevel'] >> 2 & 0x1; if ($intFlag === 1 && $intPinzhuanFlag == 0) { $arrData['uiData']['ecResult']['securityPlanTip'] = 1; } return true; } } // 有知心右侧队列时不出提示 if (!empty($arrData['uiData']['rightResult']['item'])) { return true; } //如果后端有传标识,则按照标识来判断是否出消保提示 // $bolFlagFeature = (Util::getConf('/feature', 'FEATURE_LIST/ADLEVEL/TURN') === 'ON') ? true : false; if ($bolFlagFeature && isset($arrData['uiData']['ecResult']['adlevel'])) { $intFlag = $arrData['uiData']['ecResult']['adlevel'] & 0x1; $intPinzhuanFlag = $arrData['uiData']['ecResult']['adlevel'] >> 2 & 0x1; if ($intFlag === 1 && $intPinzhuanFlag == 0) { $arrData['uiData']['ecResult']['securityPlanTip'] = 1; } } else { $arrHitIds = array(EC_FC_PP, EC_FC_PPIM_UL); $arrExcludeIds = array(EC_PP_ZQ, EC_PP_DB, EC_PP_DB_2, EC_PP_QTZ); $bolHit = false; $bolExclude = false; foreach ($arrData['uiData']['ecResult']['ecResultItem'] as $item) { if ($bolHit === false && in_array($item['id'], $arrHitIds)) { // 存在这些广告时需要出提示 $bolHit = true; } else { if ($bolExclude === false && in_array($item['id'], $arrExcludeIds)) { // 存在这些广告时不出提示 $bolExclude = true; } } } if ($bolHit === true && $bolExclude === false) { // 存在凤巢广告但不存在品牌广告时 $arrData['uiData']['ecResult']['securityPlanTip'] = 1; } } return true; }