user::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 9
c 3
b 1
f 0
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.9666
cc 1
nc 1
nop 9
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * phpBB Gallery - Core Extension
4
 *
5
 * @package   phpbbgallery/core
6
 * @author    nickvergessen
7
 * @author    satanasov
8
 * @author    Leinad4Mind
9
 * @copyright 2014 nickvergessen, 2014- satanasov, 2018- Leinad4Mind
10
 * @license   GPL-2.0-only
11
 */
12
13
namespace phpbbgallery\core;
14
15
class user
16
{
17
	/**
18
	 * phpBB-user_id
19
	 *
20
	 * @var int
21
	 */
22
	public $user_id;
23
24
	/**
25
	 * phpBB user object
26
	 *
27
	 * @var \phpbb\user
0 ignored issues
show
Bug introduced by
The type phpbb\user was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
	 */
29
	protected $user;
30
31
	/**
32
	 * Custom profile fields manager
33
	 *
34
	 * @var \phpbb\profilefields\manager
0 ignored issues
show
Bug introduced by
The type phpbb\profilefields\manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
	 */
36
	protected $user_cpf;
37
38
	/**
39
	 * Config object
40
	 *
41
	 * @var \phpbb\config\config
0 ignored issues
show
Bug introduced by
The type phpbb\config\config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
	 */
43
	protected $config;
44
45
	/**
46
	 * Auth object
47
	 *
48
	 * @var \phpbb\auth\auth
0 ignored issues
show
Bug introduced by
The type phpbb\auth\auth was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
	 */
50
	protected $auth;
51
52
	/**
53
	 * phpBB root path
54
	 *
55
	 * @var string
56
	 */
57
	protected $root_path;
58
59
	/**
60
	 * PHP file extension
61
	 *
62
	 * @var string
63
	 */
64
	protected $php_ext;
65
66
	/**
67
	 * Database object
68
	 *
69
	 * @var \phpbb\db\driver\driver
0 ignored issues
show
Bug introduced by
The type phpbb\db\driver\driver was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
	 */
71
	protected $db;
72
73
	/**
74
	 * Event dispatcher object
75
	 *
76
	 * @var \phpbb\event\dispatcher
0 ignored issues
show
Bug introduced by
The type phpbb\event\dispatcher was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
77
	 */
78
	protected $dispatcher;
79
80
	/**
81
	 * Gallery users table
82
	 *
83
	 * @var string
84
	 */
85
	protected $gallery_users_table;
86
87
	/**
88
	 * Do we have an entry for the user in the table?
89
	 */
90
	public $entry_exists = null;
91
92
	/**
93
	 * Users data in the table
94
	 */
95
	protected $data = array();
96
97
	/**
98
	 * Constructor
99
	 *
100
	 * @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db         Database object
101
	 * @param \phpbb\event\dispatcher                                   $dispatcher Event dispatcher object
102
	 * @param \phpbb\user                                               $user
103
	 * @param \phpbb\profilefields\manager                              $user_cpf
104
	 * @param \phpbb\config\config                                      $config
105
	 * @param \phpbb\auth\auth                                          $auth
106
	 * @param string                                                    $table_name Gallery users table
107
	 * @param                                                           $root_path
108
	 * @param                                                           $php_ext
109
	 */
110 153
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\event\dispatcher $dispatcher, \phpbb\user $user,
0 ignored issues
show
Bug introduced by
The type phpbb\db\driver\driver_interface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
111
		\phpbb\profilefields\manager $user_cpf, \phpbb\config\config $config, \phpbb\auth\auth $auth,
112
		$table_name, $root_path, $php_ext)
113
	{
114 153
		$this->db = $db;
115 153
		$this->dispatcher = $dispatcher;
116 153
		$this->user = $user;
117 153
		$this->user_cpf = $user_cpf;
118 153
		$this->config = $config;
119 153
		$this->auth = $auth;
120 153
		$this->gallery_users_table = $table_name;
121 153
		$this->root_path = $root_path;
122 153
		$this->php_ext = $php_ext;
123 153
	}
