Passed
Push — master ( 70dac4...ab6c4f )
by Stanislav
23:28 queued 20:40
created

search::__construct()   A

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

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

268
		$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 <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
Loading history...
269 2
					OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')';
270 2
		$result = $this->db->sql_query($sql);
271 2
		$row = $this->db->sql_fetchrow($result);
272 2
		return (int) $row['count'];
273
	}
274
275
	/**
276
	 * recent comments
277
	 * @param (int)    $limit How many imagese to query
278
	 * @param int $start
279
	 */
280 7
	public function recent_comments($limit, $start = 0)
281
	{
282 7
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
283 7
		$sql_limit = $limit;
284 7
		$exclude_albums = array();
285 7
		if (!$this->gallery_config->get('rrc_gindex_pegas'))
286
		{
287
			$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0';
288
			$result = $this->db->sql_query($sql_no_user);
289
			while ($row = $this->db->sql_fetchrow($result))
290
			{
291
				$exclude_albums[] = (int) $row['album_id'];
292
			}
293
			$this->db->sql_freeresult($result);
294
		}
295 7
		$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra());
296
		$sql_array = array(
297
			'FROM' => array(
298 7
				$this->images_table => 'i',
299 7
				$this->comments_table => 'c',
300
			),
301 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),
302 7
			'GROUP_BY'	=> 'c.comment_id, c.comment_time',
303 7
			'ORDER_BY'	=> 'comment_time DESC'
304
		);
305 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 <> ' . \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

305
		$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 <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED . ')
Loading history...
306 7
					OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')';
307
308 7
		$sql_array['SELECT'] = 'COUNT(c.comment_id) as count';
309 7
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
310 7
		$result = $this->db->sql_query($sql);
311 7
		$row = $this->db->sql_fetchrow($result);
312 7
		$this->db->sql_freeresult($result);
313 7
		$count = 0;
314 7
		if ($row)
315
		{
316 7
			$count = $row['count'];
317
		}
318 7
		$sql_array['SELECT'] = '*';
319 7
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
320 7
		$result = $this->db->sql_query_limit($sql, $sql_limit, $start);
321 7
		$rowset = array();
322
323 7
		$users_array = array();
324 7
		while ($row = $this->db->sql_fetchrow($result))
325
		{
326 6
			$rowset[] = $row;
327 6
			$users_array[$row['comment_user_id']] = array('');
328 6
			$users_array[$row['image_user_id']] = array('');
329
		}
330 7
		$this->db->sql_freeresult($result);
331 7
		if (empty($rowset))
332
		{
333 1
			$this->template->assign_vars(array(
334 1
				'ERROR'	=> $this->language->lang('NO_SEARCH_RESULTS_RECENT_COMMENTS'),
335
			));
336 1
			return;
337
		}
338
339 6
		$this->user_loader->load_users(array_keys($users_array));
340 6
		foreach ($rowset as $var)
341
		{
342
343 6
			$album_tmp = $this->album->get_info($var['image_album_id']);
344 6
			$this->template->assign_block_vars('commentrow', array(
345 6
				'COMMENT_ID'	=> (int) $var['comment_id'],
346 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,
347 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,
348 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,
349 6
				'U_COMMENT'	=> $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['comment_image_id'])) . '#comment_' . $var['comment_id'],
350 6
				'POST_AUTHOR_FULL'	=> (string) $this->user_loader->get_username($var['comment_user_id'], 'full'),
351 6
				'TIME'	=> $this->user->format_date($var['comment_time']),
352 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

352
				'TEXT'	=> /** @scrutinizer ignore-call */ generate_text_for_display($var['comment'], $var['comment_uid'], $var['comment_bitfield'], 7),
Loading history...
353 6
				'UC_IMAGE_NAME'	=> '<a href="' . $this->helper->route('phpbbgallery_core_image', array('image_id' => $var['comment_image_id'])) . '">' . $var['image_name'] . '</a>',
354
				// 'UC_THUMBNAIL'		=> $this->helper->route('phpbbgallery_core_image_file_mini', array('image_id' => $var['image_id'])),
355 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']),
356 6
				'IMAGE_AUTHOR'		=> $this->user_loader->get_username((int) $var['image_user_id'], 'full'),
357 6
				'IMAGE_TIME'		=> $this->user->format_date($var['image_time']),
358
			));
