|
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\services\blocks; |
|
12
|
|
|
|
|
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
14
|
|
|
|
|
15
|
|
|
class display |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var \phpbb\auth\auth */ |
|
18
|
|
|
protected $auth; |
|
19
|
|
|
|
|
20
|
|
|
/** @var \phpbb\config\config */ |
|
21
|
|
|
protected $config; |
|
22
|
|
|
|
|
23
|
|
|
/** @var \phpbb\config\db_text */ |
|
24
|
|
|
protected $config_text; |
|
25
|
|
|
|
|
26
|
|
|
/** @var ContainerInterface */ |
|
27
|
|
|
protected $phpbb_container; |
|
28
|
|
|
|
|
29
|
|
|
/** @var \phpbb\request\request_interface */ |
|
30
|
|
|
protected $request; |
|
31
|
|
|
|
|
32
|
|
|
/** @var \phpbb\template\template */ |
|
33
|
|
|
protected $template; |
|
34
|
|
|
|
|
35
|
|
|
/** @var \phpbb\user */ |
|
36
|
|
|
protected $user; |
|
37
|
|
|
|
|
38
|
|
|
const SHOW_ON_ALL_ROUTES = 0; |
|
39
|
|
|
const SHOW_ON_PARENT_ROUTE_ONLY = 1; |
|
40
|
|
|
const SHOW_ON_CHILD_ROUTE_ONLY = 2; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Constructor |
|
44
|
|
|
* |
|
45
|
|
|
* @param \phpbb\auth\auth $auth Auth object |
|
46
|
|
|
* @param \phpbb\config\config $config Config object |
|
47
|
|
|
* @param \phpbb\config\db_text $config_text Config text object |
|
48
|
|
|
* @param ContainerInterface $phpbb_container Service container |
|
49
|
|
|
* @param \phpbb\request\request_interface $request Request object |
|
50
|
|
|
* @param \phpbb\template\template $template Template object |
|
51
|
|
|
* @param \phpbb\user $user User object |
|
52
|
19 |
|
*/ |
|
53
|
|
|
public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\config\db_text $config_text, ContainerInterface $phpbb_container, \phpbb\request\request_interface $request, \phpbb\template\template $template, \phpbb\user $user) |
|
54
|
19 |
|
{ |
|
55
|
19 |
|
$this->auth = $auth; |
|
56
|
19 |
|
$this->config = $config; |
|
57
|
19 |
|
$this->config_text = $config_text; |
|
58
|
19 |
|
$this->phpbb_container = $phpbb_container; |
|
59
|
19 |
|
$this->request = $request; |
|
60
|
19 |
|
$this->template = $template; |
|
61
|
19 |
|
$this->user = $user; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Show blocks |
|
66
|
19 |
|
*/ |
|
67
|
|
|
public function show() |
|
68
|
19 |
|
{ |
|
69
|
19 |
|
if ($this->page_can_have_blocks()) |
|
70
|
17 |
|
{ |
|
71
|
17 |
|
$edit_mode = $this->toggle_edit_mode(); |
|
72
|
17 |
|
$style_id = $this->get_style_id(); |
|
73
|
|
|
$current_route = $this->get_current_route(); |
|
74
|
17 |
|
|
|
75
|
17 |
|
$this->show_sitemaker($current_route, $this->user->page['page_dir'], $style_id, $edit_mode); |
|
76
|
19 |
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
17 |
|
protected function get_current_route() |
|
83
|
|
|
{ |
|
84
|
17 |
|
return ltrim($this->user->page['page_dir'] . '/' . $this->user->page['page_name'], './') . ($this->user->page['forum'] ? '?f=' . $this->user->page['forum'] : ''); |
|
85
|
17 |
|
} |
|
86
|
2 |
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get style id |
|
89
|
|
|
* @return int |
|
90
|
15 |
|
*/ |
|
91
|
|
|
public function get_style_id() |
|
92
|
|
|
{ |
|
93
|
|
|
if ($this->request->is_set('style')) |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->request->variable('style', 0); |
|
96
|
|
|
} |
|
97
|
19 |
|
else |
|
98
|
|
|
{ |
|
99
|
19 |
|
return (int) ((!$this->config['override_user_style']) ? $this->user->data['user_style'] : $this->config['default_style']); |
|
100
|
19 |
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return bool |
|
105
|
|
|
*/ |
|
106
|
17 |
|
protected function page_can_have_blocks() |
|
107
|
|
|
{ |
|
108
|
17 |
|
$offlimits = array('ucp.php', 'mcp.php', 'memberlist.php'); |
|
109
|
|
|
return ($this->user->page['page_dir'] == 'adm' || in_array($this->user->page['page_name'], $offlimits)) ? false : true; |
|
110
|
17 |
|
} |
|
111
|
17 |
|
|
|
112
|
15 |
|
/** |
|
113
|
15 |
|
* @return bool |
|
114
|
15 |
|
*/ |
|
115
|
|
|
protected function toggle_edit_mode() |
|
116
|
17 |
|
{ |
|
117
|
|
|
$edit_mode = $this->request->variable($this->config['cookie_name'] . '_sm_edit_mode', false, false, \phpbb\request\request_interface::COOKIE); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
if ($this->request->is_set('edit_mode')) |
|
120
|
|
|
{ |
|
121
|
|
|
$edit_mode = $this->request->variable('edit_mode', false); |
|
122
|
|
|
$this->user->set_cookie('sm_edit_mode', $edit_mode, 0); |
|
123
|
17 |
|
} |
|
124
|
|
|
|
|
125
|
17 |
|
return $edit_mode; |
|
126
|
17 |
|
} |
|
127
|
|
|
|
|
128
|
12 |
|
/** |
|
129
|
12 |
|
* @param bool $is_sub_route |
|
130
|
12 |
|
* @return array |
|
131
|
12 |
|
*/ |
|
132
|
12 |
|
protected function get_display_modes($is_sub_route) |
|
133
|
|
|
{ |
|
134
|
|
|
if ($is_sub_route === false) |
|
135
|
|
|
{ |
|
136
|
5 |
|
$modes = array( |
|
137
|
5 |
|
self::SHOW_ON_ALL_ROUTES => true, |
|
138
|
5 |
|
self::SHOW_ON_PARENT_ROUTE_ONLY => true, |
|
139
|
5 |
|
self::SHOW_ON_CHILD_ROUTE_ONLY => false, |
|
140
|
|
|
); |
|
141
|
|
|
} |
|
142
|
17 |
|
else |
|
143
|
|
|
{ |
|
144
|
|
|
$modes = array( |
|
145
|
|
|
self::SHOW_ON_ALL_ROUTES => true, |
|
146
|
|
|
self::SHOW_ON_PARENT_ROUTE_ONLY => false, |
|
147
|
|
|
self::SHOW_ON_CHILD_ROUTE_ONLY => true, |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
17 |
|
|
|
151
|
|
|
return $modes; |
|
152
|
17 |
|
} |
|
153
|
17 |
|
|
|
154
|
17 |
|
/** |
|
155
|
|
|
* @param bool $edit_mode |
|
156
|
5 |
|
* @param array $modes |
|
157
|
|
|
* @return string |
|
158
|
4 |
|
*/ |
|
159
|
4 |
|
protected function get_edit_mode_url(&$edit_mode, array &$modes) |
|
160
|
4 |
|
{ |
|
161
|
4 |
|
$u_edit_mode = ''; |
|
162
|
4 |
|
if ($this->auth->acl_get('a_sm_manage_blocks')) |
|
163
|
|
|
{ |
|
164
|
5 |
|
if ($edit_mode) |
|
165
|
5 |
|
{ |
|
166
|
|
|
$modes = array( |
|
167
|
|
|
self::SHOW_ON_ALL_ROUTES => true, |
|
168
|
12 |
|
self::SHOW_ON_PARENT_ROUTE_ONLY => true, |
|
169
|
|
|
self::SHOW_ON_CHILD_ROUTE_ONLY => true, |
|
170
|
|
|
); |
|
171
|
17 |
|
} |
|
172
|
|
|
|
|
173
|
|
|
$u_edit_mode = append_sid(generate_board_url() . '/' . ltrim(rtrim(build_url(array('edit_mode', 'sid', 'style')), '?'), './../'), 'edit_mode=' . (int) !$edit_mode); |
|
174
|
|
|
} |
|
175
|
|
|
else |
|
176
|
|
|
{ |
|
177
|
|
|
$edit_mode = false; |
|
178
|
17 |
|
} |
|
179
|
|
|
|
|
180
|
17 |
|
return $u_edit_mode; |
|
181
|
|
|
} |
|
182
|
17 |
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* @param int $style_id |
|
185
|
|
|
* @return string |
|
186
|
|
|
*/ |
|
187
|
|
|
protected function get_layout($style_id) |
|
188
|
|
|
{ |
|
189
|
|
|
$style_prefs = array_filter((array) json_decode((string) $this->config_text->get('sm_layout_prefs'), true)); |
|
190
|
|
|
|
|
191
|
|
|
return (isset($style_prefs[$style_id])) ? basename($style_prefs[$style_id]['layout']) : 'portal'; |
|
192
|
17 |
|
} |
|
193
|
|
|
|
|
194
|
17 |
|
/** |
|
195
|
|
|
* @param int $style_id |
|
196
|
17 |
|
* @return string |
|
197
|
17 |
|
*/ |
|
198
|
17 |
|
protected function get_column_widths($style_id) |
|
199
|
|
|
{ |
|
200
|
17 |
|
$column_widths = array_filter((array) json_decode($this->config['sitemaker_column_widths'], true)); |
|
201
|
|
|
|
|
202
|
17 |
|
return (isset($column_widths[$style_id])) ? $column_widths[$style_id] : ''; |
|
203
|
17 |
|
} |
|
204
|
15 |
|
|
|
205
|
15 |
|
/** |
|
206
|
|
|
* @param int $style_id |
|
207
|
17 |
|
* @param string $current_route |
|
208
|
17 |
|
* @param string $page_dir |
|
209
|
17 |
|
* @param int $style_id |
|
210
|
17 |
|
* @param bool $edit_mode |
|
211
|
17 |
|
*/ |
|
212
|
17 |
|
protected function show_sitemaker($current_route, $page_dir, $style_id, $edit_mode) |
|
213
|
|
|
{ |
|
214
|
|
|
$blocks = $this->phpbb_container->get('blitze.sitemaker.blocks'); |
|
215
|
|
|
|
|
216
|
|
|
$route_info = $blocks->get_route_info($current_route, $page_dir, $style_id, $edit_mode); |
|
217
|
|
|
$display_modes = $this->get_display_modes($route_info['is_sub_route']); |
|
218
|
17 |
|
$u_edit_mode = $this->get_edit_mode_url($edit_mode, $display_modes); |
|
219
|
|
|
|
|
220
|
|
|
$this->show_admin_bar($edit_mode, $route_info); |
|
221
|
17 |
|
|
|
222
|
4 |
|
if ($edit_mode || !$route_info['hide_blocks']) |
|
223
|
4 |
|
{ |
|
224
|
17 |
|
$blocks->display($edit_mode, $route_info, $style_id, $display_modes); |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
$this->template->assign_vars(array( |
|
228
|
|
|
'S_SITEMAKER' => true, |
|
229
|
|
|
'S_LAYOUT' => $this->get_layout($style_id), |
|
230
|
|
|
'S_COLUMN_WIDTHS' => $this->get_column_widths($style_id), |
|
231
|
|
|
'U_EDIT_MODE' => $u_edit_mode, |
|
232
|
|
|
)); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @param bool $edit_mode |
|
237
|
|
|
* @param array $route_info |
|
238
|
|
|
*/ |
|
239
|
|
|
protected function show_admin_bar($edit_mode, array $route_info) |
|
240
|
|
|
{ |
|
241
|
|
|
if ($edit_mode) |
|
242
|
|
|
{ |
|
243
|
|
|
$this->phpbb_container->get('blitze.sitemaker.blocks.admin_bar')->show($route_info); |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|