Completed
Push — 3.2.x ( d8070d...5ec8e2 )
by Erwan
03:06
created

links::edit_link()   C

Complexity

Conditions 12
Paths 84

Size

Total Lines 72
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
dl 0
loc 72
rs 5.519
c 3
b 0
f 0
cc 12
eloc 44
nc 84
nop 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
*
4
* phpBB Directory extension for the phpBB Forum Software package.
5
*
6
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com>
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace ernadoo\phpbbdirectory\controller;
12
13
use Symfony\Component\HttpFoundation\BinaryFileResponse;
14
use Symfony\Component\HttpFoundation\Response;
15
16
class links
17
{
18
	private $link_user_id;
19
	private $site_name;
20
	private $url;
21
	private $description;
22
	private $guest_email;
23
	private $rss;
24
	private $banner;
25
	private $back;
26
	private $flag;
27
28
	private $captcha;
29
	private $s_hidden_fields = array();
30
31
	/** @var \phpbb\db\driver\driver_interface */
32
	protected $db;
33
34
	/** @var \phpbb\config\config */
35
	protected $config;
36
37
	/** @var \phpbb\language\language */
38
	protected $language;
39
40
	/** @var \phpbb\template\template */
41
	protected $template;
42
43
	/** @var \phpbb\user */
44
	protected $user;
45
46
	/** @var \phpbb\controller\helper */
47
	protected $helper;
48
49
	/** @var \phpbb\request\request */
50
	protected $request;
51
52
	/** @var \phpbb\auth\auth */
53
	protected $auth;
54
55
	/** @var \phpbb\captcha\factory */
56
	protected $captcha_factory;
57
58
	/** @var \ernadoo\phpbbdirectory\core\categorie */
59
	protected $categorie;
60
61
	/** @var \ernadoo\phpbbdirectory\core\link */
62
	protected $link;
63
64
	/** @var \ernadoo\phpbbdirectory\core\helper */
65
	protected $dir_helper;
66
67
	/** @var string phpBB root path */
68
	protected $root_path;
69
70
	/** @var string phpEx */
71
	protected $php_ext;
72
73
	/**
74
	* Constructor
75
	*
76
	* @param \phpbb\db\driver\driver_interface 		$db					Database object
77
	* @param \phpbb\config\config					$config				Config object
78
	* @param \phpbb\language\language				$language			Language object
79
	* @param \phpbb\template\template				$template			Template object
80
	* @param \phpbb\user							$user				User object
81
	* @param \phpbb\controller\helper				$helper				Controller helper object
82
	* @param \phpbb\request\request					$request			Request object
83
	* @param \phpbb\auth\auth						$auth				Auth object
84
	* @param \phpbb\captcha\factory					$captcha_factory	Captcha object
85
	* @param \ernadoo\phpbbdirectory\core\categorie	$categorie			PhpBB Directory extension categorie object
86
	* @param \ernadoo\phpbbdirectory\core\link		$link				PhpBB Directory extension link object
87
	* @param \ernadoo\phpbbdirectory\core\helper	$dir_helper			PhpBB Directory extension helper object
88
	* @param string									$root_path			phpBB root path
89
	* @param string									$php_ext   			phpEx
90
	*/
91
	public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\language\language $language, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, \phpbb\request\request $request, \phpbb\auth\auth $auth, \phpbb\captcha\factory $captcha_factory, \ernadoo\phpbbdirectory\core\categorie $categorie, \ernadoo\phpbbdirectory\core\link $link, \ernadoo\phpbbdirectory\core\helper $dir_helper, $root_path, $php_ext)