359
		}
360 6
		$this->template->assign_vars(array(
361 6
			'SEARCH_MATCHES'	=> $this->language->lang('TOTAL_COMMENTS_SPRINTF', $count),
362 6
			'SEARCH_TITLE'		=> $this->language->lang('RECENT_COMMENTS'),
363
		));
364 6
		$this->pagination->generate_template_pagination(array(
365
			'routes' => array(
366 6
				'phpbbgallery_core_search_commented',
367
				'phpbbgallery_core_search_commented_page',),
368 6
				'params' => array()), 'pagination', 'page', $count, $limit, $start
369
		);
370 6
	}
371
372
	/**
373
	 * Generate recent images and populate template
374
	 * @param (int)    $limit How many imagese to query
375
	 * @param int $start
376
	 * @param int $user
377
	 * @param string $fields
378
	 * @param bool $block_name
379
	 * @param bool $u_block
380
	 */
381 34
	public function recent($limit, $start = 0, $user = 0, $fields = 'rrc_gindex_display', $block_name = false, $u_block = false)
382
	{
383
		// We will do small escape for not devising by 0
384 34
		if ($limit == 0)
385
		{
386
			return;
387
		}
388 34
		if ($limit < -1)
389
		{
390
			$limit = -1;
391
		}
392 34
		$pagination = true;
393 34
		if ($start == -1)
394
		{
395 1
			$start = 0;
396 1
			$pagination = false;
397
		}
398 34
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
399 34
		$sql_order = '';
400 34
		switch ($this->gallery_config->get('default_sort_key'))
401
		{
402 34
			case 't':
403 34
				$sql_order = 'image_time';
404 34
				break;
405
			case 'n':
406
				$sql_order = 'image_name_clean';
407
				break;
408
			case 'vc':
409
				$sql_order = 'image_view_count';
410
				break;
411
			case 'u':
412
				$sql_order = 'image_username_clean';
413
				break;
414
			case 'ra':
415
				$sql_order = 'image_rate_avg';
416
				break;
417
			case 'r':
418
				$sql_order = 'image_rates';
419
				break;
420
			case 'c':
421
				$sql_order = 'image_comments';
422
				break;
423
			case 'lc':
424
				$sql_order = 'image_last_comment';
425
				break;
426
		}
427 34
		$sql_order = $sql_order . ($this->gallery_config->get('default_sort_dir') == 'd' ? ' DESC' : ' ASC');
428 34
		$sql_limit = $limit;
429 34
		$exclude_albums = array();
430 34
		if (!$this->gallery_config->get('rrc_gindex_pegas'))
431
		{
432
			$sql_no_user = 'SELECT album_id FROM ' . $this->albums_table . ' WHERE album_user_id > 0';
433
			$result = $this->db->sql_query($sql_no_user);
434
			while ($row = $this->db->sql_fetchrow($result))
435
			{
436
				$exclude_albums[] = (int) $row['album_id'];
437
			}
438
			$this->db->sql_freeresult($result);
439
		}
440 34
		$exclude_albums = array_merge($exclude_albums, $this->gallery_auth->get_exclude_zebra());
441
		$sql_ary = array(
442
			'FROM'	=>	array(
443 34
				$this->images_table	=> 'i'
444
			),
445
			'WHERE'	=> 'image_status <> ' . \phpbbgallery\core\block::STATUS_ORPHAN
446
		);
447 34
		if ($user > 0)
448
		{
449 30
			$sql_ary['WHERE'] .= ' and image_user_id = ' . (int) $user;
450
		}
451 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 . ')
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

451
		$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 . ')
Loading history...
452 34
					OR ' . $this->db->sql_in_set('image_album_id', array_diff($this->gallery_auth->acl_album_ids('m_status'), $exclude_albums), false, true) . ')';
