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

"; print_r($codes_str); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; return html_entity_decode($codes_str); },$str); }else { //$str=preg_replace("/\[img( align=L| align=M| align=R)?( width=[0-9]+)?( height=[0-9]+)?\]\s*(\S+?)\s*\[\/img\]/ise","$this->makeimginrss('\\4')",$str); } //替换所有h6标签为为h4 $str = str_replace("h6","h4",$str); // if ($mbcon['countdownload']=='1' && $inrss==0) $str=preg_replace(array("/\[sfile\]\s*\[attach\]([0-9]+)\[\/attach\]\s*\[\/sfile\]/ise", "/\[file\]\s*\[attach\]([0-9]+)\[\/attach\]\s*\[\/file\]/ise"), array("self::makedownload('\\1', 1, 0, true)", "self::makedownload('\\1', 0, 0, true)"), $str); $str=preg_replace("/\[attach\]([0-9]+)\[\/attach\]/is", "attachment.php?fid=\\1", $str); // $str=preg_replace("/\[sfile\]\s*(\S+?)\s*\[\/sfile\]/ise", "self::makedownload('\\1', 1, $inrss, false)", $str); $str=preg_replace("/\[file\]\s*(\S+?)\s*\[\/file\]/ise", "self::makedownload('\\1', 0, $inrss, false)", $str); //Auto add url link if ($mbcon['autoaddlink']==1) $str=preg_replace("/(?<=[^\]a-z0-9-=\"'\\/])((https?|ftp|gopher|news|telnet|rtsp|mms|callto|ed2k):\/\/|www\.)([a-z0-9\/\-_+=.~!%@?#%&;:$\\()|]+)/i", "[autourl]\\1\\3[/autourl]", $str); $regubb_search = array( "/\[size=([^\[\<]+?)\](.+?)\[\/size\]/ie", "/\[tbl( width=[0-9]+)?(%)?( bgcolor=[^ ]*)?( border=[^ ]*)?\](.+?)\[\/tbl\]/ise", "/\s*\[quote\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", "/\s*\[quote=(.+?)\][\n\r]*(.+?)[\n\r]*\[\/quote\]\s*/is", "/\s*\[code\][\n\r]*(.+?)[\n\r]*\[\/code\]\s*/ie", "/\[autourl\]([^\[]*)\[\/autourl\]/ie", "/\[url\]([^\[]*)\[\/url\]/ie", "/\[url=www.([^\[\"']+?)\](.+?)\[\/url\]/is", "/\[url=([^\[]*)\](.+?)\[\/url\]/is", "/\[email\]([^\[]*)\[\/email\]/is", "/\[acronym=([^\[]*)\](.+?)\[\/acronym\]/is", "/\[color=([a-zA-Z0-9#]+?)\](.+?)\[\/color\]/i", "/\[font=([^\[\<:;\(\)=&#\.\+\*\/]+?)\](.+?)\[\/font\]/i", "/\[p align=([^\[\<]+?)\](.+?)\[\/p\]/i", "/\[b\](.+?)\[\/b\]/i", "/\[i\](.+?)\[\/i\]/i", "/\[u\](.+?)\[\/u\]/i", "/\[strike\](.+?)\[\/strike\]/i", "/\[sup\](.+?)\[\/sup\]/i", "/\[sub\](.+?)\[\/sub\]/i", "/\s*\[php\][\n\r]*(.+?)[\n\r]*\[\/php\]\s*/ie" ); $regubb_replace = array( "self::makefontsize('\\1', '\\2')", "self::maketable('\\5','\\1','\\2','\\3','\\4')", "
\\1
", "
\\2 \\1
", "self::makecode('\\1')", "self::makeurl('\\1')", "self::makeurl('\\1')", "\\2", "\\2", "\\1", "\\2", "\\2", "\\2", "

\\2

", "\\1", "\\1", "\\1", "\\1", "\\1", "\\1", "self::xhtmlHighlightString('\\1')" ); $str=preg_replace($regubb_search, $regubb_replace, $str); //Multimedia Objects, dangerous, so visitors shall never be allowed to post such an object directly if ($advanced==1) { $str =($inrss==0) ? preg_replace("/\[(wmp|swf|real|flv)=([^\[\<]+?),([^\[\<]+?)\]\s*([^\[\<\r\n]+?)\s*\[\/(wmp|swf|real|flv)\]/ies", "makemedia('\\1', '\\4', '\\2', '\\3')", $str) : preg_replace("/\[(wmp|swf|real|flv)=([^\[\<]+?),([^\[\<]+?)\]\s*([^\[\<\r\n]+?)\s*\[\/(wmp|swf|real|flv)\]/is", "
此处包含一个多媒体文件,请用网页方式查看。
", $str); //$str=plugin_walk('ubbanalyseadvance', $str); } return $str; } //解析高亮代码内容为html ol格式,这里主要考虑后续不再引入使用该插件前端相关正则替换的js文件,用markdown编辑器替代 public function convert_article_codes(){ 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('zbp_post')->where('log_ID=604')->limit($start . ','.$pageSize)->order('log_ID asc')->select(); $info = \think\Db::table('zbp_post')->limit($start . ','.$pageSize)->order('log_ID asc')->select(); if(!$info) { echo 'Convert complete';die; } foreach($info as $key=>$val) { $data = array(); $log_ID = $val[log_ID]; $content = $val[log_Content]; session('bid', null); session('bid', $log_ID); $str = preg_replace_callback("/\s*\[codes=(.+?)\][\n\r]*(.+?)[\n\r]*\[\/codes\]\s*/",function ($matches) { $bid = session('bid'); $type = base64_encode($matches[1]); $strtemp = base64_encode($matches[2]); $map = array(); $map['bid'] = $bid; $map['type'] = $type; $map['oldhtml'] = $strtemp; $codes = \think\Db::table('zbp_zzz')->where($map)->order('id desc')->find(); return html_entity_decode($codes[html]); },$content); $data[log_Content] = $str; $info = \think\Db::table('zbp_post')->where('log_ID='.$log_ID)->update($data); } $this->success("成功更新数据$start -- ".$page*$pageSize, url('convert_article_codes', array('page'=>$page+1)), 1); } //保存解析后的高亮代码 public function saveCodeHtml(){ $tempStr = input('post.html_new'); $data = array(); $data['html'] = $tempStr; $data['bid'] = input('post.bid'); $data['type'] = input('post.type'); $data['oldhtml'] = input('post.oldhtml'); \think\Db::table('zbp_zzz')->insert($data); } private function msubstr($str,$start,$end,$len=0) { //UTF-8 Cutting preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/", $str, $info); $lens=sizeof($info[0]); if ($len==1) return array(join("",array_slice($info[0],$start,$end)), $lens); else return join("",array_slice($info[0],$start,$end)); } private function strip_ubbs ($str) { $str=preg_replace("/\[(.+?)\]/is", "", $str); $str=preg_replace("/&(.+?);/is", "", $str); return $str; } private function makecode ($str) { $str=str_replace('[autourl]', '', $str); $str=str_replace('[/autourl]', '', $str); return "
{$str}
"; } private function makefontsize ($size, $word) { $word=stripslashes($word); $sizeitem=array (0, 10, 12, 15, 16, 18, 22, 36); $size=$sizeitem[$size]; //add by rinald 2014-01-05 Start if($size >= 16){ $lineheight='line-height:2.5em;'; } //add by rinald 2014-01-05 Over return "{$word}"; } private function maketable($tablebody, $widthcode, $ifpercentage, $bgcolorcode, $bordercolorcode) { $tablebody=stripslashes($tablebody); $show="\n\n"; $bgcolor=str_replace(' bgcolor=', '', strtolower($bgcolorcode)); $bordercolor=str_replace(' border=', '', strtolower($bordercolorcode)); if (!$bordercolor) $bordercolor="#000000"; if (!$bgcolor) $bgcolor="#ffffff"; $show.="\n"; $show.="\n\n\n\n\n
"; $tablebody=str_replace(',', "", $tablebody); $tablebody=str_replace('
', "
", $tablebody); $tablebody=str_replace('
', "
", $tablebody); $show.=$tablebody; $show.="
\n\n"; return $show; } private function makeurl($url) { global $mbcon; $urllink="'; if($mbcon['shortenurl']=='1' && strlen($url) > $mbcon['urlmaxlen']) { $halfmax=floor($mbcon['urlmaxlen']/2); $url = substr($url, 0, $halfmax).'...'.substr($url, 0-$halfmax); } $urllink .= $url.''; return $urllink; } private function xhtmlHighlightString($str) { $str=base64_decode($str); if (PHP_VERSION<'4.2.0') return "
$str
"; $hlt = highlight_string($str, true); if (PHP_VERSION>'5') return "
$hlt
"; $fon = str_replace(array(''), array(''), $hlt); $ret = preg_replace('#color="(.*?)"#', 'style="color: \\1"', $fon); return "
$ret
"; } private function makedownload ($url, $sfile, $inrss, $isattached=false) { $temp_fid = explode('=',$url)[1]; $url = \think\Db::table('zbp_upload')->where('ul_Intro='.$temp_fid)->find(); $str="点击下载{$url[ul_SourceName]}"; return $str; } ```

本文最后更新于 2019-06-27 13:50:07 并被添加「」标签,已有 1607 位童鞋阅读过。
本文作者:未来往事
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处

此处评论已关闭