92
	{
93
		$this->db				= $db;
94
		$this->config			= $config;
95
		$this->language			= $language;
96
		$this->template			= $template;
97
		$this->user				= $user;
98
		$this->helper			= $helper;
99
		$this->request			= $request;
100
		$this->auth				= $auth;
101
		$this->captcha_factory 	= $captcha_factory;
102
		$this->categorie		= $categorie;
103
		$this->link				= $link;
104
		$this->dir_helper		= $dir_helper;
105
		$this->root_path		= $root_path;
106
		$this->php_ext			= $php_ext;
107
108
		$language->add_lang('directory', 'ernadoo/phpbbdirectory');
109
110
		$template->assign_vars(array(
111
			'S_PHPBB_DIRECTORY'	=> true,
112
		));
113
	}
114
115
	/**
116
	* Delete a link
117
	*
118
	* @param	int	$cat_id		The category ID
119
	* @param	int	$link_id		The link ID
120
	* @return	null|\Symfony\Component\HttpFoundation\Response	A Symfony Response object
121
	*/
122
	public function delete_link($cat_id, $link_id)
123
	{
124
		if ($this->request->is_set_post('cancel'))
125
		{
126
			$redirect = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id));
127
			redirect($redirect);
128
		}
129
130
		$sql = 'SELECT link_user_id
131
			FROM ' . DIR_LINK_TABLE . '
132
			WHERE link_id = ' . (int) $link_id;
133
		$result = $this->db->sql_query($sql);
134
		$link_data = $this->db->sql_fetchrow($result);
135
136
		if (empty($link_data))
137
		{
138
			throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
139
		}
140
141
		$delete_allowed = $this->user->data['is_registered'] && ($this->auth->acl_get('m_delete_dir') || ($this->user->data['user_id'] == $link_data['link_user_id'] && $this->auth->acl_get('u_delete_dir')));
142
143
		if (!$delete_allowed)
144
		{
145
			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
146
		}
147
148
		if (confirm_box(true))
149
		{
150
			$this->link->del($cat_id, $link_id);
151
152
			$meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id));
153
			meta_refresh(3, $meta_info);
154
			$message = $this->language->lang('DIR_DELETE_OK') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_DIR', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_base_controller') . '">', '</a>') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id)) . '">', '</a>');
155
			return $this->helper->message($message);
156
		}
157
		else
158
		{
159
			confirm_box(false, 'DIR_DELETE_SITE');
160
		}
161
	}
162
163
	/**
164
	* Edit a link
165
	*
166
	* @param	int	$cat_id		The category ID
167
	* @param	int	$link_id	The link ID
168
	* @return	null|\Symfony\Component\HttpFoundation\Response	A Symfony Response object
169
	* @throws	\phpbb\exception\http_exception
170
	*/
171
	public function edit_link($cat_id, $link_id)
