Passed
Push — master ( d062e1...de1c6e )
by Stanislav
13:42 queued 10:45
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
	const ALBUM_SHOW_IP = 128;
70
	const ALBUM_SHOW_RATINGS = 64;
71
	const ALBUM_SHOW_USERNAME = 32;
72
	const ALBUM_SHOW_VIEWS = 16;
73
	const ALBUM_SHOW_TIME = 8;
74
	const ALBUM_SHOW_IMAGENAME = 4;
75
	const ALBUM_SHOW_COMMENTS = 2;
76
	const ALBUM_SHOW_ALBUM = 1;
77
78
	/**
79
	 * Constructor
80
	 *
81
	 * @param \phpbb\config\config                                      $config       Config object
82
	 * @param \phpbb\controller\helper                                  $helper       Controller helper object
83
	 * @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db           Database object
84
	 * @param \phpbb\pagination                                         $pagination   Pagination object
85
	 * @param \phpbb\template\template                                  $template     Template object
86
	 * @param \phpbb\user                                               $user         User object
87
	 * @param \phpbb\language\language                                  $language
88
	 * @param \phpbbgallery\core\album\display                          $display      Albums display object
89
	 * @param \phpbbgallery\core\album\loader                           $loader       Albums display object
90
	 * @param \phpbbgallery\core\auth\auth                              $auth         Gallery auth object
91
	 * @param \phpbbgallery\core\auth\level                             $auth_level   Gallery auth level object
92
	 * @param \phpbbgallery\core\config                                 $gallery_config
93
	 * @param \phpbbgallery\core\notification\helper                    $notifications_helper
94
	 * @param \phpbbgallery\core\url                                    $url
95
	 * @param \phpbbgallery\core\image\image                            $image
96
	 * @param \phpbb\request\request                                    $request
97
	 * @param string                                                    $images_table Gallery image table
98
	 */
99 3
	public function __construct(\phpbb\config\config $config, \phpbb\controller\helper $helper,
100
		\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...
101
		\phpbb\template\template $template, \phpbb\user $user, \phpbb\language\language $language,
102
		\phpbbgallery\core\album\display $display, \phpbbgallery\core\album\loader $loader,
103
		\phpbbgallery\core\auth\auth $auth, \phpbbgallery\core\auth\level $auth_level,
104
		\phpbbgallery\core\config $gallery_config, \phpbbgallery\core\notification\helper $notifications_helper,
105
		\phpbbgallery\core\url $url, \phpbbgallery\core\image\image $image, \phpbb\request\request $request,
106
		\phpbbgallery\core\contest $contest,
107
		$images_table)
108
	{
109 3
		$this->config = $config;
110 3
		$this->helper = $helper;
111 3
		$this->db = $db;
112 3
		$this->pagination = $pagination;
113 3
		$this->template = $template;
114 3
		$this->user = $user;
115 3
		$this->language = $language;
116 3
		$this->display = $display;
117 3
		$this->loader = $loader;
118 3
		$this->auth = $auth;
119 3
		$this->auth_level = $auth_level;
120 3
		$this->notifications_helper = $notifications_helper;
121 3
		$this->url = $url;
122 3
		$this->image = $image;
123 3
		$this->gallery_config = $gallery_config;
124 3
		$this->request = $request;
125 3
		$this->contest = $contest;
126 3
		$this->table_images = $images_table;
127 3
	}
128
129
	/**
130
	 * Album Controller
131
	 *    Route: gallery/album/{album_id}
132
	 *
133
	 * @param int $album_id Root Album ID
134
	 * @param int $page
135
	 * @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...
136
	 */
137 3
	public function base($album_id, $page = 0)
138
	{
139 3
		$album_id = (int) $album_id;
140 3
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
141
142
		try
143
		{
144 3
			$this->loader->load($album_id);
145
		}
146 1
		catch (\Exception $e)
147
		{
148 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...
149
		}
150
151 2
		$album_data = $this->loader->get($album_id);
152
153 2
		if ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST)
154
		{
155
			if ($album_data['contest_id'] && $album_data['contest_marked'] && (($album_data['contest_start'] + $album_data['contest_end']) < time()))
156
			{
157
				$contest_end_time = $album_data['contest_start'] + $album_data['contest_end'];
158
				$this->contest->end($album_id, $album_data['contest_id'], $contest_end_time);
159
160
				$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...
161
			}
162
		}
163 2
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
164 2
		$this->auth_level->display($album_id, $album_data['album_status'], $album_data['album_user_id']);
165
166 2
		$this->display->generate_navigation($album_data);
167 2
		$this->display->display_albums($album_data, $this->config['load_moderators']);
168
169 2
		$page_title = $album_data['album_name'];
170 2
		if ($page > 1)
171
		{
172
			$page_title .= ' - ' . $this->language->lang('PAGE_TITLE_NUMBER', $page);
173
		}
