search::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 20
ccs 15
cts 15
cp 1
rs 9.7998
cc 1
nc 1
nop 14
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    satanasov
7
 * @author    Leinad4Mind
8
 * @copyright 2014- satanasov, 2018- Leinad4Mind
9
 * @license   GPL-2.0-only
10
 */
11
12
namespace phpbbgallery\core;
13
14
class search
15
{
16
	/* @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...
17
	protected $db;
18
19
	/* @var \phpbb\request\request */
0 ignored issues
show
Bug introduced by
The type phpbb\request\request 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...
20
	protected $request;
21
22
	/* @var \phpbb\template\template */
0 ignored issues
show
Bug introduced by
The type phpbb\template\template 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...
23
	protected $template;
24
25
	/* @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...
26
	protected $user;
27
28
	/* @var \phpbb\language\language */
0 ignored issues
show
Bug introduced by
The type phpbb\language\language 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...
29
	protected $language;
30
31
	/* @var \phpbb\controller\helper */
0 ignored issues
show
Bug introduced by
The type phpbb\controller\helper 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...
32
	protected $helper;
33
34
	/* @var \phpbbgallery\core\config */
35
	protected $gallery_config;
36
37
	/* @var \phpbbgallery\core\auth\auth */
38
	protected $gallery_auth;
39
40
	/* @var \phpbbgallery\core\album\album */
41
	protected $album;
42
43
	/* @var \phpbbgallery\core\image\image */
44
	protected $image;
45
46
	/* @var \phpbb\pagination */
0 ignored issues
show
Bug introduced by
The type phpbb\pagination 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...
47
	protected $pagination;
48
49
	/* @var \phpbb\user_loader */
0 ignored issues
show
Bug introduced by
The type phpbb\user_loader 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...
50
	protected $user_loader;
51
52
	/* @var string */
53
	protected $images_table;
54
55
	/* @var string */
56
	protected $albums_table;
57
58
	/* @var string */
59
	protected $comments_table;
60
61
	/* @var \phpbbgallery\core\album\display */
62
	protected $display;
63
64
	/* @var string */
65
	protected $root_path;
66
67
	/* @var string */
68
	protected $php_ext;
69
70
	/**
71
	 * Constructor
72
	 *
73
	 * @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db       Database object
74
	 * @param \phpbb\template\template                                  $template Template object
75
	 * @param \phpbb\user                                               $user     User object
76
	 * @param \phpbb\language\language                                  $language
77
	 * @param \phpbb\controller\helper                                  $helper   Controller helper object
78
	 * @param config                                                    $gallery_config
79
	 * @param auth\auth                                                 $gallery_auth
80
	 * @param album\album                                               $album
81
	 * @param image\image                                               $image
82
	 * @param \phpbb\pagination                                         $pagination
83
	 * @param \phpbb\user_loader                                        $user_loader
84
	 * @param                                                           $images_table
85
	 * @param                                                           $albums_table
86
	 * @param                                                           $comments_table
87
	 * @internal param \phpbb\auth\auth $auth Auth object
88
	 * @internal param \phpbb\config\config $config Config object
89
	 * @internal param \phpbb\request\request $request Request object
90
	 * @internal param album\display $display Albums display object
91
	 * @internal param string $root_path Root path
92
	 * @internal param string $php_ext php file extension
93
	 */
94 90
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \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...
95
		\phpbb\language\language $language, \phpbb\controller\helper $helper, \phpbbgallery\core\config $gallery_config,
96
		\phpbbgallery\core\auth\auth $gallery_auth, \phpbbgallery\core\album\album $album, \phpbbgallery\core\image\image $image,
97
		\phpbb\pagination $pagination, \phpbb\user_loader $user_loader,
98
		$images_table, $albums_table, $comments_table)
99
	{
100 90
		$this->db = $db;
101 90
		$this->template = $template;
102 90
		$this->user = $user;
103 90
		$this->language = $language;
104 90
		$this->helper = $helper;
105 90
		$this->gallery_config = $gallery_config;
106 90
		$this->gallery_auth = $gallery_auth;
107 90
		$this->album = $album;
108 90
		$this->image = $image;
109 90
		$this->pagination = $pagination;
110 90
		$this->user_loader = $user_loader;
111 90
		$this->images_table = $images_table;
112 90
		$this->albums_table = $albums_table;
113 90
		$this->comments_table = $comments_table;
114 90
	}
