/** * 提供给https项目使用的域名替换模板插件 * 异常时返回原url * @param unknown $strUrl * @param string $app * @return string */ function smarty_modifier_getHttpsHost($strUrl, $tag = '') { $strReplacedUrl = $strUrl; $ishttps = Wise_Utils::isHttps(); if ($ishttps !== 1) { return $strReplacedUrl; } if (empty($strUrl)) { return $strReplacedUrl; } $arr = parse_url($strUrl); //url不符合规范,解析失败 if (empty($arr) || !is_array($arr)) { return $strReplacedUrl; } $strScheme = $arr['scheme']; //非http开头的url if (empty($strScheme) || $strScheme != 'http') { return $strReplacedUrl; } $strHost = $arr['host']; $strDictRst = Wise_Utils::getValueFromDict($strHost, 'http_to_https'); if (empty($strDictRst)) { return $strReplacedUrl; } $arr['scheme'] = 'https'; $arr['host'] = $strDictRst; $strBuildUrl = Wise_Utils::antiParerUrl($arr); if (!empty($strBuildUrl)) { $strReplacedUrl = $strBuildUrl; } return $strReplacedUrl; }
function smarty_function_wiseMakeLinkUrl($params, &$smarty) { //兼容处理,在阿拉丁模板中要取reqData字段,主模板中取req $reqData = $smarty->getTemplateVars('req'); $pageData = $smarty->getTemplateVars('page'); if (empty($reqData)) { $reqData = $smarty->getTemplateVars('reqData'); $pageData = $smarty->getTemplateVars('pageData'); } if (isset($_ENV['HHVM'])) { $params['src'] = Wise_Utils::hhvm_htmlspecialchars_decode($params['src']); } else { $params['src'] = htmlspecialchars_decode($params['src']); } //移动公共参数,这里不要baiduid是因为在src中拼接的时候不要baiduid,所以放入tc跳转其他参数对象中 $common_prefix_array = array('from' => $reqData['from'], 'ssid' => $reqData['ssid'], 'uid' => $reqData['uid'], 'bd_page_type' => $reqData['bd_page_type'], 'pu' => $reqData['pu']); $common_prefix_str = http_build_query($common_prefix_array, '', '&'); //tc跳转其他参数 $common_tc_array = array('baiduid' => $reqData['baiduid'], 'ct' => $params['ct'] ? $params['ct'] : 0, 'cst' => $params['cst'] ? $params['cst'] : 0, 'ref' => $pageData['pageRef'] ? $pageData['pageRef'] : ($params['ref'] ? $params['ref'] : ''), 'lid' => $reqData['lid'] ? $reqData['lid'] : ($reqData['logid'] ? $reqData['logid'] : '')); if ($reqData['word']) { $common_tc_array['w'] = $reqData['pn'] . '_' . $reqData['rn'] . '_' . $reqData['word']; } $common_tc_str = http_build_query($common_tc_array, '', '&'); //添加其他参数 $other_tc_arr = array(); foreach ($params as $attr => $value) { if (strripos($attr, "other_") !== "false" && strripos($attr, "other_") === 0) { $other_tc_arr[substr($attr, 6)] = $value; } } $other_tc_str = http_build_query($other_tc_arr, '', '&'); //如果设置了pubPath为true,为src后面添加6个公共参数 if ($params['pubPath']) { $params['src'] = $params['src'] . '&' . $common_prefix_str; } $src = 'src=' . urlencode($params['src']); //如果域名不是baidu.com,使用加密插件 if (!preg_match('/\\.baidu\\.com/', $params['src'])) { $src = Wise_String::anti_src(urlencode($params['src']), '&'); } //返回链接格式为移动6公共参数 + tc跳转其他参数 //src格式为src+移动5公共参数(不要baiduid) return 'http://m.baidu.com/tc?l=1&noconvert=1&' . $common_prefix_str . '&' . $common_tc_str . '&' . $other_tc_str . '&' . $src; }
function smarty_function_makeTimg($params) { if (!is_string($params['src'])) { return; } $sec = time(); $key = "wisetimgkey"; $di = md5($key . $sec . $params['src']); $scheme = "http://"; $host = "cdn01.baidu-img.cn"; // 判断是否在https协议下 $ishttps = Wise_Utils::isHttps(); if ($ishttps == 1) { $strDictRst = Wise_Utils::getValueFromDict($host, 'http_to_https'); if (!empty($strDictRst)) { $scheme = "https://"; $host = $strDictRst; } } $url = $scheme . $host . "/timg?wisealaddin&sec={$sec}&di={$di}&"; $url .= http_build_query($params, '', '&'); return $url; }
/** * Smarty addparam modifier plugin * * Type: modifier<br> * Name: addparam<br> * Date: * Purpose: add a param * Input: url * Example: {$var|addparam:"name":"ximi"} * @version 1.0 * @param string * @param string * @return string */ function smarty_modifier_addparam($url, $key = '', $value = '', $transfer = true, $all = 0) { return Wise_Utils::addUrlParam($url, $key, $value, $transfer, $all); }
/** * Smarty wordtruncate modifier plugin * * Type: modifier<br> * Name: wordtruncate<br> * Date: * Purpose: truncate a word * Input: string to truncate * Example: {$var|wordtruncate:"4":"UTF-8":"..."} * @version 1.0 * @param string * @param string * @return string */ function smarty_modifier_wordtruncate($str, $length = 0, $encoding = 'UTF-8', $endMark = '..', $rawStartLabel = '\\2', $rawEndLabel = '\\3', $outStartLabel = '<em>', $outEndLabel = '</em>', $outpuEncoding = 'UTF-8') { return Wise_Utils::wordEmTruncate($str, $length, $encoding, $endMark, $rawStartLabel, $rawEndLabel, $outStartLabel, $outEndLabel, $outpuEncoding); }
/** * 语音标记 *@param $pu *@return int 1/0 */ public static function isVoiceSearch($pu) { $voice_search = 0; $csrc = Wise_Utils::getParamFromPu($pu, 'csrc'); $substr = strstr($csrc, '_voice'); if ($substr && $substr == '_voice') { $voice_search = 1; } return $voice_search; }
public static function getOnlineInfo($srcid = '', &$data) { $data['isonline'] = false; if (empty($srcid)) { return; } $onlineConf = Bd_Conf::getAppConf('online'); if (!empty($onlineConf) && !empty($onlineConf['srcid']) && !empty($onlineConf['appid'])) { $appid = $onlineConf['srcid'][$srcid]; if (!empty($appid) && !empty($onlineConf['appid'][$appid])) { $appInfo = $onlineConf['appid'][$appid]; $data['apikey'] = $appInfo['apikey']; $secretkey = $appInfo['secretkey']; $data['type'] = $appInfo['type']; $data['url'] = $appInfo['url']; $data['ajaxurl'] = $appInfo['ajaxurl']; $data['prixurl'] = $appInfo['prixurl']; if (preg_match('/^(\\w+\\:\\/\\/[^\\/ ]+)([^ ]*)/', trim($data['ajaxurl']), $matches)) { $data['ajaxurl'] = Wise_Utils::getHttpsHost($matches[1]) . $matches[2]; } if (!empty($data['apikey']) && !empty($secretkey)) { $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $password = ''; for ($i = 0; $i < 10; $i++) { $password .= $chars[mt_rand(0, strlen($chars) - 1)]; } $data['nonce'] = $password; $data['csrftoken'] = md5($data['nonce'] . $secretkey); $data['isonline'] = true; } } } }