Passed
Pull Request — master (#316)
by
unknown
03:13 queued 32s
created

album::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 28
ccs 19
cts 19
cp 1
rs 9.6666
cc 1
nc 1
nop 18
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
 *
5
 * @package       phpBB Gallery Core
6
 * @copyright (c) 2014 nickvergessen
7
 * @license       http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace phpbbgallery\core\controller;
12
13
class album
14
{
15
	/* @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...
16
	protected $config;
17
18
	/* @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...
19
	protected $helper;
20
21
	/* @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...
22
	protected $db;
23
24
	/* @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...
25
	protected $pagination;
26
27
	/* @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...
28
	protected $template;
29
30
	/* @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...
31
	protected $user;
32
33
	/** @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...
34
	protected $language;
35
36
	/* @var \phpbbgallery\core\album\display */
37
	protected $display;
38
39
	/* @var \phpbbgallery\core\album\loader */
40
	protected $loader;
41
42
	/* @var \phpbbgallery\core\auth\auth */
43
	protected $auth;
44
45
	/* @var \phpbbgallery\core\auth\level */
46
	protected $auth_level;
47
48
	/** @var \phpbbgallery\core\notification\helper */
49
	protected $notifications_helper;
50
51
	/** @var \phpbbgallery\core\url */
52
	protected $url;
53
54
	/** @var \phpbbgallery\core\image\image */
55
	protected $image;
56
57
	/** @var \phpbbgallery\core\config */
58
	protected $gallery_config;
59
60
	/** @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...
61
	protected $request;
62
63
	/** @var \phpbbgallery\core\contest */
64
	protected $contest;
65
66
	/* @var string */
67
	protected $table_images;
68
69
	/**
70
	 * Constructor
71
	 *
72
	 * @param \phpbb\config\config                                      $config       Config object
73
	 * @param \phpbb\controller\helper                                  $helper       Controller helper object
74
	 * @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db           Database object
75
	 * @param \phpbb\pagination                                         $pagination   Pagination object
76
	 * @param \phpbb\template\template                                  $template     Template object
77
	 * @param \phpbb\user                                               $user         User object
78
	 * @param \phpbb\language\language                                  $language
79
	 * @param \phpbbgallery\core\album\display                          $display      Albums display object
80
	 * @param \phpbbgallery\core\album\loader                           $loader       Albums display object
81
	 * @param \phpbbgallery\core\auth\auth                              $auth         Gallery auth object
82
	 * @param \phpbbgallery\core\auth\level                             $auth_level   Gallery auth level object
83
	 * @param \phpbbgallery\core\config                                 $gallery_config
84
	 * @param \phpbbgallery\core\notification\helper                    $notifications_helper
85
	 * @param \phpbbgallery\core\url                                    $url
86
	 * @param \phpbbgallery\core\image\image                            $image
87
	 * @param \phpbb\request\request                                    $request
88
	 * @param string                                                    $images_table Gallery image table
89
	 */
90 3
	public function __construct(\phpbb\config\config $config, \phpbb\controller\helper $helper,
91
		\phpbb\db\driver\driver_interface $db, \phpbb\pagination $pagination,
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...
92
		\phpbb\template\template $template, \phpbb\user $user, \phpbb\language\language $language,
93
		\phpbbgallery\core\album\display $display, \phpbbgallery\core\album\loader $loader,
94
		\phpbbgallery\core\auth\auth $auth, \phpbbgallery\core\auth\level $auth_level,
95
		\phpbbgallery\core\config $gallery_config, \phpbbgallery\core\notification\helper $notifications_helper,
96
		\phpbbgallery\core\url $url, \phpbbgallery\core\image\image $image, \phpbb\request\request $request,
97
		\phpbbgallery\core\contest $contest,
98
		$images_table)
99
	{
100 3
		$this->config = $config;
101 3
		$this->helper = $helper;
102 3
		$this->db = $db;
103 3
		$this->pagination = $pagination;
104 3
		$this->template = $template;
105 3
		$this->user = $user;
106 3
		$this->language = $language;
107 3
		$this->display = $display;
108 3
		$this->loader = $loader;
109 3
		$this->auth = $auth;
110 3
		$this->auth_level = $auth_level;
111 3
		$this->notifications_helper = $notifications_helper;
112 3
		$this->url = $url;
113 3
		$this->image = $image;
114 3
		$this->gallery_config = $gallery_config;
115 3
		$this->request = $request;
116 3
		$this->contest = $contest;
117 3
		$this->table_images = $images_table;
118 3
	}
119
120
	/**
121
	 * Album Controller
122
	 *    Route: gallery/album/{album_id}
123
	 *
124
	 * @param int $album_id Root Album ID
125
	 * @param int $page
126
	 * @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...
127
	 */
128 3
	public function base($album_id, $page = 0)
129
	{
130 3
		$album_id = (int) $album_id;
131 3
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
132
133
		try
134
		{
135 3
			$this->loader->load($album_id);
136
		}
137 1
		catch (\Exception $e)
138
		{
139 1
			throw new \phpbb\exception\http_exception(404, 'ALBUM_NOT_EXIST');
0 ignored issues
show
Bug introduced by
The type phpbb\exception\http_exception 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...
140
		}
141
142 2
		$album_data = $this->loader->get($album_id);
143
144 2
		if ($album_data['album_type'] == \phpbbgallery\core\block::TYPE_CONTEST)
145
		{
146
			if ($album_data['contest_id'] && $album_data['contest_marked'] && (($album_data['contest_start'] + $album_data['contest_end']) < time()))
147
			{
148
				$contest_end_time = $album_data['contest_start'] + $album_data['contest_end'];
149
				$this->contest->end($album_id, $album_data['contest_id'], $contest_end_time);
150
151
				$album_contest_data['contest_marked'] = \phpbbgallery\core\block::NO_CONTEST;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$album_contest_data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $album_contest_data = array(); before regardless.
Loading history...
152
			}
153
		}
154 2
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
155 2
		$this->auth_level->display($album_id, $album_data['album_status'], $album_data['album_user_id']);
156
157 2
		$this->display->generate_navigation($album_data);
158 2
		$this->display->display_albums($album_data, $this->config['load_moderators']);
159
160 2
		$page_title = $album_data['album_name'];
161 2
		if ($page > 1)
162
		{
163
			$page_title .= ' - ' . $this->language->lang('PAGE_TITLE_NUMBER', $page);
164
		}
165
166 2
		if ($this->config['load_moderators'])
167
		{
168 1
			$moderators = $this->display->get_moderators($album_id);
0 ignored issues
show
Bug introduced by
$album_id of type integer is incompatible with the type boolean expected by parameter $album_id of phpbbgallery\core\album\display::get_moderators(). ( Ignorable by Annotation )

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

168
			$moderators = $this->display->get_moderators(/** @scrutinizer ignore-type */ $album_id);
Loading history...
169 1
			if (!empty($moderators[$album_id]))
170
			{
171 1
				$moderators = $moderators[$album_id];
172 1
				$l_moderator = (sizeof($moderators) == 1) ? $this->language->lang('MODERATOR') : $this->language->lang('MODERATORS');
173 1
				$this->template->assign_vars(array(
174 1
					'L_MODERATORS' => $l_moderator,
175 1
					'MODERATORS'   => implode($this->language->lang('COMMA_SEPARATOR'), $moderators),
176
				));
177
			}
178
		}
179
180 2
		if ($this->auth->acl_check('m_', $album_id, $album_data['album_user_id']))
181
		{
182 2
			$this->template->assign_var('U_MCP', $this->helper->route(
183 2
				'phpbbgallery_core_moderate_album',
184 2
				array('album_id' => (int) $album_id)
185
			));
186
		}
187
188 2
		if ((!$album_data['album_user_id'] || $album_data['album_user_id'] == $this->user->data['user_id'])
189 2
			&& ($this->user->data['user_id'] == ANONYMOUS || $this->auth->acl_check('i_upload', $album_id, $album_data['album_user_id'])))
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...
190
		{
191 2
			if (!array_key_exists('contest_start', $album_data))
192
			{
193 2
				$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
194 2
					'phpbbgallery_core_album_upload',
195 2
					array('album_id' => (int) $album_id)
196
				));
197
			}
198
			else
199
			{
200
				if ($album_data['contest_start'] + $album_data['contest_rating'] > time())
201
				{
202
					$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
203
						'phpbbgallery_core_album_upload',
204
						array('album_id' => (int) $album_id)
205
					));
206
				}
207
			}
