zoukankan      html  css  js  c++  java
  • wego微购RSS、Sitemap、Ping、腾讯拍拍网购采集插件

    淘宝5折给力促销,咱们结婚吧高圆圆服饰

    和哥们研究淘宝客,找到微购这个程序觉得挺不错的,但是地图和RSS功能不是特别完善,于是小憩一下,做了下初级的拓展,分享给大家,开源精神嘛,大家也可以去我的网站我要购物平台去看看。

    1.拓展后台seoAction.class.php

    <?php
    !defined("BUILD_BATCH_COUNT")&&define("BUILD_BATCH_COUNT",200);
    class seoAction extends baseAction
    {
        //显示列表
        public function index(){
            $this->showindex("网站首页");
        }
        public function seller()
        {
            $this->showindex("返现商家");
        }
        public function search()
        {
            $this->showindex("逛宝贝");
        }
        public function album()
        {
            $this->showindex("专辑");
        }
        public function promo()
        {
            $this->showindex("促销活动页");
        }
        public function exchange_goods()
        {
            $this->showindex("积分商城");
        }
        public function cate()
        {
            $this->showindex("商品分类页");
        }
        public function item()
        {
            $this->showindex("商品详细页");
        }
        public function showindex($title)
        {
            $map['actionname'] = ACTION_NAME;
            $info = $this->seo_mod->where($map)->find();
            $this->assign('info',$info);
            $this->assign('title',$title);
            $this->display("index");
        }
        //修改
        public function edit()
        {
           $this->seo_mod->create();
           $status = $_POST['id'] ? $this->seo_mod->save() : $this->seo_mod->add();
           
           if($status){
                $this->success("操作成功!");
           }else{
                $this->error("操作失败!");
           }
        }
        //伪静态设置
        function rewrite(){
            $this->assign('set',$this->setting);
            $this->display();
        }
        //设置seo信息
        function doEditSeo(){
            if(isset($_POST["site"]["url_model"])){
                $_POST["site"]["url_model"];
                $address = ROOT_PATH."/index/Conf/config.php";
                $configFile = file_get_contents($address);
                $newFile = str_replace("'URL_MODEL' => {$this->setting['url_model']}","'URL_MODEL' => {$_POST['site']['url_model']}",$configFile);
                if(!file_put_contents($address,$newFile)){
                    $this->error("保存伪静态模式错误!请查看目录是否有修改权限");
                }
                if(unlink(ROOT_PATH."/index/Runtime/~runtime.php")){
                   // $success = "保存数据成功";
                }
                //保存伪静态后缀
                if(!empty($_POST['site']['html_suffix'])&&trim($_POST['site']['html_suffix'])!='/'){
                    $_br = "
    ";
                    $_tab = "	";        
                    $_profile = '<?php'.$_br;
                    $_profile .= $_tab."//seo后缀配置文件".$_br;
                    
                    $_profile .= $_tab."return array(
                                        'URL_HTML_SUFFIX'=>'{$_POST['site']['html_suffix']}'
                    );".$_br;                
                            
                    $_profile .= $_br;
                    $_profile .= '?>'.$_br;        
                    if (!file_put_contents(ROOT_PATH."/index/Conf/html_suffix.php", $_profile)) {
                         $this->error("保存后缀配置文件失败,请重试!");
                    }            
                }else{
                    $_br = "
    ";
                    $_tab = "	";        
                    $_profile = '<?php'.$_br;
                    $_profile .= $_tab."//seo后缀配置文件".$_br;
                    
                    $_profile .= $_tab."return array(
                                        
                    );".$_br;                
                            
                    $_profile .= $_br;
                    $_profile .= '?>'.$_br;        
                    if (!file_put_contents(ROOT_PATH."/index/Conf/html_suffix.php", $_profile)) {
                         $this->error("保存后缀配置文件失败,请重试!");
                    }    
                }
                 
                $map["name"] = 'url_model';
                M('setting')->where($map)->setField('data',$_POST['site']['url_model']);
                $map["name"] = 'html_suffix';
                M('setting')->where($map)->setField('data',trim($_POST['site']['html_suffix'])); 
                $this->success("保存数据成功!");
                
            }
        }
         //显示伪静态信息
         function showRewriteRules(){      
            $where=array('name'=>'html_suffix');
            $setting_mod=D('setting');
            $html_suffix_rel=$setting_mod->where($where)->find();
            $this->assign('suffix',$html_suffix_rel['data']);  //  
    
            $where=array('name'=>'url_model');        
            $url_model_rel=$setting_mod->where($where)->find();
            $this->assign('url_model',$url_model_rel['data']);  //  
            $this->display();
        }
        
        function sitemap(){
            if(!empty($_POST['dosubmit'])){
                vendor("sitemap.WSitemap");
                   $_sitemap=new WSiteMap();
                   $lastmod=date("Y-m-d");
                //首页
                $_sitemap->add($this->setting['site_domain']."/index.php",$lastmod,"always","1.0");
                //导航
                $nav_cate = M("nav")->where("is_show=1 AND in_site!='0'")->order("sort_order")->select();
                   foreach($nav_cate as $v){
                       if($v['system']=='1')
                           $loc=$this->setting['site_domain']."/index.php?a=index&m=".$v['alias'];
                       else{
                           if($v['in_site']=='0')
                               $loc=$v['url'];
                           else
                               $loc=$this->setting['site_domain']."/index.php?a=index&m=cate&cid=".$v['items_cate_id'];
                       }
                       $_sitemap->add($loc,$lastmod,"monthly","0.7");
                   }
                //逛宝贝热门搜索
                $setting_cate = M('setting')->where("name='search_words'")->select();
                $setting = explode(",",$setting_cate[0]['data']);
                foreach($setting as $v)
                    $_sitemap->add($this->setting['site_domain']."/index.php?a=index&m=search&keywords=".$v,$lastmod,"always","0.8");
                
                //专辑分类
                $album_cate = M("album_cate")->where("status=1")->order("sort_order")->select();
                foreach($album_cate as $v)
                    $_sitemap->add($this->setting['site_domain']."/index.php?m=album&a=index&cid=".$v['id'],$lastmod,"monthly","0.7");
                
                //返现商家
                $seller_cate = M("seller_cate")->where("status=1")->order("sort")->select();
                foreach($seller_cate as $v)
                    $_sitemap->add($this->setting['site_domain']."/index.php?m=seller&a=index&id=".$v['id'],$lastmod,"monthly","0.9");
                //读取标签
                $getlabel = file_get_contents("./data/label.txt");
                $label = explode(",",$getlabel);
                //所有标签
                $items_tags = M("items_tags")->where("status=1")->select();
                    foreach($items_tags as $v){
                        if(!preg_match("/w|【|】|、|(|)|\/",$v['name'])){
                            if(in_array($v['name'],$label))
                                $_sitemap->add($this->setting['site_domain']."/index.php?m=cate&a=tag&id=".$v['id'],$lastmod,"always","0.9");
                        }
                    }
                $data=$_sitemap->get();
                //读取产品  
                $data = str_replace('><', ">
    <", $data);
                //$data = iconv("GB2312", 'UTF-8',$data);
                $data=str_replace("&","&amp;",$data);
                   if(file_put_contents("sitemap.xml",$_sitemap->begin().$data)){
                          //读取商品数据
                       $this->success("提交成功,接下来将分析大数据,请耐心等候...","/admin.php?m=seo&a=sitemap_items",1);   
                   }else{
                       $this->error("提交失败!");
                }
               }
            $this->display();
        }
        
        public function sitemap_items(){
            import('ORG.Util.Page');
            vendor("sitemap.WSitemap");
            $_sitemap=new WSiteMap();
            $_items=M("items");
            $count=!empty($_GET['count'])?$_GET['count']:0;
            $nowPage=!empty($_GET['p'])?$_GET['p']:0;
            !$count&&$count=$_items->where("status=1")->count("id");
            $_page=new Page($count,BUILD_BATCH_COUNT);// 实例化分页类 传入总记录数
            $list=$_items->order('add_time DESC')->field("id,add_time")->page($nowPage.','.$_page->listRows)->select();
            foreach($list as $v){
                $lastmod=date("Y-m-d",$v['add_time']);
                $_sitemap->add($this->setting['site_domain']."/index.php?a=index&m=item&id=".$v['id'],$lastmod,"daily","0.9");
            }
            //读取产品  
            $data = str_replace('><', ">
    <", $_sitemap->get());
            //$data = iconv("GB2312", 'UTF-8',$data);
            $data=str_replace("&","&amp;",$data);
            if(!file_put_contents("sitemap.xml",$data,FILE_APPEND)){
                 @file_put_contents("sitemap.xml",$_sitemap->end(),FILE_APPEND);
                 $this->error("提交失败。","/admin.php?m=seo&a=sitemap",1); 
            }
            if($nowPage>=$_page->totalPages){
                @file_put_contents("sitemap.xml",$_sitemap->end(),FILE_APPEND);
                $this->success("生成完毕,共生成条".$count."记录。","/admin.php?m=seo&a=sitemap");
            }else{
                //生成下一页
                $this->success("共".$_page->totalPages."页,第".($nowPage+1)."页,请耐心等候...","/admin.php?m=seo&a=sitemap_items&p=".($nowPage+1)."&count=".$count,1);
            }
        }
        
        public function item_rss(){
            import('ORG.Util.Page');
            vendor("rss.WRss");
            $_rss=new WRss();
            $_items=M("items");
            $count=!empty($_GET['count'])?$_GET['count']:0;
            $nowPage=!empty($_GET['p'])?$_GET['p']:0;
            if(!$nowPage)
                @file_put_contents("rss.xml",$_rss->begin().$_rss->site($this->setting['site_title'],$this->setting['site_domain'],$this->setting['site_description']));
            !$count&&$count=$_items->where("status=1")->count("id");
            $_page=new Page($count,BUILD_BATCH_COUNT);// 实例化分页类 传入总记录数
            $list=$_items->order('add_time DESC')->field("id,title,img,seller_name,add_time")->page($nowPage.','.$_page->listRows)->select();
            foreach($list as $v){
                $lastmod=date("D d F Y h:i:s",$v['add_time']);
                $link=$this->setting['site_domain']."/index.php?a=index&m=item&id=".$v['id'];
                $_rss->add($v['title'],$link,$v['title']."<img src="{$v[img]}"/>",$v['seller_name'],$lastmod,$link);
            }
            //读取产品  
            $data = str_replace('><', ">
    <", $_rss->get());
            //$data = iconv("GB2312", 'UTF-8',$data);
            $data=str_replace("&","&amp;",$data);
            if(!file_put_contents("rss.xml",$data,FILE_APPEND)){
                 @file_put_contents("rss.xml",$_rss->end(),FILE_APPEND);
                 $this->error("提交失败。","/admin.php?m=seo&a=sitemap",1); 
            }
            if($nowPage>=$_page->totalPages){
                @file_put_contents("rss.xml",$_rss->end(),FILE_APPEND);
                $this->success("生成完毕,共生成条".$count."记录。","/admin.php?m=seo&a=sitemap");
            }else{
                //生成下一页
                $this->success("共".$_page->totalPages."页,第".($nowPage+1)."页,请耐心等候...","/admin.php?m=seo&a=item_rss&p=".($nowPage+1)."&count=".$count,3);
            }
        }
        
        public function ping(){
            $ids=$_GET['ids'];
            $p=isset($_GET['p'])?$_GET['p']:0;
            $idsArray=explode('_',$ids);
            $idsCount=count($idsArray);
            if($p<$idsCount){
                //百度google推送
                vendor("ping.WPing");
                $_ping=new WPing();
                $_items=M("items");
                $currentId=$idsArray[$p];
                $items=$_items->where("id=".$currentId)->field("title")->find();
                if(!$items){
                    $this->error("记录".$currentId."不存在,将推送下一条请耐心等候...","/admin.php?m=seo&a=ping&p=".($p+1)."&ids=".$ids,1);
                }
                $link=$this->setting['site_domain']."/index.php?a=index&m=item&id=".$currentId;
                $_ping->method($this->setting['site_name'],$this->setting['site_domain'],$link,$this->setting['site_domain'].'/rss.xml');
                $sb=$_ping->baidu()?"成功":"失败";
                $gb=$_ping->google()?"成功":"失败";
                $this->success("共".$idsCount."条记录需要需要推送,当前第".($p+1)."条,百度反馈{$sb},谷歌反馈{$gb}。请耐心等候...","/admin.php?m=seo&a=ping&p=".($p+1)."&ids=".$ids,2);
            }else{
                $this->success("推送完毕,共生成条".$idsCount."记录。","/admin.php?m=seo&a=sitemap");
            }
        }
        function get_itmes_cate($pid){
            $model = M('items_cate');
            $map["status"] = 1;
            $map["pid"] = $pid;
            $list = $model->field('id')->where($map)->select();
            foreach($list as $v){
                $id .= $v['id'].",";
            }
            $pid = trim($id,",");
            $maps["status"] = 1;
            $maps["pid"] = array('in',$pid);
            $lists = $model->field('id,name')->where($maps)->select();
            foreach($lists as $v){
                $str .= "<a href='/index.php?a=index&m=cate&cid=".$v['id']."'>{$v['name']}</a>"; 
            }
            return $str;
        }
        function test(){
            $items_tags = M("items_tags")->where("status=1")->select();
            foreach($items_tags as $v){
                if(!preg_match("/w|【|】|、|(|)|\/",$v['name'])){
                echo $v['name']."&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;http://www.qianbao.cn/index.php?m=cate&a=tag&id=".$v['id']."</br>";
                }
            }
        }
    }
    ?>

    追加系统Vendar需要的库文件RSS、Sitemap、Ping

    /includes/thinkphp/Extend/Vendar/ping/WPing.php

    <?php
    /** 
      +------------------------------------------------------------------------------ 
     * 通知搜索引擎过来抓去最新发布的内容。秒收不是梦 
     * 目前仅支持Google和Baidu 
      +------------------------------------------------------------------------------ 
     */
    class WPing {
        public $method, $callback;
        public function method($site_name,$site_url,$update_url,$update_rss) {
            $this->method = " 
          <?xml version="1.0" encoding="UTF-8"?> 
          <methodCall> 
            <methodName>weblogUpdates.extendedPing</methodName> 
            <params> 
           <param><value>{$site_name}</value></param> 
           <param><value>{$site_url}</value></param> 
           <param><value>{$update_url}</value></param> 
           <param><value>{$update_rss}</value></param> 
            </params> 
          </methodCall>";
            return $this->method;
        }
        
        public function _post($url, $postvar) {
            $ch=curl_init ();
            $headers=array ("POST " . $url . " HTTP/1.0", "Content-type: text/xml;charset="utf-8"", "Accept: text/xml", "Content-length: " . strlen ( $postvar ) );
            curl_setopt($ch,CURLOPT_URL,$url);
            curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch,CURLOPT_POST,1);
            curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
            curl_setopt($ch,CURLOPT_POSTFIELDS,$postvar);
            $res=curl_exec($ch);
            curl_close($ch);
            return $res;
        }
        
        public function google() {
            $this->callback = $this->_post ( 'http://blogsearch.google.com/ping/RPC2', $this->method );
            return strpos ( $this->callback, "<boolean>0</boolean>" ) ? true : false;
        }
        
        public function baidu() {
            $this->callback = $this->_post ( 'http://ping.baidu.com/ping/RPC2', $this->method );
            return strpos ( $this->callback, "<int>0</int>" ) ? true : false;
        }
    
    }
    ?>

    /includes/thinkphp/Extend/Vendar/rss/WRss.php

    <?php
    class WRss{
        private $urls="";
        public function add($title,$link,$description,$author,$pubDate,$guid=0,$share=true){
            !empty($title)&&$tmp.="<title>{$title}</title>";
            !empty($link)&&$tmp.="<link>{$link}</link>";
            !empty($description)&&$tmp.="<description>{$description}</description>";
            !empty($author)&&$tmp.="<author>{$author}</author>";
            !empty($pubDate)&&$tmp.="<pubDate>{$pubDate}</pubDate>";
            !empty($guid)&&$tmp.="<guid>{$guid}</guid >";
            $this->urls.="<item>".$tmp."</item>";
        }
        
        public function get($charset="UTF-8"){
            return $this->urls;
        }
        
        public function begin(){
            return '<?xml version="1.0" encoding="UTF-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0"><channel>';
        }
        
        public function end(){
            return "</channel></rss>";
        }
        
        public function site($title,$link,$description,$managingEditor="mengdj@outlook.com",$webMaster="mengdj@outlook.com"){
            return "<title>{$title}</title><link>{$link}</link><description>{$description}</description><managingEditor>{$managingEditor}</managingEditor><webMaster>{$webMaster}</webMaster>";
        }
    }
    ?>

    /includes/thinkphp/Extend/Vendar/sitemap/WSitemap.php

    <?php
    class WSiteMap{
        private $urls="";
        public function add($loc,$lastmod,$changefreq=0,$priority=0){
            !empty($loc)&&$tmp.="<loc>{$loc}</loc>";
            !empty($loc)&&$tmp.="<lastmod>{$lastmod}</lastmod>";
            !empty($loc)&&$tmp.="<changefreq>{$changefreq}</changefreq>";
            !empty($loc)&&$tmp.="<priority>{$priority}</priority>";
            $this->urls.="<url>".$tmp."</url>";
        }
        
        public function get($charset="UTF-8"){
            return $this->urls;
        }
        
        public function begin(){
            return '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
        }
        
        public function end(){
            return "</urlset>";
        }
    }
    ?>

    另外修改了thinkphp默认的Page类文件,其实也就开放了一个统计页数的属性

    修改完成后再后台添加对应的菜单就可以了,祝你好运。另外还有个拍拍平台采集插件,需要的可联系我。¥5元免费使用升级,哈哈...,当是资助开发了。

    文件以及目录可在此处下载:http://files.cnblogs.com/mengdejun/wyao.in.zip

    php源码zend加密和解密方案:http://re.paipai.com/tws/...

  • 相关阅读:
    .NET Interop 工具集
    关于正弦波的算法
    Windows Phone 系列 本地数据存储
    Xaml cannot create an instance of “X”
    Windows Phone 系列 使用 MVVM绑定时无法获取当前值
    Windows Phone 系列 应用程序图标无法显示
    Windows Phone 系列 WPConnect无法上网的问题
    Windows Phone 系列 使用 Windows Phone 保存铃声任务
    WP7.5提交应用
    Windows Phone 系列 动态删除ObservableCollection
  • 原文地址:https://www.cnblogs.com/mengdejun/p/wego_rss_sitemap_ping_paipaiapi_wyaoin_shop_plugin.html
Copyright © 2011-2022 走看看