172
	{
173
		$sql = 'SELECT link_user_id
174
			FROM ' . DIR_LINK_TABLE . '
175
			WHERE link_id = ' . (int) $link_id;
176
		$result = $this->db->sql_query($sql);
177
		$link_data = $this->db->sql_fetchrow($result);
178
		$this->link_user_id = (int) $link_data['link_user_id'];
179
180
		$edit_allowed = ($this->user->data['is_registered'] && ($this->auth->acl_get('m_edit_dir') || ($this->user->data['user_id'] == (int) $link_data['link_user_id'] && $this->auth->acl_get('u_edit_dir'))));
181
182
		if (!$edit_allowed)
183
		{
184
			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
185
		}
186
187
		$cat_id		= $this->request->variable('id', $cat_id);
188
		$submit		= $this->request->is_set_post('submit') ? true : false;
189
		$refresh	= $this->request->is_set_post('refresh_vc') ? true : false;
190
		$title		= $this->language->lang('DIR_EDIT_SITE');
191
192
		$this->template->assign_block_vars('dir_navlinks', array(
193
			'FORUM_NAME'	=> $title,
194
			'U_VIEW_FORUM'	=> $this->helper->route('ernadoo_phpbbdirectory_edit_controller', array('cat_id' => (int) $cat_id, 'link_id' => $link_id))
195
		));
196
197
		$this->categorie->get($cat_id);
198
199
		// If form is done
200
		if ($submit || $refresh)
201
		{
202
			if (false != ($result = $this->_data_processing($cat_id, $link_id, 'edit')))
203
			{
204
				return $result;
205
			}
206
		}
207
		else
208
		{
209
			$sql = 'SELECT link_id, link_uid, link_flags, link_bitfield, link_cat, link_url, link_description, link_guest_email, link_name, link_rss, link_back, link_banner, link_flag, link_cat, link_time
210
				FROM ' . DIR_LINK_TABLE . '
211
				WHERE link_id = ' . (int) $link_id;
212
			$result = $this->db->sql_query($sql);
213
214
			$site = $this->db->sql_fetchrow($result);
215
216
			if (empty($site['link_id']))
217
			{
218
				throw new \phpbb\exception\http_exception(404, 'DIR_ERROR_NO_LINKS');
219
			}
220
221
			$this->s_hidden_fields = array(
222
				'old_cat_id'	=> $site['link_cat'],
223
				'old_banner'	=> $site['link_banner'],
224
			);
225
226
			$site_description		= generate_text_for_edit($site['link_description'], $site['link_uid'], $site['link_flags']);
227
			$site['link_banner'] 	= (preg_match('/^(http:\/\/|https:\/\/|ftp:\/\/|ftps:\/\/|www\.).+/si', $site['link_banner'])) ? $site['link_banner'] : '';
228
229
			$this->url			= $site['link_url'];
230
			$this->site_name	= $site['link_name'];
231
			$this->description	= $site_description['text'];
232
			$this->guest_email	= $site['link_guest_email'];
233
			$this->rss			= $site['link_rss'];
234
			$this->banner 		= $site['link_banner'];
235
			$this->back			= $site['link_back'];
236
			$this->flag 		= $site['link_flag'];
237
		}
238
239
		$this->_populate_form($cat_id, 'edit', $title);
240
241
		return $this->helper->render('add_site.html', $title);
242
	}
243
244
	/**
245
	* Display add form
246
	*
247
	* @param	int	$cat_id		The category ID
248
	* @return	\Symfony\Component\HttpFoundation\Response	A Symfony Response object
249
	* @throws	\phpbb\exception\http_exception
250
	*/
251
	public function new_link($cat_id)
252
	{
253
		if (!$this->auth->acl_get('u_submit_dir'))
254
		{
255
			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
256
		}
257
258
		$cat_id		= $this->request->variable('id', $cat_id);
259
		$submit		= $this->request->is_set_post('submit') ? true : false;
260
		$refresh	= $this->request->is_set_post('refresh_vc') ? true : false;
261
		$title		= $this->language->lang('DIR_NEW_SITE');
262
263
		$this->template->assign_block_vars('dir_navlinks', array(
264
			'FORUM_NAME'	=> $title,
265
			'U_VIEW_FORUM'	=> $this->helper->route('ernadoo_phpbbdirectory_new_controller', array('cat_id' => (int) $cat_id))
266
		));
267
268
		$this->categorie->get($cat_id);
269
270
		// The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
271 View Code Duplication
		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'])
272
		{
273
			$this->captcha = $this->captcha_factory->get_instance($this->config['captcha_plugin']);
274
			$this->captcha->init(CONFIRM_POST);
275
		}
276
277
		// If form is done
278
		if ($submit || $refresh)
279
		{
280
			if (false != ($result = $this->_data_processing($cat_id)))
281
			{
282
				return $result;
283
			}
284
		}
285
286
		$this->_populate_form($cat_id, 'new', $title);
287
288
		return $this->helper->render('add_site.html', $title);
289
	}
290
291
	/**
292
	* View link controller
293
	*
294
	* @param	int	$link_id		The link ID
295
	* @return	\Symfony\Component\HttpFoundation\Response	A Symfony Response object
296
	*/
