51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

bo-blog转换zblog程序代码-基于thinkphp5

//转换分类
    public function convert_cate(){
        $page = input('page') ? input('page') : 1 ;
        $pageSize = 10;
        $start = ($page-1)*$pageSize;
        $where = array();
        $info = \think\Db::table('blog_categories')->where($where)->limit($start . ','.$pageSize)->order('cateid asc')->select();
        //dump($info);die;
        if(!$info) {
                echo 'Convert complete';die;
        }
        foreach($info as $key=>$val) {
            $data = array();
            $data[cate_ID] = $val[cateid];
            $data[cate_Name] = $val[catename];
            $data[cate_Order] = $val[cateorder];
            $data[cate_Alias] = $val[cateurlname];
            $data[cate_Intro] = html_entity_decode($val[catedesc]);
            $info = \think\Db::table('zbp_category')->insert($data);
        }
        $this->success("成功转换数据$start -- ".$page*$pageSize, url('convert_cate', array('page'=>$page+1)), 1);
    }
    //转换tag标签,所有数据转换完成后可以清空tag_Intro、tag_Alias字段
    public function convert_tag(){
        $page = input('page') ? input('page') : 1 ;
        $pageSize = 10;
        $start = ($page-1)*$pageSize;
        $where = array();
        $info = \think\Db::table('blog_tags')->where($where)->limit($start . ','.$pageSize)->order('tagid asc')->select();
        //dump($info);die;
        if(!$info) {
                echo 'Convert complete';die;
        }
        foreach($info as $key=>$val) {
            $data = array();
            $data[tag_Name] = $val[tagname];
            $data[tag_Count] = $val[tagcounter];
            $data[tag_Intro] = $val[tagentry];
            $data[tag_Alias] = $val[tagid];
            $info = \think\Db::table('zbp_tag')->insert($data);
        }
        $this->success("成功转换数据$start -- ".$page*$pageSize, url('convert_tag', array('page'=>$page+1)), 1);
    }
    //转换upload附件,所有数据转换完成后可以清空ul_Intro、ul_Meta字段内容,注意附件格式需要是:/2017/05/
    public function convert_upload(){
        $page = input('page') ? input('page') : 1 ;
        $pageSize = 10;
        $start = ($page-1)*$pageSize;
        $where = array();
        $info = \think\Db::table('blog_upload')->where($where)->limit($start . ','.$pageSize)->order('fid asc')->select();
        if(!$info) {
                echo 'Convert complete';die;
        }
        foreach($info as $key=>$val) {
            $data = array();
            $data[ul_AuthorID] = 1;
            $data[ul_Name] = explode('/', $val[filepath])[2];
            $ul_Meta = str_replace("attachment","https://www.fity.cn/usr/uploads",$val[filepath]);
            $ul_Meta = explode('/', $ul_Meta);
            $data[ul_Meta] = $ul_Meta[0].'/'.$ul_Meta[1].'/'.substr($ul_Meta[2] , 0 , 4).'/'.substr($ul_Meta[2] , 4 , 2).'/'.$ul_Meta[3];
//            https://www.fity.cn/usr/uploads/2017/05/201705191495194584213280.gif
//            https://www.fity.cn/usr/uploads/201305/1369327844_617989de.jpg
//            attachment/201305/1369327844_617989de.jpg

            $data[ul_SourceName] = $val[originalname];
            if(strpos($val[filepath], 'jpg') !== false){
                $data[ul_MimeType] = 'image/jpg';
            }
            if(strpos($val[filepath], 'jpeg') !== false){
                $data[ul_MimeType] = 'image/jpeg';
            }
            if(strpos($val[filepath], 'png') !== false){
                $data[ul_MimeType] = 'image/png';
            }
            if(strpos($val[filepath], 'gif') !== false){
                $data[ul_MimeType] = 'image/gif';
            }
            if(strpos($val[filepath], 'zip') !== false){
                $data[ul_MimeType] = 'application/octet-stream';
            }
            if(strpos($val[filepath], 'rar') !== false){
                $data[ul_MimeType] = 'application/octet-stream';
            }
            if(strpos($val[filepath], 'pdf') !== false){
                $data[ul_MimeType] = 'application/octet-stream';
            }
            $data[ul_PostTime] = $val[uploadtime];
            $data[ul_DownNums] = $val[dltime];
//            $data[ul_LogID] = $val[tagid];
            $data[ul_Intro] = $val[fid]; //旧fid记录
            $info = \think\Db::table('zbp_upload')->insert($data);
        }
        $this->success("成功转换数据$start -- ".$page*$pageSize, url('convert_upload', array('page'=>$page+1)), 1);
    }
    
    //转换评论
    public function convert_comment(){
        $page = input('page') ? input('page') : 1 ;
        $pageSize = 10;
        $start = ($page-1)*$pageSize;
        $where = array();
        //$where['blogid'] = '486';
        $info = \think\Db::table('blog_replies')->where($where)->limit($start . ','.$pageSize)->order('repid asc')->select();
        //dump($info);die;
        if(!$info) {
                echo 'Convert complete';die;
        }
        foreach($info as $key=>$val) {
            $data = array();
            $re_data = array();
            
            //$data[comm_ID] = $val[repid];
            $data[comm_LogID] = $val[blogid];
            $data[comm_IsChecking] = 0;
            $data[comm_RootID] = 0;
            $data[comm_ParentID] = 0;
            $data[comm_AuthorID] = 0;
            $data[comm_Name] = $val[replier];
            $data[comm_Email] = $val[repemail];
            $data[comm_HomePage] = $val[repurl];
            $data[comm_Content] = preg_replace('/\[emot\]([^\[]*)\[\/emot\]/','',$val[repcontent]);
            $data[comm_PostTime] = $val[reptime];
            $data[comm_IP] = $val[repip];
            $data[comm_Agent] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0';
            $data[comm_Meta] = '';
            $info = \think\Db::table('zbp_comment')->insert($data);
            $comm_ParentID = \think\Db::table('zbp_comment')->getLastInsID();
            \think\Db::table('zbp_post')->where('log_ID', $val[blogid])->setInc('log_CommNums'); //更新评论数

            if($val[adminrepcontent]){
                $re_data[comm_LogID] = $val[blogid];
                $re_data[comm_IsChecking] = 0;
                $re_data[comm_RootID] = $comm_ParentID;
                $re_data[comm_ParentID] = $comm_ParentID;
                $re_data[comm_AuthorID] = 1;
                $re_data[comm_Name] = $val[adminreplier];
                $re_data[comm_Email] = '136654168@qq.com';
                $re_data[comm_HomePage] = 'https://www.fity.cn';
                $re_data[comm_Content] = preg_replace('/\[emot\]([^\[]*)\[\/emot\]/','',$val[adminrepcontent]);
                $re_data[comm_PostTime] = $val[adminreptime];
                $re_data[comm_IP] = '::1';
                $re_data[comm_Agent] = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0';
                $re_data[comm_Meta] = '';
                $info = \think\Db::table('zbp_comment')->insert($re_data);
                \think\Db::table('zbp_post')->where('log_ID', $val[blogid])->setInc('log_CommNums'); //更新评论数
            }

        }
        $this->success("成功转换数据$start -- ".$page*$pageSize, url('convert_comment', array('page'=>$page+1)), 1);
    }
    
    //转换文章
    public function convert_article(){
//            echo base64_encode('<br/> 1123');die;
        
            header("Content-type: text/html; charset=utf-8");
            $page = input('page') ? input('page') : 1 ;
            $pageSize = 10;
            $start = ($page-1)*$pageSize;
            $where = array();
//            $info = \think\Db::table('blog_blogs')->where('blogid=604')->limit($start . ','.$pageSize)->order('blogid asc')->select();
            $info = \think\Db::table('blog_blogs')->limit($start . ','.$pageSize)->order('blogid asc')->select();
            if(!$info) {
                    echo 'Convert complete';die;
            }
            foreach($info as $key=>$val) {
                $data = array();
                $data[log_ID] = $val[blogid];
                $data[log_CateID] = $val[category]; //分类
                $data[log_AuthorID] = 1;
                $data[log_Status] = ($val[property] == 3) ? 1 : 0;
                $data[log_Type] = 0;
                $data[log_IsTop] = ($val[sticky] != 0) ? 2 : 0;
                $data[log_Title] = $val[title];
                $data[log_PostTime] = $val[pubtime];
                $data[log_CommNums] = ($val[replies] > 4) ? 1 : 0;
                $data[log_ViewNums] = $val[views];
                //摘要
                $newDescription = preg_replace(array("/\[url=([^\[]*)\](.+?)\[\/url\]/is","/\s*\[attach\](.*?)\[\/attach\]\s*/is","/\s*\[img(.*?)\/img\]\s*/is","/\s*\[clickandsee(.+?)\/clickandsee\]\s*/is","/\s*\[code\](.+?)\[\/code\]\s*/is","/\s*\[codes(.*?)\/codes\]\s*/is","/\s*\[hide\](.*?)\[\/hide\]\s*/is"),array("\\2","","","","","",""),$val['content']);
		$newDescription = $this->msubstr(strip_tags(preg_replace("([a-zA-z]+://[^\s|\<]*)","",$this->strip_ubbs($newDescription))), 0, 180);
                $data[log_Intro] = $newDescription;
                //正文
                $content = str_replace('[newpage]', '[separator]', $val['content']);
                $content = str_replace('[separator]', '<!--more-->', $content);
                $content = $this->convert_ubb($content,1,0,$val[blogid]);
                $data[log_Content] = $content;
                //tags标签转换:>知识>google>
                $tags = trim($val[tags],'>');
                $tags = explode('>', $tags);
                $new_tag = '';
                foreach ($tags as $key=>$val){
                    $tagid = '';
                    $map = array();
                    $map['tag_Name'] = $val;
                    $tagid = \think\Db::table('zbp_tag')->where($map)->value('tag_ID');
                    $new_tag .= ($tagid) ? '{'.$tagid.'}' : '';
                }
                $data[log_Tag] = $new_tag;   //标签
//                print_r($data);
//                die;
                //分隔符处理
                //$entry['content']=preg_replace("/\[separator\]/", "<a name=\"entrymore\"></a>", $entry['content'], 1);
                //$entry['content']=@str_replace('[separator]', '', $entry['content']);
                $info = \think\Db::table('zbp_post')->insert($data);
            }
            $this->success("成功转换数据$start -- ".$page*$pageSize, url('convert_article', array('page'=>$page+1)), 1);
        }

        private function convert_ubb ($str, $advanced=0, $inrss=0,$id) {
//            if ($logstat!=1) {
//                    $str=preg_replace("/\[hide\](.+?)\[\/hide\]/is", "<div class=\"quote hidebox\"><div class=\"quote-title\">隐藏内容</div><div class=\"quote-content\">这部分内容只能在登入之后看到。请先  <a href=\"{$config['blogurl']}/login.php?job=register\">{$lnc[79]}</a> {$lnc[235]} <a href=\"{$config['blogurl']}/login.php\">{$lnc[89]}</a> </div></div>", $str);
//            } else {
//                    $str=str_replace(array('[hide]','[/hide]'), '', $str);
//            }
            $str=str_replace(array('[hide]','[/hide]'), '', $str);
            $str=str_replace(array('{','}'), array('{', '}'), $str);
            //$str=plugin_walk('ubbanalyse', $str);
            $basicubb_search=array('[hr]', '<br>');
            $basicubb_replace=array('<hr/>', '<br/>');
            $str=str_replace($basicubb_search, $basicubb_replace, $str);

            //[IMG]
            if ($advanced==1) {
                    $str = preg_replace_callback("/\[url=([^\[]*)\]\[img( align=L| align=M| align=R)?( width=[0-9]+)?( height=[0-9]+)?\]\s*(\S+?)\s*\[\/img\]\[\/url\]/",function ($matches) {           
                            $aligncode = $matches[1];
                            $widthcode = $matches[2];
                            $heightcode = $matches[3];
                            $src = $matches[4];
                            $inrss = 0;
                            $align=str_replace(' align=', '', strtolower($aligncode));
                            if ($align=='l') $show=' align="left"';
                            elseif ($align=='r') $show=' align="right"';
                            else $alignshow='';
                            $width=str_replace(' width=', '', strtolower($widthcode));
                            if (!empty($width)) $show.=" width=\"{$width}\"";
                            $height=str_replace(' height=', '', strtolower($heightcode));
                            if (!empty($height)) $show.=" height=\"{$height}\"";
                            if ($inrss==1) $src=(substr(strtolower($src), 0, 4) == 'http') ? $src : 'https://www.fity.cn//'.$src;
                            
                            $temp_fid = explode('[/attach]',explode('[attach]', $src)[1])[0];
                            
                            if($temp_fid){
                                $src = \think\Db::table('zbp_upload')->where('ul_Intro='.$temp_fid)->value('ul_Meta');
                            }
                            //$onloadact=($inrss==0 && !empty($mbcon['autoresizeimg'])) ? " onload=\"if(this.width>{$mbcon['autoresizeimg']}) {this.resized=true; this.width={$mbcon['autoresizeimg']};}\"" : '';
                            $code="<a href=\"{$src}\" target=\"_blank\"><img src=\"{$src}\" class=\"insertimage\" alt=\"点击在新窗口中浏览此图片\" title=\"点击在新窗口中浏览此图片\" border=\"0\"{$onloadact}{$show}/></a>";
                            return $code;
                    },$str);               

                    $str = preg_replace_callback("/\[img( align=L| align=M| align=R)?( width=[0-9]+)?( height=[0-9]+)?\]\s*(\S+?)\s*\[\/img\]/",function ($matches) {
                            $aligncode = $matches[1];
                            $widthcode = $matches[2];
                            $heightcode = $matches[3];
                            $src = $matches[4];
                            $inrss = 0;
                            //global $lnc, $mbcon, $config;
                            $align=str_replace(' align=', '', strtolower($aligncode));
                            if ($align=='l') $show=' align="left"';
                            elseif ($align=='r') $show=' align="right"';
                            else $alignshow='';
                            $width=str_replace(' width=', '', strtolower($widthcode));
                            if (!empty($width)) $show.=" width=\"{$width}\"";
                            $height=str_replace(' height=', '', strtolower($heightcode));
                            if (!empty($height)) $show.=" height=\"{$height}\"";
                            if ($inrss==1) $src=(substr(strtolower($src), 0, 4) == 'http') ? $src : 'https://www.fity.cn//'.$src;
                            $temp_fid = explode('[/attach]',explode('[attach]', $src)[1])[0];
                            if($temp_fid){
                                $src = \think\Db::table('zbp_upload')->where('ul_Intro='.$temp_fid)->value('ul_Meta');
                            }
                            //$onloadact=($inrss==0 && !empty($mbcon['autoresizeimg'])) ? " onload=\"if(this.width>{$mbcon['autoresizeimg']}) {this.resized=true; this.width={$mbcon['autoresizeimg']};}\"" : '';
                            $code="<a href=\"{$src}\" target=\"_blank\"><img src=\"{$src}\" class=\"insertimage\" alt=\"点击在新窗口中浏览此图片\" title=\"点击在新窗口中浏览此图片\" border=\"0\"{$onloadact}{$show}/></a>";
                            return $code;
                    },$str);
                    
                    //代码高亮处理,如果你安装了dphighlighter插件
                    session('bid', null);
                    session('bid', $id);
                    $str_temp = preg_replace_callback("/\s*\[codes=(.+?)\][\n\r]*(.+?)[\n\r]*\[\/codes\]\s*/",function ($matches) {
                            $bid = session('bid'); 
                            $type = $matches[1];
                            $strtemp = base64_encode($matches[2]);
                            $strtemp = base64_decode(str_replace(" ","+",$strtemp));
                            $strtemp = str_replace("<br/>", "\n" , stripslashes($strtemp));
                            echo '<script type="text/javascript" src="http://192.168.4.158/static/test/jquery-1.8.2.min.js"></script>';
                            echo '<style>body{font-size:11px;}</style>';
                            echo '<script>'
                            . '$("body").empty();'
                            . '</script>';
                            $codes_str = "<textarea name=\"code\" class=\"{$type}\" rows=\"15\" cols=\"100\">".htmlspecialchars_decode($strtemp)."
赞(1)
未经允许不得转载:工具盒子 » bo-blog转换zblog程序代码-基于thinkphp5