由于是博客模块,必须开通自动Ping搜索引擎Goolge和百度的服务器,所以特意增加上了此功能。估计过2天google和百度就能收录此博客了。需要服务器或者虚拟主机php支持CURL模块,否则无法使用。

后台需要配置博客模块的"Ping谷歌和百度"开启状态。当此选项开启状态后,每次添加或者编辑博文时,系统会自动去Ping Google和百度的RPC2,以达到自动Ping服务。 后台配置博客界面如下

核心代码如下,有需要的人可以参考参考!

public function ping_service($pdata) {
        if (Http::getSupport() == 1) {
            Http::setWay(1);
        } else {
            return false;
        }
        $google_ping_url = 'http://blogsearch.google.com/ping/RPC2';
        $googleXML = '';
        $googleXML .= '<?xml version="1.0″?>' ."\n";
        $googleXML .= '<methodCall>' ."\n";
        $googleXML .= ' <methodName>weblogUpdates.extendedPing</methodName>' ."\n";
        $googleXML .= ' <params>' ."\n";
        $googleXML .= '     <param>' ."\n";
        $googleXML .= '         <value>'. htmlspecialchars($pdata['title']) .'</value>' ."\n";
        $googleXML .= '     </param>' ."\n";
        $googleXML .= '     <param>' ."\n";
        $googleXML .= '         <value>'. htmlspecialchars($this->config['SITE_CONFIG']['site_url']) .'</value>' ."\n";
        $googleXML .= '     </param>' ."\n";
        $googleXML .= '     <param>' ."\n";
        $googleXML .= '         <value>'. htmlspecialchars($pdata['link_url']) .'</value>' ."\n";
        $googleXML .= '     </param>' ."\n";
        $googleXML .= '     <param>' ."\n";
        $googleXML .= '         <value>'. htmlspecialchars(build_uri('index://blog/feed')) .'</value>' ."\n";
        $googleXML .= '     </param>' ."\n";
        $googleXML .= ' </params>' ."\n";
        $googleXML .= '</methodCall>';
        $google_header = array(
            'POST '. $google_ping_url .' HTTP/1.0"',
            'Accept: text/xml',
            'Content-type: text/xml;charset="'. $this->config['WEB_CHARSET'] .'"',
            'Content-length: '. strlen($googleXML),
        );
        $result_google = Http::doPost($google_ping_url, $googleXML, 5, $google_header);
        
        $baidu_ping_url = 'http://ping.baidu.com/ping/RPC2';
        $baiduXML = '';
        $baiduXML .= '<?xml version="1.0" encoding="'. $this->config['WEB_CHARSET'] .'"?>' ."\n";
        $baiduXML .= '<methodCall>' ."\n";
        $baiduXML .= ' <methodName>weblogUpdates.extendedPing</methodName>' ."\n";
        $baiduXML .= ' <params>' ."\n";
        $baiduXML .= '     <param>' ."\n";
        $baiduXML .= '         <value><string>'. htmlspecialchars($pdata['title']) .'</string></value>' ."\n";
        $baiduXML .= '     </param>' ."\n";
        $baiduXML .= '     <param>' ."\n";
        $baiduXML .= '         <value><string>'. htmlspecialchars($this->config['SITE_CONFIG']['site_url']) .'</string></value>' ."\n";
        $baiduXML .= '     </param>' ."\n";
        $baiduXML .= '     <param>' ."\n";
        $baiduXML .= '         <value><string>'. htmlspecialchars($pdata['link_url']) .'</string></value>' ."\n";
        $baiduXML .= '     </param>' ."\n";
        $baiduXML .= '     <param>' ."\n";
        $baiduXML .= '         <value><string>'. htmlspecialchars(build_uri('index://blog/feed')) .'</string></value>' ."\n";
        $baiduXML .= '     </param>' ."\n";
        $baiduXML .= ' </params>' ."\n";
        $baiduXML .= '</methodCall>';
        $baidu_header = array(
            'POST '. $baidu_ping_url .' HTTP/1.0"',
            'Accept: text/xml',
            'Content-type: text/xml;charset="'. $this->config['WEB_CHARSET'] .'"',
            'Content-length: '. strlen($baiduXML),
        );
        $result_baidu = Http::doPost($baidu_ping_url, $baiduXML, 5, $baidu_header);
    }
分类: PHP之路 标签: njcms博客CURLGooglePHPPingRPC模块百度

评论

暂无评论数据

暂无评论数据

目录