208
		}
209
210 2
		$this->template->assign_vars(array(
211 2
			'S_IS_POSTABLE' => $album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT,
212 2
			'S_IS_LOCKED'   => $album_data['album_status'] == \phpbbgallery\core\block::ALBUM_LOCKED,
213
214 2
			'U_RETURN_LINK'  => $this->helper->route('phpbbgallery_core_index'),
215 2
			'L_RETURN_LINK'  => $this->language->lang('RETURN_TO_GALLERY'),
216 2
			'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_id)),
217 2
			'S_IS_WATCHED'   => $this->notifications_helper->get_watched_album($album_id) ? true : false,
218 2
			'U_WATCH_TOGGLE'  => $this->helper->route('phpbbgallery_core_album_watch', array('album_id' => (int) $album_id)),
219
		));
220
221 2
		if ($album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT
222 2
			&& $album_data['album_images_real'] > 0)
223
		{
224 2
			$this->display_images($album_id, $album_data, ($page - 1) * (int) $this->config['phpbb_gallery_items_per_page'], (int) $this->config['phpbb_gallery_items_per_page']);
225
		}
226
227
//		phpbb_ext_gallery_core_misc::markread('album', $album_id);
228
229 2
		return $this->helper->render('gallery/album_body.html', $page_title);
230
	}
