コード例 #1
0
/**
 *
 *
 * @file modifier.url_limit.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:40
 */
function smarty_modifier_url_limit($string, $length, $escaped = false)
{
    $logArr['smarty_modifier'] = "modifier_url_limit";
    $status = 0;
    $logArr['url'] = $string;
    $logArr['limit_len'] = $length;
    $logArr['escaped'] = $escaped;
    if (strlen($string) == 0) {
        $result = $string;
        return $result;
    }
    $result = trim(hilight_url_limit($string, $length, $escaped));
    $resultTmp = explode(" ", $result);
    $result = implode("", $resultTmp);
    if (false === $result) {
        $result = $string;
        $status = -1;
        $logArr['result'] = $result;
        CLog::warning("fail to call hilight_url_limit", $status, $logArr, 1);
        return $string;
    }
    $logArr['result'] = $result;
    CLog::debug("success to call url_limit", $status, $logArr, 1);
    return $result;
}
コード例 #2
0
/**
 *
 *
 * @file modifier.url_bold_html.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:40
 */
function smarty_modifier_url_bold_html($string)
{
    $logArr['smarty_modifier'] = "modifier_url_bold_html";
    $status = 0;
    $logArr['string'] = $string;
    if (strlen($string) == 0) {
        $result = $string;
        return $result;
    }
    $prefix = $GLOBALS['DISPLAY']['BOLD_PREFIX'];
    $suffix = $GLOBALS['DISPLAY']['BOLD_SUFFIX'];
    $logArr['prefix'] = $prefix;
    $logArr['suffix'] = $suffix;
    $result = hilight_url_bold_html($string, $prefix, $suffix);
    if (false === $result) {
        $result = $string;
        $status = -1;
        $logArr['result'] = $result;
        CLog::warning("fail to call hilight_url_bold_html", $status, $logArr, 1);
        return $result;
    }
    $logArr['result'] = $result;
    CLog::debug("success to call url_bold_html modifier", $status, $logArr, 1);
    return $result;
}
コード例 #3
0
/**
 *
 *
 * @file modifier.strlen_character.php
 * @package plugins
 * @purpose: Calculate the number of characters of a string
 * @author chenchen20@baidu.com
 * @date 2014-03-07 14:02
 */
function smarty_modifier_strlen_character($string)
{
    $logArr['smarty_modifier'] = "modifier_strlen_character";
    $status = 0;
    $intI = 0;
    $intCount = 0;
    $logArr['string'] = $string;
    $intLength = strlen($string);
    if ($intLength == 0) {
        $status = -1;
        CLog::warning("string is empty", $status, $logArr, 1);
        return 0;
    }
    while ($intI < $intLength) {
        $chrAscii = ord($string[$intI]);
        //按字节转成ascii码
        $intCount++;
        $intI++;
        if ($intI >= $intLength) {
            break;
        }
        if ($chrAscii & 0x80) {
            //汉字的两个字符ascii码都大于0x80,此处判断是否为汉字
            $chrAscii <<= 1;
            while ($chrAscii & 0x80) {
                //判断为汉字,$intCount自增1.
                $intI++;
                $chrAscii <<= 1;
            }
        }
    }
    return $intCount;
}
コード例 #4
0
ファイル: function.widget.php プロジェクト: drehere/shenmegui
/**
 *
 *
 * @file function.widget.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_function_widget($params, Smarty_Internal_Template $template)
{
    $logArr['smarty_function'] = "function_widget";
    $name = $params['name'];
    $tpl_path = $params['path'];
    $fn = 'smarty_template_function_' . $name;
    $type = $template->smarty->getTemplateVars('_TEMPLATE_TYPE');
    $logArr['widget_name'] = $name;
    $logArr['widget_type'] = $type;
    $logArr['widget_path'] = $tpl_path;
    if (!function_exists($fn)) {
        //$tpl_path = CSmarty::getWidgetPath($type, $name);
        if (!$template->smarty->templateExists($tpl_path)) {
            $log_str = "widget not found :{$tpl_path}";
            CSmarty::addError($log_str);
            CLog::warning($log_str, -1, $logArr, 1);
            return false;
        }
        $template->smarty->fetch($tpl_path);
    }
    if (!function_exists($fn)) {
        $log_str = "template function {$fn} not found";
        CSmarty::addError($log_str);
        CLog::warning($log_str, -1, $logArr, 1);
        return false;
    } else {
        $result = $fn($template, $params);
    }
    return $result;
}
コード例 #5
0
ファイル: modifier.domain.php プロジェクト: drehere/shenmegui
/**
 *
 *
 * @file modifier.domain.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_modifier_domain($string, $encodeURI = false)
{
    $logArr['smarty_modifier'] = "modifier_domain";
    $status = 0;
    $logArr['url'] = $string;
    $domain = $string;
    if (strncasecmp($domain, "http://", 7) == 0) {
        $domain = substr($domain, 7);
    } elseif (strncasecmp($domain, "url:", 4) == 0) {
        $pos = strspn($domain, " ", 4);
        $domain = substr($domain, 4 + $pos);
        if (strncasecmp($domain, "http://", 7) == 0) {
            $domain = substr($domain, 7);
        }
    }
    if (strlen($domain) == 0) {
        $domain = $string;
    }
    if ($encodeURI) {
        $result = hilight_encodeURI($domain);
        $logArr['result'] = $result;
        if (false === $result) {
            $status = -1;
            CLog::warning("fail to call hilight_domain", $status, $logArr, 1);
            return $domain;
        }
    } else {
        $result = $domain;
    }
    return $result;
}
コード例 #6
0
ファイル: ImagePredict.php プロジェクト: drehere/shenmegui
 public function setItem($key, $val, $expiration = 0)
 {
     //$val = implode(' ',$val);
     $val = serialize($val);
     $rc = $this->_cacheBase->set($key, $val, $expiration);
     if (false === $rc) {
         CLog::warning("ImgPredict setItem failed," . $this->_cacheBase->getErrMsg());
     }
     return $rc;
 }
コード例 #7
0
ファイル: CssHeadJsFoot.php プロジェクト: drehere/shenmegui
 public static function getCssJs($type, $arrTplNames, $arrCSSUI)
 {
     $cssStr = '';
     $jsStr = '';
     $cssUI = '';
     $strLog = '';
     $uiArr = array();
     // 必须去重
     $arrTplNames = array_keys(array_flip($arrTplNames));
     $arrSmartyConf = CSmarty::getConf();
     // 预处理CSS、JS合并,读取文件
     foreach ($arrTplNames as $tpl) {
         $cssjsPath = CSmarty::getHeadCssFootJsPath(VUI_TEMPLATE_PATH, $arrSmartyConf['platform'], $arrSmartyConf['language'], $type, $tpl);
         if (!file_exists($cssjsPath)) {
             continue;
         }
         require "{$cssjsPath}";
         $strLog .= $tpl . '(';
         $className = 'CssJs_Util_' . $tpl;
         if (class_exists($className) && method_exists($className, 'getHeadCss')) {
             $cssStr .= call_user_func(array($className, 'getHeadCss'));
             if (!empty($cssStr)) {
                 $strLog .= 'css,';
             }
         }
         if (class_exists($className) && method_exists($className, 'getFootJs')) {
             $jsStr .= call_user_func(array($className, 'getFootJs'));
             if (!empty($jsStr)) {
                 $strLog .= 'js,';
             }
         }
         if (class_exists($className) && method_exists($className, 'getCssUI')) {
             $arrUis = call_user_func(array($className, 'getCssUI'));
             if (!empty($arrUis) && is_array($arrUis)) {
                 $uiArr = array_merge($uiArr, $arrUis);
                 $strLog .= implode('_', $arrUis);
             }
         }
         $strLog .= ')';
     }
     $uiArr = array_unique($uiArr);
     if (!empty($uiArr)) {
         // 通用组件的位置放在大搜索目录下
         foreach ($uiArr as $ui) {
             if (empty($arrCSSUI[$ui]['common'])) {
                 CLog::warning("Invalid UiCss:{$ui}");
             } else {
                 $cssUI .= $arrCSSUI[$ui]['common'];
             }
         }
     }
     $GLOBALS['logArr']['merge'] = $strLog;
     return array('cssMerge' => $cssUI . ' ' . $cssStr, 'jsMerge' => $jsStr);
 }
コード例 #8
0
ファイル: GetDict.php プロジェクト: drehere/shenmegui
 public function init($tplTimeDictIncludeFile)
 {
     if (file_exists("{$tplTimeDictIncludeFile}")) {
         require $tplTimeDictIncludeFile;
         if (!isset($arrDictTplTime) || empty($arrDictTplTime) || !is_array($arrDictTplTime)) {
             CLog::warning("get multi_render tplname dict is wrong, require tpl time err!");
             return false;
         }
         if (empty(self::$Dict)) {
             self::$Dict = $arrDictTplTime;
             return true;
         }
     } else {
         self::$Dict = array();
         CLog::warning("get multi_render tplname dict is wrong, dict[{$tplTimeDictIncludeFile}] is not exist!");
         return false;
     }
 }
コード例 #9
0
/**
 *
 *
 * @file modifier.encodeURI.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:50
 */
function smarty_modifier_encodeURI($uri)
{
    $logArr['smarty_modifier'] = "modifier_encodeURI";
    $status = 0;
    $logArr['uri'] = $string;
    if (strlen($uri) == 0) {
        $status = -1;
        CLog::warning("uri is empty", $status, $logArr, 1);
        return $uri;
    }
    $result = hilight_encodeURI($uri);
    if (false === $result) {
        $status = -1;
        CLog::warning("fail to call hilight_encodeURI", $status, $logArr, 1);
        return $uri;
    }
    return $result;
}
コード例 #10
0
/**
 * @file modifier.urlsign.php
 * @author search(com@baidu.com)
 * @date 2014/02/18 18:53:32
 * @brief 
 *  
 **/
function smarty_modifier_urlsign($uri)
{
    $logArr['smarty_modifier'] = "modifier_urlsign";
    $status = 0;
    $logArr['uri'] = $string;
    if (strlen($uri) == 0) {
        $status = -1;
        CLog::warning("uri is empty", $status, $logArr, 1);
        return $uri;
    }
    $result = hilight_url_sign($uri);
    if (false === $result) {
        $status = -1;
        CLog::warning("fail to call url_sign_64", $status, $logArr, 1);
        return $uri;
    }
    // result[0] : 站点签名
    // result[1] : url签名
    return $result[1];
}
コード例 #11
0
/**
 *
 * @param $strImgSrc unknown_type       	
 * @return boolean unknown data-src={%$ls.src%} data-b64-id={%$ls.imgkey%}>
 *         <img src={%$ls.src%}>
 *        
 */
function smarty_modifier_img_base64_render($strImgSrc)
{
    if (empty($strImgSrc)) {
        CLog::warning("fail to get img base64 src id, src null");
        return false;
    }
    $arrQueryInfo = CSmarty::getQueryInfo();
    $strPage = "";
    if (!isset($arrQueryInfo['base64']) || $arrQueryInfo['base64'] !== 'on') {
        $strPage = 'src="' . $strImgSrc . '"';
        return $strPage;
    }
    if (!isset($arrQueryInfo['base64_sids_for_plugin']) || empty($arrQueryInfo['base64_sids_for_plugin'][$strImgSrc])) {
        $strPage = 'src="' . $strImgSrc . '"';
        return $strPage;
    } else {
        $strPage = 'data-src="' . $strImgSrc . '" ' . 'data-b64-id="' . $arrQueryInfo['base64_sids_for_plugin'][$strImgSrc] . '"';
        CLog::debug("get img base64 src id OK");
        return $strPage;
    }
}
コード例 #12
0
ファイル: modifier.real.php プロジェクト: drehere/shenmegui
/**
 *
 *
 * @file modifier.real.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_modifier_real($string)
{
    $logArr['smarty_modifier'] = "modifier_real";
    $status = 0;
    $logArr['string'] = $string;
    if (strlen($string) == 0) {
        $result = $string;
        return $result;
    }
    $result = hilight_real($string);
    if (false == $result) {
        $result = $string;
        $status = -1;
        $logArr['result'] = $result;
        CLog::warning("fail to call hilight_real", $status, $logArr, 1);
        return $string;
    }
    $logArr['result'] = $result;
    CLog::debug("success to call real modifier", $status, $logArr, 1);
    return $result;
}
コード例 #13
0
/**
 *
 *
 * @file modifier.vui_escape.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:51
 */
