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 admin_bar |
15
|
|
|
{ |
16
|
|
|
/** @var \phpbb\config\config */ |
17
|
|
|
protected $config; |
18
|
|
|
|
19
|
|
|
/** @var ContainerInterface */ |
20
|
|
|
protected $phpbb_container; |
21
|
|
|
|
22
|
|
|
/** @var \phpbb\template\template */ |
23
|
|
|
protected $template; |
24
|
|
|
|
25
|
|
|
/** @var \phpbb\language\language */ |
26
|
|
|
protected $translator; |
27
|
|
|
|
28
|
|
|
/** @var \blitze\sitemaker\services\icon_picker */ |
29
|
|
|
protected $icons; |
30
|
|
|
|
31
|
|
|
/** @var \blitze\sitemaker\services\util */ |
32
|
|
|
protected $util; |
33
|
|
|
|
34
|
|
|
/** @var string phpEx */ |
35
|
|
|
protected $php_ext; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Constructor |
39
|
|
|
* |
40
|
|
|
* @param \phpbb\config\config $config Config object |
41
|
|
|
* @param ContainerInterface $phpbb_container Service container |
42
|
|
|
* @param \phpbb\template\template $template Template object |
43
|
|
|
* @param \phpbb\language\language $translator Language object |
44
|
|
|
* @param \blitze\sitemaker\services\icon_picker $icons Sitemaker icon picker object |
45
|
|
|
* @param \blitze\sitemaker\services\util $util Sitemaker util object |
46
|
|
|
* @param string $php_ext phpEx |
47
|
|
|
*/ |
48
|
12 |
|
public function __construct(\phpbb\config\config $config, ContainerInterface $phpbb_container, \phpbb\template\template $template, \phpbb\language\language $translator, \blitze\sitemaker\services\icon_picker $icons, \blitze\sitemaker\services\util $util, $php_ext) |
49
|
|
|
{ |
50
|
12 |
|
$this->config = $config; |
51
|
12 |
|
$this->phpbb_container = $phpbb_container; |
52
|
12 |
|
$this->template = $template; |
53
|
12 |
|
$this->translator = $translator; |
54
|
12 |
|
$this->icons = $icons; |
55
|
12 |
|
$this->util = $util; |
56
|
12 |
|
$this->php_ext = $php_ext; |
57
|
12 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Show admin bar |
61
|
|
|
* |
62
|
|
|
* @param array $route_info |
63
|
|
|
*/ |
64
|
4 |
|
public function show(array $route_info) |
65
|
|
|
{ |
66
|
2 |
|
$this->translator->add_lang('block_manager', 'blitze/sitemaker'); |
67
|
|
|
|
68
|
2 |
|
$this->phpbb_container->get('blitze.sitemaker.auto_lang')->add('blocks_admin'); |
69
|
|
|
|
70
|
2 |
|
$route = $route_info['route']; |
71
|
2 |
|
$style_id = $route_info['style']; |
72
|
|
|
|
73
|
2 |
|
$this->get_available_blocks(); |
74
|
2 |
|
$this->get_startpage_options(); |
75
|
2 |
|
$this->set_javascript_data($route, $style_id); |
76
|
2 |
|
$this->set_assets(); |
77
|
|
|
|
78
|
2 |
|
$this->template->assign_vars(array( |
79
|
2 |
|
'S_EDIT_MODE' => true, |
80
|
2 |
|
'S_ROUTE_OPS' => $this->get_route_options($route), |
81
|
2 |
|
'S_HIDE_BLOCKS' => $route_info['hide_blocks'], |
82
|
2 |
|
'S_POSITION_OPS' => $this->get_excluded_position_options($route_info['ex_positions']), |
83
|
2 |
|
'S_EX_POSITIONS' => join(', ', $route_info['ex_positions']), |
84
|
4 |
|
'S_STYLE_OPTIONS' => style_select($style_id, true), |
85
|
2 |
|
'S_STARTPAGE' => $this->startpage_is_set(), |
86
|
|
|
|
87
|
2 |
|
'ICON_PICKER' => $this->icons->picker(), |
88
|
2 |
|
)); |
89
|
2 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set data used in javascript |
93
|
|
|
* @param string $route |
94
|
|
|
* @param int $style_id |
95
|
|
|
*/ |
96
|
4 |
|
public function set_javascript_data($route, $style_id) |
97
|
|
|
{ |
98
|
4 |
|
$board_url = generate_board_url(); |
99
|
4 |
|
$ajax_url = $board_url . ((!$this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : ''); |
100
|
|
|
|
101
|
4 |
|
$is_default_route = $u_default_route = false; |
102
|
4 |
|
if ($this->config['sitemaker_default_layout']) |
103
|
4 |
|
{ |
104
|
1 |
|
$is_default_route = ($this->config['sitemaker_default_layout'] === $route) ? true : false; |
105
|
1 |
|
$u_default_route .= $board_url . '/' . $this->config['sitemaker_default_layout']; |
106
|
1 |
|
$u_default_route = reapply_sid($u_default_route); |
107
|
1 |
|
} |
108
|
|
|
|
109
|
4 |
|
$this->template->assign_vars(array( |
110
|
4 |
|
'S_IS_DEFAULT' => $is_default_route, |
111
|
|
|
|
112
|
4 |
|
'PAGE_URL' => build_url(array('style')), |
113
|
|
|
|
114
|
4 |
|
'UA_ROUTE' => $route, |
115
|
4 |
|
'UA_AJAX_URL' => $ajax_url, |
116
|
4 |
|
'UA_BOARD_URL' => $board_url, |
117
|
4 |
|
'UA_STYLE_ID' => $style_id, |
118
|
|
|
|
119
|
4 |
|
'U_VIEW_DEFAULT' => $u_default_route, |
120
|
4 |
|
)); |
121
|
4 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Get all available sitemaker blocks |
125
|
|
|
*/ |
126
|
3 |
|
public function get_available_blocks() |
127
|
|
|
{ |
128
|
3 |
|
$blocks = $this->phpbb_container->get('blitze.sitemaker.blocks.factory')->get_all_blocks(); |
129
|
|
|
|
130
|
3 |
|
foreach ($blocks as $service => $name) |
131
|
|
|
{ |
132
|
3 |
|
$this->template->assign_block_vars('block', array( |
133
|
3 |
|
'NAME' => $name, |
134
|
3 |
|
'SERVICE' => $service) |
135
|
3 |
|
); |
136
|
3 |
|
} |
137
|
3 |
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Provide options to set/unset current page as landing page |
141
|
|
|
*/ |
142
|
5 |
|
public function get_startpage_options() |
143
|
|
|
{ |
144
|
5 |
|
$symfony_request = $this->phpbb_container->get('symfony_request'); |
145
|
5 |
|
$controller = $symfony_request->attributes->get('_controller'); |
146
|
|
|
|
147
|
5 |
|
if ($controller && $controller !== 'blitze.sitemaker.forum.controller:handle') |
148
|
5 |
|
{ |
149
|
2 |
|
list($controller_service, $controller_method) = explode(':', $controller); |
150
|
2 |
|
$controller_params = $symfony_request->attributes->get('_route_params'); |
151
|
2 |
|
$controller_object = $this->phpbb_container->get($controller_service); |
152
|
2 |
|
$controller_class = get_class($controller_object); |
153
|
|
|
|
154
|
2 |
|
$r = new \ReflectionMethod($controller_class, $controller_method); |
155
|
2 |
|
$class_params = $r->getParameters(); |
156
|
|
|
|
157
|
2 |
|
list($namespace, $extension) = explode('\\', $controller_class); |
158
|
2 |
|
$controller_arguments = $this->get_arguments($controller_params, $class_params); |
159
|
|
|
|
160
|
2 |
|
$this->template->assign_vars(array( |
161
|
2 |
|
'CONTROLLER_NAME' => $controller_service, |
162
|
2 |
|
'CONTROLLER_METHOD' => $controller_method, |
163
|
2 |
|
'CONTROLLER_PARAMS' => $controller_arguments, |
164
|
2 |
|
'S_IS_STARTPAGE' => $this->is_startpage($controller_service, $controller_arguments), |
165
|
2 |
|
'UA_EXTENSION' => $namespace . '/' . $extension, |
166
|
2 |
|
)); |
167
|
2 |
|
} |
168
|
5 |
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Add js/css |
172
|
|
|
*/ |
173
|
2 |
|
public function set_assets() |
174
|
|
|
{ |
175
|
2 |
|
$this->util->add_assets(array( |
176
|
|
|
'js' => array( |
177
|
2 |
|
'@blitze_sitemaker/vendor/jquery-ui/jquery-ui.min.js', |
178
|
2 |
|
'@blitze_sitemaker/vendor/tinymce/tinymce.min.js', |
179
|
2 |
|
'@blitze_sitemaker/vendor/jqueryui-touch-punch/jquery.ui.touch-punch.min.js', |
180
|
2 |
|
'@blitze_sitemaker/vendor/twig.js/twig.min.js', |
181
|
2 |
|
100 => '@blitze_sitemaker/assets/blocks/manager.min.js', |
182
|
2 |
|
), |
183
|
|
|
'css' => array( |
184
|
2 |
|
'@blitze_sitemaker/vendor/jquery-ui/themes/smoothness/jquery-ui.min.css', |
185
|
2 |
|
'@blitze_sitemaker/assets/blocks/manager.min.css', |
186
|
|
|
) |
187
|
2 |
|
)); |
188
|
2 |
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get routes with blocks |
192
|
|
|
* |
193
|
|
|
* @param string $current_route |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
4 |
|
public function get_route_options($current_route) |
197
|
|
|
{ |
198
|
4 |
|
$routes_ary = $this->get_routes(); |
199
|
|
|
|
200
|
4 |
|
$options = '<option value="">' . $this->translator->lang('SELECT') . '</option>'; |
201
|
4 |
|
foreach ($routes_ary as $route) |
202
|
|
|
{ |
203
|
4 |
|
$selected = ($route == $current_route) ? ' selected="selected"' : ''; |
204
|
4 |
|
$options .= '<option value="' . $route . '"' . $selected . '>' . $route . '</option>'; |
205
|
4 |
|
} |
206
|
|
|
|
207
|
4 |
|
return $options; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Get excluded position options |
212
|
|
|
* |
213
|
|
|
* @param array $ex_positions |
214
|
|
|
* @return string |
215
|
|
|
*/ |
216
|
4 |
|
public function get_excluded_position_options(array $ex_positions) |
217
|
|
|
{ |
218
|
4 |
|
$options = '<option value=""' . ((!sizeof($ex_positions)) ? ' selected="selected"' : '') . '>' . $this->translator->lang('NONE') . '</option>'; |
219
|
4 |
|
foreach ($ex_positions as $position) |
220
|
|
|
{ |
221
|
1 |
|
$options .= '<option value="' . $position . '" selected="selected">' . $position . '</option>'; |
222
|
4 |
|
} |
223
|
|
|
|
224
|
4 |
|
return $options; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @return array |
229
|
|
|
*/ |
230
|
4 |
|
protected function get_routes() |
231
|
|
|
{ |
232
|
4 |
|
$factory = $this->phpbb_container->get('blitze.sitemaker.mapper.factory'); |
233
|
4 |
|
$collection = $factory->create('blocks', 'routes')->find(); |
234
|
|
|
|
235
|
4 |
|
$routes_ary = array(); |
236
|
4 |
|
foreach ($collection as $entity) |
237
|
|
|
{ |
238
|
|
|
/** @type \blitze\sitemaker\model\blocks\entity\route $entity */ |
239
|
4 |
|
$route_name = $entity->get_route(); |
240
|
4 |
|
$routes_ary[$route_name] = $route_name; |
241
|
4 |
|
} |
242
|
|
|
|
243
|
4 |
|
return $routes_ary; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @param array $controller_params |
248
|
|
|
* @param array $class_params |
249
|
|
|
* @return string |
250
|
|
|
*/ |
251
|
2 |
|
protected function get_arguments(array $controller_params, array $class_params) |
252
|
|
|
{ |
253
|
2 |
|
$arguments = array(); |
254
|
2 |
|
foreach ($class_params as $param) |
255
|
|
|
{ |
256
|
2 |
|
$name = $param->getName(); |
257
|
2 |
|
$arguments[$name] = ($param->isOptional()) ? $param->getDefaultValue() : $controller_params[$name]; |
258
|
2 |
|
} |
259
|
|
|
|
260
|
2 |
|
return join('/', $arguments); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @param string $controller_service |
265
|
|
|
* @param string $controller_arguments |
266
|
|
|
* @return bool |
267
|
|
|
*/ |
268
|
2 |
|
protected function is_startpage($controller_service, $controller_arguments) |
269
|
|
|
{ |
270
|
2 |
|
return ($this->config['sitemaker_startpage_controller'] == $controller_service && $this->config['sitemaker_startpage_params'] == $controller_arguments) ? true : false; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @return bool |
275
|
|
|
*/ |
276
|
2 |
|
protected function startpage_is_set() |
277
|
|
|
{ |
278
|
2 |
|
return ($this->config['sitemaker_startpage_controller']) ? true : false; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|