174
175 2
		if ($this->config['load_moderators'])
176
		{
177 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

177
			$moderators = $this->display->get_moderators(/** @scrutinizer ignore-type */ $album_id);
Loading history...
178 1
			if (!empty($moderators[$album_id]))
179
			{
180 1
				$moderators = $moderators[$album_id];
181 1
				$l_moderator = (sizeof($moderators) == 1) ? $this->language->lang('MODERATOR') : $this->language->lang('MODERATORS');
182 1
				$this->template->assign_vars(array(
183 1
					'L_MODERATORS' => $l_moderator,
184 1
					'MODERATORS'   => implode($this->language->lang('COMMA_SEPARATOR'), $moderators),
185
				));
186
			}
187
		}
188
189 2
		if ($this->auth->acl_check('m_', $album_id, $album_data['album_user_id']))
190
		{
191 2
			$this->template->assign_var('U_MCP', $this->helper->route(
192 2
				'phpbbgallery_core_moderate_album',
193 2
				array('album_id' => (int) $album_id)
194
			));
195
		}
196
197 2
		if ((!$album_data['album_user_id'] || $album_data['album_user_id'] == $this->user->data['user_id'])
198 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...
199
		{
200 2
			if (!array_key_exists('contest_start', $album_data))
201
			{
202 2
				$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
203 2
					'phpbbgallery_core_album_upload',
204 2
					array('album_id' => (int) $album_id)
205
				));
206
			}
207
			else
208
			{
209
				if ($album_data['contest_start'] + $album_data['contest_rating'] > time())
210
				{
211
					$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
212
						'phpbbgallery_core_album_upload',
213
						array('album_id' => (int) $album_id)
214
					));
215
				}
216
			}
217
		}
218
219 2
		$this->template->assign_vars(array(
220 2
			'S_IS_POSTABLE' => $album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT,
221 2
			'S_IS_LOCKED'   => $album_data['album_status'] == (int) \phpbbgallery\core\block::ALBUM_LOCKED,
222
223 2
			'U_RETURN_LINK'  => $this->helper->route('phpbbgallery_core_index'),
224 2
			'L_RETURN_LINK'  => $this->language->lang('RETURN_TO_GALLERY'),
225 2
			'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_id)),
226 2
			'S_IS_WATCHED'   => $this->notifications_helper->get_watched_album($album_id) ? true : false,
227 2
			'U_WATCH_TOGGLE'  => $this->helper->route('phpbbgallery_core_album_watch', array('album_id' => (int) $album_id)),
228
		));
229
230 2
		if ($album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT
231 2
			&& $album_data['album_images_real'] > 0)
232
		{
233 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']);
234
		}
235
236
//		phpbb_ext_gallery_core_misc::markread('album', $album_id);
237
238 2
		return $this->helper->render('gallery/album_body.html', $page_title);
239
	}
240
241
	/**
242
	 * @param $album_id
243
	 * @param $album_data
244
	 * @param $start
245
	 * @param $limit
246
	 */
247 2
	protected function display_images($album_id, $album_data, $start, $limit)