function smarty_modifier_vui_escape($string, $type = "html")
{
    $logArr['smarty_modifier'] = "modifier_vui_escape";
    $type = strtolower($type);
    $status = 0;
    $logArr['string'] = $string;
    $logArr['type'] = $type;
    if (strlen($string) == 0) {
        $result = $string;
        $status = -1;
        //CLog::warning("string is empty", $status, $logArr, 1);
        return $result;
    }
    switch ($type) {
        case "html":
            $type = ":h";
            break;
        case "javascript":
            $type = ":j";
            break;
        case "url":
            $type = ":u";
            break;
        default:
            $type = ":h";
            break;
    }
    $result = hilight_escape($string, ":[utf8]" . $type);
    if (false === $result) {
        $result = $string;
        $status = -1;
        $logArr['result'] = $result;
        CLog::warning("fail to call vui_escape", $status, $logArr, 1);
        return $result;
    }
    $logArr['result'] = $result;
    CLog::debug("success to call vui_escape", $status, $logArr, 1);
    return $result;
}
コード例 #14
0
/**
 *
 *
 * @file modifier.zhidaoXmlTrans.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_modifier_zhidaoXmlTrans()
{
    $logArr['smarty_modifier'] = "modifier_zhidaoXmlTrans";
    /**
     * hilight info
     * @var array
     */
    $hilight_info = CSmarty::getHilightInfo();
    $hi_word = $hilight_info['hilightInfo']['hi_word'];
    $hi_off = $hilight_info['hilightInfo']['hi_off'];
    $hi_num = $hilight_info['hilightInfo']['hi_num'];
    $status = 0;
    if (isset($hi_off[0])) {
        $hi_off[0] = 0;
    }
    $result = hilight_zhidaoXmlTrans($hi_word, $hi_off, $hi_num);
    if (false == $result) {
        $status = -1;
        CLog::warning("fail to call hilight_zhidaoXmlTrans", $status, $logArr, 1);
        return false;
    }
    CLog::debug("success to call zhidaoXmlTrans modifier", $status, $logArr, 1);
    return $result;
}
コード例 #15
0
 /**
  * @param unknown_type $arrData
  * @return boolean
  */
 public function get_sampling_template(&$arrData)
 {
     if ($arrData['uiControl']['templateSwitch'] == 2) {
         $arrTplSample = Util::getConf('/sample_variable', 'sample_variable/FRONT_PAGE_INDEX');
     } else {
         $arrTplSample = Util::getConf('/sample_variable', 'sample_variable/RESULT_PAGE_INDEX');
     }
     if (!is_array($arrTplSample) || empty($arrTplSample)) {
         //CLog::warning ( "tpl sampling conf is null" );
         return false;
     }
     $arrSids = $arrData['uiData']['queryInfo']['samplingId'];
     $arrSids = array_flip($arrSids);
     $strTplName = "";
     foreach ($arrTplSample['Contexted'] as $arrTemp) {
         if (isset($arrSids[$arrTemp['sampling_id']])) {
             $strTplName = $arrTemp['value'];
             break;
         }
     }
     if (!empty($strTplName)) {
         //$arrTplTypes = Util::getConf ( '/tpl_type', 'TEMPLATE_TYPE' );
         require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
         if (!isset($arrTplTypes)) {
             CLog::warning("tpl sampling is wrong, require tpl type err!");
             return false;
         }
         $arrControlInfo =& $arrData['uiControl'];
         // 模板类型
         $arrPlatForm = array();
         $strType = "";
         if (isset($arrTplTypes[$strTplName])) {
             $strType = $arrTplTypes[$strTplName]['type'];
             $arrPlatForm = $arrTplTypes[$strTplName]['platform'];
         } else {
             CLog::warning("tpl sampling is wrong, tpl type not existed!");
             return false;
             //	$strType = trim ( $GLOBALS ['DEFAULT_TEMPLATE_TYPE'] );
             //	$arrPlatForm [] = trim ( $GLOBALS ['DEFAULT_PLATFORM'] );
         }
         // 平台检查
         if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
             CLog::warning("tpl platform is not matching");
             return false;
         }
         //dsp参数处理
         if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
             if (empty($arrData['uiData']['queryInfo']['dspName'])) {
                 $arrData['uiData']['queryInfo']['dspName'] = "ipad";
                 CLog::warning("dspName is not ipad when using pad template.");
             }
         }
         // 检查模板配置
         $bolFlag = false;
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strTplName . '/' . $strTplName . '.cfg.php';
         if (file_exists($strTplConfigPath)) {
             $bolFlag = true;
         } else {
             $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strType . '.cfg.php';
             if (file_exists($strTplConfigPath)) {
                 $bolFlag = true;
             } else {
                 CLog::warning("tpl cfg is not existed, tplname : " . $strTplName);
                 return false;
             }
         }
         if ($bolFlag === true) {
             //补充
             /* $objTemplateSelector = new TemplateSelector ();
             			$arrTplConfig = $objTemplateSelector->getTplConfig ( $strTplConfigPath );
             			if (! is_array ( $arrTplConfig ) || empty ( $arrTplConfig ) || count ( $arrTplConfig ) <= 0) {
             				// log
             				CLog::warning ( "tpl sampling is wrong, getting cfg err!" );
             				return false;
             			}
             			
             			// 处理首页模板
             			if ($arrData ['uiControl'] ['templateSwitch'] == 2) {
             				$arrFrontPage = Util::getConf ( '/frontpage', 'FRONTPAGE/LOGO' );
             				if (! empty ( $arrFrontPage ) && is_array ( $arrFrontPage )) {
             					foreach ( $arrFrontPage as $key => $value ) {
             						$arrTplConfig [$key] = $value;
             					}
             				}
             			} */
             $arrData['uiControl']['tplSamplingPath'] = $strTplConfigPath;
             $arrControlInfo['templateName'] = $strTplName;
             $arrControlInfo['templateType'] = $strType;
             return true;
             // 解析模板配置项
             //	$bolRet = $objTemplateSelector->parseTplConfig ( $arrData, $arrTplConfig );
             //	CLog::debug ( "tpl sampling tplname : " . $strTplName );
             //	return $bolRet;
         }
     }
     return false;
 }
コード例 #16
0
ファイル: strategy.php プロジェクト: drehere/shenmegui
function strategy(&$data)
{
    if (!empty($GLOBALS['STRATEGY']['USE_STRATEGY']) && is_array($GLOBALS['STRATEGY']['USE_STRATEGY'])) {
        foreach ($GLOBALS['STRATEGY']['USE_STRATEGY'] as $key => $value) {
            $fn = $GLOBALS['STRATEGY' . $value]['STRATEGY_FUNCTION'];
            if (function_exists($fn)) {
                $fn($data, $value);
            } else {
                $status = $GLOBALS['STATUS_CODE']['FUNCTION_NOT_EXIST'];
                CLog::warning($GLOBALS['STATUS_MSG'][$status] . " [{$fn}]", $status);
            }
        }
    }
}
コード例 #17
0
/**
 * 通用的单条渲染插件,可渲染aladdin、result、ecom等目录下;
 * 不能渲染midpage、xml、data和baidu下的完整页面模板
 *
 * @package plugins
 * @author jiachunxin@baidu.com
 */
function smarty_modifier_common_render($data, $type, $templateName, $curr_sort = false)
{
    if ($GLOBALS['mulit_render_flag'] === 1) {
        $key = $data['multi_render_key'];
        if (empty($key)) {
            CLog::warning("empty_key!", 1);
        }
        return $key;
    }
    $logArr['smarty_modifier'] = "common_render";
    $conf = CSmarty::getConf();
    $language = $conf['language'];
    $platform = $conf['platform'];
    $logArr['template_type'] = $type;
    $logArr['template_name'] = $templateName;
    $logArr['language'] = $language;
    $logArr['platform'] = $platform;
    $logArr['StdStg'] = $data['StdStg'];
    // result目录下的模板不统计性能
    $time_start = Volatile::microtime(true) * 1000;
    if ($type != $GLOBALS['STRUCT_TEMPLATE_TYPE']) {
        $log_key = $data['StdStg'] . '_' . $templateName;
    } else {
        CSmarty::addStructTplRenderNumCount();
    }
    if (empty($type)) {
        CLog::warning("template type is empty", -1, $logArr, 1);
        return false;
    }
    if (empty($templateName)) {
        CLog::warning("template name is empty", -1, $logArr, 1);
        return false;
    }
    if (empty($data['resultData']['tplData']) || !is_array($data['resultData']['tplData'])) {
        CLog::warning("tplData is empty", -1, $logArr, 1);
        return false;
    }
    $data['resultData']['queryInfo'] = CSmarty::getQueryInfo();
    $data['resultData']['templateConfig'] = CSmarty::getTemplateConfig();
    if ($curr_sort === false) {
        $curr_sort = 0;
    } else {
        $curr_sort += 1;
    }
    $data['resultData']['extData']['curr_sort'] = $curr_sort;
    // page renderer
    $smarty = CSmarty::getInstance(array('language' => $language, 'type' => $type, 'platform' => $platform));
    if (false === $smarty) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        $logArr[$type . '_smarty_error'] = $errors_str;
        CLog::warning("fail to get instance of smarty, type: {$type}", $status, $logArr, 1);
        return false;
    }
    // encrypt page's url
    backend_encrypt_url($data, $platform, $language, $type, $templateName);
    // render page
    $page = $smarty->do_render($data, $templateName, 1);
    if (empty($page)) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        CLog::warning("fail to render " . $type . " page, errors[{$errors_str}],info[{$log_key}]", $status, $logArr, 1);
        return false;
    }
    $tm_cost = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    // result目录下的模板不统计性能
    if ($type != $GLOBALS['STRUCT_TEMPLATE_TYPE']) {
        $GLOBALS['logArr']["aladdin_page_size_{$log_key}"] = strlen($page);
        $GLOBALS['logArr']["time_aladdin_{$log_key}"] = $tm_cost;
        $GLOBALS['time_count_temp']['time_aladdin_total'] += $tm_cost;
        $GLOBALS['time_count_temp']['render_aladdin_num']++;
    } else {
        CSmarty::addStructTplRenderTimeCount($tm_cost);
        // result模板也统计性能,合并打印
        CSmarty::recordResultTplRenderTime($tm_cost);
    }
    return $page;
}
コード例 #18
0
 /**
  * 获取模板配置
  *
  * @param
  *       	 $strTplConfigPath
  * @return array
  */
 public function getTplConfig($strTplConfigPath)
 {
     require $strTplConfigPath;
     if (!isset($arrPhpTplConfigs)) {
         // log
         CLog::warning("tpl select is wrong, include cfg err!");
         return array();
     }
     // check配置项
     $arrTplConfig = array();
     foreach ($arrPhpTplConfigs as $key => $value) {
         if (strlen($key) > TEMP_CONFIG_KEY_LEN || strlen($value) > TEMP_CONFIG_VALUE_LEN) {
             // log
             CLog::warning("tpl select is wrong, cfg item too long!");
             return array();
         }
         if (isset($arrTplConfig[$key])) {
             // log
             CLog::warning("cfg item is already existed!");
             continue;
         }
         $arrTplConfig[$key] = $value;
     }
     // 转码
     /* $error_key = array ();
     		iconv_data ( $arrTplConfig, APP_ENCODING, $GLOBALS ['UI_ENCODING'], "tplconfig", $error_key );
     		foreach ( $error_key as $k => $v ) {
     			$GLOBALS ['logArr'] [$k] = $v;
     		}
     		if (! empty ( $error_key )) {
     			CLog::warning ( "tpl config convert encoding err" );
     		} */
     return $arrTplConfig;
 }
コード例 #19
0
ファイル: smarty_render.php プロジェクト: drehere/shenmegui
/**
 * 并行渲染
 * @param unknown_type $data
 * @param unknown_type $smarty
 * @param unknown_type uiData中阿拉丁的数据
 * @param unknown_type uiData中普通结果的数据
 */
