PageRenderTime 47ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/functions_module.php

https://github.com/marcfuentes/dal2012_noestoysolo
PHP | 883 lines | 659 code | 99 blank | 125 comment | 103 complexity | 7a1ca6f579467c9241ee3320f3ef4160 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * Class handling all types of 'plugins' (a future term)
  19. * @package phpBB3
  20. */
  21. class p_master
  22. {
  23. var $p_id;
  24. var $p_class;
  25. var $p_name;
  26. var $p_mode;
  27. var $p_parent;
  28. var $include_path = false;
  29. var $active_module = false;
  30. var $active_module_row_id = false;
  31. var $acl_forum_id = false;
  32. var $module_ary = array();
  33. /**
  34. * Constuctor
  35. * Set module include path
  36. */
  37. function p_master($include_path = false)
  38. {
  39. global $phpbb_root_path;
  40. $this->include_path = ($include_path !== false) ? $include_path : $phpbb_root_path . 'includes/';
  41. // Make sure the path ends with /
  42. if (substr($this->include_path, -1) !== '/')
  43. {
  44. $this->include_path .= '/';
  45. }
  46. }
  47. /**
  48. * Set custom include path for modules
  49. * Schema for inclusion is include_path . modulebase
  50. *
  51. * @param string $include_path include path to be used.
  52. * @access public
  53. */
  54. function set_custom_include_path($include_path)
  55. {
  56. $this->include_path = $include_path;
  57. // Make sure the path ends with /
  58. if (substr($this->include_path, -1) !== '/')
  59. {
  60. $this->include_path .= '/';
  61. }
  62. }
  63. /**
  64. * List modules
  65. *
  66. * This creates a list, stored in $this->module_ary of all available
  67. * modules for the given class (ucp, mcp and acp). Additionally
  68. * $this->module_y_ary is created with indentation information for
  69. * displaying the module list appropriately. Only modules for which
  70. * the user has access rights are included in these lists.
  71. */
  72. function list_modules($p_class)
  73. {
  74. global $auth, $db, $user, $cache;
  75. global $config, $phpbb_root_path, $phpEx;
  76. // Sanitise for future path use, it's escaped as appropriate for queries
  77. $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class));
  78. // Get cached modules
  79. if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false)
  80. {
  81. // Get modules
  82. $sql = 'SELECT *
  83. FROM ' . MODULES_TABLE . "
  84. WHERE module_class = '" . $db->sql_escape($this->p_class) . "'
  85. ORDER BY left_id ASC";
  86. $result = $db->sql_query($sql);
  87. $rows = array();
  88. while ($row = $db->sql_fetchrow($result))
  89. {
  90. $rows[$row['module_id']] = $row;
  91. }
  92. $db->sql_freeresult($result);
  93. $this->module_cache = array();
  94. foreach ($rows as $module_id => $row)
  95. {
  96. $this->module_cache['modules'][] = $row;
  97. $this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id'], $rows);
  98. }
  99. unset($rows);
  100. $cache->put('_modules_' . $this->p_class, $this->module_cache);
  101. }
  102. if (empty($this->module_cache))
  103. {
  104. $this->module_cache = array('modules' => array(), 'parents' => array());
  105. }
  106. // We "could" build a true tree with this function - maybe mod authors want to use this...
  107. // Functions for traversing and manipulating the tree are not available though
  108. // We might re-structure the module system to use true trees in 3.2.x...
  109. // $tree = $this->build_tree($this->module_cache['modules'], $this->module_cache['parents']);
  110. // Clean up module cache array to only let survive modules the user can access
  111. $right_id = false;
  112. foreach ($this->module_cache['modules'] as $key => $row)
  113. {
  114. // Not allowed to view module?
  115. if (!$this->module_auth($row['module_auth']))
  116. {
  117. unset($this->module_cache['modules'][$key]);
  118. continue;
  119. }
  120. // Category with no members, ignore
  121. if (!$row['module_basename'] && ($row['left_id'] + 1 == $row['right_id']))
  122. {
  123. unset($this->module_cache['modules'][$key]);
  124. continue;
  125. }
  126. // Skip branch
  127. if ($right_id !== false)
  128. {
  129. if ($row['left_id'] < $right_id)
  130. {
  131. unset($this->module_cache['modules'][$key]);
  132. continue;
  133. }
  134. $right_id = false;
  135. }
  136. // Not enabled?
  137. if (!$row['module_enabled'])
  138. {
  139. // If category is disabled then disable every child too
  140. unset($this->module_cache['modules'][$key]);
  141. $right_id = $row['right_id'];
  142. continue;
  143. }
  144. }
  145. // Re-index (this is needed, else we are not able to array_slice later)
  146. $this->module_cache['modules'] = array_merge($this->module_cache['modules']);
  147. // Include MOD _info files for populating language entries within the menus
  148. $this->add_mod_info($this->p_class);
  149. // Now build the module array, but exclude completely empty categories...
  150. $right_id = false;
  151. $names = array();
  152. foreach ($this->module_cache['modules'] as $key => $row)
  153. {
  154. // Skip branch
  155. if ($right_id !== false)
  156. {
  157. if ($row['left_id'] < $right_id)
  158. {
  159. continue;
  160. }
  161. $right_id = false;
  162. }
  163. // Category with no members on their way down (we have to check every level)
  164. if (!$row['module_basename'])
  165. {
  166. $empty_category = true;
  167. // We go through the branch and look for an activated module
  168. foreach (array_slice($this->module_cache['modules'], $key + 1) as $temp_row)
  169. {
  170. if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id'])
  171. {
  172. // Module there
  173. if ($temp_row['module_basename'] && $temp_row['module_enabled'])
  174. {
  175. $empty_category = false;
  176. break;
  177. }
  178. continue;
  179. }
  180. break;
  181. }
  182. // Skip the branch
  183. if ($empty_category)
  184. {
  185. $right_id = $row['right_id'];
  186. continue;
  187. }
  188. }
  189. $depth = sizeof($this->module_cache['parents'][$row['module_id']]);
  190. // We need to prefix the functions to not create a naming conflict
  191. // Function for building 'url_extra'
  192. $url_func = '_module_' . $row['module_basename'] . '_url';
  193. // Function for building the language name
  194. $lang_func = '_module_' . $row['module_basename'] . '_lang';
  195. // Custom function for calling parameters on module init (for example assigning template variables)
  196. $custom_func = '_module_' . $row['module_basename'];
  197. $names[$row['module_basename'] . '_' . $row['module_mode']][] = true;
  198. $module_row = array(
  199. 'depth' => $depth,
  200. 'id' => (int) $row['module_id'],
  201. 'parent' => (int) $row['parent_id'],
  202. 'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false,
  203. 'is_duplicate' => ($row['module_basename'] && sizeof($names[$row['module_basename'] . '_' . $row['module_mode']]) > 1) ? true : false,
  204. 'name' => (string) $row['module_basename'],
  205. 'mode' => (string) $row['module_mode'],
  206. 'display' => (int) $row['module_display'],
  207. 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '',
  208. 'lang' => ($row['module_basename'] && function_exists($lang_func)) ? $lang_func($row['module_mode'], $row['module_langname']) : ((!empty($user->lang[$row['module_langname']])) ? $user->lang[$row['module_langname']] : $row['module_langname']),
  209. 'langname' => $row['module_langname'],
  210. 'left' => $row['left_id'],
  211. 'right' => $row['right_id'],
  212. );
  213. if (function_exists($custom_func))
  214. {
  215. $custom_func($row['module_mode'], $module_row);
  216. }
  217. $this->module_ary[] = $module_row;
  218. }
  219. unset($this->module_cache['modules'], $names);
  220. }
  221. /**
  222. * Check if a certain main module is accessible/loaded
  223. * By giving the module mode you are able to additionally check for only one mode within the main module
  224. *
  225. * @param string $module_basename The module base name, for example logs, reports, main (for the mcp).
  226. * @param mixed $module_mode The module mode to check. If provided the mode will be checked in addition for presence.
  227. *
  228. * @return bool Returns true if module is loaded and accessible, else returns false
  229. */
  230. function loaded($module_basename, $module_mode = false)
  231. {
  232. if (empty($this->loaded_cache))
  233. {
  234. $this->loaded_cache = array();
  235. foreach ($this->module_ary as $row)
  236. {
  237. if (!$row['name'])
  238. {
  239. continue;
  240. }
  241. if (!isset($this->loaded_cache[$row['name']]))
  242. {
  243. $this->loaded_cache[$row['name']] = array();
  244. }
  245. if (!$row['mode'])
  246. {
  247. continue;
  248. }
  249. $this->loaded_cache[$row['name']][$row['mode']] = true;
  250. }
  251. }
  252. if ($module_mode === false)
  253. {
  254. return (isset($this->loaded_cache[$module_basename])) ? true : false;
  255. }
  256. return (!empty($this->loaded_cache[$module_basename][$module_mode])) ? true : false;
  257. }
  258. /**
  259. * Check module authorisation
  260. */
  261. function module_auth($module_auth, $forum_id = false)
  262. {
  263. global $auth, $config;
  264. $module_auth = trim($module_auth);
  265. // Generally allowed to access module if module_auth is empty
  266. if (!$module_auth)
  267. {
  268. return true;
  269. }
  270. // With the code below we make sure only those elements get eval'd we really want to be checked
  271. preg_match_all('/(?:
  272. "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |
  273. \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' |
  274. [(),] |
  275. [^\s(),]+)/x', $module_auth, $match);
  276. $tokens = $match[0];
  277. for ($i = 0, $size = sizeof($tokens); $i < $size; $i++)
  278. {
  279. $token = &$tokens[$i];
  280. switch ($token)
  281. {
  282. case ')':
  283. case '(':
  284. case '&&':
  285. case '||':
  286. case ',':
  287. break;
  288. default:
  289. if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token))
  290. {
  291. $token = '';
  292. }
  293. break;
  294. }
  295. }
  296. $module_auth = implode(' ', $tokens);
  297. // Make sure $id seperation is working fine
  298. $module_auth = str_replace(' , ', ',', $module_auth);
  299. $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id;
  300. $is_auth = false;
  301. eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z0-9_]+)(,\$id)?#', '#\$id#', '#aclf_([a-z0-9_]+)#', '#cfg_([a-z0-9_]+)#', '#request_([a-zA-Z0-9_]+)#'), array('(int) $auth->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) $auth->acl_getf_global(\'\\1\')', '(int) $config[\'\\1\']', '!empty($_REQUEST[\'\\1\'])'), $module_auth) . ');');
  302. return $is_auth;
  303. }
  304. /**
  305. * Set active module
  306. */
  307. function set_active($id = false, $mode = false)
  308. {
  309. $icat = false;
  310. $this->active_module = false;
  311. if (request_var('icat', ''))
  312. {
  313. $icat = $id;
  314. $id = request_var('icat', '');
  315. }
  316. $category = false;
  317. foreach ($this->module_ary as $row_id => $item_ary)
  318. {
  319. // If this is a module and it's selected, active
  320. // If this is a category and the module is the first within it, active
  321. // If this is a module and no mode selected, select first mode
  322. // If no category or module selected, go active for first module in first category
  323. if (
  324. (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) ||
  325. ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) ||
  326. (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) ||
  327. (!$id && !$mode && !$item_ary['cat'] && $item_ary['display'])
  328. )
  329. {
  330. if ($item_ary['cat'])
  331. {
  332. $id = $icat;
  333. $icat = false;
  334. continue;
  335. }
  336. $this->p_id = $item_ary['id'];
  337. $this->p_parent = $item_ary['parent'];
  338. $this->p_name = $item_ary['name'];
  339. $this->p_mode = $item_ary['mode'];
  340. $this->p_left = $item_ary['left'];
  341. $this->p_right = $item_ary['right'];
  342. $this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id];
  343. $this->active_module = $item_ary['id'];
  344. $this->active_module_row_id = $row_id;
  345. break;
  346. }
  347. else if (($item_ary['cat'] && $item_ary['id'] === (int) $id) || ($item_ary['parent'] === $category && $item_ary['cat']))
  348. {
  349. $category = $item_ary['id'];
  350. }
  351. }
  352. }
  353. /**
  354. * Loads currently active module
  355. *
  356. * This method loads a given module, passing it the relevant id and mode.
  357. */
  358. function load_active($mode = false, $module_url = false, $execute_module = true)
  359. {
  360. global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user;
  361. $module_path = $this->include_path . $this->p_class;
  362. $icat = request_var('icat', '');
  363. if ($this->active_module === false)
  364. {
  365. trigger_error('Module not accessible', E_USER_ERROR);
  366. }
  367. if (!class_exists("{$this->p_class}_$this->p_name"))
  368. {
  369. if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx"))
  370. {
  371. trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR);
  372. }
  373. include("$module_path/{$this->p_class}_$this->p_name.$phpEx");
  374. if (!class_exists("{$this->p_class}_$this->p_name"))
  375. {
  376. trigger_error("Module file $module_path/{$this->p_class}_$this->p_name.$phpEx does not contain correct class [{$this->p_class}_$this->p_name]", E_USER_ERROR);
  377. }
  378. if (!empty($mode))
  379. {
  380. $this->p_mode = $mode;
  381. }
  382. // Create a new instance of the desired module ... if it has a
  383. // constructor it will of course be executed
  384. $instance = "{$this->p_class}_$this->p_name";
  385. $this->module = new $instance($this);
  386. // We pre-define the action parameter we are using all over the place
  387. if (defined('IN_ADMIN'))
  388. {
  389. // Is first module automatically enabled a duplicate and the category not passed yet?
  390. if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate'])
  391. {
  392. $icat = $this->module_ary[$this->active_module_row_id]['parent'];
  393. }
  394. // Not being able to overwrite ;)
  395. $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
  396. }
  397. else
  398. {
  399. // If user specified the module url we will use it...
  400. if ($module_url !== false)
  401. {
  402. $this->module->u_action = $module_url;
  403. }
  404. else
  405. {
  406. $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name'];
  407. }
  408. $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&amp;icat=' . $icat : '') . "&amp;mode={$this->p_mode}";
  409. }
  410. // Add url_extra parameter to u_action url
  411. if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra'])
  412. {
  413. $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra'];
  414. }
  415. // Assign the module path for re-usage
  416. $this->module->module_path = $module_path . '/';
  417. // Execute the main method for the new instance, we send the module id and mode as parameters
  418. // Users are able to call the main method after this function to be able to assign additional parameters manually
  419. if ($execute_module)
  420. {
  421. $this->module->main($this->p_name, $this->p_mode);
  422. }
  423. return;
  424. }
  425. }
  426. /**
  427. * Appending url parameter to the currently active module.
  428. *
  429. * This function is called for adding specific url parameters while executing the current module.
  430. * It is doing the same as the _module_{name}_url() function, apart from being able to be called after
  431. * having dynamically parsed specific parameters. This allows more freedom in choosing additional parameters.
  432. * One example can be seen in /includes/mcp/mcp_notes.php - $this->p_master->adjust_url() call.
  433. *
  434. * @param string $url_extra Extra url parameters, e.g.: &amp;u=$user_id
  435. *
  436. */
  437. function adjust_url($url_extra)
  438. {
  439. if (empty($this->module_ary[$this->active_module_row_id]))
  440. {
  441. return;
  442. }
  443. $row = &$this->module_ary[$this->active_module_row_id];
  444. // We check for the same url_extra in $row['url_extra'] to overcome doubled additions...
  445. if (strpos($row['url_extra'], $url_extra) === false)
  446. {
  447. $row['url_extra'] .= $url_extra;
  448. }
  449. }
  450. /**
  451. * Check if a module is active
  452. */
  453. function is_active($id, $mode = false)
  454. {
  455. // If we find a name by this id and being enabled we have our active one...
  456. foreach ($this->module_ary as $row_id => $item_ary)
  457. {
  458. if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display'])
  459. {
  460. if ($mode === false || $mode === $item_ary['mode'])
  461. {
  462. return true;
  463. }
  464. }
  465. }
  466. return false;
  467. }
  468. /**
  469. * Get parents
  470. */
  471. function get_parents($parent_id, $left_id, $right_id, &$all_parents)
  472. {
  473. global $db;
  474. $parents = array();
  475. if ($parent_id > 0)
  476. {
  477. foreach ($all_parents as $module_id => $row)
  478. {
  479. if ($row['left_id'] < $left_id && $row['right_id'] > $right_id)
  480. {
  481. $parents[$module_id] = $row['parent_id'];
  482. }
  483. if ($row['left_id'] > $left_id)
  484. {
  485. break;
  486. }
  487. }
  488. }
  489. return $parents;
  490. }
  491. /**
  492. * Get tree branch
  493. */
  494. function get_branch($left_id, $right_id, $remaining)
  495. {
  496. $branch = array();
  497. foreach ($remaining as $key => $row)
  498. {
  499. if ($row['left_id'] > $left_id && $row['left_id'] < $right_id)
  500. {
  501. $branch[] = $row;
  502. continue;
  503. }
  504. break;
  505. }
  506. return $branch;
  507. }
  508. /**
  509. * Build true binary tree from given array
  510. * Not in use
  511. */
  512. function build_tree(&$modules, &$parents)
  513. {
  514. $tree = array();
  515. foreach ($modules as $row)
  516. {
  517. $branch = &$tree;
  518. if ($row['parent_id'])
  519. {
  520. // Go through the tree to find our branch
  521. $parent_tree = $parents[$row['module_id']];
  522. foreach ($parent_tree as $id => $value)
  523. {
  524. if (!isset($branch[$id]) && isset($branch['child']))
  525. {
  526. $branch = &$branch['child'];
  527. }
  528. $branch = &$branch[$id];
  529. }
  530. $branch = &$branch['child'];
  531. }
  532. $branch[$row['module_id']] = $row;
  533. if (!isset($branch[$row['module_id']]['child']))
  534. {
  535. $branch[$row['module_id']]['child'] = array();
  536. }
  537. }
  538. return $tree;
  539. }
  540. /**
  541. * Build navigation structure
  542. */
  543. function assign_tpl_vars($module_url)
  544. {
  545. global $template;
  546. $current_id = $right_id = false;
  547. // Make sure the module_url has a question mark set, effectively determining the delimiter to use
  548. $delim = (strpos($module_url, '?') === false) ? '?' : '&amp;';
  549. $current_padding = $current_depth = 0;
  550. $linear_offset = 'l_block1';
  551. $tabular_offset = 't_block2';
  552. // Generate the list of modules, we'll do this in two ways ...
  553. // 1) In a linear fashion
  554. // 2) In a combined tabbed + linear fashion ... tabs for the categories
  555. // and a linear list for subcategories/items
  556. foreach ($this->module_ary as $row_id => $item_ary)
  557. {
  558. // Skip hidden modules
  559. if (!$item_ary['display'])
  560. {
  561. continue;
  562. }
  563. // Skip branch
  564. if ($right_id !== false)
  565. {
  566. if ($item_ary['left'] < $right_id)
  567. {
  568. continue;
  569. }
  570. $right_id = false;
  571. }
  572. // Category with no members on their way down (we have to check every level)
  573. if (!$item_ary['name'])
  574. {
  575. $empty_category = true;
  576. // We go through the branch and look for an activated module
  577. foreach (array_slice($this->module_ary, $row_id + 1) as $temp_row)
  578. {
  579. if ($temp_row['left'] > $item_ary['left'] && $temp_row['left'] < $item_ary['right'])
  580. {
  581. // Module there and displayed?
  582. if ($temp_row['name'] && $temp_row['display'])
  583. {
  584. $empty_category = false;
  585. break;
  586. }
  587. continue;
  588. }
  589. break;
  590. }
  591. // Skip the branch
  592. if ($empty_category)
  593. {
  594. $right_id = $item_ary['right'];
  595. continue;
  596. }
  597. }
  598. // Select first id we can get
  599. if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id))
  600. {
  601. $current_id = $item_ary['id'];
  602. }
  603. $depth = $item_ary['depth'];
  604. if ($depth > $current_depth)
  605. {
  606. $linear_offset = $linear_offset . '.l_block' . ($depth + 1);
  607. $tabular_offset = ($depth + 1 > 2) ? $tabular_offset . '.t_block' . ($depth + 1) : $tabular_offset;
  608. }
  609. else if ($depth < $current_depth)
  610. {
  611. for ($i = $current_depth - $depth; $i > 0; $i--)
  612. {
  613. $linear_offset = substr($linear_offset, 0, strrpos($linear_offset, '.'));
  614. $tabular_offset = ($i + $depth > 1) ? substr($tabular_offset, 0, strrpos($tabular_offset, '.')) : $tabular_offset;
  615. }
  616. }
  617. $u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&amp;icat=' . $current_id : '') . '&amp;mode=' . $item_ary['mode']);
  618. // Was not allowed in categories before - /*!$item_ary['cat'] && */
  619. $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : '';
  620. // Only output a categories items if it's currently selected
  621. if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent)))
  622. {
  623. $use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset;
  624. $tpl_ary = array(
  625. 'L_TITLE' => $item_ary['lang'],
  626. 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false,
  627. 'U_TITLE' => $u_title
  628. );
  629. $template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER)));
  630. }
  631. $tpl_ary = array(
  632. 'L_TITLE' => $item_ary['lang'],
  633. 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false,
  634. 'U_TITLE' => $u_title
  635. );
  636. $template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER)));
  637. $current_depth = $depth;
  638. }
  639. }
  640. /**
  641. * Returns desired template name
  642. */
  643. function get_tpl_name()
  644. {
  645. return $this->module->tpl_name . '.html';
  646. }
  647. /**
  648. * Returns the desired page title
  649. */
  650. function get_page_title()
  651. {
  652. global $user;
  653. if (!isset($this->module->page_title))
  654. {
  655. return '';
  656. }
  657. return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title;
  658. }
  659. /**
  660. * Load module as the current active one without the need for registering it
  661. */
  662. function load($class, $name, $mode = false)
  663. {
  664. $this->p_class = $class;
  665. $this->p_name = $name;
  666. // Set active module to true instead of using the id
  667. $this->active_module = true;
  668. $this->load_active($mode);
  669. }
  670. /**
  671. * Display module
  672. */
  673. function display($page_title, $display_online_list = true)
  674. {
  675. global $template, $user;
  676. // Generate the page
  677. if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
  678. {
  679. adm_page_header($page_title);
  680. }
  681. else
  682. {
  683. page_header($page_title, $display_online_list);
  684. }
  685. $template->set_filenames(array(
  686. 'body' => $this->get_tpl_name())
  687. );
  688. if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
  689. {
  690. adm_page_footer();
  691. }
  692. else
  693. {
  694. page_footer();
  695. }
  696. }
  697. /**
  698. * Toggle whether this module will be displayed or not
  699. */
  700. function set_display($id, $mode = false, $display = true)
  701. {
  702. foreach ($this->module_ary as $row_id => $item_ary)
  703. {
  704. if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode))
  705. {
  706. $this->module_ary[$row_id]['display'] = (int) $display;
  707. }
  708. }
  709. }
  710. /**
  711. * Add custom MOD info language file
  712. */
  713. function add_mod_info($module_class)
  714. {
  715. global $user, $phpEx;
  716. if (file_exists($user->lang_path . $user->lang_name . '/mods'))
  717. {
  718. $add_files = array();
  719. $dir = @opendir($user->lang_path . $user->lang_name . '/mods');
  720. if ($dir)
  721. {
  722. while (($entry = readdir($dir)) !== false)
  723. {
  724. if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx)
  725. {
  726. $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1));
  727. }
  728. }
  729. closedir($dir);
  730. }
  731. if (sizeof($add_files))
  732. {
  733. $user->add_lang($add_files);
  734. }
  735. }
  736. }
  737. }
  738. ?>