115
116
	/**
117
	 * Generate random images and populate template
118
	 * @param (int)    $limit    how many images to generate_link
119
	 * @param int $user
120
	 * @param string $fields
121
	 * @param bool $block_name
122
	 * @param bool $u_block
123
	 */
124 33
	public function random($limit, $user = 0, $fields = 'rrc_gindex_display', $block_name = false, $u_block = false)
125
	{
126
		// We will do small escape for not devising by 0
127 33
		if ($limit == 0)
128
		{
129
			return;
130
		}
131 33
		if ($limit < -1)
132
		{
133
			$limit = -1;
134
		}
135
		// Define some vars
136 33
		$images_per_page = $limit;
137
138 33
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
139
140 33
		switch ($this->db->get_sql_layer())
141
		{
142 33
			case 'postgres':
143 33
			case 'sqlite3':
144
				$sql_order = 'RANDOM()';
145
			break;
146
147 33
			case 'mssql':
148 33
			case 'mssql_odbc':
149
				$sql_order = 'NEWID()';
150
			break;
151
152
			default:
153 33
				$sql_order = 'RAND()';
154 33
			break;
155
		}
156 33
		$sql_limit = $images_per_page;
157
		$sql = 'SELECT image_id
158 33
			FROM ' . $this->images_table . '
159 33
			WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN;
160 33
		if ($user > 0)
161
		{
162 30
			$sql .= ' and image_user_id = ' . (int) $user;
163
		}
164 33
		$exclude_albums = array();
165 33
		if (!$this->gallery_config->get('rrc_gindex_pegas'))
166
		{
167
			$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0';
168
			$result = $this->db->sql_query($sql_no_user);
169
			while ($row = $this->db->sql_fetchrow($result))
170
			{
171
				$exclude_albums[] = (int) $row['album_id'];
172
			}
173
			$this->db->sql_freeresult($result);
174
		}
175 33
		$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra());
176 33
		$sql .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
0 ignored issues
show
Bug introduced by
It seems like $this->gallery_auth->acl_album_ids('i_view') can also be of type true; however, parameter $array of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

176
		$sql .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff(/** @scrutinizer ignore-type */ $this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
Loading history...
177 33
					OR (' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('a_list'), $exclude_albums), false, true) . ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
178 33
					OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')
179 33
			ORDER BY ' . $sql_order;
180
181 33
		if (!$sql_limit)
182
		{
183
			$result = $this->db->sql_query($sql);
184
		}
185
		else
186
		{
187 33
			$result = $this->db->sql_query_limit($sql, $sql_limit);
188
		}
189 33
		$id_ary = array();
190 33
		while ($row = $this->db->sql_fetchrow($result))
191
		{
192 33
			$id_ary[] = $row['image_id'];
193
		}
194 33
		$this->db->sql_freeresult($result);
195
196 33
		$total_match_count = sizeof($id_ary);
197
198 33
		$l_search_matches = $this->language->lang('FOUND_SEARCH_MATCHES', $total_match_count);
0 ignored issues
show
Unused Code introduced by
The assignment to $l_search_matches is dead and can be removed.
Loading history...
199
200 33
		$this->template->assign_block_vars('imageblock', array(
201 33
			'BLOCK_NAME'	=> $block_name ? $block_name : $this->language->lang('RANDOM_IMAGES'),
202 33
			'U_BLOCK'	=> $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_random'),
203
		));
204
205
		// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
206 33
		if (!sizeof($id_ary))
207
		{
208
			$this->template->assign_block_vars('imageblock', array(
209
				'ERROR'	=> $this->language->lang('NO_SEARCH_RESULTS_RANDOM'),
210
			));
211
			return;
212
		}
213
214 33
		$id_ary = array_map('intval', $id_ary);
215
216 33
		$sql_where = $this->db->sql_in_set('i.image_id', $id_ary);
217
218
		$sql_array = array(
219 33
			'SELECT'		=> 'i.*, a.album_name, a.album_status, a.album_user_id, album_id',
220 33
			'FROM'			=> array($this->images_table => 'i'),
221
222
			'LEFT_JOIN'		=> array(
223
				array(
224 33
					'FROM'		=> array($this->albums_table => 'a'),
225 33
					'ON'		=> 'a.album_id = i.image_album_id',
226
				),
227
			),
228
229 33
			'WHERE'			=> 'i.image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where,
230 33
			'GROUP_BY'	=> 'i.image_id, a.album_name, a.album_status, a.album_user_id, a.album_id',
231 33
			'ORDER_BY'		=> $sql_order,
232
		);
233 33
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
234 33
		$result = $this->db->sql_query($sql);
235
236 33
		$show_options = $this->gallery_config->get($fields);
237 33
		$thumbnail_link = $this->gallery_config->get('link_thumbnail');
238 33
		$imagename_link = $this->gallery_config->get('link_image_name');
239
240 33
		while ($row = $this->db->sql_fetchrow($result))
241
		{
242 33
			$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link);
243
		}
244
245 33
		$this->db->sql_freeresult($result);
246 33
	}
