1 | <?php |
||
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\user */ |
||
26 | protected $user; |
||
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\user $user User 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 | 11 | public function __construct(\phpbb\config\config $config, ContainerInterface $phpbb_container, \phpbb\template\template $template, \phpbb\user $user, \blitze\sitemaker\services\icon_picker $icons, \blitze\sitemaker\services\util $util, $php_ext) |
|
58 | |||
59 | /** |
||
60 | * Show admin bar |
||
61 | */ |
||
62 | 3 | public function show($route_info) |
|
63 | { |
||
64 | 1 | $this->user->add_lang_ext('blitze/sitemaker', 'block_manager'); |
|
65 | |||
66 | 1 | $this->phpbb_container->get('blitze.sitemaker.auto_lang')->add('blocks_admin'); |
|
67 | |||
68 | 1 | $route = $route_info['route']; |
|
69 | 1 | $style_id = $route_info['style']; |
|
70 | |||
71 | 1 | $this->get_available_blocks(); |
|
72 | 1 | $this->get_startpage_options(); |
|
73 | 1 | $this->set_javascript_data($route, $style_id); |
|
74 | 1 | $this->set_assets(); |
|
75 | |||
76 | 1 | $this->template->assign_vars(array( |
|
77 | 1 | 'S_EDIT_MODE' => true, |
|
78 | 1 | 'S_ROUTE_OPS' => $this->get_route_options($route), |
|
79 | 1 | 'S_HIDE_BLOCKS' => $route_info['hide_blocks'], |
|
80 | 1 | 'S_POSITION_OPS' => $this->get_excluded_position_options($route_info['ex_positions']), |
|
81 | 1 | 'S_EX_POSITIONS' => join(', ', $route_info['ex_positions']), |
|
82 | 1 | 'S_STYLE_OPTIONS' => style_select($style_id, true), |
|
83 | 1 | 'S_STARTPAGE' => $this->_startpage_is_set(), |
|
84 | |||
85 | 1 | 'ICON_PICKER' => $this->icons->picker(), |
|
86 | 3 | )); |
|
87 | 1 | } |
|
88 | |||
89 | /** |
||
90 | * Set data used in javascript |
||
91 | */ |
||
92 | 3 | public function set_javascript_data($route, $style_id) |
|
93 | { |
||
94 | 3 | $board_url = generate_board_url(); |
|
95 | 3 | $ajax_url = $board_url . ((!$this->config['enable_mod_rewrite']) ? '/app.' . $this->php_ext : ''); |
|
96 | |||
97 | 3 | $is_default_route = $u_default_route = false; |
|
98 | 3 | if ($this->config['sitemaker_default_layout']) |
|
99 | 3 | { |
|
100 | 1 | $is_default_route = ($this->config['sitemaker_default_layout'] === $route) ? true : false; |
|
101 | 1 | $u_default_route .= $board_url . '/' . $this->config['sitemaker_default_layout']; |
|
102 | 1 | $u_default_route = reapply_sid($u_default_route); |
|
103 | 1 | } |
|
104 | |||
105 | 3 | $this->template->assign_vars(array( |
|
106 | 3 | 'S_IS_DEFAULT' => $is_default_route, |
|
107 | |||
108 | 3 | 'PAGE_URL' => build_url(array('style')), |
|
109 | |||
110 | 3 | 'UA_ROUTE' => $route, |
|
111 | 3 | 'UA_AJAX_URL' => $ajax_url, |
|
112 | 3 | 'UA_BOARD_URL' => $board_url, |
|
113 | 3 | 'UA_STYLE_ID' => $style_id, |
|
114 | |||
115 | 3 | 'U_VIEW_DEFAULT' => $u_default_route, |
|
116 | 3 | )); |
|
117 | 3 | } |
|
118 | |||
119 | /** |
||
120 | * Get all available sitemaker blocks |
||
121 | */ |
||
122 | 2 | public function get_available_blocks() |
|
123 | { |
||
124 | 2 | $blocks = $this->phpbb_container->get('blitze.sitemaker.blocks.factory')->get_all_blocks(); |
|
125 | |||
126 | 2 | foreach ($blocks as $service => $name) |
|
127 | { |
||
128 | 2 | $this->template->assign_block_vars('block', array( |
|
129 | 2 | 'NAME' => $name, |
|
130 | 2 | 'SERVICE' => $service) |
|
131 | 2 | ); |
|
132 | 2 | } |
|
133 | 2 | } |
|
134 | |||
135 | 4 | public function get_startpage_options() |
|
136 | { |
||
137 | 4 | $symfony_request = $this->phpbb_container->get('symfony_request'); |
|
138 | 4 | $controller = $symfony_request->attributes->get('_controller'); |
|
139 | |||
140 | 4 | if ($controller && $controller !== 'blitze.sitemaker.forum.controller:handle') |
|
141 | 4 | { |
|
142 | 2 | list($controller_service, $controller_method) = explode(':', $controller); |
|
143 | 2 | $controller_params = $symfony_request->attributes->get('_route_params'); |
|
144 | 2 | $controller_object = $this->phpbb_container->get($controller_service); |
|
145 | 2 | $controller_class = get_class($controller_object); |
|
146 | |||
147 | 2 | $r = new \ReflectionMethod($controller_class, $controller_method); |
|
148 | 2 | $params = $r->getParameters(); |
|
149 | |||
150 | 2 | $arguments = array(); |
|
151 | 2 | foreach ($params as $param) |
|
152 | { |
||
153 | 2 | $name = $param->getName(); |
|
154 | 2 | $arguments[$name] = ($param->isOptional()) ? $param->getDefaultValue() : $controller_params[$name]; |
|
155 | 2 | } |
|
156 | |||
157 | 2 | list($namespace, $extension) = explode('\\', $controller_class); |
|
158 | 2 | $controller_arguments = join('/', $arguments); |
|
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 | 4 | } |
|
169 | |||
170 | 1 | public function set_assets() |
|
186 | |||
187 | /** |
||
188 | * Get routes with blocks |
||
189 | */ |
||
190 | 3 | public function get_route_options($current_route) |
|
203 | |||
204 | /** |
||
205 | * Get excluded position options |
||
206 | */ |
||
207 | 3 | public function get_excluded_position_options($ex_positions) |
|
217 | |||
218 | /** |
||
219 | * @return array |
||
220 | */ |
||
221 | 3 | protected function _get_routes() |
|
235 | |||
236 | /** |
||
237 | * @param string $controller_service |
||
238 | * @param string $controller_arguments |
||
239 | * @return bool |
||
240 | */ |
||
241 | 2 | protected function _is_startpage($controller_service, $controller_arguments) |
|
245 | |||
246 | /** |
||
247 | * @return bool |
||
248 | */ |
||
249 | 1 | protected function _startpage_is_set() |
|
253 | } |
||
254 |