|
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\acp; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @package acp |
|
15
|
|
|
*/ |
|
16
|
|
|
class settings_module |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var \phpbb\config\config */ |
|
19
|
|
|
protected $config; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \phpbb\config\db_text */ |
|
22
|
|
|
protected $config_text; |
|
23
|
|
|
|
|
24
|
|
|
/** @var \phpbb\db\driver\driver_interface */ |
|
25
|
|
|
protected $db; |
|
26
|
|
|
|
|
27
|
|
|
/** @var \phpbb\finder */ |
|
28
|
|
|
protected $finder; |
|
29
|
|
|
|
|
30
|
|
|
/** @var \phpbb\event\dispatcher_interface */ |
|
31
|
|
|
protected $phpbb_dispatcher; |
|
32
|
|
|
|
|
33
|
|
|
/** @var \phpbb\request\request_interface */ |
|
34
|
|
|
protected $request; |
|
35
|
|
|
|
|
36
|
|
|
/** @var \phpbb\template\template */ |
|
37
|
|
|
protected $template; |
|
38
|
|
|
|
|
39
|
|
|
/** @var \phpbb\language\language */ |
|
40
|
|
|
protected $translator; |
|
41
|
|
|
|
|
42
|
|
|
/** @var \phpbb\user */ |
|
43
|
|
|
protected $user; |
|
44
|
|
|
|
|
45
|
|
|
/** @var \blitze\sitemaker\services\icons\picker */ |
|
46
|
|
|
protected $icon; |
|
47
|
|
|
|
|
48
|
|
|
/** @var \blitze\sitemaker\services\blocks\cleaner */ |
|
49
|
|
|
protected $blocks_cleaner; |
|
50
|
|
|
|
|
51
|
|
|
/** @var \blitze\sitemaker\model\mapper_factory */ |
|
52
|
|
|
protected $mapper_factory; |
|
53
|
|
|
|
|
54
|
|
|
/** @var string phpBB root path */ |
|
55
|
|
|
protected $phpbb_root_path; |
|
56
|
|
|
|
|
57
|
|
|
/** @var string phpEx */ |
|
58
|
|
|
protected $php_ext; |
|
59
|
|
|
|
|
60
|
|
|
/** @var string */ |
|
61
|
|
|
public $tpl_name; |
|
62
|
|
|
|
|
63
|
|
|
/** @var string */ |
|
64
|
|
|
public $page_title; |
|
65
|
|
|
|
|
66
|
|
|
/** @var string */ |
|
67
|
|
|
public $u_action; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* settings_module constructor. |
|
71
|
2 |
|
*/ |
|
72
|
|
|
public function __construct() |
|
73
|
2 |
|
{ |
|
74
|
|
|
global $phpbb_container, $phpbb_dispatcher, $config, $db, $request, $template, $user, $phpbb_root_path, $phpEx; |
|
75
|
2 |
|
|
|
76
|
2 |
|
$this->db = $db; |
|
77
|
2 |
|
$this->config = $config; |
|
78
|
2 |
|
$this->phpbb_dispatcher = $phpbb_dispatcher; |
|
79
|
2 |
|
$this->request = $request; |
|
80
|
2 |
|
$this->template = $template; |
|
81
|
2 |
|
$this->user = $user; |
|
82
|
|
|
$this->phpbb_root_path = $phpbb_root_path; |
|
83
|
2 |
|
$this->php_ext = $phpEx; |
|
84
|
2 |
|
|
|
85
|
2 |
|
$this->config_text = $phpbb_container->get('config_text'); |
|
86
|
2 |
|
$this->finder = $phpbb_container->get('ext.manager')->get_finder(); |
|
87
|
2 |
|
$this->translator = $phpbb_container->get('language'); |
|
88
|
2 |
|
$this->blocks_cleaner = $phpbb_container->get('blitze.sitemaker.blocks.cleaner'); |
|
89
|
2 |
|
$this->icon = $phpbb_container->get('blitze.sitemaker.icons.picker'); |
|
90
|
2 |
|
$this->mapper_factory = $phpbb_container->get('blitze.sitemaker.mapper.factory'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return void |
|
95
|
1 |
|
*/ |
|
96
|
|
|
public function main() |
|
97
|
1 |
|
{ |
|
98
|
1 |
|
$this->translator->add_lang('acp/board'); |
|
99
|
|
|
$this->translator->add_lang(['blocks_admin', 'navbar_manager'], 'blitze/sitemaker'); |
|
100
|
1 |
|
|
|
101
|
|
|
$form_key = 'blitze/sitemaker/settings'; |
|
102
|
1 |
|
|
|
103
|
|
|
$this->handle_cleanup($form_key); |
|
104
|
1 |
|
$this->handle_submit($form_key); |
|
105
|
|
|
|
|
106
|
1 |
|
add_form_key($form_key); |
|
107
|
|
|
|
|
108
|
|
|
$layouts = $this->get_layouts(); |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Event to display acp settings form |
|
112
|
|
|
* |
|
113
|
|
|
* @event blitze.sitemaker.acp_display_settings_form |
|
114
|
|
|
* @var array layouts Array of layout settings |
|
115
|
1 |
|
* @since 3.1.0 |
|
116
|
1 |
|
*/ |
|
117
|
|
|
$vars = array('layouts'); |
|
118
|
1 |
|
extract($this->phpbb_dispatcher->trigger_event('blitze.sitemaker.acp_display_settings_form', compact($vars))); |
|
119
|
1 |
|
|
|
120
|
1 |
|
$this->template->assign_vars(array( |
|
121
|
1 |
|
'u_action' => $this->u_action, |
|
122
|
1 |
|
'icon_picker' => $this->icon->picker(), |
|
123
|
1 |
|
'config' => $this->config, |
|
124
|
1 |
|
'styles' => $this->get_styles_data($layouts), |
|
125
|
1 |
|
'layouts' => $layouts, |
|
126
|
1 |
|
'menu_options' => $this->get_menu_options(), |
|
127
|
|
|
'sm_user_lang' => $this->user->data['user_lang'], |
|
128
|
1 |
|
)); |
|
129
|
1 |
|
|
|
130
|
1 |
|
$this->tpl_name = 'acp_settings'; |
|
131
|
|
|
$this->page_title = 'ACP_SM_SETTINGS'; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* @param string $form_key |
|
136
|
2 |
|
* @return void |
|
137
|
|
|
*/ |
|
138
|
2 |
|
protected function handle_cleanup($form_key) |
|
139
|
2 |
|
{ |
|
140
|
1 |
|
if (!$this->request->is_set_post('submit') && $orphans = $this->blocks_cleaner->get_orphans()) |
|
141
|
|
|
{ |
|
142
|
1 |
|
$components = $this->request->variable('cleanup', array(0 => '')); |
|
143
|
|
|
|
|
144
|
|
|
if ($this->request->is_set_post('orphans') && sizeof($components)) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->check_form_key($form_key); |
|
147
|
|
|
$this->blocks_cleaner->run($components); |
|
148
|
|
|
|
|
149
|
|
|
trigger_error($this->translator->lang('BLOCKS_CLEANUP_DONE') . adm_back_link($this->u_action)); |
|
150
|
|
|
} |
|
151
|
1 |
|
|
|
152
|
1 |
|
$this->template->assign_var('orphaned_blocks', $orphans); |
|
153
|
|
|
} |
|
154
|
1 |
|
} |
|
155
|
1 |
|
|
|
156
|
1 |
|
/** |
|
157
|
1 |
|
* @param string $form_key |
|
158
|
2 |
|
* @return void |
|
159
|
|
|
*/ |
|
160
|
|
|
protected function handle_submit($form_key) |
|
161
|
|
|
{ |
|
162
|
|
|
if ($this->request->is_set_post('submit')) |
|
163
|
1 |
|
{ |
|
164
|
|
|
$settings = $this->request->variable('config', array('' => '')); |
|
165
|
1 |
|
|
|
166
|
1 |
|
$this->check_form_key($form_key); |
|
167
|
1 |
|
|
|
168
|
1 |
|
/** |
|
169
|
1 |
|
* Event to save acp settings |
|
170
|
|
|
* |
|
171
|
|
|
* @event blitze.sitemaker.acp_save_settings |
|
172
|
|
|
* @var array settings Array of settings: [config_key] => [config_value] |
|
173
|
|
|
* @since 3.1.0 |
|
174
|
|
|
*/ |
|
175
|
1 |
|
$vars = array('settings'); |
|
176
|
|
|
extract($this->phpbb_dispatcher->trigger_event('blitze.sitemaker.acp_save_settings', compact($vars))); |
|
177
|
1 |
|
|
|
178
|
|
|
$this->save_config_settings($settings); |
|
179
|
1 |
|
|
|
180
|
|
|
trigger_error($this->translator->lang('SETTINGS_SAVED') . adm_back_link($this->u_action)); |
|
181
|
1 |
|
} |
|
182
|
1 |
|
} |
|
183
|
|
|
|
|
184
|
1 |
|
/** |
|
185
|
|
|
* @param string $form_key |
|
186
|
1 |
|
*/ |
|
187
|
|
|
protected function check_form_key($form_key) |
|
188
|
1 |
|
{ |
|
189
|
1 |
|
if (!check_form_key($form_key)) |
|
190
|
1 |
|
{ |
|
191
|
1 |
|
trigger_error('FORM_INVALID', E_USER_WARNING); |
|
192
|
1 |
|
} |
|
193
|
|
|
} |
|
194
|
1 |
|
|
|
195
|
1 |
|
/** |
|
196
|
|
|
* @param array $layouts |
|
197
|
1 |
|
* @return array |
|
198
|
|
|
*/ |
|
199
|
|
|
protected function get_styles_data(array $layouts) |
|
200
|
|
|
{ |
|
201
|
|
|
$style_prefs = (array) json_decode((string) $this->config_text->get('sm_layout_prefs'), true); |
|
202
|
|
|
|
|
203
|
|
|
$result = $this->db->sql_query('SELECT style_id, style_name FROM ' . STYLES_TABLE); |
|
204
|
|
|
|
|
205
|
|
|
$styles = array(); |
|
206
|
1 |
|
while ($row = $this->db->sql_fetchrow($result)) |
|
207
|
|
|
{ |
|
208
|
|
|
$id = $row['style_id']; |
|
209
|
1 |
|
|
|
210
|
1 |
|
$pref = $this->get_style_pref($id, $style_prefs, $layouts['portal']); |
|
211
|
1 |
|
|
|
212
|
|
|
$styles[] = array( |
|
213
|
1 |
|
'id' => $id, |
|
214
|
1 |
|
'name' => $row['style_name'], |
|
215
|
1 |
|
'layout' => $pref['layout'], |
|
216
|
1 |
|
'view' => $pref['view'], |
|
217
|
|
|
); |
|
218
|
1 |
|
} |
|
219
|
|
|
$this->db->sql_freeresult(); |
|
220
|
|
|
|
|
221
|
|
|
return $styles; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @param int $style_id |
|
226
|
1 |
|
* @param array $style_prefs |
|
227
|
|
|
* @param string $default_layout |
|
228
|
1 |
|
* @return array |
|
229
|
1 |
|
*/ |
|
230
|
|
|
protected function get_style_pref($style_id, array $style_prefs, $default_layout) |
|
231
|
|
|
{ |
|
232
|
|
|
$pref = array( |
|
233
|
|
|
'layout' => $default_layout, |
|
234
|
1 |
|
'view' => '', |
|
235
|
|
|
); |
|
236
|
1 |
|
|
|
237
|
1 |
|
if (isset($style_prefs[$style_id])) |
|
238
|
1 |
|
{ |
|
239
|
1 |
|
$pref = $style_prefs[$style_id]; |
|
240
|
1 |
|
} |
|
241
|
|
|
|
|
242
|
1 |
|
return $pref; |
|
243
|
1 |
|
} |
|
244
|
|
|
|
|
245
|
1 |
|
/** |
|
246
|
1 |
|
* @return array |
|
247
|
|
|
*/ |
|
248
|
1 |
|
protected function get_layouts() |
|
249
|
1 |
|
{ |
|
250
|
1 |
|
$files = $this->finder |
|
251
|
|
|
->suffix('_layout.twig') |
|
252
|
1 |
|
->extension_directory('/styles') |
|
253
|
|
|
->find(); |
|
254
|
|
|
$files = array_keys($files); |
|
255
|
|
|
|
|
256
|
|
|
$layouts = array(); |
|
257
|
|
|
foreach ($files as $path) |
|
258
|
|
|
{ |
|
259
|
1 |
|
$path = dirname($path); |
|
260
|
|
|
$name = basename($path); |
|
261
|
1 |
|
|
|
262
|
|
|
$layouts[$name] = $this->phpbb_root_path . $path . '/'; |
|
263
|
1 |
|
} |
|
264
|
|
|
ksort($layouts); |
|
265
|
1 |
|
|
|
266
|
|
|
return $layouts; |
|
267
|
1 |
|
} |
|
268
|
1 |
|
|
|
269
|
1 |
|
/** |
|
270
|
|
|
* @param array $settings |
|
271
|
|
|
* @return void |
|
272
|
|
|
*/ |
|
273
|
|
|
protected function save_config_settings(array $settings) |
|
274
|
|
|
{ |
|
275
|
1 |
|
$layout_prefs = $this->request->variable('layouts', array(0 => array('' => ''))); |
|
276
|
|
|
|
|
277
|
1 |
|
$this->config_text->set('sm_layout_prefs', json_encode($layout_prefs)); |
|
278
|
|
|
|
|
279
|
1 |
|
foreach ($settings as $key => $value) |
|
280
|
1 |
|
{ |
|
281
|
1 |
|
$this->config->set($key, $value); |
|
282
|
1 |
|
} |
|
283
|
1 |
|
} |
|
284
|
|
|
|
|
285
|
1 |
|
/** |
|
286
|
1 |
|
* @return string |
|
287
|
|
|
*/ |
|
288
|
|
|
protected function get_menu_options() |
|
289
|
|
|
{ |
|
290
|
|
|
$menu_mapper = $this->mapper_factory->create('menus'); |
|
291
|
1 |
|
|
|
292
|
|
|
// Get all menus |
|
293
|
|
|
$collection = $menu_mapper->find(); |
|
294
|
|
|
|
|
295
|
|
|
$options = ''; |
|
296
|
1 |
|
foreach ($collection as $entity) |
|
297
|
|
|
{ |
|
298
|
1 |
|
$id = $entity->get_menu_id(); |
|
299
|
|
|
$name = $entity->get_menu_name(); |
|
300
|
|
|
$selected = ($id == $this->config['sm_navbar_menu']) ? ' selected="selected"' : ''; |
|
301
|
1 |
|
$options .= '<option value="' . $id . '"' . $selected . '>' . $name . '</option>'; |
|
302
|
|
|
} |
|
303
|
1 |
|
|
|
304
|
1 |
|
return $options; |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
|