297
	public function view_link($link_id)
298
	{
299
		return $this->link->view($link_id);
300
	}
301
302
	/**
303
	* Vote for a link
304
	*
305
	* @param	int $cat_id		The category ID
306
	* @param	int $link_id	The link ID
307
	* @return	\Symfony\Component\HttpFoundation\Response	A Symfony Response object
308
	*/
309
	public function vote_link($cat_id, $link_id)
310
	{
311
		$this->categorie->get($cat_id);
312
313
		if (!$this->auth->acl_get('u_vote_dir') || !$this->categorie->data['cat_allow_votes'])
314
		{
315
			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
316
		}
317
318
		$data = array(
319
			'vote_link_id' 		=> (int) $link_id,
320
			'vote_user_id' 		=> (int) $this->user->data['user_id'],
321
		);
322
323
		// We check if user had already vot for this website.
324
		$sql = 'SELECT vote_link_id
325
			FROM ' . DIR_VOTE_TABLE . '
326
			WHERE ' . $this->db->sql_build_array('SELECT', $data);
327
		$result = $this->db->sql_query($sql);
328
		$data = $this->db->sql_fetchrow($result);
329
330
		if (!empty($data['vote_link_id']))
331
		{
332
			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_VOTE');
333
		}
334
335
		$this->link->add_vote($link_id);
336
337
		$meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id));
338
		meta_refresh(3, $meta_info);
339
		$message = $this->language->lang('DIR_VOTE_OK') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $meta_info . '">', '</a>');
340
		return $this->helper->message($message);
341
	}
342
343
	/**
344
	* Routine
345
	*
346
	* @param	int		$cat_id		The category ID
347
	* @param	int		$link_id	The link ID
348
	* @param	string	$mode		add|edit
349
	* @return	null|\Symfony\Component\HttpFoundation\Response	A Symfony Response object
350
	* @throws	\phpbb\exception\http_exception
351
	*/
352
	private function _data_processing($cat_id, $link_id = 0, $mode = 'new')
