From 6ebcc3f4fd1ef984870981cddec4a896a05bc4ea Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Fri, 20 May 2011 05:53:11 +0000 Subject: [PATCH] * move the parseUBB() to ubb.class.php. --- lib/front/front.class.php | 173 +------------------------------------- lib/ubb/ubb.class.php | 158 ++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 171 deletions(-) create mode 100644 lib/ubb/ubb.class.php diff --git a/lib/front/front.class.php b/lib/front/front.class.php index 6d4f077270..09c5a04b13 100644 --- a/lib/front/front.class.php +++ b/lib/front/front.class.php @@ -9,6 +9,7 @@ * @version $Id$ * @link http://www.zentao.net */ + /** * The html class, to build html tags. * @@ -155,7 +156,7 @@ class html $string .= "\n"; foreach($options as $key => $value) { - $key = str_replace('item', '', $key); // 因为对象的元素不能为数字,所以需要在配置里面会在数字前面添加item,这个地方将item去掉。 + $key = str_replace('item', '', $key); $selected = strpos($selectedItems, ",$key,") !== false ? " selected='selected'" : ''; $string .= "\n"; } @@ -342,176 +343,6 @@ class html { return " "; } - - /** - * create a export link. - * - * @param string $label - * @param string $pluginTitle - * @param string $misc - * @static - * @access public - * @return void - */ - public static function export2csv($label = '', $pluginTitle, $misc = '') - { - return "$label\n\n"; - } - - /** - * ubb2html support for php - * @requires xhEditor - * - * @author Yanis.Wang - * @site http://xheditor.com/ - * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php) - * - * @Version: 0.9.8 (build 100505) - */ - public static function parseUBB($sUBB) - { - $sHtml=$sUBB; - - global $emotPath,$cnum,$arrcode,$bUbb2htmlFunctionInit;$cnum=0;$arrcode=array(); - $emotPath='../xheditor_emot/'; - - if(!$bUbb2htmlFunctionInit) - { - function saveCodeArea($match) - { - global $cnum,$arrcode; - $cnum++;$arrcode[$cnum]=$match[0]; - return "[\tubbcodeplace_".$cnum."\t]"; - } - } - - $sHtml=preg_replace_callback('/\[code\s*(?:=\s*((?:(?!")[\s\S])+?)(?:"[\s\S]*?)?)?\]([\s\S]*?)\[\/code\]/i','saveCodeArea',$sHtml); - - //$sHtml=preg_replace("/&/",'&',$sHtml); - //$sHtml=preg_replace("//",'>',$sHtml); - $sHtml=preg_replace("/\r?\n/",'
',$sHtml); - - $sHtml=preg_replace("/\[(\/?)(b|u|i|s|sup|sub)\]/i",'<$1$2>',$sHtml); - $sHtml=preg_replace('/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i','',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getSizeName($match) - { - $arrSize=array('8pt','10pt','12pt','14pt','18pt','24pt','36pt'); - return ''; - } - } - $sHtml=preg_replace_callback("/\[size\s*=\s*(\d+?)\s*\]/i",'getSizeName',$sHtml); - $sHtml=preg_replace('/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i','',$sHtml); - $sHtml=preg_replace('/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i','',$sHtml); - $sHtml=preg_replace("/\[\/(color|size|font|back)\]/i",'',$sHtml); - - for($i=0;$i<3;$i++)$sHtml=preg_replace('/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/','

$2

