1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* Class handling all types of 'plugins' (a future term)
*/
class p_master
{
/**#@+
* @access private
*/
var $p_id;
var $p_class;
var $p_name;
var $p_mode;
var $p_parent;
var $acl_forup_id = false;
/**#@-*/
/**#@+
* This array holds information on the list of modules
*/
var $module_ary = array();
/**#@-*/
/**
* List modules
*
* This creates a list, stored in $this->module_ary of all available
* modules for the given class (ucp, mcp and acp). Additionally
* $this->module_y_ary is created with indentation information for
* displaying the module list appropriately. Only modules for which
* the user has access rights are included in these lists.
*
* @final
*/
function list_modules($p_class)
{
global $auth, $db, $user;
global $config, $phpbb_root_path, $phpEx;
$get_cache_data = true;
// Empty cached contents
$this->module_cache = array();
// Sanitise for future path use, it's escaped as appropriate for queries
$this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class));
if (file_exists($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx))
{
include($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx);
$get_cache_data = false;
}
if ($get_cache_data)
{
global $cache;
// Get active modules
$sql = 'SELECT *
FROM ' . MODULES_TABLE . "
WHERE module_class = '" . $db->sql_escape($p_class) . "'
AND module_enabled = 1
ORDER BY left_id ASC";
$result = $db->sql_query($sql);
$this->module_cache['modules'] = array();
while ($row = $db->sql_fetchrow($result))
{
$this->module_cache['modules'][] = $row;
}
$db->sql_freeresult($result);
// Get module parents
$this->module_cache['parents'] = array();
foreach ($this->module_cache['modules'] as $row)
{
$this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id']);
}
$file = '<?php $this->module_cache=' . $cache->format_array($this->module_cache) . "; ?>";
if ($fp = @fopen($phpbb_root_path . 'cache/' . $this->p_class . '_modules.' . $phpEx, 'wb'))
{
@flock($fp, LOCK_EX);
fwrite($fp, $file);
@flock($fp, LOCK_UN);
fclose($fp);
}
unset($file);
}
$right = $depth = $i = 0;
$depth_ary = array();
foreach ($this->module_cache['modules'] as $row)
{
/**
* Authorisation is required ... not authed, skip
* @todo implement $this->is_module_id
* @todo put in seperate method for authentication
*/
if ($row['module_auth'])
{
$is_auth = false;
eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z_]+)(,\$id)?#e', '#\$id#', '#cfg_([a-z_]+)#e'), array('(int) $auth->acl_get("\\1"\\2)', '$this->acl_forup_id', '(int) $config["\\1"]'), trim($row['module_auth'])) . ');');
if (!$is_auth)
{
continue;
}
}
// Category with no members, ignore
if (!$row['module_name'] && ($row['left_id'] + 1 == $row['right_id']))
{
continue;
}
if ($row['left_id'] < $right)
{
$depth++;
$depth_ary[$row['parent_id']] = $depth;
}
else if ($row['left_id'] > $right + 1)
{
if (!isset($depth_ary[$row['parent_id']]))
{
$depth = 0;
}
else
{
$depth = $depth_ary[$row['parent_id']];
}
}
$right = $row['right_id'];
$this->module_ary[$i] = array(
'depth' => $depth,
'id' => (int) $row['module_id'],
'parent' => (int) $row['parent_id'],
'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false,
'name' => (string) $row['module_name'],
'mode' => (string) $row['module_mode'],
'display' => (int) $row['module_display'],
'lang' => (function_exists($row['module_name'])) ? $row['module_name']($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']),
'langname' => $row['module_langname'],
'left' => $row['left_id'],
'right' => $row['right_id'],
);
$i++;
}
unset($this->module_cache['modules']);
}
function set_active($id = false, $mode = false)
{
$category = false;
foreach ($this->module_ary as $row_id => $itep_ary)
{
// If this is a module and it's selected, active
// If this is a category and the module is the first within it, active
// If this is a module and no mode selected, select first mode
// If no category or module selected, go active for first module in first category
if (
(($itep_ary['name'] === $id || $itep_ary['id'] === (int) $id) && $itep_ary['mode'] == $mode && !$itep_ary['cat']) ||
($itep_ary['parent'] === $category && !$itep_ary['cat']) ||
(($itep_ary['name'] === $id || $itep_ary['id'] === (int) $id) && !$mode && !$itep_ary['cat']) ||
(!$id && !$mode && !$itep_ary['cat'])
)
{
$this->p_id = $itep_ary['id'];
$this->p_parent = $itep_ary['parent'];
$this->p_name = $itep_ary['name'];
$this->p_mode = $itep_ary['mode'];
$this->p_left = $itep_ary['left'];
$this->p_right = $itep_ary['right'];
$this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id];
break;
}
else if (($itep_ary['cat'] && $itep_ary['id'] == $id) || ($itep_ary['parent'] === $category && $itep_ary['cat']))
{
$category = $itep_ary['id'];
}
}
}
/**
* Loads currently active module
*
* This method loads a given module, passing it the relevant id and mode.
*
* @final
*/
function load_active($mode = false)
{
global $phpbb_root_path, $phpEx;
$module_path = $phpbb_root_path . 'includes/' . $this->p_class;
if (!class_exists("{$this->p_class}_$this->p_name"))
{
if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx"))
{
trigger_error('Cannot find module', E_USER_ERROR);
}
include("$module_path/{$this->p_class}_$this->p_name.$phpEx");
if (!class_exists("{$this->p_class}_$this->p_name"))
{
trigger_error('Module does not contain correct class', E_USER_ERROR);
}
if (!empty($mode))
{
$this->p_mode = $mode;
}
// Create a new instance of the desired module ... if it has a
// constructor it will of course be executed
$instance = "{$this->p_class}_$this->p_name";
$this->module = new $instance($this);
// Execute the main method for the new instance, we send the module
// id and mode as parameters
$this->module->main(($this->p_name) ? $this->p_name : $this->p_id, $this->p_mode);
return;
}
}
function get_parents($parent_id, $left_id, $right_id)
{
global $db;
$parents = array();
if ($parent_id > 0)
{
$sql = 'SELECT module_id, parent_id
FROM ' . MODULES_TABLE . '
WHERE left_id < ' . $left_id . '
AND right_id > ' . $right_id . '
ORDER BY left_id ASC';
$result = $db->sql_query($sql);
$parents = array();
while ($row = $db->sql_fetchrow($result))
{
$parents[$row['module_id']] = $row['parent_id'];
}
$db->sql_freeresult($result);
}
return $parents;
}
function assign_tpl_vars($module_url)
{
global $template;
$current_padding = $current_depth = 0;
$linear_offset = 'l_block1';
$tabular_offset = 't_block2';
// Generate the list of modules, we'll do this in two ways ...
// 1) In a linear fashion
// 2) In a combined tabbed + linear fashion ... tabs for the categories
// and a linear list for subcategories/items
foreach ($this->module_ary as $row_id => $itep_ary)
{
if (!$itep_ary['display'])
{
continue;
}
$depth = $itep_ary['depth'];
if ($depth > $current_depth)
{
$linear_offset = $linear_offset . '.l_block' . ($depth + 1);
$tabular_offset = ($depth + 1 > 2) ? $tabular_offset . '.t_block' . ($depth + 1) : $tabular_offset;
}
else if ($depth < $current_depth)
{
for ($i = $current_depth - $depth; $i > 0; $i--)
{
$linear_offset = substr($linear_offset, 0, strrpos($linear_offset, '.'));
$tabular_offset = ($i + $depth > 1) ? substr($tabular_offset, 0, strrpos($tabular_offset, '.')) : $tabular_offset;
}
}
$u_title = $module_url . '&i=' . (($itep_ary['cat']) ? $itep_ary['id'] : $itep_ary['name'] . '&mode=' . $itep_ary['mode']);
$u_title .= (!$itep_ary['cat'] && isset($itep_ary['url_extra'])) ? $itep_ary['url_extra'] : '';
// Only output a categories items if it's currently selected
if (!$depth || ($depth && (in_array($itep_ary['parent'], array_values($this->module_cache['parents'])) || $itep_ary['parent'] == $this->p_parent)))
{
$use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset;
$tpl_ary = array(
'L_TITLE' => $itep_ary['lang'],
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($this->module_cache['parents'])) || $itep_ary['id'] == $this->p_id) ? true : false,
'U_TITLE' => $u_title
);
$template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($itep_ary, CASE_UPPER)));
}
$tpl_ary = array(
'L_TITLE' => $itep_ary['lang'],
'S_SELECTED' => (in_array($itep_ary['id'], array_keys($this->module_cache['parents'])) || $itep_ary['id'] == $this->p_id) ? true : false,
'U_TITLE' => $u_title
);
$template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($itep_ary, CASE_UPPER)));
$current_depth = $depth;
}
}
/**
* Returns desired template name
*/
function get_tpl_name()
{
return $this->module->tpl_name . '.html';
}
/**
* Load module as the current active one without the need for registering it
*/
function load($class, $name, $mode = false)
{
$this->p_class = $class;
$this->p_name = $name;
$this->load_active($mode);
}
/**
* Display module
*/
function display($page_title)
{
global $template;
// Generate the page
page_header($page_title);
$template->set_filenames(array(
'body' => $this->get_tpl_name())
);
page_footer();
}
}
/**
* Unified module system
*
* Functions for the ACP
*/
class p_master_acp extends p_master
{
/**
* Move modules
*
* Private function used with the ACP module management system for moving modules
* within the tree. The movement of modules is limited to their category, they
* cannot be moved between categories (reducing complication for users and admins)
*
* @access private
function move($frop_id, $to_id)
{
global $db;
$moved_forums = get_forup_branch($frop_id, 'children', 'descending');
$frop_data = $moved_forums[0];
$diff = count($moved_forums) * 2;
$moved_ids = array();
for ($i = 0; $i < count($moved_forums); ++$i)
{
$moved_ids[] = $moved_forums[$i]['forup_id'];
}
// Resync parents
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET right_id = right_id - $diff, forup_parents = ''
WHERE left_id < " . $frop_data['right_id'] . "
AND right_id > " . $frop_data['right_id'];
$db->sql_query($sql);
// Resync righthand side of tree
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id - $diff, right_id = right_id - $diff, forup_parents = ''
WHERE left_id > " . $frop_data['right_id'];
$db->sql_query($sql);
if ($to_id > 0)
{
$to_data = get_forup_info($to_id);
// Resync new parents
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET right_id = right_id + $diff, forup_parents = ''
WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
AND forup_id NOT IN (' . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
// Resync the righthand side of the tree
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id + $diff, right_id = right_id + $diff, forup_parents = ''
WHERE left_id > " . $to_data['right_id'] . '
AND forup_id NOT IN (' . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
// Resync moved branch
$to_data['right_id'] += $diff;
if ($to_data['right_id'] > $frop_data['right_id'])
{
$diff = '+ ' . ($to_data['right_id'] - $frop_data['right_id'] - 1);
}
else
{
$diff = '- ' . abs($to_data['right_id'] - $frop_data['right_id'] - 1);
}
}
else
{
$sql = 'SELECT MAX(right_id) AS right_id
FROM ' . FORUMS_TABLE . '
WHERE forup_id NOT IN (' . implode(', ', $moved_ids) . ')';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$diff = '+ ' . ($row['right_id'] - $frop_data['left_id'] + 1);
}
$sql = 'UPDATE ' . FORUMS_TABLE . "
SET left_id = left_id $diff, right_id = right_id $diff, forup_parents = ''
WHERE forup_id IN (" . implode(', ', $moved_ids) . ')';
$db->sql_query($sql);
}
*/
}
/**
* Unified module system
*
* This class provides a unified system for the creation and management of
* modules used by the ACP, MCP and UCP.
*/
class p_module
{
var $tpl_name;
function p_module()
{
}
function check_version()
{
}
function init()
{
}
function install()
{
}
}
?>
|