247
248
	/**
249
	* Get all recent images the user has access to
250
	* return (int) $images_count
251
	*/
252 2
	public function recent_count()
253
	{
254 2
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
255
256 2
		$exclude_albums = [];
257
258 2
		if (!$this->gallery_config->get('rrc_gindex_pegas'))
259
		{
260
			$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0';
261
			$result = $this->db->sql_query($sql_no_user);
262
			while ($row = $this->db->sql_fetchrow($result))
263
			{
264
				$exclude_albums[] = (int) $row['album_id'];
265
			}
266
			$this->db->sql_freeresult($result);
267
		}
268
269 2
		$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra());
270
271
		// Get allowed album ids for view and mod permissions excluding excluded albums
272 2
		$view_album_ids = array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums);
0 ignored issues
show
Bug introduced by
It seems like $this->gallery_auth->acl_album_ids('i_view') can also be of type true; however, parameter $array of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

272
		$view_album_ids = array_diff(/** @scrutinizer ignore-type */ $this->gallery_auth->acl_album_ids('i_view'), $exclude_albums);
Loading history...
273 2
		$mod_album_ids = array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums);
274
275 2
		if (empty($view_album_ids) && empty($mod_album_ids))
276
		{
277
			return 0;
278
		}
279
280
		$sql = 'SELECT COUNT(image_id) AS count
281 2
			FROM ' . $this->images_table . '
282 2
			WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN;
283
284 2
		$conditions = [];
285
286 2
		if (!empty($view_album_ids))
287
		{
288 2
			$conditions[] = '(' . $this->db->sql_in_set('image_album_id', $view_album_ids) . '
289 2
				AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')';
290
		}
291
292 2
		if (!empty($mod_album_ids))
293
		{
294
			$conditions[] = $this->db->sql_in_set('image_album_id', $mod_album_ids);
295
		}
296
297 2
		if (!empty($conditions))
298
		{
299 2
			$sql .= ' AND (' . implode(' OR ', $conditions) . ')';
300
		}
301
302 2
		$result = $this->db->sql_query($sql);
303 2
		$row = $this->db->sql_fetchrow($result);
304 2
		$this->db->sql_freeresult($result);
305
306 2
		return (int) $row['count'];
307
	}
308
309
310
311
	/**
312
	 * recent comments
313
	 * @param (int)    $limit How many images to query
314
	 * @param int $start
315
	 */
316 7
	public function recent_comments($limit, $start = 0, $pagination = true)
317
	{
318 7
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
319 7
		$sql_limit = $limit;
320 7
		$exclude_albums = array();
321 7
		if (!$this->gallery_config->get('rrc_gindex_pegas'))
322
		{
323
			$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0';
324
			$result = $this->db->sql_query($sql_no_user);
325
			while ($row = $this->db->sql_fetchrow($result))
326
			{
327
				$exclude_albums[] = (int) $row['album_id'];
328
			}
329
			$this->db->sql_freeresult($result);
330
		}
331 7
		$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra());
