listener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * VigLink extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\viglink\event;
12
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
15
/**
16
 * Event listener
17
 */
18
class listener implements EventSubscriberInterface
19
{
20
	/** @var \phpbb\config\config $config Config object */
21
	protected $config;
22
23
	/** @var \phpbb\template\template $template Template object */
24
	protected $template;
25
26
	/**
27
	 * Constructor
28
	 *
29
	 * @param \phpbb\config\config     $config   Config object
30
	 * @param \phpbb\template\template $template Template object
31
	 */
32
	public function __construct(\phpbb\config\config $config, \phpbb\template\template $template)
33
	{
34
		$this->config = $config;
35
		$this->template = $template;
36
	}
37
38
	/**
39
	 * {@inheritDoc}
40
	 */
41
	public static function getSubscribedEvents()
42
	{
43
		return array(
44
			'core.viewtopic_post_row_after'		=> 'display_viglink',
45
		);
46
	}
47
48
	/**
49
	 * Insert the VigLink JS code into forum pages
50
	 *
51
	 * @return void
52
	 */
53
	public function display_viglink()
54
	{
55
		$viglink_key = '';
56
57
		if ($this->config['allow_viglink_phpbb'] && $this->config['phpbb_viglink_api_key'])
58
		{
59
			// Use phpBB API key if VigLink is allowed for phpBB
60
			$viglink_key = $this->config['phpbb_viglink_api_key'];
61
		}
62
63
		$this->template->assign_vars(array(
64
			'VIGLINK_ENABLED'	=> $this->config['viglink_enabled'] && $viglink_key,
65
			'VIGLINK_API_KEY'	=> $viglink_key,
66
			'VIGLINK_SUB_ID'	=> md5(urlencode($this->config['viglink_api_siteid']) . $this->config['questionnaire_unique_id']),
67
		));
68
	}
69
}
70