function multi_render($data, $smarty, $arrAlaData, $arrAsData, $arrMultiRenderConf)
{
    $time_start = Volatile::microtime(true) * 1000;
    require VUI_APP_PATH . '/plugins/modifier.common_render.php';
    $arrNeedRenderSingleResult = array_merge($arrAlaData, $arrAsData);
    $time_multi_start = Volatile::microtime(true) * 1000;
    $mh = curl_multi_init();
    $url = $arrMultiRenderConf['MULTI_RENDER_URL'];
    $arrRenderMultiReq = array();
    $arrMultiPublicData = array();
    $arrMultiPublicData['smarty_conf'] = CSmarty::getConf();
    $arrMultiPublicData['DISPLAY'] = $GLOBALS['DISPLAY'];
    $arrMultiPublicData['LOG'] = $GLOBALS['LOG'];
    $arrMultiPublicData['DEFAULT_TEMPLATE_NAME'] = $GLOBALS['DEFAULT_TEMPLATE_NAME'];
    $arrMultiPublicData['DEFAULT_TEMPLATE_TYPE'] = $GLOBALS['DEFAULT_TEMPLATE_TYPE'];
    $arrMultiPublicData['ALADDIN_TEMPLATE_TYPE'] = $GLOBALS['ALADDIN_TEMPLATE_TYPE'];
    $arrMultiPublicData['STRUCT_TEMPLATE_TYPE'] = $GLOBALS['STRUCT_TEMPLATE_TYPE'];
    $arrMultiPublicData['ECOM_TEMPLATE_TYPE'] = $GLOBALS['ECOM_TEMPLATE_TYPE'];
    $arrMultiPublicData['randTime'] = CSmarty::getRandState();
    $arrMultiPublicData['TplLOG'] = $GLOBALS['TplLOG'];
    $arrMultiPublicData['ALADDIN_FIELD'] = $GLOBALS['ALADDIN_FIELD'];
    $arrMultiPublicData['globalConf'] = $GLOBALS['globalConf'];
    $data['uiData']['multi_public_data'] = $arrMultiPublicData;
    //使用logid来计算存放在共享内存中的key
    $intLogId = CLog::logId();
    $memsize = intval($arrMultiRenderConf['SHMOP']['MEM_SIZE']);
    // 共享内存的大小,单位byte
    $perm = 0666;
    // 共享内存访问权限,参考linux的权限
    $shmid = shmop_open($intLogId, "n", $perm, $memsize);
    // 创建一个共享内存,第二个参数c表示创建
    $shm_bytes_written = shmop_write($shmid, addslashes(serialize($data['uiData'])), 0);
    $arrShmData['id'] = $intLogId;
    $arrShmData['size'] = $shm_bytes_written;
    unset($data['uiData']['multi_public_data']);
    //若向共享内存中存放数据失败,则直接跳出并行渲染,回归正常渲染
    if ($arrShmData['id'] === false || empty($arrShmData['size'])) {
        CLog::warning("put data to shmop fail,back to nomarl render,data_size:" . strlen(addslashes(serialize($data['uiData']))), MULTI_RENDER_FAIL);
        return false;
    }
    $GLOBALS['multi_render_shmid'] = $shmid;
    //主模板加入并发队列
    $strReqKey = 'req_main';
    $arrMainPostData = array();
    $intRandTime = CSmarty::getRandState();
    $arrMainPostData['tempName'] = $data['uiControl']['templateName'];
    $arrMainPostData['tempSwitch'] = $data['uiControl']['templateSwitch'];
    $arrMainPostData['tempVersion'] = empty($data['uiControl']['templateVersion']) ? "" : $data['uiControl']['templateVersion'];
    $arrMainPostData['dataId'] = $arrShmData['id'];
    $arrMainPostData['dataSize'] = $arrShmData['size'];
    $arrMainPostData['randTime'] = $intRandTime;
    $hexQid = $data['uiData']['queryInfo']['queryId'];
    $strMainUrl = $url . '?renderType=' . $strReqKey . '&logId=' . $intLogId . '&qid=' . $hexQid;
    $intMainTplTimeout = intval($arrMultiRenderConf['MAIN_TPL_TIMEOUT_MS']);
    $arrRenderMultiReq[$strReqKey] = curl_init($strMainUrl);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HEADER, 0);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_NOSIGNAL, true);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POST, 1);
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HTTPHEADER, array('Expect:'));
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POSTFIELDS, http_build_query($arrMainPostData));
    curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_TIMEOUT_MS, $intMainTplTimeout);
    curl_multi_add_handle($mh, $arrRenderMultiReq[$strReqKey]);
    //按时间分包(尽可能均分),时间参数来自于进生的模板耗时报表
    //分包数量,主模板单独占用一个包
    $intSplitNum = intval($arrMultiRenderConf['PACK_NUM']) - 1;
    $arrTplTime = array();
    $intTimeCount = 0;
    $arrSplitReqData = array();
    // 分阿拉丁
    if (!empty($arrAlaData) && is_array($arrAlaData)) {
        $intDefaultAladdinTime = $arrMultiRenderConf['DEFAULT_ALADDIN_TIME'];
        $bHhvm = $GLOBALS['globalConf']['FEATURE_LIST']['HHVM_BRANCH']['TURN'] === 'ON' ? true : false;
        if ($bHhvm) {
            $getDict = new GetDict();
            $getDict->init(DATA_PATH . "/shmdict/dict/tpl_time.php");
        }
        foreach ($arrAlaData as $strKey => $arrOneAlaData) {
            if ($bHhvm) {
                //hhvm 临时方案,提前手动分发tpl_time.php文件到data/shmdict/dict/下
                $intOneTplTime = $getDict->getValueFromDict($arrOneAlaData['render_template']);
            } else {
                $intOneTplTime = shmdict_getValueFromDict($arrOneAlaData['render_template'], 'tpl_time');
            }
            $intOneTplTime = empty($intOneTplTime) ? $intDefaultAladdinTime : $intOneTplTime;
            $intTimeCount += $intOneTplTime;
            $arrTplTime[$strKey] = $intOneTplTime;
        }
        arsort($arrTplTime);
        $intSplitTplTime = ceil($intTimeCount / $intSplitNum);
        $arrGroupTime = array();
        $intIndex = 0;
        foreach ($arrTplTime as $strKey => $arrOneTplTime) {
            $intIndex = $intIndex % $intSplitNum;
            $intCount = 0;
            while ($intCount < $intSplitNum) {
                if ($arrGroupTime[$intIndex] >= $intSplitTplTime) {
                    $intIndex = ($intIndex + 1) % $intSplitNum;
                } else {
                    $arrSplitReqData[$intIndex][$strKey] = $arrAlaData[$strKey];
                    $arrGroupTime[$intIndex] += $arrOneTplTime;
                    $intIndex++;
                    break;
                }
                $intCount++;
            }
        }
    }
    // 分AS结果
    if (!empty($arrAsData) && is_array($arrAsData)) {
        $intDefaultAsTime = $arrMultiRenderConf['DEFAULT_AS_TIME'];
        $intAsCount = count($arrAsData);
        $intNewTimeCount = $intTimeCount + $intAsCount * $intDefaultAsTime;
        $intNewSplitTplTime = $intNewTimeCount / $intSplitNum;
        foreach ($arrAsData as $strKey => $arrOneAsData) {
            $intIndex = $intIndex % $intSplitNum;
            $intCount = 0;
            while ($intCount < $intSplitNum) {
                if ($arrGroupTime[$intIndex] >= $intNewSplitTplTime) {
                    $intIndex = ($intIndex + 1) % $intSplitNum;
                } else {
                    $arrSplitReqData[$intIndex][$strKey] = $arrOneAsData;
                    $arrGroupTime[$intIndex] += $intDefaultAsTime;
                    $intIndex++;
                    break;
                }
                $intCount++;
            }
        }
    }
    //将单条结果包加入并行
    if (empty($arrSplitReqData) || !is_array($arrSplitReqData)) {
        CLog::warning("split pack result is empty,back to nomarl render!", MULTI_RENDER_FAIL);
        $bolDelRst = shmop_delete($shmid);
        $bolCloseRst = shmop_close($shmid);
        if ($bolDelRst && $bolCloseRst) {
            unset($GLOBALS['multi_render_shmid']);
        }
        return false;
    }
    foreach ($arrSplitReqData as $intPackIndex => $arrOneSplitReqData) {
        if (!empty($arrOneSplitReqData) && is_array($arrOneSplitReqData)) {
            $strReqKey = 'req_' . $intPackIndex;
            $arrReqPostData = array();
            $arrReqPostData['dataId'] = $arrShmData['id'];
            $arrReqPostData['dataSize'] = $arrShmData['size'];
            $arrReqPostData['randTime'] = $intRandTime;
            $arrReqPostData['dataInfo'] = $arrOneSplitReqData;
            $strReqUrl = $url . '?renderType=' . $strReqKey . '&logId=' . $intLogId . '&qid=' . $hexQid;
            $arrRenderMultiReq[$strReqKey] = curl_init($strReqUrl);
            $intReqNum = count($arrOneSplitReqData);
            $intReqNumLine = intval($arrMultiRenderConf['SINGLE_TIMEOUT_NUM_LINE']);
            $intMoreNumPackTimeout = intval($arrMultiRenderConf['SINGLE_TPL_PACK_MAX_TIMEOUT_MS']);
            $intLessNumPackTimeout = intval($arrMultiRenderConf['SINGLE_TPL_PACK_MIN_TIMEOUT_MS']);
            $intTimeOut = $intReqNum > $intReqNumLine ? $intMoreNumPackTimeout : $intLessNumPackTimeout;
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HEADER, 0);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_NOSIGNAL, true);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POST, 1);
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_HTTPHEADER, array('Expect:'));
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_POSTFIELDS, http_build_query($arrReqPostData));
            curl_setopt($arrRenderMultiReq[$strReqKey], CURLOPT_TIMEOUT_MS, $intTimeOut);
            curl_multi_add_handle($mh, $arrRenderMultiReq[$strReqKey]);
        }
    }
    $GLOBALS['logArr']['time_multi_render_ready'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    //执行并行渲染
    $time_exe_start = Volatile::microtime(true) * 1000;
    $mrc = curl_multi_exec($mh, $active);
    if ($mrc == CURLM_CALL_MULTI_PERFORM) {
        CLog::warning("curl_multi connect fail,back to nomarl render!", MULTI_RENDER_FAIL);
        return false;
    }
    $intMaxCurlExeTimes = intval($arrMultiRenderConf['CURL_MAX_EXE_TIMES']);
    $intCurlExeCount = 0;
    while ($active && $mrc == CURLM_OK && $intCurlExeCount < $intMaxCurlExeTimes) {
        $intCurlExeCount++;
        if (curl_multi_select($mh) != -1) {
            $mrc = curl_multi_exec($mh, $active);
            if ($mrc == CURLM_CALL_MULTI_PERFORM) {
                CLog::warning("curl_multi connect fail,back to nomarl render!", MULTI_RENDER_FAIL);
                return false;
            }
        }
    }
    $GLOBALS['logArr']['time_multi_render_exec'] = round(Volatile::microtime(true) * 1000 - $time_exe_start, 2);
    $time_start = Volatile::microtime(true) * 1000;
    //接收数据
    foreach ($arrRenderMultiReq as $key => $value) {
        $arrRenderResult[$key] = curl_multi_getcontent($arrRenderMultiReq[$key]);
        curl_close($arrRenderMultiReq[$key]);
        curl_multi_remove_handle($mh, $arrRenderMultiReq[$key]);
    }
    curl_multi_close($mh);
    $isDebug = $bolPreRenderFeature = $arrMultiRenderConf['DEBUG'] == 'ON' ? true : false;
    $arrRenderedData = array();
    $intChildLastIn = 0;
    $intChildLastOut = 0;
    $intChildFirstIn = 0;
    $intTCount = 1;
    $strAllOneTime = '';
    $arrTplLog = array();
    $arrResultTplTm = array();
    $intTimeRenderStructTpl = 0;
    $intRenderStructTplNum = 0;
    $intTimeAladdinTotal = 0;
    $intRenderAladdinNum = 0;
    $intTimeUrlencryptTotal = 0;
    $arrOtherLog = array();
    foreach ($arrRenderResult as $key => $oneResult) {
        $arrUnseriResult = unserialize($oneResult);
        if (!empty($arrUnseriResult)) {
            $arrLogInfo = $arrUnseriResult['pack_log'];
            unset($arrUnseriResult['pack_log']);
            if (!empty($arrLogInfo) && is_array($arrLogInfo)) {
                $intChildLastIn = $arrLogInfo['start_time'] > $intChildLastIn ? $arrLogInfo['start_time'] : $intChildLastIn;
                if ($key != 'req_main') {
                    $GLOBALS['logArr']['time_pack_' . $intTCount] = round($arrLogInfo['end_time'] - $arrLogInfo['start_time'], 2);
                    $intTCount++;
                } else {
                    $GLOBALS['logArr']['time_render_main_tpl'] = $arrLogInfo['time_main_tpl'];
                    $GLOBALS['logArr']['time_pack_main'] = round($arrLogInfo['end_time'] - $arrLogInfo['start_time'], 2);
                }
                $arrTplLog = empty($arrTplLog) ? $arrLogInfo['tpl_log'] : array_merge($arrTplLog, $arrLogInfo['tpl_log']);
                $arrResultTplTm = empty($arrResultTplTm) ? $arrLogInfo['result_tpl_tm'] : array_merge($arrResultTplTm, $arrLogInfo['result_tpl_tm']);
                $intTimeRenderStructTpl += $arrLogInfo['time_render_struct_tpl'];
                $intRenderStructTplNum += $arrLogInfo['render_struct_tpl_num'];
                $intTimeAladdinTotal += $arrLogInfo['time_aladdin_total'];
                $intRenderAladdinNum += $arrLogInfo['render_aladdin_num'];
                $intTimeUrlencryptTotal += $arrLogInfo['time_urlencrypt_total'];
                if (!empty($arrLogInfo['logArr'])) {
                    $arrOtherLog = array_merge($arrOtherLog, $arrLogInfo['logArr']);
                }
                // debug,更为详细的日志信息
                if ($isDebug) {
                    if ($intChildFirstIn == 0) {
                        $intChildFirstIn = $arrLogInfo['start_time'];
                    } else {
                        $intChildFirstIn = $arrLogInfo['start_time'] < $intChildFirstIn ? $arrLogInfo['start_time'] : $intChildFirstIn;
                    }
                    $intChildLastOut = $arrLogInfo['end_time'] > $intChildLastOut ? $arrLogInfo['end_time'] : $intChildLastOut;
                    foreach ($arrLogInfo['one_time'] as $key => $intOneTime) {
                        $strAllOneTime .= $key . ':' . $intOneTime . '|';
                    }
                }
            }
            $arrRenderedData = array_merge($arrRenderedData, $arrUnseriResult);
        } else {
            CLog::warning("whole pack render fail!pack name:" . $key, MULTI_RENDER_FAIL);
        }
    }
    $GLOBALS['logArr'] = array_merge($GLOBALS['logArr'], $arrOtherLog);
    $GLOBALS['logArr']['time_multi_render_web'] = round($intChildLastIn - $time_exe_start, 2);
    $GLOBALS['logArr']['time_multi_render_recdata'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    CSmarty::addStructTplRenderNumCount($intRenderStructTplNum);
    CSmarty::addStructTplRenderTimeCount($intTimeRenderStructTpl);
    $GLOBALS['time_count_temp']['time_aladdin_total'] += $intTimeAladdinTotal;
    $GLOBALS['time_count_temp']['render_aladdin_num'] += $intRenderAladdinNum;
    $GLOBALS['time_count_temp']['time_urlencrypt_total'] += $intTimeUrlencryptTotal;
    if (!empty($arrResultTplTm) && is_array($arrResultTplTm)) {
        foreach ($arrResultTplTm as $intOneTplTm) {
            CSmarty::recordResultTplRenderTime($intOneTplTm);
        }
    }
    if (!empty($arrTplLog) && is_array($arrTplLog)) {
        $objTplLog = TplLog::getInstance();
        $objTplLog->setTplData($arrTplLog);
    }
    if ($isDebug) {
        $GLOBALS['logArr']['time_one_detail_time'] = $strAllOneTime;
        $GLOBALS['logArr']['time_web_curl'] = round($intChildFirstIn - $time_exe_start, 2);
        $GLOBALS['logArr']['time_multi_recdata'] = round(Volatile::microtime(true) * 1000 - $intChildLastOut, 2);
        $GLOBALS['logArr']['time_child_max'] = round($intChildLastOut - $intChildFirstIn, 2);
    }
    $time_start = Volatile::microtime(true) * 1000;
    $bolDelRst = shmop_delete($shmid);
    shmop_close($shmid);
    if (!$bolDelRst) {
        CLog::warning("clean shmop fail!id:" . $shmid, MULTI_RENDER_FAIL);
    } else {
        unset($GLOBALS['multi_render_shmid']);
    }
    //主模板并行渲染未成功
    if ($arrRenderedData['req_main']['status'] !== 0) {
        CLog::warning("multi render main tpl fail,try local render once!", MULTI_RENDER_FAIL);
        $GLOBALS['mulit_render_flag'] = 1;
        $page = $smarty->do_render($data['uiData'], $data['uiControl']['templateName'], $data['uiControl']['templateSwitch'], $data['uiControl']['templateVersion']);
        if (empty($page)) {
            CLog::warning("local render main tpl fail too,abandon treatment,back to nomarl render", MULTI_RENDER_FAIL);
            return false;
        }
    } else {
        $page = $arrRenderedData['req_main']['content'];
    }
    unset($arrRenderedData['req_main']);
    $arrReplaceKeys = array();
    $arrReplaceValues = array();
    $intFailNum = 0;
    $strFailKeys = '';
    foreach ($arrRenderedData as $strKey => $strRenderContent) {
        //单条模板未渲染成功
        if ($strRenderContent['status'] !== 0) {
            //CLog::warning("multi render single tpl fail,try local render once!key:" . $strKey, MULTI_RENDER_FAIL);
            $intFailNum++;
            $strFailKeys = empty($strFailKeys) ? $strKey : $strFailKeys . '#' . $strKey;
            $strRenderContent['content'] = render_single_result($strKey, $arrNeedRenderSingleResult, $data);
        }
        if (empty($strRenderContent['content'])) {
            CLog::warning("local render single tpl fail too,abandon treatment,remove this single result!key:" . $strKey, MULTI_RENDER_FAIL);
        }
        $arrReplaceKeys[] = $strKey;
        $arrReplaceValues[] = empty($strRenderContent['content']) ? '' : $strRenderContent['content'];
        unset($arrNeedRenderSingleResult[$strKey]);
    }
    if (!empty($arrNeedRenderSingleResult)) {
        foreach ($arrNeedRenderSingleResult as $strKey => $arrContent) {
            //CLog::warning("multi render single tpl fail,try local render once!key:" . $strKey, MULTI_RENDER_FAIL);
            $intFailNum++;
            $strFailKeys = empty($strFailKeys) ? $strKey : $strFailKeys . '#' . $strKey;
            $rst = render_single_result($strKey, $arrNeedRenderSingleResult, $data);
            if (empty($rst)) {
                CLog::warning("local render single tpl fail too,abandon treatment,remove this single result!key:" . $strKey, MULTI_RENDER_FAIL);
            }
            $arrReplaceKeys[] = $strKey;
            $arrReplaceValues[] = empty($rst) ? '' : $rst;
        }
    }
    if ($intFailNum != 0) {
        CLog::warning("local render single tpl, num[{$intFailNum}] keys[{$strFailKeys}]", MULTI_RENDER_FAIL);
    }
    $GLOBALS['logArr']['time_multi_render_retry'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    $time_start = Volatile::microtime(true) * 1000;
    $page = Util::replace($page, $arrReplaceKeys, $arrReplaceValues, 0);
    $GLOBALS['logArr']['time_multi_render_repdata'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    return $page;
}
コード例 #20
0
ファイル: base.php プロジェクト: drehere/shenmegui
/**
 * @brief process aladdin data
 * @param array $data
 * @param array $path_conf
 */
function process_aladdin_data(&$data, &$path_conf)
{
    $cnt = count($path_conf);
    $status = -1;
    if (1 === $cnt) {
        $paths = explode('.', $path_conf[0]);
        $paths_count = count($paths);
        switch ($paths_count) {
            /**
             * @example : @enc : tplData
             */
            case 1:
                $link = $data['resultData'][$paths[0]];
                if (!empty($link)) {
                    if (!is_array($link)) {
                        $data['resultData'][$paths[0]] = prefixEncryptUrl($link);
                    } else {
                        foreach ($link as $k => $v) {
                            $data['resultData'][$paths[0]][$k] = prefixEncryptUrl($v);
                        }
                    }
                } else {
                    $logArr['url'] = "data['resultData'][{$paths['0']}]";
                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                }
                break;
                /**
                 * @example : @enc : tplData.loc
                 */
            /**
             * @example : @enc : tplData.loc
             */
            case 2:
                $link = $data['resultData'][$paths[0]][$paths[1]];
                if (!empty($link)) {
                    if (!is_array($link)) {
                        $data['resultData'][$paths[0]][$paths[1]] = prefixEncryptUrl($link);
                    } else {
                        foreach ($link as $k => $v) {
                            $data['resultData'][$paths[0]][$paths[1]][$k] = prefixEncryptUrl($v);
                        }
                    }
                } else {
                    $logArr['url'] = "data['resultData'][{$paths['0']}][{$paths['1']}]";
                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                }
                break;
                /**
                 * @example : tplData.moreprice.link
                 */
            /**
             * @example : tplData.moreprice.link
             */
            case 3:
                $link = $data['resultData'][$paths[0]][$paths[1]][$paths[2]];
                if (!empty($link)) {
                    if (!is_array($link)) {
                        $data['resultData'][$paths[0]][$paths[1]][$paths[2]] = prefixEncryptUrl($link);
                    } else {
                        foreach ($link as $k => $v) {
                            $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$k] = prefixEncryptUrl($v);
                        }
                    }
                } else {
                    $logArr['url'] = "data['resultData'][{$paths['0']}][{$paths['1']}][{$paths['2']}]";
                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                }
                break;
                /**
                 * @example : tplData.moreprice.link.link
                 */
            /**
             * @example : tplData.moreprice.link.link
             */
            case 4:
                $link = $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$paths[3]];
                if (!empty($link)) {
                    if (!is_array($link)) {
                        $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$paths[3]] = prefixEncryptUrl($link);
                    } else {
                        foreach ($link as $k => $v) {
                            $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$paths[3]][$k] = prefixEncryptUrl($v);
                        }
                    }
                } else {
                    $logArr['url'] = "data['resultData'][{$paths['0']}][{$paths['1']}][{$paths['2']}][{$paths['3']}][{$k}]";
                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                }
                break;
                /**
                 * @example : tplData.moreprice.link.link.link
                 */
            /**
             * @example : tplData.moreprice.link.link.link
             */
            case 5:
                $link = $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$paths[3]][$paths[4]];
                if (!empty($link)) {
                    if (!is_array($link)) {
                        $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$paths[3]][$paths[4]] = prefixEncryptUrl($link);
                    } else {
                        foreach ($link as $k => $v) {
                            $data['resultData'][$paths[0]][$paths[1]][$paths[2]][$paths[3]][$paths[4]][$k] = prefixEncryptUrl($v);
                        }
                    }
                } else {
                    $logArr['url'] = "data['resultData'][{$paths['0']}][{$paths['1']}][{$paths['2']}][{$paths['3']}][{$paths['4']}]";
                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                }
                break;
        }
        return;
    }
    if (2 === $cnt) {
        $paths_one = explode('.', $path_conf[0]);
        $paths_one_count = count($paths_one);
        $paths_two = explode('.', $path_conf[1]);
        $paths_two_count = count($paths_two);
        $total_count = $paths_one_count + $paths_two_count;
        switch ($total_count) {
            /**
             * @example : tplData[].morebrand
             */
            case 2:
                foreach ($data['resultData'][$paths_one[0]] as $key => $value) {
                    $link = $data['resultData'][$paths_one[0]][$key][$paths_two[0]];
                    if (!empty($link)) {
                        if (!is_array($link)) {
                            $data['resultData'][$paths_one[0]][$key][$paths_two[0]] = prefixEncryptUrl($link);
                        } else {
                            foreach ($link as $k => $v) {
                                $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$k] = prefixEncryptUrl($v);
                            }
                        }
                    } else {
                        $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key}][{$paths_two['0']}]";
                        CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                    }
                }
                break;
            case 3:
                /**
                 * @example : tplData[].morebrand.link
                 */
                if (1 === $paths_one_count) {
                    foreach ($data['resultData'][$paths_one[0]] as $key => $value) {
                        $link = $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]];
                        if (!empty($link)) {
                            if (!is_array($link)) {
                                $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]] = prefixEncryptUrl($link);
                            } else {
                                foreach ($link as $k => $v) {
                                    $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$k] = prefixEncryptUrl($v);
                                }
                            }
                        } else {
                            $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key}][{$paths_two['0']}][{$paths_two['1']}]";
                            CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                        }
                    }
                    /**
                     * @example : tplData.morebrand[].link
                     */
                } else {
                    if (!empty($data['resultData'][$paths_one[0]][$paths_one[1]])) {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key => $value) {
                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$key}][{$paths_two['0']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                    }
                }
                break;
            case 4:
                /**
                 * @example : tplData[].morebrand.link.sublink
                 */
                if (1 === $paths_one_count) {
                    foreach ($data['resultData'][$paths_one[0]] as $key => $value) {
                        $link = $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]];
                        if (!empty($link)) {
                            if (!is_array($link)) {
                                $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]] = prefixEncryptUrl($link);
                            } else {
                                foreach ($link as $k => $v) {
                                    $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]][$k] = prefixEncryptUrl($v);
                                }
                            }
                        } else {
                            $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key}][{$paths_two['0']}][{$paths_two['1']}][{$paths_two['2']}]";
                            CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                        }
                    }
                    /**
                     * @example : tplData.morebrand[].link.sublink
                     */
                } else {
                    if (2 === $paths_one_count) {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key => $value) {
                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$key}][{$paths_two['0']}][{$paths_two['1']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                        /**
                         * @example : tplData.morebrand.link[].sublink
                         */
                    } else {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]] as $key => $value) {
                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$paths_one['2']}][{$key}][{$paths_two['0']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                    }
                }
                break;
            case 5:
                /**
                 * @example : tplData[].morebrand.link.sublink.subsublink
                 */
                if (1 === $paths_one_count) {
                    foreach ($data['resultData'][$paths_one[0]] as $key => $value) {
                        $link = $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]][$paths_two[3]];
                        if (!empty($link)) {
                            if (!is_array($link)) {
                                $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]][$paths_two[3]] = prefixEncryptUrl($link);
                            } else {
                                foreach ($link as $k => $v) {
                                    $data['resultData'][$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]][$paths_two[3]][$k] = prefixEncryptUrl($v);
                                }
                            }
                        } else {
                            $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key}][{$paths_two['0']}][{$paths_two['1']}][{$paths_two['2']}][{$paths_two['3']}]";
                            CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                        }
                    }
                    /**
                     * @example : tplData.morebrand[].link.sublink.subsublink
                     */
                } else {
                    if (2 === $paths_one_count) {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key => $value) {
                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$key}][{$paths_two['0']}][{$paths_two['1']}][{$paths_two['2']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                        /**
                         * @example : tplData.morebrand.link[].sublink.subsublink
                         */
                    } else {
                        if (3 === $paths_one_count) {
                            foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]] as $key => $value) {
                                $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]][$paths_two[1]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]][$paths_two[1]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]][$paths_two[1]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$paths_one['2']}][{$key}][{$paths_two['0']}][{$paths_two['1']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                            /**
                             * @example : tplData.morebrand.link.sublink[].subsublink
                             */
                        } else {
                            foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$paths_one[3]] as $key => $value) {
                                $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$paths_one[3]][$key][$paths_two[0]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$paths_one[3]][$key][$paths_two[0]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$paths_one[3]][$key][$paths_two[0]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$paths_one['2']}][{$paths_one['3']}][{$key}][{$paths_two['0']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                        }
                    }
                }
                break;
        }
        return;
    }
    if (3 === $cnt) {
        $paths_one = explode('.', $path_conf[0]);
        $paths_one_count = count($paths_one);
        $paths_two = explode('.', $path_conf[1]);
        $paths_two_count = count($paths_two);
        $paths_three = explode('.', $path_conf[2]);
        $paths_three_count = count($paths_three);
        $total_count = $paths_one_count + $paths_two_count + $paths_three_count;
        switch ($total_count) {
            /**
             * @example : tplData[].morebrand[].link
             */
            case 3:
                foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                    foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                        $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]];
                        if (!empty($link)) {
                            if (!is_array($link)) {
                                $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] = prefixEncryptUrl($link);
                            } else {
                                foreach ($link as $k => $v) {
                                    $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$k] = prefixEncryptUrl($v);
                                }
                            }
                        } else {
                            $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}]";
                            CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                        }
                    }
                }
                break;
            case 4:
                /**
                 * @example : tplData.morebrand[].link[].sublink
                 */
                if (2 === $paths_one_count) {
                    foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]] as $key1 => $value1) {
                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                    }
                    /**
                     * @example : tplData[].morebrand.link[].sublink
                     */
                } else {
                    if (2 === $paths_two_count) {
                        foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                            foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$paths_two['1']}][{$key1}][{$paths_three['0']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                        }
                        /**
                         * @example : tplData[].morebrand[].link.sublink
                         */
                    } else {
                        foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                            foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$paths_three['1']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                        }
                    }
                }
                break;
            case 5:
                /**
                 * @example : tplData.morebrand.link[].sublink[].subsublink
                 */
                if (3 === $paths_one_count) {
                    foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]] as $key0 => $value0) {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key0][$paths_two[0]] as $key1 => $value1) {
                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key0][$paths_two[0]][$key1][$paths_three[0]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key0][$paths_two[0]][$key1][$paths_three[0]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$paths_one[2]][$key0][$paths_two[0]][$key1][$paths_three[0]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$paths_one['2']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                    }
                    /**
                     * @example : tplData[].morebrand.link.sublink[].subsublink
                     */
                } else {
                    if (3 === $paths_two_count) {
                        foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                            foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$paths_two[2]] as $key1 => $value1) {
                                $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$paths_two[2]][$key1][$paths_three[0]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$paths_two[2]][$key1][$paths_three[0]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$paths_two[2]][$key1][$paths_three[0]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$paths_two['1']}][{$paths_two['2']}][{$key1}][{$paths_three['0']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                        }
                        /**
                         * @example : tplData[].morebrand[].link.sublink.subsublink
                         */
                    } else {
                        if (3 === $paths_three_count) {
                            foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                                foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                    $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$paths_three[2]];
                                    if (!empty($link)) {
                                        if (!is_array($link)) {
                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$paths_three[2]] = prefixEncryptUrl($link);
                                        } else {
                                            foreach ($link as $k => $v) {
                                                $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$paths_three[2]][$k] = prefixEncryptUrl($v);
                                            }
                                        }
                                    } else {
                                        $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$paths_three['1']}][{$paths_three['2']}]";
                                        CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                    }
                                }
                            }
                            /**
                             * @example : tplData.morebrand[].link.sublink[].subsublink
                             */
                        } else {
                            if (2 === $paths_one_count && 2 === $paths_two_count && 1 === $paths_three_count) {
                                foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                                    foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                        $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]];
                                        if (!empty($link)) {
                                            if (!is_array($link)) {
                                                $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]] = prefixEncryptUrl($link);
                                            } else {
                                                foreach ($link as $k => $v) {
                                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$k] = prefixEncryptUrl($v);
                                                }
                                            }
                                        } else {
                                            $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$key0}][{$paths_two['0']}][{$paths_two['1']}][{$key1}][{$paths_three['0']}]";
                                            CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                        }
                                    }
                                }
                                /**
                                 * @example : tplData.morebrand[].link[].sublink.subsublink
                                 */
                            } else {
                                if (2 === $paths_one_count && 1 === $paths_two_count && 2 === $paths_three_count) {
                                    foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]] as $key1 => $value1) {
                                            $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]];
                                            if (!empty($link)) {
                                                if (!is_array($link)) {
                                                    $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]] = prefixEncryptUrl($link);
                                                } else {
                                                    foreach ($link as $k => $v) {
                                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$k] = prefixEncryptUrl($v);
                                                    }
                                                }
                                            } else {
                                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$paths_one['1']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$paths_three['1']}]";
                                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                            }
                                        }
                                    }
                                    /**
                                     * @example : tplData[].morebrand.link[].sublink.subsublink
                                     */
                                } else {
                                    if (1 === $paths_one_count && 2 === $paths_two_count && 2 === $paths_three_count) {
                                        foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                                            foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                                $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$paths_three[1]];
                                                if (!empty($link)) {
                                                    if (!is_array($link)) {
                                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$paths_three[1]] = prefixEncryptUrl($link);
                                                    } else {
                                                        foreach ($link as $k => $v) {
                                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$paths_three[1]][$k] = prefixEncryptUrl($v);
                                                        }
                                                    }
                                                } else {
                                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$paths_two['1']}][{$key1}][{$paths_three['0']}][{$paths_three['1']}]";
                                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;
        }
        return;
    }
    if (4 === $cnt) {
        $paths_one = explode('.', $path_conf[0]);
        $paths_one_count = count($paths_one);
        $paths_two = explode('.', $path_conf[1]);
        $paths_two_count = count($paths_two);
        $paths_three = explode('.', $path_conf[2]);
        $paths_three_count = count($paths_three);
        $paths_four = explode('.', $path_conf[3]);
        $paths_four_count = count($paths_four);
        $total_count = $paths_one_count + $paths_two_count + $paths_three_count + $paths_four_count;
        switch ($total_count) {
            case 4:
                /**
                 * @example : tplData[].morebrand[].link[].sublink
                 */
                foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                    foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                        foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                            $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]];
                            if (!empty($link)) {
                                if (!is_array($link)) {
                                    $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]] = prefixEncryptUrl($link);
                                } else {
                                    foreach ($link as $k => $v) {
                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$paths_three[1]][$k] = prefixEncryptUrl($v);
                                    }
                                }
                            } else {
                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$key2}][{$paths_four['0']}]";
                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                            }
                        }
                    }
                }
                break;
            case 5:
                /**
                 * @example : tplData.morebrand[].link[].sublink[].subsublink
                 */
                if (2 === $paths_one_count) {
                    foreach ($data['resultData'][$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                        foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]] as $key1 => $value1) {
                            foreach ($data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                                $link = $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$key2}][{$paths_four['0']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                        }
                    }
                    /**
                     * @example : tplData[].morebrand.link[].sublink[].subsublink
                     */
                } else {
                    if (2 === $paths_two_count) {
                        foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                            foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]] as $key2 => $value2) {
                                    $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$key2][$paths_four[0]];
                                    if (!empty($link)) {
                                        if (!is_array($link)) {
                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$key2][$paths_four[0]] = prefixEncryptUrl($link);
                                        } else {
                                            foreach ($link as $k => $v) {
                                                $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$key2][$paths_four[0]][$k] = prefixEncryptUrl($v);
                                            }
                                        }
                                    } else {
                                        $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$paths_two['1']}][{$key1}][{$paths_three['0']}][{$key2}][{$paths_four['0']}]";
                                        CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                    }
                                }
                            }
                        }
                        /**
                         * @example : tplData[].morebrand[].link.sublink[].subsublink
                         */
                    } else {
                        if (2 === $paths_three_count) {
                            foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                                foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                    foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]] as $key2 => $value2) {
                                        $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$key2][$paths_four[0]];
                                        if (!empty($link)) {
                                            if (!is_array($link)) {
                                                $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$key2][$paths_four[0]] = prefixEncryptUrl($link);
                                            } else {
                                                foreach ($link as $k => $v) {
                                                    $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$key2][$paths_four[0]][$k] = prefixEncryptUrl($v);
                                                }
                                            }
                                        } else {
                                            $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$paths_three['1']}][{$key2}][{$paths_four['0']}]";
                                            CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                        }
                                    }
                                }
                            }
                            /**
                             * @example : tplData[].morebrand[].link[].sublink.subsublink
                             */
                        } else {
                            if (2 === $paths_four_count) {
                                foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                                    foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                        foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                                            $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$paths_four[1]];
                                            if (!empty($link)) {
                                                if (!is_array($link)) {
                                                    $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$paths_four[1]] = prefixEncryptUrl($link);
                                                } else {
                                                    foreach ($link as $k => $v) {
                                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$paths_four[1]][$k] = prefixEncryptUrl($v);
                                                    }
                                                }
                                            } else {
                                                $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$key2}][{$paths_four['0']}][{$paths_four['1']}]";
                                                CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;
        }
        return;
    }
    if (5 === $cnt) {
        $paths_one = explode('.', $path_conf[0]);
        $paths_one_count = count($paths_one);
        $paths_two = explode('.', $path_conf[1]);
        $paths_two_count = count($paths_two);
        $paths_three = explode('.', $path_conf[2]);
        $paths_three_count = count($paths_three);
        $paths_four = explode('.', $path_conf[3]);
        $paths_four_count = count($paths_four);
        $paths_five = explode('.', $path_conf[4]);
        $paths_five_count = count($paths_five);
        $total_count = $paths_one_count + $paths_two_count + $paths_three_count + $paths_four_count + $paths_five_count;
        switch ($total_count) {
            case 5:
                /**
                 * @example : tplData[].morebrand[].link[].sublink[].subsublink
                 */
                foreach ($data['resultData'][$paths_one[0]] as $key0 => $value0) {
                    foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                        foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                            foreach ($data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]] as $key3 => $value3) {
                                $link = $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$key3][$paths_five[0]];
                                if (!empty($link)) {
                                    if (!is_array($link)) {
                                        $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$key3][$paths_five[0]] = prefixEncryptUrl($link);
                                    } else {
                                        foreach ($link as $k => $v) {
                                            $data['resultData'][$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$key3][$paths_five[0]][$k] = prefixEncryptUrl($v);
                                        }
                                    }
                                } else {
                                    $logArr['url'] = "data['resultData'][{$paths_one['0']}][{$key0}][{$paths_two['0']}][{$key1}][{$paths_three['0']}][{$key2}][{$paths_four['0']}][{$key3}][{$paths_five['0']}]";
                                    CLog::debug("data to be encrypt is empty", $status, $logArr, 1);
                                }
                            }
                        }
                    }
                }
                break;
            default:
                break;
        }
        return;
    }
    if ($cnt > 5) {
        $logArr['path_conf'] = implode("_", $path_conf);
        CLog::warning("data to be encrypt is more than 5 level", $status, $logArr, 1);
    }
}
コード例 #21
0
/**
 *
 *
 * @file modifier.limit_ubburl.php
 * @package plugins
 * @author fengfei02@baidu.com
 * @date 2012-11-05 10:51
 */
