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\event; |
12
|
|
|
|
13
|
|
|
use phpbb\controller\helper; |
14
|
|
|
use phpbb\template\template; |
15
|
|
|
use phpbb\user; |
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
17
|
|
|
use vse\abbc3\core\bbcodes_display; |
18
|
|
|
use vse\abbc3\core\bbcodes_help; |
19
|
|
|
use vse\abbc3\core\bbcodes_parser; |
20
|
|
|
use vse\abbc3\ext; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Event listener |
24
|
|
|
*/ |
25
|
|
|
class listener implements EventSubscriberInterface |
26
|
|
|
{ |
27
|
|
|
/** @var bbcodes_parser */ |
28
|
|
|
protected $bbcodes_parser; |
29
|
|
|
|
30
|
|
|
/** @var bbcodes_display */ |
31
|
|
|
protected $bbcodes_display; |
32
|
|
|
|
33
|
|
|
/** @var bbcodes_help */ |
34
|
|
|
protected $bbcodes_help; |
35
|
|
|
|
36
|
|
|
/** @var helper */ |
37
|
|
|
protected $helper; |
38
|
|
|
|
39
|
|
|
/** @var template */ |
40
|
|
|
protected $template; |
41
|
|
|
|
42
|
|
|
/** @var user */ |
43
|
|
|
protected $user; |
44
|
|
|
|
45
|
|
|
/** @var string phpBB root path */ |
46
|
|
|
protected $ext_root_path; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Constructor |
50
|
|
|
* |
51
|
|
|
* @param bbcodes_parser $bbcodes_parser |
52
|
|
|
* @param bbcodes_display $bbcodes_display |
53
|
|
|
* @param \vse\abbc3\core\bbcodes_help $bbcodes_help |
54
|
|
|
* @param helper $helper |
55
|
19 |
|
* @param template $template |
56
|
|
|
* @param user $user |
57
|
19 |
|
* @param string $ext_root_path |
58
|
19 |
|
* @access public |
59
|
19 |
|
*/ |
60
|
19 |
|
public function __construct(bbcodes_parser $bbcodes_parser, bbcodes_display $bbcodes_display, bbcodes_help $bbcodes_help, helper $helper, template $template, user $user, $ext_root_path) |
61
|
19 |
|
{ |
62
|
19 |
|
$this->bbcodes_parser = $bbcodes_parser; |
63
|
19 |
|
$this->bbcodes_display = $bbcodes_display; |
64
|
|
|
$this->bbcodes_help = $bbcodes_help; |
65
|
|
|
$this->helper = $helper; |
66
|
|
|
$this->template = $template; |
67
|
|
|
$this->user = $user; |
68
|
|
|
$this->ext_root_path = $ext_root_path; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
1 |
|
* Assign functions defined in this class to event listeners in the core |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
1 |
|
* @static |
76
|
|
|
* @access public |
77
|
|
|
*/ |
78
|
1 |
|
public static function getSubscribedEvents() |
79
|
1 |
|
{ |
80
|
|
|
return array( |
81
|
|
|
'core.user_setup' => 'load_language_on_setup', |
82
|
1 |
|
|
83
|
1 |
|
// functions_content events |
84
|
1 |
|
'core.modify_text_for_display_before' => 'parse_bbcodes_before', |
85
|
|
|
'core.modify_text_for_display_after' => 'parse_bbcodes_after', |
86
|
|
|
|
87
|
1 |
|
// functions_display events |
88
|
|
|
'core.display_custom_bbcodes' => 'setup_custom_bbcodes', |
89
|
|
|
'core.display_custom_bbcodes_modify_sql' => 'custom_bbcode_modify_sql', |
90
|
1 |
|
'core.display_custom_bbcodes_modify_row' => 'display_custom_bbcodes', |
91
|
1 |
|
|
92
|
1 |
|
// message_parser events |
93
|
|
|
'core.modify_format_display_text_after' => 'parse_bbcodes_after', |
94
|
|
|
|
95
|
|
|
// text_formatter events (for phpBB 3.2.x) |
96
|
|
|
'core.text_formatter_s9e_parser_setup' => 's9e_allow_custom_bbcodes', |
97
|
|
|
'core.text_formatter_s9e_configure_after' => 's9e_configure_plugins', |
98
|
|
|
|
99
|
|
|
// BBCode FAQ |
100
|
|
|
'core.help_manager_add_block_after' => 'add_bbcode_faq', |
101
|
2 |
|
); |
102
|
|
|
} |
103
|
2 |
|
|
104
|
2 |
|
/** |
105
|
2 |
|
* Load common files during user setup |
106
|
2 |
|
* |
107
|
|
|
* @param \phpbb\event\data $event The event object |
108
|
2 |
|
* @access public |
109
|
2 |
|
*/ |
110
|
|
|
public function load_language_on_setup($event) |
111
|
|
|
{ |
112
|
|
|
$lang_set_ext = $event['lang_set_ext']; |
113
|
|
|
$lang_set_ext[] = array( |
114
|
|
|
'ext_name' => 'vse/abbc3', |
115
|
|
|
'lang_set' => 'abbc3', |
116
|
|
|
); |
117
|
|
|
$event['lang_set_ext'] = $lang_set_ext; |
118
|
|
|
} |
119
|
2 |
|
|
120
|
|
|
/** |
121
|
2 |
|
* Alter BBCodes before they are processed by phpBB |
122
|
2 |
|
* |
123
|
|
|
* This is used to change old/malformed ABBC3 BBCodes to a newer structure |
124
|
|
|
* |
125
|
|
|
* @param \phpbb\event\data $event The event object |
126
|
|
|
* @access public |
127
|
|
|
*/ |
128
|
|
|
public function parse_bbcodes_before($event) |
129
|
|
|
{ |
130
|
|
|
$event['text'] = $this->bbcodes_parser->pre_parse_bbcodes($event['text'], $event['uid']); |
131
|
|
|
} |
132
|
4 |
|
|
133
|
|
|
/** |
134
|
4 |
|
* Alter BBCodes after they are processed by phpBB |
135
|
4 |
|
* |
136
|
|
|
* This is used on ABBC3 BBCodes that require additional post-processing |
137
|
|
|
* |
138
|
|
|
* @param \phpbb\event\data $event The event object |
139
|
|
|
* @access public |
140
|
|
|
*/ |
141
|
|
|
public function parse_bbcodes_after($event) |
142
|
|
|
{ |
143
|
2 |
|
$event['text'] = $this->bbcodes_parser->post_parse_bbcodes($event['text']); |
144
|
|
|
} |
145
|
2 |
|
|
146
|
2 |
|
/** |
147
|
2 |
|
* Modify the SQL array to gather custom BBCode data |
148
|
2 |
|
* |
149
|
2 |
|
* @param \phpbb\event\data $event The event object |
150
|
|
|
* @access public |
151
|
|
|
*/ |
152
|
|
|
public function custom_bbcode_modify_sql($event) |
153
|
|
|
{ |
154
|
|
|
$sql_ary = $event['sql_ary']; |
155
|
|
|
$sql_ary['SELECT'] .= ', b.bbcode_group'; |
156
|
1 |
|
$sql_ary['ORDER_BY'] = 'b.bbcode_order, b.bbcode_id'; |
157
|
|
|
$event['sql_ary'] = $sql_ary; |
158
|
1 |
|
} |
159
|
1 |
|
|
160
|
1 |
|
/** |
161
|
1 |
|
* Setup custom BBCode variables |
162
|
1 |
|
* |
163
|
|
|
* @access public |
164
|
1 |
|
*/ |
165
|
1 |
|
public function setup_custom_bbcodes() |
166
|
1 |
|
{ |
167
|
1 |
|
$this->template->assign_vars(array( |
168
|
1 |
|
'ABBC3_USERNAME' => $this->user->data['username'], |
169
|
|
|
'ABBC3_BBCODE_ICONS' => $this->ext_root_path . 'images/icons', |
170
|
|
|
'ABBC3_BBVIDEO_HEIGHT' => ext::BBVIDEO_HEIGHT, |
171
|
|
|
'ABBC3_BBVIDEO_WIDTH' => ext::BBVIDEO_WIDTH, |
172
|
|
|
|
173
|
|
|
'UA_ABBC3_BBVIDEO_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'bbvideo')), |
174
|
|
|
'UA_ABBC3_PIPES_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'pipes')), |
175
|
|
|
'UA_ABBC3_URL_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'url')), |
176
|
4 |
|
)); |
177
|
|
|
} |
178
|
4 |
|
|
179
|
4 |
|
/** |
180
|
|
|
* Alter custom BBCodes display |
181
|
|
|
* |
182
|
|
|
* @param \phpbb\event\data $event The event object |
183
|
|
|
* @access public |
184
|
|
|
*/ |
185
|
|
|
public function display_custom_bbcodes($event) |
186
|
|
|
{ |
187
|
2 |
|
$event['custom_tags'] = $this->bbcodes_display->display_custom_bbcodes($event['custom_tags'], $event['row']); |
188
|
|
|
} |
189
|
2 |
|
|
190
|
2 |
|
/** |
191
|
1 |
|
* Allow custom BBCodes based on user's group memberships |
192
|
|
|
* |
193
|
|
|
* @param \phpbb\event\data $event The event object |
194
|
1 |
|
* @access public |
195
|
1 |
|
*/ |
196
|
|
|
public function s9e_allow_custom_bbcodes($event) |
197
|
|
|
{ |
198
|
|
|
if (defined('IN_CRON')) |
199
|
|
|
{ |
200
|
|
|
return; // do no apply bbcode permissions if in a cron job (for 3.1 to 3.2 update reparsing) |
201
|
|
|
} |
202
|
1 |
|
|
203
|
|
|
$this->bbcodes_display->allow_custom_bbcodes($event['parser']); |
204
|
1 |
|
} |
205
|
1 |
|
|
206
|
1 |
|
/** |
207
|
|
|
* Configure s9e Plug Ins |
208
|
|
|
* |
209
|
|
|
* @param \phpbb\event\data $event The event object |
210
|
|
|
*/ |
211
|
|
|
public function s9e_configure_plugins($event) |
212
|
|
|
{ |
213
|
|
|
$configurator = $event['configurator']; |
214
|
|
|
$configurator->plugins->load('PipeTables'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Add ABBC3 BBCodes to the BBCode FAQ |
219
|
|
|
* |
220
|
|
|
* @param object $event The event object |
221
|
|
|
* @access public |
222
|
|
|
*/ |
223
|
|
|
public function add_bbcode_faq($event) |
224
|
|
|
{ |
225
|
|
|
// Add after the HELP_BBCODE_BLOCK_OTHERS block |
226
|
|
|
if ($event['block_name'] === 'HELP_BBCODE_BLOCK_OTHERS') |
227
|
|
|
{ |
228
|
|
|
$this->bbcodes_help->faq(); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|