Discuz X2自动实现外部链接跳转,防止灌水。
找到source\function\function_discuzcode.php文件
修改函数function parseurl($url, $text, $scheme){....}为
- function parseurl($url, $text, $scheme) {
- global $_G;
- if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\["']+/i", trim($text), $matches)) {
- $url = $matches[0];
- $length = 65;
- if(strlen($url) > $length) {
- $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
- }
- $url = substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url;
- } else {
- $url = substr($url, 1);
- if(substr(strtolower($url), 0, 4) == 'www.') {
- $url = 'http://'.$url;
- }
- $url = !$scheme ? $_G['siteurl'].$url : $url;
- }
- preg_match("/^http:\/\/[^\/]+/",$url,$matchs);
- $allowURL = array(".com");//这个是允许的域名
- if(!in_array(substr($matchs[0],7),$allowURL)){
- $url = "http://haodehui.com/goto.php?url=".base64_encode($url);//这个是跳转后的网址,
- //url使用的base64_encode加密方式,用base64_decode解密就行
- }
- return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
- }
复制代码 |