Passed
Push — master ( 51345c...1b3f41 )
by Stanislav
12:38 queued 10:10
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 string */
49
	protected $table_images;
50
51
	/**
52
	 * Constructor
53
	 *
54
	 * @param \phpbb\config\config                                      $config       Config object
55
	 * @param \phpbb\controller\helper                                  $helper       Controller helper object
56
	 * @param \phpbb\db\driver\driver|\phpbb\db\driver\driver_interface $db           Database object
57
	 * @param \phpbb\pagination                                         $pagination   Pagination object
58
	 * @param \phpbb\template\template                                  $template     Template object
59
	 * @param \phpbb\user                                               $user         User object
60
	 * @param \phpbb\language\language                                  $language
61
	 * @param \phpbbgallery\core\album\display                          $display      Albums display object
62
	 * @param \phpbbgallery\core\album\loader                           $loader       Albums display object
63
	 * @param \phpbbgallery\core\auth\auth                              $auth         Gallery auth object
64
	 * @param \phpbbgallery\core\auth\level                             $auth_level   Gallery auth level object
65
	 * @param \phpbbgallery\core\config                                 $gallery_config
66
	 * @param \phpbbgallery\core\notification\helper                    $notifications_helper
67
	 * @param \phpbbgallery\core\url                                    $url
68
	 * @param \phpbbgallery\core\image\image                            $image
69
	 * @param \phpbb\request\request                                    $request
70
	 * @param string                                                    $images_table Gallery image table
71
	 */
72 3
	public function __construct(\phpbb\config\config $config, \phpbb\controller\helper $helper,
73
		\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...
74
		\phpbb\template\template $template, \phpbb\user $user, \phpbb\language\language $language,
75
		\phpbbgallery\core\album\display $display, \phpbbgallery\core\album\loader $loader,
76
		\phpbbgallery\core\auth\auth $auth, \phpbbgallery\core\auth\level $auth_level,
77
		\phpbbgallery\core\config $gallery_config, \phpbbgallery\core\notification\helper $notifications_helper,
78
		\phpbbgallery\core\url $url, \phpbbgallery\core\image\image $image, \phpbb\request\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...
79
		\phpbbgallery\core\contest $contest,
80
		$images_table)
81
	{
82 3
		$this->config = $config;
83 3
		$this->helper = $helper;
84 3
		$this->db = $db;
85 3
		$this->pagination = $pagination;
86 3
		$this->template = $template;
87 3
		$this->user = $user;
88 3
		$this->language = $language;
89 3
		$this->display = $display;
90 3
		$this->loader = $loader;
91 3
		$this->auth = $auth;
92 3
		$this->auth_level = $auth_level;
93 3
		$this->notifications_helper = $notifications_helper;
0 ignored issues
show
Bug Best Practice introduced by
The property notifications_helper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
94 3
		$this->url = $url;
0 ignored issues
show
Bug Best Practice introduced by
The property url does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
95 3
		$this->image = $image;
0 ignored issues
show
Bug Best Practice introduced by
The property image does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
96 3
		$this->gallery_config = $gallery_config;
0 ignored issues
show
Bug Best Practice introduced by
The property gallery_config does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
97 3
		$this->request = $request;
0 ignored issues
show
Bug Best Practice introduced by
The property request does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
98 3
		$this->contest = $contest;
0 ignored issues
show
Bug Best Practice introduced by
The property contest does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
99 3
		$this->table_images = $images_table;
100 3
	}
101
102
	/**
103
	 * Album Controller
104
	 *    Route: gallery/album/{album_id}
105
	 *
106
	 * @param int $album_id Root Album ID
107
	 * @param int $page
108
	 * @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...
109
	 */
110 3
	public function base($album_id, $page = 0)