function smarty_modifier_limit_ubburl($string, $length, $limiturl = true)
{
    $status = -1;
    $logArr['smarty_modifier'] = "modifier_limit_ubburl";
    $logArr['string'] = urlencode($string);
    $logArr['length'] = $length;
    if (strlen($string) == 0) {
        $result = $string;
        return $result;
    }
    $outstr = $string;
    $min_pos = PHP_INT_MAX;
    $max_pos = 0;
    $pos_hash = array();
    // not greedy matching
    preg_match_all("/\\[url.*\\].*\\[\\/url\\]/U", $string, $out, PREG_PATTERN_ORDER);
    foreach ($out[0] as $s) {
        $pos = strpos($outstr, $s);
        $p1 = strpos($s, ']');
        $p2 = strpos($s, '[/url]');
        $mid_str = substr($s, $p1 + 1, $p2 - $p1 - 1);
        $url_str = substr($s, 0, $p1 + 1);
        $pos_hash[] = array('word' => $mid_str, 'url_str' => $url_str, 'pos' => $pos);
        // not greedy matching
        $outstr = preg_replace("/\\[url.*\\].*\\[\\/url\\]/U", $mid_str, $outstr, 1);
        $min_pos = $pos < $min_pos ? $pos : $min_pos;
        $max_pos = $pos > $max_pos ? $pos : $max_pos;
    }
    $result = hilight_limitlen($outstr, $length);
    if (false === $result) {
        $result = $string;
        $logArr['result'] = $result;
        CLog::warning("fail to call limitlen", $status, $logArr, 1);
        return $result;
    }
    //there is no url tag
    if (empty($pos_hash)) {
        return $result;
    }
    //not limited
    if (substr($result, -3) !== '...') {
        return $string;
    }
    $result_len = strlen($result) - 3;
    //limited from the first url
    if ($result_len <= $min_pos) {
        return $result;
    }
    $index = 0;
    $result_arr = array();
    foreach ($pos_hash as $key => $value) {
        if ($result_len <= $value['pos']) {
            $result_arr[] = substr($result, $index);
            break;
        } else {
            if ($result_len > $value['pos'] && $result_len < $value['pos'] + strlen($value['word'])) {
                $result_arr[] = substr($result, $index, $value['pos'] - $index);
                if ($limiturl === false) {
                    $result_arr[] = $value['url_str'];
                    $result_arr[] = $value['word'];
                    $result_arr[] = '[/url]';
                }
                $result_arr[] = '...';
                break;
            } else {
                $result_arr[] = substr($result, $index, $value['pos'] - $index);
                $result_arr[] = $value['url_str'];
                $result_arr[] = $value['word'];
                $result_arr[] = '[/url]';
                $index = $value['pos'] + strlen($value['word']);
            }
        }
    }
    if ($index >= $max_pos) {
        $result_arr[] = substr($result, $index);
    }
    $result = implode('', $result_arr);
    return $result;
}
コード例 #22
0
ファイル: ImageBase64.php プロジェクト: drehere/shenmegui
 public function parse_image_conf($arrResultData, &$arrImgSids, $arrImgConf)
 {
     $cnt = count($arrImgConf);
     $status = -1;
     if (1 === $cnt) {
         $paths = explode('.', $arrImgConf[0]);
         $paths_count = count($paths);
         switch ($paths_count) {
             /**
              *
              * @example : @enc : tplData
              */
             case 1:
                 $link = $arrResultData[$paths[0]];
                 if (!empty($link)) {
                     if (!is_array($link)) {
                         $this->get_image_sid($arrImgSids, $link);
                     } else {
                         foreach ($link as $k => $v) {
                             $this->get_image_sid($arrImgSids, $v);
                         }
                     }
                 }
                 break;
                 /**
                  *
                  * @example : @enc : tplData.loc
                  */
             /**
              *
              * @example : @enc : tplData.loc
              */
             case 2:
                 $link = $arrResultData[$paths[0]][$paths[1]];
                 if (!empty($link)) {
                     if (!is_array($link)) {
                         $this->get_image_sid($arrImgSids, $link);
                     } else {
                         foreach ($link as $k => $v) {
                             $this->get_image_sid($arrImgSids, $v);
                         }
                     }
                 }
                 break;
                 /**
                  *
                  * @example : tplData.moreprice.link
                  */
             /**
              *
              * @example : tplData.moreprice.link
              */
             case 3:
                 $link = $arrResultData[$paths[0]][$paths[1]][$paths[2]];
                 if (!empty($link)) {
                     if (!is_array($link)) {
                         $this->get_image_sid($arrImgSids, $link);
                     } else {
                         foreach ($link as $k => $v) {
                             $this->get_image_sid($arrImgSids, $v);
                         }
                     }
                 }
                 break;
                 /**
                  *
                  * @example : tplData.moreprice.link.link
                  */
             /**
              *
              * @example : tplData.moreprice.link.link
              */
             case 4:
                 $link = $arrResultData[$paths[0]][$paths[1]][$paths[2]][$paths[3]];
                 if (!empty($link)) {
                     if (!is_array($link)) {
                         $this->get_image_sid($arrImgSids, $link);
                     } else {
                         foreach ($link as $k => $v) {
                             $this->get_image_sid($arrImgSids, $v);
                         }
                     }
                 }
                 break;
                 /**
                  *
                  * @example : tplData.moreprice.link.link.link
                  */
             /**
              *
              * @example : tplData.moreprice.link.link.link
              */
             case 5:
                 $link = $arrResultData[$paths[0]][$paths[1]][$paths[2]][$paths[3]][$paths[4]];
                 if (!empty($link)) {
                     if (!is_array($link)) {
                         $this->get_image_sid($arrImgSids, $link);
                     } else {
                         foreach ($link as $k => $v) {
                             $this->get_image_sid($arrImgSids, $v);
                         }
                     }
                 }
                 break;
         }
         return true;
     }
     if (2 === $cnt) {
         $paths_one = explode('.', $arrImgConf[0]);
         $paths_one_count = count($paths_one);
         $paths_two = explode('.', $arrImgConf[1]);
         $paths_two_count = count($paths_two);
         $total_count = $paths_one_count + $paths_two_count;
         switch ($total_count) {
             /**
              *
              * @example : tplData[].morebrand
              */
             case 2:
                 foreach ($arrResultData[$paths_one[0]] as $key => $value) {
                     $link = $arrResultData[$paths_one[0]][$key][$paths_two[0]];
                     if (!empty($link)) {
                         if (!is_array($link)) {
                             $this->get_image_sid($arrImgSids, $link);
                         } else {
                             foreach ($link as $k => $v) {
                                 $this->get_image_sid($arrImgSids, $v);
                             }
                         }
                     }
                 }
                 break;
             case 3:
                 /**
                  *
                  * @example : tplData[].morebrand.link
                  */
                 if (1 === $paths_one_count) {
                     foreach ($arrResultData[$paths_one[0]] as $key => $value) {
                         $link = $arrResultData[$paths_one[0]][$key][$paths_two[0]][$paths_two[1]];
                         if (!empty($link)) {
                             if (!is_array($link)) {
                                 $this->get_image_sid($arrImgSids, $link);
                             } else {
                                 foreach ($link as $k => $v) {
                                     $this->get_image_sid($arrImgSids, $v);
                                 }
                             }
                         }
                     }
                     /**
                      *
                      * @example : tplData.morebrand[].link
                      */
                 } else {
                     foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key => $value) {
                         $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key][$paths_two[0]];
                         if (!empty($link)) {
                             if (!is_array($link)) {
                                 $this->get_image_sid($arrImgSids, $link);
                             } else {
                                 foreach ($link as $k => $v) {
                                     $this->get_image_sid($arrImgSids, $v);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 4:
                 /**
                  *
                  * @example : tplData[].morebrand.link.sublink
                  */
                 if (1 === $paths_one_count) {
                     foreach ($arrResultData[$paths_one[0]] as $key => $value) {
                         $link = $arrResultData[$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]];
                         if (!empty($link)) {
                             if (!is_array($link)) {
                                 $this->get_image_sid($arrImgSids, $link);
                             } else {
                                 foreach ($link as $k => $v) {
                                     $this->get_image_sid($arrImgSids, $v);
                                 }
                             }
                         }
                     }
                     /**
                      *
                      * @example : tplData.morebrand[].link.sublink
                      */
                 } else {
                     if (2 === $paths_one_count) {
                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key => $value) {
                             $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]];
                             if (!empty($link)) {
                                 if (!is_array($link)) {
                                     $this->get_image_sid($arrImgSids, $link);
                                 } else {
                                     foreach ($link as $k => $v) {
                                         $this->get_image_sid($arrImgSids, $v);
                                     }
                                 }
                             }
                         }
                         /**
                          *
                          * @example : tplData.morebrand.link[].sublink
                          */
                     } else {
                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]] as $key => $value) {
                             $link = $arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]];
                             if (!empty($link)) {
                                 if (!is_array($link)) {
                                     $this->get_image_sid($arrImgSids, $link);
                                 } else {
                                     foreach ($link as $k => $v) {
                                         $this->get_image_sid($arrImgSids, $v);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 5:
                 /**
                  *
                  * @example : tplData[].morebrand.link.sublink.subsublink
                  */
                 if (1 === $paths_one_count) {
                     foreach ($arrResultData[$paths_one[0]] as $key => $value) {
                         $link = $arrResultData[$paths_one[0]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]][$paths_two[3]];
                         if (!empty($link)) {
                             if (!is_array($link)) {
                                 $this->get_image_sid($arrImgSids, $link);
                             } else {
                                 foreach ($link as $k => $v) {
                                     $this->get_image_sid($arrImgSids, $v);
                                 }
                             }
                         }
                     }
                     /**
                      *
                      * @example : tplData.morebrand[].link.sublink.subsublink
                      */
                 } else {
                     if (2 === $paths_one_count) {
                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key => $value) {
                             $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key][$paths_two[0]][$paths_two[1]][$paths_two[2]];
                             if (!empty($link)) {
                                 if (!is_array($link)) {
                                     $this->get_image_sid($arrImgSids, $link);
                                 } else {
                                     foreach ($link as $k => $v) {
                                         $this->get_image_sid($arrImgSids, $v);
                                     }
                                 }
                             }
                         }
                         /**
                          *
                          * @example : tplData.morebrand.link[].sublink.subsublink
                          */
                     } else {
                         if (3 === $paths_one_count) {
                             foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]] as $key => $value) {
                                 $link = $arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]][$key][$paths_two[0]][$paths_two[1]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                             /**
                              *
                              * @example : tplData.morebrand.link.sublink[].subsublink
                              */
                         } else {
                             foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]][$paths_one[3]] as $key => $value) {
                                 $link = $arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]][$paths_one[3]][$key][$paths_two[0]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
         }
         return true;
     }
     if (3 === $cnt) {
         $paths_one = explode('.', $arrImgConf[0]);
         $paths_one_count = count($paths_one);
         $paths_two = explode('.', $arrImgConf[1]);
         $paths_two_count = count($paths_two);
         $paths_three = explode('.', $arrImgConf[2]);
         $paths_three_count = count($paths_three);
         $total_count = $paths_one_count + $paths_two_count + $paths_three_count;
         switch ($total_count) {
             /**
              *
              * @example : tplData[].morebrand[].link
              */
             case 3:
                 foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                     foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                         $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]];
                         if (!empty($link)) {
                             if (!is_array($link)) {
                                 $this->get_image_sid($arrImgSids, $link);
                             } else {
                                 foreach ($link as $k => $v) {
                                     $this->get_image_sid($arrImgSids, $v);
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 4:
                 /**
                  *
                  * @example : tplData.morebrand[].link[].sublink
                  */
                 if (2 === $paths_one_count) {
                     foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]] as $key1 => $value1) {
                             $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]];
                             if (!empty($link)) {
                                 if (!is_array($link)) {
                                     $this->get_image_sid($arrImgSids, $link);
                                 } else {
                                     foreach ($link as $k => $v) {
                                         $this->get_image_sid($arrImgSids, $v);
                                     }
                                 }
                             }
                         }
                     }
                     /**
                      *
                      * @example : tplData[].morebrand.link[].sublink
                      */
                 } else {
                     if (2 === $paths_two_count) {
                         foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                             foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                 $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                         }
                         /**
                          *
                          * @example : tplData[].morebrand[].link.sublink
                          */
                     } else {
                         foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                             foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                 $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 5:
                 /**
                  *
                  * @example : tplData.morebrand.link[].sublink[].subsublink
                  */
                 if (3 === $paths_one_count) {
                     foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]] as $key0 => $value0) {
                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]][$key0][$paths_two[0]] as $key1 => $value1) {
                             $link = $arrResultData[$paths_one[0]][$paths_one[1]][$paths_one[2]][$key0][$paths_two[0]][$key1][$paths_three[0]];
                             if (!empty($link)) {
                                 if (!is_array($link)) {
                                     $this->get_image_sid($arrImgSids, $link);
                                 } else {
                                     foreach ($link as $k => $v) {
                                         $this->get_image_sid($arrImgSids, $v);
                                     }
                                 }
                             }
                         }
                     }
                     /**
                      *
                      * @example : tplData[].morebrand.link.sublink[].subsublink
                      */
                 } else {
                     if (3 === $paths_two_count) {
                         foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                             foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$paths_two[2]] as $key1 => $value1) {
                                 $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$paths_two[2]][$key1][$paths_three[0]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                         }
                         /**
                          *
                          * @example : tplData[].morebrand[].link.sublink.subsublink
                          */
                     } else {
                         if (3 === $paths_three_count) {
                             foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                                 foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                     $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$paths_three[2]];
                                     if (!empty($link)) {
                                         if (!is_array($link)) {
                                             $this->get_image_sid($arrImgSids, $link);
                                         } else {
                                             foreach ($link as $k => $v) {
                                                 $this->get_image_sid($arrImgSids, $v);
                                             }
                                         }
                                     }
                                 }
                             }
                             /**
                              *
                              * @example : tplData.morebrand[].link.sublink[].subsublink
                              */
                         } else {
                             if (2 === $paths_one_count && 2 === $paths_two_count && 1 === $paths_three_count) {
                                 foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                                     foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                         $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]];
                                         if (!empty($link)) {
                                             if (!is_array($link)) {
                                                 $this->get_image_sid($arrImgSids, $link);
                                             } else {
                                                 foreach ($link as $k => $v) {
                                                     $this->get_image_sid($arrImgSids, $v);
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 /**
                                  *
                                  * @example : tplData.morebrand[].link[].sublink.subsublink
                                  */
                             } else {
                                 if (2 === $paths_one_count && 1 === $paths_two_count && 2 === $paths_three_count) {
                                     foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]] as $key1 => $value1) {
                                             $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]];
                                             if (!empty($link)) {
                                                 if (!is_array($link)) {
                                                     $this->get_image_sid($arrImgSids, $link);
                                                 } else {
                                                     foreach ($link as $k => $v) {
                                                         $this->get_image_sid($arrImgSids, $v);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     /**
                                      *
                                      * @example : tplData[].morebrand.link[].sublink.subsublink
                                      */
                                 } else {
                                     if (1 === $paths_one_count && 2 === $paths_two_count && 2 === $paths_three_count) {
                                         foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                                             foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                                 $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$paths_three[1]];
                                                 if (!empty($link)) {
                                                     if (!is_array($link)) {
                                                         $this->get_image_sid($arrImgSids, $link);
                                                     } else {
                                                         foreach ($link as $k => $v) {
                                                             $this->get_image_sid($arrImgSids, $v);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
         }
         return true;
     }
     if (4 === $cnt) {
         $paths_one = explode('.', $arrImgConf[0]);
         $paths_one_count = count($paths_one);
         $paths_two = explode('.', $arrImgConf[1]);
         $paths_two_count = count($paths_two);
         $paths_three = explode('.', $arrImgConf[2]);
         $paths_three_count = count($paths_three);
         $paths_four = explode('.', $arrImgConf[3]);
         $paths_four_count = count($paths_four);
         $total_count = $paths_one_count + $paths_two_count + $paths_three_count + $paths_four_count;
         switch ($total_count) {
             case 4:
                 /**
                  *
                  * @example : tplData[].morebrand[].link[].sublink
                  */
                 foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                     foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                         foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                             $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]];
                             if (!empty($link)) {
                                 if (!is_array($link)) {
                                     $this->get_image_sid($arrImgSids, $link);
                                 } else {
                                     foreach ($link as $k => $v) {
                                         $this->get_image_sid($arrImgSids, $v);
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             case 5:
                 /**
                  *
                  * @example :
                  *          tplData.morebrand[].link[].sublink[].subsublink
                  */
                 if (2 === $paths_one_count) {
                     foreach ($arrResultData[$paths_one[0]][$paths_one[1]] as $key0 => $value0) {
                         foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]] as $key1 => $value1) {
                             foreach ($arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                                 $link = $arrResultData[$paths_one[0]][$paths_one[1]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     /**
                      *
                      * @example :
                      *          tplData[].morebrand.link[].sublink[].subsublink
                      */
                 } else {
                     if (2 === $paths_two_count) {
                         foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                             foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]] as $key1 => $value1) {
                                 foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]] as $key2 => $value2) {
                                     $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$paths_two[1]][$key1][$paths_three[0]][$key2][$paths_four[0]];
                                     if (!empty($link)) {
                                         if (!is_array($link)) {
                                             $this->get_image_sid($arrImgSids, $link);
                                         } else {
                                             foreach ($link as $k => $v) {
                                                 $this->get_image_sid($arrImgSids, $v);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         /**
                          *
                          * @example :
                          *          tplData[].morebrand[].link.sublink[].subsublink
                          */
                     } else {
                         if (2 === $paths_three_count) {
                             foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                                 foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                     foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]] as $key2 => $value2) {
                                         $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$paths_three[1]][$key2][$paths_four[0]];
                                         if (!empty($link)) {
                                             if (!is_array($link)) {
                                                 $this->get_image_sid($arrImgSids, $link);
                                             } else {
                                                 foreach ($link as $k => $v) {
                                                     $this->get_image_sid($arrImgSids, $v);
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             /**
                              *
                              * @example :
                              *          tplData[].morebrand[].link[].sublink.subsublink
                              */
                         } else {
                             if (2 === $paths_four_count) {
                                 foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                                     foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                                         foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                                             $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$paths_four[1]];
                                             if (!empty($link)) {
                                                 if (!is_array($link)) {
                                                     $this->get_image_sid($arrImgSids, $link);
                                                 } else {
                                                     foreach ($link as $k => $v) {
                                                         $this->get_image_sid($arrImgSids, $v);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
         }
         return true;
     }
     if (5 === $cnt) {
         $paths_one = explode('.', $arrImgConf[0]);
         $paths_one_count = count($paths_one);
         $paths_two = explode('.', $arrImgConf[1]);
         $paths_two_count = count($paths_two);
         $paths_three = explode('.', $arrImgConf[2]);
         $paths_three_count = count($paths_three);
         $paths_four = explode('.', $arrImgConf[3]);
         $paths_four_count = count($paths_four);
         $paths_five = explode('.', $arrImgConf[4]);
         $paths_five_count = count($paths_five);
         $total_count = $paths_one_count + $paths_two_count + $paths_three_count + $paths_four_count + $paths_five_count;
         switch ($total_count) {
             case 5:
                 /**
                  *
                  * @example :
                  *          tplData[].morebrand[].link[].sublink[].subsublink
                  */
                 foreach ($arrResultData[$paths_one[0]] as $key0 => $value0) {
                     foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]] as $key1 => $value1) {
                         foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]] as $key2 => $value2) {
                             foreach ($arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]] as $key3 => $value3) {
                                 $link = $arrResultData[$paths_one[0]][$key0][$paths_two[0]][$key1][$paths_three[0]][$key2][$paths_four[0]][$key3][$paths_five[0]];
                                 if (!empty($link)) {
                                     if (!is_array($link)) {
                                         $this->get_image_sid($arrImgSids, $link);
                                     } else {
                                         foreach ($link as $k => $v) {
                                             $this->get_image_sid($arrImgSids, $v);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 break;
             default:
                 break;
         }
         return true;
     }
     if ($cnt > 5) {
         $logArr['path_conf'] = implode("_", $arrImgConf);
         CLog::warning("img src to get id is more than 5 level", $status, $logArr, 1);
     }
     return false;
 }
コード例 #23
0
ファイル: Csocket.php プロジェクト: drehere/shenmegui
 public function receiveAll($intMaxDataLength, $intTimeoutMs = null)
 {
     if (!is_null($intTimeoutMs)) {
         $this->setTimeout($intTimeoutMs, $this->_intWriteTimeoutMS);
     }
     if (!is_resource($this->_sock)) {
         return false;
     }
     $intSecond = intval($this->_intReadTimeoutMS / 1000);
     $intMicroSecond = intval($this->_intReadTimeoutMS % 1000 * 1000);
     stream_set_timeout($this->_sock, $intSecond, $intMicroSecond);
     $strData = '';
     $intLeft = $intMaxDataLength;
     $tmStart = gettimeofday();
     while ($intLeft > 0) {
         $strReceived = fread($this->_sock, $intLeft);
         $intReceived = strlen($strReceived);
         if (0 == $intReceived) {
         } else {
             if ($intReceived > 0 && $intReceived <= $intLeft) {
                 $strData .= $strReceived;
                 $intLeft -= $intReceived;
             } else {
                 list($intErrorNo, $strErrorMessage) = $this->getLastError();
                 CLog::warning(sprintf('%s: error recving %d bytes from %s:%d, ' . '%d got, err(%d:%s)', __METHOD__, $intMaxDataLength, $this->_strRemoteHost, $this->_intRemotePort, strlen($strData), $intErrorNo, $strErrorMessage));
                 return false;
             }
         }
         // manual timeout checking
         $tmCurrent = gettimeofday();
         $intMSGone = ($tmCurrent['sec'] - $tmStart['sec']) * 1000 + ($tmCurrent['usec'] - $tmStart['usec']) / 1000;
         if ($intMSGone > $this->_intReadTimeoutMS) {
             CLog::warning(sprintf('%s: timeout recving %d bytes from %s:%d, ' . '%d got but %d ms has elapsed', __METHOD__, $intMaxDataLength, $this->_strRemoteHost, $this->_intRemotePort, strlen($strData), $intMSGone));
             return $strData;
         }
     }
     return $strData;
 }
コード例 #24
0
/**
 *
 *
 * @file modifier.domain.php
 * @package plugins
 * @author lanrui@baidu.com
 * @date 2013-1-16 11:40
 */
function smarty_modifier_domain_advance($string, $encodeURI = false)
{
    $logArr['smarty_modifier'] = "modifier_domain_advance";
    $status = 0;
    $logArr['url'] = $string;
    $string = trim($string);
    if (strlen($string) == 0) {
        CLog::warning("domain string is empty", $status, $logArr, 1);
        return $string;
    }
    $flag = 0;
    $domain = "";
    $domain2 = "";
    $prefix = "";
    if (strncasecmp($string, "http://", 7) == 0) {
        $domain = substr($string, 7);
        $prefix = "http://";
        $flag = 1;
    } elseif (strncasecmp($string, "https://", 8) == 0) {
        $domain = substr($string, 8);
        $prefix = "https://";
        $flag = 1;
    } elseif (strncasecmp($string, "ftp://", 6) == 0) {
        $domain = substr($string, 6);
        $prefix = "ftp://";
        $flag = 1;
    } elseif (strncasecmp($string, "url:", 4) == 0) {
        //$pos = strspn($string, " ", 4);
        //$domain = substr($string, 4+$pos);
        $domain = trim(substr($string, 4));
        if (strncasecmp($domain, "http://", 7) == 0) {
            $domain2 = substr($domain, 7);
            $prefix = "http://";
            $flag = 2;
        } elseif (strncasecmp($domain, "https://", 8) == 0) {
            $domain2 = substr($domain, 8);
            $prefix = "https://";
            $flag = 2;
        } elseif (strncasecmp($domain, "ftp://", 6) == 0) {
            $domain2 = substr($domain, 6);
            $prefix = "ftp://";
            $flag = 2;
        }
    }
    if ($encodeURI) {
        if ($flag === 1) {
            $result = hilight_encodeURI($domain);
        } elseif ($flag === 2) {
            $result = hilight_encodeURI($domain2);
        }
        $logArr['result'] = $result;
        if (false === $result) {
            $status = -1;
            CLog::warning("fail to call hilight_encodeURI", $status, $logArr, 1);
            if ($flag == 1) {
                $result = $domain;
            } elseif ($flag == 2) {
                $result = $domain2;
            } else {
                $result = $domain;
            }
        }
        if ($flag !== 0) {
            $result = $prefix . $result;
        }
    } else {
        if ($flag === 1) {
            $result = $string;
        } elseif ($flag === 2) {
            $result = $domain;
        } else {
            $result = $string;
        }
    }
    if ($flag === 0) {
        $result = "http://" . $string;
        //        if(strstr($string,'://') !== false){
        //            $result = $string;
        //        }else{
        //            $result = "http://".$string;
        //        }
    }
    $logArr['result'] = $result;
    //CLog::warning("call domain_advance", $status, $logArr, 1);
    return $result;
}
コード例 #25
0
ファイル: ItemTplSelector.php プロジェクト: drehere/shenmegui
 public function newMappingData(&$arrItem, $arrQueryInfo, $intSrcId)
 {
     if (empty($arrItem['dispData']['strategy']['mapping']) || $arrItem['dispData']['strategy']['mapping'] !== 'ON') {
         //tpl.conf中GROUP新增一个mapping字段,表示是否可以进行数据映射
         return false;
     }
     $templateName = $arrItem['dispData']['strategy']['tempName'];
     $functionName = $templateName . '_' . $intSrcId;
     //$mappingFunctionFile = $strTemplatePath . "/" . $tplConf ['type'] . "/" . $templateName . "/MappingFunction.php";
     $mappingFunctionFile = VUI_APP_PATH . '/strategy/mappingdata/' . $functionName . '.php';
     if (!file_exists($mappingFunctionFile)) {
         //映射功能文件不存在
         CLog::warning("newMappingData mappingFunctionFile is not exist:" . $mappingFunctionFile);
         return false;
     }
     require_once $mappingFunctionFile;
     if (!function_exists($functionName)) {
         //功能函数不存在
         CLog::warning("newMappingData mappingfunctionName is not exist:" . $functionName);
         return false;
     }
     call_user_func_array($functionName, array(&$arrItem, $arrQueryInfo));
     return true;
 }
コード例 #26
0
 public function checkTemplateConfig(&$arrData)
 {
     require VUI_TEMPLATE_PATH . PHP_TEMPLATES;
     if (!isset($arrTplTypes)) {
         CLog::warning("tpl param select is wrong, require tpl type err!");
         return false;
     }
     $arrQueryInfo =& $arrData['uiData']['queryInfo'];
     $arrControlInfo =& $arrData['uiControl'];
     $arrUrlConfig = $arrQueryInfo['pUrlConfig'];
     $strType = $arrTplTypes[$arrControlInfo['templateName']]['type'];
     $arrPlatForm = $arrTplTypes[$arrControlInfo['templateName']]['platform'];
     // 平台检查
     if (!in_array($arrControlInfo['platform'], $arrPlatForm)) {
         CLog::warning("tpl param select is not matching");
         return false;
     }
     //dsp参数处理
     if (count($arrPlatForm) == 1 && strcasecmp($arrControlInfo['platform'], "pad") == 0) {
         if (empty($arrData['uiData']['queryInfo']['dspName'])) {
             $arrData['uiData']['queryInfo']['dspName'] = "ipad";
             CLog::warning("dspName is not ipad when using pad template.");
         }
     }
     $strTplPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $arrControlInfo['templateName'];
     if (!file_exists($strTplPath)) {
         return false;
     }
     $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $arrControlInfo['templateName'] . '/' . $arrControlInfo['templateName'] . '.cfg.php';
     if (!file_exists($strTplConfigPath)) {
         $strTplConfigPath = CSmarty::getTplFolderPath(VUI_TEMPLATE_PATH, $arrControlInfo['platform'], $arrControlInfo['language'], $strType) . $strType . '.cfg.php';
     }
     if (!file_exists($strTplConfigPath)) {
         CLog::warning("tpl cfg is not existed, tplname : " . $strTplName);
         return false;
     }
     $arrData['uiControl']['tplSamplingPath'] = $strTplConfigPath;
     $arrControlInfo['templateType'] = $strType;
     return true;
 }
コード例 #27
0
ファイル: InstantSearch.php プロジェクト: drehere/shenmegui
 /**
  * 从 $_GET 中解析mod、cqid、isid、chk四个参数,放置于$arrUrlConfig中
  * 
  * @param unknown_type $arrSrc        	
  * @param unknown_type $arrDest        	
  */
 public function getISParams($arrSrc, $arrHeader)
 {
     $arrParams = array();
     if (isset($arrHeader['PS-ISMOD'])) {
         $arrParams['mod'] = intval($arrHeader['PS-ISMOD']);
         switch ($arrParams['mod']) {
             case IS_NORMAL_REQ:
                 $arrParams['cqid'] = '0';
                 $arrParams['isid'] = !empty($arrSrc['isid']) && ctype_alnum(trim($arrSrc['isid'])) ? trim($arrSrc['isid']) : '0';
                 $arrParams['chk'] = '0';
                 $arrParams['status'] = 0;
                 $arrParams['f4s'] = 0;
                 $arrParams['isbd'] = intval($arrSrc['isbd']);
                 $arrParams['pstg'] = intval($arrSrc['pstg']);
                 break;
             case IS_PRE_REQ:
                 //mod=1的请求需要校验  isid、ver
                 $arrParams['cqid'] = '0';
                 $arrParams['chk'] = '0';
                 if (!empty($arrSrc['isid']) && ctype_alnum(trim($arrSrc['isid']))) {
                     $arrParams['isid'] = trim($arrSrc['isid']);
                     $arrParams['status'] = 0;
                 } else {
                     $arrParams['status'] = IS_PARAM_ERROR;
                     CLog::warning("IS: pre_request session id illegal,isid:" . $arrSrc['isid'], MULTI_RENDER_FAIL);
                 }
                 if (empty($arrHeader['PS-ISVER-ENCODE']) && empty($arrHeader['PS-ISVER'])) {
                     $arrParams['status'] = IS_PARAM_ERROR;
                     CLog::warning("IS: pre_request verify empty", MULTI_RENDER_FAIL);
                 } else {
                     $arrParams['ver'] = !empty($arrHeader['PS-ISVER-ENCODE']) ? urldecode($arrHeader['PS-ISVER-ENCODE']) : $arrHeader['PS-ISVER'];
                 }
                 $arrParams['f4s'] = intval($arrSrc['f4s']);
                 $arrParams['isbd'] = intval($arrSrc['isbd']);
                 $arrParams['pstg'] = intval($arrSrc['pstg']);
                 break;
             case IS_CONFIRM_REQ:
                 //mod=2的请求需要校验cqid、isid、chk
                 if (isset($arrSrc['cqid']) && ctype_xdigit($arrSrc['cqid']) && !empty($arrSrc['isid']) && ctype_alnum(trim($arrSrc['isid'])) && isset($arrSrc['chk']) && ctype_xdigit($arrSrc['chk'])) {
                     $arrParams['cqid'] = $arrSrc['cqid'];
                     $arrParams['isid'] = $arrSrc['isid'];
                     $arrParams['chk'] = $arrSrc['chk'];
                     $arrParams['status'] = 0;
                 } else {
                     $arrParams['status'] = IS_PARAM_ERROR;
                     CLog::warning("IS: confirm_request param illegal,isid:" . $arrSrc['isid'] . " cqid:" . $arrSrc['cqid'] . " chk:" . $arrSrc['chk'], MULTI_RENDER_FAIL);
                 }
                 if (empty($arrHeader['PS-ISVER-ENCODE']) && empty($arrHeader['PS-ISVER'])) {
                     $arrParams['status'] = IS_PARAM_ERROR;
                     CLog::warning("IS: pre_request verify empty", MULTI_RENDER_FAIL);
                 } else {
                     $arrParams['ver'] = !empty($arrHeader['PS-ISVER-ENCODE']) ? urldecode($arrHeader['PS-ISVER-ENCODE']) : $arrHeader['PS-ISVER'];
                 }
                 $arrParams['f4s'] = 0;
                 $arrParams['isbd'] = intval($arrSrc['isbd']);
                 $arrParams['pstg'] = intval($arrSrc['pstg']);
                 $arrParams['csq'] = intval($arrSrc['csq']);
                 break;
             case IS_PRE_DICT_REQ:
                 //mod=11需要校验isid、ver
                 $arrParams['cqid'] = '0';
                 $arrParams['chk'] = '0';
                 if (!empty($arrSrc['isid']) && ctype_alnum(trim($arrSrc['isid']))) {
                     $arrParams['isid'] = $arrSrc['isid'];
                     $arrParams['status'] = 0;
                 } else {
                     $arrParams['status'] = IS_PARAM_ERROR;
                     CLog::warning("IS: predict_request session id illegal,isid:" . $arrSrc['isid'], MULTI_RENDER_FAIL);
                 }
                 if (empty($arrHeader['PS-ISVER-ENCODE']) && empty($arrHeader['PS-ISVER'])) {
                     $arrParams['status'] = IS_PARAM_ERROR;
                     CLog::warning("IS: predict_request verify empty", MULTI_RENDER_FAIL);
                 } else {
                     $arrParams['ver'] = !empty($arrHeader['PS-ISVER-ENCODE']) ? urldecode($arrHeader['PS-ISVER-ENCODE']) : $arrHeader['PS-ISVER'];
                 }
                 $arrParams['f4s'] = intval($arrSrc['f4s']);
                 if (!empty($arrSrc['hsug'])) {
                     $arrHsug = explode("\t", trim($arrSrc['hsug']));
                     if (!empty($arrHsug) && is_array($arrHsug)) {
                         if (isset($this->arrInstantSearchConf['max_hsug_num']) && count($arrHsug) > intval($this->arrInstantSearchConf['max_hsug_num'])) {
                             $arrHsug = array_slice($arrHsug, 0, intval($this->arrInstantSearchConf['max_hsug_num']));
                         }
                         $arrParams['hsug'] = $arrHsug;
                     }
                 }
                 if (!empty($arrSrc['clist'])) {
                     $arrClist = explode("\t", trim($arrSrc['clist']));
                     if (!empty($arrClist) && is_array($arrClist)) {
                         if (isset($this->arrInstantSearchConf['max_clist_num']) && count($arrClist) > intval($this->arrInstantSearchConf['max_clist_num'])) {
                             $arrClist = array_slice($arrClist, 0, intval($this->arrInstantSearchConf['max_clist_num']));
                         }
                         $arrParams['clist'] = $arrClist;
                     }
                 }
                 $arrParams['isbd'] = intval($arrSrc['isbd']);
                 $arrParams['pstg'] = intval($arrSrc['pstg']);
                 break;
             default:
                 $arrParams['status'] = IS_PARAM_ERROR;
                 CLog::warning("IS: asyn request mod error", MULTI_RENDER_FAIL);
                 break;
         }
     } else {
         $arrParams['status'] = IS_PARAM_ERROR;
         CLog::warning("IS: asyn request mod error", MULTI_RENDER_FAIL);
     }
     return $arrParams;
 }
コード例 #28
0
/**
 *
 *
 * @file modifier.real.php
 * @package plugins
 * @author liyudong@baidu.com
 * @date 2011-11-03 10:47
 */
function smarty_modifier_aladdin_render($data, $templateName, $curr_sort = false)
{
    $time_start = Volatile::microtime(true) * 1000;
    $logArr['smarty_modifier'] = "modifier_aladdin_render";
    /**
     * render config
     */
    $conf = CSmarty::getConf();
    /**
     * template type
     * @var string 
     */
    $type = VUI_TEMPLATE_ALADDIN_TEMPLATE_TYPE;
    $language = $conf['language'];
    $platform = $conf['platform'];
    $logArr['template_type'] = $type;
    $logArr['template_name'] = $templateName;
    $logArr['language'] = $language;
    $logArr['platform'] = $platform;
    $log_key = $data['StdStg'] . '_' . $templateName;
    /**
     * template type cannot be empty
     */
    if (strlen($type) == 0) {
        CLog::warning("template type is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * template name cannot be empty
     */
    if (empty($templateName)) {
        CLog::warning("template name is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * aladdin's tplData 
     */
    if (empty($data['resultData']['tplData']) || !is_array($data['resultData']['tplData'])) {
        CLog::warning("tplData is empty", -1, $logArr, 1);
        return false;
    }
    /**
     * set queryInfo
     */
    $data['resultData']['queryInfo'] = CSmarty::getQueryInfo();
    /**
     * set templateConfig
     */
    $data['resultData']['templateConfig'] = CSmarty::getTemplateConfig();
    /**
     * set result current sort of result page
     */
    if ($curr_sort === false) {
        $curr_sort = 0;
    } else {
        $curr_sort += 1;
    }
    $data['resultData']['extData']['curr_sort'] = $curr_sort;
    /**
     * page renderer 
     * @var Smarty
     */
    $smarty = CSmarty::getInstance(array('language' => $language, 'type' => $type, 'platform' => $platform));
    if (false === $smarty) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        $logArr['ala_smarty_error'] = $errors_str;
        CLog::warning("fail to get instance of smarty, type: {$type}", $status, $logArr, 1);
        return false;
    }
    /**
     * encrypt page's url
     */
    backend_encrypt_url($data, $platform, $language, $type, $templateName);
    /**
     * render aladdin's page
     */
    $page = $smarty->do_render($data, $templateName, 1);
    if ($page === false) {
        $status = -1;
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        CLog::warning("fail to render aladdin's page, errors[{$errors_str}]", $status, $logArr, 1);
        return false;
    }
    if (strlen($page) == 0) {
        $status = -1;
        CLog::warning("aladdin's page is empty", $status, $logArr, 1);
        return false;
    }
    $GLOBALS['logArr']["aladdin_page_size_{$log_key}"] = strlen($page);
    $GLOBALS['logArr']["time_aladdin_{$log_key}"] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
    return $page;
}
コード例 #29
0
ファイル: InputProcess.php プロジェクト: drehere/shenmegui
 public function get_headersession($arrHeader)
 {
     $arrDataSessionData = array();
     if (empty($arrHeader['PS-DATASESSIONDATA'])) {
         return $arrDataSessionData;
     }
     $arrDataSessionData = mc_pack_text2pack($arrHeader['PS-DATASESSIONDATA']);
     $arrDataSessionData = empty($arrDataSessionData) ? $arrDataSessionData : mc_pack_pack2array($arrDataSessionData);
     if (!empty($arrDataSessionData)) {
         $strEncoding = empty($arrDataSessionData['encoding']) ? 'gbk' : trim($arrDataSessionData['encoding']);
         $strUname = iconv($strEncoding, 'utf-8', $arrDataSessionData['uname']);
         $strDisplayName = iconv($strEncoding, 'utf-8', $arrDataSessionData['displayname']);
         $arrDataSessionData['uname'] = empty($strUname) ? '' : $strUname;
         $arrDataSessionData['displayname'] = empty($strDisplayName) ? '' : $strDisplayName;
     } else {
         $status = $GLOBALS['STATUS_CODE']['UNPACK_FAIL'];
         CLog::warning($GLOBALS['STATUS_MSG'][$status] . ",sessiondata raw pack:" . urlencode($arrHeader['PS-DATASESSIONDATA']), $status, $GLOBALS['logArr']);
     }
     return $arrDataSessionData;
 }
コード例 #30
0
/**
 *
 *
 * @file modifier.format_result.php
 * @brief 将结构化结果和格式统一成阿拉丁结果形式
 * @package plugins
 * @author fengfei02@baidu.com
 * @date 2012-11-12 10:47
 */
function smarty_modifier_format_result($data)
{
    $logArr['smarty_modifier'] = "modifier_format_result";
    $default_result = array();
    if (empty($data) || !is_array($data)) {
        $logArr['format_data'] = json_encode($data);
        CLog::warning("data is empty", -1, $logArr, 1);
        return $default_result;
    }
    if (empty($data['dispData']) || !is_array($data['dispData'])) {
        $logArr['format_dispData'] = json_encode($data['dispData']);
        CLog::warning("dispData is empty", -1, $logArr, 1);
        return $default_result;
    }
    if (empty($data['offsetInfo']) || !is_array($data['offsetInfo'])) {
        $logArr['format_offsetInfo'] = json_encode($data['offsetInfo']);
        CLog::warning("offsetInfo is empty", -1, $logArr, 1);
        return $default_result;
    }
    if (empty($data['dispData']['templateName'])) {
        CLog::warning("templateName is empty", -1, $logArr, 1);
        return $default_result;
    }
    //保存原有dispData数据
    $resData = $data['dispData'];
    //保存原有offsetInfo数据
    $offsetData = $data['offsetInfo'];
    //获取模板名
    //$tempName = $data['dispData']['templateName'];
    $tempName = $data['dispData']['strategy']['tempName'] ? $data['dispData']['strategy']['tempName'] : $data['dispData']['templateName'];
    //从原有数据结构中,删除dispData,offsetInfo
    //这俩数据已经保存为 resData 和 offsetData
    unset($data['dispData']);
    unset($data['offsetInfo']);
    //新建classicInfo,保存搜索结果中的经典数据:标题、摘要等等
    //包含两块内容
    //1、原有offsetInfo中的信息:标题、摘要、url、时间戳等
    //2、原有res下面的信息:ui模块直接拼在结果里的数据
    //此时的data里面已经没有offsetInfo和dispData
    $resData['classicInfo'] = array_merge($data, $offsetData);
    //将ac结果的数据结构拼装成aladdin结果的数据结构形式
    foreach ($resData as $k => $v) {
        //用于extData
        if (in_array($k, $GLOBALS['ALADDIN_FIELD'])) {
            if (empty($resData['resultData']) || !array_key_exists($k, $resData['resultData'])) {
                $resData['resultData'][$k] = $v;
            }
        } else {
            if (empty($resData['resultData']['tplData']) || !array_key_exists($k, $resData['resultData']['tplData'])) {
                $resData['resultData']['tplData'][$k] = $v;
            }
        }
        unset($resData[$k]);
    }
    //将模板名的设置设置为aladdin结果保持统一
    $resData['strategy']['tempName'] = $tempName;
    //模板中需要统一判断的
    $resData['burstFlag'] = $resData['resultData']['tplData']['classicInfo']['burstFlag'];
    $resData['comeFrome'] = $resData['resultData']['tplData']['classicInfo']['comeFrome'];
    $resData['itemIdEncry'] = $resData['resultData']['tplData']['classicInfo']['itemIdEncry'];
    return $resData;
}