353
	{
354
		if (($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir')) || ($mode == 'new' && !$this->auth->acl_get('u_submit_dir')))
355
		{
356
			throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
357
		}
358
359
		if (!check_form_key('dir_form'))
360
		{
361
			return $this->helper->message('FORM_INVALID');
362
		}
363
364
		$this->url			= $this->request->variable('url', '');
365
		$this->site_name	= $this->request->variable('site_name', '', true);
366
		$this->description	= $this->request->variable('description', '', true);
367
		$this->guest_email	= $this->request->variable('guest_email', '');
368
		$this->rss			= $this->request->variable('rss', '');
369
		$this->banner 		= $this->request->variable('banner', '');
370
		$this->back			= $this->request->variable('back', '');
371
		$this->flag 		= $this->request->variable('flag', '');
372
373
		if (!function_exists('validate_data'))
374
		{
375
			include($this->root_path . 'includes/functions_user.' . $this->php_ext);
376
		}
377
378
		// We define variables to check
379
		$data = array(
380
			'email'			=> $this->guest_email,
381
			'site_name'		=> $this->site_name,
382
			'website'		=> $this->url,
383
			'description'	=> $this->description,
384
			'rss'			=> $this->rss,
385
			'banner'		=> $this->banner,
386
			'back'			=> $this->back,
387
			'cat'			=> (int) $cat_id,
388
		);
389
390
		// We define verification type for each variable
391
		$data2 = array(
392
			'email'			=>		array(
393
				array('string', $this->user->data['is_registered'], 6, 60),
394
				array('user_email', '')),
395
			'site_name' =>			array(
396
				array('string', false, 1, 100)),
397
			'website'		=>		array(
398
				array('string',	false, 12, 255),
399
				array('match',	true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
400
			'description'	=>		array(
401
				array('string', !$this->categorie->data['cat_must_describe'], 1, $this->config['dir_length_describe'])),
402
			'rss'			=>		array(
403
				array('string', true, 12, 255),
404
				array('match',	empty($this->rss), '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
405
			'banner'		=>		array(
406
				array('string', true, 5, 255)),
407
			'back'			=>		array(
408
				array('string',	!$this->categorie->data['cat_link_back'], 12, 255),
409
				array(array($this->link, 'link_back'), true)),
410
			'cat'			=>		array(
411
				array('num', '', 1))
412
		);
413
414
		$this->user->add_lang('ucp');
415
		$error = validate_data($data, $data2);
416
		$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->language->lang('\\1'))) ? \$this->language->lang('\\1') : '\\1'", $error);
417
418
		// We check that url have good format
419
		if (preg_match('/^(http|https):\/\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url))
420
		{
421
			$error[] = $this->language->lang('DIR_ERROR_CHECK_URL');
422
		}
423
424 View Code Duplication
		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'])
425
		{
426
			$vc_response = $this->captcha->validate($data);
427
			if ($vc_response !== false)
428
			{
429
				$error[] = $vc_response;
430
			}
431
432
			if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts'])
433
			{
434
				$error[] = $this->language->lang('TOO_MANY_ADDS');
435
			}
436
		}
437
438
		if (!$error)
439
		{
440
			/**
441
			* No errrors, we execute heavy tasks wich need a valid url
442
			*/
443
444
			// Banner
445
			$this->link->banner_process($this->banner, $error);
446
447
			// PageRank
448
			$pagerank = $this->link->pagerank_process($this->url);
449
450
			// Thumb ;)
451
			$thumb = $this->link->thumb_process($this->url);
452
		}
453
454
		// Still no errors?? So let's go!
455
		if (!$error)
456
		{
457
			$uid = $bitfield = $flags = '';
458
			generate_text_for_storage($this->description, $uid, $bitfield, $flags, (bool) $this->config['allow_bbcode'], (bool) $this->config['allow_post_links'], (bool) $this->config['allow_smilies'], (bool) $this->config['allow_bbcode'], ($this->config['allow_bbcode'] && $this->config['allow_post_flash']), true, (bool) $this->config['allow_post_links']);
459
460
			$this->banner	= (!$this->banner && !$this->request->is_set_post('delete_banner')) ? $this->request->variable('old_banner', '') : $this->banner;
461
			$this->url		= $this->link->clean_url($this->url);
462
463
			$data_edit = array(
464
				'link_user_id'		=> $this->link_user_id,
465
				'link_guest_email'	=> $this->guest_email,
466
				'link_name'			=> $this->site_name,
467
				'link_url'			=> $this->url,
468
				'link_description'	=> $this->description,
469
				'link_cat'			=> (int) $cat_id,
470
				'link_rss'			=> $this->rss,
471
				'link_banner'		=> $this->banner,
472
				'link_back'			=> $this->back,
473
				'link_uid'			=> $uid,
474
				'link_flags'		=> $flags,
475
				'link_flag'			=> $this->flag,
476
				'link_bitfield'		=> $bitfield,
477
				'link_pagerank'		=> (int) $pagerank,
478
				'link_thumb'		=> $thumb,
479
			);
480
481
			$need_approval = ($this->categorie->need_approval() && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_')) ? true : false;
482
483
			if ($mode == 'edit')
484
			{
485
				$data_edit['link_cat_old'] = $this->request->variable('old_cat_id', 0);
486
				$this->link->edit($data_edit, $link_id, $need_approval);
487
			}
488
			else
489
			{
490
				$data_add = array(
491
					'link_time'			=> time(),
492
					'link_view'			=> 0,
493
					'link_active'		=> $need_approval ? false : true,
494
					'link_user_id'		=> $this->user->data['user_id'],
495
				);
496
497
				$data_add = array_merge($data_edit, $data_add);
498
499
				$this->link->add($data_add, $need_approval);
500
			}
501
502
			$meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id));
503
			meta_refresh(3, $meta_info);
504
			$message	= ($need_approval) ? $this->language->lang('DIR_'.strtoupper($mode).'_SITE_ACTIVE') : $this->language->lang('DIR_'.strtoupper($mode).'_SITE_OK');
505
			$message	= $message . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_DIR', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_base_controller') . '">', '</a>') . '<br /><br />' . $this->language->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id)) . '">', '</a>');
506
			return $this->helper->message($message);
507
		}
508
		else
509
		{
510
			if ($mode == 'edit')
511
			{
512
				$this->s_hidden_fields = array(
513
					'old_cat_id'	=> $this->request->variable('old_cat_id', 0),
514
					'old_banner'	=> $this->request->variable('old_banner', '')
515
				);
516
			}
517
518
			$this->template->assign_vars(array(
519
				'ERROR'	=> (isset($error)) ? implode('<br />', $error) : ''
520
			));
521
		}
522
	}
