1 | <?php |
||
24 | class listener implements EventSubscriberInterface |
||
25 | { |
||
26 | /** @var bbcodes_parser */ |
||
27 | protected $bbcodes_parser; |
||
28 | |||
29 | /** @var bbcodes_display */ |
||
30 | protected $bbcodes_display; |
||
31 | |||
32 | /** @var helper */ |
||
33 | protected $helper; |
||
34 | |||
35 | /** @var template */ |
||
36 | protected $template; |
||
37 | |||
38 | /** @var user */ |
||
39 | protected $user; |
||
40 | |||
41 | /** @var string phpBB root path */ |
||
42 | protected $ext_root_path; |
||
43 | |||
44 | /** |
||
45 | * Constructor |
||
46 | * |
||
47 | * @param bbcodes_parser $bbcodes_parser |
||
48 | * @param bbcodes_display $bbcodes_display |
||
49 | * @param helper $helper |
||
50 | * @param template $template |
||
51 | * @param user $user |
||
52 | * @param string $ext_root_path |
||
53 | * @access public |
||
54 | */ |
||
55 | 22 | public function __construct(bbcodes_parser $bbcodes_parser, bbcodes_display $bbcodes_display, helper $helper, template $template, user $user, $ext_root_path) |
|
|
|||
56 | { |
||
57 | 22 | $this->bbcodes_parser = $bbcodes_parser; |
|
58 | 22 | $this->bbcodes_display = $bbcodes_display; |
|
59 | 22 | $this->helper = $helper; |
|
60 | 22 | $this->template = $template; |
|
61 | 22 | $this->user = $user; |
|
62 | 22 | $this->ext_root_path = $ext_root_path; |
|
63 | 22 | } |
|
64 | |||
65 | /** |
||
66 | * Assign functions defined in this class to event listeners in the core |
||
67 | * |
||
68 | * @return array |
||
69 | * @static |
||
70 | * @access public |
||
71 | */ |
||
72 | 1 | static public function getSubscribedEvents() |
|
73 | { |
||
74 | return array( |
||
75 | 1 | 'core.user_setup' => 'load_language_on_setup', |
|
76 | |||
77 | // functions_content events |
||
78 | 1 | 'core.modify_text_for_display_before' => 'parse_bbcodes_before', |
|
79 | 1 | 'core.modify_text_for_display_after' => 'parse_bbcodes_after', |
|
80 | |||
81 | // functions_display events |
||
82 | 1 | 'core.display_custom_bbcodes' => 'setup_custom_bbcodes', |
|
83 | 1 | 'core.display_custom_bbcodes_modify_sql' => 'custom_bbcode_modify_sql', |
|
84 | 1 | 'core.display_custom_bbcodes_modify_row' => 'display_custom_bbcodes', |
|
85 | |||
86 | // message_parser events |
||
87 | 1 | 'core.modify_format_display_text_after' => 'parse_bbcodes_after', |
|
88 | 1 | 'core.modify_bbcode_init' => 'allow_custom_bbcodes', // Deprecated 3.2.x. Provides bc for 3.1.x. |
|
89 | |||
90 | // text_formatter events |
||
91 | 1 | 'core.text_formatter_s9e_parser_setup' => 's9e_allow_custom_bbcodes', |
|
92 | 1 | ); |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * Load common files during user setup |
||
97 | * |
||
98 | * @param object $event The event object |
||
99 | * @return null |
||
100 | * @access public |
||
101 | */ |
||
102 | 2 | public function load_language_on_setup($event) |
|
111 | |||
112 | /** |
||
113 | * Alter BBCodes before they are processed by phpBB |
||
114 | * |
||
115 | * This is used to change old/malformed ABBC3 BBCodes to a newer structure |
||
116 | * |
||
117 | * @param object $event The event object |
||
118 | * @return null |
||
119 | * @access public |
||
120 | */ |
||
121 | 2 | public function parse_bbcodes_before($event) |
|
125 | |||
126 | /** |
||
127 | * Alter BBCodes after they are processed by phpBB |
||
128 | * |
||
129 | * This is used on ABBC3 BBCodes that require additional post-processing |
||
130 | * |
||
131 | * @param object $event The event object |
||
132 | * @return null |
||
133 | * @access public |
||
134 | */ |
||
135 | 4 | public function parse_bbcodes_after($event) |
|
139 | |||
140 | /** |
||
141 | * Modify the SQL array to gather custom BBCode data |
||
142 | * |
||
143 | * @param object $event The event object |
||
144 | * @return null |
||
145 | * @access public |
||
146 | */ |
||
147 | 2 | public function custom_bbcode_modify_sql($event) |
|
148 | { |
||
149 | 2 | $sql_ary = $event['sql_ary']; |
|
150 | 2 | $sql_ary['SELECT'] .= ', b.bbcode_group'; |
|
151 | 2 | $sql_ary['ORDER_BY'] = 'b.bbcode_order, b.bbcode_id'; |
|
152 | 2 | $event['sql_ary'] = $sql_ary; |
|
153 | 2 | } |
|
154 | |||
155 | /** |
||
156 | * Setup custom BBCode variables |
||
157 | * |
||
158 | * @return null |
||
159 | * @access public |
||
160 | */ |
||
161 | 1 | public function setup_custom_bbcodes() |
|
162 | { |
||
163 | 1 | $this->template->assign_vars(array( |
|
164 | 1 | 'ABBC3_USERNAME' => $this->user->data['username'], |
|
165 | 1 | 'ABBC3_BBCODE_ICONS' => $this->ext_root_path . 'images/icons', |
|
166 | 1 | 'ABBC3_BBVIDEO_HEIGHT' => ext::BBVIDEO_HEIGHT, |
|
167 | 1 | 'ABBC3_BBVIDEO_WIDTH' => ext::BBVIDEO_WIDTH, |
|
168 | |||
169 | 1 | 'UA_ABBC3_BBVIDEO_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'bbvideo')), |
|
170 | 1 | 'UA_ABBC3_URL_WIZARD' => $this->helper->route('vse_abbc3_bbcode_wizard', array('mode' => 'url')), |
|
171 | 1 | )); |
|
172 | 1 | } |
|
173 | |||
174 | /** |
||
175 | * Alter custom BBCodes display |
||
176 | * |
||
177 | * @param object $event The event object |
||
178 | * @return null |
||
179 | * @access public |
||
180 | */ |
||
181 | 4 | public function display_custom_bbcodes($event) |
|
185 | |||
186 | /** |
||
187 | * Set custom BBCodes permissions |
||
188 | * |
||
189 | * @param object $event The event object |
||
190 | * @return null |
||
191 | * @access public |
||
192 | * |
||
193 | * @deprecated 3.2.0. Provides bc for phpBB 3.1.x. |
||
194 | */ |
||
195 | public function allow_custom_bbcodes($event) |
||
199 | |||
200 | /** |
||
201 | * Toggle custom BBCodes in the s9e\TextFormatter parser based on user's group memberships |
||
202 | * |
||
203 | * @param object $event The event object |
||
204 | * @return null |
||
205 | * @access public |
||
206 | */ |
||
207 | 2 | public function s9e_allow_custom_bbcodes($event) |
|
226 | } |
||
227 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.