124
125
	/**
126
	 * Set the user ID
127
	 *
128
	 * @param int  $user_id
129
	 * @param bool $load Shall we automatically load the users data from the database?
130
	 */
131 119
	public function set_user_id($user_id, $load = true)
132
	{
133 119
		$this->user_id = (int) $user_id;
134 119
		if ($load)
135
		{
136 117
			$this->load_data();
137
		}
138 119
	}
139
140
	/**
141
	 * Is it the same user?
142
	 *
143
	 * @param int $user_id
144
	 * @return    bool
145
	 */
146 111
	public function is_user($user_id)
147
	{
148 111
		return $this->user_id == $user_id;
149
	}
150
151
	/**
152
	 * Load the users data from the database and cast it...
153
	 */
154 119
	public function load_data()
155
	{
156 119
		$this->entry_exists = false;
157
		$sql = 'SELECT *
158 119
			FROM ' . $this->gallery_users_table . '
159 119
			WHERE user_id = ' . (int) $this->user_id;
160 119
		$result = $this->db->sql_query($sql, 30);
161 119
		if ($row = $this->db->sql_fetchrow($result))
162
		{
163 112
			$this->data = $this->validate_data($row);
164 112
			$this->entry_exists = true;
165
		}
166 119
		$this->db->sql_freeresult($result);
167
168 119
	}
169
170
	/**
171
	 * Load the users data from the database and cast it...
172
	 *
173
	 * @param $time
174
	 */
175 109
	public function set_permissions_changed($time)
176
	{
177 109
		if ($this->data)
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
178
		{
179 106
			$this->data['user_permissions_changed'] = $time;
180
		}
181 109
	}
182
183
	/**
184
	 * Some functions need the data to be loaded or at least checked.
185
	 * So here we loaded if it is not loaded yet and we need it ;)
186
	 */
187 5
	public function force_load()
188
	{
189 5
		if (is_null($this->entry_exists))
190
		{
191 2
			$this->load_data();
192
		}
193 5
	}
194
195
	/**
196
	 * Get user-setting, if the user does not have his own settings we fall back to default.
197
	 *
198
	 * @param string $key     Column name from the users-table
199
	 * @param bool   $default Load default value, if user has no entry
200
	 * @return    mixed            Returns the value of the column, it it does not exist it returns false.
201
	 */
202 114
	public function get_data($key, $default = true)
203
	{
204 114
		if (isset($this->data[$key]))
205
		{
206 111
			return $this->data[$key];
207
		}
208 109
		else if ($default && $this->get_default_value($key) !== null)
209
		{
210 109
			return $this->get_default_value($key);
211
		}
212
213
		return false;
214
	}
215
216
	/**
217
	 * Updates/Inserts the data, depending on whether the user already exists or not.
218
	 *    Example: 'SET key = x'
219
	 *
220
	 * @param $data
221
	 * @return bool
222
	 */
223 5
	public function update_data($data)
224
	{
225 5
		$this->force_load();
226
227 5
		$suc = false;
228 5
		if ($this->entry_exists)
229
		{
230 2
			$suc = $this->update($data);
231
		}
232
233 5
		if (($suc === false) || !$this->entry_exists)
234
		{
235 4
			$suc = $this->insert($data);
236
		}
237
238 5
		return $suc;
239
	}
240
241
	/**
242
	 * Increase/Inserts the data, depending on whether the user already exists or not.
243
	 *    Example: 'SET key = key + x'
244
	 *
245
	 * @param $num
246
	 * @return bool
247
	 */
248 1
	public function update_images($num)