231
232
	/**
233
	 * @param $album_id
234
	 * @param $album_data
235
	 * @param $start
236
	 * @param $limit
237
	 */
238 2
	protected function display_images($album_id, $album_data, $start, $limit)
239
	{
240 2
		$sort_days = $this->request->variable('st', 0);
241 2
		$sort_key = $this->request->variable('sk', ($album_data['album_sort_key']) ? $album_data['album_sort_key'] : $this->config['phpbb_gallery_default_sort_key']);
242 2
		$sort_dir = $this->request->variable('sd', ($album_data['album_sort_dir']) ? $album_data['album_sort_dir'] : $this->config['phpbb_gallery_default_sort_dir']);
243
244 2
		$image_status_check = ' AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED;
0 ignored issues
show
Unused Code introduced by
The assignment to $image_status_check is dead and can be removed.
Loading history...
245
246 2
		$image_counter = $album_data['album_images'];
0 ignored issues
show
Unused Code introduced by
The assignment to $image_counter is dead and can be removed.
Loading history...
247
248 2
		$user_id = $this->user->data['user_id'];
249 2
		$album_owner_id = $album_data['album_user_id'];
250
251 2
		if ($this->auth->acl_check('m_status', $album_id, $album_owner_id))
252
		{
253
			$image_status_check = '';
254
			$image_counter = $album_data['album_images_real'];
255
		}
256
		else
257
		{
258 2
			$image_status_check = " AND (image_status <> " . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . " OR image_user_id = $user_id)";
259 2
			$image_counter = $album_data['album_images_real'];
260
		}
261
262 2
		if (in_array($sort_key, array('r', 'ra')))
263
		{
264
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
265
		}
266
		else
267
		{
268 2
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
269
		}
270
271 2
		$limit_days = array();
272
		$sort_by_text = array(
273 2
			't'  => $this->language->lang('TIME'),
274 2
			'n'  => $this->language->lang('IMAGE_NAME'),
275 2
			'vc' => $this->language->lang('GALLERY_VIEWS'),
276 2
			'u'  => $this->language->lang('SORT_USERNAME'),
277
		);
278
		$sort_by_sql = array(
279 2
			't'  => 'image_time',
280
			'n'  => 'image_name_clean',
281
			'vc' => 'image_view_count',
282
			'u'  => 'image_username_clean',
283
		);
284
285 2
		if ($this->config['phpbb_gallery_allow_rates'])
286
		{
287 1
			$sort_by_text['ra'] = $this->language->lang('RATING');
288 1
			$sort_by_sql['ra'] = 'image_rate_points';
289 1
			$sort_by_text['r'] = $this->language->lang('RATES_COUNT');
290 1
			$sort_by_sql['r'] = 'image_rates';
291
		}
292 2
		if ($this->config['phpbb_gallery_allow_comments'])
293
		{
294 1
			$sort_by_text['c'] = $this->language->lang('COMMENTS');
295 1
			$sort_by_sql['c'] = 'image_comments';
296 1
			$sort_by_text['lc'] = $this->language->lang('NEW_COMMENT');
297 1
			$sort_by_sql['lc'] = 'image_last_comment';
298
		}
299 2
		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
Comprehensibility Best Practice introduced by
The variable $u_sort_param seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $s_limit_days does not exist. Did you maybe mean $limit_days?
Loading history...
Comprehensibility Best Practice introduced by
The variable $s_sort_key does not exist. Did you maybe mean $sort_key?
Loading history...
Comprehensibility Best Practice introduced by
The variable $s_sort_dir does not exist. Did you maybe mean $sort_dir?
Loading history...
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

299
		/** @scrutinizer ignore-call */ 
300
  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...
300 2
		$sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
301
302 2
		$this->template->assign_block_vars('imageblock', array(
303 2
			'BLOCK_NAME' => $album_data['album_name'],
304
		));
305
306 2
		$images = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $images is dead and can be removed.
Loading history...
307
		$sql = 'SELECT *
308 2
			FROM ' . $this->table_images . '
309 2
			WHERE image_album_id = ' . (int) $album_id . "
310 2
				$image_status_check
311 2
				AND image_status <> " . \phpbbgallery\core\block::STATUS_ORPHAN . "
312 2
			ORDER BY $sql_sort_order" . $sql_help_sort;
313 2
		$result = $this->db->sql_query_limit($sql, $limit, $start);
314
315
		// Now let's get display options
316 2
		$show_ip = $show_ratings = $show_username = $show_views = $show_time = $show_imagename = $show_comments = $show_album = false;
317 2
		$show_options = $this->gallery_config->get('album_display');
318 2
		if ($show_options >= 128)
319
		{
320 2
			$show_ip = true;
321 2
			$show_options = $show_options - 128;
322
		}
323 2
		if ($show_options >= 64)
324
		{
325 2
			$show_ratings = true;
326 2
			$show_options = $show_options - 64;
327
		}
328 2
		if (isset($album_data['contest_marked']))
329
		{
330
			if ($album_data['contest_marked'])
331
			{
332
				$show_ratings = false;
333
			}
334
		}
335 2
		if ($show_options >= 32)
336
		{
337 2
			$show_username = true;
338 2
			$show_options = $show_options - 32;
339
		}
340 2
		if ($show_options >= 16)
341
		{
342 2
			$show_views = true;
343 2
			$show_options = $show_options - 16;
344
		}
345 2
		if ($show_options >= 8)
346
		{
347 2
			$show_time = true;
348 2
			$show_options = $show_options - 8;
349
		}
350 2
		if ($show_options >= 4)
351
		{
352 2
			$show_imagename = true;
353 2
			$show_options = $show_options - 4;
354
		}
355 2
		if ($show_options >= 2)
356
		{
357 2
			$show_comments = true;
358 2
			$show_options = $show_options - 2;
359
		}
360 2
		if ($show_options == 1)
361
		{
362 1
			$show_album = true;
363
		}
364
365 2
		while ($row = $this->db->sql_fetchrow($result))
366
		{
367
			// Assign the image to the template-block
368 2
			$image_data = array_merge($album_data, $row);
369 2
			$album_status = $image_data['album_status'];
370 2
			$album_user_id = $image_data['album_user_id'];
371
372
			//@todo: $rating = new phpbb_gallery_image_rating($image_data['image_id'], $image_data, $image_data);
373 2
			$image_data['rating'] = '0';//@todo: $rating->get_image_rating(false, false);
374
			//@todo: unset($rating);
375
376 2
			$s_user_allowed = (($image_data['image_user_id'] == $this->user->data['user_id']) && ($album_status != \phpbbgallery\core\block::ALBUM_LOCKED));
377
378 2
			switch ($this->gallery_config->get('link_thumbnail'))
379
			{
380 2
				case 'image_page':
381 1
					$action = $this->helper->route('phpbbgallery_core_image', array('image_id' => $row['image_id']));
382 1
				break;
383 1
				case 'image':
384 1
					$action = $this->helper->route('phpbbgallery_core_image_file_source', array('image_id' => $row['image_id']));
385 1
				break;
386
				default:
387
					$action = false;
388
				break;
389
			}
390 2
			switch ($this->gallery_config->get('link_image_name'))
391
			{
392 2
				case 'image_page':
393 1
					$action_image = $this->helper->route('phpbbgallery_core_image', array('image_id' => $row['image_id']));
394 1
				break;
395 1
				case 'image':
396 1
					$action_image = $this->helper->route('phpbbgallery_core_image_file_source', array('image_id' => $row['image_id']));
397 1
				break;
398
				default:
399
					$action_image = false;
400
				break;
401
			}
402 2
			$s_allowed_delete = (($this->auth->acl_check('i_delete', $image_data['image_album_id'], $album_user_id) && $s_user_allowed) || $this->auth->acl_check('m_delete', $image_data['image_album_id'], $album_user_id));
403 2
			$s_allowed_edit = (($this->auth->acl_check('i_edit', $image_data['image_album_id'], $album_user_id) && $s_user_allowed) || $this->auth->acl_check('m_edit', $image_data['image_album_id'], $album_user_id));
404 2
			$s_quick_mod = ($s_allowed_delete || $s_allowed_edit || $this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) || $this->auth->acl_check('m_move', $image_data['image_album_id'], $album_user_id));
0 ignored issues
show
Unused Code introduced by
The assignment to $s_quick_mod is dead and can be removed.
Loading history...
405
406 2
			$s_username_hidden = $image_data['image_contest'] && !$this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) && ($this->user->data['user_id'] != $image_data['image_user_id'] || $image_data['image_user_id'] == 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...
407 2
			$this->template->assign_block_vars('imageblock.image', array(
408 2
				'IMAGE_ID'            => (int) $image_data['image_id'],
409 2
				'U_IMAGE'             => $action_image,
410 2
				'UC_IMAGE_NAME'       => $show_imagename ? htmlspecialchars_decode($image_data['image_name'], ENT_COMPAT) : false,
411 2
				'U_ALBUM'             => $show_album ? $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_data['album_id'])) : false,
412 2
				'ALBUM_NAME'          => $show_album ? $album_data['album_name'] : false,
413 2
				'IMAGE_VIEWS'         => $show_views ? (int) $image_data['image_view_count'] : -1,
414
				//'UC_THUMBNAIL'	=> 'self::generate_link('thumbnail', $phpbb_ext_gallery->config->get('link_thumbnail'), $image_data['image_id'], $image_data['image_name'], $image_data['image_album_id']),
415 2
				'UC_THUMBNAIL'        => $this->helper->route('phpbbgallery_core_image_file_mini', array('image_id' => $image_data['image_id'])),
416 2
				'UC_THUMBNAIL_ACTION' => $action,
417 2
				'S_UNAPPROVED'        => ($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) && ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_UNAPPROVED)) ? true : false,
