|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* Advanced BBCode Box |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright (c) 2013 Matt Friedman |
|
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace vse\abbc3\core; |
|
12
|
|
|
|
|
13
|
|
|
use phpbb\user; |
|
14
|
|
|
use vse\abbc3\ext; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* ABBC3 core BBCodes parser class |
|
18
|
|
|
*/ |
|
19
|
|
|
class bbcodes_parser |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var user */ |
|
22
|
|
|
protected $user; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor |
|
26
|
|
|
* |
|
27
|
|
|
* @param user $user User object |
|
28
|
|
|
* @access public |
|
29
|
|
|
*/ |
|
30
|
11 |
|
public function __construct(user $user) |
|
31
|
|
|
{ |
|
32
|
11 |
|
$this->user = $user; |
|
33
|
11 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Pre-Parser for special custom BBCodes created by ABBC3 |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $text The text to parse |
|
39
|
|
|
* @param string $uid The BBCode UID |
|
40
|
|
|
* @return string The parsed text |
|
41
|
|
|
* @access public |
|
42
|
|
|
*/ |
|
43
|
7 |
|
public function pre_parse_bbcodes($text, $uid) |
|
44
|
|
|
{ |
|
45
|
|
|
// bbvideo BBCodes (convert from older ABBC3 installations) |
|
46
|
7 |
|
$text = preg_replace_callback('#\[(bbvideo)[\s]?([0-9,]+)?:(' . $uid . ')\]([^[]+)\[/\1:\3\]#is', array($this, 'bbvideo_pass'), $text); |
|
47
|
|
|
|
|
48
|
7 |
|
return $text; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Post-Parser for special custom BBCodes created by ABBC3 |
|
53
|
|
|
* |
|
54
|
|
|
* @param string $text The text to parse |
|
55
|
|
|
* @return string The parsed text |
|
56
|
|
|
* @access public |
|
57
|
|
|
*/ |
|
58
|
4 |
|
public function post_parse_bbcodes($text) |
|
59
|
|
|
{ |
|
60
|
|
|
// hidden BBCode |
|
61
|
4 |
|
$text = preg_replace_callback('#<!-- ABBC3_BBCODE_HIDDEN -->(.*?)<!-- ABBC3_BBCODE_HIDDEN -->#s', array($this, 'hidden_pass'), $text); |
|
62
|
|
|
|
|
63
|
4 |
|
return $text; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Convert BBvideo from older ABBC3 posts to the new format |
|
68
|
|
|
* |
|
69
|
|
|
* @param array $matches 1=bbvideo, 2=width,height, 3=uid, 4=url |
|
70
|
|
|
* @return string BBvideo in the correct BBCode format |
|
71
|
|
|
* @access protected |
|
72
|
|
|
*/ |
|
73
|
4 |
|
protected function bbvideo_pass($matches) |
|
74
|
|
|
{ |
|
75
|
4 |
|
return (!empty($matches[2])) ? |
|
76
|
4 |
|
"[bbvideo=$matches[2]:$matches[3]]$matches[4][/bbvideo:$matches[3]]" : |
|
77
|
4 |
|
'[bbvideo=' . ext::BBVIDEO_WIDTH . ',' . ext::BBVIDEO_HEIGHT . ":$matches[3]]$matches[4][/bbvideo:$matches[3]]"; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Convert Hidden BBCode into its final appearance |
|
82
|
|
|
* |
|
83
|
|
|
* @param array $matches |
|
84
|
|
|
* @return string HTML render of hidden bbcode |
|
85
|
|
|
* @access protected |
|
86
|
|
|
*/ |
|
87
|
3 |
|
protected function hidden_pass($matches) |
|
88
|
|
|
{ |
|
89
|
3 |
|
if ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['is_bot']) |
|
90
|
3 |
|
{ |
|
91
|
|
|
$replacements = array( |
|
92
|
1 |
|
$this->user->lang('ABBC3_HIDDEN_ON'), |
|
93
|
1 |
|
$this->user->lang('ABBC3_HIDDEN_EXPLAIN'), |
|
94
|
1 |
|
'hidebox_hidden', |
|
95
|
1 |
|
); |
|
96
|
1 |
|
} |
|
97
|
|
|
else |
|
98
|
|
|
{ |
|
99
|
|
|
$replacements = array( |
|
100
|
2 |
|
$this->user->lang('ABBC3_HIDDEN_OFF'), |
|
101
|
2 |
|
$matches[1], |
|
102
|
2 |
|
'hidebox_visible', |
|
103
|
2 |
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
3 |
|
return vsprintf('<div class="hidebox %3$s"><div class="hidebox_title %3$s">%1$s</div><div class="%3$s">%2$s</div></div>', $replacements); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|