Conditions | 4 |
Paths | 4 |
Total Lines | 116 |
Code Lines | 88 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
160 | function bb2html_aux($text, $export) { |
||
161 | $urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)"; |
||
162 | // NOTE: |
||
163 | // This matches https:// too; I don't understand why. |
||
164 | // sample results: |
||
165 | // Array |
||
166 | // ( |
||
167 | // [0] => [img]https://a.b.c[/img] |
||
168 | // [1] => |
||
169 | // [2] => https://a.b.c |
||
170 | // ) |
||
171 | // Array |
||
172 | // ( |
||
173 | // [0] => [img]http://a.b.c[/img] |
||
174 | // [1] => http:// |
||
175 | // [2] => a.b.c |
||
176 | // ) |
||
177 | |||
178 | $httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)"; |
||
179 | // List of allowable tags |
||
180 | $bbtags = array ( |
||
181 | "@\[b\](.*?)\[/b\]@is", |
||
182 | "@\[i\](.*?)\[/i\]@is", |
||
183 | "@\[u\](.*?)\[/u\]@is", |
||
184 | "@\[s\](.*?)\[/s\]@is", |
||
185 | "@\[sup\](.*?)\[/sup\]@is", |
||
186 | "@\[url=$httpsregex\](.*?)\[/url\]@is", |
||
187 | "@\[url\]$httpsregex\[/url\]@is", |
||
188 | "@\[link=$urlregex\](.*?)\[/link\]@is", |
||
189 | "@\[link\]$urlregex\[/link\]@is", |
||
190 | "@\[url=$urlregex\](.*?)\[/url\]@is", |
||
191 | "@\[url\]$urlregex\[/url\]@is", |
||
192 | "@\[quote=(.*?)\](.*?)\[/quote\]@is", |
||
193 | "@\[quote\](.*?)\[/quote\]@is", |
||
194 | "@\[list\](.*?)\[/list\]@is", |
||
195 | "@\[list=1\](.*?)\[/list\]@is", |
||
196 | "@\[img\]$urlregex\[/img\]@is", |
||
197 | "@\[sm_img\]$urlregex\[/sm_img\]@is", |
||
198 | "@\[color=(?:\"?)(.{3,8})(?:\"?)\](.*?)\[/color\]@is", |
||
199 | "@((?:<ol>|<ul>).*?)\n\*([^\n]+)\n(.*?(</ol>|</ul>))@is", |
||
200 | "@\[size=([1-9]|[0-2][0-9])\](.*?)\[/size\]@is", |
||
201 | "@\[mailto\](.*?)\[/mailto\]@is", |
||
202 | "@\[email\](.*?)\[/email\]@is", |
||
203 | "@\[github\](?:\#|ticket:)(\d+)\[/github\]@is", |
||
204 | "@\[github\]wiki:(.*?)\[/github\]@is", |
||
205 | ); |
||
206 | |||
207 | // What the above tags are turned in to |
||
208 | if ($export) { |
||
209 | $htmltags = array ( |
||
210 | "<b>\\1</b>", |
||
211 | "<i>\\1</i>", |
||
212 | "<u>\\1</u>", |
||
213 | "<s>\\1</s>", |
||
214 | "<sup>\\1</sup>", |
||
215 | "<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>", |
||
216 | "<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>", |
||
217 | "<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>", |
||
218 | "<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>", |
||
219 | "<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>", |
||
220 | "<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>", |
||
221 | "<i>\\1 wrote:</i><blockquote>\\2</blockquote>", |
||
222 | "<blockquote>\\1</blockquote>", |
||
223 | "<ul>\\1</ul><p>", |
||
224 | "<ol>\\1</ol><p>", |
||
225 | "<img hspace=\"8\" src=\"\\1\\2\"> ", |
||
226 | "<img hspace=\"8\" width=400 src=\"\\1\\2\"> ", |
||
227 | "<font color=\"\\1\">\\2</font>", |
||
228 | "\\1<li>\\2\n\\3", |
||
229 | "<span style=\"font-size: \\1px;\">\\2</span>", |
||
230 | "<a href=\"mailto:\\1\">\\1</a>", |
||
231 | "<a href=\"mailto:\\1\">\\1</a>", |
||
232 | "<a href=\"https://github.com/BOINC/boinc/issues/\\1\">#\\1</a>", |
||
233 | "<a href=\"https://github.com/BOINC/boinc/wiki/\\1\">\\1</a>", |
||
234 | ); |
||
235 | } else { |
||
236 | $htmltags = array ( |
||
237 | "<b>\\1</b>", |
||
238 | "<i>\\1</i>", |
||
239 | "<u>\\1</u>", |
||
240 | "<s>\\1</s>", |
||
241 | "<sup>\\1</sup>", |
||
242 | "<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>", |
||
243 | "<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>", |
||
244 | "<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>", |
||
245 | "<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>", |
||
246 | "<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>", |
||
247 | "<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>", |
||
248 | "<em>\\1 wrote:</em><blockquote>\\2</blockquote>", |
||
249 | "<blockquote>\\1</blockquote>", |
||
250 | "<ul>\\1</ul><p>", |
||
251 | "<ol>\\1</ol><p>", |
||
252 | "<img hspace=\"8\" class=\"img-responsive\" src=\"\\1\\2\"> ", |
||
253 | "<img hspace=\"8\" width=400 src=\"\\1\\2\"> ", |
||
254 | "<font color=\"\\1\">\\2</font>", |
||
255 | "\\1<li>\\2\n\\3", |
||
256 | "<span style=\"font-size: \\1px;\">\\2</span>", |
||
257 | "<a href=\"mailto:\\1\">\\1</a>", |
||
258 | "<a href=\"mailto:\\1\">\\1</a>", |
||
259 | "<a href=\"https://github.com/BOINC/boinc/issues/\\1\">#\\1</a>", |
||
260 | "<a href=\"https://github.com/BOINC/boinc/wiki/\\1\">\\1</a>", |
||
261 | ); |
||
262 | } |
||
263 | |||
264 | // Do the actual replacing - iterations for nested items |
||
265 | $lasttext = ""; |
||
266 | $i = 0; |
||
267 | // $i<1000 to prevent DoS |
||
268 | while ($text != $lasttext && $i<1000) { |
||
269 | $lasttext = $text; |
||
270 | $text = preg_replace($bbtags, $htmltags, $text); |
||
271 | $i = $i + 1; |
||
272 | } |
||
273 | $text = str_replace("<ul>", '<ul style="word-break:break-word;">', $text); |
||
274 | $text = str_replace("<ol>", '<ol style="word-break:break-word;">', $text); |
||
275 | return $text; |
||
276 | } |
||
338 |