1 | <?php |
---|
2 | defined('BBCODE_ID') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | function bbcode_bar_admin_menu($menu) |
---|
5 | { |
---|
6 | $menu[] = array( |
---|
7 | 'NAME' => 'BBCode Bar', |
---|
8 | 'URL' => BBCODE_ADMIN, |
---|
9 | ); |
---|
10 | return $menu; |
---|
11 | } |
---|
12 | |
---|
13 | function add_bbcode_bar() |
---|
14 | { |
---|
15 | global $page, $pwg_loaded_plugins, $template, $conf; |
---|
16 | |
---|
17 | if (script_basename() == 'picture') |
---|
18 | { |
---|
19 | $prefilter = 'picture'; |
---|
20 | $textarea_id = 'contentid'; |
---|
21 | } |
---|
22 | else if (isset($page['section'])) |
---|
23 | { |
---|
24 | if ( |
---|
25 | script_basename() == 'index' and isset($pwg_loaded_plugins['Comments_on_Albums']) |
---|
26 | and $page['section'] == 'categories' and isset($page['category']) |
---|
27 | ) |
---|
28 | { |
---|
29 | $prefilter = 'comments_on_albums'; |
---|
30 | $textarea_id = 'contentid'; |
---|
31 | } |
---|
32 | else if ($page['section'] == 'guestbook') |
---|
33 | { |
---|
34 | $prefilter = 'guestbook'; |
---|
35 | $textarea_id = 'contentid'; |
---|
36 | } |
---|
37 | else if ($page['section'] == 'contact') |
---|
38 | { |
---|
39 | $prefilter = 'contactform'; |
---|
40 | $textarea_id = 'cf_content'; |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | if (!isset($prefilter)) |
---|
45 | { |
---|
46 | return; |
---|
47 | } |
---|
48 | |
---|
49 | $conf['bbcode_bar']['smilies'] = isset($pwg_loaded_plugins['SmiliesSupport']); |
---|
50 | |
---|
51 | // calculate separators between groups |
---|
52 | $groups = array( |
---|
53 | array('b','i','u','s'), |
---|
54 | array('p','center','right','quote'), |
---|
55 | array('ol','ul'), |
---|
56 | array('img','url','email'), |
---|
57 | array('size','color'), |
---|
58 | array('smilies'), |
---|
59 | ); |
---|
60 | |
---|
61 | $tpl_groups = array(); |
---|
62 | $count = 0; |
---|
63 | for ($i=0; $i<count($groups)-1; $i++) |
---|
64 | { |
---|
65 | $separator = false; |
---|
66 | foreach ($groups[$i] as $code) |
---|
67 | { |
---|
68 | if ($conf['bbcode_bar'][$code]) $count++; |
---|
69 | } |
---|
70 | if ($count>0) |
---|
71 | { |
---|
72 | foreach ($groups[$i+1] as $code) |
---|
73 | { |
---|
74 | if ($conf['bbcode_bar'][$code]) $separator = true; |
---|
75 | } |
---|
76 | } |
---|
77 | if ($separator) |
---|
78 | { |
---|
79 | $tpl_groups[$i] = true; |
---|
80 | $count = 0; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | $template->assign(array( |
---|
85 | 'BBCODE_PATH' => BBCODE_PATH, |
---|
86 | 'BBCODE' => array( |
---|
87 | 'codes' => $conf['bbcode_bar'], |
---|
88 | 'separators' => $tpl_groups, |
---|
89 | 'textarea_id' => $textarea_id, |
---|
90 | ), |
---|
91 | )); |
---|
92 | |
---|
93 | $template->set_filename('bbcodebar', realpath(BBCODE_PATH.'/template/bbcode_bar.tpl')); |
---|
94 | $template->parse('bbcodebar'); |
---|
95 | } |
---|
96 | |
---|
97 | // return string, HTML version of BBCoded $str |
---|
98 | function BBCodeParse($str) |
---|
99 | { |
---|
100 | global $conf; |
---|
101 | |
---|
102 | $str = bbcode_checktags(nl2br($str)); |
---|
103 | |
---|
104 | $patterns = array(); |
---|
105 | $replacements = array(); |
---|
106 | |
---|
107 | if ($conf['bbcode_bar']['p']) |
---|
108 | { |
---|
109 | //Paragraph |
---|
110 | $patterns[] = '#\[p\](.*?)\[/p\]#is'; |
---|
111 | $replacements[] = '<p>\\1</p>'; |
---|
112 | } |
---|
113 | if ($conf['bbcode_bar']['b']) |
---|
114 | { |
---|
115 | // Bold |
---|
116 | $patterns[] = '#\[b\](.*?)\[/b\]#is'; |
---|
117 | $replacements[] = '<b>\\1</b>'; |
---|
118 | } |
---|
119 | if ($conf['bbcode_bar']['i']) |
---|
120 | { |
---|
121 | //Italic |
---|
122 | $patterns[] = '#\[i\](.*?)\[/i\]#is'; |
---|
123 | $replacements[] = '<i>\\1</i>'; |
---|
124 | } |
---|
125 | if ($conf['bbcode_bar']['u']) |
---|
126 | { |
---|
127 | //Underline |
---|
128 | $patterns[] = '#\[u\](.*?)\[\/u\]#is'; |
---|
129 | $replacements[] = '<u>\\1</u>'; |
---|
130 | } |
---|
131 | if ($conf['bbcode_bar']['s']) |
---|
132 | { |
---|
133 | //Strikethrough |
---|
134 | $patterns[] = '#\[s\](.*?)\[/s\]#is'; |
---|
135 | $replacements[] = '<s>\\1</s>'; |
---|
136 | } |
---|
137 | if ($conf['bbcode_bar']['center']) |
---|
138 | { |
---|
139 | //Center |
---|
140 | $patterns[] = '#\[center\](.*?)\[/center\]#is'; |
---|
141 | $replacements[] = '<div align="center">\\1</div>'; |
---|
142 | } |
---|
143 | if ($conf['bbcode_bar']['right']) |
---|
144 | { |
---|
145 | //Right |
---|
146 | $patterns[] = '#\[right\](.*?)\[/right\]#is'; |
---|
147 | $replacements[] = '<div align="right">\\1</div>'; |
---|
148 | } |
---|
149 | if ($conf['bbcode_bar']['ol']) |
---|
150 | { |
---|
151 | //Olist |
---|
152 | $patterns[] = '#\[ol\](.*?)\[/ol\]#is'; |
---|
153 | $replacements[] = '<ol>\\1</ol>'; |
---|
154 | } |
---|
155 | if ($conf['bbcode_bar']['ul']) |
---|
156 | { |
---|
157 | //Ulist |
---|
158 | $patterns[] = '#\[ul\](.*?)\[/ul\]#is'; |
---|
159 | $replacements[] = '<ul>\\1</ul>'; |
---|
160 | } |
---|
161 | if ($conf['bbcode_bar']['ol'] || $conf['bbcode_bar']['ul']) |
---|
162 | { |
---|
163 | //List |
---|
164 | $patterns[] = '#\[li\](.*?)\[/li\]#is'; |
---|
165 | $replacements[] = '<li>\\1</li>'; |
---|
166 | } |
---|
167 | if ($conf['bbcode_bar']['quote']) |
---|
168 | { |
---|
169 | // Quotes |
---|
170 | $patterns[] = "#\[quote\](.*?)\[/quote\]#is"; |
---|
171 | $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal">\\1</span></blockquote>'; |
---|
172 | |
---|
173 | //Quotes with "user" |
---|
174 | $patterns[] = "#\[quote="(.*?)"\](.*?)\[/quote\]#is"; |
---|
175 | $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; |
---|
176 | |
---|
177 | //Quotes with user |
---|
178 | $patterns[] = "#\[quote=(.*?)\](.*?)\[/quote\]#is"; |
---|
179 | $replacements[] = '<blockquote><span style="font-size:11px;line-height:normal"><b>\\1 : </b><br/>\\2</span></blockquote>'; |
---|
180 | } |
---|
181 | if ($conf['bbcode_bar']['img']) |
---|
182 | { |
---|
183 | //Images |
---|
184 | $patterns[] = "#\[img\](.*?)\[/img\]#is"; |
---|
185 | $replacements[] = '<img src="\\1" />'; |
---|
186 | } |
---|
187 | if ($conf['bbcode_bar']['url']) |
---|
188 | { |
---|
189 | //[url]xxxx://www.zzzz.yyy[/url] |
---|
190 | $patterns[] = "#\[url\]([\w]+?://[^ \"\n\r\t<]*?)\[/url\]#is"; |
---|
191 | $replacements[] = '<a href="\\1" target="_blank">\\1</a>'; |
---|
192 | |
---|
193 | //[url]www.zzzzz.yyy[/url] |
---|
194 | $patterns[] = "#\[url\]((www|ftp)\.[^ \"\n\r\t<]*?)\[/url\]#is"; |
---|
195 | $replacements[] = '<a href="http://\\1" target="_blank">\\1</a>'; |
---|
196 | |
---|
197 | //[url=xxxx://www.zzzzz.yyy]ZzZzZ[/url] |
---|
198 | $patterns[] = "#\[url=([\w]+?://[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; |
---|
199 | $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; |
---|
200 | |
---|
201 | //[url=www.zzzzz.yyy]zZzZz[/url] |
---|
202 | $patterns[] = "#\[url=((www|ftp)\.[^ \"\n\r\t<]*?)\](.*?)\[/url\]#is"; |
---|
203 | $replacements[] = '<a href="http://\\1" target="_blank">\\2</a>'; |
---|
204 | |
---|
205 | //[url="www.zzzzz.yyy"]zZzZz[/url] |
---|
206 | $patterns[] = "#\[url="((www|ftp)\.[^ \n\r\t<]*?)"\](.*?)\[/url\]#is"; |
---|
207 | $replacements[] = '<a href="http://\\1" target="_blank">\\3</a>'; |
---|
208 | |
---|
209 | //[url="http://www.zzzzz.yyy"]zZzZz[/url] |
---|
210 | $patterns[] = "#\[url="([\w]+?://[^ \n\r\t<]*?)"\](.*?)\[/url\]#is"; |
---|
211 | $replacements[] = '<a href="\\1" target="_blank">\\2</a>'; |
---|
212 | } |
---|
213 | if ($conf['bbcode_bar']['email']) |
---|
214 | { |
---|
215 | //[email]samvure@gmail.com[/email] |
---|
216 | $patterns[] = "#\[email\]([a-z0-9&\-_.]+?@[\w\-]+\.([\w\-\.]+\.)?[\w]+)\[/email\]#is"; |
---|
217 | $replacements[] = '<a href="mailto:\\1">\\1</a>'; |
---|
218 | } |
---|
219 | if ($conf['bbcode_bar']['size']) |
---|
220 | { |
---|
221 | //Size |
---|
222 | $patterns[] = "#\[size=([1-2]?[0-9])\](.*?)\[/size\]#is"; |
---|
223 | $replacements[] = '<span style="font-size: \\1px; line-height: normal">\\2</span>'; |
---|
224 | } |
---|
225 | if ($conf['bbcode_bar']['color']) |
---|
226 | { |
---|
227 | //Colours |
---|
228 | $patterns[] = "#\[color=(\#[0-9A-F]{6}|\#[0-9A-F]{3}|[a-z]+)\](.*?)\[/color\]#is"; |
---|
229 | $replacements[] = '<span style="color: \\1">\\2</span>'; |
---|
230 | } |
---|
231 | |
---|
232 | return preg_replace($patterns, $replacements, $str); |
---|
233 | } |
---|