|
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 \phpbb\controller\helper */ |
|
20
|
|
|
protected $controller_helper; |
|
21
|
|
|
|
|
22
|
|
|
/** @var ContainerInterface */ |
|
23
|
|
|
protected $phpbb_container; |
|
24
|
|
|
|
|
25
|
|
|
/** @var \phpbb\event\dispatcher_interface */ |
|
26
|
|
|
protected $phpbb_dispatcher; |
|
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
|
|
|
/** @var \blitze\sitemaker\services\filemanager\setup */ |
|
38
|
|
|
protected $filemanager; |
|
39
|
|
|
|
|
40
|
|
|
/** @var \blitze\sitemaker\services\icon_picker */ |
|
41
|
|
|
protected $icons; |
|
42
|
|
|
|
|
43
|
|
|
/** @var \blitze\sitemaker\services\util */ |
|
44
|
|
|
protected $util; |
|
45
|
|
|
|
|
46
|
|
|
/** @var string */ |
|
47
|
|
|
protected $phpbb_root_path; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string phpEx */ |
|
50
|
|
|
protected $php_ext; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Constructor |
|
54
|
|
|
* |
|
55
|
|
|
* @param \phpbb\config\config $config Config object |
|
56
|
|
|
* @param \phpbb\controller\helper $controller_helper Controller Helper object |
|
57
|
|
|
* @param ContainerInterface $phpbb_container Service container |
|
58
|
|
|
* @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object |
|
59
|
|
|
* @param \phpbb\template\template $template Template object |
|
60
|
|
|
* @param \phpbb\language\language $translator Language object |
|
61
|
|
|
* @param \phpbb\user $user User object |
|
62
|
|
|
* @param \blitze\sitemaker\services\filemanager\setup $filemanager Filemanager object |
|
63
|
|
|
* @param \blitze\sitemaker\services\icon_picker $icons Sitemaker icon picker object |
|
64
|
12 |
|
* @param \blitze\sitemaker\services\util $util Sitemaker util object |
|
65
|
|
|
* @param string $phpbb_root_path Path to the phpbb includes directory. |
|
66
|
12 |
|
* @param string $php_ext phpEx |
|
67
|
12 |
|
*/ |
|
68
|
12 |
|
public function __construct(\phpbb\config\config $config, \phpbb\controller\helper $controller_helper, ContainerInterface $phpbb_container, \phpbb\event\dispatcher_interface $phpbb_dispatcher, \phpbb\template\template $template, \phpbb\language\language $translator, \phpbb\user $user, \blitze\sitemaker\services\filemanager\setup $filemanager, \blitze\sitemaker\services\icon_picker $icons, \blitze\sitemaker\services\util $util, $phpbb_root_path, $php_ext) |
|
69
|
12 |
|
{ |
|
70
|
12 |
|
$this->config = $config; |
|
71
|
12 |
|
$this->controller_helper = $controller_helper; |
|
72
|
12 |
|
$this->phpbb_container = $phpbb_container; |
|
73
|
12 |
|
$this->phpbb_dispatcher = $phpbb_dispatcher; |
|
74
|
12 |
|
$this->template = $template; |
|
75
|
12 |
|
$this->translator = $translator; |
|
76
|
12 |
|
$this->user = $user; |
|
77
|
12 |
|
$this->filemanager = $filemanager; |
|
78
|
|
|
$this->icons = $icons; |
|
79
|
|
|
$this->util = $util; |
|
80
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
|
81
|
|
|
$this->php_ext = $php_ext; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
/** |
|
85
|
|
|
* Show admin bar |
|
86
|
2 |
|
* |
|
87
|
|
|
* @param array $route_info |
|
88
|
2 |
|
*/ |
|
89
|
|
|
public function show(array $route_info) |
|
90
|
2 |
|
{ |
|
91
|
2 |
|
$this->translator->add_lang('block_manager', 'blitze/sitemaker'); |
|
92
|
|
|
|
|
93
|
2 |
|
$this->phpbb_container->get('blitze.sitemaker.auto_lang')->add('blocks_admin'); |
|
94
|
2 |
|
|
|
95
|
2 |
|
$route = $route_info['route']; |
|
96
|
2 |
|
$style_id = $route_info['style']; |
|
97
|
|
|
|
|
98
|
2 |
|
$this->get_available_blocks(); |
|
99
|
2 |
|
$this->get_startpage_options(); |
|
100
|
2 |
|
$this->set_javascript_data($route, $style_id); |
|
101
|
2 |
|
$this->set_assets(); |
|
102
|
2 |
|
|
|
103
|
2 |
|
$this->template->assign_vars(array( |
|
104
|
2 |
|
'S_EDIT_MODE' => true, |
|
105
|
2 |
|
'S_ROUTE_OPS' => $this->get_route_options($route), |
|
106
|
|
|
'S_HIDE_BLOCKS' => $route_info['hide_blocks'], |
|
107
|
2 |
|
'S_EX_POSITIONS' => join(', ', $route_info['ex_positions']), |
|
108
|
2 |
|
'S_STYLE_OPTIONS' => style_select($style_id, true), |
|
109
|
2 |
|
'S_STARTPAGE' => $this->startpage_is_set(), |
|
110
|
|
|
|
|
111
|
|
|
'ICON_PICKER' => $this->icons->picker(), |
|
112
|
|
|
'SM_USER_LANG' => $this->user->data['user_lang'], |
|
113
|
|
|
'TINYMCE_LANG' => $this->get_tinymce_lang(), |
|
114
|
|
|
)); |
|
115
|
|
|
} |
|
116
|
4 |
|
|
|
117
|
|
|
/** |
|
118
|
4 |
|
* Set data used in javascript |
|
119
|
4 |
|
* @param string $route |
|
120
|
4 |
|
* @param int $style_id |
|
121
|
4 |
|
*/ |
|
122
|
1 |
|
public function set_javascript_data($route, $style_id) |
|
123
|
1 |
|
{ |
|
124
|
1 |
|
$board_url = generate_board_url(); |
|
125
|
1 |
|
$is_default_route = $u_default_route = false; |
|
126
|
|
|
if ($this->config['sitemaker_default_layout']) |
|
127
|
4 |
|
{ |
|
128
|
4 |
|
$is_default_route = ($this->config['sitemaker_default_layout'] === $route) ? true : false; |
|
129
|
|
|
$u_default_route .= $board_url . '/' . $this->config['sitemaker_default_layout']; |
|
130
|
4 |
|
$u_default_route = reapply_sid($u_default_route); |
|
131
|
4 |
|
} |
|
132
|
4 |
|
|
|
133
|
4 |
|
$this->template->assign_vars(array_merge(array( |
|
134
|
|
|
'S_IS_DEFAULT' => $is_default_route, |
|
135
|
4 |
|
|
|
136
|
4 |
|
'BLOCK_ACTIONS' => $this->get_block_actions(), |
|
137
|
4 |
|
'PAGE_URL' => build_url(array('style')), |
|
138
|
4 |
|
|
|
139
|
4 |
|
'UA_BOARD_URL' => $board_url, |
|
140
|
4 |
|
'UA_ROUTE' => $route, |
|
141
|
4 |
|
'UA_STYLE_ID' => $style_id, |
|
142
|
|
|
'UA_SCRIPT_PATH' => $this->user->page['root_script_path'], |
|
143
|
4 |
|
'UA_MODREWRITE' => $this->config['enable_mod_rewrite'], |
|
144
|
4 |
|
'UA_WEB_ROOT_PATH' => $this->util->get_web_path(), |
|
145
|
4 |
|
'UA_UPLOAD_URL' => $this->controller_helper->route('blitze_sitemaker_image_upload'), |
|
146
|
|
|
|
|
147
|
|
|
'U_VIEW_DEFAULT' => $u_default_route, |
|
148
|
|
|
), $this->get_filemanager_settings())); |
|
149
|
|
|
} |
|
150
|
4 |
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return string |
|
153
|
4 |
|
*/ |
|
154
|
4 |
|
protected function get_tinymce_lang() |
|
155
|
4 |
|
{ |
|
156
|
4 |
|
$user_lang = $this->user->data['user_lang']; |
|
157
|
4 |
|
$mapping = include($this->phpbb_root_path . 'ext/blitze/sitemaker/services/blocks/lang_mapping.' . $this->php_ext); |
|
158
|
4 |
|
|
|
159
|
4 |
|
return $mapping[$user_lang] ?: preg_replace_callback('/_([a-z0-9]+)/i', function($parts) { |
|
160
|
4 |
|
return strtoupper($parts[0]); |
|
161
|
4 |
|
}, $user_lang); |
|
162
|
4 |
|
} |
|
163
|
4 |
|
|
|
164
|
|
|
/** |
|
165
|
4 |
|
* @return array |
|
166
|
4 |
|
*/ |
|
167
|
|
|
protected function get_block_actions() |
|
168
|
4 |
|
{ |
|
169
|
4 |
|
$list = array( |
|
170
|
|
|
'add_block', |
|
171
|
4 |
|
'copy_route', |
|
172
|
|
|
'edit_block', |
|
173
|
|
|
'handle_custom_action', |
|
174
|
|
|
'save_block', |
|
175
|
|
|
'save_blocks', |
|
176
|
|
|
'set_default_route', |
|
177
|
3 |
|
'set_route_prefs', |
|
178
|
|
|
'set_startpage', |
|
179
|
3 |
|
'update_block', |
|
180
|
|
|
'update_column_width', |
|
181
|
3 |
|
); |
|
182
|
|
|
|
|
183
|
3 |
|
$actions = array(); |
|
184
|
3 |
|
foreach ($list as $action) |
|
185
|
3 |
|
{ |
|
186
|
3 |
|
$actions[$action] = $this->controller_helper->route('blitze_sitemaker_blocks_admin', array('action' => $action)); |
|
187
|
3 |
|
} |
|
188
|
3 |
|
|
|
189
|
|
|
return $actions; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
5 |
|
* Get all available sitemaker blocks |
|
194
|
|
|
*/ |
|
195
|
5 |
|
public function get_available_blocks() |
|
196
|
5 |
|
{ |
|
197
|
|
|
$blocks = $this->phpbb_container->get('blitze.sitemaker.blocks.factory')->get_all_blocks(); |
|
198
|
|
|
|
|
199
|
5 |
|
foreach ($blocks as $service => $name) |
|
200
|
2 |
|
{ |
|
201
|
2 |
|
$this->template->assign_block_vars('block', array( |
|
202
|
2 |
|
'NAME' => $name, |
|
203
|
2 |
|
'SERVICE' => $service) |
|
204
|
|
|
); |
|
205
|
2 |
|
} |
|
206
|
2 |
|
} |
|
207
|
|
|
|
|
208
|
2 |
|
/** |
|
209
|
2 |
|
* Provide options to set/unset current page as landing page |
|
210
|
|
|
*/ |
|
211
|
2 |
|
public function get_startpage_options() |
|
212
|
2 |
|
{ |
|
213
|
2 |
|
$symfony_request = $this->phpbb_container->get('symfony_request'); |
|
214
|
2 |
|
$controller = $symfony_request->attributes->get('_controller'); |
|
215
|
2 |
|
|
|
216
|
2 |
|
if ($controller) |
|
217
|
2 |
|
{ |
|
218
|
2 |
|
list($controller_service, $controller_method) = explode(':', $controller); |
|
219
|
5 |
|
$controller_params = $symfony_request->attributes->get('_route_params'); |
|
220
|
|
|
$controller_object = $this->phpbb_container->get($controller_service); |
|
221
|
|
|
$controller_class = get_class($controller_object); |
|
222
|
|
|
|
|
223
|
|
|
$r = new \ReflectionMethod($controller_class, $controller_method); |
|
224
|
2 |
|
$class_params = $r->getParameters(); |
|
225
|
|
|
|
|
226
|
|
|
list($namespace, $extension) = explode('\\', $controller_class); |
|
227
|
|
|
$controller_arguments = $this->get_arguments($controller_params, $class_params); |
|
228
|
2 |
|
|
|
229
|
2 |
|
$this->template->assign_vars(array( |
|
230
|
2 |
|
'CONTROLLER_NAME' => $controller_service, |
|
231
|
2 |
|
'CONTROLLER_METHOD' => $controller_method, |
|
232
|
2 |
|
'CONTROLLER_PARAMS' => $controller_arguments, |
|
233
|
2 |
|
'S_IS_STARTPAGE' => $this->is_startpage($controller_service, $controller_arguments), |
|
234
|
|
|
'UA_EXTENSION' => $namespace . '/' . $extension, |
|
235
|
2 |
|
)); |
|
236
|
2 |
|
} |
|
237
|
|
|
} |
|
238
|
2 |
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Add js/css |
|
241
|
|
|
*/ |
|
242
|
|
|
public function set_assets() |
|
243
|
|
|
{ |
|
244
|
|
|
$assets = array( |
|
245
|
|
|
'js' => array( |
|
246
|
|
|
'@blitze_sitemaker/assets/runtime.min.js', |
|
247
|
|
|
'@blitze_sitemaker/assets/tinymce/tinymce.min.js', |
|
248
|
2 |
|
1000 => '@blitze_sitemaker/assets/blocks/manager.min.js', |
|
249
|
2 |
|
), |
|
250
|
|
|
'css' => array( |
|
251
|
2 |
|
'@blitze_sitemaker/assets/blocks/manager.min.css', |
|
252
|
2 |
|
) |
|
253
|
|
|
); |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Event to set assets for available blocks |
|
257
|
|
|
* Use array_merge_recursive to add new assets |
|
258
|
|
|
* |
|
259
|
|
|
* @event blitze.sitemaker.admin_bar.set_assets |
|
260
|
4 |
|
* @var array assets Array of assets to include of form array([js] => array(), [css] => array()) |
|
261
|
|
|
* @since 3.0.1-RC1 |
|
262
|
4 |
|
*/ |
|
263
|
|
|
$vars = array('assets'); |
|
264
|
4 |
|
extract($this->phpbb_dispatcher->trigger_event('blitze.sitemaker.admin_bar.set_assets', compact($vars))); |
|
265
|
4 |
|
|
|
266
|
|
|
$this->util->add_assets($assets); |
|
267
|
4 |
|
} |
|
268
|
4 |
|
|
|
269
|
4 |
|
/** |
|
270
|
|
|
* Get routes with blocks |
|
271
|
4 |
|
* |
|
272
|
|
|
* @param string $current_route |
|
273
|
|
|
* @return string |
|
274
|
|
|
*/ |
|
275
|
|
|
public function get_route_options($current_route) |
|
276
|
|
|
{ |
|
277
|
|
|
$routes_ary = $this->get_routes(); |
|
278
|
|
|
|
|
279
|
|
|
$options = '<option value="">' . $this->translator->lang('SELECT') . '</option>'; |
|
280
|
4 |
|
foreach ($routes_ary as $route) |
|
281
|
|
|
{ |
|
282
|
4 |
|
$selected = ($route == $current_route) ? ' selected="selected"' : ''; |
|
283
|
4 |
|
$options .= '<option value="' . $route . '"' . $selected . '>' . $route . '</option>'; |
|
284
|
|
|
} |
|
285
|
2 |
|
|
|
286
|
4 |
|
return $options; |
|
287
|
|
|
} |
|
288
|
4 |
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @return array |
|
291
|
|
|
*/ |
|
292
|
|
|
protected function get_routes() |
|
293
|
|
|
{ |
|
294
|
4 |
|
$factory = $this->phpbb_container->get('blitze.sitemaker.mapper.factory'); |
|
295
|
|
|
$collection = $factory->create('routes')->find(); |
|
296
|
4 |
|
|
|
297
|
4 |
|
$routes_ary = array(); |
|
298
|
|
|
foreach ($collection as $entity) |
|
299
|
4 |
|
{ |
|
300
|
4 |
|
/** @var \blitze\sitemaker\model\entity\route $entity */ |
|
301
|
|
|
$route_name = $entity->get_route(); |
|
302
|
|
|
$routes_ary[$route_name] = $route_name; |
|
303
|
4 |
|
} |
|
304
|
4 |
|
|
|
305
|
4 |
|
return $routes_ary; |
|
306
|
|
|
} |
|
307
|
4 |
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* @param array $controller_params |
|
310
|
|
|
* @param array $class_params |
|
311
|
|
|
* @return string |
|
312
|
|
|
*/ |
|
313
|
|
|
protected function get_arguments(array $controller_params, array $class_params) |
|
314
|
|
|
{ |
|
315
|
2 |
|
$arguments = array(); |
|
316
|
|
|
foreach ($class_params as $param) |
|
317
|
2 |
|
{ |
|
318
|
2 |
|
$name = $param->getName(); |
|
319
|
|
|
$arguments[$name] = ($param->isOptional()) ? $param->getDefaultValue() : $controller_params[$name]; |
|
320
|
2 |
|
} |
|
321
|
2 |
|
|
|
322
|
2 |
|
return join('/', $arguments); |
|
323
|
|
|
} |
|
324
|
2 |
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* @param string $controller_service |
|
327
|
|
|
* @param string $controller_arguments |
|
328
|
|
|
* @return bool |
|
329
|
|
|
*/ |
|
330
|
|
|
protected function is_startpage($controller_service, $controller_arguments) |
|
331
|
|
|
{ |
|
332
|
2 |
|
return ($this->config['sitemaker_startpage_controller'] == $controller_service && $this->config['sitemaker_startpage_params'] == $controller_arguments) ? true : false; |
|
333
|
|
|
} |
|
334
|
2 |
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* @return bool |
|
337
|
|
|
*/ |
|
338
|
|
|
protected function startpage_is_set() |
|
339
|
|
|
{ |
|
340
|
2 |
|
return ($this->config['sitemaker_startpage_controller']) ? true : false; |
|
341
|
|
|
} |
|
342
|
2 |
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* @return array |
|
345
|
|
|
*/ |
|
346
|
|
|
protected function get_filemanager_settings() |
|
347
|
|
|
{ |
|
348
|
|
|
$enabled = $this->filemanager->is_enabled(); |
|
349
|
|
|
|
|
350
|
|
|
if ($enabled) |
|
351
|
|
|
{ |
|
352
|
|
|
$this->filemanager->ensure_config_is_ready(); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
return array( |
|
356
|
|
|
'FILEMANAGER' => $enabled, |
|
357
|
|
|
'FILEMANAGER_AKEY' => $this->filemanager->get_access_key(), |
|
358
|
|
|
); |
|
359
|
|
|
} |
|
360
|
|
|
} |
|
361
|
|
|
|