',$sHtml); - $sHtml=preg_replace('/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/i','',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getImg($match) - { - $alt=$match[1];$p1=$match[2];$p2=$match[3];$p3=$match[4];$src=$match[5]; - $a=$p3?$p3:(!is_numeric($p1)?$p1:''); - return ''.$alt.''; - } - } - - $sHtml=preg_replace_callback('/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/i','getImg',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getEmot($match) - { - global $emotPath; - $arr=split(',',$match[1]); - if(!isset($arr[1])){$arr[1]=$arr[0];$arr[0]='default';} - $path=$emotPath.$arr[0].'/'.$arr[1].'.gif'; - return ''.$arr[1].''; - } - } - - $sHtml=preg_replace_callback('/\[emot\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\/\]/i','getEmot',$sHtml); - $sHtml=preg_replace('/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/i','$1',$sHtml); - $sHtml=preg_replace('/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/i','$2',$sHtml); - $sHtml=preg_replace('/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/i','$1',$sHtml); - $sHtml=preg_replace('/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/i','$2',$sHtml); - $sHtml=preg_replace("/\[quote\]([\s\S]*?)\[\/quote\]/i",'
$1
',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getFlash($match) - { - $w=$match[1];$h=$match[2];$url=$match[3]; - if(!$w)$w=480;if(!$h)$h=400; - return ''; - } - } - $sHtml=preg_replace_callback('/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/i','getFlash',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getMedia($match) - { - $w=$match[1];$h=$match[2];$play=$match[3];$url=$match[4]; - if(!$w)$w=480;if(!$h)$h=400; - return ''; - } - } - $sHtml=preg_replace_callback('/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/i','getMedia',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getTable($match) - { - return ''; - } - } - $sHtml=preg_replace_callback('/\[table\s*(?:=(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/i','getTable',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getTR($match){return '';} - } - $sHtml=preg_replace_callback('/\[tr\s*(?:=(\s*[^\]"]+))?(?:"[^\]]*?)?\s*\]/i','getTR',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getTD($match) - { - $col=isset($match[1])?$match[1]:0;$row=isset($match[2])?$match[2]:0;$w=isset($match[3])?$match[3]:null; - return '1?' colspan="'.$col.'"':'').($row>1?' rowspan="'.$row.'"':'').($w?' width="'.$w.'"':'').'>'; - } - } - $sHtml=preg_replace_callback("/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/i",'getTD',$sHtml); - $sHtml=preg_replace("/\[\/(table|tr|td)\]/i",'',$sHtml); - $sHtml=preg_replace("/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/i",'
  • $1
  • ',$sHtml); - if(!$bUbb2htmlFunctionInit) - { - function getUL($match) - { - $str=''; - } - } - $sHtml=preg_replace_callback('/\[list\s*(?:=\s*([^\]"]+))?(?:"[^\]]*?)?\s*\]/i','getUL',$sHtml); - $sHtml=preg_replace("/\[\/list\]/i",'',$sHtml); - - for($i=1;$i<=$cnum;$i++)$sHtml=str_replace("[\tubbcodeplace_".$i."\t]", $arrcode[$i],$sHtml); - - if(!$bUbb2htmlFunctionInit) - { - function fixText($match) - { - $text=$match[2]; - $text=preg_replace("/\t/",'        ',$text); - $text=preg_replace("/ /",' ',$text); - return $match[1].$text; - } - } - $sHtml=preg_replace_callback('/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/i','fixText',$sHtml); - - $bUbb2htmlFunctionInit=true; - - return $sHtml; - } } /** diff --git a/lib/ubb/ubb.class.php b/lib/ubb/ubb.class.php new file mode 100644 index 0000000000..3114f64599 --- /dev/null +++ b/lib/ubb/ubb.class.php @@ -0,0 +1,158 @@ + + * @site http://xheditor.com/ + * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php) + * + * @Version: 0.9.8 (build 100505) + */ +class ubb +{ + public static function parseUBB($sUBB) + { + $sHtml=$sUBB; + + global $emotPath,$cnum,$arrcode,$bUbb2htmlFunctionInit;$cnum=0;$arrcode=array(); + $emotPath='../xheditor_emot/'; + + if(!$bUbb2htmlFunctionInit) + { + function saveCodeArea($match) + { + global $cnum,$arrcode; + $cnum++;$arrcode[$cnum]=$match[0]; + return "[\tubbcodeplace_".$cnum."\t]"; + } + } + + $sHtml=preg_replace_callback('/\[code\s*(?:=\s*((?:(?!")[\s\S])+?)(?:"[\s\S]*?)?)?\]([\s\S]*?)\[\/code\]/i','saveCodeArea',$sHtml); + + //$sHtml=preg_replace("/&/",'&',$sHtml); + //$sHtml=preg_replace("//",'>',$sHtml); + $sHtml=preg_replace("/\r?\n/",'
    ',$sHtml); + + $sHtml=preg_replace("/\[(\/?)(b|u|i|s|sup|sub)\]/i",'<$1$2>',$sHtml); + $sHtml=preg_replace('/\[color\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i','',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getSizeName($match) + { + $arrSize=array('8pt','10pt','12pt','14pt','18pt','24pt','36pt'); + return ''; + } + } + $sHtml=preg_replace_callback("/\[size\s*=\s*(\d+?)\s*\]/i",'getSizeName',$sHtml); + $sHtml=preg_replace('/\[font\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i','',$sHtml); + $sHtml=preg_replace('/\[back\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]/i','',$sHtml); + $sHtml=preg_replace("/\[\/(color|size|font|back)\]/i",'',$sHtml); + + for($i=0;$i<3;$i++)$sHtml=preg_replace('/\[align\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\](((?!\[align(?:\s+[^\]]+)?\])[\s\S])*?)\[\/align\]/','

    $2

    ',$sHtml); + $sHtml=preg_replace('/\[img\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/img\]/i','',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getImg($match) + { + $alt=$match[1];$p1=$match[2];$p2=$match[3];$p3=$match[4];$src=$match[5]; + $a=$p3?$p3:(!is_numeric($p1)?$p1:''); + return ''.$alt.''; + } + } + + $sHtml=preg_replace_callback('/\[img\s*=([^,\]]*)(?:\s*,\s*(\d*%?)\s*,\s*(\d*%?)\s*)?(?:,?\s*(\w+))?\s*\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*)?\s*\[\/img\]/i','getImg',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getEmot($match) + { + global $emotPath; + $arr=split(',',$match[1]); + if(!isset($arr[1])){$arr[1]=$arr[0];$arr[0]='default';} + $path=$emotPath.$arr[0].'/'.$arr[1].'.gif'; + return ''.$arr[1].''; + } + } + + $sHtml=preg_replace_callback('/\[emot\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\/\]/i','getEmot',$sHtml); + $sHtml=preg_replace('/\[url\]\s*(((?!")[\s\S])*?)(?:"[\s\S]*?)?\s*\[\/url\]/i','$1',$sHtml); + $sHtml=preg_replace('/\[url\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]*?)\s*\[\/url\]/i','$2',$sHtml); + $sHtml=preg_replace('/\[email\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/email\]/i','$1',$sHtml); + $sHtml=preg_replace('/\[email\s*=\s*([^\]"]+?)(?:"[^\]]*?)?\s*\]\s*([\s\S]+?)\s*\[\/email\]/i','$2',$sHtml); + $sHtml=preg_replace("/\[quote\]([\s\S]*?)\[\/quote\]/i",'
    $1
    ',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getFlash($match) + { + $w=$match[1];$h=$match[2];$url=$match[3]; + if(!$w)$w=480;if(!$h)$h=400; + return ''; + } + } + $sHtml=preg_replace_callback('/\[flash\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/flash\]/i','getFlash',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getMedia($match) + { + $w=$match[1];$h=$match[2];$play=$match[3];$url=$match[4]; + if(!$w)$w=480;if(!$h)$h=400; + return ''; + } + } + $sHtml=preg_replace_callback('/\[media\s*(?:=\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+)\s*)?)?\]\s*(((?!")[\s\S])+?)(?:"[\s\S]*?)?\s*\[\/media\]/i','getMedia',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getTable($match) + { + return ''; + } + } + $sHtml=preg_replace_callback('/\[table\s*(?:=(\d{1,4}%?)\s*(?:,\s*([^\]"]+)(?:"[^\]]*?)?)?)?\s*\]/i','getTable',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getTR($match){return '';} + } + $sHtml=preg_replace_callback('/\[tr\s*(?:=(\s*[^\]"]+))?(?:"[^\]]*?)?\s*\]/i','getTR',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getTD($match) + { + $col=isset($match[1])?$match[1]:0;$row=isset($match[2])?$match[2]:0;$w=isset($match[3])?$match[3]:null; + return '1?' colspan="'.$col.'"':'').($row>1?' rowspan="'.$row.'"':'').($w?' width="'.$w.'"':'').'>'; + } + } + $sHtml=preg_replace_callback("/\[td\s*(?:=\s*(\d{1,2})\s*,\s*(\d{1,2})\s*(?:,\s*(\d{1,4}%?))?)?\s*\]/i",'getTD',$sHtml); + $sHtml=preg_replace("/\[\/(table|tr|td)\]/i",'',$sHtml); + $sHtml=preg_replace("/\[\*\]((?:(?!\[\*\]|\[\/list\]|\[list\s*(?:=[^\]]+)?\])[\s\S])+)/i",'
  • $1
  • ',$sHtml); + if(!$bUbb2htmlFunctionInit) + { + function getUL($match) + { + $str=''; + } + } + $sHtml=preg_replace_callback('/\[list\s*(?:=\s*([^\]"]+))?(?:"[^\]]*?)?\s*\]/i','getUL',$sHtml); + $sHtml=preg_replace("/\[\/list\]/i",'',$sHtml); + + for($i=1;$i<=$cnum;$i++)$sHtml=str_replace("[\tubbcodeplace_".$i."\t]", $arrcode[$i],$sHtml); + + if(!$bUbb2htmlFunctionInit) + { + function fixText($match) + { + $text=$match[2]; + $text=preg_replace("/\t/",'        ',$text); + $text=preg_replace("/ /",' ',$text); + return $match[1].$text; + } + } + $sHtml=preg_replace_callback('/(^|<\/?\w+(?:\s+[^>]*?)?>)([^<$]+)/i','fixText',$sHtml); + + $bUbb2htmlFunctionInit=true; + + return $sHtml; + } +}