418 2
				'S_LOCKED'            => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_LOCKED) ? true : false,
419 2
				'S_REPORTED'          => ($this->auth->acl_check('m_report', $image_data['image_album_id'], $album_user_id) && $image_data['image_reported']) ? true : false,
420 2
				'POSTER'              => ($show_username) ? (($s_username_hidden) ? $this->language->lang('CONTEST_USERNAME') : get_username_string('full', $image_data['image_user_id'], $image_data['image_username'], $image_data['image_user_colour'])) : false,
0 ignored issues
show
Bug introduced by
The function get_username_string was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

420
				'POSTER'              => ($show_username) ? (($s_username_hidden) ? $this->language->lang('CONTEST_USERNAME') : /** @scrutinizer ignore-call */ get_username_string('full', $image_data['image_user_id'], $image_data['image_username'], $image_data['image_user_colour'])) : false,
Loading history...
421 2
				'TIME'                => $show_time ? $this->user->format_date($image_data['image_time']) : false,
422
423 2
				'S_RATINGS'  => ($this->config['phpbb_gallery_allow_rates'] == 1 && $show_ratings) ? ($image_data['image_rates'] > 0 ? $image_data['image_rate_avg'] / 100 : $this->language->lang('NOT_RATED')) : false,
424 2
				'U_RATINGS'  => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#rating',
