1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* @package Board3 Portal v2.1 |
5
|
|
|
* @copyright (c) 2013 Board3 Group ( www.board3.de ) |
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
7
|
|
|
* |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace board3\portal\acp; |
11
|
|
|
|
12
|
|
|
class portal_module |
13
|
|
|
{ |
14
|
|
|
public $u_action; |
15
|
|
|
public $new_config = array(); |
16
|
|
|
|
17
|
|
|
/** @var \board3\portal\modules\module_interface */ |
18
|
|
|
protected $c_class; |
19
|
|
|
|
20
|
|
|
protected $db, $user, $cache, $template, $display_vars, $config, $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container; |
21
|
|
|
protected $root_path, $request, $php_ext, $portal_helper, $modules_helper, $log, $portal_columns; |
22
|
|
|
|
23
|
|
|
/** @var \board3\portal\portal\modules\manager */ |
24
|
|
|
protected $modules_manager; |
25
|
|
|
|
26
|
|
|
/** @var \board3\portal\portal\modules\constraints_handler */ |
27
|
|
|
protected $modules_constraints; |
28
|
|
|
|
29
|
|
|
/** @var \board3\portal\controller\helper */ |
30
|
|
|
protected $board3_controller_helper; |
31
|
|
|
|
32
|
|
|
/** @var int Board3 module enabled */ |
33
|
|
|
const B3_MODULE_ENABLED = 1; |
34
|
|
|
|
35
|
34 |
|
public function __construct() |
36
|
|
|
{ |
37
|
34 |
|
global $db, $user, $cache, $request, $template, $table_prefix; |
38
|
34 |
|
global $config, $phpbb_root_path, $phpbb_admin_path, $phpbb_container, $phpEx, $phpbb_log; |
39
|
|
|
|
40
|
34 |
|
$user->add_lang_ext('board3/portal', array('portal', 'portal_acp')); |
41
|
|
|
|
42
|
34 |
|
$this->root_path = $phpbb_root_path . 'ext/board3/portal/'; |
43
|
|
|
|
44
|
34 |
|
$this->db = $db; |
45
|
34 |
|
$this->user = $user; |
46
|
34 |
|
$this->cache = $cache; |
47
|
34 |
|
$this->template = $template; |
48
|
34 |
|
$this->config = $config; |
49
|
34 |
|
$this->request = $request; |
50
|
34 |
|
$this->phpbb_root_path = $phpbb_root_path; |
51
|
34 |
|
$this->phpbb_admin_path = $phpbb_admin_path; |
52
|
34 |
|
$this->php_ext = $phpEx; |
53
|
34 |
|
$this->phpbb_container = $phpbb_container; |
54
|
34 |
|
$this->portal_helper = $this->phpbb_container->get('board3.portal.helper'); |
55
|
34 |
|
$this->modules_helper = $this->phpbb_container->get('board3.portal.modules_helper'); |
56
|
34 |
|
$this->log = $phpbb_log; |
57
|
34 |
|
$this->portal_columns = $this->phpbb_container->get('board3.portal.columns'); |
58
|
34 |
|
$this->modules_manager = $this->phpbb_container->get('board3.portal.modules.manager'); |
59
|
34 |
|
$this->modules_constraints = $this->phpbb_container->get('board3.portal.modules.constraints_handler'); |
60
|
34 |
|
$this->board3_controller_helper = $this->phpbb_container->get('board3.portal.controller_helper'); |
61
|
|
|
|
62
|
34 |
|
if (!defined('PORTAL_MODULES_TABLE')) |
63
|
34 |
|
{ |
64
|
1 |
|
define('PORTAL_MODULES_TABLE', $this->phpbb_container->getParameter('board3.portal.modules.table')); |
65
|
1 |
|
define('PORTAL_CONFIG_TABLE', $this->phpbb_container->getParameter('board3.portal.config.table')); |
66
|
1 |
|
} |
67
|
|
|
|
68
|
34 |
|
if (!function_exists('obtain_portal_config')) |
69
|
34 |
|
{ |
70
|
|
|
include($this->root_path . 'includes/functions.' . $this->php_ext); |
71
|
|
|
} |
72
|
34 |
|
} |
73
|
|
|
|
74
|
3 |
|
public function main($id, $mode) |
75
|
|
|
{ |
76
|
3 |
|
$submit = ($this->request->is_set_post('submit')) ? true : false; |
77
|
|
|
|
78
|
3 |
|
$form_key = 'acp_portal'; |
79
|
3 |
|
add_form_key($form_key); |
80
|
|
|
|
81
|
|
|
// Setup modules manager class |
82
|
3 |
|
$this->modules_manager->set_u_action($this->u_action) |
83
|
3 |
|
->set_acp_class(__CLASS__); |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Validation types are: |
87
|
|
|
* string, int, bool, |
88
|
|
|
* script_path (absolute path in url - beginning with / and no trailing slash), |
89
|
|
|
* rpath (relative), rwpath (realtive, writeable), path (relative path, but able to escape the root), wpath (writeable) |
90
|
|
|
*/ |
91
|
|
|
switch ($mode) |
92
|
|
|
{ |
93
|
3 |
|
case 'config': |
94
|
|
|
$display_vars = array( |
95
|
2 |
|
'title' => 'ACP_PORTAL_GENERAL_TITLE', |
96
|
|
|
'vars' => array( |
97
|
2 |
|
'legend1' => 'ACP_PORTAL_CONFIG_INFO', |
98
|
2 |
|
'board3_enable' => array('lang' => 'PORTAL_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
99
|
2 |
|
'board3_left_column' => array('lang' => 'PORTAL_LEFT_COLUMN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
100
|
2 |
|
'board3_right_column' => array('lang' => 'PORTAL_RIGHT_COLUMN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
101
|
2 |
|
'board3_display_jumpbox' => array('lang' => 'PORTAL_DISPLAY_JUMPBOX', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
102
|
|
|
|
103
|
2 |
|
'legend2' => 'ACP_PORTAL_COLUMN_WIDTH_SETTINGS', |
104
|
2 |
|
'board3_left_column_width' => array('lang' => 'PORTAL_LEFT_COLUMN_WIDTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), |
105
|
2 |
|
'board3_right_column_width' => array('lang' => 'PORTAL_RIGHT_COLUMN_WIDTH', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => true), |
106
|
|
|
|
107
|
2 |
|
'legend3' => 'ACP_PORTAL_SHOW_ALL', |
108
|
2 |
|
'board3_show_all_pages' => array('lang' => 'ACP_PORTAL_SHOW_ALL', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), |
109
|
2 |
|
'board3_show_all_side' => array('lang' => 'PORTAL_SHOW_ALL_SIDE', 'validate' => 'bool', 'type' => 'custom', 'method' => array('board3.portal.modules_helper', 'display_left_right'), 'submit' => array('board3.portal.modules_helper', 'store_left_right'), 'explain' => true), |
110
|
|
|
|
111
|
2 |
|
'legend4' => 'ACP_FA', |
112
|
2 |
|
'board3_fa_styles' => array('lang' => 'ACP_FA', 'validate' => 'string', 'type' => 'custom', 'method' => array('board3.portal.modules_helper', 'display_fa_styles'), 'submit' => array('board3.portal.modules_helper', 'store_fa_styles'), 'explain' => true), |
113
|
|
|
) |
114
|
2 |
|
); |
115
|
|
|
|
116
|
2 |
|
$module_id = $this->request->variable('module_id', 0); |
117
|
|
|
if ($module_id) |
118
|
2 |
|
{ |
119
|
|
|
$sql = 'SELECT * |
120
|
|
|
FROM ' . PORTAL_MODULES_TABLE . ' |
121
|
|
|
WHERE module_id = ' . (int) $module_id; |
122
|
|
|
$result = $this->db->sql_query_limit($sql, 1); |
123
|
|
|
$module_data = $this->db->sql_fetchrow($result); |
124
|
|
|
$this->db->sql_freeresult($result); |
125
|
|
|
|
126
|
|
|
if ($module_data !== false) |
127
|
|
|
{ |
128
|
|
|
|
129
|
|
|
if (!($this->c_class = $this->portal_helper->get_module($module_data['module_classname']))) |
130
|
|
|
{ |
131
|
|
|
continue; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// Load module language |
135
|
|
|
$this->board3_controller_helper->load_module_language($this->c_class); |
136
|
|
|
|
137
|
|
|
$module_name = $this->user->lang[$this->c_class->get_name()]; |
138
|
|
|
$display_vars = $this->c_class->get_template_acp($module_id); |
139
|
|
|
$this->template->assign_vars(array( |
140
|
|
|
'MODULE_NAME' => (isset($this->c_class->hide_name) && $this->c_class->hide_name == true)? '' : $module_data['module_name'], |
141
|
|
|
'MODULE_IMAGE' => $module_data['module_image_src'], |
142
|
|
|
'MODULE_IMAGE_WIDTH' => $module_data['module_image_width'], |
143
|
|
|
'MODULE_IMAGE_HEIGHT' => $module_data['module_image_height'], |
144
|
|
|
'MODULE_IMAGE_SRC' => ($module_data['module_image_src']) ? $this->root_path . 'styles/all/theme/images/portal/' . $module_data['module_image_src'] : '', |
145
|
|
|
'MODULE_FA' => $module_data['module_fa_icon'], |
146
|
|
|
'MODULE_FA_SIZE' => $module_data['module_fa_size'], |
147
|
|
|
'MODULE_ENABLED' => ($module_data['module_status']) ? true : false, |
148
|
|
|
'MODULE_SHOW_IMAGE' => (in_array($this->portal_columns->number_to_string($module_data['module_column']), array('center', 'top', 'bottom'))) ? false : true, |
149
|
|
|
)); |
150
|
|
|
|
151
|
|
|
if ($module_data['module_classname'] != '\board3\portal\modules\custom') |
152
|
|
|
{ |
153
|
|
|
$groups_ary = explode(',', $module_data['module_group_ids']); |
154
|
|
|
|
155
|
|
|
// get group info from database and assign the block vars |
156
|
|
|
$sql = 'SELECT group_id, group_name |
157
|
|
|
FROM ' . GROUPS_TABLE . ' |
158
|
|
|
ORDER BY group_id ASC'; |
159
|
|
|
$result = $this->db->sql_query($sql); |
160
|
|
View Code Duplication |
while ($row = $this->db->sql_fetchrow($result)) |
161
|
|
|
{ |
162
|
|
|
$this->template->assign_block_vars('permission_setting', array( |
163
|
|
|
'SELECTED' => (in_array($row['group_id'], $groups_ary)) ? true : false, |
164
|
|
|
'GROUP_NAME' => (isset($this->user->lang['G_' . $row['group_name']])) ? $this->user->lang['G_' . $row['group_name']] : $row['group_name'], |
165
|
|
|
'GROUP_ID' => $row['group_id'], |
166
|
|
|
)); |
167
|
|
|
} |
168
|
|
|
$this->db->sql_freeresult($result); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$this->template->assign_var('SHOW_MODULE_OPTIONS', true); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
175
|
2 |
|
$this->new_config = $this->config; |
176
|
2 |
|
$cfg_array = ($this->request->is_set('config')) ? $this->request->variable('config', array('' => ''), true) : $this->new_config; |
177
|
2 |
|
$error = array(); |
178
|
|
|
|
179
|
|
|
// We validate the complete config if wished |
180
|
2 |
|
validate_config_vars($display_vars['vars'], $cfg_array, $error); |
181
|
2 |
|
if ($submit && !check_form_key($form_key)) |
182
|
2 |
|
{ |
183
|
1 |
|
$error[] = $this->user->lang['FORM_INVALID']; |
184
|
1 |
|
} |
185
|
|
|
|
186
|
|
|
// Do not write values if there is an error |
187
|
2 |
|
if (sizeof($error)) |
188
|
2 |
|
{ |
189
|
1 |
|
$submit = false; |
190
|
1 |
|
} |
191
|
|
|
|
192
|
|
|
// Reset module |
193
|
2 |
|
$reset_module = $this->request->variable('module_reset', 0); |
194
|
|
|
|
195
|
2 |
|
if ($reset_module && !empty($module_data)) |
196
|
2 |
|
{ |
197
|
|
|
$this->modules_manager->reset_module($id, $mode, $module_id, $module_data); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
// We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... |
201
|
2 |
|
foreach ($display_vars['vars'] as $config_name => $null) |
202
|
|
|
{ |
203
|
2 |
|
if ($submit && ((isset($null['type']) && $null['type'] == 'custom') || (isset($null['submit_type']) && $null['submit_type'] == 'custom'))) |
204
|
2 |
|
{ |
205
|
|
|
if (!is_array($null['submit'])) |
206
|
|
|
{ |
207
|
|
|
if (method_exists($this->c_class, $null['submit'])) |
208
|
|
|
{ |
209
|
|
|
$func = array($this->c_class, $null['submit']); |
210
|
|
|
$args = ($module_id != 0) ? array($config_name, $module_id) : $config_name; |
211
|
|
|
} |
212
|
|
|
else if (function_exists($null['submit'])) |
213
|
|
|
{ |
214
|
|
|
$func = $null['submit']; |
215
|
|
|
$args = ($module_id != 0) ? array($cfg_array[$config_name], $config_name, $module_id) : $config_name; |
216
|
|
|
} |
217
|
|
|
else |
218
|
|
|
{ |
219
|
|
|
throw new \RuntimeException($this->user->lang('UNKNOWN_MODULE_METHOD', $module_data['module_classname'])); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
else |
223
|
|
|
{ |
224
|
|
|
if ($null['submit'][0] == 'board3.portal.modules_helper') |
225
|
|
|
{ |
226
|
|
|
$func = array($this->modules_helper, $null['submit'][1]); |
227
|
|
|
$args = ($module_id != 0) ? array($config_name, $module_id) : array($config_name); |
228
|
|
|
} |
229
|
|
|
else |
230
|
|
|
{ |
231
|
|
|
$args = ($module_id != 0) ? array($cfg_array[$config_name], $config_name, $module_id) : array($config_name); |
232
|
|
|
$func = $null['submit']; |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
call_user_func_array($func, $args); |
237
|
|
|
} |
238
|
|
|
|
239
|
2 |
|
if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) |
240
|
2 |
|
{ |
241
|
2 |
|
continue; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
if (isset($null['type']) && $null['type'] == 'custom') |
245
|
|
|
{ |
246
|
|
|
continue; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
$this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; |
250
|
|
|
|
251
|
|
|
if ($submit) |
252
|
|
|
{ |
253
|
|
|
$this->config->set($config_name, $config_value); |
254
|
|
|
} |
255
|
2 |
|
} |
256
|
|
|
|
257
|
|
|
if ($submit) |
258
|
2 |
|
{ |
259
|
|
|
$module_permission = $this->request->variable('permission-setting', array(0 => '')); |
260
|
|
|
$groups_ary = array(); |
261
|
|
|
|
262
|
|
|
// get groups and check if the selected groups actually exist |
263
|
|
|
$sql = 'SELECT group_id |
264
|
|
|
FROM ' . GROUPS_TABLE . ' |
265
|
|
|
ORDER BY group_id ASC'; |
266
|
|
|
$result = $this->db->sql_query($sql); |
267
|
|
|
while ($row = $this->db->sql_fetchrow($result)) |
268
|
|
|
{ |
269
|
|
|
$groups_ary[] = $row['group_id']; |
270
|
|
|
} |
271
|
|
|
$this->db->sql_freeresult($result); |
272
|
|
|
|
273
|
|
|
$module_permission = array_intersect($module_permission, $groups_ary); |
274
|
|
|
$module_permission = implode(',', $module_permission); |
275
|
|
|
|
276
|
|
|
$sql_ary = array( |
277
|
|
|
'module_image_src' => $this->request->variable('module_image', ''), |
278
|
|
|
'module_image_width' => $this->request->variable('module_img_width', 0), |
279
|
|
|
'module_image_height' => $this->request->variable('module_img_height', 0), |
280
|
|
|
'module_fa_icon' => $this->request->variable('module_fa', ''), |
281
|
|
|
'module_fa_size' => $this->request->variable('module_fa_size', 16), |
282
|
|
|
'module_group_ids' => $module_permission, |
283
|
|
|
'module_status' => $this->request->variable('module_status', self::B3_MODULE_ENABLED), |
284
|
|
|
); |
285
|
|
|
|
286
|
|
|
if (!(isset($this->c_class->hide_name) && $this->c_class->hide_name == true)) |
287
|
|
|
{ |
288
|
|
|
$sql_ary['module_name'] = $this->request->variable('module_name', '', true); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
// check if module image file actually exists |
292
|
|
|
$img_error = check_file_src($sql_ary['module_image_src'], '', $module_id, false); |
293
|
|
|
|
294
|
|
|
$sql = 'UPDATE ' . PORTAL_MODULES_TABLE . ' |
295
|
|
|
SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' |
296
|
|
|
WHERE module_id = ' . (int) $module_id; |
297
|
|
|
$this->db->sql_query($sql); |
298
|
|
|
|
299
|
|
|
$this->cache->destroy('sql', PORTAL_MODULES_TABLE); |
300
|
|
|
$this->cache->destroy('sql', CONFIG_TABLE); |
301
|
|
|
|
302
|
|
|
if (isset($module_name)) |
303
|
|
|
{ |
304
|
|
|
if (isset($module_data) && $module_data['module_classname'] !== '\board3\portal\modules\custom') |
305
|
|
|
{ |
306
|
|
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_CONFIG', false, array($module_name)); |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
else |
310
|
|
|
{ |
311
|
|
|
$this->log->add('admin', $this->user->data['user_id'], $this->user->data['user_ip'], 'LOG_PORTAL_CONFIG', false, array($this->user->lang['ACP_PORTAL_' . strtoupper($mode) . '_INFO'])); |
312
|
|
|
} |
313
|
|
|
trigger_error($this->user->lang['CONFIG_UPDATED'] . ((!empty($img_error) ? '<br /><br />' . $this->user->lang['MODULE_IMAGE_ERROR'] . '<br />' . $img_error : '')) . adm_back_link(($module_id) ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=\board3\portal\acp\portal_module&mode=modules') : $this->u_action)); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
// show custom HTML files on the settings page of the modules instead of the standard board3 portal one, if chosen by module |
317
|
2 |
|
if (!isset($this->c_class->custom_acp_tpl) || empty($this->c_class->custom_acp_tpl)) |
318
|
2 |
|
{ |
319
|
2 |
|
$this->tpl_name = 'portal/acp_portal_config'; |
320
|
2 |
|
} |
321
|
2 |
|
else |
322
|
2 |
|
{ |
323
|
|
|
$this->tpl_name = 'portal/' . $this->c_class->custom_acp_tpl; |
324
|
|
|
} |
325
|
2 |
|
$this->page_title = $display_vars['title']; |
326
|
|
|
|
327
|
2 |
|
$this->template->assign_vars(array( |
328
|
2 |
|
'L_TITLE' => $this->user->lang[$display_vars['title']], |
329
|
2 |
|
'L_TITLE_EXPLAIN' => (isset($this->user->lang[$display_vars['title'] . '_EXP'])) ? $this->user->lang[$display_vars['title'] . '_EXP'] : '', |
330
|
|
|
|
331
|
2 |
|
'S_ERROR' => (sizeof($error)) ? true : false, |
332
|
2 |
|
'ERROR_MSG' => implode('<br />', $error), |
333
|
|
|
|
334
|
2 |
|
'B3P_U_ACTION' => $this->modules_manager->get_module_link('config', $module_id), |
335
|
2 |
|
'B3P_ACP_ROOT' => $this->root_path, |
336
|
2 |
|
)); |
337
|
|
|
|
338
|
|
|
// Output relevant page |
339
|
2 |
|
foreach ($display_vars['vars'] as $config_key => $vars) |
340
|
|
|
{ |
341
|
2 |
|
if (!is_array($vars) && strpos($config_key, 'legend') === false) |
342
|
2 |
|
{ |
343
|
|
|
continue; |
344
|
|
|
} |
345
|
|
|
|
346
|
2 |
|
if (strpos($config_key, 'legend') !== false) |
347
|
2 |
|
{ |
348
|
2 |
|
$this->template->assign_block_vars('options', array( |
349
|
2 |
|
'S_LEGEND' => true, |
350
|
2 |
|
'LEGEND' => (isset($this->user->lang[$vars])) ? $this->user->lang[$vars] : $vars) |
351
|
2 |
|
); |
352
|
|
|
|
353
|
2 |
|
continue; |
354
|
|
|
} |
355
|
2 |
|
$this->new_config[$config_key] = $this->config[$config_key]; |
356
|
2 |
|
$type = explode(':', $vars['type']); |
357
|
|
|
|
358
|
2 |
|
$l_explain = ''; |
359
|
2 |
|
if ($vars['explain']) |
360
|
2 |
|
{ |
361
|
2 |
|
$l_explain = (isset($this->user->lang[$vars['lang'] . '_EXP'])) ? $this->user->lang[$vars['lang'] . '_EXP'] : ''; |
362
|
2 |
|
} |
363
|
|
|
|
364
|
2 |
|
if ($vars['type'] != 'custom') |
365
|
2 |
|
{ |
366
|
2 |
|
$content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); |
367
|
2 |
|
} |
368
|
|
|
else |
369
|
|
|
{ |
370
|
2 |
|
$args = array($this->new_config[$config_key], $config_key, $module_id); |
371
|
2 |
|
if (!is_array($vars['method'])) |
372
|
2 |
|
{ |
373
|
|
|
$func = array($this->c_class, $vars['method']); |
374
|
|
|
} |
375
|
|
|
else |
376
|
|
|
{ |
377
|
2 |
|
if ($vars['method'][0] == 'board3.portal.modules_helper') |
378
|
2 |
|
{ |
379
|
2 |
|
$func = array($this->modules_helper, $vars['method'][1]); |
380
|
2 |
|
} |
381
|
|
|
else |
382
|
|
|
{ |
383
|
|
|
$func = $vars['method']; |
384
|
|
|
} |
385
|
|
|
} |
386
|
2 |
|
$content = call_user_func_array($func, $args); |
387
|
|
|
} |
388
|
|
|
|
389
|
2 |
|
if (empty($content)) |
390
|
2 |
|
{ |
391
|
|
|
continue; |
392
|
|
|
} |
393
|
|
|
|
394
|
2 |
|
$this->template->assign_block_vars('options', array( |
395
|
2 |
|
'KEY' => $config_key, |
396
|
2 |
|
'TITLE' => (isset($this->user->lang[$vars['lang']])) ? $this->user->lang[$vars['lang']] : $vars['lang'], |
397
|
2 |
|
'S_EXPLAIN' => $vars['explain'], |
398
|
2 |
|
'TITLE_EXPLAIN' => $l_explain, |
399
|
2 |
|
'CONTENT' => $content, |
400
|
2 |
|
)); |
401
|
|
|
|
402
|
2 |
|
unset($display_vars['vars'][$config_key]); |
403
|
2 |
|
} |
404
|
|
|
break; |
405
|
1 |
|
case 'modules': |
406
|
|
|
$action = $this->request->variable('action', ''); |
407
|
|
|
$module_id = $this->request->variable('module_id', ''); |
408
|
|
|
|
409
|
|
|
// Create an array of already installed modules |
410
|
|
|
$portal_modules = obtain_portal_modules(); |
411
|
|
|
$installed_modules = $module_column = array(); |
412
|
|
|
|
413
|
|
|
foreach ($portal_modules as $cur_module) |
414
|
|
|
{ |
415
|
|
|
$installed_modules[] = $cur_module['module_classname']; |
416
|
|
|
// Create an array with the columns the module is in |
417
|
|
|
$module_column[$cur_module['module_classname']][] = $this->portal_columns->number_to_string($cur_module['module_column']); |
418
|
|
|
} |
419
|
|
|
$this->modules_constraints->set_module_column($module_column); |
420
|
|
|
unset($module_column); |
421
|
|
|
|
422
|
|
|
if ($action == 'move_up') |
423
|
|
|
{ |
424
|
|
|
$this->modules_manager->move_module_vertical($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_UP); |
425
|
|
|
} |
426
|
|
|
else if ($action == 'move_down') |
427
|
|
|
{ |
428
|
|
|
$this->modules_manager->move_module_vertical($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_DOWN); |
429
|
|
|
} |
430
|
|
|
else if ($action == 'move_right') |
431
|
|
|
{ |
432
|
|
|
$this->modules_manager->move_module_horizontal($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_RIGHT); |
433
|
|
|
} |
434
|
|
|
else if ($action == 'move_left') |
435
|
|
|
{ |
436
|
|
|
$this->modules_manager->move_module_horizontal($module_id, \board3\portal\portal\modules\database_handler::MOVE_DIRECTION_LEFT); |
437
|
|
|
} |
438
|
|
|
else if ($action == 'delete') |
439
|
|
|
{ |
440
|
|
|
$this->modules_manager->module_delete($id, $mode, $action, $module_id); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
$add_list = $this->request->variable('add', array('' => '')); |
444
|
|
|
$add_module = key($add_list); |
445
|
|
|
$add_column = $this->request->variable('add_column', $this->portal_columns->string_to_number($add_module)); |
446
|
|
|
if ($add_column) |
447
|
|
|
{ |
448
|
|
|
$submit = ($this->request->is_set_post('submit')) ? true : false; |
449
|
|
|
if ($submit) |
450
|
|
|
{ |
451
|
|
|
$module_classname = $this->request->variable('module_classname', ''); |
452
|
|
|
|
453
|
|
|
if (!($this->c_class = $this->portal_helper->get_module($module_classname))) |
454
|
|
|
{ |
455
|
|
|
continue; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
// Do not add modules that shouldn't be added |
459
|
|
|
if (!$this->modules_constraints->can_add_module($this->c_class, $add_column)) |
460
|
|
|
{ |
461
|
|
|
trigger_error($this->user->lang('UNABLE_TO_ADD_MODULE') . adm_back_link($this->u_action), E_USER_WARNING); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
// Do not install if module already exists in the |
465
|
|
|
// column and it can't be added more than once |
466
|
|
|
if (!$this->c_class->can_multi_include() && !$this->modules_constraints->can_move_module($this->portal_columns->number_to_string($add_column), $module_classname)) |
467
|
|
|
{ |
468
|
|
|
trigger_error($this->user->lang['MODULE_ADD_ONCE'] . adm_back_link($this->u_action), E_USER_WARNING); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
$sql = 'SELECT module_order |
472
|
|
|
FROM ' . PORTAL_MODULES_TABLE . ' |
473
|
|
|
WHERE module_column = ' . (int) $add_column . ' |
474
|
|
|
ORDER BY module_order DESC'; |
475
|
|
|
$result = $this->db->sql_query_limit($sql, 1); |
476
|
|
|
$module_order = 1 + (int) $this->db->sql_fetchfield('module_order'); |
477
|
|
|
$this->db->sql_freeresult($result); |
478
|
|
|
|
479
|
|
|
$sql_ary = array( |
480
|
|
|
'module_classname' => $module_classname, |
481
|
|
|
'module_column' => $add_column, |
482
|
|
|
'module_order' => $module_order, |
483
|
|
|
'module_name' => $this->c_class->get_name(), |
484
|
|
|
'module_image_src' => $this->c_class->get_image(), |
485
|
|
|
'module_group_ids' => '', |
486
|
|
|
'module_image_height' => 16, |
487
|
|
|
'module_image_width' => 16, |
488
|
|
|
'module_status' => self::B3_MODULE_ENABLED, |
489
|
|
|
); |
490
|
|
|
$sql = 'INSERT INTO ' . PORTAL_MODULES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); |
491
|
|
|
$this->db->sql_query($sql); |
492
|
|
|
|
493
|
|
|
$module_id = $this->db->sql_nextid(); |
494
|
|
|
|
495
|
|
|
$error = $this->c_class->install($module_id); |
496
|
|
|
|
497
|
|
|
$this->cache->purge(); // make sure we don't get errors after re-adding a module |
498
|
|
|
|
499
|
|
|
// if something went wrong, handle the errors accordingly and undo the above query |
500
|
|
|
if (!empty($error) && $error != true) |
501
|
|
|
{ |
502
|
|
|
if (is_array($error)) |
503
|
|
|
{ |
504
|
|
|
$error_output = ''; |
505
|
|
|
foreach ($error as $cur_error) |
506
|
|
|
{ |
507
|
|
|
$error_output .= $cur_error . '<br />'; |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
else |
511
|
|
|
{ |
512
|
|
|
$error_output = $error; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
$sql = 'DELETE FROM ' . PORTAL_MODULES_TABLE . ' WHERE module_id = ' . (int) $module_id; |
516
|
|
|
$this->db->sql_query($sql); |
517
|
|
|
|
518
|
|
|
trigger_error($error_output . adm_back_link($this->u_action)); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
meta_refresh(3, $this->modules_manager->get_module_link('config', $module_id)); |
522
|
|
|
|
523
|
|
|
trigger_error($this->user->lang['SUCCESS_ADD'] . adm_back_link($this->u_action)); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
$this->template->assign_var('S_EDIT', true); |
527
|
|
|
$fileinfo = $name_ary = array(); |
528
|
|
|
$modules_list = $this->portal_helper->get_all_modules(); |
529
|
|
|
|
530
|
|
|
// Find new modules |
531
|
|
|
foreach ($modules_list as $module_class => $module) |
532
|
|
|
{ |
533
|
|
|
// Module can't be added to this column |
534
|
|
|
if (!$this->modules_constraints->can_add_module($module, $add_column)) |
535
|
|
|
{ |
536
|
|
|
continue; |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
// Do not install if module already exists in the |
540
|
|
|
// column and it can't be added more than once |
541
|
|
|
if (!$module->can_multi_include() && !$this->modules_constraints->can_move_module($this->portal_columns->number_to_string($add_column), $module_class)) |
542
|
|
|
{ |
543
|
|
|
continue; |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
if ($module->get_allowed_columns() & $this->portal_columns->string_to_constant($add_module)) |
547
|
|
|
{ |
548
|
|
|
// Load module language |
549
|
|
|
$this->board3_controller_helper->load_module_language($module); |
550
|
|
|
|
551
|
|
|
$fileinfo[] = array( |
552
|
|
|
'module' => $module_class, |
553
|
|
|
'name' => $this->user->lang[$module->get_name()], |
554
|
|
|
); |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
// we sort the $fileinfo array by the name of the modules |
559
|
|
|
foreach ($fileinfo as $key => $cur_file) |
560
|
|
|
{ |
561
|
|
|
$name_ary[$key] = $cur_file['name']; |
562
|
|
|
} |
563
|
|
|
array_multisort($name_ary, SORT_REGULAR, $fileinfo); |
564
|
|
|
$options = ''; |
565
|
|
|
|
566
|
|
|
foreach ($fileinfo as $module) |
567
|
|
|
{ |
568
|
|
|
$options .= '<option value="' . $module['module'] . '">' . $module['name'] . '</option>'; |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
$s_hidden_fields = build_hidden_fields(array( |
572
|
|
|
'add_column' => $this->portal_columns->string_to_number($add_module), |
573
|
|
|
)); |
574
|
|
|
$this->template->assign_vars(array( |
575
|
|
|
'S_MODULE_NAMES' => $options, |
576
|
|
|
'S_HIDDEN_FIELDS' => $s_hidden_fields, |
577
|
|
|
)); |
578
|
|
|
|
579
|
|
|
if ($this->request->is_ajax()) |
580
|
|
|
{ |
581
|
|
|
$this->template->assign_vars(array( |
582
|
|
|
'S_AJAX_REQUEST' => true, |
583
|
|
|
'U_ACTION' => str_replace('&', '&', $this->modules_manager->get_module_link('modules', $module_id)), |
584
|
|
|
)); |
585
|
|
|
$this->template->set_filenames(array( |
586
|
|
|
'body' => 'portal/acp_portal_modules.html') |
587
|
|
|
); |
588
|
|
|
$this->modules_manager->handle_ajax_request(array( |
589
|
|
|
'MESSAGE_BODY' => $this->template->assign_display('body'), |
590
|
|
|
'MESSAGE_TITLE' => $this->user->lang['ADD_MODULE'], |
591
|
|
|
'MESSAGE_TEXT' => $this->user->lang['ADD_MODULE'], |
592
|
|
|
|
593
|
|
|
'YES_VALUE' => $this->user->lang['SUBMIT'], |
594
|
|
|
'S_CONFIRM_ACTION' => str_replace('&', '&', $this->modules_manager->get_module_link('modules', $module_id)), //inefficient, rewrite whole function |
595
|
|
|
'S_HIDDEN_FIELDS' => $s_hidden_fields |
596
|
|
|
)); |
597
|
|
|
} |
598
|
|
|
} |
599
|
|
|
else |
600
|
|
|
{ |
601
|
|
|
$portal_modules = obtain_portal_modules(); |
602
|
|
|
|
603
|
|
|
foreach ($portal_modules as $row) |
604
|
|
|
{ |
605
|
|
|
if (!($this->c_class = $this->portal_helper->get_module($row['module_classname']))) |
606
|
|
|
{ |
607
|
|
|
continue; |
608
|
|
|
} |
609
|
|
|
|
610
|
|
|
// Load module language |
611
|
|
|
$this->board3_controller_helper->load_module_language($this->c_class); |
612
|
|
|
|
613
|
|
|
$template_column = $this->portal_columns->number_to_string($row['module_column']); |
614
|
|
|
|
615
|
|
|
// find out of we can move modules to the left or right |
616
|
|
|
if (($this->c_class->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($row['module_column'] + 1))) || ($this->c_class->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($row['module_column'] + 2)) && $row['module_column'] != 2)) |
617
|
|
|
{ |
618
|
|
|
/** |
619
|
|
|
* check if we can actually move |
620
|
|
|
* this only applies to modules in the center column as the side modules |
621
|
|
|
* will automatically skip the center column when moving if they need to |
622
|
|
|
*/ |
623
|
|
View Code Duplication |
if ($row['module_classname'] != '\board3\portal\modules\custom') |
624
|
|
|
{ |
625
|
|
|
$column_string = $this->portal_columns->number_to_string($row['module_column'] + 1); // move 1 right |
626
|
|
|
|
627
|
|
|
if ($column_string == 'right' && !$this->modules_constraints->can_move_module(array('left', 'right'), $row['module_classname'])) |
628
|
|
|
{ |
629
|
|
|
$move_right = false; |
630
|
|
|
} |
631
|
|
|
else |
632
|
|
|
{ |
633
|
|
|
$move_right = true; |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
else |
637
|
|
|
{ |
638
|
|
|
$move_right = true; |
639
|
|
|
} |
640
|
|
|
} |
641
|
|
|
else |
642
|
|
|
{ |
643
|
|
|
$move_right = false; |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
if (($this->c_class->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($row['module_column'] - 1))) || ($this->c_class->get_allowed_columns() & $this->portal_columns->string_to_constant($this->portal_columns->number_to_string($row['module_column'] - 2)) && $row['module_column'] != 2)) |
647
|
|
|
{ |
648
|
|
|
/** |
649
|
|
|
* check if we can actually move |
650
|
|
|
* this only applies to modules in the center column as the side modules |
651
|
|
|
* will automatically skip the center column when moving if they need to |
652
|
|
|
*/ |
653
|
|
View Code Duplication |
if ($row['module_classname'] != '\board3\portal\modules\custom') |
654
|
|
|
{ |
655
|
|
|
$column_string = $this->portal_columns->number_to_string($row['module_column'] - 1); // move 1 left |
656
|
|
|
|
657
|
|
|
if ($column_string == 'left' && !$this->modules_constraints->can_move_module(array('left', 'right'), $row['module_classname'])) |
658
|
|
|
{ |
659
|
|
|
$move_left = false; |
660
|
|
|
} |
661
|
|
|
else |
662
|
|
|
{ |
663
|
|
|
$move_left = true; |
664
|
|
|
} |
665
|
|
|
} |
666
|
|
|
else |
667
|
|
|
{ |
668
|
|
|
$move_left = true; |
669
|
|
|
} |
670
|
|
|
} |
671
|
|
|
else |
672
|
|
|
{ |
673
|
|
|
$move_left = false; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
$this->template->assign_block_vars('modules_' . $template_column, array( |
677
|
|
|
'MODULE_NAME' => (isset($this->user->lang[$row['module_name']])) ? $this->user->lang[$row['module_name']] : $row['module_name'], |
678
|
|
|
'MODULE_IMAGE' => ($row['module_image_src']) ? '<img src="' . $this->root_path . 'styles/all/theme/images/portal/' . $row['module_image_src'] . '" alt="' . $row['module_name'] . '" />' : '', |
679
|
|
|
'MODULE_ENABLED' => ($row['module_status']) ? true : false, |
680
|
|
|
|
681
|
|
|
'U_DELETE' => $this->modules_manager->get_module_link('modules', $row['module_id']) . '&action=delete&module_classname=' . $row['module_classname'], |
682
|
|
|
'U_EDIT' => $this->modules_manager->get_module_link('config', $row['module_id']), |
683
|
|
|
'U_MOVE_UP' => $this->u_action . '&module_id=' . $row['module_id'] . '&action=move_up', |
684
|
|
|
'U_MOVE_DOWN' => $this->u_action . '&module_id=' . $row['module_id'] . '&action=move_down', |
685
|
|
|
'U_MOVE_RIGHT' => ($move_right) ? $this->u_action . '&module_id=' . $row['module_id'] . '&action=move_right' : '', |
686
|
|
|
'U_MOVE_LEFT' => ($move_left) ? $this->u_action . '&module_id=' . $row['module_id'] . '&action=move_left' : '', |
687
|
|
|
)); |
688
|
|
|
} |
689
|
|
|
|
690
|
|
|
$this->template->assign_vars(array( |
691
|
|
|
'ICON_MOVE_LEFT' => '<img src="' . $this->root_path . 'adm/images/icon_left.gif" alt="' . $this->user->lang['MOVE_LEFT'] . '" title="' . $this->user->lang['MOVE_LEFT'] . '" />', |
692
|
|
|
'ICON_MOVE_LEFT_DISABLED' => '<img src="' . $this->root_path . 'adm/images/icon_left_disabled.gif" alt="' . $this->user->lang['MOVE_LEFT'] . '" title="' . $this->user->lang['MOVE_LEFT'] . '" />', |
693
|
|
|
'ICON_MOVE_RIGHT' => '<img src="' . $this->root_path . 'adm/images/icon_right.gif" alt="' . $this->user->lang['MOVE_RIGHT'] . '" title="' . $this->user->lang['MOVE_RIGHT'] . '" />', |
694
|
|
|
'ICON_MOVE_RIGHT_DISABLED' => '<img src="' . $this->root_path . 'adm/images/icon_right_disabled.gif" alt="' . $this->user->lang['MOVE_RIGHT'] . '" title="' . $this->user->lang['MOVE_RIGHT'] . '" />', |
695
|
|
|
'B3P_U_ACTION' => $this->modules_manager->get_module_link('modules', $module_id), |
696
|
|
|
)); |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
$this->tpl_name = 'portal/acp_portal_modules'; |
700
|
|
|
$this->page_title = 'ACP_PORTAL_MODULES'; |
701
|
|
|
break; |
702
|
|
|
|
703
|
1 |
|
default: |
704
|
1 |
|
trigger_error('NO_MODE', E_USER_ERROR); |
705
|
|
|
break; |
706
|
1 |
|
} |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
|