332
		$sql_array = array(
333
			'FROM' => array(
334 7
				$this->images_table => 'i',
335 7
				$this->comments_table => 'c',
336
			),
337 7
			'WHERE'	=> 'i.image_id = c.comment_image_id and ' . $this->db->sql_in_set('image_album_id', $this->gallery_auth->acl_album_ids('c_read'), false, true),
338 7
			'GROUP_BY'	=> 'c.comment_id, c.comment_time, i.image_id',
339 7
			'ORDER_BY'	=> 'comment_time DESC'
340
		);
341 7
		$sql_array['WHERE'] .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
0 ignored issues
show
Bug introduced by
It seems like $this->gallery_auth->acl_album_ids('i_view') can also be of type true; however, parameter $array of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

341
		$sql_array['WHERE'] .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff(/** @scrutinizer ignore-type */ $this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
Loading history...
342 7
					OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')';
343
344 7
		$sql_array_count = $sql_array;
345 7
		$sql_array_count['SELECT'] = 'COUNT(c.comment_id) as count';
346 7
		unset($sql_array_count['GROUP_BY'], $sql_array_count['ORDER_BY']);
347 7
		$sql = $this->db->sql_build_query('SELECT', $sql_array_count);
348 7
		$result = $this->db->sql_query($sql);
349 7
		$row = $this->db->sql_fetchrow($result);
350 7
		$this->db->sql_freeresult($result);
351
352 7
		$count = ($row) ? (int) $row['count'] : 0;
353
354 7
		$sql_array['SELECT'] = '*';
355 7
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
356 7
		$result = $this->db->sql_query_limit($sql, $sql_limit, $start);
357 7
		$rowset = [];
358
359 7
		$users_array = [];
360 7
		while ($row = $this->db->sql_fetchrow($result))
361
		{
362 6
			$rowset[] = $row;
363 6
			$users_array[$row['comment_user_id']] = array('');
364 6
			$users_array[$row['image_user_id']] = array('');
365
		}
366 7
		$this->db->sql_freeresult($result);
367 7
		if (empty($rowset))
368
		{
369 1
			$this->template->assign_vars(array(
370 1
				'ERROR'	=> $this->language->lang('NO_SEARCH_RESULTS_RECENT_COMMENTS'),
371
			));
372 1
			return;
373
		}
374
375 6
		$this->user_loader->load_users(array_keys($users_array));
376 6
		foreach ($rowset as $var)
377
		{
378 6
			$album_tmp = $this->album->get_info($var['image_album_id']);
379 6
			$this->template->assign_block_vars('commentrow', array(
380 6
				'COMMENT_ID'	=> (int) $var['comment_id'],
381 6
				'U_DELETE'	=> ($this->gallery_auth->acl_check('m_comments', $album_tmp['album_id'], $album_tmp['album_user_id']) || ($this->gallery_auth->acl_check('c_delete', $album_tmp['album_id'], $album_tmp['album_user_id']) && ($var['comment_user_id'] == $this->user->data['user_id']) && $this->user->data['is_registered'])) ? $this->helper->route('phpbbgallery_core_comment_delete', array('image_id' => $var['comment_image_id'], 'comment_id' => $var['comment_id'])) : false,
382 6
				'U_EDIT'	=> $this->gallery_auth->acl_check('c_edit', $album_tmp['album_id'], $album_tmp['album_user_id'])? $this->helper->route('phpbbgallery_core_comment_edit', array('image_id'	=> $var['comment_image_id'], 'comment_id'	=> $var['comment_id'])) : false,
383 6
				'U_QUOTE'	=> ($this->gallery_auth->acl_check('c_post', $album_tmp['album_id'], $album_tmp['album_user_id'])) ? $this->helper->route('phpbbgallery_core_comment_add', array('image_id'	=> $var['comment_image_id'], 'comment_id'	=> $var['comment_id'])) : false,
384 6
				'U_COMMENT'	=> $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['comment_image_id'])) . '#comment_' . $var['comment_id'],
385 6
				'POST_AUTHOR_FULL'	=> (string) $this->user_loader->get_username($var['comment_user_id'], 'full'),
386 6
				'TIME'	=> $this->user->format_date($var['comment_time']),
387 6
				'TEXT'	=> generate_text_for_display($var['comment'], $var['comment_uid'], $var['comment_bitfield'], 7),
0 ignored issues
show
Bug introduced by
The function generate_text_for_display 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

387
				'TEXT'	=> /** @scrutinizer ignore-call */ generate_text_for_display($var['comment'], $var['comment_uid'], $var['comment_bitfield'], 7),
Loading history...
388 6
				'UC_IMAGE_NAME'	=> '<a href="' . $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['comment_image_id'])) . '">' . $var['image_name'] . '</a>',