523
524
	/**
525
	* Display a banner
526
	*
527
	* @param	string $banner_img		Path to banner file
528
	* @return	Response object
529
	*/
530
	public function return_banner($banner_img)
531
	{
532
		if (!function_exists('file_gc'))
533
		{
534
			include($this->root_path . 'includes/functions_download.' . $this->php_ext);
535
		}
536
537
		$file_path = $this->dir_helper->get_banner_path($banner_img);
538
539
		if ((@file_exists($file_path) && @is_readable($file_path)))
540
		{
541
			$response = new BinaryFileResponse($file_path);
542
			$response->setContentDisposition('inline', $banner_img);
543
544
			// Without fileinfo extension, Symfony is unable to guess the mime type
545
			if (!extension_loaded('fileinfo'))
546
			{
547
				$imagesize = new \FastImageSize\FastImageSize();
548
				$image_data = $imagesize->getImageSize($file_path);
549
				$response->headers->set('Content-Type', image_type_to_mime_type($image_data['type']));
550
			}
551
		}
552
		else
553
		{
554
			$response = new Response();
555
			$response->setStatusCode(404);
556
		}
557
		file_gc(false);
558
559
		return $response;
560
	}
561
562
	/**
563
	* Populate form when an error occurred
564
	*
565
	* @param	int		$cat_id		The category ID
566
	* @param	string	$mode		add|edit
567
	* @param	string	$title		Page title (depends of $mode)
568
	* @return	null
569
	*/
570
	private function _populate_form($cat_id, $mode, $title)
571
	{
572
		global $phpbb_extension_manager;
573
574 View Code Duplication
		if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode == 'new')
575
		{
576
			$this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
577
578
			$this->user->add_lang('ucp');
579
580
			$this->template->assign_vars(array(
581
				'CAPTCHA_TEMPLATE'		=> $this->captcha->get_template(),
582
			));
583
		}
584
585
		$this->user->add_lang('posting');
586
587
		if (!function_exists('display_custom_bbcodes'))
588
		{
589
			include($this->root_path . 'includes/functions_display.' . $this->php_ext);
590
		}
591
		display_custom_bbcodes();
592
		add_form_key('dir_form');
593
594
		$ext_path = $phpbb_extension_manager->get_extension_path('ernadoo/phpbbdirectory', false);
595
		$flag_path = $ext_path.'images/flags/';
596
597
		$s_guest	= (!$this->user->data['is_registered'] || !empty($this->guest_email));
598
		$s_rss		= $this->config['dir_activ_rss'];
599
		$s_banner	= $this->config['dir_activ_banner'];
600
		$s_back		= $this->categorie->data['cat_link_back'];
601
		$s_flag		= $this->config['dir_activ_flag'];