111
	{
112 3
		$album_id = (int) $album_id;
113 3
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
114
115
		try
116
		{
117 3
			$this->loader->load($album_id);
118
		}
119 1
		catch (\Exception $e)
120
		{
121 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...
122
		}
123
124 2
		$album_data = $this->loader->get($album_id);
125
126 2
		if ($album_data['album_type'] == \phpbbgallery\core\block::TYPE_CONTEST)
127
		{
128
			if ($album_data['contest_id'] && $album_data['contest_marked'] && (($album_data['contest_start'] + $album_data['contest_end']) < time()))
129
			{
130
				$contest_end_time = $album_data['contest_start'] + $album_data['contest_end'];
131
				$this->contest->end($album_id, $album_data['contest_id'], $contest_end_time);
132
133
				$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...
134
			}
135
		}
136 2
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
137 2
		$this->auth_level->display($album_id, $album_data['album_status'], $album_data['album_user_id']);
138
139 2
		$this->display->generate_navigation($album_data);
140 2
		$this->display->display_albums($album_data, $this->config['load_moderators']);
141
142 2
		$page_title = $album_data['album_name'];
143 2
		if ($page > 1)
144
		{
145
			$page_title .= ' - ' . $this->language->lang('PAGE_TITLE_NUMBER', $page);
146
		}
147
148 2
		if ($this->config['load_moderators'])
149
		{
150 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

150
			$moderators = $this->display->get_moderators(/** @scrutinizer ignore-type */ $album_id);
Loading history...
151 1
			if (!empty($moderators[$album_id]))
152
			{
153 1
				$moderators = $moderators[$album_id];
154 1
				$l_moderator = (sizeof($moderators) == 1) ? $this->language->lang('MODERATOR') : $this->language->lang('MODERATORS');
155 1
				$this->template->assign_vars(array(
156 1
					'L_MODERATORS' => $l_moderator,
157 1
					'MODERATORS'   => implode($this->language->lang('COMMA_SEPARATOR'), $moderators),
158
				));
159
			}
160
		}
161
162 2
		if ($this->auth->acl_check('m_', $album_id, $album_data['album_user_id']))
163
		{
164 2
			$this->template->assign_var('U_MCP', $this->helper->route(
165 2
				'phpbbgallery_core_moderate_album',
166 2
				array('album_id' => (int) $album_id)
167
			));
168
		}
169 2
		if ((!$album_data['album_user_id'] || $album_data['album_user_id'] == $this->user->data['user_id'])
170 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...
171
		{
172 2
			if (!array_key_exists('contest_start', $album_data))
173
			{
174 2
				$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
175 2
					'phpbbgallery_core_album_upload',
176 2
					array('album_id' => (int) $album_id)
177
				));
178
			}
179
			else
180
			{
181
				if ($album_data['contest_start'] + $album_data['contest_rating'] > time())
182
				{
183
					$this->template->assign_var('U_UPLOAD_IMAGE', $this->helper->route(
184
						'phpbbgallery_core_album_upload',
185
						array('album_id' => (int) $album_id)
186
					));
187
				}
188
			}
189
		}
190
191 2
		$this->template->assign_vars(array(
192 2
			'S_IS_POSTABLE' => $album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT,
193 2
			'S_IS_LOCKED'   => $album_data['album_status'] == \phpbbgallery\core\block::ALBUM_LOCKED,
194
195 2
			'U_RETURN_LINK'  => $this->helper->route('phpbbgallery_core_index'),
196 2
			'L_RETURN_LINK'  => $this->language->lang('RETURN_TO_GALLERY'),
197 2
			'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_core_album', array('album_id' => (int) $album_id)),
198 2
			'S_IS_WATCHED'   => $this->notifications_helper->get_watched_album($album_id) ? true : false,
199 2
			'U_WATCH_TOGLE'  => $this->helper->route('phpbbgallery_core_album_watch', array('album_id' => (int) $album_id)),
200
		));
201
202 2
		if ($album_data['album_type'] != \phpbbgallery\core\block::TYPE_CAT
203 2
			&& $album_data['album_images_real'] > 0)
204
		{
205 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']);
206
		}
207
208
//		phpbb_ext_gallery_core_misc::markread('album', $album_id);
209
210 2
		return $this->helper->render('gallery/album_body.html', $page_title);
211
	}
212
213
	/**
214
	 * @param $album_id
215
	 * @param $album_data
216
	 * @param $start
217
	 * @param $limit
218
	 */
219 2
	protected function display_images($album_id, $album_data, $start, $limit)