389
				// 'UC_THUMBNAIL'		=> $this->helper->route('phpbbgallery_core_image_file_mini', array('image_id' => $var['image_id'])),
390 6
				'UC_THUMBNAIL'		=> $this->image->generate_link('thumbnail', $this->gallery_config->get('link_thumbnail'), $var['comment_image_id'], $var['image_name'], $var['image_album_id']),
391 6
				'IMAGE_AUTHOR'		=> $this->user_loader->get_username((int) $var['image_user_id'], 'full'),
392 6
				'IMAGE_TIME'		=> $this->user->format_date($var['image_time']),
393
			));
394
		}
395 6
		$this->template->assign_vars([
396 6
			'SEARCH_MATCHES'	=> $this->language->lang('TOTAL_COMMENTS_SPRINTF', $count),
397 6
			'SEARCH_TITLE'		=> $this->language->lang('RECENT_COMMENTS'),
398
		]);
399 6
		if ($pagination)
400
		{
401 6
			$this->pagination->generate_template_pagination([
402
				'routes' => [
403 6
						'phpbbgallery_core_search_commented',
404
						'phpbbgallery_core_search_commented_page'
405
					],
406
					'params' => []
407 6
				], 'pagination', 'page', $count, $limit, $start
408
			);
409
		}
410 6
	}
411
412
	/**
413
	 * Generate recent images and populate template
414
	 * @param (int)    $limit How many images to query
415
	 * @param int $start
416
	 * @param int $user
417
	 * @param string $fields
418
	 * @param bool $block_name
419
	 * @param bool $u_block
420
	 */
421 34
	public function recent($limit, $start = 0, $user = 0, $fields = 'rrc_gindex_display', $block_name = false, $u_block = false)
422
	{
423
		// We will do small escape for not devising by 0
424 34
		if ($limit == 0)
425
		{
426
			return;
427
		}
428 34
		if ($limit < -1)
429
		{
430
			$limit = -1;
431
		}
432 34
		$pagination = true;
433 34
		if ($start == -1)
434
		{
435 1
			$start = 0;
436 1
			$pagination = false;
437
		}
438 34
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
439 34
		$sql_order = '';
440 34
		switch ($this->gallery_config->get('default_sort_key'))
441
		{
442 34
			case 't':
443 34
				$sql_order = 'image_time';
444 34
				break;
445
			case 'n':
446
				$sql_order = 'image_name_clean';
447
				break;
448
			case 'vc':
449
				$sql_order = 'image_view_count';
450
				break;
451
			case 'u':
452
				$sql_order = 'image_username_clean';
453
				break;
454
			case 'ra':
455
				$sql_order = 'image_rate_avg';
456
				break;
457
			case 'r':
458
				$sql_order = 'image_rates';
459
				break;
460
			case 'c':
461
				$sql_order = 'image_comments';
462
				break;
463
			case 'lc':
464
				$sql_order = 'image_last_comment';
465
				break;
466
		}
467 34
		$sql_order = $sql_order . ($this->gallery_config->get('default_sort_dir') == 'd' ? ' DESC' : ' ASC');
468 34
		$sql_limit = $limit;
469 34
		$exclude_albums = array();
470 34
		if (!$this->gallery_config->get('rrc_gindex_pegas'))
471
		{
472
			$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0';
473
			$result = $this->db->sql_query($sql_no_user);
474
			while ($row = $this->db->sql_fetchrow($result))
475
			{
476
				$exclude_albums[] = (int) $row['album_id'];
477
			}
478
			$this->db->sql_freeresult($result);
479
		}
480 34
		$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra());
481
		$sql_ary = array(
482
			'FROM'	=>	array(
483 34
				$this->images_table	=> 'i'
484
			),
485 34
			'WHERE'	=> 'image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN
486
		);
487 34
		if ($user > 0)
488
		{
489 30
			$sql_ary['WHERE'] .= ' and image_user_id = ' . (int) $user;
490
		}
