listener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
ccs 7
cts 7
cp 1
crap 1
rs 9.8666
c 0
b 0
f 0
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
	 * @access public
71
	 */
72
	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)
73
	{
74
		$this->bbcodes_config = $bbcodes_config;
75
		$this->bbcodes_display = $bbcodes_display;
76
		$this->bbcodes_help = $bbcodes_help;
77 2
		$this->config = $config;
78
		$this->config_text = $db_text;
79
		$this->helper = $helper;
80 1
		$this->template = $template;
81
		$this->language = $language;
82 1
	}
83 1
84 1
	/**
85
	 * Assign functions defined in this class to event listeners in the core
86 1
	 *
87 2
	 * @return array
88
	 * @static
89 1
	 * @access public
90 1
	 */
91
	public static function getSubscribedEvents()
92
	{
93
		return [
94
			'core.user_setup'							=> 'load_language_on_setup',
95
			'core.page_header' 							=> 'load_google_fonts',
96
			'core.adm_page_header' 						=> 'load_google_fonts',
97
98
			'core.display_custom_bbcodes'				=> 'setup_custom_bbcodes',
99 2
			'core.display_custom_bbcodes_modify_sql'	=> 'custom_bbcode_modify_sql',
100
			'core.display_custom_bbcodes_modify_row'	=> 'display_custom_bbcodes',
101 2
102 2
			'core.text_formatter_s9e_parser_setup'		=> 'allow_custom_bbcodes',
103 2
			'core.text_formatter_s9e_configure_after'	=> ['configure_bbcodes', -1], // force the lowest priority
104 2
105
			'core.help_manager_add_block_after'			=> 'add_bbcode_faq',
106 2
107 2
			'core.viewtopic_modify_quick_reply_template_vars' 	=> 'set_quick_reply',
108
			'core.viewtopic_modify_page_title'					=> 'add_to_quickreply',
109
		];
110
	}
111
112
	/**
113
	 * Load common files during user setup
114
	 *
115 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...
116
	 * @access public
117 2
	 */
118 2
	public function load_language_on_setup($event)
119 2
	{
120 2
		$lang_set_ext = $event['lang_set_ext'];
121 2
		$lang_set_ext[] = [
122
			'ext_name' => 'vse/abbc3',
123
			'lang_set' => 'abbc3',
124
		];
125
		$event['lang_set_ext'] = $lang_set_ext;
126
	}
127
128 1
	/**
129
	 * Load Google fonts data
130 1
	 * For injecting Google Font names into the template
131 1
	 *
132 1
	 * @access public
133
	 */
134 1
	public function load_google_fonts()
135 1
	{
136 1
		if (!$this->config['allow_cdn'])
137 1
		{
138 1
			return;
139
		}
140
141
		$this->template->assign_var(
142
			'abbc3_google_fonts',
143
			json_decode($this->config_text->get('abbc3_google_fonts'), true)
144
		);
145
	}
146 4
147
	/**
148 4
	 * Modify the SQL array to gather custom BBCode data
149 4
	 *
150
	 * @param \phpbb\event\data $event The event object
151
	 * @access public
152
	 */
153
	public function custom_bbcode_modify_sql($event)
154
	{
155
		$sql_ary = $event['sql_ary'];
156
		$sql_ary['SELECT'] .= ', b.bbcode_group';
157 2
		$sql_ary['ORDER_BY'] = 'b.bbcode_order, b.bbcode_id';
158
		$event['sql_ary'] = $sql_ary;
159 2
	}
160 2
161 1
	/**
162
	 * Setup custom BBCode variables
163
	 *
164 1
	 * @access public
165 1
	 */
166
	public function setup_custom_bbcodes()
