1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package sitemaker |
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace blitze\sitemaker\services\blocks; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
13
|
|
|
|
14
|
|
|
class display |
15
|
|
|
{ |
16
|
|
|
/** @var \phpbb\auth\auth */ |
17
|
|
|
protected $auth; |
18
|
|
|
|
19
|
|
|
/** @var \phpbb\config\config */ |
20
|
|
|
protected $config; |
21
|
|
|
|
22
|
|
|
/** @var ContainerInterface */ |
23
|
|
|
protected $phpbb_container; |
24
|
|
|
|
25
|
|
|
/** @var \phpbb\request\request_interface */ |
26
|
|
|
protected $request; |
27
|
|
|
|
28
|
|
|
/** @var \phpbb\template\template */ |
29
|
|
|
protected $template; |
30
|
|
|
|
31
|
|
|
/** @var \phpbb\language\language */ |
32
|
|
|
protected $translator; |
33
|
|
|
|
34
|
|
|
/** @var \phpbb\user */ |
35
|
|
|
protected $user; |
36
|
|
|
|
37
|
|
|
const SHOW_ON_ALL_ROUTES = 0; |
38
|
|
|
const SHOW_ON_PARENT_ROUTE_ONLY = 1; |
39
|
|
|
const SHOW_ON_CHILD_ROUTE_ONLY = 2; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor |
43
|
|
|
* |
44
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
45
|
|
|
* @param \phpbb\config\config $config Config object |
46
|
|
|
* @param ContainerInterface $phpbb_container Service container |
47
|
|
|
* @param \phpbb\request\request_interface $request Request object |
48
|
|
|
* @param \phpbb\template\template $template Template object |
49
|
|
|
* @param \phpbb\language\language $translator Language object |
50
|
|
|
* @param \phpbb\user $user User object |
51
|
|
|
*/ |
52
|
10 |
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, ContainerInterface $phpbb_container, \phpbb\request\request_interface $request, \phpbb\template\template $template, \phpbb\language\language $translator, \phpbb\user $user) |
53
|
|
|
{ |
54
|
10 |
|
$this->auth = $auth; |
55
|
10 |
|
$this->config = $config; |
56
|
10 |
|
$this->phpbb_container = $phpbb_container; |
57
|
10 |
|
$this->request = $request; |
58
|
10 |
|
$this->template = $template; |
59
|
10 |
|
$this->translator = $translator; |
60
|
10 |
|
$this->user = $user; |
61
|
10 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Show blocks |
65
|
|
|
*/ |
66
|
10 |
|
public function show() |
67
|
|
|
{ |
68
|
10 |
|
$this->template->assign_var('L_INDEX', $this->translator->lang('HOME')); |
69
|
|
|
|
70
|
10 |
|
if ($this->page_can_have_blocks()) |
71
|
10 |
|
{ |
72
|
8 |
|
$blocks = $this->phpbb_container->get('blitze.sitemaker.blocks'); |
73
|
|
|
|
74
|
8 |
|
$edit_mode = $this->toggle_edit_mode(); |
75
|
8 |
|
$style_id = $this->get_style_id(); |
76
|
8 |
|
$route_info = $blocks->get_route_info($this->user->page['page_name'], $style_id, $edit_mode); |
77
|
|
|
|
78
|
8 |
|
$display_modes = $this->get_display_modes($route_info['is_sub_route']); |
79
|
8 |
|
$u_edit_mode = $this->get_edit_mode_url($edit_mode, $display_modes); |
80
|
|
|
|
81
|
8 |
|
$this->show_admin_bar($edit_mode, $route_info); |
82
|
8 |
|
$blocks->display($edit_mode, $route_info, $style_id, $display_modes); |
83
|
|
|
|
84
|
8 |
|
$this->template->assign_vars(array( |
85
|
8 |
|
'S_SITEMAKER' => true, |
86
|
8 |
|
'S_LAYOUT' => $this->get_layout($style_id), |
87
|
8 |
|
'U_EDIT_MODE' => $u_edit_mode, |
88
|
8 |
|
)); |
89
|
8 |
|
} |
90
|
10 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get style id |
94
|
|
|
* @return int |
95
|
|
|
*/ |
96
|
8 |
|
public function get_style_id() |
97
|
|
|
{ |
98
|
8 |
|
if ($this->request->is_set('style')) |
99
|
8 |
|
{ |
100
|
2 |
|
return $this->request->variable('style', 0); |
101
|
|
|
} |
102
|
|
|
else |
103
|
|
|
{ |
104
|
6 |
|
return (!$this->config['override_user_style']) ? $this->user->data['user_style'] : $this->config['default_style']; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return bool |
110
|
|
|
*/ |
111
|
10 |
|
protected function page_can_have_blocks() |
112
|
|
|
{ |
113
|
10 |
|
$offlimits = array('ucp.php', 'mcp.php', 'memberlist.php'); |
114
|
10 |
|
return ($this->user->page['page_dir'] == 'adm' || in_array($this->user->page['page_name'], $offlimits)) ? false : true; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
8 |
|
protected function toggle_edit_mode() |
121
|
|
|
{ |
122
|
8 |
|
$edit_mode = $this->request->variable($this->config['cookie_name'] . '_sm_edit_mode', false, false, \phpbb\request\request_interface::COOKIE); |
123
|
|
|
|
124
|
8 |
|
if ($this->request->is_set('edit_mode')) |
125
|
8 |
|
{ |
126
|
6 |
|
$edit_mode = $this->request->variable('edit_mode', false); |
127
|
6 |
|
$this->user->set_cookie('sm_edit_mode', $edit_mode, 0); |
128
|
6 |
|
} |
129
|
|
|
|
130
|
8 |
|
return $edit_mode; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param bool $is_sub_route |
135
|
|
|
* @return array |
136
|
|
|
*/ |
137
|
8 |
|
protected function get_display_modes($is_sub_route) |
138
|
|
|
{ |
139
|
8 |
|
if ($is_sub_route === false) |
140
|
8 |
|
{ |
141
|
|
|
$modes = array( |
142
|
7 |
|
self::SHOW_ON_ALL_ROUTES => true, |
143
|
7 |
|
self::SHOW_ON_PARENT_ROUTE_ONLY => true, |
144
|
7 |
|
self::SHOW_ON_CHILD_ROUTE_ONLY => false, |
145
|
7 |
|
); |
146
|
7 |
|
} |
147
|
|
|
else |
148
|
|
|
{ |
149
|
|
|
$modes = array( |
150
|
1 |
|
self::SHOW_ON_ALL_ROUTES => true, |
151
|
1 |
|
self::SHOW_ON_PARENT_ROUTE_ONLY => false, |
152
|
1 |
|
self::SHOW_ON_CHILD_ROUTE_ONLY => true, |
153
|
1 |
|
); |
154
|
|
|
} |
155
|
|
|
|
156
|
8 |
|
return $modes; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @param bool $edit_mode |
161
|
|
|
* @param array $modes |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
8 |
|
protected function get_edit_mode_url(&$edit_mode, array &$modes) |
165
|
|
|
{ |
166
|
8 |
|
$u_edit_mode = ''; |
167
|
8 |
|
if ($this->auth->acl_get('a_sm_manage_blocks')) |
168
|
8 |
|
{ |
169
|
|
|
if ($edit_mode) |
170
|
4 |
|
{ |
171
|
|
|
$modes = array( |
172
|
3 |
|
self::SHOW_ON_ALL_ROUTES => true, |
173
|
3 |
|
self::SHOW_ON_PARENT_ROUTE_ONLY => true, |
174
|
3 |
|
self::SHOW_ON_CHILD_ROUTE_ONLY => true, |
175
|
3 |
|
); |
176
|
3 |
|
} |
177
|
|
|
|
178
|
4 |
|
$u_edit_mode = append_sid(generate_board_url() . '/' . ltrim(rtrim(build_url(array('edit_mode', 'sid', 'style')), '?'), './../'), 'edit_mode=' . (int) !$edit_mode); |
179
|
4 |
|
} |
180
|
|
|
else |
181
|
|
|
{ |
182
|
4 |
|
$edit_mode = false; |
183
|
|
|
} |
184
|
|
|
|
185
|
8 |
|
return $u_edit_mode; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param int $style_id |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
8 |
|
protected function get_layout($style_id) |
193
|
|
|
{ |
194
|
8 |
|
$config_text = $this->phpbb_container->get('config_text'); |
195
|
8 |
|
$style_prefs = array_filter(json_decode($config_text->get('sm_layout_prefs'), true)); |
196
|
|
|
|
197
|
8 |
|
return (isset($style_prefs[$style_id])) ? basename($style_prefs[$style_id]['layout']) : 'portal'; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param int $style_id |
|
|
|
|
202
|
|
|
* @param bool $edit_mode |
203
|
|
|
* @param array $route_info |
204
|
|
|
*/ |
205
|
8 |
|
protected function show_admin_bar($edit_mode, array $route_info) |
206
|
|
|
{ |
207
|
|
|
if ($edit_mode) |
208
|
8 |
|
{ |
209
|
3 |
|
$this->phpbb_container->get('blitze.sitemaker.blocks.admin_bar')->show($route_info); |
210
|
3 |
|
} |
211
|
8 |
|
} |
212
|
|
|
} |
213
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.