491 34
		$user_id = $this->user->data['user_id'];
492 34
		$sql_ary['WHERE'] .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND (image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ' OR image_user_id = ' . $user_id . '))
0 ignored issues
show
Bug introduced by
It seems like $this->gallery_auth->acl_album_ids('i_view') can also be of type true; however, parameter $array of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

492
		$sql_ary['WHERE'] .= ' AND ((' . $this->db->sql_in_set('image_album_id', array_diff(/** @scrutinizer ignore-type */ $this->gallery_auth->acl_album_ids('i_view'), $exclude_albums), false, true) . ' AND (image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ' OR image_user_id = ' . $user_id . '))
Loading history...
493 34
					OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')';
494
495 34
		$sql_ary['SELECT'] = 'COUNT(image_id) as count';
496 34
		$sql = $this->db->sql_build_query('SELECT', $sql_ary);
497 34
		$result = $this->db->sql_query($sql);
498 34
		$row = $this->db->sql_fetchrow($result);
499 34
		$this->db->sql_freeresult($result);
500 34
		$count = $row['count'];
501
502 34
		$sql_ary['SELECT'] = 'image_id';
503 34
		$sql_ary['ORDER_BY'] = $sql_order;
504 34
		$sql = $this->db->sql_build_query('SELECT', $sql_ary);
505 34
		$result = $this->db->sql_query_limit($sql, $sql_limit, $start);
506 34
		$id_ary = [];
507 34
		while ($row = $this->db->sql_fetchrow($result))
508
		{
509 34
			$id_ary[] = $row['image_id'];
510
		}
511
512 34
		$this->db->sql_freeresult($result);
513
514 34
		$total_match_count = sizeof($id_ary);
515
516 34
		$l_search_matches = $this->language->lang('FOUND_SEARCH_MATCHES', $total_match_count);
0 ignored issues
show
Unused Code introduced by
The assignment to $l_search_matches is dead and can be removed.
Loading history...
517
518 34
		if ($user > 0)
519
		{
520 30
			$this->template->assign_block_vars('imageblock', array(
521 30
				'BLOCK_NAME'	=> $block_name ? $block_name : '' ,
522 30
				'U_BLOCK'	=> $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_egosearch'),
523
			));
524
		}
525
		else
526
		{
527 4
			$this->template->assign_block_vars('imageblock', array(
528 4
				'BLOCK_NAME'	=>  $block_name ? $block_name : $this->language->lang('RECENT_IMAGES'),
529 4
				'U_BLOCK'	=> $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_recent'),
530
			));
531
		}
532
533
		// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
534 34
		if (!sizeof($id_ary))
535
		{
536
			$this->template->assign_block_vars('imageblock', array(
537
				'ERROR'	=> $this->language->lang('NO_SEARCH_RESULTS_RECENT')
538
			));
539
			return;
540
		}
541
542 34
		$id_ary = array_map('intval', $id_ary);
543
544 34
		$sql_where = $this->db->sql_in_set('i.image_id', $id_ary);
545
546
		$sql_array = array(
547 34
			'SELECT'		=> 'i.*, a.album_name, a.album_status, a.album_user_id, a.album_id',
548 34
			'FROM'			=> array($this->images_table => 'i'),
549
550
			'LEFT_JOIN'		=> array(
551
				array(
552 34
					'FROM'		=> array($this->albums_table => 'a'),
553 34
					'ON'		=> 'a.album_id = i.image_album_id',
554
				),
555
			),
556
557 34
			'WHERE'			=> 'i.image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where,
558 34
			'ORDER_BY'		=> $sql_order,
559
		);
560 34
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
561 34
		$result = $this->db->sql_query($sql);
562
563 34
		$show_options = $this->gallery_config->get($fields);
564 34
		$thumbnail_link = $this->gallery_config->get('link_thumbnail');
565 34
		$imagename_link = $this->gallery_config->get('link_image_name');
566
567 34
		while ($row = $this->db->sql_fetchrow($result))
568
		{
569 34
			$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link);
570
		}
571 34
		$this->db->sql_freeresult($result);
572
573 34
		if ($user > 0)