453
454 34
		$sql_ary['SELECT'] = 'COUNT(image_id) as count';
455 34
		$sql = $this->db->sql_build_query('SELECT', $sql_ary);
456 34
		$result = $this->db->sql_query($sql);
457 34
		$row = $this->db->sql_fetchrow($result);
458 34
		$this->db->sql_freeresult($result);
459 34
		$count = $row['count'];
460
461 34
		$sql_ary['SELECT'] = 'image_id';
462 34
		$sql_ary['ORDER_BY'] = $sql_order;
463 34
		$sql = $this->db->sql_build_query('SELECT', $sql_ary);
464 34
		$result = $this->db->sql_query_limit($sql, $sql_limit, $start);
465 34
		$id_ary = array();
466 34
		while ($row = $this->db->sql_fetchrow($result))
467
		{
468 34
			$id_ary[] = $row['image_id'];
469
		}
470
471 34
		$this->db->sql_freeresult($result);
472
473 34
		$total_match_count = sizeof($id_ary);
474
475 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...
476
477 34
		if ($user > 0)
478
		{
479 30
			$this->template->assign_block_vars('imageblock', array(
480 30
				'BLOCK_NAME'	=> $block_name ? $block_name : '' ,
481 30
				'U_BLOCK'	=> $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_egosearch'),
482
			));
483
		}
484
		else
485
		{
486 4
			$this->template->assign_block_vars('imageblock', array(
487 4
				'BLOCK_NAME'	=>  $block_name ? $block_name : $this->language->lang('RECENT_IMAGES'),
488 4
				'U_BLOCK'	=> $u_block ? $u_block : $this->helper->route('phpbbgallery_core_search_recent'),
489
			));
490
		}
491
492
		// For some searches we need to print out the "no results" page directly to allow re-sorting/refining the search options.
493 34
		if (!sizeof($id_ary))
494
		{
495
			$this->template->assign_block_vars('imageblock', array(
496
				'ERROR'	=> $this->language->lang('NO_SEARCH_RESULTS_RECENT')
497
			));
498
			return;
499
		}
500
501 34
		$sql_where = $this->db->sql_in_set('i.image_id', $id_ary);
502
503
		$sql_array = array(
504 34
			'SELECT'		=> 'i.*, a.album_name, a.album_status, a.album_user_id, a.album_id',
505 34
			'FROM'			=> array($this->images_table => 'i'),
506
507
			'LEFT_JOIN'		=> array(
508
				array(
509 34
					'FROM'		=> array($this->albums_table => 'a'),
510 34
					'ON'		=> 'a.album_id = i.image_album_id',
511
				),
512
			),
513
514 34
			'WHERE'			=> 'i.image_status <> ' . \phpbbgallery\core\block::STATUS_ORPHAN . ' AND ' . $sql_where,
515 34
			'ORDER_BY'		=> $sql_order,
516
		);
517 34
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
518 34
		$result = $this->db->sql_query($sql);
519
520 34
		$show_options = $this->gallery_config->get($fields);
521 34
		$thumbnail_link = $this->gallery_config->get('link_thumbnail');
522 34
		$imagename_link = $this->gallery_config->get('link_image_name');
523
524 34
		while ($row = $this->db->sql_fetchrow($result))
525
		{
526 34
			$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link);
527
		}
528 34
		$this->db->sql_freeresult($result);
529
530 34
		if ($user > 0)
