Filter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 69
ccs 52
cts 52
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A bbcode2html() 0 66 2
1
<?php
2
3
namespace Anax\Comments;
4
5
/**
6
 * Convert bbcode to HTML
7
 */
8
class Filter
9
{
10 3
    public function bbcode2html($bbtext)
11
    {
12
13
        $bbtags = array(
14 3
            '[heading1]' => '<h1>','[/heading1]' => '</h1>',
15 3
            '[heading2]' => '<h2>','[/heading2]' => '</h2>',
16 3
            '[heading3]' => '<h3>','[/heading3]' => '</h3>',
17 3
            '[heading4]' => '<h4>','[/heading4]' => '</h4>',
18 3
            '[h1]' => '<h1>','[/h1]' => '</h1>',
19 3
            '[h2]' => '<h2>','[/h2]' => '</h2>',
20 3
            '[h3]' => '<h3>','[/h3]' => '</h3>',
21 3
            '[h4]' => '<h4>','[/h4]' => '</h4>',
22
23 3
            '[paragraph]' => '<p>','[/paragraph]' => '</p>',
24 3
            '[para]' => '<p>','[/para]' => '</p>',
25 3
            '[p]' => '<p>','[/p]' => '</p>',
26 3
            '[left]' => '<p style="text-align:left;">','[/left]' => '</p>',
27 3
            '[right]' => '<p style="text-align:right;">','[/right]' => '</p>',
28 3
            '[center]' => '<p style="text-align:center;">','[/center]' => '</p>',
29 3
            '[justify]' => '<p style="text-align:justify;">','[/justify]' => '</p>',
30
31 3
            '[bold]' => '<span style="font-weight:bold;">','[/bold]' => '</span>',
32 3
            '[italic]' => '<span style="font-weight:bold;">','[/italic]' => '</span>',
33 3
            '[underline]' => '<span style="text-decoration:underline;">','[/underline]' => '</span>',
34 3
            '[b]' => '<span style="font-weight:bold;">','[/b]' => '</span>',
35 3
            '[i]' => '<span style="font-style:italic;">','[/i]' => '</span>',
36 3
            '[u]' => '<span style="text-decoration:underline;">','[/u]' => '</span>',
37 3
            '[break]' => '<br>',
38 3
            '[br]' => '<br>',
39 3
            '[newline]' => '<br>',
40 3
            '[nl]' => '<br>',
41
42 3
            '[unordered_list]' => '<ul>','[/unordered_list]' => '</ul>',
43 3
            '[list]' => '<ul>','[/list]' => '</ul>',
44 3
            '[ul]' => '<ul>','[/ul]' => '</ul>',
45
46 3
            '[ordered_list]' => '<ol>','[/ordered_list]' => '</ol>',
47 3
            '[ol]' => '<ol>','[/ol]' => '</ol>',
48 3
            '[list_item]' => '<li>','[/list_item]' => '</li>',
49 3
            '[li]' => '<li>','[/li]' => '</li>',
50
51 3
            '[*]' => '<li>','[/*]' => '</li>',
52 3
            '[code]' => '<code>','[/code]' => '</code>',
53 3
            '[preformatted]' => '<pre>','[/preformatted]' => '</pre>',
54 3
            '[pre]' => '<pre>','[/pre]' => '</pre>',
55 3
        );
56
57 3
        $bbtext = str_ireplace(array_keys($bbtags), array_values($bbtags), $bbtext);
58
59
        $bbextended = array(
60 3
            "/\[url](.*?)\[\/url]/i" => "<a href=\"http://$1\" title=\"$1\">$1</a>",
61 3
            "/\[url=(.*?)\](.*?)\[\/url\]/i" => "<a href=\"$1\" title=\"$1\">$2</a>",
62 3
            "/\[email=(.*?)\](.*?)\[\/email\]/i" => "<a href=\"mailto:$1\">$2</a>",
63 3
            "/\[mail=(.*?)\](.*?)\[\/mail\]/i" => "<a href=\"mailto:$1\">$2</a>",
64 3
            "/\[img\]([^[]*)\[\/img\]/i" => "<img src=\"$1\" alt=\" \" />",
65 3
            "/\[image\]([^[]*)\[\/image\]/i" => "<img src=\"$1\" alt=\" \" />",
66 3
            "/\[image_left\]([^[]*)\[\/image_left\]/i" => "<img src=\"$1\" alt=\" \" class=\"img_left\" />",
67 3
            "/\[image_right\]([^[]*)\[\/image_right\]/i" => "<img src=\"$1\" alt=\" \" class=\"img_right\" />",
68 3
        );
69
70 3
        foreach ($bbextended as $match => $replacement) {
71 3
            $bbtext = preg_replace($match, $replacement, $bbtext);
72 3
        }
73
74 3
        return $bbtext;
75
    }
76
}
77