425 2
				'L_COMMENTS' => ($image_data['image_comments'] == 1) ? $this->language->lang('COMMENT') : $this->language->lang('COMMENTS'),
426 2
				'S_COMMENTS' => ($this->config['phpbb_gallery_allow_comments'] && $this->auth->acl_check('c_read', $image_data['image_album_id'], $album_user_id) && $show_comments) ? (($image_data['image_comments']) ? $image_data['image_comments'] : $this->language->lang('NO_COMMENTS')) : '',
427 2
				'U_COMMENTS' => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#comments',
428
429 2
				'U_USER_IP'                  => $show_ip && $this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) ? $image_data['image_user_ip'] : false,
430 2
				'S_IMAGE_REPORTED'           => $image_data['image_reported'],
431 2
				'U_IMAGE_REPORTED'           => '',//($image_data['image_reported']) ? $phpbb_ext_gallery->url->append_sid('mcp', "mode=report_details&amp;album_id={$image_data['image_album_id']}&amp;option_id=" . $image_data['image_reported']) : '',
432 2
				'S_STATUS_APPROVED'          => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_APPROVED) ? true : false,
433 2
				'S_STATUS_UNAPPROVED'        => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_UNAPPROVED) ? true : false,
434 2
				'S_STATUS_UNAPPROVED_ACTION' => ($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) && $image_data['image_status'] == \phpbbgallery\core\block::STATUS_UNAPPROVED) ? $this->helper->route('phpbbgallery_core_moderate_image_approve', array('image_id' => $image_data['image_id'])) : '',
