織夢(mèng)會(huì)員中心發(fā)布文章自動(dòng)過濾外部外部鏈接,保留本站站內(nèi)鏈接。這個(gè)織夢(mèng)默認(rèn)后臺(tái)本身帶有這樣的功能的,只是會(huì)員模塊里沒有而已。
實(shí)現(xiàn)自動(dòng)過濾外部鏈接
教程
打開 /member/inc/inc_archives_functions.php 在文件的最下面插入
/**
 
 *  刪除非站內(nèi)鏈接
 
 *
 
 * @access    public
 
 * @param     string  $body  內(nèi)容
 
 * @param     array  $allow_urls  允許的超鏈接
 
 * @return    string
 
 */
 
function Replace_Links( &$body, $allow_urls=array()  )
 
{
 
    $host_rule = join('|', $allow_urls);
 
    $host_rule = preg_replace("#[nr]#", '', $host_rule);
 
    $host_rule = str_replace('.', ".", $host_rule);
 
    $host_rule = str_replace('/', "/", $host_rule);
 
    $arr = '';
 
    preg_match_all("#<a([^>]*)>(.*)</a>#iU", $body, $arr);
 
    if( is_array($arr[0]) )
 
    {
 
        $rparr = array();
 
        $tgarr = array();
 
        foreach($arr[0] as $i=>$v)
 
        {
 
            if( $host_rule != '' && preg_match('#'.$host_rule.'#i', $arr[1][$i]) )
 
            {
 
                continue;
 
            } else {
 
                $rparr[] = $v;
 
                $tgarr[] = $arr[2][$i];
 
            }
 
        }
 
        if( !empty($rparr) )
 
        {
 
            $body = str_replace($rparr, $tgarr, $body);
 
        }
 
    }
 
    $arr = $rparr = $tgarr = '';
 
    return $body;
 
}
繼續(xù)在這個(gè)文件中找到,大概在329行
//自動(dòng)摘要
在它上面加入
//刪除非站內(nèi)鏈接
 
$allow_urls = array($_SERVER['HTTP_HOST']);
 
// 讀取允許的超鏈接設(shè)置
 
if(file_exists(DEDEDATA."/admin/allowurl.txt"))
 
{
 
    $allow_urls = array_merge($allow_urls, file(DEDEDATA."/admin/allowurl.txt"));
 
}
 
$body = Replace_Links($body, $allow_urls);