login::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 6
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * @package sitemaker
6
 * @copyright (c) 2013 Daniel A. (blitze)
7
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace blitze\sitemaker\blocks;
12
13
use blitze\sitemaker\services\blocks\driver\block;
14
use Symfony\Component\DependencyInjection\ContainerInterface;
15
16
/**
17
 * Login Block
18
 */
19
class login extends block
20
{
21
	/** @var ContainerInterface */
22
	protected $phpbb_container;
23
24
	/** @var \phpbb\template\template */
25
	protected $template;
26
27
	/** @var \phpbb\user */
28
	protected $user;
29
30
	/** @var \blitze\sitemaker\services\util */
31
	protected $util;
32
33
	/** @var string */
34
	protected $phpbb_root_path;
35
36
	/** @var string */
37
	protected $php_ext;
38
39
	/** @var string */
40
	protected $block_template = '@blitze_sitemaker/blocks/login.html';
41
42
	/**
43
	 * Constructor
44 5
	 *
45
	 * @param ContainerInterface					$phpbb_container		Service container
46 5
	 * @param \phpbb\template\template				$template				Template object
47 5
	 * @param \phpbb\user							$user					User object
48 5
	 * @param \blitze\sitemaker\services\util		$util					Utility Object
49 5
	 * @param string 								$phpbb_root_path		Relative path to phpBB root
50 5
	 * @param string 								$php_ext				PHP extension (php)
51 5
	 */
52
	public function __construct(ContainerInterface $phpbb_container, \phpbb\template\template $template, \phpbb\user $user, \blitze\sitemaker\services\util $util, $phpbb_root_path, $php_ext)
53
	{
54
		$this->phpbb_container = $phpbb_container;
55
		$this->template = $template;
56 1
		$this->user = $user;
57
		$this->util = $util;
58
		$this->phpbb_root_path = $phpbb_root_path;
59 1
		$this->php_ext = $php_ext;
60 1
	}
61 1
62 1
	/**
63 1
	 * {@inheritdoc}
64
	 */
65
	public function get_config(array $settings)
66
	{
67
		return array(
68
			'legend1'			=> 'SETTINGS',
69 4
			'show_hide_me'		=> array('lang' => 'SHOW_HIDE_ME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false, 'default' => 1),
70
			'allow_autologin'	=> array('lang' => 'AUTO_LOGIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false, 'default' => 1),
71 4
			'show_member_menu'	=> array('lang' => 'SHOW_MEMBER_MENU', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => false),
72
		);
73 4
	}
74 4
75 4
	/**
76 2
	 * {@inheritdoc}
77 2
	 */
78 2
	public function display(array $bdata, $edit_mode = false)
79 2
	{
80 2
		$settings = $bdata['settings'];
81 2
82 2
		$data = [];
83 2
		if (!$this->user->data['is_registered'] || $edit_mode === true)
84 2
		{
85
			$this->hide_quicklogin();
86 2
			$data = array(
87 2
				'S_SHOW_HIDE_ME'		=> ($settings['show_hide_me']) ? true : false,
88 2
				'S_AUTOLOGIN_ENABLED'   => ($settings['allow_autologin']) ? true : false,
89 2
				'S_FORM_TOKEN'			=> $this->util->get_form_key('login'),
90 1
				'S_LOGIN_ACTION'		=> append_sid("{$this->phpbb_root_path}ucp." . $this->php_ext, 'mode=login'),
91 1
				'U_REGISTER'			=> append_sid("{$this->phpbb_root_path}ucp." . $this->php_ext, 'mode=register'),
92 1
				'U_SEND_PASSWORD'		=> append_sid("{$this->phpbb_root_path}ucp." . $this->php_ext, 'mode=sendpassword'),
93
				'U_REDIRECT'			=> reapply_sid(ltrim(rtrim(build_url(array('edit_mode')), '?'), './../'))
94
			);
95
		}
96 3
		else if ($settings['show_member_menu'])
97 3
		{
98 3
			$block = $this->phpbb_container->get('blitze.sitemaker.block.member_menu');
99
			$this->set_template($block->get_template());
100
			return $block->display(array(), $edit_mode);
101
		}
102
103
		return array(
104 2
			'title'	=> 'LOGIN',
105
			'data'	=> $data,
106 2
		);
107 2
	}
108 2
109 1
	/**
110 1
	 * Quicklogin is only displayed on forum index. So we only need to hide on forum index
111 2
	 */
112
	private function hide_quicklogin()
113
	{
114
		$current_page = $this->user->page['page_name'];
115
		if ($current_page === 'index.' . $this->php_ext)
116
		{
117
			$this->template->assign_var('S_USER_LOGGED_IN', true);
118
		}
119
	}
120
121
	/**
122
	 * {@inheritdoc}
123
	 */
124
	public function get_template()
125
	{
126
		return $this->block_template;
127
	}
128
129
	/**
130
	 * @param string $template
131
	 */
132
	protected function set_template($template)
133
	{
134
		$this->block_template = $template;
135
	}
136
}
137