1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package Quick Title Edition Extension |
5
|
|
|
* @copyright (c) 2015 ABDev |
6
|
|
|
* @copyright (c) 2015 PastisD |
7
|
|
|
* @copyright (c) 2015 Geolim4 <http://geolim4.com> |
8
|
|
|
* @copyright (c) 2015 Zoddo <[email protected]> |
9
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
10
|
|
|
* |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace ernadoo\qte\event; |
14
|
|
|
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
16
|
|
|
|
17
|
|
|
class main_listener implements EventSubscriberInterface |
18
|
|
|
{ |
19
|
|
|
/** @var \phpbb\request\request */ |
20
|
|
|
protected $request; |
21
|
|
|
|
22
|
|
|
/** @var \phpbb\template\template */ |
23
|
|
|
protected $template; |
24
|
|
|
|
25
|
|
|
/** @var \phpbb\user */ |
26
|
|
|
protected $user; |
27
|
|
|
|
28
|
|
|
/** @var \phpbb\log\log */ |
29
|
|
|
protected $log; |
30
|
|
|
|
31
|
|
|
/** @var \ernadoo\qte\qte */ |
32
|
|
|
protected $qte; |
33
|
|
|
|
34
|
|
|
public function __construct(\phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, \phpbb\log\log $log, \ernadoo\qte\qte $qte) |
35
|
|
|
{ |
36
|
|
|
$this->request = $request; |
37
|
|
|
$this->template = $template; |
38
|
|
|
$this->user = $user; |
39
|
|
|
$this->log = $log; |
40
|
|
|
$this->qte = $qte; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
static public function getSubscribedEvents() |
44
|
|
|
{ |
45
|
|
|
return array( |
46
|
|
|
// viewforum |
47
|
|
|
'core.viewforum_modify_topics_data' => 'viewforum_get_user_infos', |
48
|
|
|
'core.viewforum_modify_topicrow' => 'viewforum_assign_topic_attributes', |
49
|
|
|
|
50
|
|
|
// viewtopic |
51
|
|
|
'core.viewtopic_add_quickmod_option_before' => 'viewtopic_attr_apply', |
52
|
|
|
'core.viewtopic_assign_template_vars_before' => 'viewtopic_select_assign_attributes', |
53
|
|
|
'core.viewtopic_modify_page_title' => 'viewtopic_attr_title', |
54
|
|
|
|
55
|
|
|
// posting |
56
|
|
|
'core.posting_modify_template_vars' => 'posting_select_assign_attributes', |
57
|
|
|
'core.posting_modify_submission_errors' => 'posting_check_attribute', |
58
|
|
|
'core.posting_modify_submit_post_before' => 'posting_submit_data', |
59
|
|
|
'core.submit_post_modify_sql_data' => 'posting_save_attribute', |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function viewforum_assign_topic_attributes($event) |
64
|
|
|
{ |
65
|
|
|
if (!empty($event['row']['topic_attr_id'])) |
66
|
|
|
{ |
67
|
|
|
$topic_row = $event['topic_row']; |
68
|
|
|
$topic_row['TOPIC_ATTRIBUTE'] = $this->qte->attr_display($event['row']['topic_attr_id'], $event['row']['topic_attr_user'], $event['row']['topic_attr_time']); |
69
|
|
|
$event['topic_row'] = $topic_row; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function viewforum_get_user_infos($event) |
74
|
|
|
{ |
75
|
|
|
if (sizeof($event['topic_list'])) |
76
|
|
|
{ |
77
|
|
|
$this->qte->get_users_by_topic_id($event['topic_list']); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function viewtopic_attr_title($event) |
82
|
|
|
{ |
83
|
|
|
$attr_title = $this->qte->attr_title($event['topic_data']['topic_attr_id'], $event['topic_data']['topic_attr_user'], $event['topic_data']['topic_attr_time']); |
84
|
|
|
$event['page_title'] = $attr_title ? $attr_title . ' ' . $event['page_title'] : $event['page_title']; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function viewtopic_select_assign_attributes($event) |
88
|
|
|
{ |
89
|
|
|
if (!empty($event['topic_data']['topic_attr_id'])) |
90
|
|
|
{ |
91
|
|
|
$this->qte->get_users_by_topic_id(array($event['topic_data']['topic_id'])); |
92
|
|
|
$this->template->assign_var('TOPIC_ATTRIBUTE', $this->qte->attr_display($event['topic_data']['topic_attr_id'], $event['topic_data']['topic_attr_user'], $event['topic_data']['topic_attr_time'])); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->qte->attr_select($event['forum_id'], $event['topic_data']['topic_poster'], (int) $event['topic_data']['topic_attr_id'], $event['viewtopic_url']); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function viewtopic_attr_apply($event) |
99
|
|
|
{ |
100
|
|
|
$attr_id = (int) $this->request->variable('attr_id', 0); |
101
|
|
|
if ($attr_id) |
102
|
|
|
{ |
103
|
|
|
$this->qte->get_users_by_user_id($this->user->data['user_id']); |
104
|
|
|
$this->qte->attr_apply($attr_id, $event['topic_id'], $event['forum_id'], $event['topic_data']['topic_attr_id'], $event['topic_data']['topic_poster'], $event['viewtopic_url']); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function posting_select_assign_attributes($event) |
109
|
|
|
{ |
110
|
|
|
$topic_attribute = $this->request->variable('attr_id', !empty($event['post_data']['topic_attr_id']) ? \ernadoo\qte\qte::KEEP : 0, false, \phpbb\request\request_interface::POST); |
111
|
|
|
|
112
|
|
|
$this->qte->attr_select($event['forum_id'], !empty($event['post_data']['topic_poster']) ? $event['post_data']['topic_poster'] : 0, (int) $topic_attribute, '', $event['mode']); |
113
|
|
|
|
114
|
|
|
if ($event['mode'] != 'post') |
115
|
|
|
{ |
116
|
|
|
$post_data = $event['post_data']; |
117
|
|
|
|
118
|
|
|
if ($topic_attribute != \ernadoo\qte\qte::KEEP) |
119
|
|
|
{ |
120
|
|
|
$post_data['topic_attr_id'] = (int) $topic_attribute; |
121
|
|
|
$post_data['topic_attr_user'] = (int) $this->user->data['user_id']; |
122
|
|
|
$post_data['topic_attr_time'] = time(); |
123
|
|
|
|
124
|
|
|
$this->qte->get_users_by_user_id($this->user->data['user_id']); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if ($topic_attribute != \ernadoo\qte\qte::REMOVE) |
128
|
|
|
{ |
129
|
|
|
$this->qte->get_users_by_topic_id(array($post_data['topic_id'])); |
130
|
|
|
$this->template->assign_var('TOPIC_ATTRIBUTE', $this->qte->attr_display($post_data['topic_attr_id'], $post_data['topic_attr_user'], $post_data['topic_attr_time'])); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function posting_check_attribute($event) |
136
|
|
|
{ |
137
|
|
|
$post_data = $event['post_data']; |
138
|
|
|
$post_data['attr_id'] = $this->request->variable('attr_id', \ernadoo\qte\qte::KEEP, false, \phpbb\request\request_interface::POST); |
139
|
|
|
|
140
|
|
|
if ($event['post_data']['force_attr']) |
141
|
|
|
{ |
142
|
|
|
if ((!$post_data['attr_id'] || $post_data['attr_id'] == \ernadoo\qte\qte::REMOVE) && ($event['mode'] == 'post' || ($event['mode'] == 'edit' && $event['post_data']['topic_first_post_id'] == $event['post_id'])) ) |
143
|
|
|
{ |
144
|
|
|
$error = $event['error']; |
145
|
|
|
$error[] = $this->user->lang['QTE_ATTRIBUTE_UNSELECTED']; |
146
|
|
|
$event['error'] = $error ; |
147
|
|
|
|
148
|
|
|
// init the value |
149
|
|
|
$post_data['attr_id'] = 0; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$event['post_data'] = $post_data; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function posting_submit_data($event) |
157
|
|
|
{ |
158
|
|
|
$topic_attribute = $event['post_data']['attr_id']; |
159
|
|
|
|
160
|
|
|
if ($event['mode'] != 'post' && $topic_attribute == $event['post_data']['topic_attr_id']) |
161
|
|
|
{ |
162
|
|
|
$topic_attribute = \ernadoo\qte\qte::KEEP; |
163
|
|
|
} |
164
|
|
|
else if (empty($event['post_data']['topic_attr_id']) && $topic_attribute == \ernadoo\qte\qte::REMOVE) |
165
|
|
|
{ |
166
|
|
|
$topic_attribute = \ernadoo\qte\qte::KEEP; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
$data = $event['data']; |
170
|
|
|
$data['attr_id'] = (int) (($event['mode'] == 'post') && !empty($event['post_data']['default_attr'])) ? $event['post_data']['default_attr'] : $topic_attribute; |
171
|
|
|
$event['data'] = $data; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function posting_save_attribute($event) |
175
|
|
|
{ |
176
|
|
|
if (isset($event['data']['attr_id']) && $event['data']['attr_id'] != \ernadoo\qte\qte::KEEP) |
177
|
|
|
{ |
178
|
|
|
$sql_data = $event['sql_data']; |
179
|
|
|
if ($event['data']['attr_id'] == \ernadoo\qte\qte::REMOVE) |
180
|
|
|
{ |
181
|
|
|
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_attr_id = 0'; |
182
|
|
|
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_attr_user = 0'; |
183
|
|
|
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_attr_time = 0'; |
184
|
|
|
} |
185
|
|
|
else |
186
|
|
|
{ |
187
|
|
|
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_attr_id = ' . (int) $event['data']['attr_id']; |
188
|
|
|
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_attr_user = ' . (int) $this->user->data['user_id']; |
189
|
|
|
$sql_data[TOPICS_TABLE]['stat'][] = 'topic_attr_time = ' . time(); |
190
|
|
|
} |
191
|
|
|
$event['sql_data'] = $sql_data; |
192
|
|
|
|
193
|
|
|
if (in_array($event['post_mode'], array('edit_topic', 'edit_first_post'))) |
194
|
|
|
{ |
195
|
|
|
$attr_name = ($event['data']['attr_id'] != \ernadoo\qte\qte::REMOVE) ? $this->qte->get_attr_name_by_id($event['data']['attr_id']) : ''; |
196
|
|
|
$log_data = array( |
197
|
|
|
'forum_id' => $event['data']['forum_id'], |
198
|
|
|
'topic_id' => $event['data']['topic_id'], |
199
|
|
|
$attr_name, |
200
|
|
|
); |
201
|
|
|
|
202
|
|
|
$this->log->add('mod', $this->user->data['user_id'], $this->user->ip, 'MCP_ATTRIBUTE_' . ($event['data']['attr_id'] == \ernadoo\qte\qte::REMOVE ? 'REMOVED' : 'UPDATED'), time(), $log_data); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|