main_module   F
last analyzed

Complexity

Total Complexity 110

Size/Duplication

Total Lines 1092
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 110
eloc 671
c 2
b 1
f 0
dl 0
loc 1092
rs 1.929
ccs 0
cts 878
cp 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A subscribe_pegas() 0 15 2
A move_album() 0 69 4
D manage_subscriptions() 0 143 15
F create_album() 0 141 17
A info() 0 21 2
F edit_album() 0 239 30
A initialise_album() 0 50 3
F delete_album() 0 187 14
C manage_albums() 0 90 11
C main() 0 105 12

How to fix   Complexity   

Complex Class

Complex classes like main_module 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 main_module, 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\ucp;
14
15
/**
16
* @package ucp
17
*/
18
class main_module
19
{
20
	var $u_action;
21
	protected $language;
22
	public $tpl_name;
23
	public $page_title;
24
25
	function main($id, $mode)
0 ignored issues
show
Unused Code introduced by
The parameter $mode is not used and could be removed. ( Ignorable by Annotation )

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

25
	function main($id, /** @scrutinizer ignore-unused */ $mode)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

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

25
	function main(/** @scrutinizer ignore-unused */ $id, $mode)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
	{
27
		global $user, $phpbb_container, $table_prefix, $phpbb_gallery_url;
28
		global $phpbb_ext_gallery_core_album, $albums_table, $phpbb_ext_gallery_core_auth, $phpbb_ext_gallery_core_album_display, $images_table;
29
		global $phpbb_gallery_image, $users_table, $phpbb_ext_gallery_config, $comments_table, $rates_table, $reports_table, $watch_table, $contests_table;
30
		global $phpbb_ext_gallery_user, $request;
31
32
		$phpbb_gallery_url = $phpbb_container->get('phpbbgallery.core.url');
33
		$phpbb_gallery_url->_include('functions_display', 'phpbb');
34
35
		$phpbb_ext_gallery_core_album =$phpbb_container->get('phpbbgallery.core.album');
36
37
		$phpbb_ext_gallery_core_auth = $phpbb_container->get('phpbbgallery.core.auth');
38
39
		$phpbb_ext_gallery_config = $phpbb_container->get('phpbbgallery.core.config');
40
41
		$phpbb_ext_gallery_core_album_display = $phpbb_container->get('phpbbgallery.core.album.display');
42
43
		$phpbb_gallery_image = $phpbb_container->get('phpbbgallery.core.image');
44
45
		$phpbb_ext_gallery_user = $phpbb_container->get('phpbbgallery.core.user');
46
		$this->language = $phpbb_container->get('language');
47
48
		$albums_table = $table_prefix . 'gallery_albums';
49
		$roles_table = $table_prefix . 'gallery_roles';
0 ignored issues
show
Unused Code introduced by
The assignment to $roles_table is dead and can be removed.
Loading history...
50
		$permissions_table = $table_prefix . 'gallery_permissions';
0 ignored issues
show
Unused Code introduced by
The assignment to $permissions_table is dead and can be removed.
Loading history...
51
		$modscache_table = $table_prefix . 'gallery_modscache';
0 ignored issues
show
Unused Code introduced by
The assignment to $modscache_table is dead and can be removed.
Loading history...
52
		$contests_table = $table_prefix . 'gallery_contests';
53
		$users_table = $table_prefix . 'gallery_users';
54
		$images_table = $table_prefix . 'gallery_images';
55
		$comments_table = $table_prefix . 'gallery_comments';
56
		$rates_table = $table_prefix . 'gallery_rates';
57
		$reports_table = $table_prefix . 'gallery_reports';
58
		$watch_table = $table_prefix . 'gallery_watch';
59
60
		$this->language->add_lang(array('gallery', 'gallery_acp', 'gallery_mcp', 'gallery_ucp'), 'phpbbgallery/core');
61
		$this->language->add_lang('posting');
62
		$this->tpl_name = 'gallery/ucp_gallery';
63
		add_form_key('ucp_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

63
		/** @scrutinizer ignore-call */ 
64
  add_form_key('ucp_gallery');
Loading history...
64
65
		$mode = $request->variable('mode', 'manage_albums');
66
		$action = $request->variable('action', '');
67
		$cancel = (isset($_POST['cancel'])) ? true : false;
68
		$phpbb_ext_gallery_core_auth->load_user_permissions($user->data['user_id']);
69
		if ($cancel)
70
		{
71
			$action = '';
72
		}
73
		switch ($mode)
74
		{
75
			case 'manage_albums':
76
				switch ($action)
77
				{
78
					case 'manage':
79
						$title = 'MANAGE_SUBALBUMS';
80
						$this->page_title = $this->language->lang($title);
81
						$this->manage_albums();
82
					break;
83
84
					case 'create':
85
						$title = 'CREATE_SUBALBUM';
86
						$this->page_title = $this->language->lang($title);
87
						$this->create_album();
88
					break;
89
90
					case 'edit':
91
						$title = 'EDIT_SUBALBUM';
92
						$this->page_title = $this->language->lang($title);
93
						$this->edit_album();
94
					break;
95
96
					case 'delete':
97
						$title = 'DELETE_ALBUM';
98
						$this->page_title = $this->language->lang($title);
99
						$this->delete_album();
100
					break;
101
102
					case 'move':
103
						$this->move_album();
104
					break;
105
106
					case 'initialise':
107
						$this->initialise_album();
108
					break;
109
110
					default:
111
						$title = 'UCP_GALLERY_PERSONAL_ALBUMS';
112
						$this->page_title = $this->language->lang($title);
113
						if (!$phpbb_ext_gallery_user->get_data('personal_album_id'))
114
						{
115
							$this->info();
116
						}
117
						else
118
						{
119
							$this->manage_albums();
120
						}
121
					break;
122
				}
123
			break;
124
125
			case 'manage_subscriptions':
126
				$title = 'UCP_GALLERY_WATCH';
127
				$this->page_title = $this->language->lang($title);
128
				$this->manage_subscriptions();
129
			break;
130
		}
131
	}
132
133
	function info()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
134
	{
135
		global $template, $user, $phpbb_ext_gallery_user, $phpbb_gallery_url, $phpbb_container;
136
		$this->language = $phpbb_container->get('language');
137
138
		//We need to set user_ID so we can test for any other thing
139
		$phpbb_ext_gallery_user->set_user_id($user->data['user_id']);
140
		if (!$phpbb_ext_gallery_user->get_data('personal_album_id'))
141
		{
142
			// User will probably go to initialise_album()
143
			$template->assign_vars(array(
144
				'S_INFO_CREATE'				=> true,
145
				'S_UCP_ACTION'		=> $this->u_action . '&amp;action=initialise',
146
147
				'L_TITLE'			=> $this->language->lang('UCP_GALLERY_PERSONAL_ALBUMS'),
148
				'L_TITLE_EXPLAIN'	=> $this->language->lang('NO_PERSONAL_ALBUM'),
149
			));
150
		}
151
		else
152
		{
153
			$phpbb_gallery_url->redirect('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&mode=manage_albums&action=manage');
154
		}
155
	}
156
157
	function initialise_album()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
158
	{
159
		global $cache, $db,  $user, $phpbb_ext_gallery_core_auth, $phpbb_ext_gallery_core_album, $phpbb_ext_gallery_config, $albums_table, $phpbb_ext_gallery_user;
160
		global $request, $users_table, $phpbb_container;
161
162
		// we will have to initialise $phpbb_ext_gallery_user
163
		$phpbb_ext_gallery_user->set_user_id($user->data['user_id']);
164
		if (!$phpbb_ext_gallery_user->get_data('personal_album_id'))
165
		{
166
			// Check if the user is allowed to have on
167
			if (!$phpbb_ext_gallery_core_auth->acl_check('i_upload', $phpbb_ext_gallery_core_auth::OWN_ALBUM))
168
			{
169
				trigger_error('NO_PERSALBUM_ALLOWED');
170
			}
171
172
			$album_data = array(
173
				'album_name'					=> $user->data['username'],
174
				'parent_id'						=> $request->variable('parent_id', 0),
175
				//left_id and right_id default by db
176
				'album_desc_options'			=> 7,
177
				'album_desc'					=> utf8_normalize_nfc($request->variable('album_desc', '', true)),
0 ignored issues
show
Bug introduced by
The function utf8_normalize_nfc 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

177
				'album_desc'					=> /** @scrutinizer ignore-call */ utf8_normalize_nfc($request->variable('album_desc', '', true)),
Loading history...
178
				'album_parents'					=> '',
179
				'album_type'					=> (int) \phpbbgallery\core\block::TYPE_UPLOAD,
180
				'album_status'					=> (int) \phpbbgallery\core\block::ALBUM_OPEN,
181
				'album_user_id'					=> $user->data['user_id'],
182
				'album_last_username'			=> '',
183
				'album_last_user_colour'		=> $user->data['user_colour'],
184
			);
185
			$db->sql_query('INSERT INTO ' . $albums_table . ' ' . $db->sql_build_array('INSERT', $album_data));
186
			$album_id = $db->sql_nextid();
187
188
			$phpbb_ext_gallery_user->update_data(array(
189
				'personal_album_id'	=> $album_id,
190
			));
191
192
			$this->subscribe_pegas($album_id);
193
			$phpbb_ext_gallery_config->inc('num_pegas', 1);
194
195
			// Update the config for the statistic on the index
196
			$phpbb_ext_gallery_config->set('newest_pega_user_id', $user->data['user_id']);
197
			$phpbb_ext_gallery_config->set('newest_pega_username', $user->data['username']);
198
			$phpbb_ext_gallery_config->set('newest_pega_user_colour', $user->data['user_colour']);
199
			$phpbb_ext_gallery_config->set('newest_pega_album_id', $album_id);
200
201
			$cache->destroy('_albums');
202
			$cache->destroy('sql', $albums_table);
203
			$cache->destroy('sql', $users_table);
204
			$phpbb_ext_gallery_core_auth->set_user_permissions('all', '');
205
		}
206
		redirect($this->u_action);
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

206
		/** @scrutinizer ignore-call */ 
207
  redirect($this->u_action);
Loading history...
207
	}
208
209
	function manage_albums()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
210
	{
211
		global $cache, $db, $template, $user, $phpbb_ext_gallery_core_album, $albums_table, $phpbb_ext_gallery_core_auth, $phpbb_ext_gallery_core_album_display;
212
		global $phpbb_container, $request, $phpbb_gallery_url, $phpbb_ext_gallery_user;
213
214
		$parent_id = $request->variable('parent_id', $phpbb_ext_gallery_user->get_data('personal_album_id'));
215
		$phpbb_ext_gallery_core_album->check_user($parent_id);
216
		$helper = $phpbb_container->get('controller.helper');
217
		$this->language = $phpbb_container->get('language');
218
219
		$sql = 'SELECT COUNT(album_id) albums
220
			FROM ' . $albums_table . '
221
			WHERE album_user_id = ' . (int) $user->data['user_id'];
222
		$result = $db->sql_query($sql);
223
		$albums = (int) $db->sql_fetchfield('albums');
224
		$db->sql_freeresult($result);
225
226
		$s_allowed_create = ($phpbb_ext_gallery_core_auth->acl_check('a_unlimited', $phpbb_ext_gallery_core_auth::OWN_ALBUM) || ($phpbb_ext_gallery_core_auth->acl_check('a_count', $phpbb_ext_gallery_core_auth::OWN_ALBUM) > $albums)) ? true : false;
227
		$template->assign_vars(array(
228
			'S_MANAGE_SUBALBUMS'			=> true,
229
			'U_CREATE_SUBALBUM'				=> ($s_allowed_create) ? ($this->u_action . '&amp;action=create' . (($parent_id) ? '&amp;parent_id=' . $parent_id : '')) : '',
230
231
			'L_TITLE'			=> $this->language->lang('MANAGE_SUBALBUMS'),
232
			//'ACP_GALLERY_TITLE_EXPLAIN'	=> $user->lang['ALBUM'],
233
		));
234
235
		if (!$parent_id)
236
		{
237
			$navigation = $this->language->lang('PERSONAL_ALBUM');
238
		}
239
		else
240
		{
241
			$navigation = $this->language->lang('PERSONAL_ALBUM');
242
243
			$albums_nav = $phpbb_ext_gallery_core_album_display->get_branch($user->data['user_id'], $parent_id, 'parents', 'descending');
244
			foreach ($albums_nav as $row)
245
			{
246
				if ($row['album_id'] == $parent_id)
247
				{
248
					$navigation .= ' &raquo; ' . $row['album_name'];
249
				}
250
				else
251
				{
252
					$navigation .= ' &raquo; <a href="' . $this->u_action . '&amp;action=manage&amp;parent_id=' . $row['album_id'] . '">' . $row['album_name'] . '</a>';
253
				}
254
			}
255
		}
256
257
		$album = array();
258
		$sql = 'SELECT *
259
			FROM ' . $albums_table . '
260
			WHERE parent_id = ' . (int) $parent_id . '
261
				AND album_user_id = ' . (int) $user->data['user_id'] . '
262
			ORDER BY left_id ASC';
263
		$result = $db->sql_query($sql);
264
265
		while ($row = $db->sql_fetchrow($result))
266
		{
267
			$album[] = $row;
268
		}
269
		$db->sql_freeresult($result);
270
271
		for ($i = 0, $end = count($album); $i < $end; $i++)
272
		{
273
			$folder_img = ($album[$i]['left_id'] + 1 != $album[$i]['right_id']) ? 'forum_read_subforum' : 'forum_read';
274
			$template->assign_block_vars('album_row', array(
275
				'FOLDER_IMAGE'			=> $user->img($folder_img, $album[$i]['album_name'], false, '', 'src'),
276
				'U_ALBUM'				=> $this->u_action . '&amp;action=manage&amp;parent_id=' . $album[$i]['album_id'],
277
				'ALBUM_NAME'			=> $album[$i]['album_name'],
278
				'ALBUM_DESCRIPTION'		=> generate_text_for_display($album[$i]['album_desc'], $album[$i]['album_desc_uid'], $album[$i]['album_desc_bitfield'], $album[$i]['album_desc_options']),
0 ignored issues
show
Bug introduced by
The function generate_text_for_display 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

278
				'ALBUM_DESCRIPTION'		=> /** @scrutinizer ignore-call */ generate_text_for_display($album[$i]['album_desc'], $album[$i]['album_desc_uid'], $album[$i]['album_desc_bitfield'], $album[$i]['album_desc_options']),
Loading history...
279
				'U_MOVE_UP'				=> $this->u_action . '&amp;action=move&amp;move=move_up&amp;album_id=' . $album[$i]['album_id'],
280
				'U_MOVE_DOWN'			=> $this->u_action . '&amp;action=move&amp;move=move_down&amp;album_id=' . $album[$i]['album_id'],
281
				'U_EDIT'				=> $this->u_action . '&amp;action=edit&amp;album_id=' . $album[$i]['album_id'],
282
				'U_DELETE'				=> $this->u_action . '&amp;action=delete&amp;album_id=' . $album[$i]['album_id'],
283
			));
284
		}
285
286
		$template->assign_vars(array(
287
			'NAVIGATION'		=> $navigation,
288
			'S_ALBUM'			=> $parent_id,
289
			'U_GOTO'			=> $helper->route('phpbbgallery_core_album', array('album_id' => $parent_id)),
290
			'U_EDIT'			=> $this->u_action . '&amp;action=edit&amp;album_id=' . $parent_id,
291
			'U_DELETE'			=> $this->u_action . '&amp;action=delete&amp;album_id=' . $parent_id,
292
			'U_UPLOAD'			=> $helper->route('phpbbgallery_core_album_upload', array('album_id' => $parent_id)),
293
			'ICON_MOVE_DOWN'			=> '<img src="' . $phpbb_gallery_url->path('images') . 'icon_down.gif" alt="" />',
294
			'ICON_MOVE_DOWN_DISABLED'	=> '<img src="' . $phpbb_gallery_url->path('images') . 'icon_down_disabled.gif" alt="" />',
295
			'ICON_MOVE_UP'				=> '<img src="' . $phpbb_gallery_url->path('images') . 'icon_up.gif" alt="" />',
296
			'ICON_MOVE_UP_DISABLED'		=> '<img src="' . $phpbb_gallery_url->path('images') . 'icon_up_disabled.gif" alt="" />',
297
			'ICON_EDIT'					=> '<img src="' . $phpbb_gallery_url->path('images') . 'icon_edit.gif" alt="" />',
298
			'ICON_DELETE'				=> '<img src="' . $phpbb_gallery_url->path('images') . 'icon_delete.gif" alt="" />',
299
		));
300
	}
301
302
	function create_album()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
303
	{
304
		global $cache, $db, $template, $user, $phpbb_gallery_url, $phpbb_ext_gallery_core_auth, $albums_table, $phpbb_ext_gallery_core_album, $request;
305
		global $phpbb_container, $phpbb_ext_gallery_user, $users_table;
306
		$phpbb_gallery_url->_include(array('bbcode', 'message_parser'), 'phpbb');
307
		$this->language = $phpbb_container->get('language');
308
309
		// Check if the user has already reached his limit
310
		if (!$phpbb_ext_gallery_core_auth->acl_check('i_upload', $phpbb_ext_gallery_core_auth::OWN_ALBUM))
311
		{
312
			trigger_error('NO_PERSALBUM_ALLOWED');
313
		}
314
315
		$sql = 'SELECT COUNT(album_id) albums
316
			FROM ' . $albums_table . '
317
			WHERE album_user_id = ' . (int) $user->data['user_id'];
318
		$result = $db->sql_query($sql);
319
		$albums = $db->sql_fetchfield('albums');
320
		$db->sql_freeresult($result);
321
322
		if (!$phpbb_ext_gallery_core_auth->acl_check('a_unlimited', $phpbb_ext_gallery_core_auth::OWN_ALBUM) && ($phpbb_ext_gallery_core_auth->acl_check('a_count', $phpbb_ext_gallery_core_auth::OWN_ALBUM) <= $albums))
323
		{
324
			trigger_error('NO_MORE_SUBALBUMS_ALLOWED');
325
		}
326
327
		$submit = (isset($_POST['submit'])) ? true : false;
328
		$redirect = $request->variable('redirect', '');
329
330
		if (!$submit)
331
		{
332
			$parent_id = $request->variable('parent_id', 0);
333
			$phpbb_ext_gallery_core_album->check_user($parent_id);
334
			$parents_list = $phpbb_ext_gallery_core_album->get_albumbox(false, '', $parent_id, false, false, $user->data['user_id']);
335
336
			$s_access_options = '';
337
			if ($phpbb_ext_gallery_core_auth->acl_check('a_restrict', $phpbb_ext_gallery_core_auth::OWN_ALBUM))
338
			{
339
				$access_options = array(
340
					$phpbb_ext_gallery_core_auth::ACCESS_ALL			=> 'ALL',
341
					$phpbb_ext_gallery_core_auth::ACCESS_REGISTERED	=> 'REGISTERED',
342
					$phpbb_ext_gallery_core_auth::ACCESS_NOT_FOES		=> 'NOT_FOES',
343
					$phpbb_ext_gallery_core_auth::ACCESS_FRIENDS		=> 'FRIENDS',
344
				);
345
				foreach ($access_options as $value => $lang_key)
346
				{
347
					$s_access_options .= '<option value="' . $value . '">' . $this->language->lang('ACCESS_CONTROL_' . $lang_key) . '</option>';
348
				}
349
			}
350
351
			$template->assign_vars(array(
352
				'S_CREATE_SUBALBUM'		=> true,
353
				'S_UCP_ACTION'			=> $this->u_action . '&amp;action=create' . (($redirect != '') ? '&amp;redirect=album' : ''),
354
				'L_TITLE'				=> $this->language->lang('CREATE_SUBALBUM'),
355
				'L_TITLE_EXPLAIN'		=> $this->language->lang('CREATE_SUBALBUM_EXP'),
356
357
				'S_DESC_BBCODE_CHECKED'		=> true,
358
				'S_DESC_SMILIES_CHECKED'	=> true,
359
				'S_DESC_URLS_CHECKED'		=> true,
360
				'S_PARENT_OPTIONS'			=> '<option value="' . $phpbb_ext_gallery_user->get_data('personal_album_id') . '">' . $this->language->lang('NO_PARENT_ALBUM') . '</option>' . $parents_list,
361
362
				'S_AUTH_ACCESS_OPTIONS'		=> $s_access_options,
363
				'L_ALBUM_ACCESS_EXPLAIN'	=> $this->language->lang('ALBUM_ACCESS_EXPLAIN', '<a href="' . $phpbb_gallery_url->append_sid('phpbb', 'faq') . '#f6r0">', '</a>'),
364
			));
365
		}
366
		else
367
		{
368
			if (!check_form_key('ucp_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

368
			if (!/** @scrutinizer ignore-call */ check_form_key('ucp_gallery'))
Loading history...
369
			{
370
				trigger_error('FORM_INVALID');
371
			}
372
373
			// Create the subalbum
374
			$album_data = array(
375
				'album_name'					=> $request->variable('album_name', '', true),
376
				'parent_id'						=> $request->variable('parent_id', 0),
377
				'album_parents'					=> '',
378
				'album_type'					=> (int) \phpbbgallery\core\block::TYPE_UPLOAD,
379
				'album_status'					=> (int) \phpbbgallery\core\block::ALBUM_OPEN,
380
				'album_desc_options'			=> 7,
381
				'album_desc'					=> utf8_normalize_nfc($request->variable('album_desc', '', true)),
0 ignored issues
show
Bug introduced by
The function utf8_normalize_nfc 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

381
				'album_desc'					=> /** @scrutinizer ignore-call */ utf8_normalize_nfc($request->variable('album_desc', '', true)),
Loading history...
382
				'album_user_id'					=> $user->data['user_id'],
383
				'album_last_username'			=> '',
384
				'album_auth_access'				=> ($phpbb_ext_gallery_core_auth->acl_check('a_restrict', $phpbb_ext_gallery_core_auth::OWN_ALBUM)) ? $request->variable('album_auth_access', 0) : 0,
385
			);
386
387
			$album_data['album_auth_access'] = min(3, max(0, $album_data['album_auth_access']));
388
389
			if (!$album_data['album_name'])
390
			{
391
				trigger_error('MISSING_ALBUM_NAME');
392
			}
393
			$album_data['parent_id'] = ($album_data['parent_id']) ? $album_data['parent_id'] : $phpbb_ext_gallery_user->get_data('personal_album_id');
394
			generate_text_for_storage($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options'], $request->variable('desc_parse_bbcode', false), $request->variable('desc_parse_urls', false), $request->variable('desc_parse_smilies', false));
0 ignored issues
show
Bug introduced by
The function generate_text_for_storage 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

394
			/** @scrutinizer ignore-call */ 
395
   generate_text_for_storage($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options'], $request->variable('desc_parse_bbcode', false), $request->variable('desc_parse_urls', false), $request->variable('desc_parse_smilies', false));
Loading history...
395
396
			/**
397
			* borrowed from phpBB3
398
			* @author: phpBB Group
399
			* @location: acp_forums->manage_forums
400
			*/
401
			// Parent should always be filled otherwise we use initialise_album()
402
			if ($album_data['parent_id'])
403
			{
404
				$sql = 'SELECT left_id, right_id, album_type
405
					FROM ' . $albums_table . '
406
					WHERE album_id = ' . (int) $album_data['parent_id'];
407
				$result = $db->sql_query($sql);
408
				$row = $db->sql_fetchrow($result);
409
				$db->sql_freeresult($result);
410
411
				if (!$row)
412
				{
413
					trigger_error('PARENT_NOT_EXIST', E_USER_WARNING);
414
				}
415
416
				$sql = 'UPDATE ' . $albums_table . '
417
					SET left_id = left_id + 2, right_id = right_id + 2
418
					WHERE left_id > ' . (int) $row['right_id'] . '
419
						AND album_user_id = ' . (int) $album_data['album_user_id'];
420
				$db->sql_query($sql);
421
422
				$sql = 'UPDATE ' . $albums_table . '
423
					SET right_id = right_id + 2
424
					WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id
425
						AND album_user_id = ' . $album_data['album_user_id'];
426
				$db->sql_query($sql);
427
428
				$album_data['left_id'] = $row['right_id'];
429
				$album_data['right_id'] = $row['right_id'] + 1;
430
			}
431
			$db->sql_query('INSERT INTO ' . $albums_table . ' ' . $db->sql_build_array('INSERT', $album_data));
432
			$redirect_album_id = $db->sql_nextid();
433
434
			$this->subscribe_pegas($redirect_album_id);
435
436
			$cache->destroy('_albums');
437
			$cache->destroy('sql', $albums_table);
438
			$cache->destroy('sql', $users_table);
439
			$phpbb_ext_gallery_core_auth->set_user_permissions('all', '');
440
441
			trigger_error($this->language->lang('CREATED_SUBALBUM') . '<br /><br />
442
				<a href="' . (($redirect) ? $phpbb_gallery_url->append_sid('album', "album_id=$redirect_album_id") : $phpbb_gallery_url->append_sid('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&amp;mode=manage_albums&amp;action=manage&amp;parent_id=' . (($album_data['parent_id']) ? $album_data['parent_id'] : $phpbb_ext_gallery_user->get_data('personal_album_id')))) . '">' . $user->lang('BACK_TO_PREV') . '</a>');
443
		}
444
	}
445
446
	function edit_album()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
447
	{
448
		global $config, $cache, $db, $template, $user, $phpbb_gallery_url, $phpbb_ext_gallery_core_album, $phpbb_ext_gallery_core_auth, $albums_table, $phpbb_ext_gallery_core_album_display;
449
		global $request, $phpbb_container, $phpbb_ext_gallery_user, $users_table;
450
451
		$this->language = $phpbb_container->get('language');
452
453
		$phpbb_gallery_url->_include(array('bbcode','message_parser'), 'phpbb');
454
455
		$album_id = $request->variable('album_id', 0);
456
		$phpbb_ext_gallery_core_album->check_user($album_id);
457
458
		$submit = (isset($_POST['submit'])) ? true : false;
459
		$redirect = $request->variable('redirect', '');
460
		if (!$submit)
461
		{
462
			$album_data = $phpbb_ext_gallery_core_album->get_info($album_id);
463
			$album_desc_data = generate_text_for_edit($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_options']);
0 ignored issues
show
Bug introduced by
The function generate_text_for_edit 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
			$album_desc_data = /** @scrutinizer ignore-call */ generate_text_for_edit($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_options']);
Loading history...
464
465
			// Make sure no direct child forums are able to be selected as parents.
466
			$exclude_albums = array($album_id);
467
			foreach ($phpbb_ext_gallery_core_album_display->get_branch($album_data['album_user_id'], $album_id, 'children') as $row)
468
			{
469
				$exclude_albums[] = (int) $row['album_id'];
470
			}
471
472
			$parents_list = $phpbb_ext_gallery_core_album->get_albumbox(false, '', $album_data['parent_id'], false, $exclude_albums, $user->data['user_id']);
473
474
			$s_access_options = '';
475
			if ($phpbb_ext_gallery_core_auth->acl_check('a_restrict', $phpbb_ext_gallery_core_auth::OWN_ALBUM) && $album_data['parent_id'])
476
			{
477
				$access_options = array(
478
					$phpbb_ext_gallery_core_auth::ACCESS_ALL			=> 'ALL',
479
					$phpbb_ext_gallery_core_auth::ACCESS_REGISTERED	=> 'REGISTERED',
480
					$phpbb_ext_gallery_core_auth::ACCESS_NOT_FOES		=> 'NOT_FOES',
481
					$phpbb_ext_gallery_core_auth::ACCESS_FRIENDS		=> 'FRIENDS',
482
				);
483
				if (isset($config['zebra_enhance_version']))
484
				{
485
					$access_options[$phpbb_ext_gallery_core_auth::ACCESS_SPECIAL_FRIENDS] = 'SPECIAL_FRIENDS';
486
				}
487
				foreach ($access_options as $value => $lang_key)
488
				{
489
					$s_access_options .= '<option value="' . $value . (($value == $album_data['album_auth_access']) ? '" selected="selected' : '') . '">' . $this->language->lang('ACCESS_CONTROL_' . $lang_key) . '</option>';
490
				}
491
			}
492
493
			$template->assign_vars(array(
494
				'S_EDIT_SUBALBUM'			=> true,
495
				'S_PERSONAL_ALBUM'			=> ($album_id == $phpbb_ext_gallery_user->get_data('personal_album_id')) ? true : false,
496
				'S_AUTH_ACCESS_OPTIONS'		=> $s_access_options,
497
				'L_ALBUM_ACCESS_EXPLAIN'	=> $this->language->lang('ALBUM_ACCESS_EXPLAIN', '<a href="' . $phpbb_gallery_url->append_sid('phpbb', 'faq') . '#f6r0">', '</a>'),
498
499
				'L_TITLE'					=> $this->language->lang('EDIT_SUBALBUM'),
500
				'L_TITLE_EXPLAIN'			=> $this->language->lang('EDIT_SUBALBUM_EXP'),
501
502
				'S_ALBUM_ACTION' 			=> $this->u_action . '&amp;action=edit&amp;album_id=' . $album_id . (($redirect != '') ? '&amp;redirect=album' : ''),
503
				'S_PARENT_OPTIONS'			=> '<option value="' . $phpbb_ext_gallery_user->get_data('personal_album_id') . '">' . $this->language->lang('NO_PARENT_ALBUM') . '</option>' . $parents_list,
504
505
				'ALBUM_NAME' 				=> $album_data['album_name'],
506
				'ALBUM_DESC'				=> $album_desc_data['text'],
507
				'ALBUM_TYPE'				=> $album_data['album_type'],
508
				'S_DESC_BBCODE_CHECKED'		=> ($album_desc_data['allow_bbcode']) ? true : false,
509
				'S_DESC_SMILIES_CHECKED'	=> ($album_desc_data['allow_smilies']) ? true : false,
510
				'S_DESC_URLS_CHECKED'		=> ($album_desc_data['allow_urls']) ? true : false,
511
512
				'S_MODE' 					=> 'edit',
513
			));
514
		}
515
		else
516
		{
517
			// Is it salty ?
518
			if (!check_form_key('ucp_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

518
			if (!/** @scrutinizer ignore-call */ check_form_key('ucp_gallery'))
Loading history...
519
			{
520
				trigger_error('FORM_INVALID');
521
			}
522
523
			$album_data = array(
524
				'album_name'					=> ($album_id == $phpbb_ext_gallery_user->get_data('personal_album_id')) ? $user->data['username'] : $request->variable('album_name', '', true),
525
				'parent_id'						=> $request->variable('parent_id', (($album_id == $phpbb_ext_gallery_user->get_data('personal_album_id')) ? 0 : $phpbb_ext_gallery_user->get_data('personal_album_id'))),
526
				//left_id and right_id are created some lines later
527
				'album_parents'					=> '',
528
				'album_type'					=> (int) \phpbbgallery\core\block::TYPE_UPLOAD,
529
				'album_desc_options'			=> 7,
530
				'album_desc'					=> utf8_normalize_nfc($request->variable('album_desc', '', true)),
0 ignored issues
show
Bug introduced by
The function utf8_normalize_nfc 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

530
				'album_desc'					=> /** @scrutinizer ignore-call */ utf8_normalize_nfc($request->variable('album_desc', '', true)),
Loading history...
531
				'album_auth_access'				=> ($phpbb_ext_gallery_core_auth->acl_check('a_restrict', $phpbb_ext_gallery_core_auth::OWN_ALBUM)) ? $request->variable('album_auth_access', 0) : 0,
532
			);
533
534
			generate_text_for_storage($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options'], $request->variable('desc_parse_bbcode', false), $request->variable('desc_parse_urls', false), $request->variable('desc_parse_smilies', false));
0 ignored issues
show
Bug introduced by
The function generate_text_for_storage 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

534
			/** @scrutinizer ignore-call */ 
535
   generate_text_for_storage($album_data['album_desc'], $album_data['album_desc_uid'], $album_data['album_desc_bitfield'], $album_data['album_desc_options'], $request->variable('desc_parse_bbcode', false), $request->variable('desc_parse_urls', false), $request->variable('desc_parse_smilies', false));
Loading history...
535
			$row = $phpbb_ext_gallery_core_album->get_info($album_id);
536
			$parent_id = (int) $album_data['parent_id'];
537
			if (!$row['parent_id'])
538
			{
539
				// do not allow to restrict access on the base-album
540
				$album_data['album_auth_access'] = 0;
541
			}
542
543
			// Ensure that no child is selected as parent
544
			$exclude_albums = array($album_id);
545
			foreach ($phpbb_ext_gallery_core_album_display->get_branch($row['album_user_id'], $album_id, 'children') as $loop)
546
			{
547
				$exclude_albums[] = (int) $loop['album_id'];
548
			}
549
			if (in_array($parent_id, $exclude_albums))
550
			{
551
				$parent_id = (int) $row['parent_id'];
552
			}
553
554
			// If the parent is different, the left_id and right_id have changed.
555
			if ($row['parent_id'] != $parent_id)
556
			{
557
				if ($parent_id > 0)
558
				{
559
					// Get the parent album now, so it throws an error when it does not exist, before we change the database.
560
					$parent = $phpbb_ext_gallery_core_album->get_info($parent_id);
0 ignored issues
show
Unused Code introduced by
The assignment to $parent is dead and can be removed.
Loading history...
561
				}
562
563
				// How many do we have to move and how far.
564
				$moving_ids = ($row['right_id'] - $row['left_id']) + 1;
565
				$sql = 'SELECT MAX(right_id) right_id
566
					FROM ' . $albums_table . '
567
					WHERE album_user_id = ' . (int) $row['album_user_id'];
568
				$result = $db->sql_query($sql);
569
				$moving_distance = ($db->sql_fetchfield('right_id') - $row['left_id']) + 1;
570
				$db->sql_freeresult($result);
571
572
				$stop_updating = $moving_distance + $row['left_id'];
573
574
				// Update the moving albums... move them to the end.
575
				$sql = 'UPDATE ' . $albums_table . '
576
					SET right_id = right_id + ' . $moving_distance . ',
577
						left_id = left_id + ' . $moving_distance . '
578
					WHERE album_user_id = ' . (int) $row['album_user_id'] . '
579
						AND left_id >= ' . (int) $row['left_id'] . '
580
						AND right_id <= ' . (int) $row['right_id'];
581
				$db->sql_query($sql);
582
583
				$new['left_id'] = $row['left_id'] + $moving_distance;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$new was never initialized. Although not strictly required by PHP, it is generally a good practice to add $new = array(); before regardless.
Loading history...
584
				$new['right_id'] = $row['right_id'] + $moving_distance;
585
586
				// Close the gap, we produced through moving.
587
				if ($parent_id == 0)
588
				{
589
					$sql = 'UPDATE ' . $albums_table . '
590
						SET left_id = left_id - ' . $moving_ids . '
591
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
592
							AND left_id >= ' . (int) $row['left_id'];
593
					$db->sql_query($sql);
594
595
					$sql = 'UPDATE ' . $albums_table . '
596
						SET right_id = right_id - ' . $moving_ids . '
597
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
598
							AND right_id >= ' . (int) $row['left_id'];
599
					$db->sql_query($sql);
600
				}
601
				else
602
				{
603
					$sql = 'UPDATE ' . $albums_table . '
604
						SET left_id = left_id - ' . $moving_ids . '
605
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
606
							AND left_id >= ' . (int) $row['left_id'] . '
607
							AND right_id <= ' . (int) $stop_updating;
608
					$db->sql_query($sql);
609
610
					$sql = 'UPDATE ' . $albums_table . '
611
						SET right_id = right_id - ' . $moving_ids . '
612
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
613
							AND right_id >= ' . (int) $row['left_id'] . '
614
							AND right_id <= ' . (int) $stop_updating;
615
					$db->sql_query($sql);
616
617
					// We should get new parent again for the case if it has been changed
618
					$parent = $phpbb_ext_gallery_core_album->get_info($parent_id);
619
620
					$sql = 'UPDATE ' . $albums_table . '
621
						SET left_id = left_id + ' . $moving_ids . '
622
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
623
							AND left_id >= ' . (int) $parent['right_id'] . '
624
							AND right_id <= ' . (int) $stop_updating;
625
					$db->sql_query($sql);
626
627
					$sql = 'UPDATE ' . $albums_table . '
628
						SET right_id = right_id + ' . $moving_ids . '
629
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
630
							AND right_id >= ' . (int) $parent['right_id'] . '
631
							AND right_id <= ' . (int) $stop_updating;
632
					$db->sql_query($sql);
633
634
					// We should get new parent again for the case if it has been changed
635
					$parent = $phpbb_ext_gallery_core_album->get_info($parent_id);
636
637
					// Move the albums to the suggested gap.
638
					$move_back = ($new['right_id'] - $parent['right_id']) + 1;
639
					$sql = 'UPDATE ' . $albums_table . '
640
						SET left_id = left_id - ' . $move_back . ',
641
							right_id = right_id - ' . $move_back . '
642
						WHERE album_user_id = ' . (int) $row['album_user_id'] . '
643
							AND left_id >= ' . (int) $stop_updating;
644
					$db->sql_query($sql);
645
				}
646
			}
647
648
			// The album name has changed, clear the parents list of all albums.
649
			if ($album_data['album_name'] == '')
650
			{
651
				$album_data['album_name'] = $row['album_name'];
652
			}
653
			else if ($row['album_name'] != $album_data['album_name'])
654
			{
655
				$sql = 'UPDATE ' . $albums_table . "
656
					SET album_parents = ''";
657
				$db->sql_query($sql);
658
			}
659
660
			// The album access has changed, clear the permissions of all users.
661
			if (isset($config['zebra_enhance_version']))
662
			{
663
				$album_data['album_auth_access'] = min(4, max(0, $album_data['album_auth_access']));
664
			}
665
			else
666
			{
667
				$album_data['album_auth_access'] = min(3, max(0, $album_data['album_auth_access']));
668
			}
669
			if ($row['album_auth_access'] != $album_data['album_auth_access'])
670
			{
671
				$phpbb_ext_gallery_core_auth->set_user_permissions('all', '');
672
			}
673
674
			$sql = 'UPDATE ' . $albums_table . ' 
675
					SET ' . $db->sql_build_array('UPDATE', $album_data) . '
676
					WHERE album_id  = ' . (int) $album_id;
677
			$db->sql_query($sql);
678
679
			$cache->destroy('sql', $albums_table);
680
			$cache->destroy('sql', $users_table);
681
			$cache->destroy('_albums');
682
683
			trigger_error($this->language->lang('EDITED_SUBALBUM') . '<br /><br />
684
				<a href="' . (($redirect) ? $phpbb_gallery_url->append_sid('album', "album_id=$album_id") : $phpbb_gallery_url->append_sid('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&amp;mode=manage_albums&amp;action=manage&amp;parent_id=' . (($album_data['parent_id']) ? $album_data['parent_id'] : $phpbb_ext_gallery_user->get_data('personal_album_id')))) . '">' . $this->language->lang('BACK_TO_PREV') . '</a>');
685
		}
686
	}
687
688
	function delete_album()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
689
	{
690
		global $cache, $db, $template, $user, $phpbb_gallery_url, $phpbb_ext_gallery_core_album, $albums_table, $phpbb_container;
691
		global $images_table, $phpbb_gallery_image, $phpbb_ext_gallery_config, $phpbb_dispatcher, $request, $users_table;
692
		global $comments_table, $images_table, $rates_table, $reports_table, $watch_table, $phpbb_ext_gallery_core_auth, $phpbb_ext_gallery_user;
693
694
		$this->language = $phpbb_container->get('language');
695
696
		$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

696
		$s_hidden_fields = /** @scrutinizer ignore-call */ build_hidden_fields(array(
Loading history...
697
			'album_id'		=> $request->variable('album_id', 0),
698
		));
699
700
		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

700
		if (/** @scrutinizer ignore-call */ confirm_box(true))
Loading history...
701
		{
702
			$album_id = $request->variable('album_id', 0);
703
			$left_id = $right_id = 0;
704
			$deleted_images_na = '';
705
			$deleted_albums = array();
706
707
			// Check for owner
708
			$sql = 'SELECT album_id, left_id, right_id, parent_id
709
				FROM ' . $albums_table . '
710
				WHERE album_user_id = ' . (int) $user->data['user_id'] . '
711
				ORDER BY left_id ASC';
712
			$result = $db->sql_query($sql);
713
714
			while ($row = $db->sql_fetchrow($result))
715
			{
716
				$album[] = $row;
717
				if ($row['album_id'] == $album_id)
718
				{
719
					$left_id = $row['left_id'];
720
					$right_id = $row['right_id'];
721
					$parent_id = $row['parent_id'];
722
				}
723
			}
724
			$db->sql_freeresult($result);
725
726
			for ($i = 0, $end = count($album); $i < $end; $i++)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $album does not seem to be defined for all execution paths leading up to this point.
Loading history...
727
			{
728
				if (($left_id <= $album[$i]['left_id']) && ($album[$i]['left_id'] <= $right_id))
729
				{
730
					$deleted_albums[] = $album[$i]['album_id'];
731
				}
732
			}
733
734
			// $deleted_albums is the array of albums we are going to delete.
735
			// Now get the images in $deleted_images
736
			$sql = 'SELECT image_id, image_filename
737
				FROM ' . $images_table . '
738
				WHERE ' . $db->sql_in_set('image_album_id', $deleted_albums) . '
739
				ORDER BY image_id ASC';
740
			$result = $db->sql_query($sql);
741
742
			$deleted_images = $filenames = array();
743
			while ($row = $db->sql_fetchrow($result))
744
			{
745
				$deleted_images[] = $row['image_id'];
746
				$filenames[(int) $row['image_id']] = $row['image_filename'];
747
			}
748
749
			// We have all image_ids in $deleted_images which are deleted.
750
			// Aswell as the album_ids in $deleted_albums.
751
			// So now drop the comments, ratings, images and albums.
752
			if (!empty($deleted_images))
753
			{
754
				$phpbb_gallery_image->delete_images($deleted_images, $filenames);
755
			}
756
757
			$sql = 'DELETE FROM ' . $albums_table . '
758
				WHERE ' . $db->sql_in_set('album_id', $deleted_albums);
759
			$db->sql_query($sql);
760
761
			// Make sure the overall image & comment count is correct...
762
			$sql = 'SELECT COUNT(image_id) AS num_images, SUM(image_comments) AS num_comments
763
				FROM ' . $images_table . '
764
				WHERE image_status <> ' . (int) \phpbbgallery\core\block::STATUS_UNAPPROVED . '
765
					AND image_status <> ' . (int) \phpbbgallery\core\block::STATUS_ORPHAN;
766
			$result = $db->sql_query($sql);
767
			$row = $db->sql_fetchrow($result);
768
			$db->sql_freeresult($result);
769
770
			$phpbb_ext_gallery_config->set('num_images', $row['num_images']);
771
			$phpbb_ext_gallery_config->set('num_comments', (int) $row['num_comments']);
772
773
			$num_images = sizeof($deleted_images);
774
			if ($num_images)
775
			{
776
				// TODO
777
				//$phpbb_gallery_hookup->add_image($user->data['user_id'], 0 - $num_images);
778
				$phpbb_ext_gallery_user->update_images((0 - $num_images));
779
			}
780
781
			// Maybe we deleted all, so we have to empty phpbb_gallery::$user->get_data('personal_album_id')
782
			if (in_array($phpbb_ext_gallery_user->get_data('personal_album_id'), $deleted_albums))
783
			{
784
				$phpbb_ext_gallery_user->update_data(array(
785
					'personal_album_id'		=> 0,
786
				));
787
788
				$phpbb_ext_gallery_config->dec('num_pegas', 1);
789
790
				if ($phpbb_ext_gallery_config->get('newest_pega_album_id') == $phpbb_ext_gallery_user->get_data('personal_album_id'))
791
				{
792
					// Update the config for the statistic on the index
793
					if ($phpbb_ext_gallery_config->get('num_pegas') > 0)
794
					{
795
						$sql_array = array(
796
							'SELECT'		=> 'a.album_id, u.user_id, u.username, u.user_colour',
797
							'FROM'			=> array($albums_table => 'a'),
798
799
							'LEFT_JOIN'		=> array(
800
								array(
801
									'FROM'		=> array(USERS_TABLE => 'u'),
0 ignored issues
show
Bug introduced by
The constant phpbbgallery\core\ucp\USERS_TABLE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
802
									'ON'		=> 'u.user_id = a.album_user_id',
803
								),
804
							),
805
806
							'WHERE'			=> 'a.album_user_id <> ' . (int) \phpbbgallery\core\block::PUBLIC_ALBUM . ' AND a.parent_id = 0',
807
							'ORDER_BY'		=> 'a.album_id DESC',
808
						);
809
						$sql = $db->sql_build_query('SELECT', $sql_array);
810
						$result = $db->sql_query_limit($sql, 1);
811
						$newest_pgallery = $db->sql_fetchrow($result);
812
						$db->sql_freeresult($result);
813
814
						$phpbb_ext_gallery_config->set('newest_pega_user_id', $newest_pgallery['user_id']);
815
						$phpbb_ext_gallery_config->set('newest_pega_username', $newest_pgallery['username']);
816
						$phpbb_ext_gallery_config->set('newest_pega_user_colour', $newest_pgallery['user_colour']);
817
						$phpbb_ext_gallery_config->set('newest_pega_album_id', $newest_pgallery['album_id']);
818
					}
819
					else
820
					{
821
						$phpbb_ext_gallery_config->set('newest_pega_user_id', 0);
822
						$phpbb_ext_gallery_config->set('newest_pega_username', '');
823
						$phpbb_ext_gallery_config->set('newest_pega_user_colour', '');
824
						$phpbb_ext_gallery_config->set('newest_pega_album_id', 0);
825
					}
826
				}
827
			}
828
			else
829
			{
830
				// Solve the left_id right_id problem
831
				$delete_id = $right_id - ($left_id - 1);
832
833
				$sql = 'UPDATE ' . $albums_table . "
834
					SET left_id = left_id - $delete_id
835
					WHERE left_id > $left_id
836
						AND album_user_id = " . (int) $user->data['user_id'];
837
				$db->sql_query($sql);
838
839
				$sql = 'UPDATE ' . $albums_table . "
840
					SET right_id = right_id - $delete_id
841
					WHERE right_id > $right_id
842
						AND album_user_id = ". (int) $user->data['user_id'];
843
				$db->sql_query($sql);
844
			}
845
846
			/**
847
			* Event delete user albums
848
			*
849
			* @event phpbbgallery.core.ucp.delete_album
850
			* @var	int		album_id			Album ID
851
			* @var	array	deleted_albums		Deleted album IDs
852
			* @since 1.2.0
853
			*/
854
			$vars = array('album_id', 'deleted_albums');
855
			extract($phpbb_dispatcher->trigger_event('phpbbgallery.core.ucp.delete_album', compact($vars)));
856
857
			$cache->destroy('sql', $albums_table);
858
			$cache->destroy('sql', $comments_table);
859
			$cache->destroy('sql', $images_table);
860
			$cache->destroy('sql', $rates_table);
861
			$cache->destroy('sql', $reports_table);
862
			$cache->destroy('sql', $watch_table);
863
			$cache->destroy('sql', $users_table);
864
			$cache->destroy('_albums');
865
			$phpbb_ext_gallery_core_auth->set_user_permissions('all', '');
866
867
			trigger_error($this->language->lang('DELETED_ALBUMS') . '<br /><br />
868
				<a href="' . (($parent_id) ? $phpbb_gallery_url->append_sid('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&amp;mode=manage_albums&amp;action=manage&amp;parent_id=' . $parent_id) : $phpbb_gallery_url->append_sid('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&amp;mode=manage_albums')) . '">' . $this->language->lang('BACK_TO_PREV') . '</a>');
869
		}
870
		else
871
		{
872
			$album_id = $request->variable('album_id', 0);
873
			$phpbb_ext_gallery_core_album->check_user($album_id);
874
			confirm_box(false, 'DELETE_ALBUM', $s_hidden_fields);
875
		}
876
	}
877
878
	function move_album()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
879
	{
880
		global $cache, $db, $user, $phpbb_ext_gallery_core_album, $albums_table, $request, $phpbb_gallery_url, $users_table;
881
882
		$album_id = $request->variable('album_id', 0);
883
		$phpbb_ext_gallery_core_album->check_user($album_id);
884
885
		$move = $request->variable('move', '', true);
886
		$moving = $phpbb_ext_gallery_core_album->get_info($album_id);
887
888
		$sql = 'SELECT album_id, left_id, right_id
889
			FROM ' . $albums_table . "
890
			WHERE parent_id = {$moving['parent_id']}
891
				AND album_user_id = {$user->data['user_id']}
892
				AND " . (($move == 'move_up') ? "right_id < {$moving['right_id']} ORDER BY right_id DESC" : "left_id > {$moving['left_id']} ORDER BY left_id ASC");
893
		$result = $db->sql_query_limit($sql, 1);
894
		$target = $db->sql_fetchrow($result);
895
		$db->sql_freeresult($result);
896
897
		if (!sizeof($target))
898
		{
899
			// The album is already on top or bottom
900
			return false;
901
		}
902
903
		if ($move == 'move_up')
904
		{
905
			$left_id = $target['left_id'];
906
			$right_id = $moving['right_id'];
907
908
			$diff_up = $moving['left_id'] - $target['left_id'];
909
			$diff_down = $moving['right_id'] + 1 - $moving['left_id'];
910
911
			$move_up_left = $moving['left_id'];
912
			$move_up_right = $moving['right_id'];
913
		}
914
		else
915
		{
916
			$left_id = $moving['left_id'];
917
			$right_id = $target['right_id'];
918
919
			$diff_up = $moving['right_id'] + 1 - $moving['left_id'];
920
			$diff_down = $target['right_id'] - $moving['right_id'];
921
922
			$move_up_left = $moving['right_id'] + 1;
923
			$move_up_right = $target['right_id'];
924
		}
925
926
		// Now do the dirty job
927
		$sql = 'UPDATE ' . $albums_table . "
928
			SET left_id = left_id + CASE
929
				WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
930
				ELSE {$diff_down}
931
			END,
932
			right_id = right_id + CASE
933
				WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
934
				ELSE {$diff_down}
935
			END,
936
			album_parents = ''
937
			WHERE
938
				left_id BETWEEN {$left_id} AND {$right_id}
939
				AND right_id BETWEEN {$left_id} AND {$right_id}
940
				AND album_user_id = {$user->data['user_id']}";
941
		$db->sql_query($sql);
942
943
		$cache->destroy('sql', $albums_table);
944
		$cache->destroy('sql', $users_table);
945
		$cache->destroy('_albums');
946
		$phpbb_gallery_url->redirect('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&amp;mode=manage_albums&amp;action=manage&amp;parent_id=' . $moving['parent_id']);
947
	}
948
949
	function manage_subscriptions()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
950
	{
951
		global $db, $template, $user, $phpbb_container, $phpbb_ext_gallery_core_album, $phpbb_gallery_notification, $watch_table, $albums_table, $contests_table;
952
		global $images_table, $comments_table, $request, $phpbb_gallery_url, $phpbb_ext_gallery_core_auth;
953
954
		$phpbb_ext_gallery_core_image = $phpbb_container->get('phpbbgallery.core.image');
955
		$phpbb_ext_gallery_config = $phpbb_container->get('phpbbgallery.core.config');
956
		$phpbb_gallery_notification = $phpbb_container->get('phpbbgallery.core.notification');
957
		$this->language = $phpbb_container->get('language');
958
959
		$action = $request->variable('action', '');
960
		$image_id_ary = $request->variable('image_id_ary', array(0));
961
		$album_id_ary = $request->variable('album_id_ary', array(0));
962
		if (($image_id_ary || $album_id_ary) && ($action == 'unsubscribe'))
963
		{
964
			if ($album_id_ary)
965
			{
966
				$phpbb_gallery_notification->remove_albums($album_id_ary);
967
			}
968
			if ($image_id_ary)
969
			{
970
				$phpbb_gallery_notification->remove($image_id_ary);
971
			}
972
973
			meta_refresh(3, $this->u_action);
0 ignored issues
show
Bug introduced by
The function meta_refresh 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

973
			/** @scrutinizer ignore-call */ 
974
   meta_refresh(3, $this->u_action);
Loading history...
974
			$message = '';
975
			if ($album_id_ary)
976
			{
977
				$message .= $this->language->lang('UNWATCHED_ALBUMS') . '<br />';
978
			}
979
			if ($image_id_ary)
980
			{
981
				$message .= $this->language->lang('UNWATCHED_IMAGES') . '<br />';
982
			}
983
			$message .= '<br />' . sprintf($this->language->lang('RETURN_UCP'), '<a href="' . $this->u_action . '">', '</a>');
984
			trigger_error($message);
985
		}
986
987
		// Subscribed albums
988
		$sql_array = array(
989
			'SELECT'		=> '*',
990
			'FROM'			=> array($watch_table => 'w'),
991
992
			'LEFT_JOIN'		=> array(
993
				array(
994
					'FROM'		=> array($albums_table => 'a'),
995
					'ON'		=> 'w.album_id = a.album_id',
996
				),
997
				array(
998
					'FROM'		=> array($contests_table => 'c'),
999
					'ON'		=> 'a.album_id = c.contest_album_id',
1000
				),
1001
			),
1002
1003
			'WHERE'			=> 'w.album_id <> 0 AND w.user_id = ' . (int) $user->data['user_id'],
1004
		);
1005
		$sql = $db->sql_build_query('SELECT', $sql_array);
1006
		$result = $db->sql_query($sql);
1007
		while ($row = $db->sql_fetchrow($result))
1008
		{
1009
			$template->assign_block_vars('album_row', array(
1010
				'ALBUM_ID'			=> $row['album_id'],
1011
				'ALBUM_NAME'		=> $row['album_name'],
1012
				'U_VIEW_ALBUM'		=> $phpbb_gallery_url->show_album($row['album_id']),
1013
				'ALBUM_DESC'		=> generate_text_for_display($row['album_desc'], $row['album_desc_uid'], $row['album_desc_bitfield'], $row['album_desc_options']),
0 ignored issues
show
Bug introduced by
The function generate_text_for_display 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

1013
				'ALBUM_DESC'		=> /** @scrutinizer ignore-call */ generate_text_for_display($row['album_desc'], $row['album_desc_uid'], $row['album_desc_bitfield'], $row['album_desc_options']),
Loading history...
1014
1015
				'UC_IMAGE_NAME'		=> $phpbb_ext_gallery_core_image->generate_link('image_name', $phpbb_ext_gallery_config->get('link_image_name'), $row['album_last_image_id'], $row['album_last_image_name'], $row['album_id']),
1016
				'UC_FAKE_THUMBNAIL'	=> $phpbb_ext_gallery_core_image->generate_link('fake_thumbnail', $phpbb_ext_gallery_config->get('link_thumbnail'), $row['album_last_image_id'], $row['album_last_image_name'], $row['album_id']),
1017
				'UPLOADER'			=> (($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) && ($row['contest_marked'] && !$phpbb_ext_gallery_core_auth->acl_check('m_status', $row['album_id'], $row['album_user_id']))) ? $this->language->lang('CONTEST_USERNAME') : get_username_string('full', $row['album_last_user_id'], $row['album_last_username'], $row['album_last_user_colour']),
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

1017
				'UPLOADER'			=> (($row['album_type'] == (int) \phpbbgallery\core\block::TYPE_CONTEST) && ($row['contest_marked'] && !$phpbb_ext_gallery_core_auth->acl_check('m_status', $row['album_id'], $row['album_user_id']))) ? $this->language->lang('CONTEST_USERNAME') : /** @scrutinizer ignore-call */ get_username_string('full', $row['album_last_user_id'], $row['album_last_username'], $row['album_last_user_colour']),
Loading history...
1018
				'LAST_IMAGE_TIME'	=> $user->format_date($row['album_last_image_time']),
1019
				'LAST_IMAGE'		=> $row['album_last_image_id'],
1020
				'U_IMAGE'			=> $phpbb_gallery_url->show_image($row['image_id']),
1021
			));
1022
		}
1023
		$db->sql_freeresult($result);
1024
1025
		// Subscribed images
1026
		$start				= $request->variable('start', 0);
1027
		$images_per_page	= $phpbb_ext_gallery_config->get('items_per_page');
1028
		$total_images		= 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $total_images is dead and can be removed.
Loading history...
1029
1030
		$sql = 'SELECT COUNT(image_id) as images
1031
			FROM ' . $watch_table . '
1032
			WHERE image_id <> 0
1033
				AND user_id = ' . (int) $user->data['user_id'];
1034
		$result = $db->sql_query($sql);
1035
		$total_images = (int) $db->sql_fetchfield('images');
1036
		$db->sql_freeresult($result);
1037
1038
		$sql_array = array(
1039
			'SELECT'		=> 'w.*, i.*, a.album_name, c.*',
1040
			'FROM'			=> array($watch_table => 'w'),
1041
1042
			'LEFT_JOIN'		=> array(
1043
				array(
1044
					'FROM'		=> array($images_table => 'i'),
1045
					'ON'		=> 'w.image_id = i.image_id',
1046
				),
1047
				array(
1048
					'FROM'		=> array($albums_table => 'a'),
1049
					'ON'		=> 'a.album_id = i.image_album_id',
1050
				),
1051
				array(
1052
					'FROM'		=> array($comments_table => 'c'),
1053
					'ON'		=> 'i.image_last_comment = c.comment_id',
1054
				),
1055
			),
1056
1057
			'WHERE'			=> 'w.image_id <> 0 AND w.user_id = ' . (int) $user->data['user_id'],
1058
		);
1059
		$sql = $db->sql_build_query('SELECT', $sql_array);
1060
		$result = $db->sql_query($sql, $images_per_page, $start);
1061
		while ($row = $db->sql_fetchrow($result))
1062
		{
1063
			$template->assign_block_vars('image_row', array(
1064
				'UPLOADER'			=> ($row['image_contest'] && !$phpbb_ext_gallery_core_auth->acl_check('m_status', $row['image_album_id'])) ? $this->language->lang('CONTEST_USERNAME') : get_username_string('full', $row['image_user_id'], $row['image_username'], $row['image_user_colour']),
1065
				'LAST_COMMENT_BY'	=> get_username_string('full', $row['comment_user_id'], $row['comment_username'], $row['comment_user_colour']),
1066
				'COMMENT'			=> $row['image_comments'],
1067
				'LAST_COMMENT_TIME'	=> $user->format_date($row['comment_time']),
1068
				'IMAGE_TIME'		=> $user->format_date($row['image_time']),
1069
				'UC_IMAGE_NAME'		=> $phpbb_ext_gallery_core_image->generate_link('image_name', $phpbb_ext_gallery_config->get('link_image_name'), $row['image_id'], $row['image_name'], $row['album_id']),
1070
				'UC_FAKE_THUMBNAIL'	=> $phpbb_ext_gallery_core_image->generate_link('fake_thumbnail', $phpbb_ext_gallery_config->get('link_thumbnail'), $row['image_id'], $row['image_name'], $row['album_id']),
1071
				'ALBUM_NAME'		=> $row['album_name'],
1072
				'IMAGE_ID'			=> $row['image_id'],
1073
				'U_VIEW_ALBUM'		=> $phpbb_gallery_url->show_album($row['image_album_id']),
1074
				'U_IMAGE'			=> $phpbb_gallery_url->show_image($row['image_id']),
1075
			));
1076
		}
1077
		$db->sql_freeresult($result);
1078
1079
		$template->assign_vars(array(
1080
			'S_MANAGE_SUBSCRIPTIONS'	=> true,
1081
			'S_UCP_ACTION'				=> $this->u_action,
1082
1083
			'L_TITLE'					=> $this->language->lang('UCP_GALLERY_WATCH'),
1084
			'L_TITLE_EXPLAIN'			=> $this->language->lang('YOUR_SUBSCRIPTIONS'),
1085
1086
			//'PAGINATION'				=> generate_pagination($phpbb_ext_gallery->url->append_sid('phpbb', 'ucp', 'i=-phpbbgallery-core-ucp-main_module&amp;mode=manage_subscriptions'), $total_images, $images_per_page, $start),
1087
			//'PAGE_NUMBER'				=> on_page($total_images, $images_per_page, $start),
1088
			//'TOTAL_IMAGES'				=> $user->lang('VIEW_ALBUM_IMAGES', $total_images),
1089
1090
			'DISP_FAKE_THUMB'			=> true,
1091
			'FAKE_THUMB_SIZE'			=> $phpbb_ext_gallery_config->get('mini_thumbnail_size'),
1092
		));
1093
	}
1094
1095
	function subscribe_pegas($album_id)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1096
	{
1097
		global $db, $users_table, $phpbb_container;
1098
		$phpbb_gallery_notification = $phpbb_container->get('phpbbgallery.core.notification');
1099
1100
		$sql = 'SELECT user_id
1101
			FROM ' . $users_table . '
1102
			WHERE subscribe_pegas = 1';
1103
		$result = $db->sql_query($sql);
1104
1105
		while ($row = $db->sql_fetchrow($result))
1106
		{
1107
			$phpbb_gallery_notification->add_albums($album_id, (int) $row['user_id']);
1108
		}
1109
		$db->sql_freeresult($result);
1110
	}
1111
}
1112