/**
  * @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;
 }
Exemple #2
0
 public function load_image_tpl_conf($platform, $language, $type, $templateName)
 {
     /**
      * load config
      */
     $tplConfPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $platform, $language, $type);
     /**
      * not tend to encrypt url
      */
     if (!file_exists("{$tplConfPath}/{$templateName}/tpl.conf")) {
         return false;
     }
     if (filesize("{$tplConfPath}/{$templateName}/tpl.conf") == 0) {
         return false;
     }
     /**
      * load configure file
      *
      * 这种方式不合理,考虑优化为require php文件数组方式。
      */
     $conf = TplConf::config_load("{$tplConfPath}/{$templateName}", "tpl.conf");
     /**
      * load configure file failed
      */
     if (false === $conf) {
         /**
          * default log config
          */
         $status = $GLOBALS['STATUS_CODE']['LOAD_TPLCONF_FAIL'];
         $logArr['platform'] = $platform;
         $logArr['language'] = $language;
         $logArr['type'] = $type;
         $logArr['templateName'] = $templateName;
         CLog::warning($GLOBALS['STATUS_MSG'][$status] . ", load tpl config fail", $status, $logArr, 1);
         return false;
     }
     $arrImgConf = array();
     foreach ($conf['img'] as $key => $value) {
         $temp_path = array();
         $path_array = explode('[]', $value);
         foreach ($path_array as $path) {
             $new_path = array();
             $path_item = explode('.', $path);
             foreach ($path_item as $item) {
                 $item = trim($item);
                 if (!empty($item)) {
                     $new_path[] = $item;
                 }
             }
             if (!empty($new_path)) {
                 $temp_path[] = implode('.', $new_path);
             }
         }
         if (!empty($temp_path)) {
             $arrImgConf[] = $temp_path;
         }
     }
     $conf['img'] = $arrImgConf;
     return $conf;
 }
 /**
  * 模板选择
  *
  * @param $arrData unknown_type       	
  * @return true or false
  */
 public function getUserInfo(&$arrData)
 {
     if (empty($arrData) || !is_array($arrData)) {
         CLog::warning("tpl select is wrong, param err!");
         return false;
     }
     // Flag
     if (Util::getConf('/feature', 'FEATURE_LIST/TemplateSelector/TURN') !== 'ON') {
         return true;
     }
     // 读取tn和tplName
     // $arrAccounts = Util::getConf ( '/accounts', 'ACCOUNT_TPLNAME' );
     // $arrTplTypes = Util::getConf ( '/tpl_type', 'TEMPLATE_TYPE' );
     require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
     if (!isset($arrTplTypes)) {
         CLog::warning("tpl select is wrong, require tpl type err!");
         return false;
     }
     $arrQueryInfo =& $arrData['uiData']['queryInfo'];
     $arrHilightInfo =& $arrData['uiData']['hilightInfo'];
     $arrControlInfo =& $arrData['uiControl'];
     $arrUrlConfig = $arrQueryInfo['pUrlConfig'];
     $arrTplConfig = array();
     $strTn = "";
     $strTplName = "";
     if (isset($arrControlInfo['oriAccountName']) && !empty($arrControlInfo['oriAccountName']) && isset($arrControlInfo['oriTplName']) && !empty($arrControlInfo['oriTplName'])) {
         $strTn = trim($arrControlInfo['oriAccountName']);
         $strTplName = trim($arrControlInfo['oriTplName']);
     }
     // 处理首页模板
     /* if ($arrData ['uiControl'] ['templateSwitch'] == 2) {
     			$strTn = isset ( $arrUrlConfig ['tn'] ) ? trim ( $arrUrlConfig ['tn'] ) : '';
     			$strTplName = "";
     			if (! empty ( $strTn )) {
     				$strTplName = get_value_by_key ( $strTn );
     			}
     			if (empty ( $strTplName )) {
     				$arrUrlConfig ['tn'] = trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
     			}
     			// return true;
     		} */
     /* when useing debug page. */
     if (!empty($GLOBALS['DEBUG_PAGE_TN']) && strcasecmp($GLOBALS['DEBUG_PAGE_TN'], $strTn) == 0) {
         $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
     } else {
         // tn选择模板
         /* $strTn = isset ( $arrUrlConfig ['tn'] ) ? trim ( $arrUrlConfig ['tn'] ) : trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
         			$strTplName = "";
         			if (! empty ( $strTn )) {
         				$strTplName = get_value_by_key ( $strTn );
         			}
         			if (! empty ( $strTplName )) {
         				$arrControlInfo ['templateName'] = $strTplName;
         			} else {
         				$arrUrlConfig ['tn'] = trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
         				$arrControlInfo ['templateName'] = trim ( $GLOBALS ['DEFAULT_TEMPLATE_NAME'] );
         				$arrQueryInfo ['strategyName'] = BAIDU_TEMPLATE;
         			} */
         if (!empty($strTn) && !empty($strTplName)) {
             $arrUrlConfig['tn'] = $strTn;
             $arrControlInfo['templateName'] = $strTplName;
         } else {
             $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
         }
         // 是否是站内搜索,是则选模板SITE_SEARCH_TEMP_PP
         if (isset($arrUrlConfig['sts'])) {
             $arrUrlConfig['sts'] = trim($arrUrlConfig['sts']);
             if (!empty($arrUrlConfig['sts'])) {
                 if (isset($arrQueryInfo['isHideSite']) && intval($arrQueryInfo['isHideSite']) == 1 && isset($arrTplTypes[$GLOBALS['TEMP_SITE_NOPP']])) {
                     $arrControlInfo['templateName'] = $GLOBALS['TEMP_SITE_NOPP'];
                 } else {
                     if (isset($arrTplTypes[$GLOBALS['TEMP_SITE_PP']])) {
                         $arrControlInfo['templateName'] = $GLOBALS['TEMP_SITE_PP'];
                     }
                 }
             }
         }
     }
     // 模板类型
     $arrPlatForm = array();
     if (isset($arrTplTypes[$arrControlInfo['templateName']])) {
         $arrControlInfo['templateType'] = $arrTplTypes[$arrControlInfo['templateName']]['type'];
         $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
     } else {
         $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrControlInfo['templateType'] = trim($GLOBALS['DEFAULT_TEMPLATE_TYPE']);
         $arrPlatForm[] = trim($GLOBALS['DEFAULT_PLATFORM']);
     }
     // 平台检查
     if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
         if (count($arrPlatForm) >= 2) {
             $arrControlInfo['platform'] = $arrPlatForm[1];
         } else {
             $arrControlInfo['platform'] = $arrPlatForm[0];
         }
         $arrQueryInfo['dspName'] = "";
     }
     //dsp参数处理
     if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
         if (empty($arrData['uiData']['queryInfo']['dspName'])) {
             $arrData['uiData']['queryInfo']['dspName'] = "ipad";
             CLog::warning("dspName is not ipad when using pad template.");
         }
     }
     //检查模板目录是否存在,不存在使用baidu模板
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'];
     if (!file_exists($strTplConfigPath)) {
         $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
         $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
         // 模板类型
         unset($arrPlatForm);
         $arrPlatForm = array();
         if (isset($arrTplTypes[$arrControlInfo['templateName']])) {
             $arrControlInfo['templateType'] = $arrTplTypes[$arrControlInfo['templateName']]['type'];
             $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
         } else {
             $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateType'] = trim($GLOBALS['DEFAULT_TEMPLATE_TYPE']);
             $arrPlatForm[] = trim($GLOBALS['DEFAULT_PLATFORM']);
         }
         // 平台检查
         if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
             if (count($arrPlatForm) >= 2) {
                 $arrControlInfo['platform'] = $arrPlatForm[1];
             } else {
                 $arrControlInfo['platform'] = $arrPlatForm[0];
             }
             $arrQueryInfo['dspName'] = "";
         }
     }
     // 获取模板配置信息
     unset($strTplConfigPath);
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
     if (!file_exists($strTplConfigPath)) {
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateType'] . '.cfg.php';
         if (!file_exists($strTplConfigPath)) {
             $arrControlInfo['templateName'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrControlInfo['templateType'] = trim($GLOBALS['DEFAULT_TEMPLATE_TYPE']);
             $arrUrlConfig['tn'] = trim($GLOBALS['DEFAULT_TEMPLATE_NAME']);
             $arrQueryInfo['strategyName'] = BAIDU_TEMPLATE;
             $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
             if (!file_exists($strTplConfigPath)) {
                 $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateType'] . '.cfg.php';
                 if (!file_exists($strTplConfigPath)) {
                     $arrControlInfo['platform'] = trim($GLOBALS['DEFAULT_PLATFORM']);
                     $arrControlInfo['language'] = trim($GLOBALS['DEFAULT_LANGUAGE']);
                     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
                     if (!file_exists($strTplConfigPath)) {
                         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $arrControlInfo['templateType']) . $arrControlInfo['templateType'] . '.cfg.php';
                         if (!file_exists($strTplConfigPath)) {
                             CLog::warning("tpl select is wrong, cfg not existed!");
                             return false;
                         }
                     }
                 }
             }
         }
     }
     $arrQueryInfo['accountName'] = $arrUrlConfig['tn'];
     $arrData['uiControl']['tplConfigPath'] = $strTplConfigPath;
     $arrData['uiControl']['tplConfigName'] = $arrControlInfo['templateName'];
     $arrData['uiControl']['tplConfigType'] = $arrControlInfo['templateType'];
     /* $arrTplConfig = $this->getTplConfig ( $strTplConfigPath );
     		if (! is_array ( $arrTplConfig ) || empty ( $arrTplConfig ) || count ( $arrTplConfig ) <= 0) {
     			// log
     			CLog::warning ( "tpl select is wrong, getting cfg err!" );
     			return false;
     		}
     		
     		// 处理首页模板
     		if ($arrData ['uiControl'] ['templateSwitch'] == 2) {
     			$arrFrontPage = Util::getConf ( '/frontpage', 'FRONTPAGE/LOGO' );
     			if (! empty ( $arrFrontPage ) && is_array ( $arrFrontPage )) {
     				foreach ( $arrFrontPage as $key => $value ) {
     					$arrTplConfig [$key] = $value;
     				}
     			}
     		}
     		
     		// 解析模板配置项
     		$bolRet = $this->parseTplConfig ( $arrData, $arrTplConfig ); */
     return true;
 }
 public function checkTemplateConfig(&$arrData)
 {
     require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
     if (!isset($arrTplTypes)) {
         CLog::warning("tpl param select is wrong, require tpl type err!");
         return false;
     }
     $arrQueryInfo =& $arrData['uiData']['queryInfo'];
     $arrControlInfo =& $arrData['uiControl'];
     $arrUrlConfig = $arrQueryInfo['pUrlConfig'];
     $strType = $arrTplTypes[$arrControlInfo['templateName']]['type'];
     $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
     // 平台检查
     if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
         CLog::warning("tpl param select is not matching");
         return false;
     }
     //dsp参数处理
     if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
         if (empty($arrData['uiData']['queryInfo']['dspName'])) {
             $arrData['uiData']['queryInfo']['dspName'] = "ipad";
             CLog::warning("dspName is not ipad when using pad template.");
         }
     }
     $strTplPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $arrControlInfo['templateName'];
     if (!file_exists($strTplPath)) {
         return false;
     }
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
     if (!file_exists($strTplConfigPath)) {
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strType . '.cfg.php';
     }
     if (!file_exists($strTplConfigPath)) {
         CLog::warning("tpl cfg is not existed, tplname : " . $strTplName);
         return false;
     }
     $arrData['uiControl']['tplSamplingPath'] = $strTplConfigPath;
     $arrControlInfo['templateType'] = $strType;
     return true;
 }