summary refs log tree commit diff stats
path: root/includes/bbcode.php
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2008-12-10 16:27:32 -0500
committerStarla Insigna <hatkirby@fourisland.com>2008-12-10 16:27:32 -0500
commite7aa66fe5edf8dea9bf47c48efc197535c570962 (patch)
treec1d0c8aa809386c6d7c1fb7f5fbf641b37536c60 /includes/bbcode.php
parent2f85b606ccf161bb73370e85aead40318e9e216f (diff)
downloadfourisland-e7aa66fe5edf8dea9bf47c48efc197535c570962.tar.gz
fourisland-e7aa66fe5edf8dea9bf47c48efc197535c570962.tar.bz2
fourisland-e7aa66fe5edf8dea9bf47c48efc197535c570962.zip
Created own bbcode system
To be able to test for Internet Explorer troubles, the dependency on the bbcode PECL module had to be dropped, and so it has been. Hopefully this
BBCode module works.
Diffstat (limited to 'includes/bbcode.php')
-rwxr-xr-xincludes/bbcode.php193
1 files changed, 75 insertions, 118 deletions
diff --git a/includes/bbcode.php b/includes/bbcode.php index 4a1870a..e4b3d7f 100755 --- a/includes/bbcode.php +++ b/includes/bbcode.php
@@ -22,130 +22,87 @@ if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);}
22 22
23require('headerproc.php'); 23require('headerproc.php');
24 24
25$bbcode = bbcode_create(array('' => array('type' => BBCODE_TYPE_ROOT))); 25class BBCode
26
27// [b][/b] - Bold
28bbcode_add_element($bbcode,'b',array( 'type' => BBCODE_TYPE_NOARG,
29 'open_tag' => '<B>',
30 'close_tag' => '</B>'));
31
32// [i][/i] - Italic
33bbcode_add_element($bbcode,'i',array( 'type' => BBCODE_TYPE_NOARG,
34 'open_tag' => '<I>',
35 'close_tag' => '</I>'));
36
37// [url][/url] - [url=][/url] - Link
38bbcode_add_element($bbcode,'url',array( 'type' => BBCODE_TYPE_OPTARG,
39 'open_tag' => '<a href="{PARAM}">',
40 'close_tag' => '</a>',
41 'default_arg' => '{CONTENT}'));
42
43// [img][/img] - [img=][/img] - Image
44bbcode_add_element($bbcode,'img',array( 'type' => BBCODE_TYPE_OPTARG,
45 'open_tag' => '<IMG SRC="',
46 'close_tag' => '" ALT="{PARAM}" ALIGN="RIGHT"></IMG>',
47 'default_tag' => '{CONTENT}'));
48
49// [big][/big] - Big
50bbcode_add_element($bbcode,'big',array( 'type' => BBCODE_TYPE_NOARG,
51 'open_tag' => '<BIG>',
52 'close_tag' => '</BIG>'));
53
54// [small][/small] - Small
55bbcode_add_element($bbcode,'small',array( 'type' => BBCODE_TYPE_NOARG,
56 'open_tag' => '<SMALL>',
57 'close_tag' => '</SMALL>'));
58
59// [ul][/ul] - Unordered List
60bbcode_add_element($bbcode,'ul',array( 'type' => BBCODE_TYPE_NOARG,
61 'open_tag' => '<UL>',
62 'close_tag' => '</UL>',
63 'childs' => 'li'));
64
65// [ol][/ol] - Ordered List
66bbcode_add_element($bbcode,'ol',array( 'type' => BBCODE_TYPE_NOARG,
67 'open_tag' => '<OL>',
68 'close_tag' => '</OL>',
69 'childs' => 'li'));
70
71// [li][/li] - List Item
72bbcode_add_element($bbcode,'li',array( 'type' => BBCODE_TYPE_NOARG,
73 'open_tag' => '<LI>',
74 'close_tag' => '</LI>'));
75
76// [code][/code] - Code
77bbcode_add_element($bbcode,'code',array( 'type' => BBCODE_TYPE_NOARG,
78 'open_tag' => '<CODE>',
79 'close_tag' => '</CODE>'));
80
81// [pre][/pre] - Preformatted Code
82bbcode_add_element($bbcode,'pre',array( 'type' => BBCODE_TYPE_NOARG,
83 'open_tag' => '<P><DIV CLASS="autosize"><DIV CLASS="bubble"><DIV CLASS="bquote"><BLOCKQUOTE><DIV><PRE>',
84 'close_tag' => '</PRE></DIV></BLOCKQUOTE></DIV></DIV></DIV><DIV CLASS="cleardiv"></DIV>'));
85
86function bb_fixCode($string)
87{ 26{
88 $he = htmlentities($string); 27 var $init = false;
89 $br = nl2br($he); 28 var $bbcodes;
90 $sp = str_replace(' ','&nbsp;$nbsp;',$br); 29 var $bbcodes2;
91 $ta = str_replace(' ','&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',$sp); 30
92 return($ta); 31 function init()
32 {
33 $this->bbcodes['b'] = '<B>{CONTENT}</B>';
34 $this->bbcodes['i'] = '<I>{CONTENT}</I>';
35 $this->bbcodes['url'] = '<A HREF="{CONTENT}">{CONTENT}</A>';
36 $this->bbcodes2['url'] = '<A HREF="{PARAM}">{CONTENT}</A>';
37 $this->bbcodes['img'] = '<IMG SRC="{CONTENT}" />';
38 $this->bbcodes2['img'] = '<IMG SRC="{CONTENT}" ALT="{PARAM}" TITLE="{PARAM}" ALIGN="right" />';
39 $this->bbcodes['big'] = '<BIG>{CONTENT}</BIG>';
40 $this->bbcodes['small'] = '<SMALL>{CONTENT}</SMALL>';
41 $this->bbcodes['ul'] = '<UL>{CONTENT}</UL>';
42 $this->bbcodes['ol'] = '<OL>{CONTENT}</OL>';
43 $this->bbcodes['li'] = '<LI>{CONTENT}</LI>';
44 $this->bbcodes['code'] = '<CODE>{CONTENT}</CODE>';
45 $this->bbcodes['pre'] = '<P><DIV CLASS="autosize"><DIV CLASS="bubble"><DIV CLASS="bquote"><BLOCKQUOTE><DIV><PRE>{CONTENT}</PRE></DIV></BLOCKQUOTE></DIV></DIV></DIV><DIV CLASS="cleardiv"></DIV>';
46 $this->bbcodes2['blog'] = '<A HREF="/blog/{PARAM}/">{CONTENT}</A>';
47 $this->bbcodes['ins'] = '<INS>{CONTENT}</INS>';
48 $this->bbcodes['del'] = '<DEL>{CONTENT}</DEL>';
49 $this->bbcodes['bquote'] = '<P><DIV CLASS="autosize"><DIV CLASS="bubble"><DIV CLASS="bquote"><BLOCKQUOTE><DIV><NOBR>{CONTENT}</NOBR></DIV></BLOCKQUOTE></DIV><CITE><STRONG>Anonymous</STRONG></CITE></DIV></DIV><DIV CLASS="cleardiv"></DIV>';
50 $this->bbcodes2['bquote'] = '<P><DIV CLASS="autosize"><DIV CLASS="bubble"><DIV CLASS="bquote"><BLOCKQUOTE><DIV><NOBR>{CONTENT}</NOBR></DIV></BLOCKQUOTE></DIV><CITE><STRONG>{PARAM}</STRONG></CITE></DIV></DIV><DIV CLASS="cleardiv"></DIV>';
51 $this->bbcodes2['abbr'] = '<ABBR TITLE="{PARAM}">{CONTENT}</ABBR>';
52 $this->bbcodes['hidden'] = '<DIV STYLE="display: none">{CONTENT}</DIV>';
53
54 $this->init = true;
55 }
56
57 function parseBBCode($text)
58 {
59 if (!$this->init)
60 {
61 $this->init();
62 }
63
64 $to_parse = str_replace("\n",'[br]',htmlentities($text));
65
66 foreach ($this->bbcodes as $name => $value)
67 {
68 while (strpos($to_parse, '[' . $name . ']') !== FALSE)
69 {
70 $bbcode_uid = unique_id();
71 $to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[' . $name . ']'), strlen($name) + 2);
72 $to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[/' . $name . ']'), strlen($name) + 3);
73
74 $value = str_replace('{CONTENT}', '\1', $value);
75 $to_parse = preg_replace('/\[' . $name . ':' . $bbcode_uid . '\](.*)\[\/' . $name . ':' . $bbcode_uid . '\]/', $value, $to_parse);
76 }
77 }
78
79 foreach ($this->bbcodes2 as $name => $value)
80 {
81 while (strpos($to_parse, '[' . $name . '=') !== FALSE)
82 {
83 $bbcode_uid = unique_id();
84 $to_parse = substr_replace($to_parse, '[' . $name . ':' . $bbcode_uid . '=', strpos($to_parse, '[' . $name . '='), strlen($name) + 2);
85 $to_parse = substr_replace($to_parse, '[/' . $name . ':' . $bbcode_uid . ']', strpos($to_parse, '[/' . $name . ']'), strlen($name) + 3);
86
87 $value = str_replace('{PARAM}', '\1', $value);
88 $value = str_replace('{CONTENT}', '\2', $value);
89 $to_parse = preg_replace('/\[' . $name . ':' . $bbcode_uid . '=([^\]]*)\](.*)\[\/' . $name . ':' . $bbcode_uid . '\]/', $value, $to_parse);
90 }
91 }
92
93 return str_replace('[br]','<BR />',$to_parse);
94 }
93} 95}
94 96
95// [blog][/blog] - Blog Link
96bbcode_add_element($bbcode,'blog',array( 'type' => BBCODE_TYPE_OPTARG,
97 'open_tag' => (isset($oldBlog) ? '<A HREF="/archives/{CONTENT}.php">' : '<A HREF="/blog/{PARAM}/">'),
98 'close_tag' => '</A>',
99 'default_arg' => '{CONTENT}'));
100
101// [quote][/quote] - Quotes DB Link
102bbcode_add_element($bbcode,'quote',array( 'type' => BBCODE_TYPE_NOARG,
103 'open_tag' => (isset($oldBlog) ? '<A HREF="http://quotes.fourisland.com/?{CONTENT}">#' : '<A HREF="/quotes/{CONTENT}.php">#'),
104 'close_tag' => '</A>'));
105
106// [ins][/ins] - Insert
107bbcode_add_element($bbcode,'ins',array( 'type' => BBCODE_TYPE_NOARG,
108 'open_tag' => '<INS>',
109 'close_tag' => '</INS>'));
110
111// [del][/del] - Delete
112bbcode_add_element($bbcode,'del',array( 'type' => BBCODE_TYPE_NOARG,
113 'open_tag' => '<DEL>',
114 'close_tag' => '</DEL>'));
115
116// [bquote][/bquote] - Blockquote
117bbcode_add_element($bbcode,'bquote',array( 'type' => BBCODE_TYPE_OPTARG,
118 'open_tag' => '<P><DIV CLASS="autosize"><DIV CLASS="bubble"><DIV CLASS="bquote"><BLOCKQUOTE><DIV><NOBR>',
119 'close_tag' => '</NOBR></DIV></BLOCKQUOTE></DIV><CITE><STRONG>{PARAM}</STRONG></CITE></DIV></DIV><DIV CLASS="cleardiv"></DIV>',
120 'default_arg' => 'Anonymous'));
121
122// [project][/project] - Project Link
123bbcode_add_element($bbcode,'project',array( 'type' => BBCODE_TYPE_NOARG,
124 'open_tag' => (isset($oldBlog) ? '<A HREF="http://projects.fourisland.com/{CONTENT}/">' : '<A HREF="/projects/{CONTENT}/">'),
125 'close_tag' => '</A>'));
126
127// [abbr][/abbr] - Abbreviation
128bbcode_add_element($bbcode,'abbr',array( 'type' => BBCODE_TYPE_OPTARG,
129 'open_tag' => '<ABBR TITLE="{PARAM}">',
130 'close_tag' => '</ABBR>',
131 'default_arg' => ''));
132
133// [br] - Line Break
134bbcode_add_element($bbcode,'br',array( 'type' => BBCODE_TYPE_SINGLE,
135 'open_tag' => '<BR>'));
136
137// [hidden][/hidden] - Hidden Text
138bbcode_add_element($bbcode,'hidden',array( 'type' => BBCODE_TYPE_OPTARG,
139 'open_tag' => '<DIV STYLE="display: none">',
140 'close_tag' => '</DIV>',
141 'default_arg' => ''));
142
143function parseBBCode($text) 97function parseBBCode($text)
144{ 98{
145 global $bbcode; 99 global $bbcode;
146 $to_parse = str_replace("\n",'[br]',htmlentities($text)); 100 if (!isset($bbcode))
147 $to_parse = bbcode_parse($bbcode,$to_parse); 101 {
148 return str_replace('[br]','',$to_parse); 102 $bbcode = new BBCode();
103 }
104
105 return $bbcode->parseBBCode($text);
149} 106}
150 107
151?> 108?>