Passed
Pull Request — master (#316)
by
unknown
03:32 queued 51s
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 2
		if ((!$album_data['album_user_id'] || $album_data['album_user_id'] == $this->user->data['user_id'])
188 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...
189
		{
190 2
			if (!array_key_exists('contest_start', $album_data))
191
			{
192 2
				$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
193 2
					'phpbbgallery_core_album_upload',
194 2
					array('album_id' => (int) $album_id)
195
				));
196
			}
197
			else
198
			{
199
				if ($album_data['contest_start'] + $album_data['contest_rating'] > time())
200
				{
201
					$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
202
						'phpbbgallery_core_album_upload',
203
						array('album_id' => (int) $album_id)
204
					));
205
				}
206
			}
207
		}
208
209 2
		$this->template->assign_vars(array(
210 2
			'S_IS_POSTABLE' => $album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT,
211 2
			'S_IS_LOCKED'   => $album_data['album_status'] == \phpbbgallery\core\block::ALBUM_LOCKED,
212
213 2
			'U_RETURN_LINK'  => $this->helper->route('phpbbgallery_core_index'),
214 2
			'L_RETURN_LINK'  => $this->language->lang('RETURN_TO_GALLERY'),
215 2
			'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_id)),
216 2
			'S_IS_WATCHED'   => $this->notifications_helper->get_watched_album($album_id) ? true : false,
217 2
			'U_WATCH_TOGLE'  => $this->helper->route('phpbbgallery_core_album_watch', array('album_id' => (int) $album_id)),
218
		));
219
220 2
		if ($album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT
221 2
			&& $album_data['album_images_real'] > 0)
222
		{
223 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']);
224
		}
225
226
//		phpbb_ext_gallery_core_misc::markread('album', $album_id);
227
228 2
		return $this->helper->render('gallery/album_body.html', $page_title);
229
	}
230
231
	/**
232
	 * @param $album_id
233
	 * @param $album_data
234
	 * @param $start
235
	 * @param $limit
236
	 */
237 2
	protected function display_images($album_id, $album_data, $start, $limit)
238
	{
239 2
		$sort_days = $this->request->variable('st', 0);
240 2
		$sort_key = $this->request->variable('sk', ($album_data['album_sort_key']) ? $album_data['album_sort_key'] : $this->config['phpbb_gallery_default_sort_key']);
241 2
		$sort_dir = $this->request->variable('sd', ($album_data['album_sort_dir']) ? $album_data['album_sort_dir'] : $this->config['phpbb_gallery_default_sort_dir']);
242
243 2
		$image_status_check = ' AND image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED;
244 2
		$image_counter = $album_data['album_images'];
245
246 2
		$user_id = $this->user->data['user_id'];
247 2
		$album_owner_id = $album_data['album_user_id'];
248
249 2
		if ($this->auth->acl_check('m_status', $album_id, $album_owner_id))
250
		{
251
			$image_status_check = '';
252
			$image_counter = $album_data['album_images_real'];
253
		}
254 2
		else if ($user_id == $album_owner_id)
255
		{
256
			$image_status_check = " AND (image_status <> " . \phpbbgallery\core\block::STATUS_UNAPPROVED . " OR image_user_id = $user_id)";
257
			$image_counter = $album_data['album_images_real'];
258
		}
259
260 2
		if (in_array($sort_key, array('r', 'ra')))
261
		{
262
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
263
		}
264
		else
265
		{
266 2
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
267
		}
268
269 2
		$limit_days = array();
270
		$sort_by_text = array(
271 2
			't'  => $this->language->lang('TIME'),
272 2
			'n'  => $this->language->lang('IMAGE_NAME'),
273 2
			'vc' => $this->language->lang('GALLERY_VIEWS'),
274 2
			'u'  => $this->language->lang('SORT_USERNAME'),
275
		);
276
		$sort_by_sql = array(
277 2
			't'  => 'image_time',
278
			'n'  => 'image_name_clean',
279
			'vc' => 'image_view_count',
280
			'u'  => 'image_username_clean',
281
		);
282
283 2
		if ($this->config['phpbb_gallery_allow_rates'])
284
		{
285 1
			$sort_by_text['ra'] = $this->language->lang('RATING');
286 1
			$sort_by_sql['ra'] = 'image_rate_points';
287 1
			$sort_by_text['r'] = $this->language->lang('RATES_COUNT');
288 1
			$sort_by_sql['r'] = 'image_rates';
289
		}
290 2
		if ($this->config['phpbb_gallery_allow_comments'])
291
		{
292 1
			$sort_by_text['c'] = $this->language->lang('COMMENTS');
293 1
			$sort_by_sql['c'] = 'image_comments';
294 1
			$sort_by_text['lc'] = $this->language->lang('NEW_COMMENT');
295 1
			$sort_by_sql['lc'] = 'image_last_comment';
296
		}
297 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
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

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

418
				'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...
419 2
				'TIME'                => $show_time ? $this->user->format_date($image_data['image_time']) : false,
420
421 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,
422 2
				'U_RATINGS'  => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#rating',
423 2
				'L_COMMENTS' => ($image_data['image_comments'] == 1) ? $this->language->lang('COMMENT') : $this->language->lang('COMMENTS'),
424 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')) : '',
425 2
				'U_COMMENTS' => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#comments',
426
427 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,
428 2
				'S_IMAGE_REPORTED'           => $image_data['image_reported'],
429 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']) : '',
430 2
				'S_STATUS_APPROVED'          => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_APPROVED),
431 2
				'S_STATUS_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,
432 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'])) : '',
433 2
				'S_STATUS_LOCKED'            => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_LOCKED),
434
435 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'])*/ : '',
436 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']) : '',
437 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')),
438
439 2
				'S_CONTEST_RANK' => $image_data['image_contest_rank'],
440
			));
441
		}
442 2
		$this->db->sql_freeresult($result);
443
444 2
		$this->pagination->generate_template_pagination(array(
445
			'routes' => array(
446 2
				'phpbbgallery_core_album',
447
				'phpbbgallery_core_album_page',
448
			),
449
			'params' => array(
450 2
				'album_id' => (int) $album_id,
451 2
				'sk'       => $sort_key,
452 2
				'sd'       => $sort_dir,
453 2
				'st'       => $sort_days,
454
			),
455 2
		), 'pagination', 'page', $image_counter, $limit, $start);
456
457 2
		$this->template->assign_vars(array(
458 2
			'TOTAL_IMAGES'      => $this->language->lang('VIEW_ALBUM_IMAGES', $image_counter),
459 2
			'S_SELECT_SORT_DIR' => $s_sort_dir,
460 2
			'S_SELECT_SORT_KEY' => $s_sort_key,
461
		));
462 2
	}
463
464
	/**
465
	 * @param $album_id
466
	 * @return \Symfony\Component\HttpFoundation\Response
467
	 */
468
	public function watch($album_id)
469
	{
470
		$album_id = (int) $album_id;
471
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
472
473
		$album_data = $this->loader->get($album_id);
474
475
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
476
		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

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

529
				/** @scrutinizer ignore-call */ 
530
    redirect($this->helper->route('phpbbgallery_core_index'));
Loading history...
530
			}
531
532
			// Display login box for guests and an error for users
533
			if (!$this->user->data['is_registered'])
534
			{
535
				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

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