1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\services\users; |
11
|
|
|
|
12
|
|
|
abstract class contacts |
13
|
|
|
{ |
14
|
|
|
/** @var \phpbb\auth\auth */ |
15
|
|
|
protected $auth; |
16
|
|
|
|
17
|
|
|
/** @var \phpbb\config\config */ |
18
|
|
|
protected $config; |
19
|
|
|
|
20
|
|
|
/** @var \phpbb\language\language */ |
21
|
|
|
protected $translator; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\user */ |
24
|
|
|
protected $user; |
25
|
|
|
|
26
|
|
|
/** @var string */ |
27
|
|
|
protected $phpbb_root_path; |
28
|
|
|
|
29
|
|
|
/** @var string */ |
30
|
|
|
protected $php_ext; |
31
|
|
|
|
32
|
|
|
/** @var bool */ |
33
|
|
|
protected $mailto_allowed; |
34
|
|
|
|
35
|
|
|
/** @var bool */ |
36
|
|
|
protected $email_form_allowed; |
37
|
|
|
|
38
|
|
|
/** @var bool */ |
39
|
|
|
protected $jabber_allowed; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* |
44
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
45
|
|
|
* @param \phpbb\config\config $config Config object |
46
|
|
|
* @param \phpbb\language\language $translator Language object |
47
|
|
|
* @param \phpbb\user $user User Object |
48
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
49
|
|
|
* @param string $php_ext php file extension |
50
|
|
|
*/ |
51
|
96 |
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\language\language $translator, \phpbb\user $user, $phpbb_root_path, $php_ext) |
52
|
|
|
{ |
53
|
96 |
|
$this->auth = $auth; |
54
|
96 |
|
$this->config = $config; |
55
|
96 |
|
$this->translator = $translator; |
56
|
96 |
|
$this->user = $user; |
57
|
96 |
|
$this->phpbb_root_path = $phpbb_root_path; |
58
|
96 |
|
$this->php_ext = $php_ext; |
59
|
|
|
|
60
|
96 |
|
$this->mailto_allowed = $this->get_mailto_allowed(); |
61
|
96 |
|
$this->email_form_allowed = $this->get_email_form_allowed(); |
62
|
96 |
|
$this->jabber_allowed = $this->get_jabber_allowed(); |
63
|
96 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param array $row |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
14 |
|
protected function get_email_contact(array $row) |
70
|
|
|
{ |
71
|
14 |
|
$email = array(); |
72
|
14 |
|
if ($this->user_email_allowed($row)) |
73
|
14 |
|
{ |
74
|
|
|
$email = array( |
75
|
14 |
|
'ID' => 'email', |
76
|
14 |
|
'NAME' => $this->translator->lang('SEND_EMAIL'), |
77
|
14 |
|
'U_CONTACT' => $this->get_email_url($row), |
78
|
14 |
|
); |
79
|
14 |
|
} |
80
|
|
|
|
81
|
14 |
|
return $email; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param array $row |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
14 |
|
protected function user_email_allowed(array $row) |
89
|
|
|
{ |
90
|
14 |
|
return ((!empty($row['user_allow_viewemail']) && $this->auth->acl_get('u_sendemail')) || $this->auth->acl_get('a_email')) ? true : false; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param array $row |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
14 |
|
protected function get_email_url(array $row) |
98
|
|
|
{ |
99
|
14 |
|
return ($this->email_form_allowed) ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=email&u=' . $row['user_id']) : (($this->mailto_allowed) ? 'mailto:' . $row['user_email'] : ''); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return bool |
104
|
|
|
*/ |
105
|
96 |
|
protected function get_email_form_allowed() |
106
|
|
|
{ |
107
|
96 |
|
return ($this->config['board_email_form'] && $this->config['email_enable']) ? true : false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
96 |
|
protected function get_mailto_allowed() |
114
|
|
|
{ |
115
|
96 |
|
return ($this->config['board_hide_emails'] && !$this->auth->acl_get('a_email')) ? false : true; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param array $row |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
14 |
|
protected function get_jabber_contact(array $row) |
123
|
|
|
{ |
124
|
14 |
|
$jabber = array(); |
125
|
14 |
|
if ($this->jabber_allowed && $row['user_jabber']) |
126
|
14 |
|
{ |
127
|
|
|
$jabber = array( |
128
|
4 |
|
'ID' => 'jabber', |
129
|
4 |
|
'NAME' => $this->translator->lang('JABBER'), |
130
|
4 |
|
'U_CONTACT' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=contact&action=jabber&u=' . $row['user_id']), |
131
|
4 |
|
); |
132
|
4 |
|
} |
133
|
|
|
|
134
|
14 |
|
return $jabber; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
96 |
|
protected function get_jabber_allowed() |
141
|
|
|
{ |
142
|
96 |
|
return ($this->config['jab_enable'] && $this->auth->acl_get('u_sendim')) ? true : false; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param array $row |
147
|
|
|
* @param array $can_receive_pm_list |
148
|
|
|
* @param array $permanently_banned_users |
149
|
|
|
* @return array |
150
|
|
|
*/ |
151
|
14 |
|
protected function get_pm_contact(array $row, array $can_receive_pm_list, array $permanently_banned_users) |
152
|
|
|
{ |
153
|
14 |
|
$pm = array(); |
154
|
14 |
|
if ($this->user_can_pm() && $this->can_receive_pm($row, $can_receive_pm_list, $permanently_banned_users)) |
155
|
14 |
|
{ |
156
|
|
|
$pm = array( |
157
|
4 |
|
'ID' => 'pm', |
158
|
4 |
|
'NAME' => $this->translator->lang('SEND_PRIVATE_MESSAGE'), |
159
|
4 |
|
'U_CONTACT' => append_sid("{$this->phpbb_root_path}ucp.{$this->php_ext}", 'i=pm&mode=compose&u=' . $row['user_id']), |
160
|
4 |
|
); |
161
|
4 |
|
} |
162
|
|
|
|
163
|
14 |
|
return $pm; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return bool |
168
|
|
|
*/ |
169
|
14 |
|
protected function user_can_pm() |
170
|
|
|
{ |
171
|
14 |
|
return ($this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm')) ? true : false; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param array $row |
176
|
|
|
* @param array $can_receive_pm_list |
177
|
|
|
* @param array $permanently_banned_users |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
14 |
|
protected function can_receive_pm(array $row, array $can_receive_pm_list, array $permanently_banned_users) |
181
|
|
|
{ |
182
|
|
|
return ( |
183
|
14 |
|
$this->user_is_allowed_to_pm($row, $permanently_banned_users) && |
184
|
|
|
|
185
|
|
|
// They must be able to read PMs |
186
|
14 |
|
in_array($row['user_id'], $can_receive_pm_list) && |
187
|
|
|
|
188
|
|
|
// They must allow users to contact via PM |
189
|
4 |
|
$this->user_allows_pm_contact($row['user_allow_pm']) |
190
|
14 |
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @param array $row |
195
|
|
|
* @param array $permanently_banned_users |
196
|
|
|
* @return bool |
197
|
|
|
*/ |
198
|
14 |
|
protected function user_is_allowed_to_pm(array $row, array $permanently_banned_users) |
199
|
|
|
{ |
200
|
|
|
return ( |
201
|
|
|
// They must not be permanently banned |
202
|
14 |
|
!in_array($row['user_id'], $permanently_banned_users) && |
203
|
|
|
|
204
|
|
|
// is this user type allowed to send pms? |
205
|
14 |
|
$this->user_type_can_pm($row) |
206
|
14 |
|
); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param array $row |
211
|
|
|
* @return bool |
212
|
|
|
*/ |
213
|
14 |
|
protected function user_type_can_pm(array $row) |
214
|
|
|
{ |
215
|
|
|
return ( |
216
|
|
|
// They must be a "normal" user |
217
|
14 |
|
$row['user_type'] != USER_IGNORE && |
218
|
|
|
|
219
|
|
|
// They must not be deactivated by the administrator |
220
|
14 |
|
($row['user_type'] != USER_INACTIVE || $row['user_inactive_reason'] != INACTIVE_MANUAL) |
221
|
14 |
|
); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param bool $user_allow_pm |
226
|
|
|
* @return bool |
227
|
|
|
*/ |
228
|
4 |
|
protected function user_allows_pm_contact($user_allow_pm) |
229
|
|
|
{ |
230
|
4 |
|
return (($this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_')) || $user_allow_pm); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get the list of users who can receive private messages |
235
|
|
|
* |
236
|
|
|
* @param array $user_ids |
237
|
|
|
* @return array |
238
|
|
|
*/ |
239
|
14 |
|
protected function get_can_receive_pm_list(array $user_ids) |
240
|
|
|
{ |
241
|
14 |
|
$can_receive_pm_list = $this->auth->acl_get_list($user_ids, 'u_readpm'); |
242
|
14 |
|
return (empty($can_receive_pm_list) || !isset($can_receive_pm_list[0]['u_readpm'])) ? array() : $can_receive_pm_list[0]['u_readpm']; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Get the list of permanently banned users |
247
|
|
|
* |
248
|
|
|
* @param array $user_ids |
249
|
|
|
* @return array |
250
|
|
|
*/ |
251
|
14 |
|
protected function get_banned_users_list(array $user_ids) |
252
|
|
|
{ |
253
|
14 |
|
if (!function_exists('phpbb_get_banned_user_ids')) |
254
|
14 |
|
{ |
255
|
1 |
|
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); |
256
|
1 |
|
} |
257
|
|
|
|
258
|
14 |
|
return phpbb_get_banned_user_ids($user_ids, false); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|