@@ -17,16 +17,16 @@ discard block |
||
17 | 17 | |
18 | 18 | private $captcha_text = null; |
19 | 19 | private $captcha_result = null; |
20 | - private $captcha_hash = null; |
|
20 | + private $captcha_hash = null; |
|
21 | 21 | private $captcha_generated = false; |
22 | 22 | |
23 | 23 | function __construct(View $View, $settings = array()) { |
24 | 24 | $this->options = SimpleCaptcha::$defaults; |
25 | 25 | |
26 | 26 | # Set up an array with the operators that we want to use. With difficulty=1 it is only subtraction and addition. |
27 | - $this->captcha_operator_convert = array( '-' ); |
|
27 | + $this->captcha_operator_convert = array('-'); |
|
28 | 28 | |
29 | - $configs = (array)Configure::read('Captcha'); |
|
29 | + $configs = (array) Configure::read('Captcha'); |
|
30 | 30 | if (!empty($configs)) { |
31 | 31 | $this->options = array_merge($this->options, $configs); |
32 | 32 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $captchaOperator = $this->captcha_operator_convert[mt_rand(0, count($this->captcha_operator_convert) - 1)]; |
51 | 51 | |
52 | 52 | # Get the equation in textual form to show to the user. |
53 | - $this->captcha_text = $numberOne . ' ' . $captchaOperator . ' ' . $numberTwo; |
|
53 | + $this->captcha_text = $numberOne.' '.$captchaOperator.' '.$numberTwo; |
|
54 | 54 | |
55 | 55 | # Evaluate the equation and get the result. |
56 | 56 | $this->captcha_result = $numberOne - $numberTwo; |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return string |
79 | 79 | */ |
80 | 80 | public function input($model = null, $options = array()) { |
81 | - return $this->active($model, $options) . $this->passive($model, $options); |
|
81 | + return $this->active($model, $options).$this->passive($model, $options); |
|
82 | 82 | return $out; |
83 | 83 | } |
84 | 84 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | $out = '<div style="display:none">'. |
96 | 96 | $this->Form->input($field.'_hash', array('value'=>$this->captcha_hash)). |
97 | 97 | $this->Form->input($field.'_time', array('value'=>time())). |
98 | - $this->Form->input((!empty($model)?$model.'.':'').$this->options['dummyField'], array('value'=>'')). |
|
98 | + $this->Form->input((!empty($model) ? $model.'.' : '').$this->options['dummyField'], array('value'=>'')). |
|
99 | 99 | '</div>'; |
100 | 100 | |
101 | 101 | return $out; |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'class'=>'captcha', |
118 | 118 | 'value'=>'', |
119 | 119 | 'maxlength'=>3, |
120 | - 'label'=>__('Captcha',true), |
|
120 | + 'label'=>__('Captcha', true), |
|
121 | 121 | 'combined'=>true, 'autocomplete'=>'off' |
122 | 122 | ); |
123 | 123 | $options = array_merge($defaultOptions, $options); |
@@ -8,54 +8,54 @@ discard block |
||
8 | 8 | * Output of form data for the captcha |
9 | 9 | */ |
10 | 10 | class SimpleCaptchaHelper extends AppHelper { |
11 | - var $helpers = array('Form'); |
|
11 | + var $helpers = array('Form'); |
|
12 | 12 | |
13 | - private $options = null; |
|
14 | - private $methods = array('hash', 'db', 'session'); |
|
13 | + private $options = null; |
|
14 | + private $methods = array('hash', 'db', 'session'); |
|
15 | 15 | |
16 | - private $captcha_operator_convert = null; |
|
16 | + private $captcha_operator_convert = null; |
|
17 | 17 | |
18 | - private $captcha_text = null; |
|
19 | - private $captcha_result = null; |
|
20 | - private $captcha_hash = null; |
|
21 | - private $captcha_generated = false; |
|
18 | + private $captcha_text = null; |
|
19 | + private $captcha_result = null; |
|
20 | + private $captcha_hash = null; |
|
21 | + private $captcha_generated = false; |
|
22 | 22 | |
23 | - function __construct(View $View, $settings = array()) { |
|
24 | - $this->options = SimpleCaptcha::$defaults; |
|
23 | + function __construct(View $View, $settings = array()) { |
|
24 | + $this->options = SimpleCaptcha::$defaults; |
|
25 | 25 | |
26 | - # Set up an array with the operators that we want to use. With difficulty=1 it is only subtraction and addition. |
|
27 | - $this->captcha_operator_convert = array( '-' ); |
|
26 | + # Set up an array with the operators that we want to use. With difficulty=1 it is only subtraction and addition. |
|
27 | + $this->captcha_operator_convert = array( '-' ); |
|
28 | 28 | |
29 | - $configs = (array)Configure::read('Captcha'); |
|
30 | - if (!empty($configs)) { |
|
31 | - $this->options = array_merge($this->options, $configs); |
|
32 | - } |
|
29 | + $configs = (array)Configure::read('Captcha'); |
|
30 | + if (!empty($configs)) { |
|
31 | + $this->options = array_merge($this->options, $configs); |
|
32 | + } |
|
33 | 33 | |
34 | - parent::__construct($View, $settings); |
|
35 | - } |
|
34 | + parent::__construct($View, $settings); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * Generates the captcha values |
|
40 | - * |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - protected function _generate() { |
|
44 | - if ($this->captcha_generated === TRUE) return; |
|
45 | - # Choose the first number randomly between 6 and 10. This is to stop the answer being negative. |
|
46 | - $numberOne = mt_rand(6, 9); |
|
47 | - # Choose the second number randomly between 0 and 5. |
|
48 | - $numberTwo = mt_rand(1, 5); |
|
49 | - # Choose the operator randomly from the array. |
|
50 | - $captchaOperator = $this->captcha_operator_convert[mt_rand(0, count($this->captcha_operator_convert) - 1)]; |
|
38 | + /** |
|
39 | + * Generates the captcha values |
|
40 | + * |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + protected function _generate() { |
|
44 | + if ($this->captcha_generated === TRUE) return; |
|
45 | + # Choose the first number randomly between 6 and 10. This is to stop the answer being negative. |
|
46 | + $numberOne = mt_rand(6, 9); |
|
47 | + # Choose the second number randomly between 0 and 5. |
|
48 | + $numberTwo = mt_rand(1, 5); |
|
49 | + # Choose the operator randomly from the array. |
|
50 | + $captchaOperator = $this->captcha_operator_convert[mt_rand(0, count($this->captcha_operator_convert) - 1)]; |
|
51 | 51 | |
52 | - # Get the equation in textual form to show to the user. |
|
53 | - $this->captcha_text = $numberOne . ' ' . $captchaOperator . ' ' . $numberTwo; |
|
52 | + # Get the equation in textual form to show to the user. |
|
53 | + $this->captcha_text = $numberOne . ' ' . $captchaOperator . ' ' . $numberTwo; |
|
54 | 54 | |
55 | - # Evaluate the equation and get the result. |
|
56 | - $this->captcha_result = $numberOne - $numberTwo; |
|
55 | + # Evaluate the equation and get the result. |
|
56 | + $this->captcha_result = $numberOne - $numberTwo; |
|
57 | 57 | |
58 | - # Session-Way (only one form at a time) - must be a component then |
|
58 | + # Session-Way (only one form at a time) - must be a component then |
|
59 | 59 | //$this->Session->write('Captcha.result', $result); |
60 | 60 | |
61 | 61 | # DB-Way (several forms possible, high security via IP-Based max limits) |
@@ -63,89 +63,89 @@ discard block |
||
63 | 63 | // $Captcha = ClassRegistry::init('Captcha'); |
64 | 64 | // $Captcha->new(); $Captcha->update(); etc |
65 | 65 | |
66 | - # Timestamp-SessionID-Hash-Way (several forms possible, not as secure) |
|
67 | - $this->captcha_hash = SimpleCaptcha::buildHash(array('timestamp' => time(), 'result' => $this->captcha_result), $this->options); |
|
68 | - |
|
69 | - $this->captcha_generated = TRUE; |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * active + passive captcha |
|
75 | - * |
|
76 | - * @param type $model |
|
77 | - * @param type $options |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function input($model = null, $options = array()) { |
|
81 | - return $this->active($model, $options) . $this->passive($model, $options); |
|
82 | - return $out; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * passive captcha |
|
87 | - * 2010-01-08 ms |
|
88 | - */ |
|
89 | - public function passive($model = null, $options = array()) { |
|
90 | - $this->_generate(); |
|
91 | - |
|
92 | - $field = $this->__fieldName($model); |
|
93 | - |
|
94 | - # add passive part on active forms as well |
|
95 | - $out = '<div style="display:none">'. |
|
66 | + # Timestamp-SessionID-Hash-Way (several forms possible, not as secure) |
|
67 | + $this->captcha_hash = SimpleCaptcha::buildHash(array('timestamp' => time(), 'result' => $this->captcha_result), $this->options); |
|
68 | + |
|
69 | + $this->captcha_generated = TRUE; |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * active + passive captcha |
|
75 | + * |
|
76 | + * @param type $model |
|
77 | + * @param type $options |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function input($model = null, $options = array()) { |
|
81 | + return $this->active($model, $options) . $this->passive($model, $options); |
|
82 | + return $out; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * passive captcha |
|
87 | + * 2010-01-08 ms |
|
88 | + */ |
|
89 | + public function passive($model = null, $options = array()) { |
|
90 | + $this->_generate(); |
|
91 | + |
|
92 | + $field = $this->__fieldName($model); |
|
93 | + |
|
94 | + # add passive part on active forms as well |
|
95 | + $out = '<div style="display:none">'. |
|
96 | 96 | $this->Form->input($field.'_hash', array('value'=>$this->captcha_hash)). |
97 | 97 | $this->Form->input($field.'_time', array('value'=>time())). |
98 | 98 | $this->Form->input((!empty($model)?$model.'.':'').$this->options['dummyField'], array('value'=>'')). |
99 | 99 | '</div>'; |
100 | 100 | |
101 | - return $out; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * active math captcha |
|
106 | - * either combined with between=true (all in this one funtion) |
|
107 | - * or seperated by =false (needs input(false) and captcha() calls then) |
|
108 | - * @param bool between: [default: true] |
|
109 | - * 2010-01-08 ms |
|
110 | - */ |
|
111 | - public function active($model = null, $options = array()) { |
|
112 | - $this->_generate(); |
|
113 | - |
|
114 | - // @todo refactor into __construct |
|
115 | - $defaultOptions = array( |
|
116 | - 'type'=>'text', |
|
117 | - 'class'=>'captcha', |
|
118 | - 'value'=>'', |
|
119 | - 'maxlength'=>3, |
|
120 | - 'label'=>__('Captcha',true), |
|
121 | - 'combined'=>true, 'autocomplete'=>'off' |
|
122 | - ); |
|
123 | - $options = array_merge($defaultOptions, $options); |
|
124 | - |
|
125 | - $out = ''; |
|
126 | - if ($this->options['type'] == 'active') { |
|
127 | - // obvuscate operation for bots by reversing the code in source but reverse effect with CSS |
|
128 | - $out .= '<span id="captchaCode" style="unicode-bidi: bidi-override; direction: rtl;">'.strrev($this->captcha_text); |
|
129 | - // let's go nuts here |
|
130 | - $out .= '<span style="display: none;"> - '.mt_rand(10, 20).'</span>'; |
|
131 | - $out .= '</span>'; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - if ($options['combined'] === true) { |
|
101 | + return $out; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * active math captcha |
|
106 | + * either combined with between=true (all in this one funtion) |
|
107 | + * or seperated by =false (needs input(false) and captcha() calls then) |
|
108 | + * @param bool between: [default: true] |
|
109 | + * 2010-01-08 ms |
|
110 | + */ |
|
111 | + public function active($model = null, $options = array()) { |
|
112 | + $this->_generate(); |
|
113 | + |
|
114 | + // @todo refactor into __construct |
|
115 | + $defaultOptions = array( |
|
116 | + 'type'=>'text', |
|
117 | + 'class'=>'captcha', |
|
118 | + 'value'=>'', |
|
119 | + 'maxlength'=>3, |
|
120 | + 'label'=>__('Captcha',true), |
|
121 | + 'combined'=>true, 'autocomplete'=>'off' |
|
122 | + ); |
|
123 | + $options = array_merge($defaultOptions, $options); |
|
124 | + |
|
125 | + $out = ''; |
|
126 | + if ($this->options['type'] == 'active') { |
|
127 | + // obvuscate operation for bots by reversing the code in source but reverse effect with CSS |
|
128 | + $out .= '<span id="captchaCode" style="unicode-bidi: bidi-override; direction: rtl;">'.strrev($this->captcha_text); |
|
129 | + // let's go nuts here |
|
130 | + $out .= '<span style="display: none;"> - '.mt_rand(10, 20).'</span>'; |
|
131 | + $out .= '</span>'; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + if ($options['combined'] === true) { |
|
136 | 136 | $options['between'] = $out.' = '; |
137 | 137 | } |
138 | - unset($options['combined']); |
|
139 | - |
|
140 | - return $this->Form->input($this->__fieldName($model), $options); |
|
141 | - } |
|
142 | - |
|
143 | - private function __fieldName($model_name = null) { |
|
144 | - $field_name = 'captcha'; |
|
145 | - if (isSet($model_name)) { |
|
146 | - $field_name = $model_name.'.'.$field_name; |
|
147 | - } |
|
148 | - return $field_name; |
|
149 | - } |
|
138 | + unset($options['combined']); |
|
139 | + |
|
140 | + return $this->Form->input($this->__fieldName($model), $options); |
|
141 | + } |
|
142 | + |
|
143 | + private function __fieldName($model_name = null) { |
|
144 | + $field_name = 'captcha'; |
|
145 | + if (isSet($model_name)) { |
|
146 | + $field_name = $model_name.'.'.$field_name; |
|
147 | + } |
|
148 | + return $field_name; |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | ?> |
152 | 152 | \ No newline at end of file |
@@ -41,7 +41,9 @@ |
||
41 | 41 | * @return array |
42 | 42 | */ |
43 | 43 | protected function _generate() { |
44 | - if ($this->captcha_generated === TRUE) return; |
|
44 | + if ($this->captcha_generated === TRUE) { |
|
45 | + return; |
|
46 | + } |
|
45 | 47 | # Choose the first number randomly between 6 and 10. This is to stop the answer being negative. |
46 | 48 | $numberOne = mt_rand(6, 9); |
47 | 49 | # Choose the second number randomly between 0 and 5. |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class SimpleCaptcha extends Object { |
4 | - static public $defaults = array ( |
|
4 | + static public $defaults = array( |
|
5 | 5 | 'dummyField' => 'homepage', |
6 | 6 | 'method' => 'hash', |
7 | 7 | 'checkSession' => false, |
@@ -1,22 +1,22 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class SimpleCaptcha extends Object { |
4 | - static public $defaults = array ( |
|
5 | - 'dummyField' => 'homepage', |
|
6 | - 'method' => 'hash', |
|
7 | - 'checkSession' => false, |
|
8 | - 'checkIp' => false, |
|
9 | - 'salt' => '', |
|
10 | - 'type' => 'active', |
|
11 | - ); |
|
4 | + static public $defaults = array ( |
|
5 | + 'dummyField' => 'homepage', |
|
6 | + 'method' => 'hash', |
|
7 | + 'checkSession' => false, |
|
8 | + 'checkIp' => false, |
|
9 | + 'salt' => '', |
|
10 | + 'type' => 'active', |
|
11 | + ); |
|
12 | 12 | |
13 | - public static function buildHash($params, $options) { |
|
14 | - $hashValue = date('c', $params['timestamp']).'_'; |
|
15 | - $hashValue .= ($options['checkSession']) ? session_id().'_' : ''; |
|
16 | - $hashValue .= ($options['checkIp']) ? env('REMOTE_ADDR').'_' : ''; |
|
17 | - $hashValue .= $params['result'].'_'.$options['salt']; |
|
18 | - $hashValue = Security::hash($hashValue); |
|
19 | - return $hashValue; |
|
20 | - } |
|
13 | + public static function buildHash($params, $options) { |
|
14 | + $hashValue = date('c', $params['timestamp']).'_'; |
|
15 | + $hashValue .= ($options['checkSession']) ? session_id().'_' : ''; |
|
16 | + $hashValue .= ($options['checkIp']) ? env('REMOTE_ADDR').'_' : ''; |
|
17 | + $hashValue .= $params['result'].'_'.$options['salt']; |
|
18 | + $hashValue = Security::hash($hashValue); |
|
19 | + return $hashValue; |
|
20 | + } |
|
21 | 21 | } |
22 | 22 | ?> |
23 | 23 | \ No newline at end of file |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | public function testAtLinkKnownUsers() { |
285 | 285 | $input = '@Alice @Bob @Bobby Junior @Bobby Tables @Dr. No'; |
286 | 286 | $expected = |
287 | - "<a href='/at/Alice'>@Alice</a>" . |
|
288 | - " @Bob " . |
|
289 | - "<a href='/at/Bobby+Junior'>@Bobby Junior</a>" . |
|
290 | - " @Bobby Tables " . |
|
287 | + "<a href='/at/Alice'>@Alice</a>". |
|
288 | + " @Bob ". |
|
289 | + "<a href='/at/Bobby+Junior'>@Bobby Junior</a>". |
|
290 | + " @Bobby Tables ". |
|
291 | 291 | "<a href='/at/Dr.+No'>@Dr. No</a>"; |
292 | 292 | |
293 | 293 | $result = $this->_Parser->parse($input); |
@@ -580,8 +580,8 @@ discard block |
||
580 | 580 | |
581 | 581 | public function testIframe() { |
582 | 582 | //* test allowed domain |
583 | - $input = '[iframe height=349 width=560 ' . |
|
584 | - 'src=http://www.youtube.com/embed/HdoW3t_WorU ' . |
|
583 | + $input = '[iframe height=349 width=560 '. |
|
584 | + 'src=http://www.youtube.com/embed/HdoW3t_WorU '. |
|
585 | 585 | 'frameborder=0][/iframe]'; |
586 | 586 | $expected = [ |
587 | 587 | ['iframe' => [ |
@@ -596,8 +596,8 @@ discard block |
||
596 | 596 | $this->assertTags($result, $expected); |
597 | 597 | |
598 | 598 | //* test forbidden domains |
599 | - $input = '[iframe height=349 width=560 ' . |
|
600 | - 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
599 | + $input = '[iframe height=349 width=560 '. |
|
600 | + 'src=http://www.youtubescam.com/embed/HdoW3t_WorU '. |
|
601 | 601 | 'frameborder=0][/iframe]'; |
602 | 602 | $expected = '/src/i'; |
603 | 603 | $result = $this->_Parser->parse($input, ['video_domains_allowed' => 'youtube | vimeo']); |
@@ -605,8 +605,8 @@ discard block |
||
605 | 605 | } |
606 | 606 | |
607 | 607 | public function testIframeAllDomainsAllowed() { |
608 | - $input = '[iframe height=349 width=560 ' . |
|
609 | - 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
608 | + $input = '[iframe height=349 width=560 '. |
|
609 | + 'src=http://www.youtubescam.com/embed/HdoW3t_WorU '. |
|
610 | 610 | '][/iframe]'; |
611 | 611 | $expected = 'src="http://www.youtubescam.com/embed/HdoW3t_WorU'; |
612 | 612 | $result = $this->_Parser->parse($input, ['video_domains_allowed' => '*']); |
@@ -614,8 +614,8 @@ discard block |
||
614 | 614 | } |
615 | 615 | |
616 | 616 | public function testIframeNoDomainAllowed() { |
617 | - $input = '[iframe height=349 width=560 ' . |
|
618 | - 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
617 | + $input = '[iframe height=349 width=560 '. |
|
618 | + 'src=http://www.youtubescam.com/embed/HdoW3t_WorU '. |
|
619 | 619 | '][/iframe]'; |
620 | 620 | $expected = '/src/i'; |
621 | 621 | $result = $this->_Parser->parse($input, ['video_domains_allowed' => '']); |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | |
635 | 635 | // test for URIs without protocol |
636 | 636 | $input = '[img]/somewhere/macnemo.png[/img]'; |
637 | - $expected = '<img src="' . $this->_Helper->webroot . 'somewhere/macnemo.png" alt=""/>'; |
|
637 | + $expected = '<img src="'.$this->_Helper->webroot.'somewhere/macnemo.png" alt=""/>'; |
|
638 | 638 | $result = $this->_Parser->parse($input); |
639 | 639 | $this->assertEquals($expected, $result); |
640 | 640 | |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | public function testCodeNoCitationMark() { |
818 | 818 | // [code]<citation mark>[/code] should not be cited |
819 | 819 | $input = h( |
820 | - "[code]\n" . $this->_Helper->settings['quote_symbol'] . "\n[/code]" |
|
820 | + "[code]\n".$this->_Helper->settings['quote_symbol']."\n[/code]" |
|
821 | 821 | ); |
822 | 822 | $expected = '`span class=.*?richtext-citation`'; |
823 | 823 | $result = $this->_Parser->parse($input); |
@@ -832,11 +832,11 @@ discard block |
||
832 | 832 | |
833 | 833 | public function testQuote() { |
834 | 834 | $_qs = h($this->_Helper->settings['quote_symbol']); |
835 | - $input = $_qs . ' fo [b]test[/b] ba'; |
|
835 | + $input = $_qs.' fo [b]test[/b] ba'; |
|
836 | 836 | $result = $this->_Parser->parse($input); |
837 | 837 | $expected = [ |
838 | 838 | 'span' => ['class' => 'richtext-citation'], |
839 | - $_qs . ' fo ', |
|
839 | + $_qs.' fo ', |
|
840 | 840 | 'strong' => [], |
841 | 841 | 'test', |
842 | 842 | '/strong', |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | //* test autoconversion for audio files |
865 | 865 | $html5AudioExtensions = array('m4a', 'ogg', 'mp3', 'wav', 'opus'); |
866 | 866 | foreach ($html5AudioExtensions as $extension) { |
867 | - $url = 'http://example.com/audio.' . $extension; |
|
867 | + $url = 'http://example.com/audio.'.$extension; |
|
868 | 868 | $input = "[video]{$url}[/video]"; |
869 | 869 | $result = $this->_Parser->parse($input); |
870 | 870 | $expected = array( |
@@ -927,7 +927,7 @@ discard block |
||
927 | 927 | $input = "[audio]{$url}[/audio]"; |
928 | 928 | $result = $this->_Parser->parse($input); |
929 | 929 | $expected = array( |
930 | - 'audio' => array( 'src' => $url, 'controls' => 'controls' ), |
|
930 | + 'audio' => array('src' => $url, 'controls' => 'controls'), |
|
931 | 931 | ); |
932 | 932 | $this->assertTags($result, $expected); |
933 | 933 |
@@ -1,337 +1,337 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | - use Plugin\BbcodeParser\Lib; |
|
4 | - use Saito\User\Userlist; |
|
5 | - |
|
6 | - App::import('Lib', 'Stopwatch.Stopwatch'); |
|
7 | - App::import('Helper', |
|
8 | - array( |
|
9 | - 'FileUpload.FileUpload', |
|
10 | - 'CakephpGeshi.Geshi', |
|
11 | - )); |
|
12 | - App::import('Helper', 'MailObfuscator.MailObfuscator'); |
|
13 | - |
|
14 | - App::uses('Controller', 'Controller'); |
|
15 | - App::uses('View', 'View'); |
|
16 | - App::uses('ParserHelper', 'View/Helper'); |
|
17 | - App::uses('HtmlHelper', 'View/Helper'); |
|
18 | - App::uses('CakeRequest', 'Network'); |
|
19 | - |
|
20 | - class BbcodeParserTest extends CakeTestCase { |
|
21 | - |
|
22 | - protected $_Parser = null; |
|
23 | - |
|
24 | - public function testBold() { |
|
25 | - $input = '[b]bold[/b]'; |
|
26 | - $expected = array('strong' => array(), 'bold', '/strong'); |
|
27 | - $result = $this->_Parser->parse($input); |
|
28 | - $this->assertTags($result, $expected); |
|
29 | - } |
|
30 | - |
|
31 | - public function testQuoteblock() { |
|
32 | - $input = '[quote]foo bar[/quote]'; |
|
33 | - $expected = array('blockquote' => array(), 'foo bar', '/blockquote'); |
|
34 | - $result = $this->_Parser->parse($input); |
|
35 | - $this->assertTags($result, $expected); |
|
36 | - } |
|
37 | - |
|
38 | - public function testEmphasis() { |
|
39 | - $input = '[i]italic[/i]'; |
|
40 | - $expected = array('em' => array(), 'italic', '/em'); |
|
41 | - $result = $this->_Parser->parse($input); |
|
42 | - $this->assertTags($result, $expected); |
|
43 | - } |
|
44 | - |
|
45 | - public function testStrike() { |
|
46 | - $expected = ['del' => [], 'text', '/del']; |
|
47 | - |
|
48 | - // [strike] |
|
49 | - $input = '[strike]text[/strike]'; |
|
50 | - $result = $this->_Parser->parse($input); |
|
51 | - $this->assertTags($result, $expected); |
|
52 | - |
|
53 | - // [s] |
|
54 | - $input = '[s]text[/s]'; |
|
55 | - $result = $this->_Parser->parse($input); |
|
56 | - $this->assertTags($result, $expected); |
|
57 | - } |
|
58 | - |
|
59 | - public function testSpoiler() { |
|
60 | - $input = 'pre [spoiler] te "\' xt[/spoiler]'; |
|
61 | - $expected = [ |
|
62 | - 'pre', |
|
63 | - [ |
|
64 | - 'div' => [ |
|
65 | - 'class' => 'richtext-spoiler', |
|
66 | - 'style' => 'display: inline;' |
|
67 | - ] |
|
68 | - ], |
|
69 | - ['script' => true], |
|
70 | - 'preg:/(.*?)"string":" te "' xt"(.*?)(?=<)/', |
|
71 | - '/script', |
|
72 | - [ |
|
73 | - 'a' => [ |
|
74 | - 'href' => '#', |
|
75 | - 'class' => 'richtext-spoiler-link', |
|
76 | - 'onclick' |
|
77 | - ] |
|
78 | - ], |
|
79 | - 'preg:/.*▇ Spoiler ▇.*?(?=<)/', |
|
80 | - '/a', |
|
81 | - '/div' |
|
82 | - ]; |
|
83 | - $result = $this->_Parser->parse($input); |
|
84 | - $this->assertTags($result, $expected, true); |
|
85 | - } |
|
86 | - |
|
87 | - public function testList() { |
|
88 | - $input = "[list]\n[*]fooo\n[*]bar\n[/list]"; |
|
89 | - $expected = [ |
|
90 | - ['ul' => []], |
|
91 | - ['li' => []], |
|
92 | - 'fooo', |
|
93 | - ['br' => []], |
|
94 | - '/li', |
|
95 | - ['li' => []], |
|
96 | - 'bar', |
|
97 | - ['br' => []], |
|
98 | - '/li', |
|
99 | - '/ul' |
|
100 | - ]; |
|
101 | - $result = $this->_Parser->parse($input); |
|
102 | - $this->assertTags($result, $expected); |
|
103 | - } |
|
104 | - |
|
105 | - public function testMaskLinkWithoutProtocol() { |
|
106 | - $input = '[url=thetempe.st/station]purge[/url]'; |
|
107 | - $expected = [ |
|
108 | - 'a' => [ |
|
109 | - 'href' => 'http://thetempe.st/station', |
|
110 | - 'rel' => 'external', |
|
111 | - 'target' => '_blank' |
|
112 | - ], |
|
113 | - 'purge', |
|
114 | - '/a' |
|
115 | - ]; |
|
116 | - $result = $this->_Parser->parse($input); |
|
117 | - $this->assertTags($result, $expected); |
|
118 | - } |
|
119 | - |
|
120 | - public function testParserEngineCaching() { |
|
121 | - $input = '[img=]foo.png[/img]'; |
|
122 | - $result = $this->_Parser->parse($input, ['multimedia' => true]); |
|
123 | - $this->assertContains('<img src', $result); |
|
124 | - $result = $this->_Parser->parse($input, ['multimedia' => false]); |
|
125 | - $this->assertNotContains('<img src', $result); |
|
126 | - } |
|
127 | - |
|
128 | - public function testLink() { |
|
129 | - $input = '[url=http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250678480561&ssPageName=ADME:X:RTQ:DE:1123]test[/url]'; |
|
130 | - $expected = "<a href='http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250678480561&ssPageName=ADME:X:RTQ:DE:1123' rel='external' target='_blank'>test</a> <span class='richtext-linkInfo'>[ebay.de]</span>"; |
|
131 | - $result = $this->_Parser->parse($input); |
|
132 | - $this->assertEquals($expected, $result); |
|
133 | - |
|
134 | - /** |
|
135 | - * external server |
|
136 | - */ |
|
137 | - $input = '[url]http://heise.de/foobar[/url]'; |
|
138 | - $expected = array( |
|
139 | - 'a' => array( |
|
140 | - 'href' => 'http://heise.de/foobar', |
|
141 | - 'rel' => 'external', |
|
142 | - 'target' => '_blank' |
|
143 | - ), |
|
144 | - 'http://heise.de/foobar', |
|
145 | - '/a' |
|
146 | - ); |
|
147 | - $result = $this->_Parser->parse($input); |
|
148 | - $this->assertTags($result, $expected); |
|
149 | - |
|
150 | - $input = '[link]http://heise.de/foobar[/link]'; |
|
151 | - $expected = array( |
|
152 | - 'a' => array( |
|
153 | - 'href' => 'http://heise.de/foobar', |
|
154 | - 'rel' => 'external', |
|
155 | - 'target' => '_blank' |
|
156 | - ), |
|
157 | - 'http://heise.de/foobar', |
|
158 | - '/a' |
|
159 | - ); |
|
160 | - $result = $this->_Parser->parse($input); |
|
161 | - $this->assertTags($result, $expected); |
|
162 | - |
|
163 | - // masked link |
|
164 | - $input = '[url=http://heise.de/foobar]foobar[/url]'; |
|
165 | - $expected = array( |
|
166 | - 'a' => array( |
|
167 | - 'href' => 'http://heise.de/foobar', |
|
168 | - 'rel' => 'external', |
|
169 | - 'target' => '_blank' |
|
170 | - ), |
|
171 | - 'foobar', |
|
172 | - '/a', |
|
173 | - 'span' => array('class' => 'richtext-linkInfo'), '[heise.de]', '/span' |
|
174 | - ); |
|
175 | - $result = $this->_Parser->parse($input); |
|
176 | - $this->assertTags($result, $expected); |
|
177 | - |
|
178 | - // masked link with no label |
|
179 | - $input = '[url=http://heise.de/foobar label=none ]foobar[/url]'; |
|
180 | - $expected = array( |
|
181 | - 'a' => array( |
|
182 | - 'href' => 'http://heise.de/foobar', |
|
183 | - 'rel' => 'external', |
|
184 | - 'target' => '_blank', |
|
185 | - ), |
|
186 | - 'foobar', |
|
187 | - '/a', |
|
188 | - ); |
|
189 | - $result = $this->_Parser->parse($input); |
|
190 | - $this->assertTags($result, $expected); |
|
191 | - |
|
192 | - /** |
|
193 | - * local server |
|
194 | - */ |
|
195 | - $input = '[url=http://macnemo.de/foobar]foobar[/url]'; |
|
196 | - $expected = "<a href='http://macnemo.de/foobar'>foobar</a>"; |
|
197 | - $result = $this->_Parser->parse($input); |
|
198 | - $this->assertEquals($expected, $result); |
|
199 | - |
|
200 | - $input = '[url]/foobar[/url]'; |
|
201 | - $expected = array( |
|
202 | - 'a' => array( |
|
203 | - 'href' => '/foobar', |
|
204 | - ), |
|
205 | - 'preg:/\/foobar/', |
|
206 | - '/a', |
|
207 | - ); |
|
208 | - $result = $this->_Parser->parse($input); |
|
209 | - $this->assertTags($result, $expected); |
|
210 | - |
|
211 | - // test lokaler server with absolute url |
|
212 | - $input = '[url=/foobar]foobar[/url]'; |
|
213 | - $expected = "<a href='/foobar'>foobar</a>"; |
|
214 | - $result = $this->_Parser->parse($input); |
|
215 | - $this->assertEquals($expected, $result); |
|
216 | - |
|
217 | - // test 'http://' only |
|
218 | - $input = '[url=http://]foobar[/url]'; |
|
219 | - $expected = "<a href='http://'>foobar</a>"; |
|
220 | - $result = $this->_Parser->parse($input); |
|
221 | - $this->assertEquals($expected, $result); |
|
222 | - |
|
223 | - // test for co.uk |
|
224 | - $input = '[url=http://heise.co.uk/foobar]foobar[/url]'; |
|
225 | - $expected = array( |
|
226 | - 'a' => array( |
|
227 | - 'href' => 'http://heise.co.uk/foobar', |
|
228 | - 'rel' => 'external', |
|
229 | - 'target' => '_blank' |
|
230 | - ), |
|
231 | - 'foobar', |
|
232 | - '/a', |
|
233 | - 'span' => array('class' => 'richtext-linkInfo'), '[heise.co.uk]', |
|
234 | - '/span' |
|
235 | - ); |
|
236 | - $result = $this->_Parser->parse($input); |
|
237 | - $this->assertTags($result, $expected); |
|
238 | - } |
|
239 | - |
|
240 | - public function testHashLinkSuccess() { |
|
241 | - // inline content ([i]) |
|
242 | - $input = "[i]#2234[/i]"; |
|
243 | - $expected = [ |
|
244 | - 'em' => [], |
|
245 | - 'a' => [ |
|
246 | - 'href' => '/hash/2234' |
|
247 | - ], |
|
248 | - '#2234', |
|
249 | - '/a', |
|
250 | - '/em' |
|
251 | - ]; |
|
252 | - $result = $this->_Parser->parse($input); |
|
253 | - $this->assertTags($result, $expected); |
|
254 | - |
|
255 | - // lists |
|
256 | - $input = "[list][*]#2234[/list]"; |
|
257 | - $expected = [ |
|
258 | - 'ul' => true, |
|
259 | - 'li' => true, |
|
260 | - 'a' => [ |
|
261 | - 'href' => '/hash/2234' |
|
262 | - ], |
|
263 | - '#2234', |
|
264 | - '/a', |
|
265 | - '/li', |
|
266 | - '/ul' |
|
267 | - ]; |
|
268 | - $result = $this->_Parser->parse($input); |
|
269 | - $this->assertTags($result, $expected); |
|
270 | - } |
|
271 | - |
|
272 | - public function testHashLinkFailure() { |
|
273 | - // don't hash code |
|
274 | - $input = '[code]#2234[/code]'; |
|
275 | - $result = $this->_Parser->parse($input); |
|
276 | - $this->assertNotContains('>#2234</a>', $result); |
|
277 | - |
|
278 | - // not a valid hash |
|
279 | - $input = '#2234t'; |
|
280 | - $result = $this->_Parser->parse($input); |
|
281 | - $this->assertEquals('#2234t', $result); |
|
282 | - } |
|
283 | - |
|
284 | - public function testAtLinkKnownUsers() { |
|
285 | - $input = '@Alice @Bob @Bobby Junior @Bobby Tables @Dr. No'; |
|
286 | - $expected = |
|
287 | - "<a href='/at/Alice'>@Alice</a>" . |
|
288 | - " @Bob " . |
|
289 | - "<a href='/at/Bobby+Junior'>@Bobby Junior</a>" . |
|
290 | - " @Bobby Tables " . |
|
291 | - "<a href='/at/Dr.+No'>@Dr. No</a>"; |
|
292 | - |
|
293 | - $result = $this->_Parser->parse($input); |
|
294 | - $this->assertEquals($expected, $result, '@User string is not replaced with link to user profile.'); |
|
295 | - |
|
296 | - $input = '[code]@Alice[/code]'; |
|
297 | - $result = $this->_Parser->parse($input); |
|
298 | - $this->assertNotContains('>@Alice</a>', $result); |
|
299 | - } |
|
300 | - |
|
301 | - public function testAtLinkKnownUsersLinebreak() { |
|
302 | - $input = "@Alice\nfoo"; |
|
303 | - $result = $this->_Parser->parse($input); |
|
304 | - $expected = [ |
|
305 | - 'a' => ['href' => '/at/Alice'], |
|
306 | - '@Alice', |
|
307 | - '/a', |
|
308 | - 'br' => true |
|
309 | - ]; |
|
310 | - $this->assertTags($result, $expected); |
|
311 | - } |
|
312 | - |
|
313 | - public function testLinkEmptyUrl() { |
|
314 | - $input = '[url=][/url]'; |
|
315 | - $expected = "<a href=''></a>"; |
|
316 | - $result = $this->_Parser->parse($input); |
|
317 | - $this->assertEquals($expected, $result); |
|
318 | - } |
|
319 | - |
|
320 | - public function testEditMarker() { |
|
321 | - $input = 'pre [e] post'; |
|
322 | - $expected = [ |
|
323 | - 'pre ', |
|
324 | - 'span' => [ |
|
325 | - 'class' => 'richtext-editMark' |
|
326 | - ], |
|
327 | - '/span', |
|
328 | - ' post' |
|
329 | - ]; |
|
330 | - $result = $this->_Parser->parse($input); |
|
331 | - $this->assertTags($result, $expected); |
|
332 | - } |
|
333 | - |
|
334 | - /* |
|
3 | + use Plugin\BbcodeParser\Lib; |
|
4 | + use Saito\User\Userlist; |
|
5 | + |
|
6 | + App::import('Lib', 'Stopwatch.Stopwatch'); |
|
7 | + App::import('Helper', |
|
8 | + array( |
|
9 | + 'FileUpload.FileUpload', |
|
10 | + 'CakephpGeshi.Geshi', |
|
11 | + )); |
|
12 | + App::import('Helper', 'MailObfuscator.MailObfuscator'); |
|
13 | + |
|
14 | + App::uses('Controller', 'Controller'); |
|
15 | + App::uses('View', 'View'); |
|
16 | + App::uses('ParserHelper', 'View/Helper'); |
|
17 | + App::uses('HtmlHelper', 'View/Helper'); |
|
18 | + App::uses('CakeRequest', 'Network'); |
|
19 | + |
|
20 | + class BbcodeParserTest extends CakeTestCase { |
|
21 | + |
|
22 | + protected $_Parser = null; |
|
23 | + |
|
24 | + public function testBold() { |
|
25 | + $input = '[b]bold[/b]'; |
|
26 | + $expected = array('strong' => array(), 'bold', '/strong'); |
|
27 | + $result = $this->_Parser->parse($input); |
|
28 | + $this->assertTags($result, $expected); |
|
29 | + } |
|
30 | + |
|
31 | + public function testQuoteblock() { |
|
32 | + $input = '[quote]foo bar[/quote]'; |
|
33 | + $expected = array('blockquote' => array(), 'foo bar', '/blockquote'); |
|
34 | + $result = $this->_Parser->parse($input); |
|
35 | + $this->assertTags($result, $expected); |
|
36 | + } |
|
37 | + |
|
38 | + public function testEmphasis() { |
|
39 | + $input = '[i]italic[/i]'; |
|
40 | + $expected = array('em' => array(), 'italic', '/em'); |
|
41 | + $result = $this->_Parser->parse($input); |
|
42 | + $this->assertTags($result, $expected); |
|
43 | + } |
|
44 | + |
|
45 | + public function testStrike() { |
|
46 | + $expected = ['del' => [], 'text', '/del']; |
|
47 | + |
|
48 | + // [strike] |
|
49 | + $input = '[strike]text[/strike]'; |
|
50 | + $result = $this->_Parser->parse($input); |
|
51 | + $this->assertTags($result, $expected); |
|
52 | + |
|
53 | + // [s] |
|
54 | + $input = '[s]text[/s]'; |
|
55 | + $result = $this->_Parser->parse($input); |
|
56 | + $this->assertTags($result, $expected); |
|
57 | + } |
|
58 | + |
|
59 | + public function testSpoiler() { |
|
60 | + $input = 'pre [spoiler] te "\' xt[/spoiler]'; |
|
61 | + $expected = [ |
|
62 | + 'pre', |
|
63 | + [ |
|
64 | + 'div' => [ |
|
65 | + 'class' => 'richtext-spoiler', |
|
66 | + 'style' => 'display: inline;' |
|
67 | + ] |
|
68 | + ], |
|
69 | + ['script' => true], |
|
70 | + 'preg:/(.*?)"string":" te "' xt"(.*?)(?=<)/', |
|
71 | + '/script', |
|
72 | + [ |
|
73 | + 'a' => [ |
|
74 | + 'href' => '#', |
|
75 | + 'class' => 'richtext-spoiler-link', |
|
76 | + 'onclick' |
|
77 | + ] |
|
78 | + ], |
|
79 | + 'preg:/.*▇ Spoiler ▇.*?(?=<)/', |
|
80 | + '/a', |
|
81 | + '/div' |
|
82 | + ]; |
|
83 | + $result = $this->_Parser->parse($input); |
|
84 | + $this->assertTags($result, $expected, true); |
|
85 | + } |
|
86 | + |
|
87 | + public function testList() { |
|
88 | + $input = "[list]\n[*]fooo\n[*]bar\n[/list]"; |
|
89 | + $expected = [ |
|
90 | + ['ul' => []], |
|
91 | + ['li' => []], |
|
92 | + 'fooo', |
|
93 | + ['br' => []], |
|
94 | + '/li', |
|
95 | + ['li' => []], |
|
96 | + 'bar', |
|
97 | + ['br' => []], |
|
98 | + '/li', |
|
99 | + '/ul' |
|
100 | + ]; |
|
101 | + $result = $this->_Parser->parse($input); |
|
102 | + $this->assertTags($result, $expected); |
|
103 | + } |
|
104 | + |
|
105 | + public function testMaskLinkWithoutProtocol() { |
|
106 | + $input = '[url=thetempe.st/station]purge[/url]'; |
|
107 | + $expected = [ |
|
108 | + 'a' => [ |
|
109 | + 'href' => 'http://thetempe.st/station', |
|
110 | + 'rel' => 'external', |
|
111 | + 'target' => '_blank' |
|
112 | + ], |
|
113 | + 'purge', |
|
114 | + '/a' |
|
115 | + ]; |
|
116 | + $result = $this->_Parser->parse($input); |
|
117 | + $this->assertTags($result, $expected); |
|
118 | + } |
|
119 | + |
|
120 | + public function testParserEngineCaching() { |
|
121 | + $input = '[img=]foo.png[/img]'; |
|
122 | + $result = $this->_Parser->parse($input, ['multimedia' => true]); |
|
123 | + $this->assertContains('<img src', $result); |
|
124 | + $result = $this->_Parser->parse($input, ['multimedia' => false]); |
|
125 | + $this->assertNotContains('<img src', $result); |
|
126 | + } |
|
127 | + |
|
128 | + public function testLink() { |
|
129 | + $input = '[url=http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250678480561&ssPageName=ADME:X:RTQ:DE:1123]test[/url]'; |
|
130 | + $expected = "<a href='http://cgi.ebay.de/ws/eBayISAPI.dll?ViewItem&item=250678480561&ssPageName=ADME:X:RTQ:DE:1123' rel='external' target='_blank'>test</a> <span class='richtext-linkInfo'>[ebay.de]</span>"; |
|
131 | + $result = $this->_Parser->parse($input); |
|
132 | + $this->assertEquals($expected, $result); |
|
133 | + |
|
134 | + /** |
|
135 | + * external server |
|
136 | + */ |
|
137 | + $input = '[url]http://heise.de/foobar[/url]'; |
|
138 | + $expected = array( |
|
139 | + 'a' => array( |
|
140 | + 'href' => 'http://heise.de/foobar', |
|
141 | + 'rel' => 'external', |
|
142 | + 'target' => '_blank' |
|
143 | + ), |
|
144 | + 'http://heise.de/foobar', |
|
145 | + '/a' |
|
146 | + ); |
|
147 | + $result = $this->_Parser->parse($input); |
|
148 | + $this->assertTags($result, $expected); |
|
149 | + |
|
150 | + $input = '[link]http://heise.de/foobar[/link]'; |
|
151 | + $expected = array( |
|
152 | + 'a' => array( |
|
153 | + 'href' => 'http://heise.de/foobar', |
|
154 | + 'rel' => 'external', |
|
155 | + 'target' => '_blank' |
|
156 | + ), |
|
157 | + 'http://heise.de/foobar', |
|
158 | + '/a' |
|
159 | + ); |
|
160 | + $result = $this->_Parser->parse($input); |
|
161 | + $this->assertTags($result, $expected); |
|
162 | + |
|
163 | + // masked link |
|
164 | + $input = '[url=http://heise.de/foobar]foobar[/url]'; |
|
165 | + $expected = array( |
|
166 | + 'a' => array( |
|
167 | + 'href' => 'http://heise.de/foobar', |
|
168 | + 'rel' => 'external', |
|
169 | + 'target' => '_blank' |
|
170 | + ), |
|
171 | + 'foobar', |
|
172 | + '/a', |
|
173 | + 'span' => array('class' => 'richtext-linkInfo'), '[heise.de]', '/span' |
|
174 | + ); |
|
175 | + $result = $this->_Parser->parse($input); |
|
176 | + $this->assertTags($result, $expected); |
|
177 | + |
|
178 | + // masked link with no label |
|
179 | + $input = '[url=http://heise.de/foobar label=none ]foobar[/url]'; |
|
180 | + $expected = array( |
|
181 | + 'a' => array( |
|
182 | + 'href' => 'http://heise.de/foobar', |
|
183 | + 'rel' => 'external', |
|
184 | + 'target' => '_blank', |
|
185 | + ), |
|
186 | + 'foobar', |
|
187 | + '/a', |
|
188 | + ); |
|
189 | + $result = $this->_Parser->parse($input); |
|
190 | + $this->assertTags($result, $expected); |
|
191 | + |
|
192 | + /** |
|
193 | + * local server |
|
194 | + */ |
|
195 | + $input = '[url=http://macnemo.de/foobar]foobar[/url]'; |
|
196 | + $expected = "<a href='http://macnemo.de/foobar'>foobar</a>"; |
|
197 | + $result = $this->_Parser->parse($input); |
|
198 | + $this->assertEquals($expected, $result); |
|
199 | + |
|
200 | + $input = '[url]/foobar[/url]'; |
|
201 | + $expected = array( |
|
202 | + 'a' => array( |
|
203 | + 'href' => '/foobar', |
|
204 | + ), |
|
205 | + 'preg:/\/foobar/', |
|
206 | + '/a', |
|
207 | + ); |
|
208 | + $result = $this->_Parser->parse($input); |
|
209 | + $this->assertTags($result, $expected); |
|
210 | + |
|
211 | + // test lokaler server with absolute url |
|
212 | + $input = '[url=/foobar]foobar[/url]'; |
|
213 | + $expected = "<a href='/foobar'>foobar</a>"; |
|
214 | + $result = $this->_Parser->parse($input); |
|
215 | + $this->assertEquals($expected, $result); |
|
216 | + |
|
217 | + // test 'http://' only |
|
218 | + $input = '[url=http://]foobar[/url]'; |
|
219 | + $expected = "<a href='http://'>foobar</a>"; |
|
220 | + $result = $this->_Parser->parse($input); |
|
221 | + $this->assertEquals($expected, $result); |
|
222 | + |
|
223 | + // test for co.uk |
|
224 | + $input = '[url=http://heise.co.uk/foobar]foobar[/url]'; |
|
225 | + $expected = array( |
|
226 | + 'a' => array( |
|
227 | + 'href' => 'http://heise.co.uk/foobar', |
|
228 | + 'rel' => 'external', |
|
229 | + 'target' => '_blank' |
|
230 | + ), |
|
231 | + 'foobar', |
|
232 | + '/a', |
|
233 | + 'span' => array('class' => 'richtext-linkInfo'), '[heise.co.uk]', |
|
234 | + '/span' |
|
235 | + ); |
|
236 | + $result = $this->_Parser->parse($input); |
|
237 | + $this->assertTags($result, $expected); |
|
238 | + } |
|
239 | + |
|
240 | + public function testHashLinkSuccess() { |
|
241 | + // inline content ([i]) |
|
242 | + $input = "[i]#2234[/i]"; |
|
243 | + $expected = [ |
|
244 | + 'em' => [], |
|
245 | + 'a' => [ |
|
246 | + 'href' => '/hash/2234' |
|
247 | + ], |
|
248 | + '#2234', |
|
249 | + '/a', |
|
250 | + '/em' |
|
251 | + ]; |
|
252 | + $result = $this->_Parser->parse($input); |
|
253 | + $this->assertTags($result, $expected); |
|
254 | + |
|
255 | + // lists |
|
256 | + $input = "[list][*]#2234[/list]"; |
|
257 | + $expected = [ |
|
258 | + 'ul' => true, |
|
259 | + 'li' => true, |
|
260 | + 'a' => [ |
|
261 | + 'href' => '/hash/2234' |
|
262 | + ], |
|
263 | + '#2234', |
|
264 | + '/a', |
|
265 | + '/li', |
|
266 | + '/ul' |
|
267 | + ]; |
|
268 | + $result = $this->_Parser->parse($input); |
|
269 | + $this->assertTags($result, $expected); |
|
270 | + } |
|
271 | + |
|
272 | + public function testHashLinkFailure() { |
|
273 | + // don't hash code |
|
274 | + $input = '[code]#2234[/code]'; |
|
275 | + $result = $this->_Parser->parse($input); |
|
276 | + $this->assertNotContains('>#2234</a>', $result); |
|
277 | + |
|
278 | + // not a valid hash |
|
279 | + $input = '#2234t'; |
|
280 | + $result = $this->_Parser->parse($input); |
|
281 | + $this->assertEquals('#2234t', $result); |
|
282 | + } |
|
283 | + |
|
284 | + public function testAtLinkKnownUsers() { |
|
285 | + $input = '@Alice @Bob @Bobby Junior @Bobby Tables @Dr. No'; |
|
286 | + $expected = |
|
287 | + "<a href='/at/Alice'>@Alice</a>" . |
|
288 | + " @Bob " . |
|
289 | + "<a href='/at/Bobby+Junior'>@Bobby Junior</a>" . |
|
290 | + " @Bobby Tables " . |
|
291 | + "<a href='/at/Dr.+No'>@Dr. No</a>"; |
|
292 | + |
|
293 | + $result = $this->_Parser->parse($input); |
|
294 | + $this->assertEquals($expected, $result, '@User string is not replaced with link to user profile.'); |
|
295 | + |
|
296 | + $input = '[code]@Alice[/code]'; |
|
297 | + $result = $this->_Parser->parse($input); |
|
298 | + $this->assertNotContains('>@Alice</a>', $result); |
|
299 | + } |
|
300 | + |
|
301 | + public function testAtLinkKnownUsersLinebreak() { |
|
302 | + $input = "@Alice\nfoo"; |
|
303 | + $result = $this->_Parser->parse($input); |
|
304 | + $expected = [ |
|
305 | + 'a' => ['href' => '/at/Alice'], |
|
306 | + '@Alice', |
|
307 | + '/a', |
|
308 | + 'br' => true |
|
309 | + ]; |
|
310 | + $this->assertTags($result, $expected); |
|
311 | + } |
|
312 | + |
|
313 | + public function testLinkEmptyUrl() { |
|
314 | + $input = '[url=][/url]'; |
|
315 | + $expected = "<a href=''></a>"; |
|
316 | + $result = $this->_Parser->parse($input); |
|
317 | + $this->assertEquals($expected, $result); |
|
318 | + } |
|
319 | + |
|
320 | + public function testEditMarker() { |
|
321 | + $input = 'pre [e] post'; |
|
322 | + $expected = [ |
|
323 | + 'pre ', |
|
324 | + 'span' => [ |
|
325 | + 'class' => 'richtext-editMark' |
|
326 | + ], |
|
327 | + '/span', |
|
328 | + ' post' |
|
329 | + ]; |
|
330 | + $result = $this->_Parser->parse($input); |
|
331 | + $this->assertTags($result, $expected); |
|
332 | + } |
|
333 | + |
|
334 | + /* |
|
335 | 335 | * without obfuscator |
336 | 336 | * |
337 | 337 | public function testEmail() { |
@@ -362,697 +362,697 @@ discard block |
||
362 | 362 | } |
363 | 363 | */ |
364 | 364 | |
365 | - public function testEmailMailto() { |
|
366 | - $MO = $this->getMock('MailObfuscator', array('link')); |
|
367 | - $MO->expects($this->once(4)) |
|
368 | - ->method('link') |
|
369 | - ->with('[email protected]', null); |
|
370 | - $this->_Helper->MailObfuscator = $MO; |
|
371 | - |
|
372 | - $input = '[email]mailto:[email protected][/email]'; |
|
373 | - $this->_Parser->parse($input); |
|
374 | - } |
|
375 | - |
|
376 | - public function testEmailMailtoMask() { |
|
377 | - $MO = $this->getMock('MailObfuscator', array('link')); |
|
378 | - $MO->expects($this->once(4)) |
|
379 | - ->method('link') |
|
380 | - ->with('[email protected]', 'Mail'); |
|
381 | - $this->_Helper->MailObfuscator = $MO; |
|
382 | - |
|
383 | - $input = '[email=mailto:[email protected]]Mail[/email]'; |
|
384 | - $this->_Parser->parse($input); |
|
385 | - } |
|
386 | - |
|
387 | - public function testEmailNoMailto() { |
|
388 | - $MO = $this->getMock('MailObfuscator', array('link')); |
|
389 | - $MO->expects($this->once(4)) |
|
390 | - ->method('link') |
|
391 | - ->with('[email protected]', null); |
|
392 | - $this->_Helper->MailObfuscator = $MO; |
|
393 | - |
|
394 | - $input = '[email][email protected][/email]'; |
|
395 | - $this->_Parser->parse($input); |
|
396 | - } |
|
397 | - |
|
398 | - public function testEmailNoMailtoMask() { |
|
399 | - $MO = $this->getMock('MailObfuscator', array('link')); |
|
400 | - $MO->expects($this->once(4)) |
|
401 | - ->method('link') |
|
402 | - ->with('[email protected]', 'Mail'); |
|
403 | - $this->_Helper->MailObfuscator = $MO; |
|
404 | - |
|
405 | - $input = '[[email protected]]Mail[/email]'; |
|
406 | - $this->_Parser->parse($input); |
|
407 | - } |
|
408 | - |
|
409 | - public function testFlash() { |
|
410 | - $bbcode = '[flash_video]//www.youtube.com/v/MrBRPYlrGF8?version=3&hl=en_US|560|315[/flash_video]'; |
|
411 | - $expected = <<<EOF |
|
365 | + public function testEmailMailto() { |
|
366 | + $MO = $this->getMock('MailObfuscator', array('link')); |
|
367 | + $MO->expects($this->once(4)) |
|
368 | + ->method('link') |
|
369 | + ->with('[email protected]', null); |
|
370 | + $this->_Helper->MailObfuscator = $MO; |
|
371 | + |
|
372 | + $input = '[email]mailto:[email protected][/email]'; |
|
373 | + $this->_Parser->parse($input); |
|
374 | + } |
|
375 | + |
|
376 | + public function testEmailMailtoMask() { |
|
377 | + $MO = $this->getMock('MailObfuscator', array('link')); |
|
378 | + $MO->expects($this->once(4)) |
|
379 | + ->method('link') |
|
380 | + ->with('[email protected]', 'Mail'); |
|
381 | + $this->_Helper->MailObfuscator = $MO; |
|
382 | + |
|
383 | + $input = '[email=mailto:[email protected]]Mail[/email]'; |
|
384 | + $this->_Parser->parse($input); |
|
385 | + } |
|
386 | + |
|
387 | + public function testEmailNoMailto() { |
|
388 | + $MO = $this->getMock('MailObfuscator', array('link')); |
|
389 | + $MO->expects($this->once(4)) |
|
390 | + ->method('link') |
|
391 | + ->with('[email protected]', null); |
|
392 | + $this->_Helper->MailObfuscator = $MO; |
|
393 | + |
|
394 | + $input = '[email][email protected][/email]'; |
|
395 | + $this->_Parser->parse($input); |
|
396 | + } |
|
397 | + |
|
398 | + public function testEmailNoMailtoMask() { |
|
399 | + $MO = $this->getMock('MailObfuscator', array('link')); |
|
400 | + $MO->expects($this->once(4)) |
|
401 | + ->method('link') |
|
402 | + ->with('[email protected]', 'Mail'); |
|
403 | + $this->_Helper->MailObfuscator = $MO; |
|
404 | + |
|
405 | + $input = '[[email protected]]Mail[/email]'; |
|
406 | + $this->_Parser->parse($input); |
|
407 | + } |
|
408 | + |
|
409 | + public function testFlash() { |
|
410 | + $bbcode = '[flash_video]//www.youtube.com/v/MrBRPYlrGF8?version=3&hl=en_US|560|315[/flash_video]'; |
|
411 | + $expected = <<<EOF |
|
412 | 412 | <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="560" height="315"> |
413 | 413 | <param name="movie" value="//www.youtube.com/v/MrBRPYlrGF8?version=3&amp;hl=en_US"></param> |
414 | 414 | <embed src="//www.youtube.com/v/MrBRPYlrGF8?version=3&amp;hl=en_US" width="560" height="315" type="application/x-shockwave-flash" wmode="opaque" style="width:560px; height:315px;" id="VideoPlayback" flashvars=""> </embed> </object> |
415 | 415 | EOF; |
416 | - $actual = $this->_Parser->parse($bbcode, ['video_domains_allowed' => 'youtube']); |
|
417 | - $this->assertEquals(trim($expected), trim($actual)); |
|
418 | - } |
|
419 | - |
|
420 | - public function testFloat() { |
|
421 | - $expected = [ |
|
422 | - ['div' => ['class' => 'clearfix']], |
|
423 | - '/div', |
|
424 | - ['div' => ['class' => 'richtext-float']], |
|
425 | - 'text', |
|
426 | - '/div', |
|
427 | - 'more' |
|
428 | - ]; |
|
429 | - |
|
430 | - $input = '[float]text[/float]more'; |
|
431 | - $result = $this->_Parser->parse($input); |
|
432 | - $this->assertTags($result, $expected); |
|
433 | - } |
|
434 | - |
|
435 | - public function testLinkAuto() { |
|
436 | - $input = 'http://heise.de/foobar'; |
|
437 | - $expected = "<a href='http://heise.de/foobar' rel='external' target='_blank'>http://heise.de/foobar</a>"; |
|
438 | - $result = $this->_Parser->parse($input); |
|
439 | - $this->assertEquals($expected, $result); |
|
440 | - |
|
441 | - // autolink surrounded by text |
|
442 | - $input = 'some http://heise.de/foobar text'; |
|
443 | - $expected = "some <a href='http://heise.de/foobar' rel='external' target='_blank'>http://heise.de/foobar</a> text"; |
|
444 | - $result = $this->_Parser->parse($input); |
|
445 | - $this->assertEquals($expected, $result); |
|
446 | - |
|
447 | - // no autolink in [code] |
|
448 | - $input = '[code]http://heise.de/foobar[/code]'; |
|
449 | - $needle = 'heise.de/foobar</a>'; |
|
450 | - $result = $this->_Parser->parse($input); |
|
451 | - $this->assertNotContains($result, $needle); |
|
452 | - |
|
453 | - // no autolink in [url] |
|
454 | - $input = '[url=http://a.com/]http://b.de/[/url]'; |
|
455 | - $result = $this->_Parser->parse($input); |
|
456 | - $this->assertRegExp('#href=["\']http://a.com/["\'][^>]*?>http://b.de/#', $result); |
|
457 | - |
|
458 | - // email autolink |
|
459 | - $input = 'text [email protected] test'; |
|
460 | - // $expected = "text <a href='mailto:[email protected]'>[email protected]</a> test"; |
|
461 | - $result = $this->_Parser->parse($input); |
|
462 | - // $this->assertEquals($expected, $result); |
|
463 | - // @bogus weak test |
|
464 | - $this->assertRegExp('/^text .*href=".* test$/sm', $result); |
|
465 | - |
|
466 | - //# in list |
|
467 | - $input = <<<EOF |
|
416 | + $actual = $this->_Parser->parse($bbcode, ['video_domains_allowed' => 'youtube']); |
|
417 | + $this->assertEquals(trim($expected), trim($actual)); |
|
418 | + } |
|
419 | + |
|
420 | + public function testFloat() { |
|
421 | + $expected = [ |
|
422 | + ['div' => ['class' => 'clearfix']], |
|
423 | + '/div', |
|
424 | + ['div' => ['class' => 'richtext-float']], |
|
425 | + 'text', |
|
426 | + '/div', |
|
427 | + 'more' |
|
428 | + ]; |
|
429 | + |
|
430 | + $input = '[float]text[/float]more'; |
|
431 | + $result = $this->_Parser->parse($input); |
|
432 | + $this->assertTags($result, $expected); |
|
433 | + } |
|
434 | + |
|
435 | + public function testLinkAuto() { |
|
436 | + $input = 'http://heise.de/foobar'; |
|
437 | + $expected = "<a href='http://heise.de/foobar' rel='external' target='_blank'>http://heise.de/foobar</a>"; |
|
438 | + $result = $this->_Parser->parse($input); |
|
439 | + $this->assertEquals($expected, $result); |
|
440 | + |
|
441 | + // autolink surrounded by text |
|
442 | + $input = 'some http://heise.de/foobar text'; |
|
443 | + $expected = "some <a href='http://heise.de/foobar' rel='external' target='_blank'>http://heise.de/foobar</a> text"; |
|
444 | + $result = $this->_Parser->parse($input); |
|
445 | + $this->assertEquals($expected, $result); |
|
446 | + |
|
447 | + // no autolink in [code] |
|
448 | + $input = '[code]http://heise.de/foobar[/code]'; |
|
449 | + $needle = 'heise.de/foobar</a>'; |
|
450 | + $result = $this->_Parser->parse($input); |
|
451 | + $this->assertNotContains($result, $needle); |
|
452 | + |
|
453 | + // no autolink in [url] |
|
454 | + $input = '[url=http://a.com/]http://b.de/[/url]'; |
|
455 | + $result = $this->_Parser->parse($input); |
|
456 | + $this->assertRegExp('#href=["\']http://a.com/["\'][^>]*?>http://b.de/#', $result); |
|
457 | + |
|
458 | + // email autolink |
|
459 | + $input = 'text [email protected] test'; |
|
460 | + // $expected = "text <a href='mailto:[email protected]'>[email protected]</a> test"; |
|
461 | + $result = $this->_Parser->parse($input); |
|
462 | + // $this->assertEquals($expected, $result); |
|
463 | + // @bogus weak test |
|
464 | + $this->assertRegExp('/^text .*href=".* test$/sm', $result); |
|
465 | + |
|
466 | + //# in list |
|
467 | + $input = <<<EOF |
|
468 | 468 | [list] |
469 | 469 | [*] http://heise.de |
470 | 470 | [/list] |
471 | 471 | EOF; |
472 | - $result = $this->_Parser->parse($input); |
|
473 | - $expected = "<a href='http://heise.de"; |
|
474 | - $this->assertTextContains($expected, $result); |
|
475 | - } |
|
476 | - |
|
477 | - public function testLinkAutoWithoutHttpPrefix() { |
|
478 | - $input = 'some www.example.com/foobar text'; |
|
479 | - $expected = [ |
|
480 | - 'some ', |
|
481 | - 'a' => [ |
|
482 | - 'href' => 'http://www.example.com/foobar', |
|
483 | - 'rel' => 'external', |
|
484 | - 'target' => '_blank', |
|
485 | - ], |
|
486 | - 'http://www.example.com/foobar', |
|
487 | - '/a', |
|
488 | - ' text' |
|
489 | - ]; |
|
490 | - $result = $this->_Parser->parse($input); |
|
491 | - $this->assertTags($result, $expected); |
|
492 | - } |
|
493 | - |
|
494 | - public function testLinkAutoUrlWithinParentheses() { |
|
495 | - $input = 'some (www.example.com/foobar) text'; |
|
496 | - $expected = [ |
|
497 | - 'some (', |
|
498 | - 'a' => [ |
|
499 | - 'href' => 'http://www.example.com/foobar', |
|
500 | - 'rel' => 'external', |
|
501 | - 'target' => '_blank', |
|
502 | - ], |
|
503 | - 'http://www.example.com/foobar', |
|
504 | - '/a', |
|
505 | - ') text' |
|
506 | - ]; |
|
507 | - $result = $this->_Parser->parse($input); |
|
508 | - $this->assertTags($result, $expected); |
|
509 | - } |
|
510 | - |
|
511 | - public function testLinkAutoSurroundingChars() { |
|
512 | - $input = 'text http://example.com/?foo,,, text'; |
|
513 | - $result = $this->_Parser->parse($input); |
|
514 | - $expected = [ |
|
515 | - 'text ', |
|
516 | - 'a' => [ |
|
517 | - 'href' => 'http://example.com/?foo,,', |
|
518 | - 'rel' => 'external', |
|
519 | - 'target' => '_blank', |
|
520 | - ], |
|
521 | - 'http://example.com/?foo,,', |
|
522 | - '/a', |
|
523 | - ', text' |
|
524 | - ]; |
|
525 | - $this->assertTags($result, $expected); |
|
526 | - |
|
527 | - // Question mark |
|
528 | - $input = 'question http://example.com/? Text'; |
|
529 | - $result = $this->_Parser->parse($input); |
|
530 | - $expected = [ |
|
531 | - 'question ', |
|
532 | - 'a' => [ |
|
533 | - 'href' => 'http://example.com/', |
|
534 | - 'rel' => 'external', |
|
535 | - 'target' => '_blank', |
|
536 | - ], |
|
537 | - 'http://example.com/', |
|
538 | - '/a', |
|
539 | - '? Text' |
|
540 | - ]; |
|
541 | - $this->assertTags($result, $expected); |
|
542 | - |
|
543 | - // No Question mark but url |
|
544 | - $input = 'no question http://example.com/?foo=bar text'; |
|
545 | - $result = $this->_Parser->parse($input); |
|
546 | - $expected = [ |
|
547 | - 'no question ', |
|
548 | - 'a' => [ |
|
549 | - 'href' => 'http://example.com/?foo=bar', |
|
550 | - 'rel' => 'external', |
|
551 | - 'target' => '_blank', |
|
552 | - ], |
|
553 | - 'http://example.com/?foo=bar', |
|
554 | - '/a', |
|
555 | - ' text' |
|
556 | - ]; |
|
557 | - $this->assertTags($result, $expected); |
|
558 | - } |
|
559 | - |
|
560 | - public function testReturnText() { |
|
561 | - $in = 'test [b]test[b] test'; |
|
562 | - $expected = 'test test test'; |
|
563 | - $actual = $this->_Parser->parse($in, ['return' => 'text']); |
|
564 | - $this->assertEquals($expected, $actual); |
|
565 | - } |
|
566 | - |
|
567 | - public function testShortenLink() { |
|
568 | - $maxLength = 15; |
|
569 | - |
|
570 | - $input = '[url]http://this/url/is/32/chars/long[/url]'; |
|
571 | - $expected = "<a href='http://this/url/is/32/chars/long' rel='external' target='_blank'>http:// … /long</a>"; |
|
572 | - $result = $this->_Parser->parse($input, ['text_word_maxlength' => $maxLength]); |
|
573 | - $this->assertEquals($expected, $result); |
|
574 | - |
|
575 | - $input = 'http://this/url/is/32/chars/long'; |
|
576 | - $expected = "<a href='http://this/url/is/32/chars/long' rel='external' target='_blank'>http:// … /long</a>"; |
|
577 | - $result = $this->_Parser->parse($input, ['text_word_maxlength' => $maxLength]); |
|
578 | - $this->assertEquals($expected, $result); |
|
579 | - } |
|
580 | - |
|
581 | - public function testIframe() { |
|
582 | - //* test allowed domain |
|
583 | - $input = '[iframe height=349 width=560 ' . |
|
584 | - 'src=http://www.youtube.com/embed/HdoW3t_WorU ' . |
|
585 | - 'frameborder=0][/iframe]'; |
|
586 | - $expected = [ |
|
587 | - ['iframe' => [ |
|
588 | - 'src' => 'http://www.youtube.com/embed/HdoW3t_WorU?&wmode=Opaque', |
|
589 | - 'height' => '349', |
|
590 | - 'width' => '560', |
|
591 | - 'frameborder' => '0'] |
|
592 | - ], |
|
593 | - '/iframe', |
|
594 | - ]; |
|
595 | - $result = $this->_Parser->parse($input, ['video_domains_allowed' => 'youtube | vimeo']); |
|
596 | - $this->assertTags($result, $expected); |
|
597 | - |
|
598 | - //* test forbidden domains |
|
599 | - $input = '[iframe height=349 width=560 ' . |
|
600 | - 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
601 | - 'frameborder=0][/iframe]'; |
|
602 | - $expected = '/src/i'; |
|
603 | - $result = $this->_Parser->parse($input, ['video_domains_allowed' => 'youtube | vimeo']); |
|
604 | - $this->assertNoPattern($expected, $result); |
|
605 | - } |
|
606 | - |
|
607 | - public function testIframeAllDomainsAllowed() { |
|
608 | - $input = '[iframe height=349 width=560 ' . |
|
609 | - 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
610 | - '][/iframe]'; |
|
611 | - $expected = 'src="http://www.youtubescam.com/embed/HdoW3t_WorU'; |
|
612 | - $result = $this->_Parser->parse($input, ['video_domains_allowed' => '*']); |
|
613 | - $this->assertContains($expected, $result); |
|
614 | - } |
|
615 | - |
|
616 | - public function testIframeNoDomainAllowed() { |
|
617 | - $input = '[iframe height=349 width=560 ' . |
|
618 | - 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
619 | - '][/iframe]'; |
|
620 | - $expected = '/src/i'; |
|
621 | - $result = $this->_Parser->parse($input, ['video_domains_allowed' => '']); |
|
622 | - $this->assertNotRegExp($expected, $result); |
|
623 | - } |
|
624 | - |
|
625 | - public function testExternalImage() { |
|
626 | - $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
627 | - Configure::write('Saito.Settings.bbcode_img', true); |
|
628 | - |
|
629 | - // test for standard URIs |
|
630 | - $input = '[img]http://localhost/img/macnemo.png[/img]'; |
|
631 | - $expected = '<img src="http://localhost/img/macnemo.png" alt=""/>'; |
|
632 | - $result = $this->_Parser->parse($input); |
|
633 | - $this->assertEquals($expected, $result); |
|
634 | - |
|
635 | - // test for URIs without protocol |
|
636 | - $input = '[img]/somewhere/macnemo.png[/img]'; |
|
637 | - $expected = '<img src="' . $this->_Helper->webroot . 'somewhere/macnemo.png" alt=""/>'; |
|
638 | - $result = $this->_Parser->parse($input); |
|
639 | - $this->assertEquals($expected, $result); |
|
640 | - |
|
641 | - // test scaling with 1 parameter |
|
642 | - $input = '[img=50]http://localhost/img/macnemo.png[/img]'; |
|
643 | - $expected = '<img src="http://localhost/img/macnemo.png" width="50" alt=""/>'; |
|
644 | - $result = $this->_Parser->parse($input); |
|
645 | - $this->assertEquals($expected, $result); |
|
646 | - |
|
647 | - // test scaling with 2 parameters |
|
648 | - $input = '[img=50x100]http://localhost/img/macnemo.png[/img]'; |
|
649 | - $expected = '<img src="http://localhost/img/macnemo.png" width="50" height="100" alt=""/>'; |
|
650 | - $result = $this->_Parser->parse($input); |
|
651 | - $this->assertEquals($expected, $result); |
|
652 | - |
|
653 | - // float left |
|
654 | - $input = '[img=left]http://localhost/img/macnemo.png[/img]'; |
|
655 | - $expected = array( |
|
656 | - array('img' => array( |
|
657 | - 'src' => 'http://localhost/img/macnemo.png', |
|
658 | - 'style' => "float: left;", |
|
659 | - 'alt' => "", |
|
660 | - )) |
|
661 | - ); |
|
662 | - $result = $this->_Parser->parse($input); |
|
663 | - $this->assertTags($result, $expected); |
|
664 | - |
|
665 | - // float right |
|
666 | - $input = '[img=right]http://localhost/img/macnemo.png[/img]'; |
|
667 | - $expected = array( |
|
668 | - array('img' => array( |
|
669 | - 'src' => 'http://localhost/img/macnemo.png', |
|
670 | - 'style' => "float: right;", |
|
671 | - 'alt' => "", |
|
672 | - )) |
|
673 | - ); |
|
674 | - $result = $this->_Parser->parse($input); |
|
675 | - $this->assertTags($result, $expected); |
|
676 | - |
|
677 | - Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
678 | - } |
|
679 | - |
|
680 | - public function testImageNestedInExternalLink() { |
|
681 | - $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
682 | - Configure::write('Saito.Settings.bbcode_img', true); |
|
683 | - |
|
684 | - $input = '[url=http://heise.de][img]http://heise.de/img.png[/img][/url]'; |
|
685 | - |
|
686 | - /* |
|
472 | + $result = $this->_Parser->parse($input); |
|
473 | + $expected = "<a href='http://heise.de"; |
|
474 | + $this->assertTextContains($expected, $result); |
|
475 | + } |
|
476 | + |
|
477 | + public function testLinkAutoWithoutHttpPrefix() { |
|
478 | + $input = 'some www.example.com/foobar text'; |
|
479 | + $expected = [ |
|
480 | + 'some ', |
|
481 | + 'a' => [ |
|
482 | + 'href' => 'http://www.example.com/foobar', |
|
483 | + 'rel' => 'external', |
|
484 | + 'target' => '_blank', |
|
485 | + ], |
|
486 | + 'http://www.example.com/foobar', |
|
487 | + '/a', |
|
488 | + ' text' |
|
489 | + ]; |
|
490 | + $result = $this->_Parser->parse($input); |
|
491 | + $this->assertTags($result, $expected); |
|
492 | + } |
|
493 | + |
|
494 | + public function testLinkAutoUrlWithinParentheses() { |
|
495 | + $input = 'some (www.example.com/foobar) text'; |
|
496 | + $expected = [ |
|
497 | + 'some (', |
|
498 | + 'a' => [ |
|
499 | + 'href' => 'http://www.example.com/foobar', |
|
500 | + 'rel' => 'external', |
|
501 | + 'target' => '_blank', |
|
502 | + ], |
|
503 | + 'http://www.example.com/foobar', |
|
504 | + '/a', |
|
505 | + ') text' |
|
506 | + ]; |
|
507 | + $result = $this->_Parser->parse($input); |
|
508 | + $this->assertTags($result, $expected); |
|
509 | + } |
|
510 | + |
|
511 | + public function testLinkAutoSurroundingChars() { |
|
512 | + $input = 'text http://example.com/?foo,,, text'; |
|
513 | + $result = $this->_Parser->parse($input); |
|
514 | + $expected = [ |
|
515 | + 'text ', |
|
516 | + 'a' => [ |
|
517 | + 'href' => 'http://example.com/?foo,,', |
|
518 | + 'rel' => 'external', |
|
519 | + 'target' => '_blank', |
|
520 | + ], |
|
521 | + 'http://example.com/?foo,,', |
|
522 | + '/a', |
|
523 | + ', text' |
|
524 | + ]; |
|
525 | + $this->assertTags($result, $expected); |
|
526 | + |
|
527 | + // Question mark |
|
528 | + $input = 'question http://example.com/? Text'; |
|
529 | + $result = $this->_Parser->parse($input); |
|
530 | + $expected = [ |
|
531 | + 'question ', |
|
532 | + 'a' => [ |
|
533 | + 'href' => 'http://example.com/', |
|
534 | + 'rel' => 'external', |
|
535 | + 'target' => '_blank', |
|
536 | + ], |
|
537 | + 'http://example.com/', |
|
538 | + '/a', |
|
539 | + '? Text' |
|
540 | + ]; |
|
541 | + $this->assertTags($result, $expected); |
|
542 | + |
|
543 | + // No Question mark but url |
|
544 | + $input = 'no question http://example.com/?foo=bar text'; |
|
545 | + $result = $this->_Parser->parse($input); |
|
546 | + $expected = [ |
|
547 | + 'no question ', |
|
548 | + 'a' => [ |
|
549 | + 'href' => 'http://example.com/?foo=bar', |
|
550 | + 'rel' => 'external', |
|
551 | + 'target' => '_blank', |
|
552 | + ], |
|
553 | + 'http://example.com/?foo=bar', |
|
554 | + '/a', |
|
555 | + ' text' |
|
556 | + ]; |
|
557 | + $this->assertTags($result, $expected); |
|
558 | + } |
|
559 | + |
|
560 | + public function testReturnText() { |
|
561 | + $in = 'test [b]test[b] test'; |
|
562 | + $expected = 'test test test'; |
|
563 | + $actual = $this->_Parser->parse($in, ['return' => 'text']); |
|
564 | + $this->assertEquals($expected, $actual); |
|
565 | + } |
|
566 | + |
|
567 | + public function testShortenLink() { |
|
568 | + $maxLength = 15; |
|
569 | + |
|
570 | + $input = '[url]http://this/url/is/32/chars/long[/url]'; |
|
571 | + $expected = "<a href='http://this/url/is/32/chars/long' rel='external' target='_blank'>http:// … /long</a>"; |
|
572 | + $result = $this->_Parser->parse($input, ['text_word_maxlength' => $maxLength]); |
|
573 | + $this->assertEquals($expected, $result); |
|
574 | + |
|
575 | + $input = 'http://this/url/is/32/chars/long'; |
|
576 | + $expected = "<a href='http://this/url/is/32/chars/long' rel='external' target='_blank'>http:// … /long</a>"; |
|
577 | + $result = $this->_Parser->parse($input, ['text_word_maxlength' => $maxLength]); |
|
578 | + $this->assertEquals($expected, $result); |
|
579 | + } |
|
580 | + |
|
581 | + public function testIframe() { |
|
582 | + //* test allowed domain |
|
583 | + $input = '[iframe height=349 width=560 ' . |
|
584 | + 'src=http://www.youtube.com/embed/HdoW3t_WorU ' . |
|
585 | + 'frameborder=0][/iframe]'; |
|
586 | + $expected = [ |
|
587 | + ['iframe' => [ |
|
588 | + 'src' => 'http://www.youtube.com/embed/HdoW3t_WorU?&wmode=Opaque', |
|
589 | + 'height' => '349', |
|
590 | + 'width' => '560', |
|
591 | + 'frameborder' => '0'] |
|
592 | + ], |
|
593 | + '/iframe', |
|
594 | + ]; |
|
595 | + $result = $this->_Parser->parse($input, ['video_domains_allowed' => 'youtube | vimeo']); |
|
596 | + $this->assertTags($result, $expected); |
|
597 | + |
|
598 | + //* test forbidden domains |
|
599 | + $input = '[iframe height=349 width=560 ' . |
|
600 | + 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
601 | + 'frameborder=0][/iframe]'; |
|
602 | + $expected = '/src/i'; |
|
603 | + $result = $this->_Parser->parse($input, ['video_domains_allowed' => 'youtube | vimeo']); |
|
604 | + $this->assertNoPattern($expected, $result); |
|
605 | + } |
|
606 | + |
|
607 | + public function testIframeAllDomainsAllowed() { |
|
608 | + $input = '[iframe height=349 width=560 ' . |
|
609 | + 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
610 | + '][/iframe]'; |
|
611 | + $expected = 'src="http://www.youtubescam.com/embed/HdoW3t_WorU'; |
|
612 | + $result = $this->_Parser->parse($input, ['video_domains_allowed' => '*']); |
|
613 | + $this->assertContains($expected, $result); |
|
614 | + } |
|
615 | + |
|
616 | + public function testIframeNoDomainAllowed() { |
|
617 | + $input = '[iframe height=349 width=560 ' . |
|
618 | + 'src=http://www.youtubescam.com/embed/HdoW3t_WorU ' . |
|
619 | + '][/iframe]'; |
|
620 | + $expected = '/src/i'; |
|
621 | + $result = $this->_Parser->parse($input, ['video_domains_allowed' => '']); |
|
622 | + $this->assertNotRegExp($expected, $result); |
|
623 | + } |
|
624 | + |
|
625 | + public function testExternalImage() { |
|
626 | + $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
627 | + Configure::write('Saito.Settings.bbcode_img', true); |
|
628 | + |
|
629 | + // test for standard URIs |
|
630 | + $input = '[img]http://localhost/img/macnemo.png[/img]'; |
|
631 | + $expected = '<img src="http://localhost/img/macnemo.png" alt=""/>'; |
|
632 | + $result = $this->_Parser->parse($input); |
|
633 | + $this->assertEquals($expected, $result); |
|
634 | + |
|
635 | + // test for URIs without protocol |
|
636 | + $input = '[img]/somewhere/macnemo.png[/img]'; |
|
637 | + $expected = '<img src="' . $this->_Helper->webroot . 'somewhere/macnemo.png" alt=""/>'; |
|
638 | + $result = $this->_Parser->parse($input); |
|
639 | + $this->assertEquals($expected, $result); |
|
640 | + |
|
641 | + // test scaling with 1 parameter |
|
642 | + $input = '[img=50]http://localhost/img/macnemo.png[/img]'; |
|
643 | + $expected = '<img src="http://localhost/img/macnemo.png" width="50" alt=""/>'; |
|
644 | + $result = $this->_Parser->parse($input); |
|
645 | + $this->assertEquals($expected, $result); |
|
646 | + |
|
647 | + // test scaling with 2 parameters |
|
648 | + $input = '[img=50x100]http://localhost/img/macnemo.png[/img]'; |
|
649 | + $expected = '<img src="http://localhost/img/macnemo.png" width="50" height="100" alt=""/>'; |
|
650 | + $result = $this->_Parser->parse($input); |
|
651 | + $this->assertEquals($expected, $result); |
|
652 | + |
|
653 | + // float left |
|
654 | + $input = '[img=left]http://localhost/img/macnemo.png[/img]'; |
|
655 | + $expected = array( |
|
656 | + array('img' => array( |
|
657 | + 'src' => 'http://localhost/img/macnemo.png', |
|
658 | + 'style' => "float: left;", |
|
659 | + 'alt' => "", |
|
660 | + )) |
|
661 | + ); |
|
662 | + $result = $this->_Parser->parse($input); |
|
663 | + $this->assertTags($result, $expected); |
|
664 | + |
|
665 | + // float right |
|
666 | + $input = '[img=right]http://localhost/img/macnemo.png[/img]'; |
|
667 | + $expected = array( |
|
668 | + array('img' => array( |
|
669 | + 'src' => 'http://localhost/img/macnemo.png', |
|
670 | + 'style' => "float: right;", |
|
671 | + 'alt' => "", |
|
672 | + )) |
|
673 | + ); |
|
674 | + $result = $this->_Parser->parse($input); |
|
675 | + $this->assertTags($result, $expected); |
|
676 | + |
|
677 | + Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
678 | + } |
|
679 | + |
|
680 | + public function testImageNestedInExternalLink() { |
|
681 | + $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
682 | + Configure::write('Saito.Settings.bbcode_img', true); |
|
683 | + |
|
684 | + $input = '[url=http://heise.de][img]http://heise.de/img.png[/img][/url]'; |
|
685 | + |
|
686 | + /* |
|
687 | 687 | $expected = "<a href='http://heise.de' rel='external' target='_blank'><img src=\"http://heise.de/img.png\" class=\"external_image\" style=\"\" width=\"auto\" height=\"auto\" alt=\"\" /></a>"; |
688 | 688 | */ |
689 | - $expected = [ |
|
690 | - [ |
|
691 | - 'a' => [ |
|
692 | - 'href' => 'http://heise.de', |
|
693 | - 'rel' => 'external', |
|
694 | - 'target' => '_blank', |
|
695 | - ] |
|
696 | - ], |
|
697 | - [ |
|
698 | - 'img' => [ |
|
699 | - 'src' => 'http://heise.de/img.png', |
|
700 | - 'alt' => '', |
|
701 | - ] |
|
702 | - ], |
|
703 | - '/a' |
|
704 | - ]; |
|
705 | - $result = $this->_Parser->parse($input); |
|
706 | - $this->assertTags($result, $expected); |
|
707 | - |
|
708 | - Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
709 | - } |
|
710 | - |
|
711 | - public function testInternalImage() { |
|
712 | - // Create a map of arguments to return values. |
|
713 | - $map = [ |
|
714 | - ['test.png', [], '<img src="test.png" />'], |
|
715 | - [ |
|
716 | - 'test.png', |
|
717 | - [ |
|
718 | - 'autoResize' => false, |
|
719 | - 'resizeThumbOnly' => false, |
|
720 | - 'width' => '50', |
|
721 | - 'height' => '60', |
|
722 | - ], |
|
723 | - '<img src="test.png" width="50" height="60" alt="">' |
|
724 | - ] |
|
725 | - ]; |
|
726 | - $FileUploader = $this->getMock('FileUploaderHelper', ['image', 'reset']); |
|
727 | - $FileUploader->expects($this->atLeastOnce()) |
|
728 | - ->method('image') |
|
729 | - ->will($this->returnValueMap($map)); |
|
730 | - $this->_Helper->FileUpload = $FileUploader; |
|
731 | - |
|
732 | - // internal image |
|
733 | - $input = '[upload]test.png[/upload]'; |
|
734 | - $expected = [ |
|
735 | - ['img' => ['src' => 'test.png']], |
|
736 | - ]; |
|
737 | - $result = $this->_Parser->parse($input); |
|
738 | - $this->assertTags($result, $expected); |
|
739 | - |
|
740 | - // internal image with attributes |
|
741 | - $input = '[upload width=50 height=60]test.png[/upload]'; |
|
742 | - $expected = array( |
|
743 | - ['img' => |
|
744 | - [ |
|
745 | - 'src' => 'test.png', |
|
746 | - 'width' => '50', |
|
747 | - 'height' => '60', |
|
748 | - 'alt' => '' |
|
749 | - ] |
|
750 | - ] |
|
751 | - ); |
|
752 | - $result = $this->_Parser->parse($input); |
|
753 | - $this->assertTags($result, $expected); |
|
754 | - |
|
755 | - // internal image legacy [img#] tag |
|
756 | - $input = '[img#]test.png[/img]'; |
|
757 | - $expected = [ |
|
758 | - [ |
|
759 | - 'img' => [ |
|
760 | - 'src' => 'test.png', |
|
761 | - ] |
|
762 | - ] |
|
763 | - ]; |
|
764 | - $result = $this->_Parser->parse($input); |
|
765 | - $this->assertTags($result, $expected); |
|
766 | - |
|
767 | - // nested image does not have [domain.info] |
|
768 | - $input = '[url=http://heise.de][upload]test.png[/upload][/url]'; |
|
769 | - $expected = "/richtext-linkInfo/"; |
|
770 | - $result = $this->_Parser->parse($input); |
|
771 | - $this->assertNotRegExp($expected, $result); |
|
772 | - } |
|
773 | - |
|
774 | - public function testSmiliesNoSmiliesInCodeTag() { |
|
775 | - $input = '[code text]:)[/code]'; |
|
776 | - $needle = '<img'; |
|
777 | - $result = $this->_Parser->parse($input, array('cache' => false)); |
|
778 | - $this->assertNotContains($needle, $result); |
|
779 | - } |
|
780 | - |
|
781 | - public function testCodeNestedTags() { |
|
782 | - $input = '[code][b]text[b][/code]'; |
|
783 | - $expected = [ |
|
784 | - [ |
|
785 | - 'div' => ['class' => 'geshi-wrapper'] |
|
786 | - ], |
|
787 | - 'preg:/.*?\[b\]text\[b\].*/', |
|
788 | - ]; |
|
789 | - $result = $this->_Parser->parse($input); |
|
790 | - $this->assertTags($result, $expected); |
|
791 | - } |
|
792 | - |
|
793 | - public function testCodeWhitespace() { |
|
794 | - $input = "[code]\ntest\n[/code]"; |
|
795 | - $expected = "/>test</"; |
|
796 | - $result = $this->_Parser->parse($input); |
|
797 | - $this->assertRegExp($expected, $result); |
|
798 | - } |
|
799 | - |
|
800 | - public function testCodeSimple() { |
|
801 | - $input = '[code]text[/code]'; |
|
802 | - $result = $this->_Parser->parse($input); |
|
803 | - $expected = 'lang="text"'; |
|
804 | - $this->assertContains($expected, $result); |
|
805 | - } |
|
806 | - |
|
807 | - public function testCodeLangAttribute() { |
|
808 | - $input = '[code=php]text[/code]'; |
|
809 | - $result = $this->_Parser->parse($input); |
|
810 | - $expected = 'lang="php"'; |
|
811 | - $this->assertContains($expected, $result); |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * tests that citation marks are not replaced in code-blocks |
|
816 | - */ |
|
817 | - public function testCodeNoCitationMark() { |
|
818 | - // [code]<citation mark>[/code] should not be cited |
|
819 | - $input = h( |
|
820 | - "[code]\n" . $this->_Helper->settings['quote_symbol'] . "\n[/code]" |
|
821 | - ); |
|
822 | - $expected = '`span class=.*?richtext-citation`'; |
|
823 | - $result = $this->_Parser->parse($input); |
|
824 | - $this->assertNotRegExp($expected, $result); |
|
825 | - } |
|
826 | - |
|
827 | - public function testCodeDetaginize() { |
|
828 | - $input = '[code bash]pre http://example.com post[/code]'; |
|
829 | - $result = $this->_Parser->parse($input); |
|
830 | - $this->assertNotContains('autoLink', $result); |
|
831 | - } |
|
832 | - |
|
833 | - public function testQuote() { |
|
834 | - $_qs = h($this->_Helper->settings['quote_symbol']); |
|
835 | - $input = $_qs . ' fo [b]test[/b] ba'; |
|
836 | - $result = $this->_Parser->parse($input); |
|
837 | - $expected = [ |
|
838 | - 'span' => ['class' => 'richtext-citation'], |
|
839 | - $_qs . ' fo ', |
|
840 | - 'strong' => [], |
|
841 | - 'test', |
|
842 | - '/strong', |
|
843 | - ' ba', |
|
844 | - '/span' |
|
845 | - ]; |
|
846 | - $this->assertTags($result, $expected); |
|
847 | - } |
|
848 | - |
|
849 | - public function testHtml5Video() { |
|
850 | - //* setup |
|
851 | - $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
852 | - Configure::write('Saito.Settings.bbcode_img', true); |
|
853 | - |
|
854 | - //* @td write video tests |
|
855 | - $url = 'http://example.com/audio.mp4'; |
|
856 | - $input = "[video]{$url}[/video]"; |
|
857 | - $result = $this->_Parser->parse($input); |
|
858 | - $expected = array( |
|
859 | - 'video' => array('src' => $url, 'controls' => 'controls', |
|
860 | - 'x-webkit-airplay' => 'allow'), |
|
861 | - ); |
|
862 | - $this->assertTags($result, $expected); |
|
863 | - |
|
864 | - //* test autoconversion for audio files |
|
865 | - $html5AudioExtensions = array('m4a', 'ogg', 'mp3', 'wav', 'opus'); |
|
866 | - foreach ($html5AudioExtensions as $extension) { |
|
867 | - $url = 'http://example.com/audio.' . $extension; |
|
868 | - $input = "[video]{$url}[/video]"; |
|
869 | - $result = $this->_Parser->parse($input); |
|
870 | - $expected = array( |
|
871 | - 'audio' => array('src' => $url, 'controls' => 'controls'), |
|
872 | - ); |
|
873 | - $this->assertTags($result, $expected); |
|
874 | - } |
|
875 | - |
|
876 | - //* teardown |
|
877 | - Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
878 | - } |
|
879 | - |
|
880 | - public function testHr() { |
|
881 | - $input = '[hr][hr]'; |
|
882 | - $expected = '<hr><hr>'; |
|
883 | - $result = $this->_Parser->parse($input); |
|
884 | - $this->assertEquals($result, $expected); |
|
885 | - } |
|
886 | - |
|
887 | - public function testHrShort() { |
|
888 | - $input = '[---][---]'; |
|
889 | - $expected = '<hr><hr>'; |
|
890 | - $result = $this->_Parser->parse($input); |
|
891 | - $this->assertEquals($result, $expected); |
|
892 | - } |
|
893 | - |
|
894 | - public function testEmbedlyDisabled() { |
|
895 | - $observer = $this->getMock('Embedly', array('setApiKey', 'embedly')); |
|
896 | - $observer->expects($this->never()) |
|
897 | - ->method('setApiKey'); |
|
898 | - $this->_Helper->Embedly = $observer; |
|
899 | - $input = '[embed]foo[/embed]'; |
|
900 | - $this->_Parser->parse($input); |
|
901 | - } |
|
902 | - |
|
903 | - public function testEmbedlyEnabled() { |
|
904 | - $observer = $this->getMock('Embedly', array('setApiKey', 'embedly')); |
|
905 | - $observer->expects($this->once()) |
|
906 | - ->method('setApiKey') |
|
907 | - ->with($this->equalTo('abc123')); |
|
908 | - $observer->expects($this->once()) |
|
909 | - ->method('embedly') |
|
910 | - ->with($this->equalTo('foo')); |
|
911 | - $this->_Helper->Embedly = $observer; |
|
912 | - $input = '[embed]foo[/embed]'; |
|
913 | - |
|
914 | - $this->_Parser->parse($input, [ |
|
915 | - 'embedly_enabled' => true, |
|
916 | - 'embedly_key' => 'abc123' |
|
917 | - ]); |
|
918 | - } |
|
919 | - |
|
920 | - public function testHtml5Audio() { |
|
921 | - //* setup |
|
922 | - $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
923 | - Configure::write('Saito.Settings.bbcode_img', true); |
|
924 | - |
|
925 | - //* simple test |
|
926 | - $url = 'http://example.com/audio3.m4a'; |
|
927 | - $input = "[audio]{$url}[/audio]"; |
|
928 | - $result = $this->_Parser->parse($input); |
|
929 | - $expected = array( |
|
930 | - 'audio' => array( 'src' => $url, 'controls' => 'controls' ), |
|
931 | - ); |
|
932 | - $this->assertTags($result, $expected); |
|
933 | - |
|
934 | - //* teardown |
|
935 | - Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
936 | - } |
|
937 | - |
|
938 | - /* * ******************** Setup ********************** */ |
|
939 | - |
|
940 | - public function setUp() { |
|
941 | - Cache::clear(); |
|
942 | - |
|
943 | - Configure::write('Asset.timestamp', false); |
|
944 | - |
|
945 | - if (isset($_SERVER['SERVER_NAME'])) { |
|
946 | - $this->server_name = $_SERVER['SERVER_NAME']; |
|
947 | - } else { |
|
948 | - $this->server_name = false; |
|
949 | - } |
|
950 | - |
|
951 | - if (isset($_SERVER['SERVER_PORT'])) { |
|
952 | - $this->server_port = $_SERVER['SERVER_PORT']; |
|
953 | - } else { |
|
954 | - $this->server_port = false; |
|
955 | - } |
|
956 | - |
|
957 | - $this->asset_timestamp = Configure::read('Asset.timestamp'); |
|
958 | - |
|
959 | - $this->text_word_maxlength = Configure::read('Saito.Settings.text_word_maxlength'); |
|
960 | - Configure::write('Saito.Settings.text_word_maxlength', 10000); |
|
961 | - |
|
962 | - $this->autolink = Configure::read('Saito.Settings.autolink'); |
|
963 | - Configure::write('Saito.Settings.autolink', true); |
|
964 | - |
|
965 | - $_SERVER['SERVER_NAME'] = 'macnemo.de'; |
|
966 | - $_SERVER['SERVER_PORT'] = '80'; |
|
967 | - |
|
968 | - parent::setUp(); |
|
969 | - |
|
970 | - $Request = new CakeRequest('/'); |
|
971 | - $Controller = new Controller($Request); |
|
972 | - $View = new View($Controller); |
|
973 | - |
|
974 | - //= smiley fixture |
|
975 | - $smiliesFixture = [ |
|
976 | - [ |
|
977 | - 'order' => 1, |
|
978 | - 'icon' => 'wink.png', |
|
979 | - 'image' => 'wink.png', |
|
980 | - 'title' => 'Wink', |
|
981 | - 'code' => ';)', |
|
982 | - 'type' => 'image' |
|
983 | - ], |
|
984 | - [ |
|
985 | - 'order' => 2, |
|
986 | - 'icon' => 'smile_icon.svg', |
|
987 | - 'image' => 'smile_image.svg', |
|
988 | - 'title' => 'Smile', |
|
989 | - 'code' => ':-)', |
|
990 | - 'type' => 'image' |
|
991 | - ], |
|
992 | - [ |
|
993 | - 'order' => 3, |
|
994 | - 'icon' => 'coffee', |
|
995 | - 'image' => 'coffee', |
|
996 | - 'title' => 'Coffee', |
|
997 | - 'code' => '[_]P', |
|
998 | - 'type' => 'font' |
|
999 | - ], |
|
1000 | - ]; |
|
1001 | - Cache::write('Saito.Smilies.data', $smiliesFixture); |
|
1002 | - $SmileyCache = new \Saito\Smiley\Cache($Controller); |
|
1003 | - |
|
1004 | - //= userlist fixture |
|
1005 | - $Userlist = new Userlist\UserlistArray(); |
|
1006 | - $Userlist->set(['Alice', 'Bobby Junior', 'Dr. No']); |
|
1007 | - |
|
1008 | - //= ParserHelper |
|
1009 | - $settings = [ |
|
1010 | - 'autolink' => true, |
|
1011 | - 'bbcode_img' => true, |
|
1012 | - 'multimedia' => true, |
|
1013 | - 'quote_symbol' => '»', |
|
1014 | - 'hashBaseUrl' => '/hash/', |
|
1015 | - 'atBaseUrl' => '/at/', |
|
1016 | - 'return' => 'html', |
|
1017 | - 'smilies' => true, |
|
1018 | - 'smiliesData' => $SmileyCache, |
|
1019 | - 'text_word_maxlength' => 120, |
|
1020 | - 'UserList' => $Userlist, |
|
1021 | - 'webroot' => '' |
|
1022 | - ]; |
|
1023 | - $this->_Helper = $ParserHelper = new ParserHelper($View, $settings); |
|
1024 | - $ParserHelper->beforeRender(null); |
|
1025 | - |
|
1026 | - //= Smiley Renderer |
|
1027 | - $SmileyRenderer = new \Saito\Smiley\Renderer($SmileyCache); |
|
1028 | - $SmileyRenderer->setHelper($this->_Helper); |
|
1029 | - $this->_Helper->SmileyRenderer = $SmileyRenderer; |
|
1030 | - |
|
1031 | - //= Parser |
|
1032 | - $this->_Parser = new Lib\Parser($ParserHelper, $settings); |
|
1033 | - } |
|
1034 | - |
|
1035 | - public function tearDown() { |
|
1036 | - parent::tearDown(); |
|
1037 | - if ($this->server_name) { |
|
1038 | - $_SERVER['SERVER_NAME'] = $this->server_name; |
|
1039 | - } |
|
1040 | - |
|
1041 | - if ($this->server_name) { |
|
1042 | - $_SERVER['SERVER_PORT'] = $this->server_port; |
|
1043 | - } |
|
1044 | - |
|
1045 | - Configure::write('Asset.timestamp', $this->asset_timestamp); |
|
1046 | - |
|
1047 | - Configure::write('Saito.Settings.text_word_maxlength', |
|
1048 | - $this->text_word_maxlength); |
|
1049 | - |
|
1050 | - Configure::write('Saito.Settings.autolink', $this->autolink); |
|
1051 | - |
|
1052 | - Cache::clear(); |
|
1053 | - ClassRegistry::flush(); |
|
1054 | - unset($this->_Parser); |
|
1055 | - } |
|
1056 | - |
|
1057 | - } |
|
689 | + $expected = [ |
|
690 | + [ |
|
691 | + 'a' => [ |
|
692 | + 'href' => 'http://heise.de', |
|
693 | + 'rel' => 'external', |
|
694 | + 'target' => '_blank', |
|
695 | + ] |
|
696 | + ], |
|
697 | + [ |
|
698 | + 'img' => [ |
|
699 | + 'src' => 'http://heise.de/img.png', |
|
700 | + 'alt' => '', |
|
701 | + ] |
|
702 | + ], |
|
703 | + '/a' |
|
704 | + ]; |
|
705 | + $result = $this->_Parser->parse($input); |
|
706 | + $this->assertTags($result, $expected); |
|
707 | + |
|
708 | + Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
709 | + } |
|
710 | + |
|
711 | + public function testInternalImage() { |
|
712 | + // Create a map of arguments to return values. |
|
713 | + $map = [ |
|
714 | + ['test.png', [], '<img src="test.png" />'], |
|
715 | + [ |
|
716 | + 'test.png', |
|
717 | + [ |
|
718 | + 'autoResize' => false, |
|
719 | + 'resizeThumbOnly' => false, |
|
720 | + 'width' => '50', |
|
721 | + 'height' => '60', |
|
722 | + ], |
|
723 | + '<img src="test.png" width="50" height="60" alt="">' |
|
724 | + ] |
|
725 | + ]; |
|
726 | + $FileUploader = $this->getMock('FileUploaderHelper', ['image', 'reset']); |
|
727 | + $FileUploader->expects($this->atLeastOnce()) |
|
728 | + ->method('image') |
|
729 | + ->will($this->returnValueMap($map)); |
|
730 | + $this->_Helper->FileUpload = $FileUploader; |
|
731 | + |
|
732 | + // internal image |
|
733 | + $input = '[upload]test.png[/upload]'; |
|
734 | + $expected = [ |
|
735 | + ['img' => ['src' => 'test.png']], |
|
736 | + ]; |
|
737 | + $result = $this->_Parser->parse($input); |
|
738 | + $this->assertTags($result, $expected); |
|
739 | + |
|
740 | + // internal image with attributes |
|
741 | + $input = '[upload width=50 height=60]test.png[/upload]'; |
|
742 | + $expected = array( |
|
743 | + ['img' => |
|
744 | + [ |
|
745 | + 'src' => 'test.png', |
|
746 | + 'width' => '50', |
|
747 | + 'height' => '60', |
|
748 | + 'alt' => '' |
|
749 | + ] |
|
750 | + ] |
|
751 | + ); |
|
752 | + $result = $this->_Parser->parse($input); |
|
753 | + $this->assertTags($result, $expected); |
|
754 | + |
|
755 | + // internal image legacy [img#] tag |
|
756 | + $input = '[img#]test.png[/img]'; |
|
757 | + $expected = [ |
|
758 | + [ |
|
759 | + 'img' => [ |
|
760 | + 'src' => 'test.png', |
|
761 | + ] |
|
762 | + ] |
|
763 | + ]; |
|
764 | + $result = $this->_Parser->parse($input); |
|
765 | + $this->assertTags($result, $expected); |
|
766 | + |
|
767 | + // nested image does not have [domain.info] |
|
768 | + $input = '[url=http://heise.de][upload]test.png[/upload][/url]'; |
|
769 | + $expected = "/richtext-linkInfo/"; |
|
770 | + $result = $this->_Parser->parse($input); |
|
771 | + $this->assertNotRegExp($expected, $result); |
|
772 | + } |
|
773 | + |
|
774 | + public function testSmiliesNoSmiliesInCodeTag() { |
|
775 | + $input = '[code text]:)[/code]'; |
|
776 | + $needle = '<img'; |
|
777 | + $result = $this->_Parser->parse($input, array('cache' => false)); |
|
778 | + $this->assertNotContains($needle, $result); |
|
779 | + } |
|
780 | + |
|
781 | + public function testCodeNestedTags() { |
|
782 | + $input = '[code][b]text[b][/code]'; |
|
783 | + $expected = [ |
|
784 | + [ |
|
785 | + 'div' => ['class' => 'geshi-wrapper'] |
|
786 | + ], |
|
787 | + 'preg:/.*?\[b\]text\[b\].*/', |
|
788 | + ]; |
|
789 | + $result = $this->_Parser->parse($input); |
|
790 | + $this->assertTags($result, $expected); |
|
791 | + } |
|
792 | + |
|
793 | + public function testCodeWhitespace() { |
|
794 | + $input = "[code]\ntest\n[/code]"; |
|
795 | + $expected = "/>test</"; |
|
796 | + $result = $this->_Parser->parse($input); |
|
797 | + $this->assertRegExp($expected, $result); |
|
798 | + } |
|
799 | + |
|
800 | + public function testCodeSimple() { |
|
801 | + $input = '[code]text[/code]'; |
|
802 | + $result = $this->_Parser->parse($input); |
|
803 | + $expected = 'lang="text"'; |
|
804 | + $this->assertContains($expected, $result); |
|
805 | + } |
|
806 | + |
|
807 | + public function testCodeLangAttribute() { |
|
808 | + $input = '[code=php]text[/code]'; |
|
809 | + $result = $this->_Parser->parse($input); |
|
810 | + $expected = 'lang="php"'; |
|
811 | + $this->assertContains($expected, $result); |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * tests that citation marks are not replaced in code-blocks |
|
816 | + */ |
|
817 | + public function testCodeNoCitationMark() { |
|
818 | + // [code]<citation mark>[/code] should not be cited |
|
819 | + $input = h( |
|
820 | + "[code]\n" . $this->_Helper->settings['quote_symbol'] . "\n[/code]" |
|
821 | + ); |
|
822 | + $expected = '`span class=.*?richtext-citation`'; |
|
823 | + $result = $this->_Parser->parse($input); |
|
824 | + $this->assertNotRegExp($expected, $result); |
|
825 | + } |
|
826 | + |
|
827 | + public function testCodeDetaginize() { |
|
828 | + $input = '[code bash]pre http://example.com post[/code]'; |
|
829 | + $result = $this->_Parser->parse($input); |
|
830 | + $this->assertNotContains('autoLink', $result); |
|
831 | + } |
|
832 | + |
|
833 | + public function testQuote() { |
|
834 | + $_qs = h($this->_Helper->settings['quote_symbol']); |
|
835 | + $input = $_qs . ' fo [b]test[/b] ba'; |
|
836 | + $result = $this->_Parser->parse($input); |
|
837 | + $expected = [ |
|
838 | + 'span' => ['class' => 'richtext-citation'], |
|
839 | + $_qs . ' fo ', |
|
840 | + 'strong' => [], |
|
841 | + 'test', |
|
842 | + '/strong', |
|
843 | + ' ba', |
|
844 | + '/span' |
|
845 | + ]; |
|
846 | + $this->assertTags($result, $expected); |
|
847 | + } |
|
848 | + |
|
849 | + public function testHtml5Video() { |
|
850 | + //* setup |
|
851 | + $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
852 | + Configure::write('Saito.Settings.bbcode_img', true); |
|
853 | + |
|
854 | + //* @td write video tests |
|
855 | + $url = 'http://example.com/audio.mp4'; |
|
856 | + $input = "[video]{$url}[/video]"; |
|
857 | + $result = $this->_Parser->parse($input); |
|
858 | + $expected = array( |
|
859 | + 'video' => array('src' => $url, 'controls' => 'controls', |
|
860 | + 'x-webkit-airplay' => 'allow'), |
|
861 | + ); |
|
862 | + $this->assertTags($result, $expected); |
|
863 | + |
|
864 | + //* test autoconversion for audio files |
|
865 | + $html5AudioExtensions = array('m4a', 'ogg', 'mp3', 'wav', 'opus'); |
|
866 | + foreach ($html5AudioExtensions as $extension) { |
|
867 | + $url = 'http://example.com/audio.' . $extension; |
|
868 | + $input = "[video]{$url}[/video]"; |
|
869 | + $result = $this->_Parser->parse($input); |
|
870 | + $expected = array( |
|
871 | + 'audio' => array('src' => $url, 'controls' => 'controls'), |
|
872 | + ); |
|
873 | + $this->assertTags($result, $expected); |
|
874 | + } |
|
875 | + |
|
876 | + //* teardown |
|
877 | + Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
878 | + } |
|
879 | + |
|
880 | + public function testHr() { |
|
881 | + $input = '[hr][hr]'; |
|
882 | + $expected = '<hr><hr>'; |
|
883 | + $result = $this->_Parser->parse($input); |
|
884 | + $this->assertEquals($result, $expected); |
|
885 | + } |
|
886 | + |
|
887 | + public function testHrShort() { |
|
888 | + $input = '[---][---]'; |
|
889 | + $expected = '<hr><hr>'; |
|
890 | + $result = $this->_Parser->parse($input); |
|
891 | + $this->assertEquals($result, $expected); |
|
892 | + } |
|
893 | + |
|
894 | + public function testEmbedlyDisabled() { |
|
895 | + $observer = $this->getMock('Embedly', array('setApiKey', 'embedly')); |
|
896 | + $observer->expects($this->never()) |
|
897 | + ->method('setApiKey'); |
|
898 | + $this->_Helper->Embedly = $observer; |
|
899 | + $input = '[embed]foo[/embed]'; |
|
900 | + $this->_Parser->parse($input); |
|
901 | + } |
|
902 | + |
|
903 | + public function testEmbedlyEnabled() { |
|
904 | + $observer = $this->getMock('Embedly', array('setApiKey', 'embedly')); |
|
905 | + $observer->expects($this->once()) |
|
906 | + ->method('setApiKey') |
|
907 | + ->with($this->equalTo('abc123')); |
|
908 | + $observer->expects($this->once()) |
|
909 | + ->method('embedly') |
|
910 | + ->with($this->equalTo('foo')); |
|
911 | + $this->_Helper->Embedly = $observer; |
|
912 | + $input = '[embed]foo[/embed]'; |
|
913 | + |
|
914 | + $this->_Parser->parse($input, [ |
|
915 | + 'embedly_enabled' => true, |
|
916 | + 'embedly_key' => 'abc123' |
|
917 | + ]); |
|
918 | + } |
|
919 | + |
|
920 | + public function testHtml5Audio() { |
|
921 | + //* setup |
|
922 | + $bbcodeImg = Configure::read('Saito.Settings.bbcode_img'); |
|
923 | + Configure::write('Saito.Settings.bbcode_img', true); |
|
924 | + |
|
925 | + //* simple test |
|
926 | + $url = 'http://example.com/audio3.m4a'; |
|
927 | + $input = "[audio]{$url}[/audio]"; |
|
928 | + $result = $this->_Parser->parse($input); |
|
929 | + $expected = array( |
|
930 | + 'audio' => array( 'src' => $url, 'controls' => 'controls' ), |
|
931 | + ); |
|
932 | + $this->assertTags($result, $expected); |
|
933 | + |
|
934 | + //* teardown |
|
935 | + Configure::write('Saito.Settings.bbcode_img', $bbcodeImg); |
|
936 | + } |
|
937 | + |
|
938 | + /* * ******************** Setup ********************** */ |
|
939 | + |
|
940 | + public function setUp() { |
|
941 | + Cache::clear(); |
|
942 | + |
|
943 | + Configure::write('Asset.timestamp', false); |
|
944 | + |
|
945 | + if (isset($_SERVER['SERVER_NAME'])) { |
|
946 | + $this->server_name = $_SERVER['SERVER_NAME']; |
|
947 | + } else { |
|
948 | + $this->server_name = false; |
|
949 | + } |
|
950 | + |
|
951 | + if (isset($_SERVER['SERVER_PORT'])) { |
|
952 | + $this->server_port = $_SERVER['SERVER_PORT']; |
|
953 | + } else { |
|
954 | + $this->server_port = false; |
|
955 | + } |
|
956 | + |
|
957 | + $this->asset_timestamp = Configure::read('Asset.timestamp'); |
|
958 | + |
|
959 | + $this->text_word_maxlength = Configure::read('Saito.Settings.text_word_maxlength'); |
|
960 | + Configure::write('Saito.Settings.text_word_maxlength', 10000); |
|
961 | + |
|
962 | + $this->autolink = Configure::read('Saito.Settings.autolink'); |
|
963 | + Configure::write('Saito.Settings.autolink', true); |
|
964 | + |
|
965 | + $_SERVER['SERVER_NAME'] = 'macnemo.de'; |
|
966 | + $_SERVER['SERVER_PORT'] = '80'; |
|
967 | + |
|
968 | + parent::setUp(); |
|
969 | + |
|
970 | + $Request = new CakeRequest('/'); |
|
971 | + $Controller = new Controller($Request); |
|
972 | + $View = new View($Controller); |
|
973 | + |
|
974 | + //= smiley fixture |
|
975 | + $smiliesFixture = [ |
|
976 | + [ |
|
977 | + 'order' => 1, |
|
978 | + 'icon' => 'wink.png', |
|
979 | + 'image' => 'wink.png', |
|
980 | + 'title' => 'Wink', |
|
981 | + 'code' => ';)', |
|
982 | + 'type' => 'image' |
|
983 | + ], |
|
984 | + [ |
|
985 | + 'order' => 2, |
|
986 | + 'icon' => 'smile_icon.svg', |
|
987 | + 'image' => 'smile_image.svg', |
|
988 | + 'title' => 'Smile', |
|
989 | + 'code' => ':-)', |
|
990 | + 'type' => 'image' |
|
991 | + ], |
|
992 | + [ |
|
993 | + 'order' => 3, |
|
994 | + 'icon' => 'coffee', |
|
995 | + 'image' => 'coffee', |
|
996 | + 'title' => 'Coffee', |
|
997 | + 'code' => '[_]P', |
|
998 | + 'type' => 'font' |
|
999 | + ], |
|
1000 | + ]; |
|
1001 | + Cache::write('Saito.Smilies.data', $smiliesFixture); |
|
1002 | + $SmileyCache = new \Saito\Smiley\Cache($Controller); |
|
1003 | + |
|
1004 | + //= userlist fixture |
|
1005 | + $Userlist = new Userlist\UserlistArray(); |
|
1006 | + $Userlist->set(['Alice', 'Bobby Junior', 'Dr. No']); |
|
1007 | + |
|
1008 | + //= ParserHelper |
|
1009 | + $settings = [ |
|
1010 | + 'autolink' => true, |
|
1011 | + 'bbcode_img' => true, |
|
1012 | + 'multimedia' => true, |
|
1013 | + 'quote_symbol' => '»', |
|
1014 | + 'hashBaseUrl' => '/hash/', |
|
1015 | + 'atBaseUrl' => '/at/', |
|
1016 | + 'return' => 'html', |
|
1017 | + 'smilies' => true, |
|
1018 | + 'smiliesData' => $SmileyCache, |
|
1019 | + 'text_word_maxlength' => 120, |
|
1020 | + 'UserList' => $Userlist, |
|
1021 | + 'webroot' => '' |
|
1022 | + ]; |
|
1023 | + $this->_Helper = $ParserHelper = new ParserHelper($View, $settings); |
|
1024 | + $ParserHelper->beforeRender(null); |
|
1025 | + |
|
1026 | + //= Smiley Renderer |
|
1027 | + $SmileyRenderer = new \Saito\Smiley\Renderer($SmileyCache); |
|
1028 | + $SmileyRenderer->setHelper($this->_Helper); |
|
1029 | + $this->_Helper->SmileyRenderer = $SmileyRenderer; |
|
1030 | + |
|
1031 | + //= Parser |
|
1032 | + $this->_Parser = new Lib\Parser($ParserHelper, $settings); |
|
1033 | + } |
|
1034 | + |
|
1035 | + public function tearDown() { |
|
1036 | + parent::tearDown(); |
|
1037 | + if ($this->server_name) { |
|
1038 | + $_SERVER['SERVER_NAME'] = $this->server_name; |
|
1039 | + } |
|
1040 | + |
|
1041 | + if ($this->server_name) { |
|
1042 | + $_SERVER['SERVER_PORT'] = $this->server_port; |
|
1043 | + } |
|
1044 | + |
|
1045 | + Configure::write('Asset.timestamp', $this->asset_timestamp); |
|
1046 | + |
|
1047 | + Configure::write('Saito.Settings.text_word_maxlength', |
|
1048 | + $this->text_word_maxlength); |
|
1049 | + |
|
1050 | + Configure::write('Saito.Settings.autolink', $this->autolink); |
|
1051 | + |
|
1052 | + Cache::clear(); |
|
1053 | + ClassRegistry::flush(); |
|
1054 | + unset($this->_Parser); |
|
1055 | + } |
|
1056 | + |
|
1057 | + } |
|
1058 | 1058 |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $options = array_merge($this->_cSettings, $options); |
218 | 218 | |
219 | 219 | // serializing complex objects kills PHP |
220 | - $serializable = array_filter($options, function ($value) { |
|
220 | + $serializable = array_filter($options, function($value) { |
|
221 | 221 | return !is_object($value); |
222 | 222 | }); |
223 | 223 | $parserId = md5(serialize($serializable)); |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | $this->_Parser->addCodeDefinition($builder->build()); |
259 | 259 | break; |
260 | 260 | case 'class': |
261 | - require_once (\CakePlugin::path('BbcodeParser') . DS . 'Lib' . DS . 'jBBCode' . DS . 'Definitions' . DS . 'JbbCodeDefinitions.php'); |
|
262 | - $class = '\Plugin\BbcodeParser\Lib\jBBCode\Definitions\\' . ucfirst($title); |
|
261 | + require_once (\CakePlugin::path('BbcodeParser').DS.'Lib'.DS.'jBBCode'.DS.'Definitions'.DS.'JbbCodeDefinitions.php'); |
|
262 | + $class = '\Plugin\BbcodeParser\Lib\jBBCode\Definitions\\'.ucfirst($title); |
|
263 | 263 | $this->_Parser->addCodeDefinition(new $class($this->_Helper, $options)); |
264 | 264 | break; |
265 | 265 | default: |
@@ -1,272 +1,272 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | - namespace Plugin\BbcodeParser\Lib; |
|
3 | + namespace Plugin\BbcodeParser\Lib; |
|
4 | 4 | |
5 | - use Plugin\BbcodeParser\Lib\jBBCode\Definitions; |
|
6 | - use Plugin\BbcodeParser\Lib\jBBCode\Visitors; |
|
7 | - use Plugin\BbcodeParser\Lib\Processors; |
|
5 | + use Plugin\BbcodeParser\Lib\jBBCode\Definitions; |
|
6 | + use Plugin\BbcodeParser\Lib\jBBCode\Visitors; |
|
7 | + use Plugin\BbcodeParser\Lib\Processors; |
|
8 | 8 | |
9 | - class Parser extends \Saito\Markup\Parser { |
|
9 | + class Parser extends \Saito\Markup\Parser { |
|
10 | 10 | |
11 | - /** |
|
12 | - * @var \JBBCode\Parser |
|
13 | - */ |
|
14 | - protected $_Parser; |
|
11 | + /** |
|
12 | + * @var \JBBCode\Parser |
|
13 | + */ |
|
14 | + protected $_Parser; |
|
15 | 15 | |
16 | - protected $_Preprocessors; |
|
16 | + protected $_Preprocessors; |
|
17 | 17 | |
18 | - protected $_Postprocessors; |
|
18 | + protected $_Postprocessors; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - * |
|
23 | - * [ |
|
24 | - * <set title> => [ |
|
25 | - * <arbitrary definition title> => [ <definition> ] |
|
26 | - * ] |
|
27 | - * ] |
|
28 | - * |
|
29 | - */ |
|
30 | - protected $_tags = [ |
|
31 | - 'basic' => [ |
|
32 | - // strong |
|
33 | - 'b' => [ |
|
34 | - 'type' => 'replacement', |
|
35 | - 'title' => 'b', |
|
36 | - 'replacement' => '<strong>{param}</strong>' |
|
37 | - ], |
|
38 | - // code |
|
39 | - 'codeWithAttributes' => [ |
|
40 | - 'type' => 'class', |
|
41 | - 'title' => 'CodeWithAttributes' |
|
42 | - ], |
|
43 | - 'codeWithoutAttributes' => [ |
|
44 | - 'type' => 'class', |
|
45 | - 'title' => 'CodeWithoutAttributes' |
|
46 | - ], |
|
47 | - // edit marker |
|
48 | - 'e' => [ |
|
49 | - 'type' => 'replacement', |
|
50 | - 'title' => 'e', |
|
51 | - 'replacement' => '<span class="richtext-editMark"></span>{param}' |
|
52 | - ], |
|
53 | - // float |
|
54 | - 'float' => [ |
|
55 | - 'type' => 'replacement', |
|
56 | - 'title' => 'float', |
|
57 | - 'replacement' => '<div class="clearfix"></div><div class="richtext-float">{param}</div>' |
|
58 | - ], |
|
59 | ||
60 | - 'email' => [ |
|
61 | - 'type' => 'class', |
|
62 | - 'title' => 'email' |
|
63 | - ], |
|
64 | - 'emailWithAttributes' => [ |
|
65 | - 'type' => 'class', |
|
66 | - 'title' => 'emailWithAttributes' |
|
67 | - ], |
|
68 | - // hr |
|
69 | - 'hr' => [ |
|
70 | - 'type' => 'replacement', |
|
71 | - 'title' => 'hr', |
|
72 | - 'replacement' => '<hr>{param}' |
|
73 | - ], |
|
74 | - '---' => [ |
|
75 | - 'type' => 'replacement', |
|
76 | - 'title' => '---', |
|
77 | - 'replacement' => '<hr>{param}' |
|
78 | - ], |
|
79 | - // emphasis |
|
80 | - 'i' => [ |
|
81 | - 'type' => 'replacement', |
|
82 | - 'title' => 'i', |
|
83 | - 'replacement' => '<em>{param}</em>' |
|
84 | - ], |
|
85 | - // list |
|
86 | - 'list' => [ |
|
87 | - 'type' => 'class', |
|
88 | - 'title' => 'ulList' |
|
89 | - ], |
|
90 | - // spoiler |
|
91 | - 'spoiler' => [ |
|
92 | - 'type' => 'class', |
|
93 | - 'title' => 'spoiler' |
|
94 | - ], |
|
95 | - // strike |
|
96 | - 's' => [ |
|
97 | - 'type' => 'replacement', |
|
98 | - 'title' => 's', |
|
99 | - 'replacement' => '<del>{param}</del>', |
|
100 | - ], |
|
101 | - 'strike' => [ |
|
102 | - 'type' => 'replacement', |
|
103 | - 'title' => 'strike', |
|
104 | - 'replacement' => '<del>{param}</del>', |
|
105 | - ], |
|
106 | - // url |
|
107 | - 'link' => [ |
|
108 | - 'type' => 'class', |
|
109 | - 'title' => 'link' |
|
110 | - ], |
|
111 | - 'linkWithAttributes' => [ |
|
112 | - 'type' => 'class', |
|
113 | - 'title' => 'linkWithAttributes' |
|
114 | - ], |
|
115 | - 'url' => [ |
|
116 | - 'type' => 'class', |
|
117 | - 'title' => 'url' |
|
118 | - ], |
|
119 | - 'urlWithAttributes' => [ |
|
120 | - 'type' => 'class', |
|
121 | - 'title' => 'urlWithAttributes' |
|
122 | - ], |
|
123 | - // quotes |
|
124 | - 'quote' => [ |
|
125 | - 'type' => 'replacement', |
|
126 | - 'title' => 'quote', |
|
127 | - 'replacement' => '<blockquote>{param}</blockquote>' |
|
128 | - ] |
|
129 | - ], |
|
130 | - 'multimedia' => [ |
|
131 | - 'embed' => [ |
|
132 | - 'type' => 'class', |
|
133 | - 'title' => 'Embed' |
|
134 | - ], |
|
135 | - 'flash' => [ |
|
136 | - 'type' => 'class', |
|
137 | - 'title' => 'Flash' |
|
138 | - ], |
|
139 | - 'iframe' => [ |
|
140 | - 'type' => 'class', |
|
141 | - 'title' => 'Iframe' |
|
142 | - ], |
|
143 | - 'image' => [ |
|
144 | - 'type' => 'class', |
|
145 | - 'title' => 'Image' |
|
146 | - ], |
|
147 | - 'imageWithAttributes' => [ |
|
148 | - 'type' => 'class', |
|
149 | - 'title' => 'ImageWithAttributes' |
|
150 | - ], |
|
151 | - 'html5audio' => [ |
|
152 | - 'type' => 'class', |
|
153 | - 'title' => 'Html5Audio' |
|
154 | - ], |
|
155 | - 'html5video' => [ |
|
156 | - 'type' => 'class', |
|
157 | - 'title' => 'Html5Video' |
|
158 | - ], |
|
159 | - 'upload' => [ |
|
160 | - 'type' => 'class', |
|
161 | - 'title' => 'Upload' |
|
162 | - ], |
|
163 | - 'uploadWithAttributes' => [ |
|
164 | - 'type' => 'class', |
|
165 | - 'title' => 'UploadWithAttributes' |
|
166 | - ] |
|
167 | - ] |
|
168 | - ]; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + * |
|
23 | + * [ |
|
24 | + * <set title> => [ |
|
25 | + * <arbitrary definition title> => [ <definition> ] |
|
26 | + * ] |
|
27 | + * ] |
|
28 | + * |
|
29 | + */ |
|
30 | + protected $_tags = [ |
|
31 | + 'basic' => [ |
|
32 | + // strong |
|
33 | + 'b' => [ |
|
34 | + 'type' => 'replacement', |
|
35 | + 'title' => 'b', |
|
36 | + 'replacement' => '<strong>{param}</strong>' |
|
37 | + ], |
|
38 | + // code |
|
39 | + 'codeWithAttributes' => [ |
|
40 | + 'type' => 'class', |
|
41 | + 'title' => 'CodeWithAttributes' |
|
42 | + ], |
|
43 | + 'codeWithoutAttributes' => [ |
|
44 | + 'type' => 'class', |
|
45 | + 'title' => 'CodeWithoutAttributes' |
|
46 | + ], |
|
47 | + // edit marker |
|
48 | + 'e' => [ |
|
49 | + 'type' => 'replacement', |
|
50 | + 'title' => 'e', |
|
51 | + 'replacement' => '<span class="richtext-editMark"></span>{param}' |
|
52 | + ], |
|
53 | + // float |
|
54 | + 'float' => [ |
|
55 | + 'type' => 'replacement', |
|
56 | + 'title' => 'float', |
|
57 | + 'replacement' => '<div class="clearfix"></div><div class="richtext-float">{param}</div>' |
|
58 | + ], |
|
59 | ||
60 | + 'email' => [ |
|
61 | + 'type' => 'class', |
|
62 | + 'title' => 'email' |
|
63 | + ], |
|
64 | + 'emailWithAttributes' => [ |
|
65 | + 'type' => 'class', |
|
66 | + 'title' => 'emailWithAttributes' |
|
67 | + ], |
|
68 | + // hr |
|
69 | + 'hr' => [ |
|
70 | + 'type' => 'replacement', |
|
71 | + 'title' => 'hr', |
|
72 | + 'replacement' => '<hr>{param}' |
|
73 | + ], |
|
74 | + '---' => [ |
|
75 | + 'type' => 'replacement', |
|
76 | + 'title' => '---', |
|
77 | + 'replacement' => '<hr>{param}' |
|
78 | + ], |
|
79 | + // emphasis |
|
80 | + 'i' => [ |
|
81 | + 'type' => 'replacement', |
|
82 | + 'title' => 'i', |
|
83 | + 'replacement' => '<em>{param}</em>' |
|
84 | + ], |
|
85 | + // list |
|
86 | + 'list' => [ |
|
87 | + 'type' => 'class', |
|
88 | + 'title' => 'ulList' |
|
89 | + ], |
|
90 | + // spoiler |
|
91 | + 'spoiler' => [ |
|
92 | + 'type' => 'class', |
|
93 | + 'title' => 'spoiler' |
|
94 | + ], |
|
95 | + // strike |
|
96 | + 's' => [ |
|
97 | + 'type' => 'replacement', |
|
98 | + 'title' => 's', |
|
99 | + 'replacement' => '<del>{param}</del>', |
|
100 | + ], |
|
101 | + 'strike' => [ |
|
102 | + 'type' => 'replacement', |
|
103 | + 'title' => 'strike', |
|
104 | + 'replacement' => '<del>{param}</del>', |
|
105 | + ], |
|
106 | + // url |
|
107 | + 'link' => [ |
|
108 | + 'type' => 'class', |
|
109 | + 'title' => 'link' |
|
110 | + ], |
|
111 | + 'linkWithAttributes' => [ |
|
112 | + 'type' => 'class', |
|
113 | + 'title' => 'linkWithAttributes' |
|
114 | + ], |
|
115 | + 'url' => [ |
|
116 | + 'type' => 'class', |
|
117 | + 'title' => 'url' |
|
118 | + ], |
|
119 | + 'urlWithAttributes' => [ |
|
120 | + 'type' => 'class', |
|
121 | + 'title' => 'urlWithAttributes' |
|
122 | + ], |
|
123 | + // quotes |
|
124 | + 'quote' => [ |
|
125 | + 'type' => 'replacement', |
|
126 | + 'title' => 'quote', |
|
127 | + 'replacement' => '<blockquote>{param}</blockquote>' |
|
128 | + ] |
|
129 | + ], |
|
130 | + 'multimedia' => [ |
|
131 | + 'embed' => [ |
|
132 | + 'type' => 'class', |
|
133 | + 'title' => 'Embed' |
|
134 | + ], |
|
135 | + 'flash' => [ |
|
136 | + 'type' => 'class', |
|
137 | + 'title' => 'Flash' |
|
138 | + ], |
|
139 | + 'iframe' => [ |
|
140 | + 'type' => 'class', |
|
141 | + 'title' => 'Iframe' |
|
142 | + ], |
|
143 | + 'image' => [ |
|
144 | + 'type' => 'class', |
|
145 | + 'title' => 'Image' |
|
146 | + ], |
|
147 | + 'imageWithAttributes' => [ |
|
148 | + 'type' => 'class', |
|
149 | + 'title' => 'ImageWithAttributes' |
|
150 | + ], |
|
151 | + 'html5audio' => [ |
|
152 | + 'type' => 'class', |
|
153 | + 'title' => 'Html5Audio' |
|
154 | + ], |
|
155 | + 'html5video' => [ |
|
156 | + 'type' => 'class', |
|
157 | + 'title' => 'Html5Video' |
|
158 | + ], |
|
159 | + 'upload' => [ |
|
160 | + 'type' => 'class', |
|
161 | + 'title' => 'Upload' |
|
162 | + ], |
|
163 | + 'uploadWithAttributes' => [ |
|
164 | + 'type' => 'class', |
|
165 | + 'title' => 'UploadWithAttributes' |
|
166 | + ] |
|
167 | + ] |
|
168 | + ]; |
|
169 | 169 | |
170 | - /** |
|
171 | - * Initialized parsers |
|
172 | - * |
|
173 | - * @var array |
|
174 | - */ |
|
175 | - protected $_initializedParsers = array(); |
|
170 | + /** |
|
171 | + * Initialized parsers |
|
172 | + * |
|
173 | + * @var array |
|
174 | + */ |
|
175 | + protected $_initializedParsers = array(); |
|
176 | 176 | |
177 | - /** |
|
178 | - * Parses BBCode |
|
179 | - * |
|
180 | - * ### Options |
|
181 | - * |
|
182 | - * - `return` string "html"|"text" result type |
|
183 | - * - `multimedia` bool true|false parse or ignore multimedia content |
|
184 | - * |
|
185 | - * @param $string |
|
186 | - * @param array $options |
|
187 | - * @return mixed|string |
|
188 | - */ |
|
189 | - public function parse($string, array $options = []) { |
|
190 | - $this->_initParser($options); |
|
177 | + /** |
|
178 | + * Parses BBCode |
|
179 | + * |
|
180 | + * ### Options |
|
181 | + * |
|
182 | + * - `return` string "html"|"text" result type |
|
183 | + * - `multimedia` bool true|false parse or ignore multimedia content |
|
184 | + * |
|
185 | + * @param $string |
|
186 | + * @param array $options |
|
187 | + * @return mixed|string |
|
188 | + */ |
|
189 | + public function parse($string, array $options = []) { |
|
190 | + $this->_initParser($options); |
|
191 | 191 | |
192 | - $string = $this->_Preprocessors->process($string); |
|
192 | + $string = $this->_Preprocessors->process($string); |
|
193 | 193 | |
194 | - $this->_Parser->parse($string); |
|
194 | + $this->_Parser->parse($string); |
|
195 | 195 | |
196 | - $this->_Parser->accept(new Visitors\JbbCodeNl2BrVisitor($this->_Helper, $options)); |
|
197 | - if ($this->_cSettings['autolink']) { |
|
198 | - $this->_Parser->accept(new Visitors\JbbCodeAutolinkVisitor($this->_Helper, $options)); |
|
199 | - } |
|
200 | - if ($this->_cSettings['smilies']) { |
|
201 | - $this->_Parser->accept(new Visitors\JbbCodeSmileyVisitor($this->_Helper, $options)); |
|
202 | - } |
|
196 | + $this->_Parser->accept(new Visitors\JbbCodeNl2BrVisitor($this->_Helper, $options)); |
|
197 | + if ($this->_cSettings['autolink']) { |
|
198 | + $this->_Parser->accept(new Visitors\JbbCodeAutolinkVisitor($this->_Helper, $options)); |
|
199 | + } |
|
200 | + if ($this->_cSettings['smilies']) { |
|
201 | + $this->_Parser->accept(new Visitors\JbbCodeSmileyVisitor($this->_Helper, $options)); |
|
202 | + } |
|
203 | 203 | |
204 | - switch ($options['return']) { |
|
205 | - case 'text': |
|
206 | - $html = $this->_Parser->getAsText(); |
|
207 | - break; |
|
208 | - default: |
|
209 | - $html = $this->_Parser->getAsHtml(); |
|
210 | - } |
|
204 | + switch ($options['return']) { |
|
205 | + case 'text': |
|
206 | + $html = $this->_Parser->getAsText(); |
|
207 | + break; |
|
208 | + default: |
|
209 | + $html = $this->_Parser->getAsHtml(); |
|
210 | + } |
|
211 | 211 | |
212 | - $html = $this->_Postprocessors->process($html); |
|
213 | - return $html; |
|
214 | - } |
|
212 | + $html = $this->_Postprocessors->process($html); |
|
213 | + return $html; |
|
214 | + } |
|
215 | 215 | |
216 | - protected function _initParser(&$options) { |
|
217 | - $options = array_merge($this->_cSettings, $options); |
|
216 | + protected function _initParser(&$options) { |
|
217 | + $options = array_merge($this->_cSettings, $options); |
|
218 | 218 | |
219 | - // serializing complex objects kills PHP |
|
220 | - $serializable = array_filter($options, function ($value) { |
|
221 | - return !is_object($value); |
|
222 | - }); |
|
223 | - $parserId = md5(serialize($serializable)); |
|
224 | - if (isset($this->_initializedParsers[$parserId])) { |
|
225 | - $this->_Parser = $this->_initializedParsers[$parserId]; |
|
226 | - return; |
|
227 | - } |
|
219 | + // serializing complex objects kills PHP |
|
220 | + $serializable = array_filter($options, function ($value) { |
|
221 | + return !is_object($value); |
|
222 | + }); |
|
223 | + $parserId = md5(serialize($serializable)); |
|
224 | + if (isset($this->_initializedParsers[$parserId])) { |
|
225 | + $this->_Parser = $this->_initializedParsers[$parserId]; |
|
226 | + return; |
|
227 | + } |
|
228 | 228 | |
229 | - $this->_Parser = new \JBBCode\Parser(); |
|
230 | - $this->_addDefinitionSet('basic', $options); |
|
229 | + $this->_Parser = new \JBBCode\Parser(); |
|
230 | + $this->_addDefinitionSet('basic', $options); |
|
231 | 231 | |
232 | - if (!empty($this->_cSettings['bbcode_img']) && $options['multimedia']) { |
|
233 | - $this->_addDefinitionSet('multimedia', $options); |
|
234 | - } |
|
232 | + if (!empty($this->_cSettings['bbcode_img']) && $options['multimedia']) { |
|
233 | + $this->_addDefinitionSet('multimedia', $options); |
|
234 | + } |
|
235 | 235 | |
236 | - $this->_Preprocessors = new Processors\BbcodeProcessorCollection(); |
|
237 | - $this->_Preprocessors->add(new Processors\BbcodeImageUploadLegacyPreprocessor()); |
|
238 | - $this->_Preprocessors->add(new Processors\BbcodePreparePreprocessor()); |
|
236 | + $this->_Preprocessors = new Processors\BbcodeProcessorCollection(); |
|
237 | + $this->_Preprocessors->add(new Processors\BbcodeImageUploadLegacyPreprocessor()); |
|
238 | + $this->_Preprocessors->add(new Processors\BbcodePreparePreprocessor()); |
|
239 | 239 | |
240 | - $this->_Postprocessors = new Processors\BbcodeProcessorCollection(); |
|
241 | - $this->_Postprocessors->add(new Processors\BbcodeQuotePostprocessor($options)); |
|
240 | + $this->_Postprocessors = new Processors\BbcodeProcessorCollection(); |
|
241 | + $this->_Postprocessors->add(new Processors\BbcodeQuotePostprocessor($options)); |
|
242 | 242 | |
243 | - $this->_initializedParsers[$parserId] = $this->_Parser; |
|
244 | - } |
|
243 | + $this->_initializedParsers[$parserId] = $this->_Parser; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * @param $set |
|
248 | - * @param $options |
|
249 | - * @throws \Exception |
|
250 | - */ |
|
251 | - protected function _addDefinitionSet($set, $options) { |
|
252 | - foreach ($this->_tags[$set] as $definition) { |
|
253 | - $title = $definition['title']; |
|
254 | - switch ($definition['type']) { |
|
255 | - case 'replacement': |
|
256 | - $builder = new \JBBCode\CodeDefinitionBuilder($title, |
|
257 | - $definition['replacement']); |
|
258 | - $this->_Parser->addCodeDefinition($builder->build()); |
|
259 | - break; |
|
260 | - case 'class': |
|
261 | - require_once (\CakePlugin::path('BbcodeParser') . DS . 'Lib' . DS . 'jBBCode' . DS . 'Definitions' . DS . 'JbbCodeDefinitions.php'); |
|
262 | - $class = '\Plugin\BbcodeParser\Lib\jBBCode\Definitions\\' . ucfirst($title); |
|
263 | - $this->_Parser->addCodeDefinition(new $class($this->_Helper, $options)); |
|
264 | - break; |
|
265 | - default: |
|
266 | - throw new \Exception(); |
|
267 | - } |
|
268 | - } |
|
269 | - } |
|
246 | + /** |
|
247 | + * @param $set |
|
248 | + * @param $options |
|
249 | + * @throws \Exception |
|
250 | + */ |
|
251 | + protected function _addDefinitionSet($set, $options) { |
|
252 | + foreach ($this->_tags[$set] as $definition) { |
|
253 | + $title = $definition['title']; |
|
254 | + switch ($definition['type']) { |
|
255 | + case 'replacement': |
|
256 | + $builder = new \JBBCode\CodeDefinitionBuilder($title, |
|
257 | + $definition['replacement']); |
|
258 | + $this->_Parser->addCodeDefinition($builder->build()); |
|
259 | + break; |
|
260 | + case 'class': |
|
261 | + require_once (\CakePlugin::path('BbcodeParser') . DS . 'Lib' . DS . 'jBBCode' . DS . 'Definitions' . DS . 'JbbCodeDefinitions.php'); |
|
262 | + $class = '\Plugin\BbcodeParser\Lib\jBBCode\Definitions\\' . ucfirst($title); |
|
263 | + $this->_Parser->addCodeDefinition(new $class($this->_Helper, $options)); |
|
264 | + break; |
|
265 | + default: |
|
266 | + throw new \Exception(); |
|
267 | + } |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - } |
|
271 | + } |
|
272 | 272 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | // use Cakes Validation class to detect valid URL |
21 | 21 | \App::uses('Validation', 'Utility'); |
22 | 22 | if (\Validation::url($url)) { |
23 | - $url = 'http://' . $url; |
|
23 | + $url = 'http://'.$url; |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | if (!empty($url) && preg_match('/\<img\s*?src=/', $text) !== 1) { |
37 | 37 | $host = DomainParser::domainAndTld($url); |
38 | 38 | if ($host !== false && $host !== env('SERVER_NAME')) { |
39 | - $out .= ' <span class=\'richtext-linkInfo\'>[' . $host . ']</span>'; |
|
39 | + $out .= ' <span class=\'richtext-linkInfo\'>['.$host.']</span>'; |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | $_placeholder = ' … '; |
67 | - $leftMargin = (int)floor($_textWordMaxLength / 2); |
|
68 | - $rightMargin = (int)(-1 * ($_textWordMaxLength - $leftMargin - mb_strlen($_placeholder))); |
|
67 | + $leftMargin = (int) floor($_textWordMaxLength / 2); |
|
68 | + $rightMargin = (int) (-1 * ($_textWordMaxLength - $leftMargin - mb_strlen($_placeholder))); |
|
69 | 69 | |
70 | - $string = mb_substr($string, 0, $leftMargin) . $_placeholder . |
|
70 | + $string = mb_substr($string, 0, $leftMargin).$_placeholder. |
|
71 | 71 | mb_substr($string, $rightMargin); |
72 | 72 | return $string; |
73 | 73 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return string |
80 | 80 | */ |
81 | 81 | protected function _decorateTarget($string) { |
82 | - $decorator = function ($matches) { |
|
82 | + $decorator = function($matches) { |
|
83 | 83 | $out = ''; |
84 | 84 | $url = $matches[1]; |
85 | 85 | |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | $parsedUrl = @parse_url($url); |
91 | 91 | |
92 | 92 | if (isset($parsedUrl['host'])) { |
93 | - if ($parsedUrl['host'] !== env('SERVER_NAME') && $parsedUrl['host'] !== "www." . env('SERVER_NAME')) { |
|
93 | + if ($parsedUrl['host'] !== env('SERVER_NAME') && $parsedUrl['host'] !== "www.".env('SERVER_NAME')) { |
|
94 | 94 | $out = " rel='external' target='_blank'"; |
95 | 95 | } |
96 | 96 | } |
97 | - return $matches[0] . $out; |
|
97 | + return $matches[0].$out; |
|
98 | 98 | }; |
99 | 99 | |
100 | 100 | return preg_replace_callback('#href=["\'](.*?)["\']#is', |
@@ -1,104 +1,104 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | - namespace Plugin\BbcodeParser\Lib\Helper; |
|
4 | - |
|
5 | - use Saito\DomainParser; |
|
6 | - |
|
7 | - trait UrlParserTrait { |
|
8 | - |
|
9 | - protected function _email($url, $text = null) { |
|
10 | - if (empty($text)) { |
|
11 | - $text = null; |
|
12 | - } |
|
13 | - $url = str_replace('mailto:', '', $url); |
|
14 | - return $this->MailObfuscator->link($url, $text); |
|
15 | - } |
|
16 | - |
|
17 | - protected function _url($url, $text, $label = false, $truncate = false) { |
|
18 | - // add http:// to URLs without protocol |
|
19 | - if (strpos($url, '://') === false) { |
|
20 | - // use Cakes Validation class to detect valid URL |
|
21 | - \App::uses('Validation', 'Utility'); |
|
22 | - if (\Validation::url($url)) { |
|
23 | - $url = 'http://' . $url; |
|
24 | - } |
|
25 | - } |
|
26 | - |
|
27 | - if ($truncate === true) { |
|
28 | - $text = $this->_truncate($text); |
|
29 | - } |
|
30 | - $out = "<a href='$url'>$text</a>"; |
|
31 | - |
|
32 | - $out = $this->_decorateTarget($out); |
|
33 | - |
|
34 | - // add domain info: `[url=domain.info]my link[/url]` -> `my link [domain.info]` |
|
35 | - if ($label !== false && $label !== 'none' && $label !== 'false') { |
|
36 | - if (!empty($url) && preg_match('/\<img\s*?src=/', $text) !== 1) { |
|
37 | - $host = DomainParser::domainAndTld($url); |
|
38 | - if ($host !== false && $host !== env('SERVER_NAME')) { |
|
39 | - $out .= ' <span class=\'richtext-linkInfo\'>[' . $host . ']</span>'; |
|
40 | - } |
|
41 | - } |
|
42 | - } |
|
43 | - return $out; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Truncates long links |
|
48 | - * |
|
49 | - * @bogus does this truncate strings or the longest word in the string or what? |
|
50 | - * @bogus what about [url=][img]...[/img][url]. Is the [img] url truncated too? |
|
51 | - * |
|
52 | - * @param type $string |
|
53 | - * @throws \Exception |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - protected function _truncate($string) { |
|
57 | - if (!isset($this->_sOptions['text_word_maxlength'])) { |
|
58 | - throw new \Exception('Text word maxlength not set.'); |
|
59 | - } |
|
60 | - $_textWordMaxLength = $this->_sOptions['text_word_maxlength']; |
|
61 | - |
|
62 | - if (mb_strlen($string) <= $_textWordMaxLength) { |
|
63 | - return $string; |
|
64 | - } |
|
65 | - |
|
66 | - $_placeholder = ' … '; |
|
67 | - $leftMargin = (int)floor($_textWordMaxLength / 2); |
|
68 | - $rightMargin = (int)(-1 * ($_textWordMaxLength - $leftMargin - mb_strlen($_placeholder))); |
|
69 | - |
|
70 | - $string = mb_substr($string, 0, $leftMargin) . $_placeholder . |
|
71 | - mb_substr($string, $rightMargin); |
|
72 | - return $string; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Adds target="_blank" to *all* external links in arbitrary string $string |
|
77 | - * |
|
78 | - * @param $string |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - protected function _decorateTarget($string) { |
|
82 | - $decorator = function ($matches) { |
|
83 | - $out = ''; |
|
84 | - $url = $matches[1]; |
|
85 | - |
|
86 | - // preventing error message for parse_url('http://'); |
|
87 | - if (substr($url, -3) === '://') { |
|
88 | - return $matches[0]; |
|
89 | - } |
|
90 | - $parsedUrl = @parse_url($url); |
|
91 | - |
|
92 | - if (isset($parsedUrl['host'])) { |
|
93 | - if ($parsedUrl['host'] !== env('SERVER_NAME') && $parsedUrl['host'] !== "www." . env('SERVER_NAME')) { |
|
94 | - $out = " rel='external' target='_blank'"; |
|
95 | - } |
|
96 | - } |
|
97 | - return $matches[0] . $out; |
|
98 | - }; |
|
99 | - |
|
100 | - return preg_replace_callback('#href=["\'](.*?)["\']#is', |
|
101 | - $decorator, $string); |
|
102 | - } |
|
103 | - |
|
104 | - } |
|
105 | 3 | \ No newline at end of file |
4 | + namespace Plugin\BbcodeParser\Lib\Helper; |
|
5 | + |
|
6 | + use Saito\DomainParser; |
|
7 | + |
|
8 | + trait UrlParserTrait { |
|
9 | + |
|
10 | + protected function _email($url, $text = null) { |
|
11 | + if (empty($text)) { |
|
12 | + $text = null; |
|
13 | + } |
|
14 | + $url = str_replace('mailto:', '', $url); |
|
15 | + return $this->MailObfuscator->link($url, $text); |
|
16 | + } |
|
17 | + |
|
18 | + protected function _url($url, $text, $label = false, $truncate = false) { |
|
19 | + // add http:// to URLs without protocol |
|
20 | + if (strpos($url, '://') === false) { |
|
21 | + // use Cakes Validation class to detect valid URL |
|
22 | + \App::uses('Validation', 'Utility'); |
|
23 | + if (\Validation::url($url)) { |
|
24 | + $url = 'http://' . $url; |
|
25 | + } |
|
26 | + } |
|
27 | + |
|
28 | + if ($truncate === true) { |
|
29 | + $text = $this->_truncate($text); |
|
30 | + } |
|
31 | + $out = "<a href='$url'>$text</a>"; |
|
32 | + |
|
33 | + $out = $this->_decorateTarget($out); |
|
34 | + |
|
35 | + // add domain info: `[url=domain.info]my link[/url]` -> `my link [domain.info]` |
|
36 | + if ($label !== false && $label !== 'none' && $label !== 'false') { |
|
37 | + if (!empty($url) && preg_match('/\<img\s*?src=/', $text) !== 1) { |
|
38 | + $host = DomainParser::domainAndTld($url); |
|
39 | + if ($host !== false && $host !== env('SERVER_NAME')) { |
|
40 | + $out .= ' <span class=\'richtext-linkInfo\'>[' . $host . ']</span>'; |
|
41 | + } |
|
42 | + } |
|
43 | + } |
|
44 | + return $out; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Truncates long links |
|
49 | + * |
|
50 | + * @bogus does this truncate strings or the longest word in the string or what? |
|
51 | + * @bogus what about [url=][img]...[/img][url]. Is the [img] url truncated too? |
|
52 | + * |
|
53 | + * @param type $string |
|
54 | + * @throws \Exception |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + protected function _truncate($string) { |
|
58 | + if (!isset($this->_sOptions['text_word_maxlength'])) { |
|
59 | + throw new \Exception('Text word maxlength not set.'); |
|
60 | + } |
|
61 | + $_textWordMaxLength = $this->_sOptions['text_word_maxlength']; |
|
62 | + |
|
63 | + if (mb_strlen($string) <= $_textWordMaxLength) { |
|
64 | + return $string; |
|
65 | + } |
|
66 | + |
|
67 | + $_placeholder = ' … '; |
|
68 | + $leftMargin = (int)floor($_textWordMaxLength / 2); |
|
69 | + $rightMargin = (int)(-1 * ($_textWordMaxLength - $leftMargin - mb_strlen($_placeholder))); |
|
70 | + |
|
71 | + $string = mb_substr($string, 0, $leftMargin) . $_placeholder . |
|
72 | + mb_substr($string, $rightMargin); |
|
73 | + return $string; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Adds target="_blank" to *all* external links in arbitrary string $string |
|
78 | + * |
|
79 | + * @param $string |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + protected function _decorateTarget($string) { |
|
83 | + $decorator = function ($matches) { |
|
84 | + $out = ''; |
|
85 | + $url = $matches[1]; |
|
86 | + |
|
87 | + // preventing error message for parse_url('http://'); |
|
88 | + if (substr($url, -3) === '://') { |
|
89 | + return $matches[0]; |
|
90 | + } |
|
91 | + $parsedUrl = @parse_url($url); |
|
92 | + |
|
93 | + if (isset($parsedUrl['host'])) { |
|
94 | + if ($parsedUrl['host'] !== env('SERVER_NAME') && $parsedUrl['host'] !== "www." . env('SERVER_NAME')) { |
|
95 | + $out = " rel='external' target='_blank'"; |
|
96 | + } |
|
97 | + } |
|
98 | + return $matches[0] . $out; |
|
99 | + }; |
|
100 | + |
|
101 | + return preg_replace_callback('#href=["\'](.*?)["\']#is', |
|
102 | + $decorator, $string); |
|
103 | + } |
|
104 | + |
|
105 | + } |
|
106 | 106 | \ No newline at end of file |
@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | } |
61 | 61 | } |
62 | 62 | krsort($names); |
63 | - $baseUrl = $this->_sOptions['webroot'] . $this->_sOptions['atBaseUrl']; |
|
63 | + $baseUrl = $this->_sOptions['webroot'].$this->_sOptions['atBaseUrl']; |
|
64 | 64 | foreach ($names as $name => $v) { |
65 | 65 | $title = urlencode($name); |
66 | - $link = $this->_url($baseUrl . $title, "@$name", |
|
66 | + $link = $this->_url($baseUrl.$title, "@$name", |
|
67 | 67 | false); |
68 | 68 | $string = str_replace("@$name", $link, $string); |
69 | 69 | } |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | protected function _autolink($string) { |
75 | - $replace = function ($matches) { |
|
75 | + $replace = function($matches) { |
|
76 | 76 | // exclude punctuation at end of sentence from URLs |
77 | 77 | $ignoredEndChars = implode('|', [',', '\?', ',', '\.', '\)', '!']); |
78 | 78 | preg_match( |
79 | - '/(?P<element>.*?)(?P<suffix>' . $ignoredEndChars . ')?$/', |
|
79 | + '/(?P<element>.*?)(?P<suffix>'.$ignoredEndChars.')?$/', |
|
80 | 80 | $matches['element'], |
81 | 81 | $m |
82 | 82 | ); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $matches = $m + $matches; |
85 | 85 | |
86 | 86 | if (strpos($matches['element'], '://') === false) { |
87 | - $matches['element'] = 'http://' . $matches['element']; |
|
87 | + $matches['element'] = 'http://'.$matches['element']; |
|
88 | 88 | } |
89 | 89 | $matches += [ |
90 | 90 | 'prefix' => '', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | |
94 | 94 | $url = $this->_url($matches['element'], $matches['element'], false, |
95 | 95 | true); |
96 | - return $matches['prefix'] . $url . $matches['suffix']; |
|
96 | + return $matches['prefix'].$url.$matches['suffix']; |
|
97 | 97 | }; |
98 | 98 | |
99 | 99 | //# autolink http://urls |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | //# autolink email |
114 | 114 | $string = preg_replace_callback( |
115 | 115 | "#(?<=^|[\n ])(?P<content>([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+))#i", |
116 | - function ($matches) { |
|
116 | + function($matches) { |
|
117 | 117 | return $this->_email($matches['content']); |
118 | 118 | }, $string |
119 | 119 | ); |
@@ -122,12 +122,12 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | protected function _hashLink($string) { |
125 | - $baseUrl = $this->_sOptions['webroot'] . $this->_sOptions['hashBaseUrl']; |
|
125 | + $baseUrl = $this->_sOptions['webroot'].$this->_sOptions['hashBaseUrl']; |
|
126 | 126 | $string = preg_replace_callback( |
127 | 127 | '/(?<=\s|^|])(?<tag>#)(?<element>\d+)(?!\w)/', |
128 | - function ($m) use ($baseUrl) { |
|
128 | + function($m) use ($baseUrl) { |
|
129 | 129 | $hash = $m['element']; |
130 | - return $this->_url($baseUrl . $hash, '#' . $hash); |
|
130 | + return $this->_url($baseUrl.$hash, '#'.$hash); |
|
131 | 131 | }, |
132 | 132 | $string |
133 | 133 | ); |
@@ -1,137 +1,137 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | - namespace Plugin\BbcodeParser\Lib\jBBCode\Visitors; |
|
3 | + namespace Plugin\BbcodeParser\Lib\jBBCode\Visitors; |
|
4 | 4 | |
5 | - use Plugin\BbcodeParser\Lib\Helper\UrlParserTrait; |
|
5 | + use Plugin\BbcodeParser\Lib\Helper\UrlParserTrait; |
|
6 | 6 | |
7 | - class JbbCodeAutolinkVisitor extends JbbCodeTextVisitor { |
|
7 | + class JbbCodeAutolinkVisitor extends JbbCodeTextVisitor { |
|
8 | 8 | |
9 | - use UrlParserTrait; |
|
9 | + use UrlParserTrait; |
|
10 | 10 | |
11 | - protected $_disallowedTags = ['code']; |
|
11 | + protected $_disallowedTags = ['code']; |
|
12 | 12 | |
13 | - protected function _processTextNode($string, $node) { |
|
14 | - // don't auto-link in url tags; problem is that 'urlWithAttributes' definition |
|
15 | - // reuses 'url' tag with ParseContent = true |
|
16 | - if ($node->getParent()->getTagName() === 'url') { |
|
17 | - return $string; |
|
18 | - } |
|
19 | - $string = $this->_hashLink($string); |
|
20 | - $string = $this->_atUserLink($string); |
|
21 | - return $this->_autolink($string); |
|
22 | - } |
|
13 | + protected function _processTextNode($string, $node) { |
|
14 | + // don't auto-link in url tags; problem is that 'urlWithAttributes' definition |
|
15 | + // reuses 'url' tag with ParseContent = true |
|
16 | + if ($node->getParent()->getTagName() === 'url') { |
|
17 | + return $string; |
|
18 | + } |
|
19 | + $string = $this->_hashLink($string); |
|
20 | + $string = $this->_atUserLink($string); |
|
21 | + return $this->_autolink($string); |
|
22 | + } |
|
23 | 23 | |
24 | - protected function _atUserLink($string) { |
|
25 | - $tags = array(); |
|
24 | + protected function _atUserLink($string) { |
|
25 | + $tags = array(); |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | * - '\pP' all unicode punctuation marks |
29 | 29 | * - '<' if nl2br has taken place whatchout for <br /> linebreaks |
30 | 30 | */ |
31 | - $hasTags = preg_match_all('/(\s|^)@([^\s\pP<]+)/m', $string, $tags); |
|
32 | - if (!$hasTags) { |
|
33 | - return $string; |
|
34 | - } |
|
35 | - |
|
36 | - // would be cleaner to pass userlist by value, but for performance reasons |
|
37 | - // we only query the db if we actually have any @ tags |
|
38 | - $users = $this->_sOptions['UserList']->get(); |
|
39 | - sort($users); |
|
40 | - $names = array(); |
|
41 | - if (empty($tags[2]) === false) { |
|
42 | - $tags = $tags[2]; |
|
43 | - foreach ($tags as $tag) { |
|
44 | - if (in_array($tag, $users)) { |
|
45 | - $names[$tag] = 1; |
|
46 | - } else { |
|
47 | - $continue = 0; |
|
48 | - foreach ($users as $user) { |
|
49 | - if (mb_strpos($user, $tag) === 0) { |
|
50 | - $names[$user] = 1; |
|
51 | - $continue = true; |
|
52 | - } |
|
53 | - if ($continue === false) { |
|
54 | - break; |
|
55 | - } elseif ($continue !== 0) { |
|
56 | - $continue = false; |
|
57 | - } |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
62 | - krsort($names); |
|
63 | - $baseUrl = $this->_sOptions['webroot'] . $this->_sOptions['atBaseUrl']; |
|
64 | - foreach ($names as $name => $v) { |
|
65 | - $title = urlencode($name); |
|
66 | - $link = $this->_url($baseUrl . $title, "@$name", |
|
67 | - false); |
|
68 | - $string = str_replace("@$name", $link, $string); |
|
69 | - } |
|
70 | - |
|
71 | - return $string; |
|
72 | - } |
|
73 | - |
|
74 | - protected function _autolink($string) { |
|
75 | - $replace = function ($matches) { |
|
76 | - // exclude punctuation at end of sentence from URLs |
|
77 | - $ignoredEndChars = implode('|', [',', '\?', ',', '\.', '\)', '!']); |
|
78 | - preg_match( |
|
79 | - '/(?P<element>.*?)(?P<suffix>' . $ignoredEndChars . ')?$/', |
|
80 | - $matches['element'], |
|
81 | - $m |
|
82 | - ); |
|
83 | - // keep ['element'] and ['suffix'] and include ['prefix'] |
|
84 | - $matches = $m + $matches; |
|
85 | - |
|
86 | - if (strpos($matches['element'], '://') === false) { |
|
87 | - $matches['element'] = 'http://' . $matches['element']; |
|
88 | - } |
|
89 | - $matches += [ |
|
90 | - 'prefix' => '', |
|
91 | - 'suffix' => '' |
|
92 | - ]; |
|
93 | - |
|
94 | - $url = $this->_url($matches['element'], $matches['element'], false, |
|
95 | - true); |
|
96 | - return $matches['prefix'] . $url . $matches['suffix']; |
|
97 | - }; |
|
98 | - |
|
99 | - //# autolink http://urls |
|
100 | - $string = preg_replace_callback( |
|
101 | - "#(?<=^|[\n (])(?P<element>[\w]+?://.*?[^ \"\n\r\t<]*)#is", |
|
102 | - $replace, |
|
103 | - $string |
|
104 | - ); |
|
105 | - |
|
106 | - //# autolink without http://, i.e. www.foo.bar/baz |
|
107 | - $string = preg_replace_callback( |
|
108 | - "#(?P<prefix>^|[\n (])(?P<element>(www|ftp)\.[\w\-]+\.[\w\-.\~]+(?:/[^ \"\t\n\r<]*)?)#is", |
|
109 | - $replace, |
|
110 | - $string |
|
111 | - ); |
|
112 | - |
|
113 | - //# autolink email |
|
114 | - $string = preg_replace_callback( |
|
115 | - "#(?<=^|[\n ])(?P<content>([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+))#i", |
|
116 | - function ($matches) { |
|
117 | - return $this->_email($matches['content']); |
|
118 | - }, $string |
|
119 | - ); |
|
120 | - |
|
121 | - return $string; |
|
122 | - } |
|
123 | - |
|
124 | - protected function _hashLink($string) { |
|
125 | - $baseUrl = $this->_sOptions['webroot'] . $this->_sOptions['hashBaseUrl']; |
|
126 | - $string = preg_replace_callback( |
|
127 | - '/(?<=\s|^|])(?<tag>#)(?<element>\d+)(?!\w)/', |
|
128 | - function ($m) use ($baseUrl) { |
|
129 | - $hash = $m['element']; |
|
130 | - return $this->_url($baseUrl . $hash, '#' . $hash); |
|
131 | - }, |
|
132 | - $string |
|
133 | - ); |
|
134 | - return $string; |
|
135 | - } |
|
136 | - |
|
137 | - } |
|
31 | + $hasTags = preg_match_all('/(\s|^)@([^\s\pP<]+)/m', $string, $tags); |
|
32 | + if (!$hasTags) { |
|
33 | + return $string; |
|
34 | + } |
|
35 | + |
|
36 | + // would be cleaner to pass userlist by value, but for performance reasons |
|
37 | + // we only query the db if we actually have any @ tags |
|
38 | + $users = $this->_sOptions['UserList']->get(); |
|
39 | + sort($users); |
|
40 | + $names = array(); |
|
41 | + if (empty($tags[2]) === false) { |
|
42 | + $tags = $tags[2]; |
|
43 | + foreach ($tags as $tag) { |
|
44 | + if (in_array($tag, $users)) { |
|
45 | + $names[$tag] = 1; |
|
46 | + } else { |
|
47 | + $continue = 0; |
|
48 | + foreach ($users as $user) { |
|
49 | + if (mb_strpos($user, $tag) === 0) { |
|
50 | + $names[$user] = 1; |
|
51 | + $continue = true; |
|
52 | + } |
|
53 | + if ($continue === false) { |
|
54 | + break; |
|
55 | + } elseif ($continue !== 0) { |
|
56 | + $continue = false; |
|
57 | + } |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | + krsort($names); |
|
63 | + $baseUrl = $this->_sOptions['webroot'] . $this->_sOptions['atBaseUrl']; |
|
64 | + foreach ($names as $name => $v) { |
|
65 | + $title = urlencode($name); |
|
66 | + $link = $this->_url($baseUrl . $title, "@$name", |
|
67 | + false); |
|
68 | + $string = str_replace("@$name", $link, $string); |
|
69 | + } |
|
70 | + |
|
71 | + return $string; |
|
72 | + } |
|
73 | + |
|
74 | + protected function _autolink($string) { |
|
75 | + $replace = function ($matches) { |
|
76 | + // exclude punctuation at end of sentence from URLs |
|
77 | + $ignoredEndChars = implode('|', [',', '\?', ',', '\.', '\)', '!']); |
|
78 | + preg_match( |
|
79 | + '/(?P<element>.*?)(?P<suffix>' . $ignoredEndChars . ')?$/', |
|
80 | + $matches['element'], |
|
81 | + $m |
|
82 | + ); |
|
83 | + // keep ['element'] and ['suffix'] and include ['prefix'] |
|
84 | + $matches = $m + $matches; |
|
85 | + |
|
86 | + if (strpos($matches['element'], '://') === false) { |
|
87 | + $matches['element'] = 'http://' . $matches['element']; |
|
88 | + } |
|
89 | + $matches += [ |
|
90 | + 'prefix' => '', |
|
91 | + 'suffix' => '' |
|
92 | + ]; |
|
93 | + |
|
94 | + $url = $this->_url($matches['element'], $matches['element'], false, |
|
95 | + true); |
|
96 | + return $matches['prefix'] . $url . $matches['suffix']; |
|
97 | + }; |
|
98 | + |
|
99 | + //# autolink http://urls |
|
100 | + $string = preg_replace_callback( |
|
101 | + "#(?<=^|[\n (])(?P<element>[\w]+?://.*?[^ \"\n\r\t<]*)#is", |
|
102 | + $replace, |
|
103 | + $string |
|
104 | + ); |
|
105 | + |
|
106 | + //# autolink without http://, i.e. www.foo.bar/baz |
|
107 | + $string = preg_replace_callback( |
|
108 | + "#(?P<prefix>^|[\n (])(?P<element>(www|ftp)\.[\w\-]+\.[\w\-.\~]+(?:/[^ \"\t\n\r<]*)?)#is", |
|
109 | + $replace, |
|
110 | + $string |
|
111 | + ); |
|
112 | + |
|
113 | + //# autolink email |
|
114 | + $string = preg_replace_callback( |
|
115 | + "#(?<=^|[\n ])(?P<content>([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+))#i", |
|
116 | + function ($matches) { |
|
117 | + return $this->_email($matches['content']); |
|
118 | + }, $string |
|
119 | + ); |
|
120 | + |
|
121 | + return $string; |
|
122 | + } |
|
123 | + |
|
124 | + protected function _hashLink($string) { |
|
125 | + $baseUrl = $this->_sOptions['webroot'] . $this->_sOptions['hashBaseUrl']; |
|
126 | + $string = preg_replace_callback( |
|
127 | + '/(?<=\s|^|])(?<tag>#)(?<element>\d+)(?!\w)/', |
|
128 | + function ($m) use ($baseUrl) { |
|
129 | + $hash = $m['element']; |
|
130 | + return $this->_url($baseUrl . $hash, '#' . $hash); |
|
131 | + }, |
|
132 | + $string |
|
133 | + ); |
|
134 | + return $string; |
|
135 | + } |
|
136 | + |
|
137 | + } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | protected function _audio($content) { |
20 | 20 | $out = "<audio src='$content' controls='controls'>"; |
21 | 21 | $out .= Message::format(__( |
22 | - 'Your browser does not support HTML5 audio. Please updgrade to a modern ' . |
|
22 | + 'Your browser does not support HTML5 audio. Please updgrade to a modern '. |
|
23 | 23 | 'browser. In order to watch this stream you need an HTML5 capable browser.', |
24 | 24 | true)); |
25 | 25 | $out .= "</audio>"; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | protected function _video($content) { |
30 | 30 | // fix audio files mistakenly wrapped into an [video] tag |
31 | - if (preg_match('/(' . implode('|', self::$_html5AudioExtensions) . ')$/i', |
|
31 | + if (preg_match('/('.implode('|', self::$_html5AudioExtensions).')$/i', |
|
32 | 32 | $content) === 1 |
33 | 33 | ) { |
34 | 34 | return $this->_audio($content); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | $out = "<video src='$content' controls='controls' x-webkit-airplay='allow'>"; |
38 | 38 | $out .= Message::format(__( |
39 | - 'Your browser does not support HTML5 video. Please updgrade to a modern ' . |
|
39 | + 'Your browser does not support HTML5 video. Please updgrade to a modern '. |
|
40 | 40 | 'browser. In order to watch this stream you need an HTML5 capable browser.', |
41 | 41 | true)); |
42 | 42 | $out .= '</video>'; |
@@ -1,67 +1,67 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | - namespace Plugin\BbcodeParser\Lib\jBBCode\Definitions; |
|
3 | + namespace Plugin\BbcodeParser\Lib\jBBCode\Definitions; |
|
4 | 4 | |
5 | - use Plugin\BbcodeParser\Lib\Helper\Message; |
|
5 | + use Plugin\BbcodeParser\Lib\Helper\Message; |
|
6 | 6 | |
7 | - abstract class Html5Media extends CodeDefinition { |
|
7 | + abstract class Html5Media extends CodeDefinition { |
|
8 | 8 | |
9 | - protected $_sParseContent = false; |
|
9 | + protected $_sParseContent = false; |
|
10 | 10 | |
11 | - protected static $_html5AudioExtensions = array( |
|
12 | - 'm4a', |
|
13 | - 'ogg', |
|
14 | - 'opus', |
|
15 | - 'mp3', |
|
16 | - 'wav', |
|
17 | - ); |
|
11 | + protected static $_html5AudioExtensions = array( |
|
12 | + 'm4a', |
|
13 | + 'ogg', |
|
14 | + 'opus', |
|
15 | + 'mp3', |
|
16 | + 'wav', |
|
17 | + ); |
|
18 | 18 | |
19 | - protected function _audio($content) { |
|
20 | - $out = "<audio src='$content' controls='controls'>"; |
|
21 | - $out .= Message::format(__( |
|
22 | - 'Your browser does not support HTML5 audio. Please updgrade to a modern ' . |
|
23 | - 'browser. In order to watch this stream you need an HTML5 capable browser.', |
|
24 | - true)); |
|
25 | - $out .= "</audio>"; |
|
26 | - return $out; |
|
27 | - } |
|
19 | + protected function _audio($content) { |
|
20 | + $out = "<audio src='$content' controls='controls'>"; |
|
21 | + $out .= Message::format(__( |
|
22 | + 'Your browser does not support HTML5 audio. Please updgrade to a modern ' . |
|
23 | + 'browser. In order to watch this stream you need an HTML5 capable browser.', |
|
24 | + true)); |
|
25 | + $out .= "</audio>"; |
|
26 | + return $out; |
|
27 | + } |
|
28 | 28 | |
29 | - protected function _video($content) { |
|
30 | - // fix audio files mistakenly wrapped into an [video] tag |
|
31 | - if (preg_match('/(' . implode('|', self::$_html5AudioExtensions) . ')$/i', |
|
32 | - $content) === 1 |
|
33 | - ) { |
|
34 | - return $this->_audio($content); |
|
35 | - } |
|
29 | + protected function _video($content) { |
|
30 | + // fix audio files mistakenly wrapped into an [video] tag |
|
31 | + if (preg_match('/(' . implode('|', self::$_html5AudioExtensions) . ')$/i', |
|
32 | + $content) === 1 |
|
33 | + ) { |
|
34 | + return $this->_audio($content); |
|
35 | + } |
|
36 | 36 | |
37 | - $out = "<video src='$content' controls='controls' x-webkit-airplay='allow'>"; |
|
38 | - $out .= Message::format(__( |
|
39 | - 'Your browser does not support HTML5 video. Please updgrade to a modern ' . |
|
40 | - 'browser. In order to watch this stream you need an HTML5 capable browser.', |
|
41 | - true)); |
|
42 | - $out .= '</video>'; |
|
43 | - return $out; |
|
44 | - } |
|
37 | + $out = "<video src='$content' controls='controls' x-webkit-airplay='allow'>"; |
|
38 | + $out .= Message::format(__( |
|
39 | + 'Your browser does not support HTML5 video. Please updgrade to a modern ' . |
|
40 | + 'browser. In order to watch this stream you need an HTML5 capable browser.', |
|
41 | + true)); |
|
42 | + $out .= '</video>'; |
|
43 | + return $out; |
|
44 | + } |
|
45 | 45 | |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - class Html5Audio extends Html5Media { |
|
48 | + class Html5Audio extends Html5Media { |
|
49 | 49 | |
50 | - protected $_sTagName = 'audio'; |
|
50 | + protected $_sTagName = 'audio'; |
|
51 | 51 | |
52 | - protected function _parse($content, $attributes) { |
|
53 | - return $this->_audio($content); |
|
54 | - } |
|
52 | + protected function _parse($content, $attributes) { |
|
53 | + return $this->_audio($content); |
|
54 | + } |
|
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - class Html5Video extends Html5Media { |
|
58 | + class Html5Video extends Html5Media { |
|
59 | 59 | |
60 | - protected $_sTagName = 'video'; |
|
60 | + protected $_sTagName = 'video'; |
|
61 | 61 | |
62 | - protected function _parse($content, $attributes) { |
|
63 | - return $this->_video($content); |
|
64 | - } |
|
62 | + protected function _parse($content, $attributes) { |
|
63 | + return $this->_video($content); |
|
64 | + } |
|
65 | 65 | |
66 | - } |
|
66 | + } |
|
67 | 67 |
@@ -20,7 +20,7 @@ |
||
20 | 20 | // load config from app/Config/geshi.php |
21 | 21 | $this->Geshi->features = false; |
22 | 22 | |
23 | - $string = '<div class="geshi-wrapper"><pre lang="' . $type . '">' . $content . '</pre></div>'; |
|
23 | + $string = '<div class="geshi-wrapper"><pre lang="'.$type.'">'.$content.'</pre></div>'; |
|
24 | 24 | |
25 | 25 | $string = $this->Geshi->highlight($string); |
26 | 26 | return $string; |
@@ -1,36 +1,36 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | - namespace Plugin\BbcodeParser\Lib\jBBCode\Definitions; |
|
3 | + namespace Plugin\BbcodeParser\Lib\jBBCode\Definitions; |
|
4 | 4 | |
5 | - class CodeWithoutAttributes extends CodeDefinition { |
|
5 | + class CodeWithoutAttributes extends CodeDefinition { |
|
6 | 6 | |
7 | - protected $_sTagName = 'code'; |
|
7 | + protected $_sTagName = 'code'; |
|
8 | 8 | |
9 | - protected $_sParseContent = false; |
|
9 | + protected $_sParseContent = false; |
|
10 | 10 | |
11 | - protected function _parse($content, $attributes) { |
|
12 | - $type = 'text'; |
|
13 | - if (!empty($attributes['code'])) { |
|
14 | - $type = $attributes['code']; |
|
15 | - } |
|
11 | + protected function _parse($content, $attributes) { |
|
12 | + $type = 'text'; |
|
13 | + if (!empty($attributes['code'])) { |
|
14 | + $type = $attributes['code']; |
|
15 | + } |
|
16 | 16 | |
17 | - $this->Geshi->defaultLanguage = 'text'; |
|
18 | - // allow all languages |
|
19 | - $this->Geshi->validLanguages = [true]; |
|
20 | - // load config from app/Config/geshi.php |
|
21 | - $this->Geshi->features = false; |
|
17 | + $this->Geshi->defaultLanguage = 'text'; |
|
18 | + // allow all languages |
|
19 | + $this->Geshi->validLanguages = [true]; |
|
20 | + // load config from app/Config/geshi.php |
|
21 | + $this->Geshi->features = false; |
|
22 | 22 | |
23 | - $string = '<div class="geshi-wrapper"><pre lang="' . $type . '">' . $content . '</pre></div>'; |
|
23 | + $string = '<div class="geshi-wrapper"><pre lang="' . $type . '">' . $content . '</pre></div>'; |
|
24 | 24 | |
25 | - $string = $this->Geshi->highlight($string); |
|
26 | - return $string; |
|
27 | - } |
|
25 | + $string = $this->Geshi->highlight($string); |
|
26 | + return $string; |
|
27 | + } |
|
28 | 28 | |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - class CodeWithAttributes extends CodeWithoutAttributes { |
|
31 | + class CodeWithAttributes extends CodeWithoutAttributes { |
|
32 | 32 | |
33 | - protected $_sUseOptions = true; |
|
33 | + protected $_sUseOptions = true; |
|
34 | 34 | |
35 | - } |
|
35 | + } |
|
36 | 36 |
@@ -70,7 +70,7 @@ |
||
70 | 70 | 'className' => 'btn-markItUp-Link', |
71 | 71 | 'key' => 'L', |
72 | 72 | 'openWith' => |
73 | - '[url=[![' . __('geshi_link_popup') . ']!]]', |
|
73 | + '[url=[!['.__('geshi_link_popup').']!]]', |
|
74 | 74 | 'closeWith' => '[/url]', |
75 | 75 | 'placeHolder' => __('geshi_link_placeholder'), |
76 | 76 | ), |
@@ -1,92 +1,92 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | - namespace Plugin\BbcodeParser\Lib; |
|
3 | + namespace Plugin\BbcodeParser\Lib; |
|
4 | 4 | |
5 | - class Editor extends \Saito\Markup\Editor { |
|
5 | + class Editor extends \Saito\Markup\Editor { |
|
6 | 6 | |
7 | - public function getEditorHelp() { |
|
8 | - return $this->_Helper->SaitoHelp->icon('BbcodeParser.1', [ |
|
9 | - 'label' => __d('bbcode_parser', 'parsedAsBbcode') |
|
10 | - ]); |
|
11 | - } |
|
7 | + public function getEditorHelp() { |
|
8 | + return $this->_Helper->SaitoHelp->icon('BbcodeParser.1', [ |
|
9 | + 'label' => __d('bbcode_parser', 'parsedAsBbcode') |
|
10 | + ]); |
|
11 | + } |
|
12 | 12 | |
13 | - public function getMarkupSet() { |
|
14 | - return array( |
|
15 | - 'Bold' => array( |
|
16 | - 'name' => "<i class='fa fa-bold'></i>", |
|
17 | - 'title' => __('Bold'), |
|
18 | - 'className' => 'btn-markItUp-Bold', |
|
19 | - 'key' => 'B', |
|
20 | - 'openWith' => '[b]', |
|
21 | - 'closeWith' => '[/b]' |
|
22 | - ), |
|
23 | - 'Italic' => array( |
|
24 | - 'name' => "<i class='fa fa-italic'></i>", |
|
25 | - 'title' => __('Italic'), |
|
26 | - 'className' => 'btn-markItUp-Italic', |
|
27 | - 'key' => 'I', |
|
28 | - 'openWith' => '[i]', |
|
29 | - 'closeWith' => '[/i]' |
|
30 | - ), |
|
31 | - 'Stroke' => array( |
|
32 | - 'name' => "<i class='fa fa-strikethrough'></i>", |
|
33 | - 'title' => __('Strike Through'), |
|
34 | - 'className' => 'btn-markItUp-Stroke', |
|
35 | - 'openWith' => '[strike]', |
|
36 | - 'closeWith' => '[/strike]' |
|
37 | - ), |
|
38 | - 'Code' => array( |
|
39 | - 'name' => "<i class='fa fa-s-code'></i>", |
|
40 | - 'title' => __('Code'), |
|
41 | - 'className' => 'btn-markItUp-Code', |
|
42 | - 'openWith' => '[code=text]\n', |
|
43 | - 'closeWith' => '\n[/code]' |
|
44 | - ), |
|
45 | - 'Bulleted list' => array( |
|
46 | - 'name' => "<i class='fa fa-list-ul'></i>", |
|
47 | - 'title' => __('Bullet List'), |
|
48 | - 'className' => 'btn-markItUp-List', |
|
49 | - 'openWith' => '[list]\n[*] ', |
|
50 | - 'closeWith' => '\n[*]\n[/list]' |
|
51 | - ), |
|
52 | - 'Spoiler' => [ |
|
53 | - 'name' => "<i class='fa fa-stop'></i>", |
|
54 | - 'className' => 'btn-markItUp-Spoiler', |
|
55 | - 'title' => __('Spoiler'), |
|
56 | - 'openWith' => '[spoiler]', |
|
57 | - 'closeWith' => '[/spoiler]' |
|
58 | - ], |
|
59 | - 'Quote' => [ |
|
60 | - 'name' => "<i class='fa fa-quote-left'></i>", |
|
61 | - 'className' => 'btn-markItUp-Quote', |
|
62 | - 'title' => __('Cite'), |
|
63 | - 'openWith' => '[quote]', |
|
64 | - 'closeWith' => '[/quote]' |
|
65 | - ], |
|
66 | - 'separator', |
|
67 | - 'Link' => array( |
|
68 | - 'name' => "<i class='fa fa-link'></i>", |
|
69 | - 'title' => __('Link'), |
|
70 | - 'className' => 'btn-markItUp-Link', |
|
71 | - 'key' => 'L', |
|
72 | - 'openWith' => |
|
73 | - '[url=[![' . __('geshi_link_popup') . ']!]]', |
|
74 | - 'closeWith' => '[/url]', |
|
75 | - 'placeHolder' => __('geshi_link_placeholder'), |
|
76 | - ), |
|
77 | - 'Media' => array( |
|
78 | - 'name' => "<i class='fa fa-multimedia'></i>", |
|
79 | - 'className' => 'btn-markItUp-Media', |
|
80 | - 'title' => __('Media'), |
|
81 | - 'key' => 'P', |
|
82 | - ), |
|
83 | - 'Upload' => array( |
|
84 | - 'name' => '<i class=\'fa fa-upload\'></i>', |
|
85 | - 'title' => __('Upload'), |
|
86 | - 'className' => 'btn-markItUp-Upload' |
|
87 | - ), |
|
88 | - 'separator' |
|
89 | - ); |
|
90 | - } |
|
13 | + public function getMarkupSet() { |
|
14 | + return array( |
|
15 | + 'Bold' => array( |
|
16 | + 'name' => "<i class='fa fa-bold'></i>", |
|
17 | + 'title' => __('Bold'), |
|
18 | + 'className' => 'btn-markItUp-Bold', |
|
19 | + 'key' => 'B', |
|
20 | + 'openWith' => '[b]', |
|
21 | + 'closeWith' => '[/b]' |
|
22 | + ), |
|
23 | + 'Italic' => array( |
|
24 | + 'name' => "<i class='fa fa-italic'></i>", |
|
25 | + 'title' => __('Italic'), |
|
26 | + 'className' => 'btn-markItUp-Italic', |
|
27 | + 'key' => 'I', |
|
28 | + 'openWith' => '[i]', |
|
29 | + 'closeWith' => '[/i]' |
|
30 | + ), |
|
31 | + 'Stroke' => array( |
|
32 | + 'name' => "<i class='fa fa-strikethrough'></i>", |
|
33 | + 'title' => __('Strike Through'), |
|
34 | + 'className' => 'btn-markItUp-Stroke', |
|
35 | + 'openWith' => '[strike]', |
|
36 | + 'closeWith' => '[/strike]' |
|
37 | + ), |
|
38 | + 'Code' => array( |
|
39 | + 'name' => "<i class='fa fa-s-code'></i>", |
|
40 | + 'title' => __('Code'), |
|
41 | + 'className' => 'btn-markItUp-Code', |
|
42 | + 'openWith' => '[code=text]\n', |
|
43 | + 'closeWith' => '\n[/code]' |
|
44 | + ), |
|
45 | + 'Bulleted list' => array( |
|
46 | + 'name' => "<i class='fa fa-list-ul'></i>", |
|
47 | + 'title' => __('Bullet List'), |
|
48 | + 'className' => 'btn-markItUp-List', |
|
49 | + 'openWith' => '[list]\n[*] ', |
|
50 | + 'closeWith' => '\n[*]\n[/list]' |
|
51 | + ), |
|
52 | + 'Spoiler' => [ |
|
53 | + 'name' => "<i class='fa fa-stop'></i>", |
|
54 | + 'className' => 'btn-markItUp-Spoiler', |
|
55 | + 'title' => __('Spoiler'), |
|
56 | + 'openWith' => '[spoiler]', |
|
57 | + 'closeWith' => '[/spoiler]' |
|
58 | + ], |
|
59 | + 'Quote' => [ |
|
60 | + 'name' => "<i class='fa fa-quote-left'></i>", |
|
61 | + 'className' => 'btn-markItUp-Quote', |
|
62 | + 'title' => __('Cite'), |
|
63 | + 'openWith' => '[quote]', |
|
64 | + 'closeWith' => '[/quote]' |
|
65 | + ], |
|
66 | + 'separator', |
|
67 | + 'Link' => array( |
|
68 | + 'name' => "<i class='fa fa-link'></i>", |
|
69 | + 'title' => __('Link'), |
|
70 | + 'className' => 'btn-markItUp-Link', |
|
71 | + 'key' => 'L', |
|
72 | + 'openWith' => |
|
73 | + '[url=[![' . __('geshi_link_popup') . ']!]]', |
|
74 | + 'closeWith' => '[/url]', |
|
75 | + 'placeHolder' => __('geshi_link_placeholder'), |
|
76 | + ), |
|
77 | + 'Media' => array( |
|
78 | + 'name' => "<i class='fa fa-multimedia'></i>", |
|
79 | + 'className' => 'btn-markItUp-Media', |
|
80 | + 'title' => __('Media'), |
|
81 | + 'key' => 'P', |
|
82 | + ), |
|
83 | + 'Upload' => array( |
|
84 | + 'name' => '<i class=\'fa fa-upload\'></i>', |
|
85 | + 'title' => __('Upload'), |
|
86 | + 'className' => 'btn-markItUp-Upload' |
|
87 | + ), |
|
88 | + 'separator' |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | |
92 | - } |
|
93 | 92 | \ No newline at end of file |
93 | + } |
|
94 | 94 | \ No newline at end of file |