| [ PHPXref.com ] | [ Generated: Sun Jul 20 16:35:25 2008 ] | [ bBlog 0.7.6 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 // modifier.bbcode.php - bBlog text formating plugin, 3 // modifier.bbcode.php - Converts BBCode style tags to HTML 4 // modifier.bbcode.php - and makes URLs clickable 5 6 function identify_modifier_bbcode () { 7 $help = bblog_modifier_bbcode_help(); 8 return array ( 9 'name' =>'bbcode', 10 'type' =>'modifier', 11 'nicename' =>'BBCode', 12 'description' =>'Converts BBCode style tags to HTML and makes URLs clickable', 13 'authors' =>'André Rabold, Nathan Codding, The PHPBB group', 14 'licence' =>'GPL', 15 'help' => $help 16 ); 17 } 18 19 function bblog_modifier_bbcode_help () { 20 // help copied from phpbb (C) the PHPBB GROUP and released under the GPL 21 ob_start(); 22 ?> 23 <h4>Introduction</h4> 24 <a href="#0">What is BBCode?</a><br /> 25 <br /> 26 <h4>Text Formatting</h4> 27 <a href="#1">How to create bold, italic and underlined text</a><br /> 28 <a href="#2">How to change the text colour or size</a><br /> 29 <a href="#3">Can I combine formatting tags?</a><br /> 30 <h4>Outputting fixed-width text</h4> 31 <a href="#5">Outputting code or fixed width data</a><br /> 32 <h4>Generating lists</h4> 33 <a href="#6">Creating an Un-ordered list</a><br /> 34 <a href="#7">Creating an Ordered list</a><br /> 35 <h4>Creating Links</h4> 36 <a href="#8">Linking to another site</a><br /> 37 <h4>Showing images in posts</h4> 38 <a href="#9">Adding an image to a post</a><br /> 39 <br /><br /> 40 41 <h4>Introduction</h4> 42 <p><a name="0"></a><b>What is BBCode?</b><br /> 43 BBCode is a special implementation of HTML. 44 You enable or disable BBCode on a per post basis via the posting form. 45 BBCode itself is similar in style to HTML, tags are enclosed in square braces [ and ] rather than < and > and it offers greater control 46 over what and how something is displayed. 47 48 <del>Depending on the template you are using you may find adding BBCode 49 to your posts is made much easier through a clickable interface above the message area on the posting form. </del> 50 51 Even with this you may find the following guide useful.<br /> 52 <a href="#Top">Back to top</a></p> 53 54 <h4>Text Formatting</h4> 55 <p><a name="1"></a><b>How to create bold, italic and underlined text</b><br /> 56 BBCode includes tags to allow you to quickly change the basic style of your text. 57 This is achieved in the following ways: <ul><li>To make a piece of text bold 58 enclose it in <b>[b][/b]</b>, eg. <br /><br /><b>[b]</b>Hello<b>[/b]</b><br /><br />will become 59 <b>Hello</b></li><li>For underlining use <b>[u][/u]</b>, for example:<br /><br /><b>[u]</b> 60 Good Morning<b>[/u]</b><br /><br />becomes <u>Good Morning</u></li><li> 61 To italicise text use <b>[i][/i]</b>, eg.<br /><br />This is <b>[i]</b>Great!<b>[/i]</b><br /><br /> 62 would give This is <i>Great!</i></li></ul><br /> 63 <a href="#Top">Back to top</a></p> 64 65 <p><a name="2"></a><b>How to change the text colour or size</b><br /> 66 To alter the color or size of your text the following tags can be used. 67 Keep in mind that how the output appears will depend on the viewers browser and system: 68 <ul><li>Changing the colour of text is achieved by wrapping it in 69 <b>[color=][/color]</b>. You can specify either a recognised colour name 70 (eg. red, blue, yellow, etc.) or the hexadecimal 71 triplet alternative, eg. #FFFFFF, #000000. For example, 72 to create red text you could use:<br /><br /><b>[color=red]</b>Hello!<b>[/color]</b><br /> 73 <br />or<br /><br /><b>[color=#FF0000]</b>Hello!<b>[/color]</b><br /> 74 <br />will both output <span style="color:red">Hello!</span></li> 75 <li>Changing the text size is achieved in a similar way using 76 <b>[size=][/size]</b>. This tag is dependent on the 77 template you are using but the recommended format is a 78 numerical value representing the text size in pixels, 79 starting at 1 (so tiny you will not see it) through to 29 80 (very large). For example:<br /><br /><b>[size=9]</b>SMALL<b>[/size]</b><br /> 81 <br />will generally be <span style="font-size:9px">SMALL</span><br /> 82 <br />whereas:<br /><br /><b>[size=24]</b>HUGE!<b>[/size]</b><br /> 83 <br />will be <span style="font-size:24px">HUGE!</span></li></ul><br /> 84 <a href="#Top" >Back to top</a></p> 85 86 <p><a name="3"></a><b>Can I combine formatting tags?</b><br /> 87 Yes, of course you can, for example to get someones attention you may write: 88 <br /><br /><b>[size=18][color=red][b]</b>LOOK AT ME!<b>[/b][/color][/size]</b> 89 <br /><br />this would output <span style="color:red;font-size:18px"> 90 <b>LOOK AT ME!</b></span><br /><br />We don't 91 recommend you output lots of text that looks like this though! 92 Remember it is up to you, the poster to ensure 93 tags are closed correctly. For example the following is 94 incorrect:<br /><br /><b>[b][u]</b>This is wrong<b>[/b][/u]</b><br /> 95 <a href="#Top" class="gensmall">Back to top</a></p> 96 97 <h4>Outputting fixed-width text</h4> 98 99 <p><a name="5"></a><b>Outputting code or fixed width data</b><br /> 100 If you want to output a piece of code or in fact anything that requires a 101 fixed width, eg. Courier type font you should enclose the text in 102 <b>[code][/code]</b> tags, eg.<br /> 103 <br /><b>[code]</b>echo "This is some code";<b>[/code]</b> 104 <br /><br />All formatting used within <b>[code][/code]</b> 105 tags is retained when you later view it.<br /> 106 <a href="#Top">Back to top</a></p> 107 108 109 <h4>Generating lists</h4> 110 <p><a name="6"></a><b>Creating an Un-ordered list</b><br /> 111 BBCode supports two types of lists, unordered and ordered. They are essentially the same as their HTML equivalents. An unordered list ouputs each item in your list sequentially one after the other indenting each with a bullet character. To create an unordered list you use <b>[list][/list]</b> and define each item within the list using <b>[*]</b>. For example to list your favorite colours you could use:<br /><br /><b>[list]</b><br /><b>[*]</b>Red<br /><b>[*]</b>Blue<br /><b>[*]</b>Yellow<br /><b>[/list]</b><br /><br />This would generate the following list:<ul><li>Red</li><li>Blue</li><li>Yellow</li></ul><br /> 112 <a href="#Top">Back to top</a></p> 113 114 <p><a name="7"></a><b>Creating an Ordered list</b><br /> 115 The second type of list, an ordered list gives you control over what is output before each item. To create an ordered list you use <b>[list=1][/list]</b> to create a numbered list or alternatively <b>[list=a][/list]</b> for an alphabetical list. As with the unordered list items are specified using <b>[*]</b>. For example:<br /><br /><b>[list=1]</b><br /><b>[*]</b>Go to the shops<br /><b>[*]</b>Buy a new computer<br /><b>[*]</b>Swear at computer when it crashes<br /><b>[/list]</b><br /><br />will generate the following:<ol type="1"><li>Go to the shops</li><li>Buy a new computer</li><li>Swear at computer when it crashes</li></ol>Whereas for an alphabetical list you would use:<br /><br /><b>[list=a]</b><br /><b>[*]</b>The first possible answer<br /><b>[*]</b>The second possible answer<br /><b>[*]</b>The third possible answer<br /><b>[/list]</b><br /><br />giving<ol type="a"><li>The first possible answer</li><li>The second possible answer</li><li>The third possible answer</li></ol><br /> 116 <a href="#Top">Back to top</a></p> 117 118 <h4>Creating Links</h4> 119 120 <p><a name="8"></a><b>Linking to another site</b> 121 BBCode supports a number of ways of creating URIs, Uniform Resource Indicators better known as URLs.<ul><li>The first of these uses the <b>[url=][/url]</b> tag, whatever you type after the = sign will cause the contents of that tag to act as a URL. For example to link to phpBB.com you could use:<br /><br /><b>[url=http://www.phpbb.com/]</b>Visit phpBB!<b>[/url]</b><br /><br />This would generate the following link, <a href="http://www.phpbb.com/" target="_blank">Visit phpBB!</a> You will notice the link opens in a new window so the user can continue browsing the forums if they wish.</li><li>If you want the URL itself displayed as the link you can do this by simply using:<br /><br /><b>[url]</b>http://www.phpbb.com/<b>[/url]</b><br /><br />This would generate the following link, <a href="http://www.phpbb.com/" target="_blank">http://www.phpbb.com/</a></li><li>Additionally phpBB features something called <i>Magic Links</i>, this will turn any syntatically correct URL into a link without you needing to specify any tags or even the leading http://. For example typing www.phpbb.com into your message will automatically lead to <a href="http://www.phpbb.com/" target="_blank">www.phpbb.com</a> being output when you view the message.</li><li>The same thing applies equally to email addresses, you can either specify an address explicitly for example:<br /><br /><b>[email]</b>no.one@domain.adr<b>[/email]</b><br /><br />which will output <a href="emailto:no.one@domain.adr">no.one@domain.adr</a> or you can just type no.one@domain.adr into your message and it will be automatically converted when you view.</li></ul>As with all the BBCode tags you can wrap URLs around any of the other tags such as <b>[img][/img]</b> (see next entry), <b>[b][/b]</b>, etc. As with the formatting tags it is up to you to ensure the correct open and close order is following, for example:<br /><br /><b>[url=http://www.phpbb.com/][img]</b>http://www.phpbb.com/images/phplogo.gif<b>[/url][/img]</b><br /><br />is <u>not</u> correct which may lead to your post being deleted so take care.<br /> 122 <a href="#Top">Back to top</a></p> 123 124 <h4>Showing images in posts</h4> 125 126 <p><a name="9"></a><b>Adding an image to a post</b><br /> 127 BBCode incorporates a tag for including images in your posts. 128 Two very important things to remember when using this tag are; 129 many users do not appreciate lots of images being shown in posts 130 and secondly the image you display must already be available 131 on the internet (it cannot exist only on your computer for example, 132 unless you run a webserver!). There is currently no way of storing 133 images locally with phpBB (all these issues are expected to 134 be addressed in the next release of phpBB). 135 To display an image you must surround the URL pointing to the 136 image with <b>[img][/img]</b> tags. For example:<br /><br /> 137 <b>[img]</b>http://www.phpbb.com/images/phplogo.gif<b>[/img]</b> 138 <br /><br />As noted in the URL section above you can wrap an image 139 in a <b>[url][/url]</b> tag if you wish, eg.<br /><br /> 140 <b>[url=http://www.phpbb.com/][img]</b>http://www.phpbb.com/images/phplogo.gif<b>[/img][/url]</b> 141 <br /><br />would generate:<br /> 142 <br /><a href="http://www.phpbb.com/" target="_blank"><img src="http://www.phpbb.com/images/phplogo.gif" border="0" alt="" /></a><br /><br /> 143 <a href="#Top" >Back to top</a></p> 144 145 <?php 146 $o = ob_get_contents(); 147 ob_end_clean(); 148 return $o; 149 } 150 151 152 /* 153 * Smarty plugin 154 * ------------------------------------------------------------ 155 * Type: modifier 156 * Name: bbcode2html 157 * Purpose: Converts BBCode style tags to HTML 158 * Author: André Rabold 159 * Version: 1.3c 160 * Remarks: Notice that this function does not check for 161 * correct syntax. Try not to use it with invalid 162 * BBCode because this could lead to unexpected 163 * results ;-) 164 * What's new: - Fixed a bug with <li>...</li> tags (thanks 165 * to Rob Schultz for pointing this out) 166 * 167 * Version 1.3b 168 * - Added more support for phpBB2: 169 * [list]...[/list:u] unordered lists 170 * [list]...[/list:o] ordered lists 171 * 172 * Version 1.3 173 * - added support for phpBB2 like tag identifier 174 * like [b:b6a0cef7ea]This is bold[/b:b6a0cef7ea] 175 * (thanks to Rob Schultz) 176 * - added support for quotes within the quote tag 177 * so [quote="foo"]bar[/quote] does work now 178 * correctly 179 * - removed str_replace functions 180 * 181 * Version 1.2 182 * - now supports CSS classes: 183 * ng_email (mailto links) 184 * ng_url (www links) 185 * ng_quote (quotes) 186 * ng_quote_body (quotes) 187 * ng_code (source code) 188 * ng_list (html lists) 189 * ng_list_item (list items) 190 * - replaced slow ereg_replace() functions 191 * - Alterned [quote] and [code] to use CSS classes 192 * instead of HTML <blockquote />, <hr />, ... tags. 193 * - Additional BBCode tags [list] and [*] to display 194 * nice HTML lists. Example: 195 * [list] 196 * [*]first item 197 * [*]second item 198 * [*]third item 199 * [/list] 200 * The [list] tag can have an additional parameter: 201 * [list] unorderer list with bullets 202 * [list=1] ordered list 1,2,3,4,... 203 * [list=i] ordered list i,ii,iii,iv,... 204 * [list=I] ordered list I,II,III,IV,... 205 * [list=a] ordered list a,b,c,d,... 206 * [list=A] ordered list A,B,C,D,... 207 * - produces well-formed output 208 * - cleaned up the code 209 * ------------------------------------------------------------ 210 */ 211 function smarty_modifier_bbcode($message) { 212 $preg = array( 213 // Font and text manipulation ( [color] [size] [font] [align] ) 214 '/\[color=(.*?)(?::\w+)?\](.*?)\[\/color(?::\w+)?\]/si' => "<span style=\"color:\\1\">\\2</span>", 215 '/\[size=(.*?)(?::\w+)?\](.*?)\[\/size(?::\w+)?\]/si' => "<span style=\"font-size:\\1\">\\2</span>", 216 '/\[font=(.*?)(?::\w+)?\](.*?)\[\/font(?::\w+)?\]/si' => "<span style=\"font-family:\\1\">\\2</span>", 217 '/\[align=(.*?)(?::\w+)?\](.*?)\[\/align(?::\w+)?\]/si' => "<div style=\"text-align:\\1\">\\2</div>", 218 '/\[b(?::\w+)?\](.*?)\[\/b(?::\w+)?\]/si' => "<b>\\1</b>", 219 '/\[i(?::\w+)?\](.*?)\[\/i(?::\w+)?\]/si' => "<i>\\1</i>", 220 '/\[u(?::\w+)?\](.*?)\[\/u(?::\w+)?\]/si' => "<u>\\1</u>", 221 '/\[center(?::\w+)?\](.*?)\[\/center(?::\w+)?\]/si' => "<div style=\"text-align:center\">\\1</div>", 222 '/\[code(?::\w+)?\](.*?)\[\/code(?::\w+)?\]/si' => "<div class=\"ng_code\">\\1</div>", 223 // [email] 224 '/\[email(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\" class=\"ng_email\">\\1</a>", 225 '/\[email=(.*?)(?::\w+)?\](.*?)\[\/email(?::\w+)?\]/si' => "<a href=\"mailto:\\1\" class=\"ng_email\">\\2</a>", 226 // [url] 227 '/\[url(?::\w+)?\]www\.(.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"http://www.\\1\" class=\"ng_url\">\\1</a>", 228 '/\[url(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"\\1\" class=\"ng_url\">\\1</a>", 229 '/\[url=(.*?)(?::\w+)?\](.*?)\[\/url(?::\w+)?\]/si' => "<a href=\"\\1\" class=\"ng_url\">\\2</a>", 230 // [img] 231 '/\[img(?::\w+)?\](.*?)\[\/img(?::\w+)?\]/si' => "<img src=\"\\1\" border=\"0\" />", 232 '/\[img=(.*?)x(.*?)(?::\w+)?\](.*?)\[\/img(?::\w+)?\]/si' => "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" border=\"0\" />", 233 // [quote] 234 '/\[quote(?::\w+)?\](.*?)\[\/quote(?::\w+)?\]/si' => "<div class=\"ng_quote\">Quote:<div class=\"ng_quote_body\">\\1</div></div>", 235 '/\[quote=(?:"|"|\')?(.*?)["\']?(?:"|"|\')?\](.*?)\[\/quote(?::\w+)?\]/si' => "<div class=\"ng_quote\">Quote \\1:<div class=\"ng_quote_body\">\\2</div></div>", 236 // [list] 237 '/\[\*(?::\w+)?\]\s*([^\[]*)/si' => "<li class=\"ng_list_item\">\\1</li>", 238 '/\[list(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/si' => "<ul class=\"ng_list\">\\1</ul>", 239 '/\[list(?::\w+)?\](.*?)\[\/list:u(?::\w+)?\]/s' => "<ul class=\"ng_list\">\\1</ul>", 240 '/\[list=1(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/si' => "<ol class=\"ng_list\" style=\"list-style-type:decimal;\">\\1</ol>", 241 '/\[list=i(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => "<ol class=\"ng_list\" style=\"list-style-type:lower-roman;\">\\1</ol>", 242 '/\[list=I(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => "<ol class=\"ng_list\" style=\"list-style-type:upper-roman;\">\\1</ol>", 243 '/\[list=a(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => "<ol class=\"ng_list\" style=\"list-style-type:lower-alpha;\">\\1</ol>", 244 '/\[list=A(?::\w+)?\](.*?)\[\/list(?::\w+)?\]/s' => "<ol class=\"ng_list\" style=\"list-style-type:upper-alpha;\">\\1</ol>", 245 '/\[list(?::\w+)?\](.*?)\[\/list:o(?::\w+)?\]/s' => "<ol class=\"ng_list\" style=\"list-style-type:decimal;\">\\1</ol>", 246 // the following lines clean up our output a bit 247 '/<ol(.*?)>(?:.*?)<li(.*?)>/si' => "<ol\\1><li\\2>", 248 '/<ul(.*?)>(?:.*?)<li(.*?)>/si' => "<ul\\1><li\\2>" 249 ); 250 $message = preg_replace(array_keys($preg), array_values($preg), $message); 251 252 // make clickable() : 253 /** 254 * Rewritten by Nathan Codding - Feb 6, 2001. 255 * - Goes through the given string, and replaces xxxx://yyyy with an HTML <a> tag linking 256 * to that URL 257 * - Goes through the given string, and replaces www.xxxx.yyyy[zzzz] with an HTML <a> tag linking 258 * to http://www.xxxx.yyyy[/zzzz] 259 * - Goes through the given string, and replaces xxxx@yyyy with an HTML mailto: tag linking 260 * to that email address 261 * - Only matches these 2 patterns either after a space, or at the beginning of a line 262 * 263 * Notes: the email one might get annoying - it's easy to make it more restrictive, though.. maybe 264 * have it require something like xxxx@yyyy.zzzz or such. We'll see. 265 */ 266 267 // pad it with a space so we can match things at the start of the 1st line. 268 $ret = ' ' . $message; 269 270 // matches an "xxxx://yyyy" URL at the start of a line, or after a space. 271 // xxxx can only be alpha characters. 272 // yyyy is anything up to the first space, newline, comma, double quote or < 273 $ret = preg_replace("#([\t\r\n ])([a-z0-9]+?){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="\2://\3">\2://\3</a>', $ret); 274 275 // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing 276 // Must contain at least 2 dots. xxxx contains either alphanum, or "-" 277 // zzzz is optional.. will contain everything up to the first space, newline, 278 // comma, double quote or <. 279 $ret = preg_replace("#([\t\r\n ])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)#i", '\1<a href="http://\2.\3">\2.\3</a>', $ret); 280 281 // matches an email@domain type address at the start of a line, or after a space. 282 // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".". 283 $ret = preg_replace("#([\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); 284 285 // Remove our padding.. 286 $ret = substr($ret, 1); 287 288 return (nl2br($ret)); 289 } 290 291 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |