search::base()   F
last analyzed

Complexity

Conditions 34
Paths > 20000

Size

Total Lines 231
Code Lines 151

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 1190

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 151
c 6
b 0
f 0
dl 0
loc 231
rs 0
ccs 0
cts 202
cp 0
cc 34
nc 399392
nop 1
crap 1190

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\controller;
13
14
class search
15
{
16
	/* @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...
17
	protected $auth;
18
19
	/* @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...
20
	protected $config;
21
22
	/* @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...
23
	protected $db;
24
25
	/** @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...
26
	protected $pagination;
27
28
	/* @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...
29
	protected $request;
30
31
	/* @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...
32
	protected $template;
33
34
	/* @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...
35
	protected $user;
36
37
	/** @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...
38
	protected $language;
39
40
	/* @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...
41
	protected $helper;
42
43
	/* @var \phpbbgallery\core\album\display */
44
	protected $display;
45
46
	/** @var \phpbbgallery\core\config  */
47
	protected $gallery_config;
48
49
	/** @var \phpbbgallery\core\auth\auth  */
50
	protected $gallery_auth;
51
52
	/** @var \phpbbgallery\core\album\album  */
53
	protected $album;
54
55
	/** @var \phpbbgallery\core\image\image  */
56
	protected $image;
57
58
	/** @var \phpbbgallery\core\url  */
59
	protected $url;
60
61
	/** @var \phpbbgallery\core\search  */
62
	protected $gallery_search;
63
64
	/** @var   */
65
	protected $images_table;
66
67
	/** @var   */
68
	protected $albums_table;
69
70
	/** @var   */
71
	protected $comments_table;
72
73
	/* @var string */
74
	protected $root_path;
75
76
	/* @var string */
77
	protected $php_ext;
78
79
	/**
80
	 * Constructor
81
	 *
82
	 * @param \phpbb\auth\auth                                          $auth      Auth object
83
	 * @param \phpbb\config\config                                      $config    Config object
84
	 * @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db        Database object
85
	 * @param \phpbb\pagination                                         $pagination
86
	 * @param \phpbb\request\request                                    $request   Request object
87
	 * @param \phpbb\template\template                                  $template  Template object
88
	 * @param \phpbb\user                                               $user      User object
89
	 * @param \phpbb\language\language                                  $language
90
	 * @param \phpbb\controller\helper                                  $helper    Controller helper object
91
	 * @param \phpbbgallery\core\album\display                          $display   Albums display object
92
	 * @param \phpbbgallery\core\config                                 $gallery_config
93
	 * @param \phpbbgallery\core\auth\auth                              $gallery_auth
94
	 * @param \phpbbgallery\core\album\album                            $album
95
	 * @param \phpbbgallery\core\image\image                            $image
96
	 * @param \phpbbgallery\core\url                                    $url
97
	 * @param \phpbbgallery\core\search                                 $gallery_search
98
	 * @param                                                           $images_table
99
	 * @param                                                           $albums_table
100
	 * @param                                                           $comments_table
101
	 * @param string                                                    $root_path Root path
102
	 * @param string                                                    $php_ext   php file extension
103
	 */
104
	public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db,
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...
105
		\phpbb\pagination $pagination, \phpbb\request\request $request,
106
		\phpbb\template\template $template, \phpbb\user $user, \phpbb\language\language $language, \phpbb\controller\helper $helper,
107
		\phpbbgallery\core\album\display $display, \phpbbgallery\core\config $gallery_config,
108
		\phpbbgallery\core\auth\auth $gallery_auth, \phpbbgallery\core\album\album $album, \phpbbgallery\core\image\image $image,
109
		\phpbbgallery\core\url $url, \phpbbgallery\core\search $gallery_search,
110
		$images_table, $albums_table, $comments_table, $root_path, $php_ext)
111
	{
112
		$this->auth = $auth;
113
		$this->config = $config;
114
		$this->db = $db;
115
		$this->pagination = $pagination;
116
		$this->request = $request;
117
		$this->template = $template;
118
		$this->user = $user;
119
		$this->language = $language;
120
		$this->helper = $helper;
121
		$this->display = $display;
122
		$this->gallery_config = $gallery_config;
123
		$this->gallery_auth = $gallery_auth;
124
		$this->album = $album;
125
		$this->image = $image;
126
		$this->url = $url;
127
		$this->gallery_search = $gallery_search;
128
		$this->images_table = $images_table;
129
		$this->albums_table = $albums_table;
130
		$this->comments_table = $comments_table;
131
		$this->root_path = $root_path;
132
		$this->php_ext = $php_ext;
133
	}
134
135
	/**
136
	 * Index Controller
137
	 *    Route: gallery/search/{page}
138
	 *
139
	 * @param int $page
140
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response 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...
141
	 */
142
143
	public function base($page = 1)
144
	{
145
		$search_id		= $this->request->variable('search_id', '');
146
		$image_id		= $this->request->variable('image_id', 0);
0 ignored issues
show
Unused Code introduced by
The assignment to $image_id is dead and can be removed.
Loading history...
147
148
		$submit			= $this->request->variable('submit', false);
149
		$keywords		= utf8_normalize_nfc($this->request->variable('keywords', '', true));
0 ignored issues
show
Bug introduced by
The function utf8_normalize_nfc 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

149
		$keywords		= /** @scrutinizer ignore-call */ utf8_normalize_nfc($this->request->variable('keywords', '', true));
Loading history...
150
		$add_keywords	= utf8_normalize_nfc($this->request->variable('add_keywords', '', true));
151
		$username		= $this->request->variable('username', '', true);
152
		$user_id			= $this->request->variable('user_id', array(0));
153
		$search_terms	= $this->request->variable('terms', 'all');
154
		$search_album	= $this->request->variable('aid', array(0));
155
		$search_child	= $this->request->variable('sc', true);
156
		$search_fields	= $this->request->variable('sf', 'all');
157
		$sort_days		= $this->request->variable('st', 0);
158
		$sort_key		= $this->request->variable('sk', 't');
159
		$sort_dir		= $this->request->variable('sd', 'd');
160
		$filtered		= $this->request->variable('filtered', false);
161
162
		$start 			= ($page - 1) * $this->gallery_config->get('items_per_page');
163
		if ($filtered)
164
		{
165
			$submit = true;
166
		}
167
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
168
		$this->language->add_lang('search');
169
		/**
170
		* Build the sort options
171
		*/
172
		$limit_days = array(0 => $this->language->lang('ALL_IMAGES'), 1 => $this->language->lang('1_DAY'), 7 => $this->language->lang('7_DAYS'), 14 => $this->language->lang('2_WEEKS'), 30 => $this->language->lang('1_MONTH'), 90 => $this->language->lang('3_MONTHS'), 180 => $this->language->lang('6_MONTHS'), 365 => $this->language->lang('1_YEAR'));
173
		$sort_by_text = array('t' => $this->language->lang('TIME'), 'n' => $this->language->lang('IMAGE_NAME'), 'u' => $this->language->lang('SORT_USERNAME'), 'vc' => $this->language->lang('GALLERY_VIEWS'));
174
		$sort_by_sql = array('t' => 'image_time', 'n' => 'image_name_clean', 'u' => 'image_username_clean', 'vc' => 'image_view_count');
175
176
		if ($this->gallery_config->get('allow_rates'))
177
		{
178
			$sort_by_text['ra'] = $this->language->lang('RATING');
179
			$sort_by_sql['ra'] = 'image_rate_points';//@todo: (phpbb_gallery_contest::$mode == phpbb_gallery_contest::MODE_SUM) ? 'image_rate_points' : 'image_rate_avg';
180
			$sort_by_text['r'] = $this->language->lang('RATES_COUNT');
181
			$sort_by_sql['r'] = 'image_rates';
182
		}
183
		if ($this->gallery_config->get('allow_comments'))
184
		{
185
			$sort_by_text['c'] = $this->language->lang('COMMENTS');
186
			$sort_by_sql['c'] = 'image_comments';
187
			$sort_by_text['lc'] = $this->language->lang('NEW_COMMENT');
188
			$sort_by_sql['lc'] = 'image_last_comment';
189
		}
190
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
191
192
		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
193
		gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
0 ignored issues
show
Bug introduced by
The function gen_sort_selects 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

193
		/** @scrutinizer ignore-call */ 
194
  gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
Loading history...
194
		$sql_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
195
196
		// We will build SQL array and then build query (easily change count with rq)
197
		$sql_array = $sql_where = array();
198
		$sql_array['FROM'] = array(
199
			$this->images_table => 'i',
200
		);
201
		if ($keywords || $username || $user_id || $search_id || $submit)
202
		{
203
			// Let's resolve username to user id ... or array of them.
204
			if ($username)
205
			{
206
				if ((strpos($username, '*') !== false) && (utf8_strlen(str_replace(array('*', '%'), '', $username)) < $this->config['min_search_author_chars']))
0 ignored issues
show
Bug introduced by
The function utf8_strlen 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

206
				if ((strpos($username, '*') !== false) && (/** @scrutinizer ignore-call */ utf8_strlen(str_replace(array('*', '%'), '', $username)) < $this->config['min_search_author_chars']))
Loading history...
207
				{
208
					trigger_error(sprintf($this->language->lang('TOO_FEW_AUTHOR_CHARS'), $this->config['min_search_author_chars']));
209
				}
210
				$username_parsed = (strpos($username, '*') !== false) ? ' username_clean ' . $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), utf8_clean_string($this->db->sql_escape($username)))) : ' username_clean = \'' . $this->db->sql_escape(utf8_clean_string($username)) .'\'';
0 ignored issues
show
Bug introduced by
The function utf8_clean_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

210
				$username_parsed = (strpos($username, '*') !== false) ? ' username_clean ' . $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), /** @scrutinizer ignore-call */ utf8_clean_string($this->db->sql_escape($username)))) : ' username_clean = \'' . $this->db->sql_escape(utf8_clean_string($username)) .'\'';
Loading history...
211
				$sql = 'SELECT user_id
212
					FROM ' . USERS_TABLE . '
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\controller\USERS_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
213
					WHERE ' . $username_parsed . '
214
					AND user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ')';
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\controller\USER_FOUNDER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant phpbbgallery\core\controller\USER_NORMAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
215
				$result = $this->db->sql_query_limit($sql, 100);
216
217
				$user_id_ary = [];
218
				while ($row = $this->db->sql_fetchrow($result))
219
				{
220
					$user_id_ary[] = (int) $row['user_id'];
221
				}
222
				$this->db->sql_freeresult($result);
223
224
				$user_id_ary[] = (int) ANONYMOUS;
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\controller\ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
225
				$user_id = $user_id_ary;
226
			}
227
228
			if (!empty($user_id))
229
			{
230
				$sql_where[] =  $this->db->sql_in_set('i.image_user_id', $user_id);
231
			}
232
			// if we search in an existing search result just add the additional keywords. But we need to use "all search terms"-mode
233
			// so we can keep the old keywords in their old mode, but add the new ones as required words
234
			if ($add_keywords)
235
			{
236
				if ($search_terms == 'all')
237
				{
238
					$keywords .= ' ' . $add_keywords;
239
				}
240
				else
241
				{
242
					$search_terms = 'all';
243
					$keywords = preg_replace('#\s+#u', ' |', $keywords) . ' ' .$add_keywords;
244
				}
245
			}
246
			$keywords_ary = ($keywords) ? explode(' ', $keywords) : array();
247
248
			// pre-made searches
249
			$sql = $field = $l_search_title = $search_results = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $l_search_title is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $search_results is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $sql is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $field is dead and can be removed.
Loading history...
250
251
			$total_match_count = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_match_count is dead and can be removed.
Loading history...
252
			$sql_limit = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $sql_limit is dead and can be removed.
Loading history...
253
254
			$search_query = '';
255
			$matches = array('i.image_name', 'i.image_desc');
0 ignored issues
show
Unused Code introduced by
The assignment to $matches is dead and can be removed.
Loading history...
256
257
			if (is_array($keywords_ary) && !sizeof($keywords_ary) && is_array($user_id_ary) && !sizeof($user_id_ary))
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $user_id_ary does not seem to be defined for all execution paths leading up to this point.
Loading history...
258
			{
259
				trigger_error('NO_SEARCH_RESULTS');
260
			}
261
			$matches = array('i.image_name', 'i.image_desc');
262
263
			foreach ($keywords_ary as $word)
264
			{
265
				$match_search_query = '';
266
				foreach ($matches as $match)
267
				{
268
					$match_search_query .= (($match_search_query) ? ' OR ' : '') . 'LOWER('. $match . ') ';
269
					$match_search_query .= $this->db->sql_like_expression(str_replace('*', $this->db->get_any_char(), $this->db->get_any_char() . mb_strtolower($word) . $this->db->get_any_char()));
270
				}
271
				$search_query .= ((!$search_query) ? '' : (($search_terms == 'all') ? ' AND ' : ' OR ')) . '(' . $match_search_query . ')';
272
			}
273
			$sql_where[] = $search_query;
274
275
			if (empty($search_album))
276
			{
277
				$sql_where[] = $this->db->sql_in_set('i.image_album_id', $this->gallery_auth->acl_album_ids('i_view'));
278
			}
279
			else
280
			{
281
				$sql_where[] = $this->db->sql_in_set('i.image_album_id', $search_album);
282
			}
283
			$sql_array['WHERE'] = implode(' and ', array_filter($sql_where));
284
			$sql_array['SELECT'] = 'COUNT(i.image_id) as count';
285
286
			$sql = $this->db->sql_build_query('SELECT', $sql_array);
287
			$result = $this->db->sql_query($sql);
288
			$row = $this->db->sql_fetchrow($result);
289
			$search_count = $row['count'];
290
			//var_dump($sql);
291
			$this->db->sql_freeresult($result);
292
			if ($search_count == 0)
293
			{
294
				trigger_error('NO_SEARCH_RESULTS');
295
			}
296
			$sql_array['SELECT'] = '*, a.album_name, a.album_status, a.album_user_id, a.album_id';
297
			$sql_array['LEFT_JOIN']	= array(
298
				array(
299
					'FROM'		=> array($this->albums_table => 'a'),
300
					'ON'		=> 'a.album_id = i.image_album_id',
301
				)
302
			);
303
			$sql_array['ORDER_BY'] = $sql_order;
304
			$sql_array['GROUP_BY'] = $sort_by_sql[$sort_key] . ', i.image_id, a.album_id';
305
306
			$sql = $this->db->sql_build_query('SELECT', $sql_array);
307
			$result = $this->db->sql_query_limit($sql, $this->gallery_config->get('items_per_page'), $start);
308
			while ($row = $this->db->sql_fetchrow($result))
309
			{
310
				$rowset[] = $row;
311
			}
312
			$this->db->sql_freeresult($result);
313
			$this->template->assign_block_vars('imageblock', array(
314
				'BLOCK_NAME'	=> '',
315
				'U_BLOCK'	=> $this->helper->route('phpbbgallery_core_search'),
316
			));
317
318
			$show_options = $this->gallery_config->get('search_display');
319
			$thumbnail_link = $this->gallery_config->get('link_thumbnail');
320
			$imagename_link = $this->gallery_config->get('link_image_name');
321
			foreach ($rowset as $row)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $rowset does not seem to be defined for all execution paths leading up to this point.
Loading history...
322
			{
323
				$this->image->assign_block('imageblock.image', $row, $show_options, $thumbnail_link, $imagename_link);
324
			}
325
			$current_page = $page*$this->gallery_config->get('items_per_page');
326
			$this->pagination->generate_template_pagination(array(
327
				'routes' => array(
328
					'phpbbgallery_core_search',
329
					'phpbbgallery_core_search_page',
330
				),
331
				'params' => array(
332
					'keywords'	=> $keywords,
333
					'username'	=> $username,
334
					'user_id'	=> $user_id,
335
					'terms'		=> $search_terms,
336
					'aid'			=> $search_album,
337
					'sc'			=> $search_child,
338
					'sf'			=> $search_fields,
339
					'st'			=> $sort_days,
340
					'sk'			=> $sort_key,
341
					'sd'			=> $sort_dir,
342
					'filtered'	=> true
343
				),
344
			), 'pagination', 'page', $search_count, $this->gallery_config->get('items_per_page'), $current_page - 1);
345
346
			$this->template->assign_vars(array(
347
				'SEARCH_MATCHES'	=> $this->language->lang('FOUND_SEARCH_MATCHES', $search_count),
348
			));
349
			return $this->helper->render('gallery/search_results.html', $this->language->lang('GALLERY'));
350
		}
351
		// Is user able to search? Has search been disabled?
352
		if (!$this->auth->acl_get('u_search') || !$this->config['load_search'])
353
		{
354
			$this->template->assign_var('S_NO_SEARCH', true);
355
			trigger_error('NO_SEARCH');
356
		}
357
		$this->template->assign_block_vars('navlinks', array(
358
			'FORUM_NAME'	=> $this->language->lang('SEARCH'),
359
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search'),
360
		));
361
362
		$s_albums = $this->album->get_albumbox(false, false, false, 'i_view' /*'a_search'*/);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type string expected by parameter $select_name of phpbbgallery\core\album\album::get_albumbox(). ( Ignorable by Annotation )

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

362
		$s_albums = $this->album->get_albumbox(false, /** @scrutinizer ignore-type */ false, false, 'i_view' /*'a_search'*/);
Loading history...
363
		$s_hidden_fields = array();
364
		$this->template->assign_vars(array(
365
			'S_SEARCH_ACTION'		=> $this->helper->route('phpbbgallery_core_search'), // We force no ?sid= appending by using 0
366
			'S_HIDDEN_FIELDS'		=> build_hidden_fields($s_hidden_fields),
0 ignored issues
show
Bug introduced by
The function build_hidden_fields 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

366
			'S_HIDDEN_FIELDS'		=> /** @scrutinizer ignore-call */ build_hidden_fields($s_hidden_fields),
Loading history...
367
			'S_ALBUM_OPTIONS'		=> $s_albums,
368
			'S_SELECT_SORT_DIR'		=> $s_sort_dir,
369
			'S_SELECT_SORT_KEY'		=> $s_sort_key,
370
			'S_SELECT_SORT_DAYS'	=> $s_limit_days,
371
			'S_IN_SEARCH'			=> true,
372
		));
373
		return $this->helper->render('gallery/search_body.html', $this->language->lang('GALLERY'));
374
	}
375
376
	/**
377
	* Index Controller
378
	*	Route: gallery/search/random
379
	*
380
	* @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
381
	*/
382
	public function random()
383
	{
384
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
385
		$this->language->add_lang('search');
386
387
		// Is user able to search? Has search been disabled?
388
		if (!$this->auth->acl_get('u_search') || !$this->config['load_search'])
389
		{
390
			$this->template->assign_var('S_NO_SEARCH', true);
391
			trigger_error('NO_SEARCH');
392
		}
393
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
394
		$this->template->assign_block_vars('navlinks', array(
395
			'FORUM_NAME'	=> $this->language->lang('GALLERY'),
396
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_index'),
397
		));
398
		$this->template->assign_block_vars('navlinks', array(
399
			'FORUM_NAME'	=> $this->language->lang('SEARCH'),
400
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search'),
401
		));
402
		$this->template->assign_block_vars('navlinks', array(
403
			'FORUM_NAME'	=> $this->language->lang('SEARCH_RANDOM'),
404
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search_random'),
405
		));
406
407
		$this->gallery_search->random($this->gallery_config->get('items_per_page'));
408
409
		return $this->helper->render('gallery/search_random.html', $this->language->lang('GALLERY'));
410
	}
411
412
	/**
413
	 * Index Controller
414
	 *    Route: gallery/search/recent/{page}
415
	 *
416
	 * @param $page
417
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
418
	 */
419
	public function recent($page)
420
	{
421
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
422
		$this->language->add_lang('search');
423
424
		// Is user able to search? Has search been disabled?
425
		if (!$this->auth->acl_get('u_search') || !$this->config['load_search'])
426
		{
427
			$this->template->assign_var('S_NO_SEARCH', true);
428
			trigger_error('NO_SEARCH');
429
		}
430
431
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
432
		$this->template->assign_block_vars('navlinks', array(
433
			'FORUM_NAME'	=> $this->language->lang('GALLERY'),
434
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_index'),
435
		));
436
		$this->template->assign_block_vars('navlinks', array(
437
			'FORUM_NAME'	=> $this->language->lang('SEARCH'),
438
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search'),
439
		));
440
		$this->template->assign_block_vars('navlinks', array(
441
			'FORUM_NAME'	=> $this->language->lang('SEARCH_RECENT'),
442
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search_recent'),
443
		));
444
445
		$limit = $this->gallery_config->get('items_per_page');
446
		$start = ($page - 1) * $limit;
447
		$image_counter = $this->gallery_search->recent_count();
0 ignored issues
show
Unused Code introduced by
The assignment to $image_counter is dead and can be removed.
Loading history...
448
449
		$this->gallery_search->recent($limit, $start);
450
451
		return $this->helper->render('gallery/search_recent.html', $this->language->lang('GALLERY'));
452
	}
453
454
	/**
455
	 * Index Controller
456
	 *    Route: gallery/search/commented/{page}
457
	 *
458
	 * @param $page
459
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
460
	 */
461
	public function recent_comments($page)
462
	{
463
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
464
		$this->language->add_lang('search');
465
466
		// Is user able to search? Has search been disabled?
467
		if (!$this->auth->acl_get('u_search') || !$this->config['load_search'])
468
		{
469
			$this->template->assign_var('S_NO_SEARCH', true);
470
			trigger_error('NO_SEARCH');
471
		}
472
473
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
474
		$this->template->assign_block_vars('navlinks', array(
475
			'FORUM_NAME'	=> $this->language->lang('GALLERY'),
476
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_index'),
477
		));
478
		$this->template->assign_block_vars('navlinks', array(
479
			'FORUM_NAME'	=> $this->language->lang('SEARCH'),
480
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search'),
481
		));
482
		$this->template->assign_block_vars('navlinks', array(
483
			'FORUM_NAME'	=> $this->language->lang('SEARCH_RECENT_COMMENTS'),
484
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search_commented'),
485
		));
486
487
		$limit = $this->gallery_config->get('items_per_page');
488
		$start = ($page - 1) * $limit;
489
490
		$this->gallery_search->recent_comments($limit, $start);
491
492
		return $this->helper->render('gallery/search_results.html', $this->language->lang('GALLERY'));
493
	}
494
495
	/**
496
	 * Index Controller
497
	 *    Route: gallery/search/self/{page}
498
	 *
499
	 * @param $page
500
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
501
	 */
502
	public function ego_search($page)
503
	{
504
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
505
		$this->language->add_lang('search');
506
507
		// Is user able to search? Has search been disabled?
508
		if (!$this->auth->acl_get('u_search') || !$this->config['load_search'])
509
		{
510
			$this->template->assign_var('S_NO_SEARCH', true);
511
			trigger_error('NO_SEARCH');
512
		}
513
514
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
515
		$this->template->assign_block_vars('navlinks', array(
516
			'FORUM_NAME'	=> $this->language->lang('GALLERY'),
517
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_index'),
518
		));
519
		$this->template->assign_block_vars('navlinks', array(
520
			'FORUM_NAME'	=> $this->language->lang('SEARCH'),
521
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search'),
522
		));
523
		$this->template->assign_block_vars('navlinks', array(
524
			'FORUM_NAME'	=> $this->language->lang('SEARCH_USER_IMAGES_OF', $this->user->data['username']),
525
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search_egosearch'),
526
		));
527
528
		$limit = $this->gallery_config->get('items_per_page');
529
		$start = ($page - 1) * $limit;
530
531
		$this->gallery_search->recent($limit, $start, $this->user->data['user_id']);
532
533
		return $this->helper->render('gallery/search_results.html', $this->language->lang('GALLERY'));
534
	}
535
536
	/**
537
	 * Index Controller
538
	 *    Route: gallery/search/toprated/{page}
539
	 *
540
	 * @param $page
541
	 * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
542
	 */
543
	public function toprated($page)
544
	{
545
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
546
		$this->language->add_lang('search');
547
548
		// Is user able to search? Has search been disabled?
549
		if (!$this->auth->acl_get('u_search') || !$this->config['load_search'])
550
		{
551
			$this->template->assign_var('S_NO_SEARCH', true);
552
			trigger_error('NO_SEARCH');
553
		}
554
555
		$this->gallery_auth->load_user_permissions($this->user->data['user_id']);
556
		$this->template->assign_block_vars('navlinks', array(
557
			'FORUM_NAME'	=> $this->language->lang('GALLERY'),
558
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_index'),
559
		));
560
		$this->template->assign_block_vars('navlinks', array(
561
			'FORUM_NAME'	=> $this->language->lang('SEARCH'),
562
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search'),
563
		));
564
		$this->template->assign_block_vars('navlinks', array(
565
			'FORUM_NAME'	=> $this->language->lang('SEARCH_TOPRATED'),
566
			'U_VIEW_FORUM'	=> $this->helper->route('phpbbgallery_core_search_egosearch'),
567
		));
568
569
		$limit = $this->gallery_config->get('items_per_page');
570
		$start = ($page - 1) * $limit;
571
572
		$this->gallery_search->rating($limit, $start);
573
574
		return $this->helper->render('gallery/search_results.html', $this->language->lang('GALLERY'));
575
	}
576
}
577