|
Posted on 2006-05-20 20:27 oxl 阅读(911) 评论(1) 编辑 收藏 所属分类: 工作琐碎
block.result_section.php
function smarty_block_result_section($params, $content, &$smarty, &$repeat) { extract($params); $row = mysql_fetch_assoc($result); if ($row) { $smarty->assign($flag, $row); $repeat = true; } else { $repeat = false; } return $content; }
function.more_page.php
function smarty_function_more_page($params, $smarty) { extract($params); ob_start(); if($pagesum>1){ $back=$page-1; $next=$page+1; echo "<table cellspacing=0 cellpadding=0 border=0 width=100%>\n"; echo "<form method=post>\n"; echo "<tr>\n"; echo "<td align=right noWrap>\n"; if($page>1){ echo "<a href=\"?$escape","size=$size&page=1\">[首页]</a>\n"; echo "<a href=\"?$escape","size=$size&page=$back\">[前页]</a>\n"; } if($page<$pagesum){ echo "<a href=\"?$escape","size=$size&page=$next\">[后页]</a>\n"; echo "<a href=\"?$escape","size=$size&page=$pagesum\">[尾页]</a>\n"; } echo"主题数[<font color=ff0000>$sum</font>]\n"; echo"序号[<font color=ff0000>",$num+1,"~$last</font>]\n"; echo "第[<font color=ff0000>$page</font>]页/共[<font color=ff0000>$pagesum</font>]页 \n"; echo "转到:<input type=text name=page size=2 maxlength=4 style=\"font-size:12px;height:16px\" onFocus=\"this.select()\">\n"; echo "<input type=\"submit\" value=\"跳 转\" style=\"background:cccccc;border-width:1px;font-size:12px;height:16px;cursor:hand\">\n"; $array=split("&",urldecode($escape)); for($i=0;$i<count($array);$i++){ list($name,$value)=split("=",$array[$i]); if($value!=""){ echo "<input type=hidden name=\"$name\" value=\"$value\">\n"; } } echo "<input type=hidden name=size value=\"$size\">\n"; echo "</td>\n"; echo "</tr>\n"; echo "</form>\n"; echo "</table>\n"; } $content = ob_get_contents(); ob_end_clean(); return $content; } modifier.ubbdecode.php
function smarty_modifier_ubbdecode($code,$url){ $code=preg_replace("/<br>/is","\n",$code); $code=preg_replace("/<br>/is","[br]",$code); $code=preg_replace("/<b>(.+?)<\/b>/is","[b]\\1[/b]",$code); $code=preg_replace("/<i>(.+?)<\/i>/is","[i]\\1[/i]",$code); $code=preg_replace("/<u>(.+?)<\/u>/is","[u]\\1[/u]",$code); $code=preg_replace("/<s>(.+?)<\/s>/is","[s]\\1[/s]",$code); $code=preg_replace("/<h(\d)>(.+?)<\/h(\d)>/is","[h\\1]\\2[/h\\3]",$code); $code=preg_replace("/<center>(.+?)<\/center>/is","[center]\\1[/center]",$code); $code=preg_replace("/<right>(.+?)<\/right>/is","[right]\\1[/right]",$code); $code=preg_replace("/<font face=\"(.*?)\">(.*?)<\/font>/is","[font=\\1]\\2[/font]",$code); $code=preg_replace("/<font color=\"(.*?)\">(.*?)<\/font>/is","[color=\\1]\\2[/color]",$code); $code=preg_replace("/<font size=\"(.*?)\">(.*?)<\/font>/is","[size=\\1]\\2[/size]",$code); $code=preg_replace("/<marquee>(.+?)<\/marquee>/is","[move]\\1[/move]",$code); $code=preg_replace("/<marquee behavior=alternate>(.+?)<\/marquee>/is","[fly]\\1[/fly]",$code); $code=preg_replace("/<table width=(\d+) style=\"filter:shadow\(color=(\w+),direction=(\d+)\)\">(.+?)<\/table>/is","[shadow=\\1,\\2,\\3]\\4[/shadow]",$code); $code=preg_replace("/<table width=(\d+) style=\"filter:glow\(color=(\w+),direction=(\d+)\)\">(.+?)<\/table>/is","[glow=\\1,\\2,\\3]\\4[/glow]",$code); $code=preg_replace("/<table width=(\d+) style=\"filter:blur\(color=(\w+),direction=(\d+)\)\">(.+?)<\/table>/is","[blur=\\1,\\2,\\3]\\4[/blur]",$code); $code=preg_replace("/<table style=\"filter:flipH\">(.+?)<\/table>/is","[flipH]\\1[/flipH]",$code); $code=preg_replace("/<table style=\"filter:flipV\">(.+?)<\/table>/is","[flipV]\\1[/flipV]",$code); $code=preg_replace("/<table style=\"filter:invert\">(.+?)<\/table>/is","[invert]\\1[/invert]",$code); $code=preg_replace("/<table style=\"filter:xray\">(.+?)<\/table>/is","[xray]\\1[/xray]",$code); $code=preg_replace("/<blockquote style=margin:0><font size=1>.*?<\/font><hr size=1 noshade><pre>(.+?)<\/pre><hr size=1 noshade><\/blockquote>/is","[code]\\1[/code]",$code); $code=preg_replace("/<table border=1 cellspacing=0 width=98% bordercolorlight=000000 bordercolordark=FFFFFF><tr><td>(.+?)<\/td><\/tr><\/table>/is","[quote]\\1\[/quote]",$code); $code=preg_replace("/<ul type=square>(.+?)<\/ul>/is","[list]\\1[/list]",$code); $code=preg_replace("/<ol type=(A|1)>(.+?)<\/ol>/is","[list=\\1]\\2[/list=\\1]",$code); $code=preg_replace("/<li>(.+?)<\/li>/is","[*]\\1[/*]",$code); $code=preg_replace("/<table(.*?)>(.+?)<\/table>/is","[table\\1]\\2[/table]",$code); $code=preg_replace("/<tr(.*?)>(.+?)<\/tr>/is","[tr\\1]\\2[/tr]",$code); $code=preg_replace("/<td(.*?)>(.*?)<\/td>/is","[td\\1]\\2[/td]",$code); $code=preg_replace("/\"((\d{6})\d{10}\/\d\.(jpg|gif|png))\"/is","\"$url/\\2/\\1\"",$code); $code=preg_replace("/<a href=\"(http|https|ftp)(:\/\/\S+\.\S+\.\S+)\.(jpg|gif|png)\".*?>(.+?)<\/a>/is","\\4",$code); $code=preg_replace("/<a href=\"(http|https|ftp)(:\/\/\S+\.\S+\.\S+)\".*?>\\1\\2<\/a>/is","[url]\\1\\2[/url]",$code); $code=preg_replace("/<a href=\"(http|https|ftp)(:\/\/\S+\.\S+\.\S+)\".*?>(.+?)<\/a>/is","[url=\\1\\2]\\3[/url]",$code); $code=preg_replace("/<a href=\"?mailto:([_\.0-9a-z-]+@[0-9a-z][0-9a-z-]+\.+[a-z]{2,3})\"?>[_\.0-9a-z-]+@[0-9a-z][0-9a-z-]+\.+[a-z]{2,3}<\/a>/is","[email]\\1[/email]",$code); $code=preg_replace("/<a href=\"?mailto:([_\.0-9a-z-]+@[0-9a-z][0-9a-z-]+\.+[a-z]{2,3})\"?>(.+?)<\/a>/is","[email=\\1]\\2[/email]",$code); $code=preg_replace("/<img src=\"?(http|https)(:\/\/\S+?\.(jpg|gif|png))\"?.*?>/is","[img]\\1\\2[/img]",$code); $code=preg_replace("/<embed src=\"?(http|https|ftp)(:\/\/\S+?\.(wav|mid|ram|ra))\"? autoplay=\d+ width=\d+ height=\d+>/is","[music]\\1\\2[/music]",$code); $code=preg_replace("/<object width=\d+ height=\d+>\s*<param name=movie value=\"?http:\/\/\S+?\.swf\"?>\s*<param name=quality value=high>\s*<embed src=\"?(http:\/\/\S+?\.swf)\"? quality=high width=\d+ height=\d+><\/embed>\s*<\/object>/is","[flash]\\1[/flash]",$code); return $code; }
modifier.ubbcode.php
function smarty_modifier_ubbcode($code){ $code=preg_replace("/\[br\]/is","<br>",$code); $code=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$code); $code=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$code); $code=preg_replace("/\[u\](.+?)\[\/u\]/is","<u>\\1</u>",$code); $code=preg_replace("/\[s\](.+?)\[\/s\]/is","<s>\\1</s>",$code); $code=preg_replace("/\[h(\d)\](.+?)\[\/h(\d)\]/is","<h\\1>\\2</h\\3>",$code); $code=preg_replace("/\[left\](.+?)\[\/left\]/is","<left>\\1</left>",$code); $code=preg_replace("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$code); $code=preg_replace("/\[right\](.+?)\[\/right\]/is","<right>\\1</right>",$code); $code=preg_replace("/\[font=\s*(.*?)\s*\]\s*(.*?)\s*\[\/font\]/is","<font face=\"\\1\">\\2</font>",$code); $code=preg_replace("/\[color=(\S+?)\]\s*(.*?)\s*\[\/color\]/is","<font color=\"\\1\">\\2</font>",$code); $code=preg_replace("/\[size=\s*(.*?)\s*\]\s*(.*?)\s*\[\/size\]/is","<font size=\"\\1\">\\2</font>",$code); $code=preg_replace("/\[move\](.+?)\[\/move\]/is","<marquee>\\1</marquee>",$code); $code=preg_replace("/\[fly\](.+?)\[\/fly\]/is","<marquee behavior=alternate>\\1</marquee>",$code); $code=preg_replace("/\[shadow=(\d{1,3})\d*\,(\w+)\,(\d+)\](.+?)\[\/shadow\]/is","<table width=\\1 style=\"filter:shadow(color=\\2,direction=\\3)\">\\4</table>",$code); $code=preg_replace("/\[glow=(\d{1,3})\d*\,(\w+)\,(\d+)\](.+?)\[\/glow\]/is","<table width=\\1 style=\"filter:glow(color=\\2,direction=\\3)\">\\4</table>",$code); $code=preg_replace("/\[blur=(\d{1,3})\d*\,(\w+)\,(\d+)\](.+?)\[\/blur\]/is","<table width=\\1 style=\"filter:blur(color=\\2,direction=\\3)\">\\4</table>",$code); $code=preg_replace("/\[flipH\](.+?)\[\/flipH\]/is","<table style=\"filter:flipH\">\\1</table>",$code); $code=preg_replace("/\[flipV\](.+?)\[\/flipV\]/is","<table style=\"filter:flipV\">\\1</table>",$code); $code=preg_replace("/\[invert\](.+?)\[\/invert\]/is","<table style=\"filter:invert\">\\1</table>",$code); $code=preg_replace("/\[xray\](.+?)\[\/xray\]/is","<table style=\"filter:xray\">\\1</table>",$code); $code=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote style=margin:0><font size=1>以下内容为程序代码:</font><hr size=1 noshade><pre>\\1</pre><hr size=1 noshade></blockquote>",$code); $code=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<table border=1 cellspacing=0 width=98% bordercolorlight=000000 bordercolordark=FFFFFF><tr><td>\\1</td></tr></table>",$code); $code=preg_replace("/\[list\](.+?)\[\/list\]/is","<ul type=square>\\1</ul>",$code); $code=preg_replace("/\[list=(A|1)\](.+?)\[\/list=[A|1]\]/is","<ol type=\\1>\\2</ol>",$code); $code=preg_replace("/\[\*\](.+?)\[\/\*\]/is","<li>\\1</li>",$code); $code=preg_replace("/\[table(.*?)\](.+?)\[\/table\]/is","<table\\1>\\2</table>",$code); $code=preg_replace("/\[tr(.*?)\](.+?)\[\/tr\]/is","<tr\\1>\\2</tr>",$code); $code=preg_replace("/\[td(.*?)\](.*?)\[\/td\]/is","<td\\1>\\2</td>",$code); $code=preg_replace("/\[url\]\s*(http|https|ftp)(:\/\/\S+?)\s*\[\/url\]/is","<a href=\"\\1\\2\" target=_blank>\\1\\2</a>",$code); $code=preg_replace("/\[url=(http|https|ftp)(:\/\/\S+?)\](.+?)\[\/url\]/is","<a href=\"\\1\\2\" target=_blank>\\3</a>",$code); $code=preg_replace("/\[url=\\\\\"?(http|https|ftp)(:\/\/\S+?)\\\\\"?\](.+?)\[\/url\]/is","<a href=\"\\1\\2\" target=_blank>\\3</a>",$code); $code=preg_replace("/\[email\]\s*([_\.0-9a-z-]+@[0-9a-z][0-9a-z-]+\.+[a-z]{2,3})\s*\[\/email\]/is","<a href=\"mailto:\\1\">\\1</a>",$code); $code=preg_replace("/\[email=([_\.0-9a-z-]+@[0-9a-z][0-9a-z-]+\.+[a-z]{2,3})\](.+?)\[\/email\]/is","<a href=\"mailto:\\1\">\\2</a>",$code); #$code=preg_replace("/\[img\](http|https)(:\/\/\S+\.\S+\.\S+\/\S+\.(jpg|gif|png))\[\/img\]/is","<br><a href=\"\\1\\2\" target=\"_blank\"><img src=\"\\1\\2\" border=\"0\" onload=\"javascript:if(this.width>screen.width-400)this.width=screen.width-400\"></a><br>",$code); if(preg_match("/add_pre\.php/is",$_SERVER["SCRIPT_NAME"])){ $code=preg_replace("/\[img\](http|https)((:\/\/\S+?)\.(jpg|gif|png))\[\/img\]/is","<a href=\"\\1\\2\" target=\"_blank\"><img src=\"\\1\\2\" border=\"0\" onload=\"javascript:if(this.width>document.body.offsetWidth-180)this.width=document.body.offsetWidth-180\" alt=\"按此在新窗口浏览图片\"></a>",$code); } else { preg_match_all("/\[img\](http|https)((:\/\/\S+?)\.(jpg|gif|png))\[\/img\]/is",$code,$matches); for($i=0;$i<count($matches[0]);$i++){ preg_match("/(http|https)((:\/\/\S+?)\.(jpg|gif|png))/is",$matches[0][$i],$replace); $src=@fopen($replace[0],"r"); $dst=@fopen("cache","w+"); while($tmp=@fread($src,8192)){ @fwrite($dst,$tmp); } @fclose($dst); @fclose($src); $size=@GetImageSize("cache"); if($size){ if($size[0]>480){ $size[1]=intval(480/$size[0]*$size[1]); $size[0]=480; $matches[1][$i]="<a href=\"$replace[0]\" target=\"_blank\"><img src=\"$replace[0]\" border=\"0\" width=\"$size[0]\" height=\"$size[1]\" alt=\"按此在新窗口浏览图片\"></a>"; } else{ $matches[1][$i]="<img src=\"$replace[0]\" border=\"0\" width=\"$size[0]\" height=\"$size[1]\">"; } } else{ $matches[1][$i]=""; } $matches[0][$i]="/".@preg_replace("/\//is","\/",@QuoteMeta($matches[0][$i]))."/is"; @usleep(1); } $code=preg_replace($matches[0],$matches[1],$code); } $code=preg_replace("/\[music\](http|https|ftp)((:\/\/\S+?)\.(wav|mid|ram|ra))\[\/music\]/is","<embed src=\"\\1\\2\" autoplay=0 width=120 height=40>",$code); if(preg_match("/preview\.php/is",$_SERVER["SCRIPT_NAME"])){ $code=preg_replace("/\[flash\]\s*(http(:\/\/\S+?)\.swf)\s*\[\/flash\]/is","<object width=320 height=240>\n<param name=movie value=\"\\1\">\n<param name=quality value=high>\n<embed src=\"\\1\" quality=high width=320 height=240></embed>\n</object>",$code); } else { $code=preg_replace("/\[flash\]\s*(http(:\/\/\S+?)\.swf)\s*\[\/flash\]/is","<object width=320 height=240>\n<param name=movie value=\"\\1\">\n<param name=quality value=high>\n<embed src=\"\\1\" quality=high width=480 height=360></embed>\n</object>",$code); } return $code; } modifier.trim_char.php
function smarty_modifier_trim_char($string, $length) { if(strlen($string) > $length){ $string=substr($string,0,$length); preg_match_all("/[".chr(0xa1)."-".chr(0xff)."]/s",$string,$matchs); if(count($matchs[0])%2){ $string=substr($string,0,$length-1); } $string="$string"; } return $string; } function.print_page.php
function smarty_function_print_page($params, $smarty) { extract($params); $groupsize=10; ob_start(); ?> <table cellspacing=0 cellpadding=0 border=0 width=100%> <form method=post> <tr> <td align=right noWrap> 总第[<?echo "$pagesum/$page"?>]页 分页: <? $groupsum=intval($pagesum/$groupsize); for($i=1;$i<=$groupsum;$i++){ if($page>($i-1)*$groupsize&&$page<=$i*$groupsize){ break; } } echo "<a href=\"?$escape","size=$size&page=1\" title=\"首页\">",($page==1)?"<font face=\"webdings\" color=\"red\">9</font>":"<font face=\"webdings\">9</font>","</a>\n"; if($i>1){ echo "<a href=\"?$escape","size=$size&page=",($i-2)*$groupsize+1,"\" title=\"上十页\"><font face=\"webdings\">7</font></a>\n"; } for($j=($i-1)*$groupsize+1;$j<=$i*$groupsize&&$j<=$pagesum;$j++){ echo "<a href=\"?$escape","size=$size&page=$j\"><b>",($j==$page)?"<font color=\"red\">$j</font>":$j,"</b></a>\n"; } if($i<$groupsum){ echo "<a href=\"?$escape","size=$size&page=",$i*$groupsize+1,"\" title=\"下十页\"><font face=\"webdings\">8</font></a>\n"; } echo "<a href=\"?$escape","size=$size&page=$pagesum\" title=\"尾页\">",($page==$pagesum)?"<font face=\"webdings\" color=\"red\">:</font>":"<font face=\"webdings\">:</font>","</a>\n"; ?> 转到: <input type=text name="page" size="2" value="<?echo $page?>" maxlength=4 style="font-size:12px;height:16px" onFocus="this.select()"> <input type="submit" value="跳 转" style="background:cccccc;border-width:1px;font-size:12px;height:16px;cursor:hand"> <? $array=split("&",urldecode($escape)); for($i=0;$i<count($array);$i++){ list($name,$value)=split("=",$array[$i]); if($value!=""){ echo "<input type=hidden name=\"$name\" value=\"$value\">\n"; } } echo "<input type=hidden name=size value=\"$size\">\n"; ?> </td> </tr> </form> </table> <? $content = ob_get_contents(); ob_end_clean(); return $content; }
DSDasdSD
Feedback
# re: 工作需要,写了几个Smarty插件.[未登录] 回复 更多评论
2008-10-24 17:29 by
ob_get_contents();
Thank you very much.
|