220
	{
221 2
		$sort_days = $this->request->variable('st', 0);
222 2
		$sort_key = $this->request->variable('sk', ($album_data['album_sort_key']) ? $album_data['album_sort_key'] : $this->config['phpbb_gallery_default_sort_key']);
223 2
		$sort_dir = $this->request->variable('sd', ($album_data['album_sort_dir']) ? $album_data['album_sort_dir'] : $this->config['phpbb_gallery_default_sort_dir']);
224
225 2
		$image_status_check = ' AND image_status <> ' . \phpbbgallery\core\block::STATUS_UNAPPROVED;
226 2
		$image_counter = $album_data['album_images'];
227 2
		if ($this->auth->acl_check('m_status', $album_id, $album_data['album_user_id']))
228
		{
229
			$image_status_check = '';
230
			$image_counter = $album_data['album_images_real'];
231
		}
232
233 2
		if (in_array($sort_key, array('r', 'ra')))
234
		{
235
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
236
		}
237
		else
238
		{
239 2
			$sql_help_sort = ', image_id ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
240
		}
241
242 2
		$limit_days = array();
243
		$sort_by_text = array(
244 2
			't'  => $this->language->lang('TIME'),
245 2
			'n'  => $this->language->lang('IMAGE_NAME'),
246 2
			'vc' => $this->language->lang('GALLERY_VIEWS'),
247 2
			'u'  => $this->language->lang('SORT_USERNAME'),
248
		);
249
		$sort_by_sql = array(
250 2
			't'  => 'image_time',
251
			'n'  => 'image_name_clean',
252
			'vc' => 'image_view_count',
253
			'u'  => 'image_username_clean',
254
		);
255
256 2
		if ($this->config['phpbb_gallery_allow_rates'])
257
		{
258 1
			$sort_by_text['ra'] = $this->language->lang('RATING');
259 1
			$sort_by_sql['ra'] = 'image_rate_points';
260 1
			$sort_by_text['r'] = $this->language->lang('RATES_COUNT');
261 1
			$sort_by_sql['r'] = 'image_rates';
262
		}
263 2
		if ($this->config['phpbb_gallery_allow_comments'])
264
		{
265 1
			$sort_by_text['c'] = $this->language->lang('COMMENTS');
266 1
			$sort_by_sql['c'] = 'image_comments';
267 1
			$sort_by_text['lc'] = $this->language->lang('NEW_COMMENT');
268 1
			$sort_by_sql['lc'] = 'image_last_comment';
269
		}
270 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 $s_sort_key does not exist. Did you maybe mean $sort_key?
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

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

391
				'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...
392 2
				'TIME'                => $show_time ? $this->user->format_date($image_data['image_time']) : false,
393
394 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,
395 2
				'U_RATINGS'  => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#rating',
396 2
				'L_COMMENTS' => ($image_data['image_comments'] == 1) ? $this->language->lang('COMMENT') : $this->language->lang('COMMENTS'),
397 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')) : '',
398 2
				'U_COMMENTS' => $this->helper->route('phpbbgallery_core_image', array('image_id' => $image_data['image_id'])) . '#comments',
399
400 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,
401 2
				'S_IMAGE_REPORTED'           => $image_data['image_reported'],
402 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']) : '',
403 2
				'S_STATUS_APPROVED'          => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_APPROVED),
404 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,
405 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'])) : '',
406 2
				'S_STATUS_LOCKED'            => ($image_data['image_status'] == \phpbbgallery\core\block::STATUS_LOCKED),
407
408 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'])*/ : '',
409 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']) : '',
410 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')),
411
412 2
				'S_CONTEST_RANK' => $image_data['image_contest_rank'],
413
			));
414
		}
415 2
		$this->db->sql_freeresult($result);
416
417 2
		$this->pagination->generate_template_pagination(array(
418
			'routes' => array(
419 2
				'phpbbgallery_core_album',
420
				'phpbbgallery_core_album_page',
421
			),
422
			'params' => array(
423 2
				'album_id' => (int) $album_id,
424 2
				'sk'       => $sort_key,
425 2
				'sd'       => $sort_dir,
426 2
				'st'       => $sort_days,
427
			),
428 2
		), 'pagination', 'page', $image_counter, $limit, $start);
429
430 2
		$this->template->assign_vars(array(
431 2
			'TOTAL_IMAGES'      => $this->language->lang('VIEW_ALBUM_IMAGES', $image_counter),
432 2
			'S_SELECT_SORT_DIR' => $s_sort_dir,
433 2
			'S_SELECT_SORT_KEY' => $s_sort_key,
434
		));
435 2
	}
436
437
	/**
438
	 * @param $album_id
439
	 * @return \Symfony\Component\HttpFoundation\Response
440
	 */
441
	public function watch($album_id)
442
	{
443
		$album_id = (int) $album_id;
444
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
445
446
		$album_data = $this->loader->get($album_id);
447
448
		$this->check_permissions($album_id, $album_data['album_user_id'], $album_data['album_auth_access']);
449
		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

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

502
				/** @scrutinizer ignore-call */ 
503
    redirect($this->helper->route('phpbbgallery_core_index'));
Loading history...
503
			}
504
505
			// Display login box for guests and an error for users
506
			if (!$this->user->data['is_registered'])
507
			{
508
				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

508
				/** @scrutinizer ignore-call */ 
509
    login_box();
Loading history...
509
			}
510
			else
511
			{
512
				//return $this->error('NOT_AUTHORISED', 403);
513
				trigger_error($this->language->lang('NOT_AUTHORISED'));
514
			}
515
		}
516 2
	}
517
}
518