435 2
				'S_STATUS_UNAPPROVED_PERMISSIONS' => ($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) && $image_data['image_status'] == \phpbbgallery\core\block::STATUS_UNAPPROVED) ? true : false,
436 2
				'S_STATUS_LOCKED'            => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_LOCKED) ? true : false,
437
438 2
				'U_REPORT' => ($this->auth->acl_check('m_report', $image_data['image_album_id'], $album_user_id) && $image_data['image_reported']) ? '123'/*$this->url->append_sid('mcp', "mode=report_details&amp;album_id={$image_data['image_album_id']}&amp;option_id=" . $image_data['image_reported'])*/ : '',
439 2
				'U_STATUS' => '',//($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id)) ? $phpbb_ext_gallery->url->append_sid('mcp', "mode=queue_details&amp;album_id={$image_data['image_album_id']}&amp;option_id=" . $image_data['image_id']) : '',
440 2
				'L_STATUS' => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_UNAPPROVED) ? $this->language->lang('APPROVE_IMAGE') : (($image_data['image_status'] == \phpbbgallery\core\block::STATUS_APPROVED) ? $this->language->lang('CHANGE_IMAGE_STATUS') : $this->language->lang('UNLOCK_IMAGE')),
441
442 2
				'S_CONTEST_RANK' => $image_data['image_contest_rank'],
443
			));
444
		}
445 2
		$this->db->sql_freeresult($result);
446
447 2
		$this->pagination->generate_template_pagination(array(
448
			'routes' => array(
449 2
				'phpbbgallery_core_album',
450
				'phpbbgallery_core_album_page',
451
			),
452
			'params' => array(
453 2
				'album_id' => (int) $album_id,
454 2
				'sk'       => $sort_key,
455 2
				'sd'       => $sort_dir,
456 2
				'st'       => $sort_days,
457
			),
458 2
		), 'pagination', 'page', $image_counter, $limit, $start);