249
	{
250 1
		$suc = false;
251 1
		if ($this->entry_exists || is_null($this->entry_exists))
252
		{
253 1
			$suc = $this->update_image_count($num);
254 1
			if ($suc === false)
255
			{
256 1
				$suc = $this->update(array('user_images' => max(0, $num)));
257
			}
258
		}
259
260 1
		if ($suc === false)
261
		{
262
			$suc = $this->insert(array('user_images' => max(0, $num)));
263
		}
264
265 1
		return $suc;
266
	}
267
268
	/**
269
	 * Updates the users table with the new data.
270
	 *
271
	 * @param array $data Array of data we want to add/update.
272
	 * @return    bool            Returns true if the columns were updated successfully
273
	 */
274 3
	private function update($data)
275
	{
276 3
		$sql_ary = array_merge($this->validate_data($data), array(
277 3
			'user_last_update' => time(),
278
		));
279 3
		unset($sql_ary['user_id']);
280
281 3
		$sql = 'UPDATE ' . $this->gallery_users_table . '
282 3
			SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
283 3
			WHERE user_id = ' . (int) $this->user_id;
284 3
		$this->db->sql_query($sql);
285
286 3
		$this->data = array_merge($this->data, $sql_ary);
287
288 3
		return ($this->db->sql_affectedrows() == 1) ? true : false;
289
	}
290
291
	/**
292
	 * Updates the users table by increasing the values.
293
	 *
294
	 * @param int $num Number of images to add to the counter
295
	 * @return    bool            Returns true if the columns were updated successfully, else false
296
	 */
297 1
	protected function update_image_count($num)
298
	{
299 1
		$sql = 'UPDATE ' . $this->gallery_users_table . '
300 1
			SET user_images = user_images ' . (($num > 0) ? (' + ' . $num) : (' - ' . abs($num))) . ',
301 1
				user_last_update = ' . time() . '
302 1
			WHERE ' . (($num < 0) ? ' user_images > ' . abs($num) . ' AND ' : '') . '
303 1
				user_id = ' . $this->user_id;
304 1
		$this->db->sql_query($sql);
305
306 1
		if ($this->db->sql_affectedrows() == 1)
307
		{
308 1
			if (!empty($this->data))
309
			{
310 1
				$this->data['user_last_update'] = time();
311 1
				$this->data['user_images'] += $num;
312
			}
313 1
			return true;
314
		}
315 1
		return false;
316
	}
317
318
	/**
319
	 * Updates the users table with the new data.
320
	 *
321
	 * @param array $data Array of data we want to insert
322
	 * @return    bool            Returns true if the data was inserted successfully
323
	 */
324 4
	private function insert($data)
