Completed
Push — develop-3.2.x ( 26b46b...e41dd4 )
by Matt
06:51
created

listener   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 203
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 98.46%

Importance

Changes 8
Bugs 0 Features 4
Metric Value
wmc 13
c 8
b 0
f 4
lcom 3
cbo 2
dl 0
loc 203
ccs 64
cts 65
cp 0.9846
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A load_language_on_setup() 0 9 1
A parse_bbcodes_before() 0 4 1
A parse_bbcodes_after() 0 4 1
A display_custom_bbcodes() 0 4 1
A __construct() 0 9 1
A custom_bbcode_modify_sql() 0 7 1
A setup_custom_bbcodes() 0 12 1
A allow_custom_bbcodes() 0 4 1
A getSubscribedEvents() 0 22 1
A s9e_allow_custom_bbcodes() 0 19 4
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_parser;
19
use vse\abbc3\ext;
20
21
/**
22
 * Event listener
23
 */
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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)
103
	{
104 2
		$lang_set_ext = $event['lang_set_ext'];
105 2
		$lang_set_ext[] = array(
106 2
			'ext_name' => 'vse/abbc3',
107 2
			'lang_set' => 'abbc3',
108
		);
109 2
		$event['lang_set_ext'] = $lang_set_ext;
110 2
	}
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)
122
	{
123 2
		$event['text'] = $this->bbcodes_parser->pre_parse_bbcodes($event['text'], $event['uid']);
124 2
	}
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)
136
	{
137 4
		$event['text'] = $this->bbcodes_parser->post_parse_bbcodes($event['text']);
138 4
	}
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)
182
	{
183 4
		$event['custom_tags'] = $this->bbcodes_display->display_custom_bbcodes($event['custom_tags'], $event['row']);
184 4
	}
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)
196
	{
197
		$event['bbcodes'] = $this->bbcodes_display->allow_custom_bbcodes($event['bbcodes'], $event['rowset']);
0 ignored issues
show
Deprecated Code introduced by
The method vse\abbc3\core\bbcodes_d...:allow_custom_bbcodes() has been deprecated with message: 3.2.0. Provides bc for phpBB 3.1.x.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
198
	}
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)
208
	{
209 2
		if (defined('IN_CRON'))
210 2
		{
211
			return; // do no apply bbcode permissions if in a cron job (for 3.1 to 3.2 update reparsing)
212
		}
213
214
		/** @var $service \phpbb\textformatter\s9e\parser object from the text_formatter.parser service */
215 2
		$service = $event['parser'];
216 2
		$parser = $service->get_parser();
217 2
		foreach ($parser->registeredVars['abbc3.bbcode_groups'] as $bbcode_name => $groups)
218
		{
219 2
			if (!$this->bbcodes_display->user_in_bbcode_group($groups))
220 2
			{
221 1
				$bbcode_name = rtrim($bbcode_name, '=');
222 1
				$service->disable_bbcode($bbcode_name);
223 1
			}
224 2
		}
225 2
	}
226
}
227