summaryrefslogtreecommitdiffstats
path: root/code/bbcode.inc.php
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2006-04-11 20:38:04 +0200
committerneoraider <devnull@localhost>2006-04-11 20:38:04 +0200
commit70df8e380e9ffa0bbcb351b09c668fdc606bac28 (patch)
tree75365760a6188d1b4aa136d977431eb1aa0eb5ca /code/bbcode.inc.php
parentc754b687bb2ad5a36cbfdab7466516492b977781 (diff)
downloadbbcode-70df8e380e9ffa0bbcb351b09c668fdc606bac28.tar
bbcode-70df8e380e9ffa0bbcb351b09c668fdc606bac28.zip
Modul funktioniert jetzt.
Diffstat (limited to 'code/bbcode.inc.php')
-rw-r--r--code/bbcode.inc.php200
1 files changed, 199 insertions, 1 deletions
diff --git a/code/bbcode.inc.php b/code/bbcode.inc.php
index 0941f5c..5d213f4 100644
--- a/code/bbcode.inc.php
+++ b/code/bbcode.inc.php
@@ -1,5 +1,203 @@
<?PHP
class BBCode {
-
+ function Parse($input) {
+ $tags = '';
+ $tl = 0;
+ $tmpok = '';
+ $tmpnok = '';
+ $tmptag = '';
+ $tmpend = '';
+ $tmplist = '';
+ $lists = '';
+
+ $input = strtr($input, array('<' => '&lt;', '>' => '&gt;', '&' => '&amp;', '"' => '&quot;', "\n" => '<br />', "\r" => ''));
+ if($input[0] == '[') {
+ strtok(' ' . $input, '[');
+ $out = '';
+ }
+ else $out = strtok($input, '[');
+
+ while($part = strtok('[')) {
+ if($tmpok) {
+ if(substr($part, 0, strlen($tmpend)) == $tmpend) {
+ $out .= $tmpok . substr($part, strlen($tmpend));
+ $tags = $tmptag . $tags;
+ $lists = $tmplist . $lists;
+ $tl = strcspn($tags, ']');
+ $tmpok = '';
+ $tmpnok = '';
+ $tmptag = '';
+ $tmpend = '';
+ $tmplist = '';
+ continue;
+ }
+ else {
+ $out .= '[' . $tmpnok;
+ $tmpok = '';
+ $tmpnok = '';
+ $tmptag = '';
+ $tmpend = '';
+ $tmplist = '';
+ }
+ }
+
+ if(substr($part, 0, 2) == 'b]') {
+ $out .= '<span style="font-weight:bold">' . substr($part, 2);
+ $tags = '[/b]' . $tags;
+ }
+ elseif(substr($part, 0, 2) == 'i]') {
+ $out .= '<span style="font-style:italic">' . substr($part, 2);
+ $tags = '[/i]' . $tags;
+ }
+ elseif(substr($part, 0, 2) == 'u]') {
+ $out .= '<span style="text-decoration:underline">' . substr($part, 2);
+ $tags = '[/u]' . $tags;
+ }
+ elseif(substr($part, 0, 5) == 'size=') {
+ $size = intval(substr($part, 5));
+ if($size == 9 && $part[6] == ']') {
+ $out .= '<span style="font-size:9pt">' . substr($part, 7);
+ $tags = '[/size]' . $tags;
+ }
+ elseif(($size >= 10 && $size <= 24) && $part[7] == ']') {
+ $out .= '<span style="font-size:' . $size . 'pt">' . substr($part, 8);
+ $tags = '[/size]' . $tags;
+ }
+ else $out .= '[' . $part;
+ }
+ elseif(substr($part, 0, 6) == 'color=') {
+ $l = strspn(substr($part, 6), 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890#(),%');
+ if($part[$l+6] == ']') {
+ $out .= '<span style="color:' . substr($part, 6, $l) . '">' . substr($part, $l+7);
+ $tags = '[/color]' . $tags;
+ }
+ else $out .= '[' . $part;
+ }
+ elseif(substr($part, 0, 5) == 'code]') {
+ $out .= '<div class="bbcode_code"><span class="bbcode_code_caption">Code:</span><div class="bbode_code_text">' . substr($part, 5);
+ $tags = '[/code]' . $tags;
+ }
+ elseif(substr($part, 0, 4) == 'url]') {
+ $tmpok = '<a href="' . substr($part, 4) . '">' . substr($part, 4) . '</a>';
+ $tmpnok = $part;
+ $tmpend = '/url]';
+ }
+ elseif(substr($part, 0, 4) == 'url=') {
+ $l = strcspn(substr($part, 4), '[] ');
+ if($part[$l+4] == ']') {
+ $out .= '<a href="' . substr($part, 4, $l) . '">' . substr($part, $l+5);
+ $tags = '[/url]' . $tags;
+ }
+ else $out .= '[' . $part;
+ }
+ elseif(substr($part, 0, 6) == 'email]') {
+ $tmpok = '<a href="mailto:' . substr($part, 6) . '">' . substr($part, 6) . '</a>';
+ $tmpnok = $part;
+ $tmpend = '/email]';
+ }
+ elseif(substr($part, 0, 6) == 'email=') {
+ $l = strcspn(substr($part, 6), '[] ');
+ if($part[$l+6] == ']') {
+ $out .= '<a href="mailto:' . substr($part, 6, $l) . '">' . substr($part, $l+7);
+ $tags = '[/email]' . $tags;
+ }
+ else $out .= '[' . $part;
+ }
+ elseif(substr($part, 0, 4) == 'img]') {
+ $tmpok = '<img src="images/' . substr($part, 4) . '.jpg" alt="" />';
+ $tmpnok = $part;
+ $tmpend = '/img]';
+ }
+ elseif(substr($part, 0, 5) == 'list]') {
+ $tmpok = substr($part, 5) . '<ul><li>';
+ $tmpnok = $part;
+ $tmptag = '[/list]';
+ $tmpend = '*]';
+ $tmplist = 'u';
+ }
+ elseif(substr($part, 0, 7) == 'list=1]') {
+ $tmpok = substr($part, 7) . '<ol style="list-style-type:decimal"><li>';
+ $tmpnok = $part;
+ $tmptag = '[/list]';
+ $tmpend = '*]';
+ $tmplist = 'o';
+ }
+ elseif(substr($part, 0, 7) == 'list=a]') {
+ $tmpok = substr($part, 7) . '<ol style="list-style-type:lower-latin"><li>';
+ $tmpnok = $part;
+ $tmptag = '[/list]';
+ $tmpend = '*]';
+ $tmplist = 'o';
+ }
+ elseif(substr($part, 0, 2) == '*]') {
+ if(substr($tags, 0, 7) == '[/list]') $out .= '</li><li>' . substr($part, 2);
+ else $out .= '[' . $part;
+ }
+ elseif($tl && substr($part, 0, $tl) == substr($tags, 1, $tl)) {
+ $tags = substr($tags, $tl+1);
+
+ switch(substr($part, 1, $tl-2)) {
+ case 'b':
+ case 'i':
+ case 'u':
+ case 'size':
+ case 'color':
+ $out .= '</span>';
+ break;
+ case 'url':
+ case 'email':
+ $out .= '</a>';
+ break;
+ case 'code':
+ $out .= '</div></div>';
+ break;
+ case 'list':
+ $out .= '</li></' . $lists[0] . 'l>';
+ $lists = substr($lists, 1);
+ }
+
+ $out .= substr($part, $tl);
+ }
+ else $out .= '[' . $part;
+
+ $tl = strcspn($tags, ']');
+ }
+
+ if($tmpok) $out .= '[' . $tmpnok;
+
+ $part = strtok($tags, '[');
+
+ while($part) {
+ $tags = substr($tags, $tl+1);
+
+ switch(substr($part, 1, $tl-2)) {
+ case 'b':
+ case 'i':
+ case 'u':
+ case 'size':
+ case 'color':
+ $out .= '</span>';
+ break;
+ case 'url':
+ case 'email':
+ $out .= '</a>';
+ break;
+ case 'code':
+ $out .= '</blockcode></div>';
+ break;
+ case 'list':
+ $out .= '</li></' . $lists[0] . 'l>';
+ $lists = substr($lists, 1);
+ }
+
+ $tl = strcspn($tags, ']');
+
+ $part = strtok('[');
+ }
+
+ return $out;
+ }
}
+
+ $GLOBALS['bbcode'] = new BBCode;
?>