upload   F
last analyzed

Complexity

Total Complexity 74

Size/Duplication

Total Lines 587
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 74
eloc 293
c 0
b 0
f 0
dl 0
loc 587
ccs 0
cts 402
cp 0
rs 2.48

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 32 1
B check_fs() 0 15 9
F main() 0 438 64

How to fix   Complexity   

Complex Class

Complex classes like upload often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use upload, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * phpBB Gallery - Core Extension
4
 *
5
 * @package   phpbbgallery/core
6
 * @author    nickvergessen
7
 * @author    satanasov
8
 * @author    Leinad4Mind
9
 * @copyright 2014 nickvergessen, 2014- satanasov, 2018- Leinad4Mind
10
 * @license   GPL-2.0-only
11
 */
12
13
namespace phpbbgallery\core\controller;
14
15
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface 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
17
class upload
18
{
19
	/** @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...
20
	protected $request;
21
22
	/** @var \phpbb\db\driver\driver_interface  */
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...
23
	protected $db;
24
25
	/* @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...
26
	protected $user;
27
28
	/** @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...
29
	protected $language;
30
31
	/** @var \phpbb\template\template  */
0 ignored issues
show
Bug introduced by
The type phpbb\template\template was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
	protected $template;
33
34
	/** @var \phpbb\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...
35
	protected $config;
36
37
	/** @var ContainerInterface  */
38
	protected $phpbb_container;
39
40
	/* @var \phpbbgallery\core\misc */
41
	protected $misc;
42
43
	/** @var \phpbbgallery\core\auth\auth  */
44
	protected $auth;
45
46
	/* @var \phpbbgallery\core\album\album */
47
	protected $album;
48
49
	/* @var \phpbbgallery\core\album\album */
50
	protected $display;
51
52
	/** @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...
53
	protected $helper;
54
55
	/** @var \phpbbgallery\core\config  */
56
	protected $gallery_config;
57
58
	/** @var \phpbbgallery\core\user  */
59
	protected $gallery_user;
60
61
	/** @var \phpbbgallery\core\image\image  */
62
	protected $image;
63
64
	/** @var \phpbbgallery\core\url  */
65
	protected $url;
66
67
	/** @var \phpbbgallery\core\upload  */
68
	protected $gallery_upload;
69
70
	/** @var \phpbbgallery\core\notification  */
71
	protected $gallery_notification;
72
73
	/** @var \phpbbgallery\core\notification\helper  */
74
	protected $notification_helper;
75
76
	/** @var \phpbbgallery\core\block  */
77
	protected $block;
78
79
	/** @var \phpbbgallery\core\contest */
80
	protected $contest;
81
82
	/** @var   */
83
	protected $images_table;
84
85
	/** @var   */
86
	protected $phpbb_root_path;
87
88
	/**
89
	 * Constructor
90
	 *
91
	 * @param \phpbb\request\request                 $request
92
	 * @param \phpbb\db\driver\driver_interface      $db
93
	 * @param \phpbb\user                            $user    User object
94
	 * @param \phpbb\language\language               $language
95
	 * @param \phpbb\template\template               $template
96
	 * @param \phpbb\config\config                   $config
97
	 * @param Container|ContainerInterface           $phpbb_container
0 ignored issues
show
Bug introduced by
The type phpbbgallery\core\controller\Container 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...
98
	 * @param \phpbbgallery\core\album\album         $album   Album class
99
	 * @param \phpbbgallery\core\misc                $misc    Misc class
100
	 * @param \phpbbgallery\core\auth\auth           $auth
101
	 * @param \phpbbgallery\core\album\display       $display Display class
102
	 * @param \phpbb\controller\helper               $helper
103
	 * @param \phpbbgallery\core\config              $gallery_config
104
	 * @param \phpbbgallery\core\user                $gallery_user
105
	 * @param \phpbbgallery\core\image\image         $image
106
	 * @param \phpbbgallery\core\notification        $gallery_notification
107
	 * @param \phpbbgallery\core\notification\helper $notification_helper
108
	 * @param \phpbbgallery\core\url                 $url
109
	 * @param \phpbbgallery\core\upload              $gallery_upload
110
	 * @param \phpbbgallery\core\block               $block
111
	 * @param                                        $images_table
112
	 * @param                                        $phpbb_root_path
113
	 */
114
115
	public function __construct(\phpbb\request\request $request, \phpbb\db\driver\driver_interface $db, \phpbb\user $user,
116
		\phpbb\language\language $language, \phpbb\template\template $template, \phpbb\config\config $config, ContainerInterface $phpbb_container,
117
		\phpbbgallery\core\album\album $album, \phpbbgallery\core\misc $misc, \phpbbgallery\core\auth\auth $auth, \phpbbgallery\core\album\display $display,
118
		\phpbb\controller\helper $helper, \phpbbgallery\core\config $gallery_config, \phpbbgallery\core\user $gallery_user,
119
		\phpbbgallery\core\image\image $image, \phpbbgallery\core\notification $gallery_notification,
120
		\phpbbgallery\core\notification\helper $notification_helper, \phpbbgallery\core\url $url,
121
		\phpbbgallery\core\upload $gallery_upload, \phpbbgallery\core\block $block, \phpbbgallery\core\contest $contest,
122
		$images_table, $phpbb_root_path)
123
	{
124
		$this->request = $request;
125
		$this->db = $db;
126
		$this->user = $user;
127
		$this->language = $language;
128
		$this->template = $template;
129
		$this->config = $config;
130
		$this->phpbb_container = $phpbb_container;
131
		$this->album = $album;
132
		$this->misc = $misc;
133
		$this->auth = $auth;
134
		$this->display = $display;
0 ignored issues
show
Documentation Bug introduced by
It seems like $display of type phpbbgallery\core\album\display is incompatible with the declared type phpbbgallery\core\album\album of property $display.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
135
		$this->helper = $helper;
136
		$this->gallery_config = $gallery_config;
137
		$this->gallery_user = $gallery_user;
138
		$this->image = $image;
139
		$this->url = $url;
140
		$this->gallery_upload = $gallery_upload;
141
		$this->gallery_notification = $gallery_notification;
142
		$this->notification_helper = $notification_helper;
143
		$this->block = $block;
144
		$this->contest = $contest;
145
		$this->images_table = $images_table;
146
		$this->phpbb_root_path = $phpbb_root_path;
147
	}
148
149
	public function main($album_id)
150
	{
151
		$this->language->add_lang(array('gallery'), 'phpbbgallery/core');
152
		$album_data = $this->album->get_info($album_id);
153
		$this->display->generate_navigation($album_data);
0 ignored issues
show
Bug introduced by
The method generate_navigation() does not exist on phpbbgallery\core\album\album. ( Ignorable by Annotation )

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

153
		$this->display->/** @scrutinizer ignore-call */ 
154
                  generate_navigation($album_data);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
		add_form_key('gallery');
0 ignored issues
show
Bug introduced by
The function add_form_key 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

154
		/** @scrutinizer ignore-call */ 
155
  add_form_key('gallery');
Loading history...
155
		$album_backlink = $this->helper->route('phpbbgallery_core_album', array('album_id'	=> $album_id));
156
		$album_loginlink = 'ucp.php?mode=login';
157
		$error = '';
158
		//Let's get authorisation
159
		$this->auth->load_user_permissions($this->user->data['user_id']);
160
		if (!$this->auth->acl_check('i_upload', $album_id, $album_data['album_user_id']) || ($album_data['album_status'] == $this->block->get_album_status_locked()))
161
		{
162
			$this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
163
		}
164
		if ($album_data['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST)
165
		{
166
			$contest = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $contest is dead and can be removed.
Loading history...
167
			$contest = $this->contest->get_contest($album_id, 'album');
168
			if ($contest['contest_start'] + $contest['contest_rating'] <= time())
169
			{
170
				$this->misc->not_authorised($album_backlink, $album_loginlink, 'LOGIN_EXPLAIN_UPLOAD');
171
			}
172
		}
173
		$page_title = 'Upload to "' . $album_data['album_name'] . '"';
174
175
		// Before all
176
		if (!$this->check_fs())
177
		{
178
			trigger_error('NO_WRITE_ACCESS');
179
		}
180
		$submit = $this->request->variable('submit', false);
181
		$mode = $this->request->variable('mode', 'upload');
182
		// So let's see if we have AJAX and use jQuery shit.
183
		// We are going to use ajax upload only for registered users.
184
		// Anons should suffer.
185
		if ($this->request->is_ajax() && $this->user->data['is_registered'])
186
		{
187
			// So we use ajax request to upload (so we are going to copy some functions from other upload
188
			// Upload Quota Check
189
			// 1. Check album-configuration Quota
190
			if (($this->gallery_config->get('album_images') >= 0) && ($album_data['album_images'] >= $this->gallery_config->get('album_images')))
191
			{
192
				//@todo: Add return link
193
				trigger_error('ALBUM_REACHED_QUOTA');
194
			}
195
196
			// 2. Check user-limit, if he is not allowed to go unlimited
197
			if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']))
198
			{
199
				$sql = 'SELECT COUNT(image_id) count
200
					FROM ' . $this->images_table . '
201
					WHERE image_user_id = ' . (int) $this->user->data['user_id'] . '
202
						AND image_status <> ' . (int) $this->block->get_image_status_orphan() . '
203
						AND image_album_id = ' . (int) $album_id;
204
				$result = $this->db->sql_query($sql);
205
				$own_images = (int) $this->db->sql_fetchfield('count');
206
				$this->db->sql_freeresult($result);
207
				if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']))
208
				{
209
					//@todo: Add return link
210
					trigger_error($this->language->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])));
211
				}
212
			}
213
214
			$upload_files_limit = ($this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) ? $this->gallery_config->get('num_uploads') : min(($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images), $this->gallery_config->get('num_uploads'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $own_images does not seem to be defined for all execution paths leading up to this point.
Loading history...
215
			$process = $this->gallery_upload;
216
			$process->set_up($album_id, $upload_files_limit);
217
			$process->set_username($this->user->data['username']);
218
			$process->set_allow_comments(1);
219
			$process->upload_file(1);
220
			if (!empty($process->errors))
221
			{
222
				return new \Symfony\Component\HttpFoundation\JsonResponse(array(
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\JsonResponse 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...
223
					'files'	=> array(
224
						array(
225
							'error'	=> implode(',', $process->errors)
226
						)
227
					)
228
				));
229
			}
230
			$checks = $process->generate_hidden_fields();
231
			$process->get_images($checks);
232
			$image_names = array();
233
			foreach ($process->images as $ID)
234
			{
235
				$image_names[] = $process->image_data[$ID]['image_name'];
236
			}
237
			$process->set_names($image_names);
238
239
			$success = true;
240
			foreach ($process->images as $image_id)
241
			{
242
				$success = $success && $process->update_image($image_id, !$this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id']), $album_data['album_contest']);
243
				if ($this->gallery_user->get_data('watch_own'))
244
				{
245
					$this->gallery_notification->add($image_id);
246
				}
247
			}
248
249
			if ($this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id']))
250
			{
251
				//$this->notification_helper->notify_album($album_id, $this->user->data['user_id']);
252
				$data = array(
253
					'targets'	=> array($this->user->data['user_id']),
254
					'album_id'	=> $album_id,
255
					'last_image'	=> end($process->images),
256
				);
257
				$this->notification_helper->new_image($data);
258
			}
259
			else
260
			{
261
				$target = array(
262
					'album_id'	=>	$album_id,
263
					'last_image'	=> end($process->images),
264
					'uploader'		=> $this->user->data['user_id'],
265
				);
266
				$this->notification_helper->notify('approval', $target);
267
			}
268
			// ToDo - notifications!!!
269
			//$phpbb_gallery_notification->send_notification('album', $album_id, $image_names[0]);
270
			$this->image->handle_counter($process->images, true);
271
			$this->album->update_info($album_id);
272
273
			// So if all is fine let's prepare response
274
			$response = array();
275
			foreach ($process->images as $ID)
276
			{
277
				$response[] = array(
278
					'url' => $this->helper->route('phpbbgallery_core_image', array('image_id' => $ID)),
279
					'thumbnail'	=> $this->helper->route('phpbbgallery_core_image_file_mini', array('image_id' => $ID)),
280
					'name'	=> $process->image_data[$ID]['image_name'],
281
					//	'type'	=> $process->image_data[$process->images[0]]['image_name'],
282
					'size'	=> $process->image_data[$ID]['filesize_upload'],
283
					//	'delete_url'	=> '',
284
					//	'delete_type'	=> ''
285
				);
286
			}
287
			return new \Symfony\Component\HttpFoundation\JsonResponse(array(
288
				'files'	=> $response
289
			));
290
291
		}
292
		if ($mode == 'upload')
293
		{
294
			// Upload Quota Check
295
			// 1. Check album-configuration Quota
296
			if (($this->gallery_config->get('album_images') >= 0) && ($album_data['album_images'] >= $this->gallery_config->get('album_images')))
297
			{
298
				//@todo: Add return link
299
				trigger_error('ALBUM_REACHED_QUOTA');
300
			}
301
302
			// 2. Check user-limit, if he is not allowed to go unlimited
303
			if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']))
304
			{
305
				$sql = 'SELECT COUNT(image_id) count
306
					FROM ' . $this->images_table . '
307
					WHERE image_user_id = ' . (int) $this->user->data['user_id'] . '
308
						AND image_status <> ' . (int) $this->block->get_image_status_orphan() . '
309
						AND image_album_id = ' . (int) $album_id;
310
				$result = $this->db->sql_query($sql);
311
				$own_images = (int) $this->db->sql_fetchfield('count');
312
				$this->db->sql_freeresult($result);
313
				if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']))
314
				{
315
					//@todo: Add return link
316
					trigger_error($this->language->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])));
317
				}
318
			}
319
320
			if ($this->misc->display_captcha('upload'))
321
			{
322
				$captcha = $this->phpbb_container->get('captcha.factory')->get_instance($this->config['captcha_plugin']);
323
				$captcha->init(CONFIRM_POST);
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\controller\CONFIRM_POST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
324
				$s_captcha_hidden_fields = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $s_captcha_hidden_fields is dead and can be removed.
Loading history...
325
				$this->template->assign_vars(array(
326
					'S_CONFIRM_CODE'		=> true,
327
					'CAPTCHA_TEMPLATE'		=> $captcha->get_template(),
328
				));
329
330
			}
331
332
			$upload_files_limit = ($this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) ? $this->gallery_config->get('num_uploads') : min(($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images), $this->gallery_config->get('num_uploads'));
333
			$process = $this->gallery_upload;
334
			$process->set_up($album_id, $upload_files_limit);
335
			if ($submit)
336
			{
337
				if (!check_form_key('gallery'))
0 ignored issues
show
Bug introduced by
The function check_form_key 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

337
				if (!/** @scrutinizer ignore-call */ check_form_key('gallery'))
Loading history...
338
				{
339
					trigger_error('FORM_INVALID');
340
				}
341
				//$process->set_rotating($this->request->variable('rotate', array(0)));
342
				$process->set_allow_comments($this->request->variable('allow_comments', false));
343
344
				if ($this->misc->display_captcha('upload'))
345
				{
346
					$captcha_error = $captcha->validate();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $captcha does not seem to be defined for all execution paths leading up to this point.
Loading history...
347
					if ($captcha_error !== false)
348
					{
349
						$process->new_error($captcha_error);
350
					}
351
				}
352
353
				if (!$this->user->data['is_registered'])
354
				{
355
					$username = $this->request->variable('username', $this->user->data['username']);
356
					if (!function_exists('validate_username'))
357
					{
358
						$this->url->_include(array('functions_user'), 'phpbb');
359
					}
360
					if ($result = validate_username($username))
361
					{
362
						$this->language->add_lang('ucp');
363
						$error_array[] = $this->language->lang($result . '_USERNAME');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$error_array was never initialized. Although not strictly required by PHP, it is generally a good practice to add $error_array = array(); before regardless.
Loading history...
364
					}
365
					else
366
					{
367
						$process->set_username($username);
368
					}
369
				}
370
371
				if (empty($process->errors))
372
				{
373
					$files = $this->request->variable('files', array('name'=> array('' => ''), 'type' => array('' => ''), 'tmp_name' => array('' => ''), 'error' =>  array('' => ''), 'size' => array('' => '')), true, \phpbb\request\request_interface::FILES);
0 ignored issues
show
Bug introduced by
The type phpbb\request\request_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...
374
					$count = count($files['name']);
375
					if ($count <= $upload_files_limit)
376
					{
377
						$process->upload_file($count);
378
					}
379
				}
380
381
				if (!$process->uploaded_files)
382
				{
383
					$process->new_error($this->language->lang('UPLOAD_NO_FILE'));
384
				}
385
				else
386
				{
387
					$mode = 'upload_edit';
388
					// Remove submit, so we get the first screen of step 2.
389
					$submit = false;
390
				}
391
392
				$error = implode('<br />', $process->errors);
393
394
				/*if (phpbb_gallery_misc::display_captcha('upload'))
395
				{
396
					$captcha->reset();
397
				}*/
398
			}
399
400
			if ($mode == 'upload')
401
			{
402
				$this->template->assign_vars(array(
403
					'ERROR'					=> $error,
404
					'S_MAX_FILESIZE'		=> get_formatted_filesize($this->gallery_config->get('max_filesize')),
0 ignored issues
show
Bug introduced by
The function get_formatted_filesize 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
					'S_MAX_FILESIZE'		=> /** @scrutinizer ignore-call */ get_formatted_filesize($this->gallery_config->get('max_filesize')),
Loading history...
405
					'S_MAX_WIDTH'			=> $this->gallery_config->get('max_width'),
406
					'S_MAX_HEIGHT'			=> $this->gallery_config->get('max_height'),
407
					'S_ALLOWED_FILETYPES'	=> implode(', ', $process->get_allowed_types(true)),
408
					'S_ALBUM_ACTION'		=>  $this->helper->route('phpbbgallery_core_album_upload', array('album_id' => $album_id)),
409
					'S_UPLOAD'				=> true,
410
					'S_ALLOW_ROTATE'		=> ($this->gallery_config->get('allow_rotate') && function_exists('imagerotate')),
411
					'S_UPLOAD_LIMIT'		=> $upload_files_limit,
412
					'S_COMMENTS_ENABLED'	=> $this->gallery_config->get('allow_comments') && $this->gallery_config->get('comment_user_control'),
413
					'S_ALLOW_COMMENTS'		=> true,
414
					'L_ALLOW_COMMENTS'		=> $this->language->lang('ALLOW_COMMENTS_ARY', $upload_files_limit),
415
				));
416
417
				// The quick upload will work only for registered users!
418
				// So fuck you bots and anons
419
				if ($this->user->data['is_registered'])
420
				{
421
					$filetypes = array();
422
					foreach ($process->get_allowed_types(true) as $VAR)
423
					{
424
						if ($VAR == 'jpg')
425
						{
426
							$filetypes[] = 'jpe?g';
427
						}
428
						if ($VAR == 'zip')
429
						{
430
							continue;
431
						}
432
						else
433
						{
434
							$filetypes[] = $VAR;
435
						}
436
					}
437
					$this->template->assign_vars(array(
438
						'S_GALLERY_QUICK_UPLOAD'	=> true,
439
						'S_QUICK_MAX_FILESIZE'	=> $this->gallery_config->get('max_filesize'),
440
						'S_QUICK_FILE_TYPES' => '/(\.|\/)(' . implode('|', $filetypes) . ')$/i',
441
					));
442
				}
443
				/*if (phpbb_gallery_misc::display_captcha('upload'))
444
				{
445
					if (!$submit || !$captcha->is_solved())
446
					{
447
						$template->assign_vars(array(
448
							'S_CONFIRM_CODE'			=> true,
449
							'CAPTCHA_TEMPLATE'			=> $captcha->get_template(),
450
						));
451
					}
452
					$template->assign_vars(array(
453
						'S_CAPTCHA_HIDDEN_FIELDS'	=> $s_captcha_hidden_fields,
454
					));
455
				}*/
456
			}
457
		}
458
		if ($mode == 'upload_edit')
459
		{
460
			if ($submit)
461
			{
462
				// Upload Quota Check
463
				// 1. Check album-configuration Quota
464
				if (($this->gallery_config->get('album_images') >= 0) && ($album_data['album_images'] >= $this->gallery_config->get('album_images')))
465
				{
466
					//@todo: Add return link
467
					trigger_error('ALBUM_REACHED_QUOTA');
468
				}
469
470
				// 2. Check user-limit, if he is not allowed to go unlimited
471
				if (!$this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id']))
472
				{
473
					$sql = 'SELECT COUNT(image_id) count
474
						FROM ' . $this->images_table . '
475
						WHERE image_user_id = ' . (int) $this->user->data['user_id'] . '
476
							AND image_status <> ' . (int) $this->block->get_image_status_orphan() . '
477
							AND image_album_id = ' . (int) $album_id;
478
					$result = $this->db->sql_query($sql);
479
					$own_images = (int) $this->db->sql_fetchfield('count');
480
					$this->db->sql_freeresult($result);
481
					if ($own_images >= $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']))
482
					{
483
						//@todo: Add return link
484
						trigger_error($this->language->lang('USER_REACHED_QUOTA', $this->auth->acl_check('i_count', $album_id, $album_data['album_user_id'])));
485
					}
486
				}
487
				$description_array = $this->request->variable('message', array(''), true);
488
				foreach ($description_array as $var)
489
				{
490
					if (strlen($var) > $this->gallery_config->get('description_length'))
491
					{
492
						trigger_error($this->language->lang('DESC_TOO_LONG'));
493
					}
494
				}
495
				$upload_files_limit = ($this->auth->acl_check('i_unlimited', $album_id, $album_data['album_user_id'])) ? $this->gallery_config->get('num_uploads') : min(($this->auth->acl_check('i_count', $album_id, $album_data['album_user_id']) - $own_images), $this->gallery_config->get('num_uploads'));
496
497
				$upload_ids = $this->request->variable('upload_ids', array(''));
498
499
				$process = $this->gallery_upload;
500
				$process->set_up($album_id, $upload_files_limit);
501
				$process->set_rotating($this->request->variable('rotate', array(0)));
502
				$process->get_images($upload_ids);
503
				$image_names = $this->request->variable('image_name', array(''), true);
504
				$process->set_names($image_names);
505
				$process->set_descriptions($description_array);
506
				$process->set_image_num($this->request->variable('image_num', 0));
507
				$process->use_same_name($this->request->variable('same_name', false));
508
509
				$success = true;
510
				foreach ($process->images as $image_id)
511
				{
512
					$success = $success && $process->update_image($image_id, !$this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id']), $album_data['album_contest']);
513
					if ($this->gallery_user->get_data('watch_own'))
514
					{
515
						$this->gallery_notification->add($image_id);
516
					}
517
				}
518
519
				$message = '';
520
				$error = implode('<br />', $process->errors);
521
				if ($this->auth->acl_check('i_approve', $album_id, $album_data['album_user_id']))
522
				{
523
					$message .= (!$error) ? $this->language->lang('ALBUM_UPLOAD_SUCCESSFUL') : $this->language->lang('ALBUM_UPLOAD_SUCCESSFUL_ERROR', $error);
524
					$meta_refresh_time = ($success) ? 3 : 20;
525
					//$this->notification_helper->notify_album($album_id, $this->user->data['user_id']);
526
					$data = array(
527
						'targets'	=> array($this->user->data['user_id']),
528
						'album_id'	=> (int) $album_id,
529
						'last_image'	=> end($process->images),
530
					);
531
					$this->notification_helper->new_image($data);
532
				}
533
				else
534
				{
535
					$target = array(
536
						'album_id'	=>	(int) $album_id,
537
						'last_image'	=> end($process->images),
538
						'uploader'		=> $this->user->data['user_id'],
539
					);
540
					$this->notification_helper->notify('approval', $target);
541
					$message .= (!$error) ? $this->language->lang('ALBUM_UPLOAD_NEED_APPROVAL') : $this->language->lang('ALBUM_UPLOAD_NEED_APPROVAL_ERROR', $error);
542
					$meta_refresh_time = 20;
543
				}
544
				$message .= '<br /><br />' . sprintf($this->language->lang('CLICK_RETURN_ALBUM'), '<a href="' . $album_backlink . '">', '</a>');
545
546
				// ToDo - notifications!!!
547
				//$phpbb_gallery_notification->send_notification('album', $album_id, $image_names[0]);
548
549
				$this->image->handle_counter($process->images, true);
550
				$this->album->update_info($album_id);
551
552
				$this->url->meta_refresh($meta_refresh_time, $album_backlink);
553
				trigger_error($message);
554
			}
555
556
			$num_images = 0;
557
			foreach ($process->images as $image_id)
558
			{
559
				$data = $process->image_data[$image_id];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $process does not seem to be defined for all execution paths leading up to this point.
Loading history...
560
				$this->template->assign_block_vars('image', array(
561
					'U_IMAGE'		=> $this->image->generate_link('thumbnail', 'plugin', $image_id, $data['image_name'], $album_id),
562
					'IMAGE_NAME'	=> $data['image_name'],
563
					'IMAGE_DESC'	=> $data['image_desc'],
564
				));
565
				$num_images++;
566
			}
567
568
			$s_hidden_fields = build_hidden_fields(array(
0 ignored issues
show
Bug introduced by
The function build_hidden_fields was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

568
			$s_hidden_fields = /** @scrutinizer ignore-call */ build_hidden_fields(array(
Loading history...
569
				'upload_ids'	=> $process->generate_hidden_fields(),
570
			));
571
572
			$s_can_rotate = ($this->gallery_config->get('allow_rotate') && function_exists('imagerotate'));
573
			$this->template->assign_vars(array(
574
				'ERROR'				=> $error,
575
				'S_UPLOAD_EDIT'		=> true,
576
				'S_ALLOW_ROTATE'	=> $s_can_rotate,
577
				'S_ALBUM_ACTION'		=>  $this->helper->route('phpbbgallery_core_album_upload', array('album_id' => $album_id)),
578
				'S_USERNAME'		=> (!$this->user->data['is_registered']) ? $username : '',
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $username does not seem to be defined for all execution paths leading up to this point.
Loading history...
579
				'NUM_IMAGES'		=> $num_images,
580
				'COLOUR_ROWSPAN'	=> ($s_can_rotate) ? $num_images * 3 : $num_images * 2,
581
582
				'L_DESCRIPTION_LENGTH'	=> $this->language->lang('DESCRIPTION_LENGTH', $this->gallery_config->get('description_length')),
583
				'S_HIDDEN_FIELDS'	=> $s_hidden_fields,
584
			));
585
		}
586
		return $this->helper->render('gallery/posting_body.html', $page_title);
587
	}
588
589
	private function check_fs()
590
	{
591
592
		$phpbbgallery_core_file = $this->phpbb_root_path . 'files/phpbbgallery/core';
593
		$phpbbgallery_core_file_medium = $this->phpbb_root_path . 'files/phpbbgallery/core/medium';
594
		$phpbbgallery_core_file_mini = $this->phpbb_root_path . 'files/phpbbgallery/core/mini';
595
		$phpbbgallery_core_file_source = $this->phpbb_root_path . 'files/phpbbgallery/core/source';
596
597
		if (file_exists($phpbbgallery_core_file) && is_writable($phpbbgallery_core_file) && file_exists($phpbbgallery_core_file_source) && is_writable($phpbbgallery_core_file_source) && file_exists($phpbbgallery_core_file_medium) && is_writable($phpbbgallery_core_file_medium) && file_exists($phpbbgallery_core_file_mini) && is_writable($phpbbgallery_core_file_mini))
598
		{
599
			return true;
600
		}
601
		else
602
		{
603
			return false;
604
		}
605
	}
606
}
607