531
		{
532 30
			$this->template->assign_vars(array(
533 30
				'SEARCH_MATCHES'	=> $this->language->lang('TOTAL_IMAGES_SPRINTF', $count),
534 30
				'SEARCH_TITLE'		=> $this->language->lang('SEARCH_USER_IMAGES_OF', $this->user->data['username']),
535
			));
536 30
			$this->pagination->generate_template_pagination(array(
537
				'routes' => array(
538 30
					'phpbbgallery_core_search_egosearch',
539
					'phpbbgallery_core_search_egosearch_page',),
540 30
					'params' => array()), 'pagination', 'page', $count, $limit, $start
541
			);
542
		}
543
		else
544
		{
545 4
			$this->template->assign_vars(array(
546 4
				'TOTAL_IMAGES'				=> $this->language->lang('VIEW_ALBUM_IMAGES', $count),
547
			));
548 4
			if ($pagination)
549
			{
550 3
				$this->pagination->generate_template_pagination(array(
551
					'routes' => array(
552 3
						'phpbbgallery_core_search_recent',
553
						'phpbbgallery_core_search_recent_page',),
554 3
						'params' => array()), 'pagination', 'page', $count, $limit, $start
555
				);
556
			}
557
		}
558 34
	}
559
560
	/**
561
	 * Get top rated image
562
	 * @param $limit
563
	 * @param int $start
564
	 */
565
	public function rating($limit, $start = 0)
566
	{
567
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
568
		$sql_array = array();
569
		$sql_array['FROM'] = array(
570
			$this->images_table	=> 'i'
571
		);
572
		$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';
573
		$sql_array['SELECT'] = 'COUNT(image_id) as count';
574
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
575
		$result = $this->db->sql_query($sql);
576
		$row = $this->db->sql_fetchrow($result);
577
		$this->db->sql_freeresult($result);
578
		$count = $row['count'];
579
		$sql_array['SELECT'] = '* , a.album_name, a.album_status, a.album_user_id, a.album_id';
580
		$sql_array['LEFT_JOIN']	= array(
581
			array(
582
				'FROM'		=> array($this->albums_table => 'a'),
583
				'ON'		=> 'a.album_id = i.image_album_id',
584
			)
585
		);
586
		$sql_array['ORDER_BY'] = 'image_rate_avg DESC, image_rates DESC';
587
		$sql = $this->db->sql_build_query('SELECT', $sql_array);
588
		$result = $this->db->sql_query_limit($sql, $limit, $start);
589
		$rowset = array();
590
591
		while ($row = $this->db->sql_fetchrow($result))
592
		{
593
			$rowset[] = $row;
594
			$users_array[$row['image_user_id']] = array('');
595
		}
596
		$this->db->sql_freeresult($result);
597
		if (empty($rowset))
598
		{
599
			$this->template->assign_var('S_NO_SEARCH', true);
600
			trigger_error('NO_SEARCH');
601
		}
602
603
		$this->template->assign_block_vars('imageblock', array(
604
			'BLOCK_NAME'	=> $this->language->lang('SEARCH_TOPRATED'),
605
			'U_BLOCK'	=> $this->helper->route('phpbbgallery_core_search_toprated'),
606
		));
607
		$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...
608
		// Now let's get display options
609
		$show_options = $this->gallery_config->get('rrc_gindex_display');
610
		$thumbnail_link = $this->gallery_config->get('link_thumbnail');
611
		$imagename_link = $this->gallery_config->get('link_image_name');
612
		foreach ($rowset as $row)
613
		{
614
			$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link);
615
		}
616
617
		$this->template->assign_vars(array(
618
			'SEARCH_MATCHES'	=> $this->language->lang('TOTAL_IMAGES_SPRINTF', $count),
619
			'SEARCH_TITLE'		=> $this->language->lang('SEARCH_TOPRATED'),
620
		));
621
		$this->pagination->generate_template_pagination(array(
622
			'routes' => array(
623
				'phpbbgallery_core_search_toprated',
624
				'phpbbgallery_core_search_toprated_page',),
625
				'params' => array()), 'pagination', 'page', $count, $limit, $start
626
		);
627
	}
628
}
629