602
603
		$this->template->assign_vars(array(
604
			'BBCODE_STATUS'			=> ($this->config['allow_bbcode']) 	? $this->language->lang('BBCODE_IS_ON', '<a href="' . append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode') . '">', '</a>') : $this->language->lang('BBCODE_IS_OFF', '<a href="' . append_sid($this->root_path."faq.$this->php_ext", 'mode=bbcode') . '">', '</a>'),
605
			'IMG_STATUS'			=> ($this->config['allow_bbcode'])	? $this->language->lang('IMAGES_ARE_ON') : $this->language->lang('IMAGES_ARE_OFF'),
606
			'SMILIES_STATUS'		=> ($this->config['allow_smilies']) ? $this->language->lang('SMILIES_ARE_ON') : $this->language->lang('SMILIES_ARE_OFF'),
607
			'URL_STATUS'			=> ($this->config['allow_post_links']) ? $this->language->lang('URL_IS_ON') : $this->language->lang('URL_IS_OFF'),
608
			'FLASH_STATUS'			=> ($this->config['allow_bbcode'] && $this->config['allow_post_flash'])	? $this->language->lang('FLASH_IS_ON') : $this->language->lang('FLASH_IS_OFF'),
609
610
			'L_TITLE'				=> $title,
611
			'L_DIR_DESCRIPTION_EXP'	=> $this->language->lang('DIR_DESCRIPTION_EXP', $this->config['dir_length_describe']),
612
			'L_DIR_SUBMIT_TYPE'		=> $this->categorie->dir_submit_type($this->categorie->need_approval()),
613
			'L_DIR_SITE_BANN_EXP'	=> $this->language->lang('DIR_SITE_BANN_EXP', $this->config['dir_banner_width'], $this->config['dir_banner_height']),
614
615
			'S_GUEST'				=> $s_guest ? true : false,
616
			'S_RSS'					=> $s_rss ? true : false,
617
			'S_BANNER'				=> $s_banner ? true : false,
618
			'S_BACK'				=> $s_back ? true : false,
619
			'S_FLAG'				=> $s_flag ? true : false,
620
			'S_BBCODE_ALLOWED' 		=> (bool) $this->config['allow_bbcode'],
621
			'S_BBCODE_IMG'			=> (bool) $this->config['allow_bbcode'],
622
			'S_BBCODE_FLASH'		=> ($this->config['allow_bbcode'] && $this->config['allow_post_flash']) ? true : false,
623
			'S_BBCODE_QUOTE'		=> true,
624
			'S_LINKS_ALLOWED'		=> (bool) $this->config['allow_post_links'],
625
626
			'DIR_FLAG_PATH'			=> $flag_path,
627
			'DIR_FLAG_IMAGE'		=> $this->flag ? $this->dir_helper->get_img_path('flags', $this->flag) : '',
628
629
			'EDIT_MODE'				=> ($mode == 'edit') ? true : false,
630
631
			'SITE_NAME'				=> isset($this->site_name) ? $this->site_name : '',
632
			'SITE_URL'				=> isset($this->url) ? $this->url : '',
633
			'DESCRIPTION'			=> isset($this->description) ? $this->description : '',
634
			'GUEST_EMAIL'			=> isset($this->guest_email) ? $this->guest_email : '',
635
			'RSS'					=> isset($this->rss) ? $this->rss : '',
636
			'BANNER'				=> isset($this->banner) ? $this->banner : '',
637
			'BACK'					=> isset($this->back) ? $this->back : '',
638
			'S_POST_ACTION'			=> '',
639
			'S_CATLIST'				=> $this->categorie->make_cat_select($cat_id),
640
			'S_LIST_FLAG'			=> $this->link->get_dir_flag_list($flag_path, $this->flag),
641
			'S_DESC_STAR'			=> (@$this->categorie->data['cat_must_describe']) ? '*' : '',
642
			'S_ROOT'				=> $cat_id,
643
			'S_HIDDEN_FIELDS'		=> build_hidden_fields($this->s_hidden_fields),
644
		));
645
	}
646
}
647