1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2016 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
|
|
|
class data extends contacts |
13
|
|
|
{ |
14
|
|
|
/** @var \phpbb\auth\auth */ |
15
|
|
|
protected $auth; |
16
|
|
|
|
17
|
|
|
/** @var \phpbb\config\config */ |
18
|
|
|
protected $config; |
19
|
|
|
|
20
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
21
|
|
|
protected $db; |
22
|
|
|
|
23
|
|
|
/** @var \phpbb\profilefields\manager */ |
24
|
|
|
protected $profile_fields; |
25
|
|
|
|
26
|
|
|
/** @var \phpbb\language\language */ |
27
|
|
|
protected $translator; |
28
|
|
|
|
29
|
|
|
/** @var \phpbb\user */ |
30
|
|
|
protected $user; |
31
|
|
|
|
32
|
|
|
/** @var string */ |
33
|
|
|
protected $phpbb_root_path; |
34
|
|
|
|
35
|
|
|
/** @var string */ |
36
|
|
|
protected $php_ext; |
37
|
|
|
|
38
|
|
|
/** @var array */ |
39
|
|
|
protected $user_cache = array(); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* |
44
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
45
|
|
|
* @param \phpbb\config\config $config Config object |
46
|
|
|
* @param \phpbb\db\driver\driver_interface $db Database connection |
47
|
|
|
* @param \phpbb\profilefields\manager $profile_fields Profile fields manager |
48
|
|
|
* @param \phpbb\language\language $translator Language object |
49
|
|
|
* @param \phpbb\user $user User Object |
50
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
51
|
|
|
* @param string $php_ext php file extension |
52
|
|
|
*/ |
53
|
88 |
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\profilefields\manager $profile_fields, \phpbb\language\language $translator, \phpbb\user $user, $phpbb_root_path, $php_ext) |
54
|
|
|
{ |
55
|
88 |
|
parent::__construct($auth, $config, $translator, $user, $phpbb_root_path, $php_ext); |
56
|
|
|
|
57
|
88 |
|
$this->auth = $auth; |
58
|
88 |
|
$this->config = $config; |
59
|
88 |
|
$this->db = $db; |
60
|
88 |
|
$this->profile_fields = $profile_fields; |
61
|
88 |
|
$this->translator = $translator; |
62
|
88 |
|
$this->user = $user; |
63
|
88 |
|
$this->phpbb_root_path = $phpbb_root_path; |
64
|
88 |
|
$this->php_ext = $php_ext; |
65
|
88 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param array $user_ids |
69
|
|
|
* @param string $sql_where |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
8 |
|
public function get_users(array $user_ids, $sql_where = '') |
73
|
|
|
{ |
74
|
8 |
|
$query_ids = array_diff($user_ids, array_keys($this->user_cache)); |
75
|
|
|
|
76
|
8 |
|
if (sizeof($query_ids)) |
77
|
8 |
|
{ |
78
|
8 |
|
$sql_where .= (($sql_where) ? ' AND ' : '') . $this->db->sql_in_set('user_id', $query_ids); |
79
|
8 |
|
$this->query($sql_where); |
80
|
8 |
|
} |
81
|
|
|
|
82
|
8 |
|
return array_intersect_key($this->user_cache, array_flip($user_ids)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $sql_where |
87
|
|
|
* @param string $order_by |
88
|
|
|
* @param int|bool $limit |
89
|
|
|
* @return array|bool |
90
|
|
|
*/ |
91
|
10 |
|
public function query($sql_where = '', $order_by = '', $limit = false) |
92
|
|
|
{ |
93
|
10 |
|
$sql = $this->get_sql_statement($sql_where, $order_by); |
94
|
10 |
|
$result = $this->db->sql_query_limit($sql, $limit); |
95
|
|
|
|
96
|
10 |
|
$users = array(); |
97
|
10 |
|
while ($row = $this->db->sql_fetchrow($result)) |
98
|
|
|
{ |
99
|
8 |
|
$user_id = $row['user_id']; |
100
|
8 |
|
$users[$user_id] = $row; |
101
|
|
|
|
102
|
8 |
|
$this->user_cache[$user_id] = $this->get_data($row); |
103
|
8 |
|
$this->user_cache[$user_id] += $this->get_rank($row); |
104
|
8 |
|
} |
105
|
10 |
|
$this->db->sql_freeresult($result); |
106
|
|
|
|
107
|
10 |
|
if (!sizeof($users)) |
108
|
10 |
|
{ |
109
|
4 |
|
return false; |
110
|
|
|
} |
111
|
|
|
|
112
|
8 |
|
$this->get_additional_fields($users); |
113
|
8 |
|
unset($users); |
114
|
|
|
|
115
|
8 |
|
return $this->user_cache; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param array $row |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
8 |
|
public function get_data($row) |
123
|
|
|
{ |
124
|
8 |
|
$user_id = $row['user_id']; |
125
|
8 |
|
$date_format = $this->translator->lang('DATE_FORMAT'); |
126
|
|
|
|
127
|
|
|
return array( |
128
|
8 |
|
'AVATAR' => $this->get_avatar($row), |
129
|
8 |
|
'USERNAME' => get_username_string('username', $user_id, $row['username'], $row['user_colour']), |
130
|
8 |
|
'USERNAME_FULL' => get_username_string('full', $user_id, $row['username'], $row['user_colour']), |
131
|
|
|
|
132
|
8 |
|
'JOINED' => $this->user->format_date($row['user_regdate'], "|$date_format|"), |
133
|
8 |
|
'VISITED' => $this->get_last_visit_date($row['user_lastvisit'], $date_format), |
134
|
8 |
|
'POSTS' => $row['user_posts'], |
135
|
8 |
|
'POSTS_PCT' => $this->translator->lang_array('POST_PCT', $this->calculate_percent_posts($row['user_posts'])), |
136
|
|
|
|
137
|
8 |
|
'CONTACT_USER' => $this->translator->lang('CONTACT_USER', get_username_string('username', $user_id, $row['username'], $row['user_colour'], $row['username'])), |
138
|
|
|
|
139
|
8 |
|
'U_SEARCH_POSTS' => $this->get_search_url($user_id), |
140
|
8 |
|
'U_VIEWPROFILE' => get_username_string('profile', $user_id, $row['username'], $row['user_colour']), |
141
|
|
|
|
142
|
8 |
|
'contact_fields' => array(), |
143
|
8 |
|
'profile_fields' => array(), |
144
|
8 |
|
); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
1 |
|
public function get_profile_fields() |
151
|
|
|
{ |
152
|
|
|
$sql = 'SELECT l.lang_name, f.field_ident |
153
|
1 |
|
FROM ' . PROFILE_LANG_TABLE . ' l, ' . PROFILE_FIELDS_TABLE . ' f |
154
|
1 |
|
WHERE l.lang_id = ' . $this->user->get_iso_lang_id() . ' |
155
|
|
|
AND f.field_active = 1 |
156
|
|
|
AND f.field_no_view = 0 |
157
|
|
|
AND f.field_hide = 0 |
158
|
|
|
AND l.field_id = f.field_id |
159
|
1 |
|
ORDER BY f.field_order'; |
160
|
1 |
|
$result = $this->db->sql_query($sql); |
161
|
|
|
|
162
|
1 |
|
$cpf_options = false; |
163
|
1 |
|
while ($row = $this->db->sql_fetchrow($result)) |
164
|
|
|
{ |
165
|
1 |
|
$cpf_options[$row['field_ident']] = $row['lang_name']; |
166
|
1 |
|
} |
167
|
1 |
|
$this->db->sql_freeresult($result); |
168
|
|
|
|
169
|
1 |
|
return $cpf_options; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param array $row |
174
|
|
|
* @return string |
175
|
|
|
*/ |
176
|
8 |
|
protected function get_avatar(array $row) |
177
|
|
|
{ |
178
|
8 |
|
return ($this->user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : ''; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param int $user_posts |
183
|
|
|
* @return int |
184
|
|
|
*/ |
185
|
8 |
|
protected function calculate_percent_posts($user_posts) |
186
|
|
|
{ |
187
|
8 |
|
return ($this->config['num_posts']) ? min(100, ($user_posts / $this->config['num_posts']) * 100) : 0; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param int $last_visited |
192
|
|
|
* @param string $date_format |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
8 |
|
protected function get_last_visit_date($last_visited, $date_format) |
196
|
|
|
{ |
197
|
8 |
|
return ($last_visited) ? $this->user->format_date($last_visited, "|$date_format|") : ''; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param int $user_id |
202
|
|
|
* @return string |
203
|
|
|
*/ |
204
|
8 |
|
protected function get_search_url($user_id) |
205
|
|
|
{ |
206
|
8 |
|
return ($this->auth->acl_get('u_search')) ? append_sid($this->phpbb_root_path . 'search.' . $this->php_ext, "author_id=$user_id&sr=posts") : ''; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @param array $row |
211
|
|
|
* @return array |
212
|
|
|
*/ |
213
|
8 |
|
public function get_rank(array $row) |
214
|
|
|
{ |
215
|
8 |
|
if (!function_exists('phpbb_get_user_rank')) |
216
|
8 |
|
{ |
217
|
1 |
|
include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); |
218
|
1 |
|
} |
219
|
|
|
|
220
|
8 |
|
$user_rank_data = phpbb_get_user_rank($row, $row['user_posts']); |
221
|
|
|
|
222
|
8 |
|
if (!empty($user_rank_data)) |
223
|
8 |
|
{ |
224
|
|
|
return array( |
225
|
8 |
|
'RANK_TITLE' => $user_rank_data['title'], |
226
|
8 |
|
'RANK_IMAGE' => $user_rank_data['img'], |
227
|
8 |
|
'RANK_IMAGE_SRC' => $user_rank_data['img_src'], |
228
|
8 |
|
); |
229
|
|
|
} |
230
|
|
|
else |
231
|
|
|
{ |
232
|
|
|
return array( |
233
|
|
|
'RANK_TITLE' => '', |
234
|
|
|
'RANK_IMAGE' => '', |
235
|
|
|
'RANK_IMAGE_SRC' => '', |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @param array $users |
242
|
|
|
*/ |
243
|
8 |
|
protected function get_additional_fields(array $users) |
244
|
|
|
{ |
245
|
8 |
|
$user_ids = array_keys($users); |
246
|
|
|
|
247
|
8 |
|
$can_receive_pm_list = $this->get_can_receive_pm_list($user_ids); |
248
|
8 |
|
$permanently_banned_users = $this->get_banned_users_list($user_ids); |
249
|
|
|
|
250
|
|
|
// Grab all profile fields from users in id cache for later use - similar to the poster cache |
251
|
8 |
|
$profile_fields_cache = $this->profile_fields->grab_profile_fields_data($user_ids); |
252
|
|
|
|
253
|
8 |
|
for ($i = 0, $size = sizeof($user_ids); $i < $size; $i++) |
254
|
|
|
{ |
255
|
8 |
|
$id = $user_ids[$i]; |
256
|
8 |
|
$row = $users[$id]; |
257
|
|
|
|
258
|
8 |
|
$this->user_cache[$id]['contact_fields'] = array_filter(array( |
259
|
8 |
|
'pm' => $this->get_pm_contact($row, $can_receive_pm_list, $permanently_banned_users), |
260
|
8 |
|
'email' => $this->get_email_contact($row), |
261
|
8 |
|
'jabber' => $this->get_jabber_contact($row), |
262
|
8 |
|
)); |
263
|
8 |
|
$this->get_custom_profile_fields($id, $profile_fields_cache); |
264
|
8 |
|
} |
265
|
8 |
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param int $user_id |
269
|
|
|
* @param array $profile_fields_cache |
270
|
|
|
*/ |
271
|
8 |
|
protected function get_custom_profile_fields($user_id, array $profile_fields_cache) |
272
|
|
|
{ |
273
|
8 |
|
$cp_row = (isset($profile_fields_cache[$user_id])) ? $this->profile_fields->generate_profile_fields_template_data($profile_fields_cache[$user_id]) : array('blockrow' => array()); |
274
|
|
|
|
275
|
8 |
|
foreach ($cp_row['blockrow'] as $field_data) |
276
|
|
|
{ |
277
|
4 |
|
$field = $field_data['PROFILE_FIELD_IDENT']; |
278
|
|
|
|
279
|
4 |
|
if ($field_data['S_PROFILE_CONTACT']) |
280
|
4 |
|
{ |
281
|
|
|
$this->user_cache[$user_id]['contact_fields'][$field] = array( |
282
|
|
|
'ID' => $field, |
283
|
|
|
'NAME' => $field_data['PROFILE_FIELD_NAME'], |
284
|
|
|
'U_CONTACT' => $field_data['PROFILE_FIELD_CONTACT'], |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
else |
288
|
|
|
{ |
289
|
4 |
|
$this->user_cache[$user_id]['profile_fields'][$field] = $field_data; |
290
|
|
|
} |
291
|
8 |
|
} |
292
|
8 |
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param string $sql_where |
296
|
|
|
* @param string $order_by |
297
|
|
|
* @return string |
298
|
|
|
*/ |
299
|
10 |
|
protected function get_sql_statement($sql_where = '', $order_by = '') |
300
|
|
|
{ |
301
|
|
|
return 'SELECT user_id, username, user_type, user_colour, user_avatar, user_avatar_type, user_avatar_height, user_avatar_width, user_regdate, user_lastvisit, user_birthday, user_posts, user_rank, user_allow_viewemail, user_allow_pm, user_jabber, user_inactive_reason |
302
|
10 |
|
FROM ' . USERS_TABLE . |
303
|
10 |
|
(($sql_where) ? ' WHERE ' . $sql_where : '') . |
304
|
10 |
|
(($order_by) ? ' ORDER BY ' . $order_by : ''); |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|