248
	{
249 2
		$sort_days = $this->request->variable('st', 0);
250 2
		$sort_key = $this->request->variable('sk', ($album_data['album_sort_key']) ? $album_data['album_sort_key'] : $this->config['phpbb_gallery_default_sort_key']);
251 2
		$sort_dir = $this->request->variable('sd', ($album_data['album_sort_dir']) ? $album_data['album_sort_dir'] : $this->config['phpbb_gallery_default_sort_dir']);
252
253 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...
254
255 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...
256
257 2
		$user_id = $this->user->data['user_id'];
258 2
		$album_owner_id = $album_data['album_user_id'];
259
260 2
		if ($this->auth->acl_check('m_status', $album_id, $album_owner_id))
261
		{
262
			$image_status_check = '';
263
			$image_counter = $album_data['album_images_real'];
264
		}
265
		else
266
		{
267 2
			$image_status_check = " AND (image_status <> " . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . " OR image_user_id = $user_id)";
268
269
			$sql = 'SELECT COUNT(*) AS total_images
270 2
				FROM ' . $this->table_images . '
271 2
				WHERE image_album_id = ' . (int) $album_id . "
272 2
					AND (image_status <> " . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . " OR image_user_id = $user_id)
273 2
					AND image_status <> " . (int) \phpbbgallery\core\block::STATUS_ORPHAN;
274 2
			$result = $this->db->sql_query($sql);
275 2
			$image_counter = (int) $this->db->sql_fetchfield('total_images');
276 2
			$this->db->sql_freeresult($result);
277
		}
278
279 2
		if (in_array($sort_key, array('r', 'ra')))
280
		{
281
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
282
		}
283
		else
284
		{
285 2
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
286
		}
287
288 2
		$limit_days = array();
289
		$sort_by_text = array(
290 2
			't'  => $this->language->lang('TIME'),
291 2
			'n'  => $this->language->lang('IMAGE_NAME'),
292 2
			'vc' => $this->language->lang('GALLERY_VIEWS'),
293 2
			'u'  => $this->language->lang('SORT_USERNAME'),
294
		);
295
		$sort_by_sql = array(
296 2
			't'  => 'image_time',
297
			'n'  => 'image_name_clean',
298
			'vc' => 'image_view_count',
299
			'u'  => 'image_username_clean',
300
		);
301
302 2
		if ($this->config['phpbb_gallery_allow_rates'])
303
		{
304 1
			$sort_by_text['ra'] = $this->language->lang('RATING');
305 1
			$sort_by_sql['ra'] = 'image_rate_points';
306 1
			$sort_by_text['r'] = $this->language->lang('RATES_COUNT');
307 1
			$sort_by_sql['r'] = 'image_rates';
308
		}
309 2
		if ($this->config['phpbb_gallery_allow_comments'])
310
		{
311 1
			$sort_by_text['c'] = $this->language->lang('COMMENTS');
312 1
			$sort_by_sql['c'] = 'image_comments';
313 1
			$sort_by_text['lc'] = $this->language->lang('NEW_COMMENT');
314 1
			$sort_by_sql['lc'] = 'image_last_comment';
315
		}
316 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

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

404
				'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...
405 2
				'TIME'                => $show_time ? $this->user->format_date($image_data['image_time']) : false,
406
407 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,
408 2
				'U_RATINGS'  => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#rating',
409 2
				'L_COMMENTS' => ($image_data['image_comments'] == 1) ? $this->language->lang('COMMENT') : $this->language->lang('COMMENTS'),
410 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')) : '',
411 2
				'U_COMMENTS' => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#comments',
412
413 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,
414 2
				'S_IMAGE_REPORTED'           => $image_data['image_reported'],
415 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']) : '',
416 2
				'S_STATUS_APPROVED'          => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_APPROVED) ? true : false,
417 2
				'S_STATUS_UNAPPROVED'        => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? true : false,
418 2
				'S_STATUS_UNAPPROVED_ACTION' => ($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) && $image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? $this->helper->route('phpbbgallery_core_moderate_image_approve', array('image_id' => $image_data['image_id'])) : '',
419 2
				'S_STATUS_UNAPPROVED_PERMISSIONS' => ($this->auth->acl_check('m_status', $image_data['image_album_id'], $album_user_id) && $image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? true : false,
420 2
				'S_STATUS_LOCKED'            => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_LOCKED) ? true : false,
421
422 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'])*/ : '',
423 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']) : '',
424 2
				'L_STATUS' => ($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_UNAPPROVED) ? $this->language->lang('APPROVE_IMAGE') : (($image_data['image_status'] == (int) \phpbbgallery\core\block::STATUS_APPROVED) ? $this->language->lang('CHANGE_IMAGE_STATUS') : $this->language->lang('UNLOCK_IMAGE')),
425
426 2
				'S_CONTEST_RANK' => $image_data['image_contest_rank'],
427
			));
428
		}
429 2
		$this->db->sql_freeresult($result);
430
431 2
		$this->pagination->generate_template_pagination(array(
432
			'routes' => array(
433 2
				'phpbbgallery_core_album',
434
				'phpbbgallery_core_album_page',
435
			),
436
			'params' => array(
437 2
				'album_id' => (int) $album_id,
438 2
				'sk'       => $sort_key,
439 2
				'sd'       => $sort_dir,
440 2
				'st'       => $sort_days,
441
			),
442 2
		), 'pagination', 'page', $image_counter, $limit, $start);
443
444 2
		$this->template->assign_vars(array(
445 2
			'TOTAL_IMAGES'      => $this->language->lang('VIEW_ALBUM_IMAGES', $image_counter),
446 2
			'S_SELECT_SORT_DIR' => $s_sort_dir,
447 2
			'S_SELECT_SORT_KEY' => $s_sort_key,
448
		));
449 2
	}
450
451
	/**
452
	 * @param $album_id
453
	 * @return \Symfony\Component\HttpFoundation\Response
454
	 */
455
	public function watch($album_id)
456
	{
457
		$album_id = (int) $album_id;
458
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
459
460
		$album_data = $this->loader->get($album_id);
461
462
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
463
		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

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

516
				/** @scrutinizer ignore-call */ 
517
    redirect($this->helper->route('phpbbgallery_core_index'));
Loading history...
517
			}
518
519
			// Display login box for guests and an error for users
520
			if (!$this->user->data['is_registered'])
521
			{
522
				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

522
				/** @scrutinizer ignore-call */ 
523
    login_box();
Loading history...
523
			}
524
			else
525
			{
526
				//return $this->error('NOT_AUTHORISED', 403);
527
				trigger_error($this->language->lang('NOT_AUTHORISED'));
528
			}
529
		}
530 2
	}
531
}
532