325
	{
326 4
		$sql_ary = array_merge(self::get_default_values(), $this->validate_data($data), array(
0 ignored issues
show
Bug Best Practice introduced by
The method phpbbgallery\core\user::get_default_values() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

326
		$sql_ary = array_merge(self::/** @scrutinizer ignore-call */ get_default_values(), $this->validate_data($data), array(
Loading history...
327 4
			'user_id'          => $this->user_id,
328 4
			'user_last_update' => time(),
329
		));
330
331 4
		$this->db->sql_return_on_error(true);
332
333 4
		$sql = 'INSERT INTO ' . $this->gallery_users_table . '
334 4
			' . $this->db->sql_build_array('INSERT', $sql_ary);
335 4
		$this->db->sql_query($sql);
336 4
		$error = $this->db->get_sql_error_triggered();
337
338 4
		$this->db->sql_return_on_error(false);
339
340 4
		$this->data = $sql_ary;
341 4
		$this->entry_exists = true;
342
343 4
		return ($error) ? false : true;
344
	}
345
346
	/**
347
	 * Delete the user from the table.
348
	 */
349 1
	public function delete()
350
	{
351 1
		$sql = 'DELETE FROM ' . $this->gallery_users_table . '
352 1
			WHERE user_id = ' . (int) $this->user_id;
353 1
		$this->db->sql_query($sql);
354 1
	}
355
356
	/**
357
	 * Delete the user from the table.
358
	 *
359
	 * @param mixed $user_ids Can either be an array of IDs, one ID or the string 'all' to delete all users.
360
	 */
361 1
	public function delete_users($user_ids)
362
	{
363
364 1
		$sql_where = $this->sql_build_where($user_ids);
365
366 1
		$sql = 'DELETE FROM ' . $this->gallery_users_table . '
367 1
			' . $sql_where;
368 1
		$this->db->sql_query($sql);
369 1
	}
370
371
	/**
372
	 * Updates the users table with new data.
373
	 *
374
	 * @param mixed $user_ids Can either be an array of IDs, one ID or the string 'all' to update all users.
375
	 * @param array $data     Array of data we want to add/update.
376
	 * @return    bool                Returns true if the columns were updated successfully
377
	 */
378 1
	public function update_users($user_ids, $data)
379
	{
380 1
		$sql_ary = array_merge($this->validate_data($data), array(
381 1
			'user_last_update' => time(),
382
		));
383 1
		unset($sql_ary['user_id']);
384
385 1
		$sql_where = $this->sql_build_where($user_ids);
386
387 1
		$sql = 'UPDATE ' . $this->gallery_users_table . '
388 1
			SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . '
389 1
			' . $sql_where;
390 1
		$this->db->sql_query($sql);
391
392 1
		return ($this->db->sql_affectedrows() != 0) ? true : false;
393
	}
394
395
	/**
396
	 * Builds a valid WHERE-sql-statement, with casted integers, or empty to allow handling all users.
397
	 *
398
	 * @param mixed $user_ids Can either be an array of IDs, one ID or the string 'all' to update all users.
399
	 * @return    string                The WHERE statement with "WHERE " if needed.
400
	 */
401 5
	public function sql_build_where($user_ids)
402
	{
403 5
		if (is_array($user_ids) && !empty($user_ids))
404
		{
405 3
			$sql_where = 'WHERE ' . $this->db->sql_in_set('user_id', array_map('intval', $user_ids));
406
		}
407 4
		else if ($user_ids == 'all')
408
		{
409 3
			$sql_where = '';
410
		}
411
		else
412
		{
413 3
			$sql_where = 'WHERE user_id = ' . (int) $user_ids;
414
		}
415
416 5
		return $sql_where;
417
	}
418
419
	/**
420
	 * Validate user data.
421
	 *
422
	 * @param array $data Array of data we need to validate
423
	 * @param bool  $inc  Are we incrementing the value
424
	 * @return    array            Array with all allowed keys and their casted and selected values
425
	 */
426 115
	public function validate_data($data, $inc = false)
427
	{
428 115
		$validated_data = array();
429 115
		foreach ($data as $name => $value)
430
		{
431 115
			switch ($name)
432
			{
433 115
				case 'user_id':
434 115
				case 'user_images':
435 115
				case 'personal_album_id':
436 112
				case 'user_lastmark':
437 112
				case 'user_last_update':
438 115
					if ($inc && ($name == 'user_images'))
439
					{
440
						// While incrementing, the images might be lower than 0.
441
						$validated_data[$name] = (int) $value;
442
					}
443
					else
444
					{
445 115
						$validated_data[$name] = max(0, (int) $value);
446
					}
447 115
				break;
448
449 112
				case 'watch_own':
450 112
				case 'watch_com':
451 112
				case 'subscribe_pegas':
452 112
				case 'rrc_zebra':
453 112
					$validated_data[$name] = (bool) $value;
454 112
				break;
455
456 112
				case 'user_permissions':
457 112
					$validated_data[$name] = $value;
458 112
				break;
459
460
				default:
461 112
					$is_validated = false;
462
463
					/**
464
					 * Event user validate data
465
					 *
466
					 * @event phpbbgallery.core.user.validate_data
467
					 * @var    bool    is_validated    is value validated
468
					 * @var    string    name            value name
469
					 * @var    mixed    value            value of the value
470
					 * @since 1.2.0
471
					 */
472 112
					$vars = array('is_validated', 'name', 'value');
473 112
					extract($this->dispatcher->trigger_event('phpbbgallery.core.user.validate_data', compact($vars)));
474
475 112
					if ($is_validated)
476
					{
477
						$validated_data[$name] = $value;
478
					}
479 112
				break;
480
			}
481
		}
482 115
		return $validated_data;
483
	}
484
485 109
	private function get_default_value($key)
486
	{
487 109
		$default_values = $this->get_default_values();
488
489 109
		if (isset($default_values[$key]))
490
		{
491 109
			return $default_values[$key];
492
		}
493
494
		return null;
495
	}
496
497 113
	private function get_default_values()
498
	{
499 113
		static $default_values;
500
501 113
		if ($default_values)
502
		{
503 113
			return $default_values;
504
		}
505
506 1
		$default_values = self::$default_values;
507
508
		/**
509
		 * Event user validate data
510
		 *
511
		 * @event phpbbgallery.core.user.get_default_values
512
		 * @var    array    default_values    the default values array
513
		 * @since 1.2.0
514
		 */
515 1
		$vars = array('default_values');
516 1
		extract($this->dispatcher->trigger_event('phpbbgallery.core.user.get_default_values', compact($vars)));
517
518 1
		return $default_values;
519
	}
520
521
	/**
522
	 * Default values for new users.
523
	 */
524
	static protected $default_values = array(
525
		'user_images'              => 0,
526
		'personal_album_id'        => 0,
527
		'user_lastmark'            => 0,
528
		'user_last_update'         => 0,
529
		'user_permissions_changed' => 0,
530
531
		'user_permissions'    => '',
532
533
		// Shall other users be allowed to comment on this users images by default?
534
		'user_allow_comments' => true,
535
		// Shall the user be subscribed to his own images?
536
		'watch_own'           => true,
537
		// Shall the user be subscribed if he comments on an images?
538
		'watch_com'           => false,
539
		// Automatically subscribe user to new personal galleries?
540
		'subscribe_pegas'     => false,
541
		// Should we hide Foes from RRC
542
		'rrc_zebra'           => false,
543
	);
544
545
	/**
546
	 * @param $user_cache
547
	 * @param $row
548
	 */
549
	public function add_user_to_cache(&$user_cache, $row)
550
	{
551
		$user_id = $row['user_id'];
552
		if (!function_exists('phpbb_get_user_rank'))
553
		{
554
			include($this->root_path . 'includes/functions_display.' . $this->php_ext);
555
		}
556
557
		$now = $this->user->create_datetime();
558
		$now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset());
0 ignored issues
show
Bug introduced by
The function phpbb_gmgetdate was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

558
		$now = /** @scrutinizer ignore-call */ phpbb_gmgetdate($now->getTimestamp() + $now->getOffset());
Loading history...
559
560
		// Cache various user specific data ... so we don't have to recompute
561
		// this each time the same user appears on this page
562
		if (!isset($user_cache[$user_id]))
563
		{
564
			if ($user_id == ANONYMOUS)
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
565
			{
566
				$user_cache_data = array(
0 ignored issues
show
Unused Code introduced by
The assignment to $user_cache_data is dead and can be removed.
Loading history...
567
					'user_type'           => USER_IGNORE,
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\USER_IGNORE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
568
					'joined'              => '',
569
					'posts'               => '',
570
					'sig'                 => '',
571
					'sig_bbcode_uid'      => '',
572
					'sig_bbcode_bitfield' => '',
573
					'online'              => false,
574
					'avatar'              => ($this->user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : '',
0 ignored issues
show
Bug introduced by
The function phpbb_get_user_avatar was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

574
					'avatar'              => ($this->user->optionget('viewavatars')) ? /** @scrutinizer ignore-call */ phpbb_get_user_avatar($row) : '',
Loading history...
575
					'rank_title'          => '',
576
					'rank_image'          => '',
577
					'rank_image_src'      => '',
578
					'pm'                  => '',
579
					'email'               => '',
580
					'jabber'              => '',
581
					'search'              => '',
582
					'age'                 => '',
583
					'username'            => $row['username'],
584
					'user_colour'         => $row['user_colour'],
585
					'contact_user'        => '',
586
					'warnings'            => 0,
587
					'allow_pm'            => 0,
588
				);
589
			}
590
			else
591
			{
592
				$user_sig = '';
593
				// We add the signature to every posters entry because enable_sig is post dependent
594
				if ($row['user_sig'] && $this->config['allow_sig'] && $this->user->optionget('viewsigs'))
595
				{
596
					$user_sig = $row['user_sig'];
597
				}
598
				$user_cache_data = array(
599
					'user_type'            => $row['user_type'],
600
					'user_inactive_reason' => $row['user_inactive_reason'],
601
					'joined'               => $this->user->format_date($row['user_regdate']),
602
					'posts'                => $row['user_posts'],
603
					'warnings'             => (isset($row['user_warnings'])) ? $row['user_warnings'] : 0,
604
					'sig'                  => $user_sig,
605
					'sig_bbcode_uid'       => (!empty($row['user_sig_bbcode_uid'])) ? $row['user_sig_bbcode_uid'] : '',
606
					'sig_bbcode_bitfield'  => (!empty($row['user_sig_bbcode_bitfield'])) ? $row['user_sig_bbcode_bitfield'] : '',
607
					'viewonline'           => $row['user_allow_viewonline'],
608
					'allow_pm'             => $row['user_allow_pm'],
609
					'avatar'               => ($this->user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : '',
610
					'age'                  => '',
611
					'rank_title'           => '',
612
					'rank_image'           => '',
613
					'rank_image_src'       => '',
614
					'username'             => $row['username'],
615
					'user_colour'          => $row['user_colour'],
616
					'contact_user'         => $this->user->lang('CONTACT_USER', get_username_string('username', $user_id, $row['username'], $row['user_colour'], $row['username'])),
0 ignored issues
show
Bug introduced by
The function get_username_string was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

616
					'contact_user'         => $this->user->lang('CONTACT_USER', /** @scrutinizer ignore-call */ get_username_string('username', $user_id, $row['username'], $row['user_colour'], $row['username'])),
Loading history...
617
					'online'               => false,
618
					'jabber'               => ($this->config['jab_enable'] && $row['user_jabber'] && $this->auth->acl_get('u_sendim')) ? append_sid("{$this->root_path}memberlist.$this->php_ext", "mode=contact&amp;action=jabber&amp;u=$user_id") : '',
0 ignored issues
show
Bug introduced by
The function append_sid was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

618
					'jabber'               => ($this->config['jab_enable'] && $row['user_jabber'] && $this->auth->acl_get('u_sendim')) ? /** @scrutinizer ignore-call */ append_sid("{$this->root_path}memberlist.$this->php_ext", "mode=contact&amp;action=jabber&amp;u=$user_id") : '',
Loading history...
619
					'search'               => ($this->config['load_search'] && $this->auth->acl_get('u_search')) ? append_sid("{$this->root_path}search.$this->php_ext", "author_id=$user_id&amp;sr=posts") : '',
620
					'author_full'          => get_username_string('full', $user_id, $row['username'], $row['user_colour']),
621
					'author_colour'        => get_username_string('colour', $user_id, $row['username'], $row['user_colour']),
622
					'author_username'      => get_username_string('username', $user_id, $row['username'], $row['user_colour']),
623
					'author_profile'       => get_username_string('profile', $user_id, $row['username'], $row['user_colour']),
624
				);
625
626
				$user_cache[$user_id] = $user_cache_data;
627
628
				$user_rank_data = phpbb_get_user_rank($row, $row['user_posts']);
629
				$user_cache[$user_id]['rank_title'] = $user_rank_data['title'];
630
				$user_cache[$user_id]['rank_image'] = $user_rank_data['img'];
631
				$user_cache[$user_id]['rank_image_src'] = $user_rank_data['img_src'];
632
633
				if ((!empty($row['user_allow_viewemail']) && $this->auth->acl_get('u_sendemail')) || $this->auth->acl_get('a_email'))
634
				{
635
					$user_cache[$user_id]['email'] = ($this->config['board_email_form'] && $this->config['email_enable']) ? append_sid("{$this->root_path}memberlist.$this->php_ext", "mode=email&amp;u=$user_id") : (($this->config['board_hide_emails'] && !$this->auth->acl_get('a_email')) ? '' : 'mailto:' . $row['user_email']);
636
				}
637
				else
638
				{
639
					$user_cache[$user_id]['email'] = '';
640
				}
641
				if ($this->config['allow_birthdays'] && !empty($row['user_birthday']))
642
				{
643
					list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $row['user_birthday']));
644
					if ($bday_year)
645
					{
646
						$diff = $now['mon'] - $bday_month;
647
						if ($diff == 0)
648
						{
649
							$diff = ($now['mday'] - $bday_day < 0) ? 1 : 0;
650
						}
651
						else
652
						{
653
							$diff = ($diff < 0) ? 1 : 0;
654
						}
655
						$user_cache[$user_id]['age'] = (int) ($now['year'] - $bday_year - $diff);
656
					}
657
				}
658
			}
659
		}
660
	}
661
662
	/**
663
	 * Get user personal album
664
	 * Checks and returns users personal album
665
	 * returns (int) $album_id or 0
666
	 */
667 4
	public function get_own_root_album()
668
	{
669 4
		$sql = 'SELECT personal_album_id FROM ' . $this->gallery_users_table . ' WHERE user_id = ' . (int) $this->user_id;
670 4
		$result = $this->db->sql_query($sql);
671 4
		$row = $this->db->sql_fetchrow($result);
672 4
		if ($row)
673
		{
674 4
			return (int) $row['personal_album_id'];
675
		}
676 1
		return false;
677
	}
678
679
	/**
680
	 * Destroy user data and set this class to empty
681
	 */
682 8
	public function destroy()
683
	{
684 8
		$this->user_id = null;
685 8
		$this->entry_exists = null;
686 8
		$this->data = array();
687 8
	}
688
689
	/**
690
	 * @param array $user_ids Array of user IDs
691
	 * @return int                    Count of updated Users
692
	 */
693
694
	public function set_personal_albums($user_ids)
695
	{
696
		if (!is_array($user_ids))
0 ignored issues
show
introduced by
The condition is_array($user_ids) is always true.
Loading history...
697
		{
698
			$user_ids = array($user_ids);
699
		}
700
		$sql = 'SELECT user_id, personal_album_id FROM ' . $this->gallery_users_table . ' WHERE ' . $this->db->sql_in_set('user_id', $user_ids);
701
		//var_dump($sql);
702
		$result = $this->db->sql_query($sql);
703
		$set_array = array();
704
		while ($row = $this->db->sql_fetchrow($result))
705
		{
706
			//var_dump($row);
707
			if ($row['personal_album_id'] > 0)
708
			{
709
				$set_array[$row['user_id']] = $row['personal_album_id'];
710
			}
711
		}
712
		$this->db->sql_freeresult($result);
713
		$updated_rows = 0;
714
		if (count($set_array) > 0)
715
		{
716
			foreach ($set_array as $uid => $album_id)
717
			{
718
				// Fill album CPF.
719
				$cpf_vars = array(
720
					'pf_gallery_palbum' => (int) $album_id,
721
				);
722
				$this->user_cpf->update_profile_field_data((int) $uid, $cpf_vars);
723
724
				$updated_rows++;
725
			}
726
		}
727
728
		return $updated_rows;
729
	}
730
}
731