Passed
Branch master (e751cb)
by Matt
02:48
created

listener   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 236
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 2 Features 0
Metric Value
eloc 70
dl 0
loc 236
ccs 61
cts 61
cp 1
rs 10
c 7
b 2
f 0
wmc 17

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 18 1
A load_language_on_setup() 0 8 1
A load_google_fonts() 0 5 1
A custom_bbcode_modify_sql() 0 6 1
A setup_custom_bbcodes() 0 12 1
A set_quick_reply() 0 3 2
A display_custom_bbcodes() 0 8 2
A configure_bbcodes() 0 8 1
A allow_custom_bbcodes() 0 8 2
A add_to_quickreply() 0 7 2
A __construct() 0 11 1
A add_bbcode_faq() 0 5 2
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\config\config;
0 ignored issues
show
Bug introduced by
The type phpbb\config\config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use phpbb\config\db_text;
0 ignored issues
show
Bug introduced by
The type phpbb\config\db_text was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use phpbb\language\language;
0 ignored issues
show
Bug introduced by
The type phpbb\language\language was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use phpbb\routing\helper;
0 ignored issues
show
Bug introduced by
The type phpbb\routing\helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use phpbb\template\template;
0 ignored issues
show
Bug introduced by
The type phpbb\template\template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use phpbb\user;
0 ignored issues
show
Bug introduced by
The type phpbb\user was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\EventD...ventSubscriberInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use vse\abbc3\core\bbcodes_display;
21
use vse\abbc3\core\bbcodes_help;
22
use vse\abbc3\core\bbcodes_config;
23
use vse\abbc3\ext;
24
25
/**
26
 * Event listener
27
 */
