This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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, $style_id, $edit_mode); |
|
76 | 19 | } |
|
77 | } |
||
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | 17 | protected function get_current_route() |
|
83 | { |
||
84 | 17 | $current_route = ltrim($this->user->page['page_dir'] . '/' . $this->user->page['page_name'], './') . ($this->user->page['forum'] ? '?f=' . $this->user->page['forum'] : ''); |
|
85 | 17 | return substr($current_route, 0, 100); |
|
86 | 2 | } |
|
87 | |||
88 | /** |
||
89 | * Get style id |
||
90 | 15 | * @return int |
|
91 | */ |
||
92 | public function get_style_id() |
||
93 | { |
||
94 | if ($this->request->is_set('style')) |
||
95 | { |
||
96 | return $this->request->variable('style', 0); |
||
97 | 19 | } |
|
98 | else |
||
99 | 19 | { |
|
100 | 19 | return (int) ((!$this->config['override_user_style']) ? $this->user->data['user_style'] : $this->config['default_style']); |
|
101 | } |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @return bool |
||
106 | 17 | */ |
|
107 | protected function page_can_have_blocks() |
||
108 | 17 | { |
|
109 | $offlimits = array('ucp.php', 'mcp.php', 'memberlist.php'); |
||
110 | 17 | return ($this->user->page['page_dir'] == 'adm' || in_array($this->user->page['page_name'], $offlimits)) ? false : true; |
|
111 | 17 | } |
|
112 | 15 | ||
113 | 15 | /** |
|
114 | 15 | * @return bool |
|
115 | */ |
||
116 | 17 | protected function toggle_edit_mode() |
|
117 | { |
||
118 | $edit_mode = $this->request->variable($this->config['cookie_name'] . '_sm_edit_mode', false, false, \phpbb\request\request_interface::COOKIE); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
119 | |||
120 | if ($this->request->is_set('edit_mode')) |
||
121 | { |
||
122 | $edit_mode = $this->request->variable('edit_mode', false); |
||
123 | 17 | $this->user->set_cookie('sm_edit_mode', $edit_mode, 0); |
|
124 | } |
||
125 | 17 | ||
126 | 17 | return $edit_mode; |
|
127 | } |
||
128 | 12 | ||
129 | 12 | /** |
|
130 | 12 | * @param bool $is_sub_route |
|
131 | 12 | * @return array |
|
132 | 12 | */ |
|
133 | protected function get_display_modes($is_sub_route) |
||
134 | { |
||
135 | if ($is_sub_route === false) |
||
136 | 5 | { |
|
137 | 5 | $modes = array( |
|
138 | 5 | self::SHOW_ON_ALL_ROUTES => true, |
|
139 | 5 | self::SHOW_ON_PARENT_ROUTE_ONLY => true, |
|
140 | self::SHOW_ON_CHILD_ROUTE_ONLY => false, |
||
141 | ); |
||
142 | 17 | } |
|
143 | else |
||
144 | { |
||
145 | $modes = array( |
||
146 | self::SHOW_ON_ALL_ROUTES => true, |
||
147 | self::SHOW_ON_PARENT_ROUTE_ONLY => false, |
||
148 | self::SHOW_ON_CHILD_ROUTE_ONLY => true, |
||
149 | ); |
||
150 | 17 | } |
|
151 | |||
152 | 17 | return $modes; |
|
153 | 17 | } |
|
154 | 17 | ||
155 | /** |
||
156 | 5 | * @param bool $edit_mode |
|
157 | * @param array $modes |
||
158 | 4 | * @return string |
|
159 | 4 | */ |
|
160 | 4 | protected function get_edit_mode_url(&$edit_mode, array &$modes) |
|
161 | 4 | { |
|
162 | 4 | $u_edit_mode = ''; |
|
163 | if ($this->auth->acl_get('a_sm_manage_blocks')) |
||
164 | 5 | { |
|
165 | 5 | if ($edit_mode) |
|
166 | { |
||
167 | $modes = array( |
||
168 | 12 | self::SHOW_ON_ALL_ROUTES => true, |
|
169 | self::SHOW_ON_PARENT_ROUTE_ONLY => true, |
||
170 | self::SHOW_ON_CHILD_ROUTE_ONLY => true, |
||
171 | 17 | ); |
|
172 | } |
||
173 | |||
174 | $u_edit_mode = append_sid(generate_board_url() . '/' . ltrim(rtrim(build_url(array('edit_mode', 'sid', 'style')), '?'), './../'), 'edit_mode=' . (int) !$edit_mode); |
||
175 | } |
||
176 | else |
||
177 | { |
||
178 | 17 | $edit_mode = false; |
|
179 | } |
||
180 | 17 | ||
181 | return $u_edit_mode; |
||
182 | 17 | } |
|
183 | |||
184 | /** |
||
185 | * @param int $style_id |
||
186 | * @return string |
||
187 | */ |
||
188 | protected function get_layout($style_id) |
||
189 | { |
||
190 | $style_prefs = array_filter((array) json_decode((string) $this->config_text->get('sm_layout_prefs'), true)); |
||
191 | |||
192 | 17 | return (isset($style_prefs[$style_id])) ? basename($style_prefs[$style_id]['layout']) : 'portal'; |
|
193 | } |
||
194 | 17 | ||
195 | /** |
||
196 | 17 | * @param int $style_id |
|
197 | 17 | * @return string |
|
198 | 17 | */ |
|
199 | protected function get_column_widths($style_id) |
||
200 | 17 | { |
|
201 | $column_widths = array_filter((array) json_decode($this->config['sitemaker_column_widths'], true)); |
||
202 | 17 | ||
203 | 17 | return (isset($column_widths[$style_id])) ? $column_widths[$style_id] : ''; |
|
204 | 15 | } |
|
205 | 15 | ||
206 | /** |
||
207 | 17 | * @param int $style_id |
|
208 | 17 | * @param string $current_route |
|
209 | 17 | * @param int $style_id |
|
210 | 17 | * @param bool $edit_mode |
|
211 | 17 | */ |
|
212 | 17 | protected function show_sitemaker($current_route, $style_id, $edit_mode) |
|
213 | { |
||
214 | /** @var \blitze\sitemaker\services\blocks\blocks $blocks */ |
||
215 | $blocks = $this->phpbb_container->get('blitze.sitemaker.blocks'); |
||
216 | |||
217 | $page_dir = $this->user->page['page_dir']; |
||
218 | 17 | $forum_id = $this->user->page['forum']; |
|
219 | |||
220 | $route_info = $blocks->get_route_info($current_route, $page_dir, $forum_id, $style_id, $edit_mode); |
||
221 | 17 | $display_modes = $this->get_display_modes($route_info['is_sub_route']); |
|
222 | 4 | $u_edit_mode = $this->get_edit_mode_url($edit_mode, $display_modes); |
|
223 | 4 | ||
224 | 17 | $this->show_admin_bar($edit_mode, $route_info); |
|
225 | |||
226 | if ($edit_mode || !$route_info['hide_blocks']) |
||
227 | { |
||
228 | $blocks->display($edit_mode, $route_info, $display_modes); |
||
229 | } |
||
230 | |||
231 | $this->template->assign_vars(array( |
||
232 | 'S_SITEMAKER' => true, |
||
233 | 'S_LAYOUT' => $this->get_layout($style_id), |
||
234 | 'S_COLUMN_WIDTHS' => $this->get_column_widths($style_id), |
||
235 | 'U_EDIT_MODE' => $u_edit_mode, |
||
236 | )); |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * @param bool $edit_mode |
||
241 | * @param array $route_info |
||
242 | */ |
||
243 | protected function show_admin_bar($edit_mode, array $route_info) |
||
244 | { |
||
245 | if ($edit_mode) |
||
246 | { |
||
247 | $this->phpbb_container->get('blitze.sitemaker.blocks.admin_bar')->show($route_info); |
||
248 | } |
||
249 | } |
||
250 | } |
||
251 |