167
	{
168
		$this->template->assign_vars([
169
			'ABBC3_BBCODE_ICONS'		=> $this->bbcodes_display->get_icons(),
170
			'ABBC3_BBCODE_FONTS'		=> ext::ABBC3_BBCODE_FONTS,
171
172 1
			'S_ABBC3_BBCODES_BAR'		=> $this->config['abbc3_bbcode_bar'],
173
			'S_ABBC3_BCSTYLE_BAR'		=> phpbb_version_compare(PHPBB_VERSION, ext::PHPBB_LEGACY_MAX, '<='),
0 ignored issues
show
Bug introduced by
The function phpbb_version_compare was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
			'S_ABBC3_BCSTYLE_BAR'		=> /** @scrutinizer ignore-call */ phpbb_version_compare(PHPBB_VERSION, ext::PHPBB_LEGACY_MAX, '<='),
Loading history...
Bug introduced by
The constant vse\abbc3\event\PHPBB_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
174 1
175 1
			'UA_ABBC3_BBVIDEO_WIZARD'	=> $this->helper->route('vse_abbc3_bbcode_wizard', ['mode' => 'bbvideo']),
176 1
			'UA_ABBC3_PIPES_WIZARD'		=> $this->helper->route('vse_abbc3_bbcode_wizard', ['mode' => 'pipes']),
177 1
			'UA_ABBC3_URL_WIZARD'		=> $this->helper->route('vse_abbc3_bbcode_wizard', ['mode' => 'url']),
178
		]);
179
	}
180
181
	/**
182
	 * Alter custom BBCodes display
183
	 *
184
	 * @param \phpbb\event\data $event The event object
185 3
	 * @access public
186
	 */
187 3
	public function display_custom_bbcodes($event)
188 3
	{
189 1
		if (!$this->config['abbc3_bbcode_bar'])
190 1
		{
191 3
			return;
192
		}
193
194
		$event['custom_tags'] = $this->bbcodes_display->display_custom_bbcodes($event['custom_tags'], $event['row']);
195
	}
196
197
	/**
198
	 * Allow custom BBCodes based on user's group memberships
199
	 *
200
	 * @param \phpbb\event\data $event The event object
201
	 * @access public
202
	 */
203
	public function allow_custom_bbcodes($event)
204
	{
205
		if (defined('IN_CRON'))
206
		{
207
			return; // do no apply bbcode permissions if in a cron job (for 3.1 to 3.2 update reparsing)
208
		}
209
210
		$this->bbcodes_display->allow_custom_bbcodes($event['parser']);
211
	}
212
213
	/**
214
	 * Configure TextFormatter powered PlugIns and BBCodes
215
	 *
216
	 * @param \phpbb\event\data $event The event object
217
	 * @access public
218
	 */
219
	public function configure_bbcodes($event)
220
	{
221
		$configurator = $event['configurator'];
222
		$configurator->registeredVars['abbc3.pipes_enabled'] = $this->config['abbc3_pipes'];
223
		$configurator->registeredVars['abbc3.auto_video_enabled'] = $this->config['abbc3_auto_video'];
224
225
		$this->bbcodes_config->pipes($configurator);
226
		$this->bbcodes_config->bbvideo($configurator);
227
		$this->bbcodes_config->auto_video($configurator);
228
		$this->bbcodes_config->hidden($configurator);
229
	}
230
231
	/**
232
	 * Add ABBC3 BBCodes to the BBCode FAQ after the HELP_BBCODE_BLOCK_OTHERS block
233
	 *
234
	 * @param \phpbb\event\data $event The event object
235
	 * @access public
236
	 */
237
	public function add_bbcode_faq($event)
238
	{
239
		if ($event['block_name'] === 'HELP_BBCODE_BLOCK_OTHERS')
240
		{
241
			$this->bbcodes_help->faq();
242
		}
243
	}
244
245
	/**
246
	 * If Quick Reply allowed, set our quick_reply property.
247
	 * Added compatibility check for Quick Reply Reloaded (qr_bbcode).
248
	 *
249
	 * @access public
250
	 */
251
	public function set_quick_reply()
252
	{
253
		$this->quick_reply = $this->config['abbc3_qr_bbcodes'] && !$this->config['qr_bbcode'];
254
	}
255
256
	/**
257
	 * Add BBCodes to Quick Reply.
258
	 *
259
	 * @param \phpbb\event\data $event The event object
260
	 * @access public
261
	 */
262
	public function add_to_quickreply($event)
263
	{
264
		if ($this->quick_reply)
265
		{
266
			$this->language->add_lang('posting');
267
			$this->template->assign_var('S_ABBC3_QUICKREPLY', true);
268
			$this->template->assign_vars($this->bbcodes_display->bbcode_statuses($event['forum_id']));
269
		}
270
	}
271
}
272