28
class listener implements EventSubscriberInterface
29
{
30
	/** @var bbcodes_config */
31
	protected $bbcodes_config;
32
33
	/** @var bbcodes_display */
34
	protected $bbcodes_display;
35
36
	/** @var bbcodes_help */
37
	protected $bbcodes_help;
38
39
	/** @var config */
40
	protected $config;
41
42
	/** @var db_text */
43
	protected $config_text;
44
45
	/** @var helper */
46
	protected $helper;
47
48
	/** @var language */
49
	protected $language;
50
51
	/** @var template */
52
	protected $template;
53
54
	/** @var user */
55
	protected $user;
56
57
	protected $quick_reply = false;
58
59 16
	/**
60 1
	 * Constructor
61 16
	 *
62 16
	 * @param bbcodes_config  $bbcodes_config
63 16
	 * @param bbcodes_display $bbcodes_display
64 16
	 * @param bbcodes_help    $bbcodes_help
65 16
	 * @param config          $config
66 16
	 * @param db_text         $db_text
67 16
	 * @param helper          $helper
68 16
	 * @param language        $language
69
	 * @param template        $template
70
	 * @param user            $user
71
	 * @access public
72
	 */
73
	public function __construct(bbcodes_config $bbcodes_config, bbcodes_display $bbcodes_display, bbcodes_help $bbcodes_help, config $config, db_text $db_text, helper $helper, language $language, template $template, user $user)
74
	{
75
		$this->bbcodes_config = $bbcodes_config;
76
		$this->bbcodes_display = $bbcodes_display;
77 2
		$this->bbcodes_help = $bbcodes_help;
78
		$this->config = $config;
79
		$this->config_text = $db_text;
80 1
		$this->helper = $helper;
81
		$this->template = $template;
82 1
		$this->user = $user;
83 1
		$this->language = $language;
84 1
	}
85
86 1
	/**
87 2
	 * Assign functions defined in this class to event listeners in the core
88
	 *
89 1
	 * @return array
90 1
	 * @static
91
	 * @access public
92
	 */
93
	public static function getSubscribedEvents()
94
	{
95
		return [
96
			'core.user_setup'							=> 'load_language_on_setup',
97
			'core.page_header' 							=> 'load_google_fonts',
98
			'core.adm_page_header' 						=> 'load_google_fonts',
99 2
100
			'core.display_custom_bbcodes'				=> 'setup_custom_bbcodes',
101 2
			'core.display_custom_bbcodes_modify_sql'	=> 'custom_bbcode_modify_sql',
102 2
			'core.display_custom_bbcodes_modify_row'	=> 'display_custom_bbcodes',
103 2
104 2
			'core.text_formatter_s9e_parser_setup'		=> 'allow_custom_bbcodes',
105
			'core.text_formatter_s9e_configure_after'	=> ['configure_bbcodes', -1], // force lowest priority
106 2
107 2
			'core.help_manager_add_block_after'			=> 'add_bbcode_faq',
108
109
			'core.viewtopic_modify_quick_reply_template_vars' 	=> 'set_quick_reply',
110
			'core.viewtopic_modify_page_title'					=> 'add_to_quickreply',
111
		];
112
	}
113
114
	/**
115 2
	 * Load common files during user setup
116
	 *
117 2
	 * @param \phpbb\event\data $event The event object
0 ignored issues
show
Bug introduced by
The type phpbb\event\data was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
118 2
	 * @access public
119 2
	 */
120 2
	public function load_language_on_setup($event)
121 2
	{
122
		$lang_set_ext = $event['lang_set_ext'];
123
		$lang_set_ext[] = [
124
			'ext_name' => 'vse/abbc3',
125
			'lang_set' => 'abbc3',
126
		];
127
		$event['lang_set_ext'] = $lang_set_ext;
128 1
	}
129
130 1
	/**
131 1
	 * Load Google fonts data
132 1
	 * For injecting Google Font names into the template
133
	 *
134 1
	 * @access public
135 1
	 */
136 1
	public function load_google_fonts()
137 1
	{
138 1
		$this->template->assign_var(
139
			'abbc3_google_fonts',
140
			json_decode($this->config_text->get('abbc3_google_fonts'), true)
141
		);
142
	}
143
144
	/**
145
	 * Modify the SQL array to gather custom BBCode data
146 4
	 *
147
	 * @param \phpbb\event\data $event The event object
148 4
	 * @access public
149 4
	 */
150
	public function custom_bbcode_modify_sql($event)
151
	{
152
		$sql_ary = $event['sql_ary'];
153
		$sql_ary['SELECT'] .= ', b.bbcode_group';
154
		$sql_ary['ORDER_BY'] = 'b.bbcode_order, b.bbcode_id';
155
		$event['sql_ary'] = $sql_ary;
156
	}
157 2
158
	/**
159 2
	 * Setup custom BBCode variables
160 2
	 *
161 1
	 * @access public
162
	 */
163
	public function setup_custom_bbcodes()
164 1
	{
165 1
		$this->template->assign_vars([
166
			'ABBC3_USERNAME'			=> $this->user->data['username'],
167
			'ABBC3_BBCODE_ICONS'		=> $this->bbcodes_display->get_icons(),
168
			'ABBC3_BBCODE_FONTS'		=> ext::ABBC3_BBCODE_FONTS,
169
170
			'S_ABBC3_BBCODES_BAR'		=> $this->config['abbc3_bbcode_bar'],
171
172 1
			'UA_ABBC3_BBVIDEO_WIZARD'	=> $this->helper->route('vse_abbc3_bbcode_wizard', ['mode' => 'bbvideo']),
173
			'UA_ABBC3_PIPES_WIZARD'		=> $this->helper->route('vse_abbc3_bbcode_wizard', ['mode' => 'pipes']),
174 1
			'UA_ABBC3_URL_WIZARD'		=> $this->helper->route('vse_abbc3_bbcode_wizard', ['mode' => 'url']),
175 1
		]);
176 1
	}
177 1
178
	/**
179
	 * Alter custom BBCodes display
180
	 *
181
	 * @param \phpbb\event\data $event The event object
182
	 * @access public
183
	 */
184
	public function display_custom_bbcodes($event)
185 3
	{
186
		if (!$this->config['abbc3_bbcode_bar'])
187 3
		{
188 3
			return;
189 1
		}
190 1
191 3
		$event['custom_tags'] = $this->bbcodes_display->display_custom_bbcodes($event['custom_tags'], $event['row']);
192
	}
193
194
	/**
195
	 * Allow custom BBCodes based on user's group memberships
196
	 *
197
	 * @param \phpbb\event\data $event The event object
198
	 * @access public
199
	 */
200
	public function allow_custom_bbcodes($event)
201
	{
202
		if (defined('IN_CRON'))
203
		{
204
			return; // do no apply bbcode permissions if in a cron job (for 3.1 to 3.2 update reparsing)
205
		}
206
207
		$this->bbcodes_display->allow_custom_bbcodes($event['parser']);
208
	}
209
210
	/**
211
	 * Configure TextFormatter powered PlugIns and BBCodes
212
	 *
213
	 * @param \phpbb\event\data $event The event object
214
	 * @access public
215
	 */
216
	public function configure_bbcodes($event)
217
	{
218
		$configurator = $event['configurator'];
219
		$configurator->registeredVars['abbc3.pipes_enabled'] = $this->config['abbc3_pipes'];
220
221
		$this->bbcodes_config->pipes($configurator);
222
		$this->bbcodes_config->bbvideo($configurator);
223
		$this->bbcodes_config->hidden($configurator);
224
	}
225
226
	/**
227
	 * Add ABBC3 BBCodes to the BBCode FAQ after the HELP_BBCODE_BLOCK_OTHERS block
228
	 *
229
	 * @param \phpbb\event\data $event The event object
230
	 * @access public
231
	 */
232
	public function add_bbcode_faq($event)
233
	{
234
		if ($event['block_name'] === 'HELP_BBCODE_BLOCK_OTHERS')
235
		{
236
			$this->bbcodes_help->faq();
237
		}
238
	}
239
240
	/**
241
	 * If Quick Reply allowed, set our quick_reply property.
242
	 * Added compatibility check for Quick Reply Reloaded (qr_bbcode).
243
	 *
244
	 * @access public
245
	 */
246
	public function set_quick_reply()
247
	{
248
		$this->quick_reply = $this->config['abbc3_qr_bbcodes'] && !$this->config['qr_bbcode'];
249
	}
250
251
	/**
252
	 * Add BBCodes to Quick Reply.
253
	 *
254
	 * @param \phpbb\event\data $event The event object
255
	 * @access public
256
	 */
257
	public function add_to_quickreply($event)
258
	{
259
		if ($this->quick_reply)
260
		{
261
			$this->language->add_lang('posting');
262
			$this->template->assign_var('S_ABBC3_QUICKREPLY', true);
263
			$this->template->assign_vars($this->bbcodes_display->bbcode_statuses($event['forum_id']));
264
		}
265
	}
266
}
267