`
nakupanda
  • 浏览: 410061 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

从DISCUZ中拿出来的UBBCODE函数

    博客分类:
  • php
阅读更多

<?php
/*
从Discuz7.2中分离出来的UBBCODE函数
*/
function parseurl($url, $text) {
if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) {
$url = $matches[0];
$length = 65;
if(strlen($url) > $length) {
$text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
}
return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>';
} else {
$url = substr($url, 1);
if(substr(strtolower($url), 0, 4) == 'www.') {
$url = 'http://'.$url;
}
return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
}
}

function parseemail($email, $text) {
if(!$email && preg_match("/\s*([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+)\s*/i", $text, $matches)) {
$email = trim($matches[0]);
return '<a href="mailto:'.$email.'">'.$email.'</a>';
} else {
return '<a href="mailto:'.substr($email, 1).'">'.$text.'</a>';
}
}

function parsetrtd($bgcolor, $colspan, $rowspan, $width) {
return ($bgcolor == 'td' ? '</td>' : '<tr'.($bgcolor ? ' bgcolor="'.$bgcolor.'"' : '').'>').'<td'.($colspan > 1 ? ' colspan="'.$colspan.'"' : '').($rowspan > 1 ? ' rowspan="'.$rowspan.'"' : '').($width ? ' width="'.$width.'"' : '').'>';
}

function parsetable($width, $bgcolor, $message) {
if(!preg_match("/^\[tr(?:=([\(\)%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) {
return str_replace('\\"', '"', preg_replace("/\[tr(?:=([\(\)%,#\w]+))?\]|\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]|\[\/td\]|\[\/tr\]/", '', $message));
}
if(substr($width, -1) == '%') {
$width = substr($width, 0, -1) <= 98 ? intval($width).'%' : '98%';
} else {
$width = intval($width);
$width = $width ? ($width <= 560 ? $width.'px' : '98%') : '';
}
return '<table cellspacing="0" class="t_table" '.
($width == '' ? NULL : 'style="width:'.$width.'"').
($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>').
str_replace('\\"', '"', preg_replace(array(
"/\[tr(?:=([\(\)%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie",
"/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/ie",
"/\[\/td\]\s*\[\/tr\]\s*/i"
), array(
"parsetrtd('\\1', '\\2', '\\3', '\\4')",
"parsetrtd('td', '\\1', '\\2', '\\3')",
'</td></tr>'
), $message)
).'</table>';
}

function bbcodeurl($url, $tags) {
if(!preg_match("/<.+?>/s", $url)) {
if(!in_array(strtolower(substr($url, 0, 6)), array('http:/', 'https:', 'ftp://', 'rtsp:/', 'mms://'))) {
$url = 'http://'.$url;
}
return str_replace(array('submit', 'logging.php'), array('', ''), sprintf($tags, $url, addslashes($url)));
} else {
return '&nbsp;'.$url;
}
}

function parseimg($width, $height, $src) {
return bbcodeurl($src, '<img'.($width > 0 ? " width=\"$width\"" : '').($height > 0 ? " height=\"$height\"" : '')." src=\"$src\" border=\"0\" alt=\"\" />");
}

function ubbcode($message){
$msglower = strtolower($message);
if(strpos($msglower, '[/url]') !== FALSE) {
$message = preg_replace("/\[url(=((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k|thunder|synacast){1}:\/\/|www\.|mailto:)([^\s\[\"']+?))?\](.+?)\[\/url\]/ies", "parseurl('\\1', '\\5')", $message);
}
if(strpos($msglower, '[/email]') !== FALSE) {
$message = preg_replace("/\[email(=([a-z0-9\-_.+]+)@([a-z0-9\-_]+[.][a-z0-9\-_.]+))?\](.+?)\[\/email\]/ies", "parseemail('\\1', '\\4')", $message);
}
$message = str_replace(array(
'[/color]', '[/size]', '[/font]', '[/align]', '', '', '[s]', '[/s]', '[hr]', '[/p]',
'[i=s]', '', '', '', '', '
    ', '[list=1]', '[list=a]',
    '[list=A]', '
  • ', '
', '[indent]', '[/indent]', '[/float]' ), array(
'</font>', '</font>', '</font>', '</p>', '<strong>', '</strong>', '<strike>', '</strike>', '<hr class="solidline" />', '</p>', '<i class="pstatus">', '<i>',
'</i>', '<u>', '</u>', '<ul>', '<ul type="1" class="litype_1">', '<ul type="a" class="litype_2">',
'<ul type="A" class="litype_3">', '<li>', '</ul>', '<blockquote>', '</blockquote>', '</span>'
), preg_replace(array(
"/\[color=([#\w]+?)\]/i",
"/\[size=(\d+?)\]/i",
"/\[size=(\d+(\.\d+)?(px|pt|in|cm|mm|pc|em|ex|%)+?)\]/i",
"/\[font=([^\[\<]+?)\]/i",
"/\[align=(left|center|right)\]/i",
"/\[p=(\d{1,2}), (\d{1,2}), (left|center|right)\]/i",
"/\[float=(left|right)\]/i"

), array(
"<font color=\"\\1\">",
"<font size=\"\\1\">",
"<font style=\"font-size: \\1\">",
"<font face=\"\\1 \">",
"<p align=\"\\1\">",
"<p style=\"line-height: \\1px; text-indent: \\2em; text-align: \\3;\">",
"<span style=\"float: \\1;\">"
), $message));
$nest = 0;
while(strpos($msglower, '[table') !== FALSE && strpos($msglower, '') !== FALSE){
$message = preg_replace("/\[table(?:=(\d{1,4}%?)(?:,([\(\)%,#\w ]+))?)?\]\s*(.+?)\s*\[\/table\]/ies", "parsetable('\\1', '\\2', '\\3')", $message);
if(++$nest > 4) break;
}

if(strpos($msglower, '[/img]') !== FALSE) {
$message = preg_replace(array(
"/\[img\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies",
"/\[img=(\d{1,4})[x|\,](\d{1,4})\]\s*([^\[\<\r\n]+?)\s*\[\/img\]/ies"
), array(
"bbcodeurl('\\1', '<img src=\"%s\" onload=\"thumbImg(this)\" alt=\"\" />')",
"parseimg('\\1', '\\2', '\\3')"
), $message);
}

unset($msglower);
return $message;
}
?>



分享到:
评论

相关推荐

    ubbcode函数

    Public Function UbbCode(strContent) Dim re Set re = New RegExp re.IgnoreCase = True re.Global = True ‘过滤危险脚本 re.Pattern = “([removed])” strContent = re.Replace(strContent, ...

    pjblog中的UBBCode.js

    pjblog中的UBBCode.js

    涂鸦板 for dvbbs 6.0

    随便传播~~~我是拿普通的涂鸦板改了来到动网来用~~ 有不明白的就到动网论坛插件专区来问~~我反正经常都在那里~~ 管理帐号和密码都是:admin 进去自己改相关信息~~ 解包出来后把111tuya.asp放在BBS根目录。...

    长乐未央文章管理 HArticle V1.0 Build 20020422

    文章支持UBBCODE,UBBCODE的使用,请参照一般的论坛使用方法,本程序UBBCODE转化代码借鉴了动网论坛的代码,感谢动网论坛! 3. 可以说没有后台文件,所有管理均结合于前台,可进行移动整个版块的文章或者某篇文章到...

    BIWEB商务智能网站系统 v5.8.1

    BIWEB商务智能网站系统是依托在ArthurXF企业应用级PHP开发框架上的大型网站系统,是由上海网务网络信息有限公司经历了5年不断的在各种大型项目中实践、总结、开发设计出来的一个快速开发、简单易用的面向对象的企业...

    Java-PHP-C#

    比如说,我们想从 path/URL 提取文件名 – 下面的代码就是你需要: ereg("([^\\/]*)$", $pathOrUrl, $regs); echo $regs[1]; 高级的代换 ereg_replace() 和 eregi_replace()也是非常有用的: 假如我们想把所有...

    ubb表情 可以直接使用

    ubb 表情 face文件夹 表情图片目录 ubb.css CSS样式文件 faces.js JS功能文件 ubbcode.php UBB解释函数,使用方法示例:($info['content']);?&gt; face.html 演示文件,请看HTML代码

    LESSY-BLOG(LBS2.0.283汉化修改版)

    在 Cookies 里面使用 User ID 而不是 username, 可能修正了 cookies 的保存问题- class/functions.asp: 修改 trimUBB() 函数- class/ubbcode.asp: 用 &lt;blockquote&gt; 和 &lt;pre&gt; 来转换 [quote] 和 [code] 标记, 修正 ...

    新互CMS网站管理系统 v1.0.rar

    如果您的服务器IE为5.5或者以上版本,可以使用inc/ie5.5 目录中ubbcode.asp文件替换inc目录下同名文件。 3. 设置使用 1) 在一般情况下上传到服务器或者本地WEB目录后即可以正常使用。直接在浏览器中输入地址就可...

    asp常用字符串处理库-适合初学者

    1、MyFormatDatetime ...5、UBBCode 不说你也知道 6、JavaInfo JS提示 7、MyPrint Response.write 改装 8、MyRequest Request改装 9、cutStr() 解决文章标题长度 这一套字符串处理函数解决了文章系统的几乎所有需求。

    GuestBook Therefor 2002 Build 0001

    同时支持emotion、UBBCode、多样template(模板)、主页嵌入、核心+界面分离编写的中文留言簿程序!是目前专业主页设计之留言簿完美解决方案!

    leadbbs3.14 D调美化全插件增强版

    23论坛里的贴图自动加上阴影 24是否开放媒体播放可以轻松选择的更新UBBCODE 25加入顶部翻页、底部发帖的方法(包括主题列表和帖子界面) 26强化了的收件箱,可标记已读/为读 27首页显示区版主 28经验做...

    无忧中国休闲社区新动网风格Dvbbs6.1A

    5、如果您的服务器IE为5.5或者以上版本,可以使用论坛inc/ie5.5+目录中ubbcode.asp文件替换inc目录下同名文件以达到最佳浏览效果 6、完成了以上步骤后,就可以正常使用论坛了;为了保障论坛系统的稳定和...

    asp.net(c#) ubb处理类

    代码如下:using System; using System.Web; using System.Web.UI; using System.Text.RegularExpressions; namespace STH.function { /// &lt;summary&gt; /// UbbCode... public UbbCode() { // // TODO: 在此处添加构造函数

    精通正则表达式基于.NET ASP PHP JSP JavaScript

    JSPExample5.jsp JSP页面中字符数据的简单使用 JSPExample6.jsp 结合布尔类型变量判断学生成绩等级 JSPExample7.jsp text.html页面提交至该页,并显示提交数据 text.html 页面数据提交至...

    动网Dvbbs v8.2.0 Build 20090904.rar

    16、修正 Dv_ubbcode.asp文件中有书写错误 Inc/Dv_ubbcode.asp 更新相应文件 17、修正 设置用户不能查看其他用户发帖时也无法查看自己的帖子 Dispbbs.asp 更新相应文件 18、修正 加入圈子点券数限制失效问题 ...

    Struts+Hibernate做的BBS

    ①、将原论坛数据库文件夹及数据库文件、inc\BBSSetup.asp、inc\md5.asp、inc\AD_Data.asp、inc\Ubbcode_Setup.asp、inc\Upload_Setup.asp、inc\User_Setup.asp及user\inc\user_reg.asp三个文件按原文件夹结构上传;...

Global site tag (gtag.js) - Google Analytics