574
		{
575 30
			$this->template->assign_vars(array(
576 30
				'SEARCH_MATCHES'	=> $this->language->lang('TOTAL_IMAGES_SPRINTF', $count),
577 30
				'SEARCH_TITLE'		=> $this->language->lang('SEARCH_USER_IMAGES_OF', $this->user->data['username']),
578
			));
579 30
			$this->pagination->generate_template_pagination(array(
580
				'routes' => array(
581 30
					'phpbbgallery_core_search_egosearch',
582
					'phpbbgallery_core_search_egosearch_page',),
583 30
					'params' => array()), 'pagination', 'page', $count, $limit, $start
584
			);
585
		}
586
		else
587
		{
588 4
			$this->template->assign_vars(array(
589 4
				'TOTAL_IMAGES'				=> $this->language->lang('VIEW_ALBUM_IMAGES', $count),
590
			));
591 4
			if ($pagination)
592
			{
593 3
				$this->pagination->generate_template_pagination(array(
594
					'routes' => array(
595 3
						'phpbbgallery_core_search_recent',
596
						'phpbbgallery_core_search_recent_page',),
597 3
						'params' => array()), 'pagination', 'page', $count, $limit, $start
598
				);
599
			}
600
		}
601 34
	}
602
603
	/**
604
	 * Get top rated image
605
	 * @param $limit
606
	 * @param int $start
607
	 */
608
	public function rating($limit, $start = 0)
609
	{
610
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
611
		$sql_array = array();
612
		$sql_array['FROM'] = array(
613
			$this->images_table	=> 'i'
614
		);
615
		$sql_array['WHERE'] = $this->db->sql_in_set('image_album_id', $this->gallery_auth->acl_album_ids('i_view'), false, true) . ' and image_rate_avg <> 0';
616
		$sql_array['SELECT'] = 'COUNT(image_id) as count';
617
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
618
		$result = $this->db->sql_query($sql);
619
		$row = $this->db->sql_fetchrow($result);
620
		$this->db->sql_freeresult($result);
621
		$count = $row['count'];
622
		$sql_array['SELECT'] = '* , a.album_name, a.album_status, a.album_user_id, a.album_id';
623
		$sql_array['LEFT_JOIN']	= array(
624
			array(
625
				'FROM'		=> array($this->albums_table => 'a'),
626
				'ON'		=> 'a.album_id = i.image_album_id',
627
			)
628
		);
629
		$sql_array['ORDER_BY'] = 'image_rate_avg DESC, image_rates DESC';
630
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
631
		$result = $this->db->sql_query_limit($sql, $limit, $start);
632
		$rowset = [];
633
634
		while ($row = $this->db->sql_fetchrow($result))
635
		{
636
			$rowset[] = $row;
637
			$users_array[$row['image_user_id']] = array('');
638
		}
639
		$this->db->sql_freeresult($result);
640
		if (empty($rowset))
641
		{
642
			$this->template->assign_var('S_NO_SEARCH', true);
643
			trigger_error('NO_SEARCH');
644
		}
645
646
		$this->template->assign_block_vars('imageblock', array(
647
			'BLOCK_NAME'	=> $this->language->lang('SEARCH_TOPRATED'),
648
			'U_BLOCK'	=> $this->helper->route('phpbbgallery_core_search_toprated'),
649
		));
650
		$this->user_loader->load_users(array_keys($users_array));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $users_array does not seem to be defined for all execution paths leading up to this point.
Loading history...
651
		// Now let's get display options
652
		$show_options = $this->gallery_config->get('rrc_gindex_display');
653
		$thumbnail_link = $this->gallery_config->get('link_thumbnail');
654
		$imagename_link = $this->gallery_config->get('link_image_name');
655
		foreach ($rowset as $row)
656
		{
657
			$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link);
658
		}
659
660
		$this->template->assign_vars(array(
661
			'SEARCH_MATCHES'	=> $this->language->lang('TOTAL_IMAGES_SPRINTF', $count),
662
			'SEARCH_TITLE'		=> $this->language->lang('SEARCH_TOPRATED'),
663
		));
664
		$this->pagination->generate_template_pagination(array(
665
			'routes' => array(
666
				'phpbbgallery_core_search_toprated',
667
				'phpbbgallery_core_search_toprated_page',),
668
				'params' => array()), 'pagination', 'page', $count, $limit, $start
669
		);
670
	}
671
}
672