-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathucp_listener.php
105 lines (93 loc) · 2.52 KB
/
ucp_listener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/**
*
* Topic Preview
*
* @copyright (c) 2013 Matt Friedman
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace vse\topicpreview\event;
use phpbb\config\config;
use phpbb\language\language;
use phpbb\request\request;
use phpbb\template\template;
use phpbb\user;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Event listener for UCP related actions
*/
class ucp_listener implements EventSubscriberInterface
{
/** @var config */
protected $config;
/** @var language */
protected $language;
/** @var request */
protected $request;
/** @var template */
protected $template;
/** @var user */
protected $user;
/**
* Constructor
*
* @param config $config Config object
* @param language $language Language object
* @param request $request Request object
* @param template $template Template object
* @param user $user User object
*/
public function __construct(config $config, language $language, request $request, template $template, user $user)
{
$this->config = $config;
$this->language = $language;
$this->request = $request;
$this->template = $template;
$this->user = $user;
}
/**
* Assign functions defined in this class to event listeners in the core
*
* @return array
*/
public static function getSubscribedEvents()
{
return array(
'core.ucp_prefs_view_data' => 'ucp_prefs_get_data',
'core.ucp_prefs_view_update_data' => 'ucp_prefs_set_data',
);
}
/**
* Get user's Topic Preview option and display it in UCP Prefs View page
*
* @param \phpbb\event\data $event The event object
*/
public function ucp_prefs_get_data($event)
{
// Request the user option vars and add them to the data array
$event['data'] = array_merge($event['data'], array(
'topic_preview' => $this->request->variable('topic_preview', (int) $this->user->data['user_topic_preview']),
));
// Output the data vars to the template (except on form submit)
if (!$event['submit'])
{
$this->language->add_lang('topic_preview_ucp', 'vse/topicpreview');
$this->template->assign_vars(array(
'S_TOPIC_PREVIEW' => $this->config['topic_preview_limit'],
'S_DISPLAY_TOPIC_PREVIEW' => $event['data']['topic_preview'],
));
}
}
/**
* Add user's Topic Preview option state into the sql_array
*
* @param \phpbb\event\data $event The event object
*/
public function ucp_prefs_set_data($event)
{
$event['sql_ary'] = array_merge($event['sql_ary'], array(
'user_topic_preview' => $event['data']['topic_preview'],
));
}
}