459
460 2
		$this->template->assign_vars(array(
461 2
			'TOTAL_IMAGES'      => $this->language->lang('VIEW_ALBUM_IMAGES', $image_counter),
462 2
			'S_SELECT_SORT_DIR' => $s_sort_dir,
463 2
			'S_SELECT_SORT_KEY' => $s_sort_key,
464
		));
465 2
	}
466
467
	/**
468
	 * @param $album_id
469
	 * @return \Symfony\Component\HttpFoundation\Response
470
	 */
471
	public function watch($album_id)
472
	{
473
		$album_id = (int) $album_id;
474
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
475
476
		$album_data = $this->loader->get($album_id);
477
478
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
479
		if (confirm_box(true))
0 ignored issues
show
Bug introduced by
The function confirm_box 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

479
		if (/** @scrutinizer ignore-call */ confirm_box(true))
Loading history...
480
		{
481
			$back_link = $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_id));
482
			if ($this->notifications_helper->get_watched_album($album_id) == 1)
483
			{
484
				$this->notifications_helper->remove_albums($album_id);
485
				$this->template->assign_vars(array(
486
					'INFORMATION' => $this->language->lang('UNWATCH_ALBUM'),
487
				));
488
				$this->url->meta_refresh(3, $back_link);
489
				return $this->helper->render('gallery/message.html', $this->language->lang('GALLERY'));
490
			}
491
			else
492
			{
493
				$this->notifications_helper->add_albums($album_id);
494
				$this->template->assign_vars(array(
495
					'INFORMATION' => $this->language->lang('WATCH_ALBUM'),
496
				));
497
				$this->url->meta_refresh(3, $back_link);
498
				return $this->helper->render('gallery/message.html', $this->language->lang('GALLERY'));
499
			}
500
		}
501
		else
502
		{
503
			if ($this->notifications_helper->get_watched_album($album_id) == 1)
504
			{
505
				$lang = $this->language->lang('UNWATCH_ALBUM');
506
			}
507
			else
508
			{
509
				$lang = $this->language->lang('WATCH_ALBUM');
510
			}
511
			$s_hidden_fields = '';
512
			confirm_box(false, $lang, $s_hidden_fields);
513
		}
514
		//return $this->helper->render('gallery/moderate_approve.html', $this->language->lang('GALLERY'));
515
	}
516
517
	/**
518
	 * @param int $album_id
519
	 * @param     $owner_id
520
	 * @param     $album_auth_level
521
	 * @internal param array $album_data
522
	 */
523 2
	protected function check_permissions($album_id, $owner_id, $album_auth_level)
524
	{
525 2
		$this->auth->load_user_permissions($this->user->data['user_id']);
526 2
		$zebra_array = $this->auth->get_user_zebra($this->user->data['user_id']);
527 2
		if (!$this->auth->acl_check('i_view', $album_id, $owner_id) || $this->auth->get_zebra_state($zebra_array, (int) $owner_id, (int) $album_id) < (int) $album_auth_level)
528
		{
529
			if ($this->user->data['is_bot'])
530
			{
531
				// Redirect bots back to the index
532
				redirect($this->helper->route('phpbbgallery_core_index'));
0 ignored issues
show
Bug introduced by
The function redirect 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

532
				/** @scrutinizer ignore-call */ 
533
    redirect($this->helper->route('phpbbgallery_core_index'));
Loading history...
533
			}
534
535
			// Display login box for guests and an error for users
536
			if (!$this->user->data['is_registered'])
537
			{
538
				login_box();
0 ignored issues
show
Bug introduced by
The function login_box 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

538
				/** @scrutinizer ignore-call */ 
539
    login_box();
Loading history...
539
			}
540
			else
541
			{
542
				//return $this->error('NOT_AUTHORISED', 403);
543
				trigger_error($this->language->lang('NOT_AUTHORISED'));
544
			}
545
		}
546 2
	}
547
}
548