|
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 |
|
// functions_content events |
|
83
|
1 |
|
'core.modify_text_for_display_before' => 'parse_bbcodes_before', |
|
84
|
1 |
|
'core.modify_text_for_display_after' => 'parse_bbcodes_after', |
|
85
|
|
|
// functions_display events |
|
86
|
|
|
'core.display_custom_bbcodes' => 'setup_custom_bbcodes', |
|
87
|
1 |
|
'core.display_custom_bbcodes_modify_sql' => 'custom_bbcode_modify_sql', |
|
88
|
|
|
'core.display_custom_bbcodes_modify_row' => 'display_custom_bbcodes', |
|
89
|
|
|
// message_parser events |
|
90
|
1 |
|
'core.modify_format_display_text_after' => 'parse_bbcodes_after', |
|
91
|
1 |
|
// text_formatter events |
|
92
|
1 |
|
'core.text_formatter_s9e_parser_setup' => 's9e_allow_custom_bbcodes', |
|
93
|
|
|
'core.text_formatter_s9e_configure_after' => 's9e_configure_plugins', |
|
94
|
|
|
// BBCode FAQ |
|
95
|
|
|
'core.help_manager_add_block_after' => 'add_bbcode_faq', |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Load common files during user setup |
|
101
|
2 |
|
* |
|
102
|
|
|
* @param \phpbb\event\data $event The event object |
|
103
|
2 |
|
* @access public |
|
104
|
2 |
|
*/ |
|
105
|
2 |
|
public function load_language_on_setup($event) |
|
106
|
2 |
|
{ |
|
107
|
|
|
$lang_set_ext = $event['lang_set_ext']; |
|
108
|
2 |
|
$lang_set_ext[] = array( |
|
109
|
2 |
|
'ext_name' => 'vse/abbc3', |
|
110
|
|
|
'lang_set' => 'abbc3', |
|
111
|
|
|
); |
|
112
|
|
|
$event['lang_set_ext'] = $lang_set_ext; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Alter BBCodes before they are processed by phpBB |
|
117
|
|
|
* |
|
118
|
|
|
* This is used to change old/malformed ABBC3 BBCodes to a newer structure |
|
119
|
2 |
|
* |
|
120
|
|
|
* @param \phpbb\event\data $event The event object |
|
121
|
2 |
|
* @access public |
|
122
|
2 |
|
*/ |
|
123
|
|
|
public function parse_bbcodes_before($event) |
|
124
|
|
|
{ |
|
125
|
|
|
$event['text'] = $this->bbcodes_parser->pre_parse_bbcodes($event['text'], $event['uid']); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Alter BBCodes after they are processed by phpBB |
|
130
|
|
|
* |
|
131
|
|
|
* This is used on ABBC3 BBCodes that require additional post-processing |
|
132
|
4 |
|
* |
|
133
|
|
|
* @param \phpbb\event\data $event The event object |
|
134
|
4 |
|
* @access public |
|
135
|
4 |
|
*/ |
|
136
|
|
|
public function parse_bbcodes_after($event) |
|
137
|
|
|
{ |
|
138
|
|
|
$event['text'] = $this->bbcodes_parser->post_parse_bbcodes($event['text']); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Modify the SQL array to gather custom BBCode data |
|
143
|
2 |
|
* |
|
144
|
|
|
* @param \phpbb\event\data $event The event object |
|
145
|
2 |
|
* @access public |
|
146
|
2 |
|
*/ |
|
147
|
2 |
|
public function custom_bbcode_modify_sql($event) |
|
148
|
2 |
|
{ |
|
149
|
2 |
|
$sql_ary = $event['sql_ary']; |
|
150
|
|
|
$sql_ary['SELECT'] .= ', b.bbcode_group'; |
|
151
|
|
|
$sql_ary['ORDER_BY'] = 'b.bbcode_order, b.bbcode_id'; |
|
152
|
|
|
$event['sql_ary'] = $sql_ary; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
1 |
|
* Setup custom BBCode variables |
|
157
|
|
|
* |
|
158
|
1 |
|
* @access public |
|
159
|
1 |
|
*/ |
|
160
|
1 |
|
public function setup_custom_bbcodes() |
|
161
|
1 |
|
{ |
|
162
|
1 |
|
$this->template->assign_vars(array( |
|
163
|
|
|
'ABBC3_USERNAME' => $this->user->data['username'], |
|
164
|
1 |
|
'ABBC3_BBCODE_ICONS' => $this->ext_root_path . 'images/icons', |
|
165
|
1 |
|
'ABBC3_BBVIDEO_HEIGHT' => ext::BBVIDEO_HEIGHT, |
|
166
|
1 |
|
'ABBC3_BBVIDEO_WIDTH' => ext::BBVIDEO_WIDTH, |
|
167
|
1 |
|
|
|
168
|
1 |
|
'UA_ABBC3_BBVIDEO_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'bbvideo')), |
|
169
|
|
|
'UA_ABBC3_PIPES_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'pipes')), |
|
170
|
|
|
'UA_ABBC3_URL_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'url')), |
|
171
|
|
|
)); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Alter custom BBCodes display |
|
176
|
4 |
|
* |
|
177
|
|
|
* @param \phpbb\event\data $event The event object |
|
178
|
4 |
|
* @access public |
|
179
|
4 |
|
*/ |
|
180
|
|
|
public function display_custom_bbcodes($event) |
|
181
|
|
|
{ |
|
182
|
|
|
$event['custom_tags'] = $this->bbcodes_display->display_custom_bbcodes($event['custom_tags'], $event['row']); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Allow custom BBCodes based on user's group memberships |
|
187
|
2 |
|
* |
|
188
|
|
|
* @param \phpbb\event\data $event The event object |
|
189
|
2 |
|
* @access public |
|
190
|
2 |
|
*/ |
|
191
|
1 |
|
public function s9e_allow_custom_bbcodes($event) |
|
192
|
|
|
{ |
|
193
|
|
|
if (defined('IN_CRON')) |
|
194
|
1 |
|
{ |
|
195
|
1 |
|
return; // do no apply bbcode permissions if in a cron job (for 3.1 to 3.2 update reparsing) |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$this->bbcodes_display->allow_custom_bbcodes($event['parser']); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
1 |
|
* Configure s9e Plug Ins |
|
203
|
|
|
* |
|
204
|
1 |
|
* @param \phpbb\event\data $event The event object |
|
205
|
1 |
|
*/ |
|
206
|
1 |
|
public function s9e_configure_plugins($event) |
|
207
|
|
|
{ |
|
208
|
|
|
$configurator = $event['configurator']; |
|
209
|
|
|
$configurator->plugins->load('PipeTables'); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Add ABBC3 BBCodes to the BBCode FAQ after the HELP_BBCODE_BLOCK_OTHERS block |
|
214
|
|
|
* |
|
215
|
|
|
* @param \phpbb\event\data $event The event object |
|
216
|
|
|
* @access public |
|
217
|
|
|
*/ |
|
218
|
|
|
public function add_bbcode_faq($event) |
|
219
|
|
|
{ |
|
220
|
|
|
if ($event['block_name'] === 'HELP_BBCODE_BLOCK_OTHERS') |
|
221
|
|
|
{ |
|
222
|
|
|
$this->bbcodes_help->faq(); |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|