From 140746089594307c9bc2ad084ea2355dcbddbe16 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 29 Jan 2008 15:57:56 +0000 Subject: Merging revisions #r8346, #r8347 and #r8348 git-svn-id: file:///svn/phpbb/trunk@8349 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index b55c408b8c..b58993d878 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -59,7 +59,7 @@ class p_master WHERE module_class = '" . $db->sql_escape($this->p_class) . "' ORDER BY left_id ASC"; $result = $db->sql_query($sql); - + $rows = array(); while ($row = $db->sql_fetchrow($result)) { @@ -114,7 +114,7 @@ class p_master unset($this->module_cache['modules'][$key]); continue; } - + $right_id = false; } @@ -147,7 +147,7 @@ class p_master { continue; } - + $right_id = false; } @@ -194,7 +194,7 @@ class p_master $custom_func = '_module_' . $row['module_basename']; $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; - + $module_row = array( 'depth' => $depth, @@ -209,7 +209,7 @@ class p_master 'display' => (int) $row['module_display'], 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '', - + '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']), 'langname' => $row['module_langname'], @@ -309,7 +309,7 @@ class p_master break; default: - if (!preg_match('#(?:acl_([a-z_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z_]+))|(?:cfg_([a-z_]+))|(?:request_([a-z_]+))#', $token)) + if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token)) { $token = ''; } @@ -325,7 +325,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - eval('$is_auth = (int) (' . preg_replace(array('#acl_([a-z_]+)(,\$id)?#', '#\$id#', '#aclf_([a-z_]+)#', '#cfg_([a-z_]+)#', '#request_([a-z_]+)#'), array('(int) $auth->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) $auth->acl_getf_global(\'\\1\')', '(int) $config[\'\\1\']', '!empty($_REQUEST[\'\\1\'])'), $module_auth) . ');'); + 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) . ');'); return $is_auth; } -- cgit v1.2.1 From 4b5fab372ff69a809144dee3a0a7f90c219fe400 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Wed, 30 Jan 2008 16:14:39 +0000 Subject: merge with revision #r8350 git-svn-id: file:///svn/phpbb/trunk@8351 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index b58993d878..f4ee454033 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -677,7 +677,7 @@ class p_master } // Select first id we can get - if (!$current_id && (in_array($item_ary['id'], array_keys($this->module_cache['parents'])) || $item_ary['id'] == $this->p_id)) + if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id)) { $current_id = $item_ary['id']; } @@ -710,7 +710,7 @@ class p_master $tpl_ary = array( 'L_TITLE' => $item_ary['lang'], - 'S_SELECTED' => (in_array($item_ary['id'], array_keys($this->module_cache['parents'])) || $item_ary['id'] == $this->p_id) ? true : false, + 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, 'U_TITLE' => $u_title ); @@ -719,7 +719,7 @@ class p_master $tpl_ary = array( 'L_TITLE' => $item_ary['lang'], - 'S_SELECTED' => (in_array($item_ary['id'], array_keys($this->module_cache['parents'])) || $item_ary['id'] == $this->p_id) ? true : false, + 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, 'U_TITLE' => $u_title ); -- cgit v1.2.1 From 2f4a618900e2c3b6ea14c68cbeb5897cd2ac1a04 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 29 May 2008 12:25:56 +0000 Subject: ok... i hope i haven't messed too much with the code and everything is still working. Changes: - Ascraeus now uses constants for the phpbb root path and the php extension. This ensures more security for external applications and modifications (no more overwriting of root path and extension possible through insecure mods and register globals enabled) as well as no more globalizing needed. - A second change implemented here is an additional short-hand-notation for append_sid(). It is allowed to omit the root path and extension now (for example calling append_sid('memberlist')) - in this case the root path and extension get added automatically. The hook is called after these are added. git-svn-id: file:///svn/phpbb/trunk@8572 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index f4ee454033..c1d04cf245 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -44,8 +44,7 @@ class p_master */ function list_modules($p_class) { - global $auth, $db, $user, $cache; - global $config, $phpbb_root_path, $phpEx; + global $auth, $db, $user, $cache, $config; // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); @@ -393,9 +392,9 @@ class p_master */ function load_active($mode = false, $module_url = false, $execute_module = true) { - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user; + global $user; - $module_path = $phpbb_root_path . 'includes/' . $this->p_class; + $module_path = PHPBB_ROOT_PATH . 'includes/' . $this->p_class; $icat = request_var('icat', ''); if ($this->active_module === false) @@ -405,16 +404,16 @@ class p_master if (!class_exists("{$this->p_class}_$this->p_name")) { - if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) + if (!file_exists("$module_path/{$this->p_class}_$this->p_name." . PHP_EXT)) { - trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR); + trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name." . PHP_EXT, E_USER_ERROR); } - include("$module_path/{$this->p_class}_$this->p_name.$phpEx"); + include("$module_path/{$this->p_class}_$this->p_name." . PHP_EXT); if (!class_exists("{$this->p_class}_$this->p_name")) { - 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); + trigger_error("Module file $module_path/{$this->p_class}_$this->p_name." . PHP_EXT . " does not contain correct class [{$this->p_class}_$this->p_name]", E_USER_ERROR); } if (!empty($mode)) @@ -438,7 +437,7 @@ class p_master } // Not being able to overwrite ;) - $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } else { @@ -449,7 +448,7 @@ class p_master } else { - $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; + $this->module->u_action = PHPBB_ROOT_PATH . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; } $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; @@ -816,7 +815,7 @@ class p_master */ function add_mod_info($module_class) { - global $user, $phpEx; + global $user; if (file_exists($user->lang_path . 'mods')) { @@ -828,9 +827,9 @@ class p_master { while (($entry = readdir($dir)) !== false) { - if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx) + if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == PHP_EXT) { - $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1)); + $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen(PHP_EXT) + 1)); } } closedir($dir); -- cgit v1.2.1 From 589db44b5695730678f41c8d5868c73d4726054e Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 24 Aug 2008 10:04:15 +0000 Subject: Merge of the language-specific custom path change Revision #r8782 git-svn-id: file:///svn/phpbb/trunk@8786 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index c1d04cf245..c9d9a9770b 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -817,11 +817,11 @@ class p_master { global $user; - if (file_exists($user->lang_path . 'mods')) + if (file_exists($user->lang_path . $user->lang_name . '/mods')) { $add_files = array(); - $dir = @opendir($user->lang_path . 'mods'); + $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); if ($dir) { -- cgit v1.2.1 From 3bd6984785b53834ff3c61cd3452308539be2314 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 23 Nov 2008 12:45:22 +0000 Subject: [Change] Alllow applications to set custom module inclusion path (idea by HoL) git-svn-id: file:///svn/phpbb/trunk@9096 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index c9d9a9770b..3d2330c965 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -28,11 +28,45 @@ class p_master var $p_mode; var $p_parent; + var $include_path = false; var $active_module = false; var $active_module_row_id = false; var $acl_forum_id = false; var $module_ary = array(); + /** + * Constuctor + * Set module include path + */ + public function __construct($include_path = false) + { + $this->include_path = ($include_path !== false) ? $include_path : PHPBB_ROOT_PATH . 'includes/'; + + // Make sure the path ends with / + if (substr($this->include_path, -1) !== '/') + { + $this->include_path .= '/'; + } + } + + /** + * Set custom include path for modules + * Schema for inclusion is include_path . modulebase + * + * @param string $include_path include path to be used. + * @access public + */ + public function set_custom_include_path($include_path) + { + $this->include_path = $include_path; + + // Make sure the path ends with / + if (substr($this->include_path, -1) !== '/') + { + $this->include_path .= '/'; + } + } + /** * List modules * @@ -394,7 +428,7 @@ class p_master { global $user; - $module_path = PHPBB_ROOT_PATH . 'includes/' . $this->p_class; + $module_path = $this->include_path . $this->p_class; $icat = request_var('icat', ''); if ($this->active_module === false) -- cgit v1.2.1 From 07e9b83a3de0264916a058b9cf180b91b297604f Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 24 Nov 2008 00:20:33 +0000 Subject: - updated all code to use the request class instead of any direct access to super globals - disabled super globals in common.php. See commit r9101 for more information - cleaned up/simplified a few lines along the way. git-svn-id: file:///svn/phpbb/trunk@9102 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 3d2330c965..404a5e5a09 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -358,7 +358,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - 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) . ');'); + 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\']', 'request::variable(\'\\1\', false)'), $module_auth) . ');'); return $is_auth; } -- cgit v1.2.1 From 5b9a3c9a7d8f8e4590dddf4440ac82c30ef3f730 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Thu, 25 Dec 2008 14:47:57 +0000 Subject: add nils' request and super globals class rename request:: to phpbb_request:: git-svn-id: file:///svn/phpbb/trunk@9230 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 404a5e5a09..2899848009 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -358,7 +358,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - 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\']', 'request::variable(\'\\1\', false)'), $module_auth) . ');'); + 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\']', 'phpbb_request::variable(\'\\1\', false)'), $module_auth) . ');'); return $is_auth; } -- cgit v1.2.1 From 889fa871402814874d5d4f01b2f1c829d8206eb9 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 28 Dec 2008 13:27:58 +0000 Subject: implement new phpbb::$acm object, replacing $cache global git-svn-id: file:///svn/phpbb/trunk@9240 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 2899848009..6a7301c798 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -78,13 +78,13 @@ class p_master */ function list_modules($p_class) { - global $auth, $db, $user, $cache, $config; + global $auth, $db, $user, $config; // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); // Get cached modules - if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false) + if (($this->module_cache = phpbb::$acm->get('modules_' . $this->p_class)) === false) { // Get modules $sql = 'SELECT * @@ -108,7 +108,7 @@ class p_master } unset($rows); - $cache->put('_modules_' . $this->p_class, $this->module_cache); + phpbb::$acm->put('modules_' . $this->p_class, $this->module_cache); } if (empty($this->module_cache)) -- cgit v1.2.1 From 19aed179e53f9660a7202e2e50816e1cef0f7be9 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 28 Dec 2008 23:30:09 +0000 Subject: $config to phpbb::$config git-svn-id: file:///svn/phpbb/trunk@9242 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 6a7301c798..9206febca6 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -78,7 +78,7 @@ class p_master */ function list_modules($p_class) { - global $auth, $db, $user, $config; + global $auth, $db, $user; // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); @@ -310,7 +310,7 @@ class p_master */ function module_auth($module_auth, $forum_id = false) { - global $auth, $config; + global $auth; $module_auth = trim($module_auth); @@ -358,7 +358,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - 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\']', 'phpbb_request::variable(\'\\1\', false)'), $module_auth) . ');'); + 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) phpbb::$config[\'\\1\']', 'phpbb_request::variable(\'\\1\', false)'), $module_auth) . ');'); return $is_auth; } -- cgit v1.2.1 From 57aea7e62f7df2424ffbd1adc90941bff482d7ea Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Fri, 16 Jan 2009 17:41:04 +0000 Subject: modified some files to get the admin index page working, as well as index page in logged in state and not logged in state additionally prepare for a working installation git-svn-id: file:///svn/phpbb/trunk@9272 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 54 +++++++++++++------------------------ 1 file changed, 19 insertions(+), 35 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 9206febca6..c980840fa5 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -40,7 +40,7 @@ class p_master */ public function __construct($include_path = false) { - $this->include_path = ($include_path !== false) ? $include_path : PHPBB_ROOT_PATH . 'includes/'; + $this->include_path = ($include_path !== false) ? $include_path : PHPBB_ROOT_PATH . 'modules/'; // Make sure the path ends with / if (substr($this->include_path, -1) !== '/') @@ -78,8 +78,6 @@ class p_master */ function list_modules($p_class) { - global $auth, $db, $user; - // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); @@ -89,16 +87,16 @@ class p_master // Get modules $sql = 'SELECT * FROM ' . MODULES_TABLE . " - WHERE module_class = '" . $db->sql_escape($this->p_class) . "' + WHERE module_class = '" . phpbb::$db->sql_escape($this->p_class) . "' ORDER BY left_id ASC"; - $result = $db->sql_query($sql); + $result = phpbb::$db->sql_query($sql); $rows = array(); - while ($row = $db->sql_fetchrow($result)) + while ($row = phpbb::$db->sql_fetchrow($result)) { $rows[$row['module_id']] = $row; } - $db->sql_freeresult($result); + phpbb::$db->sql_freeresult($result); $this->module_cache = array(); foreach ($rows as $module_id => $row) @@ -243,7 +241,7 @@ class p_master 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '', - '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']), + 'lang' => ($row['module_basename'] && function_exists($lang_func)) ? $lang_func($row['module_mode'], $row['module_langname']) : phpbb::$user->lang($row['module_langname']), 'langname' => $row['module_langname'], 'left' => $row['left_id'], @@ -310,8 +308,6 @@ class p_master */ function module_auth($module_auth, $forum_id = false) { - global $auth; - $module_auth = trim($module_auth); // Generally allowed to access module if module_auth is empty @@ -358,7 +354,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - 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) phpbb::$config[\'\\1\']', 'phpbb_request::variable(\'\\1\', false)'), $module_auth) . ');'); + 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) phpbb::$acl->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) phpbb::$acl->acl_getf_global(\'\\1\')', '(int) phpbb::$config[\'\\1\']', 'phpbb_request::variable(\'\\1\', false)'), $module_auth) . ');'); return $is_auth; } @@ -426,8 +422,6 @@ class p_master */ function load_active($mode = false, $module_url = false, $execute_module = true) { - global $user; - $module_path = $this->include_path . $this->p_class; $icat = request_var('icat', ''); @@ -471,7 +465,7 @@ class p_master } // Not being able to overwrite ;) - $this->module->u_action = append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = phpbb::$url->append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } else { @@ -482,10 +476,10 @@ class p_master } else { - $this->module->u_action = PHPBB_ROOT_PATH . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; + $this->module->u_action = PHPBB_ROOT_PATH . ((phpbb::$user->page['page_dir']) ? phpbb::$user->page['page_dir'] . '/' : '') . phpbb::$user->page['page_name']; } - $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = phpbb::$url->append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } // Add url_extra parameter to u_action url @@ -560,8 +554,6 @@ class p_master */ function get_parents($parent_id, $left_id, $right_id, &$all_parents) { - global $db; - $parents = array(); if ($parent_id > 0) @@ -646,8 +638,6 @@ class p_master */ function assign_tpl_vars($module_url) { - global $template; - $current_id = $right_id = false; // Make sure the module_url has a question mark set, effectively determining the delimiter to use @@ -747,7 +737,7 @@ class p_master 'U_TITLE' => $u_title ); - $template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); + phpbb::$template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); } $tpl_ary = array( @@ -756,7 +746,7 @@ class p_master 'U_TITLE' => $u_title ); - $template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); + phpbb::$template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); $current_depth = $depth; } @@ -775,14 +765,12 @@ class p_master */ function get_page_title() { - global $user; - if (!isset($this->module->page_title)) { return ''; } - return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title; + return phpbb::$user->lang($this->module->page_title); } /** @@ -804,10 +792,8 @@ class p_master */ function display($page_title, $display_online_list = true) { - global $template, $user; - // Generate the page - if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + if (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin']) { adm_page_header($page_title); } @@ -816,11 +802,11 @@ class p_master page_header($page_title, $display_online_list); } - $template->set_filenames(array( + phpbb::$template->set_filenames(array( 'body' => $this->get_tpl_name()) ); - if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + if (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin']) { adm_page_footer(); } @@ -849,13 +835,11 @@ class p_master */ function add_mod_info($module_class) { - global $user; - - if (file_exists($user->lang_path . $user->lang_name . '/mods')) + if (file_exists(phpbb::$user->lang_path . phpbb::$user->lang_name . '/mods')) { $add_files = array(); - $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); + $dir = @opendir(phpbb::$user->lang_path . phpbb::$user->lang_name . '/mods'); if ($dir) { @@ -871,7 +855,7 @@ class p_master if (sizeof($add_files)) { - $user->add_lang($add_files); + phpbb::$user->add_lang($add_files); } } } -- cgit v1.2.1 From 14eb46cda05d75e0e3d4f8190b1b7661d8b72793 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Mon, 19 Jan 2009 15:24:24 +0000 Subject: Adjust some files to support new methods... git-svn-id: file:///svn/phpbb/trunk@9279 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index c980840fa5..c6c457aba4 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -792,28 +792,13 @@ class p_master */ function display($page_title, $display_online_list = true) { - // Generate the page - if (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin']) - { - adm_page_header($page_title); - } - else - { - page_header($page_title, $display_online_list); - } + page_header($page_title, $display_online_list); phpbb::$template->set_filenames(array( 'body' => $this->get_tpl_name()) ); - if (defined('IN_ADMIN') && isset(phpbb::$user->data['session_admin']) && phpbb::$user->data['session_admin']) - { - adm_page_footer(); - } - else - { - page_footer(); - } + page_footer(); } /** -- cgit v1.2.1 From bf8ac19eaa8d74f9dfd6d597190f5664e7339382 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:13:59 +0000 Subject: Move trunk/phpBB to old_trunk/phpBB git-svn-id: file:///svn/phpbb/trunk@10210 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 849 ------------------------------------ 1 file changed, 849 deletions(-) delete mode 100644 phpBB/includes/functions_module.php (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php deleted file mode 100644 index c6c457aba4..0000000000 --- a/phpBB/includes/functions_module.php +++ /dev/null @@ -1,849 +0,0 @@ -include_path = ($include_path !== false) ? $include_path : PHPBB_ROOT_PATH . 'modules/'; - - // Make sure the path ends with / - if (substr($this->include_path, -1) !== '/') - { - $this->include_path .= '/'; - } - } - - /** - * Set custom include path for modules - * Schema for inclusion is include_path . modulebase - * - * @param string $include_path include path to be used. - * @access public - */ - public function set_custom_include_path($include_path) - { - $this->include_path = $include_path; - - // Make sure the path ends with / - if (substr($this->include_path, -1) !== '/') - { - $this->include_path .= '/'; - } - } - - /** - * 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. - */ - function list_modules($p_class) - { - // Sanitise for future path use, it's escaped as appropriate for queries - $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); - - // Get cached modules - if (($this->module_cache = phpbb::$acm->get('modules_' . $this->p_class)) === false) - { - // Get modules - $sql = 'SELECT * - FROM ' . MODULES_TABLE . " - WHERE module_class = '" . phpbb::$db->sql_escape($this->p_class) . "' - ORDER BY left_id ASC"; - $result = phpbb::$db->sql_query($sql); - - $rows = array(); - while ($row = phpbb::$db->sql_fetchrow($result)) - { - $rows[$row['module_id']] = $row; - } - phpbb::$db->sql_freeresult($result); - - $this->module_cache = array(); - foreach ($rows as $module_id => $row) - { - $this->module_cache['modules'][] = $row; - $this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id'], $rows); - } - unset($rows); - - phpbb::$acm->put('modules_' . $this->p_class, $this->module_cache); - } - - if (empty($this->module_cache)) - { - $this->module_cache = array('modules' => array(), 'parents' => array()); - } - - // We "could" build a true tree with this function - maybe mod authors want to use this... - // Functions for traversing and manipulating the tree are not available though - // We might re-structure the module system to use true trees in 3.2.x... - // $tree = $this->build_tree($this->module_cache['modules'], $this->module_cache['parents']); - - // Clean up module cache array to only let survive modules the user can access - $right_id = false; - foreach ($this->module_cache['modules'] as $key => $row) - { - // Not allowed to view module? - if (!$this->module_auth($row['module_auth'])) - { - unset($this->module_cache['modules'][$key]); - continue; - } - - // Category with no members, ignore - if (!$row['module_basename'] && ($row['left_id'] + 1 == $row['right_id'])) - { - unset($this->module_cache['modules'][$key]); - continue; - } - - // Skip branch - if ($right_id !== false) - { - if ($row['left_id'] < $right_id) - { - unset($this->module_cache['modules'][$key]); - continue; - } - - $right_id = false; - } - - // Not enabled? - if (!$row['module_enabled']) - { - // If category is disabled then disable every child too - unset($this->module_cache['modules'][$key]); - $right_id = $row['right_id']; - continue; - } - } - - // Re-index (this is needed, else we are not able to array_slice later) - $this->module_cache['modules'] = array_merge($this->module_cache['modules']); - - // Include MOD _info files for populating language entries within the menus - $this->add_mod_info($this->p_class); - - // Now build the module array, but exclude completely empty categories... - $right_id = false; - $names = array(); - - foreach ($this->module_cache['modules'] as $key => $row) - { - // Skip branch - if ($right_id !== false) - { - if ($row['left_id'] < $right_id) - { - continue; - } - - $right_id = false; - } - - // Category with no members on their way down (we have to check every level) - if (!$row['module_basename']) - { - $empty_category = true; - - // We go through the branch and look for an activated module - foreach (array_slice($this->module_cache['modules'], $key + 1) as $temp_row) - { - if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id']) - { - // Module there - if ($temp_row['module_basename'] && $temp_row['module_enabled']) - { - $empty_category = false; - break; - } - continue; - } - break; - } - - // Skip the branch - if ($empty_category) - { - $right_id = $row['right_id']; - continue; - } - } - - $depth = sizeof($this->module_cache['parents'][$row['module_id']]); - - // We need to prefix the functions to not create a naming conflict - - // Function for building 'url_extra' - $url_func = '_module_' . $row['module_basename'] . '_url'; - - // Function for building the language name - $lang_func = '_module_' . $row['module_basename'] . '_lang'; - - // Custom function for calling parameters on module init (for example assigning template variables) - $custom_func = '_module_' . $row['module_basename']; - - $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; - - $module_row = array( - 'depth' => $depth, - - 'id' => (int) $row['module_id'], - 'parent' => (int) $row['parent_id'], - 'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false, - - 'is_duplicate' => ($row['module_basename'] && sizeof($names[$row['module_basename'] . '_' . $row['module_mode']]) > 1) ? true : false, - - 'name' => (string) $row['module_basename'], - 'mode' => (string) $row['module_mode'], - 'display' => (int) $row['module_display'], - - 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '', - - 'lang' => ($row['module_basename'] && function_exists($lang_func)) ? $lang_func($row['module_mode'], $row['module_langname']) : phpbb::$user->lang($row['module_langname']), - 'langname' => $row['module_langname'], - - 'left' => $row['left_id'], - 'right' => $row['right_id'], - ); - - if (function_exists($custom_func)) - { - $custom_func($row['module_mode'], $module_row); - } - - $this->module_ary[] = $module_row; - } - - unset($this->module_cache['modules'], $names); - } - - /** - * Check if a certain main module is accessible/loaded - * By giving the module mode you are able to additionally check for only one mode within the main module - * - * @param string $module_basename The module base name, for example logs, reports, main (for the mcp). - * @param mixed $module_mode The module mode to check. If provided the mode will be checked in addition for presence. - * - * @return bool Returns true if module is loaded and accessible, else returns false - */ - function loaded($module_basename, $module_mode = false) - { - if (empty($this->loaded_cache)) - { - $this->loaded_cache = array(); - - foreach ($this->module_ary as $row) - { - if (!$row['name']) - { - continue; - } - - if (!isset($this->loaded_cache[$row['name']])) - { - $this->loaded_cache[$row['name']] = array(); - } - - if (!$row['mode']) - { - continue; - } - - $this->loaded_cache[$row['name']][$row['mode']] = true; - } - } - - if ($module_mode === false) - { - return (isset($this->loaded_cache[$module_basename])) ? true : false; - } - - return (!empty($this->loaded_cache[$module_basename][$module_mode])) ? true : false; - } - - /** - * Check module authorisation - */ - function module_auth($module_auth, $forum_id = false) - { - $module_auth = trim($module_auth); - - // Generally allowed to access module if module_auth is empty - if (!$module_auth) - { - return true; - } - - // With the code below we make sure only those elements get eval'd we really want to be checked - preg_match_all('/(?: - "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | - \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | - [(),] | - [^\s(),]+)/x', $module_auth, $match); - - $tokens = $match[0]; - for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) - { - $token = &$tokens[$i]; - - switch ($token) - { - case ')': - case '(': - case '&&': - case '||': - case ',': - break; - - default: - if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token)) - { - $token = ''; - } - break; - } - } - - $module_auth = implode(' ', $tokens); - - // Make sure $id seperation is working fine - $module_auth = str_replace(' , ', ',', $module_auth); - - $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; - - $is_auth = false; - 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) phpbb::$acl->acl_get(\'\\1\'\\2)', '(int) $forum_id', '(int) phpbb::$acl->acl_getf_global(\'\\1\')', '(int) phpbb::$config[\'\\1\']', 'phpbb_request::variable(\'\\1\', false)'), $module_auth) . ');'); - - return $is_auth; - } - - /** - * Set active module - */ - function set_active($id = false, $mode = false) - { - $icat = false; - $this->active_module = false; - - if (request_var('icat', '')) - { - $icat = $id; - $id = request_var('icat', ''); - } - - $category = false; - foreach ($this->module_ary as $row_id => $item_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 ( - (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || - ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) || - (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || - (!$id && !$mode && !$item_ary['cat'] && $item_ary['display']) - ) - { - if ($item_ary['cat']) - { - $id = $icat; - $icat = false; - - continue; - } - - $this->p_id = $item_ary['id']; - $this->p_parent = $item_ary['parent']; - $this->p_name = $item_ary['name']; - $this->p_mode = $item_ary['mode']; - $this->p_left = $item_ary['left']; - $this->p_right = $item_ary['right']; - - $this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id]; - $this->active_module = $item_ary['id']; - $this->active_module_row_id = $row_id; - - break; - } - else if (($item_ary['cat'] && $item_ary['id'] === (int) $id) || ($item_ary['parent'] === $category && $item_ary['cat'])) - { - $category = $item_ary['id']; - } - } - } - - /** - * Loads currently active module - * - * This method loads a given module, passing it the relevant id and mode. - */ - function load_active($mode = false, $module_url = false, $execute_module = true) - { - $module_path = $this->include_path . $this->p_class; - $icat = request_var('icat', ''); - - if ($this->active_module === false) - { - trigger_error('Module not accessible', E_USER_ERROR); - } - - if (!class_exists("{$this->p_class}_$this->p_name")) - { - if (!file_exists("$module_path/{$this->p_class}_$this->p_name." . PHP_EXT)) - { - trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name." . PHP_EXT, E_USER_ERROR); - } - - include("$module_path/{$this->p_class}_$this->p_name." . PHP_EXT); - - if (!class_exists("{$this->p_class}_$this->p_name")) - { - trigger_error("Module file $module_path/{$this->p_class}_$this->p_name." . PHP_EXT . " does not contain correct class [{$this->p_class}_$this->p_name]", 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); - - // We pre-define the action parameter we are using all over the place - if (defined('IN_ADMIN')) - { - // Is first module automatically enabled a duplicate and the category not passed yet? - if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) - { - $icat = $this->module_ary[$this->active_module_row_id]['parent']; - } - - // Not being able to overwrite ;) - $this->module->u_action = phpbb::$url->append_sid(PHPBB_ADMIN_PATH . 'index.' . PHP_EXT, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; - } - else - { - // If user specified the module url we will use it... - if ($module_url !== false) - { - $this->module->u_action = $module_url; - } - else - { - $this->module->u_action = PHPBB_ROOT_PATH . ((phpbb::$user->page['page_dir']) ? phpbb::$user->page['page_dir'] . '/' : '') . phpbb::$user->page['page_name']; - } - - $this->module->u_action = phpbb::$url->append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; - } - - // Add url_extra parameter to u_action url - if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) - { - $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; - } - - // Assign the module path for re-usage - $this->module->module_path = $module_path . '/'; - - // Execute the main method for the new instance, we send the module id and mode as parameters - // Users are able to call the main method after this function to be able to assign additional parameters manually - if ($execute_module) - { - $this->module->main($this->p_name, $this->p_mode); - } - - return; - } - } - - /** - * Appending url parameter to the currently active module. - * - * This function is called for adding specific url parameters while executing the current module. - * It is doing the same as the _module_{name}_url() function, apart from being able to be called after - * having dynamically parsed specific parameters. This allows more freedom in choosing additional parameters. - * One example can be seen in /includes/mcp/mcp_notes.php - $this->p_master->adjust_url() call. - * - * @param string $url_extra Extra url parameters, e.g.: &u=$user_id - * - */ - function adjust_url($url_extra) - { - if (empty($this->module_ary[$this->active_module_row_id])) - { - return; - } - - $row = &$this->module_ary[$this->active_module_row_id]; - - // We check for the same url_extra in $row['url_extra'] to overcome doubled additions... - if (strpos($row['url_extra'], $url_extra) === false) - { - $row['url_extra'] .= $url_extra; - } - } - - /** - * Check if a module is active - */ - function is_active($id, $mode = false) - { - // If we find a name by this id and being enabled we have our active one... - foreach ($this->module_ary as $row_id => $item_ary) - { - if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display']) - { - if ($mode === false || $mode === $item_ary['mode']) - { - return true; - } - } - } - - return false; - } - - /** - * Get parents - */ - function get_parents($parent_id, $left_id, $right_id, &$all_parents) - { - $parents = array(); - - if ($parent_id > 0) - { - foreach ($all_parents as $module_id => $row) - { - if ($row['left_id'] < $left_id && $row['right_id'] > $right_id) - { - $parents[$module_id] = $row['parent_id']; - } - - if ($row['left_id'] > $left_id) - { - break; - } - } - } - - return $parents; - } - - /** - * Get tree branch - */ - function get_branch($left_id, $right_id, $remaining) - { - $branch = array(); - - foreach ($remaining as $key => $row) - { - if ($row['left_id'] > $left_id && $row['left_id'] < $right_id) - { - $branch[] = $row; - continue; - } - break; - } - - return $branch; - } - - /** - * Build true binary tree from given array - * Not in use - */ - function build_tree(&$modules, &$parents) - { - $tree = array(); - - foreach ($modules as $row) - { - $branch = &$tree; - - if ($row['parent_id']) - { - // Go through the tree to find our branch - $parent_tree = $parents[$row['module_id']]; - - foreach ($parent_tree as $id => $value) - { - if (!isset($branch[$id]) && isset($branch['child'])) - { - $branch = &$branch['child']; - } - $branch = &$branch[$id]; - } - $branch = &$branch['child']; - } - - $branch[$row['module_id']] = $row; - if (!isset($branch[$row['module_id']]['child'])) - { - $branch[$row['module_id']]['child'] = array(); - } - } - - return $tree; - } - - /** - * Build navigation structure - */ - function assign_tpl_vars($module_url) - { - $current_id = $right_id = false; - - // Make sure the module_url has a question mark set, effectively determining the delimiter to use - $delim = (strpos($module_url, '?') === false) ? '?' : '&'; - - $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 => $item_ary) - { - // Skip hidden modules - if (!$item_ary['display']) - { - continue; - } - - // Skip branch - if ($right_id !== false) - { - if ($item_ary['left'] < $right_id) - { - continue; - } - - $right_id = false; - } - - // Category with no members on their way down (we have to check every level) - if (!$item_ary['name']) - { - $empty_category = true; - - // We go through the branch and look for an activated module - foreach (array_slice($this->module_ary, $row_id + 1) as $temp_row) - { - if ($temp_row['left'] > $item_ary['left'] && $temp_row['left'] < $item_ary['right']) - { - // Module there and displayed? - if ($temp_row['name'] && $temp_row['display']) - { - $empty_category = false; - break; - } - continue; - } - break; - } - - // Skip the branch - if ($empty_category) - { - $right_id = $item_ary['right']; - continue; - } - } - - // Select first id we can get - if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id)) - { - $current_id = $item_ary['id']; - } - - $depth = $item_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 . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); - - // Was not allowed in categories before - /*!$item_ary['cat'] && */ - $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; - - // Only output a categories items if it's currently selected - if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent))) - { - $use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset; - - $tpl_ary = array( - 'L_TITLE' => $item_ary['lang'], - 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, - 'U_TITLE' => $u_title - ); - - phpbb::$template->assign_block_vars($use_tabular_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); - } - - $tpl_ary = array( - 'L_TITLE' => $item_ary['lang'], - 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id) ? true : false, - 'U_TITLE' => $u_title - ); - - phpbb::$template->assign_block_vars($linear_offset, array_merge($tpl_ary, array_change_key_case($item_ary, CASE_UPPER))); - - $current_depth = $depth; - } - } - - /** - * Returns desired template name - */ - function get_tpl_name() - { - return $this->module->tpl_name . '.html'; - } - - /** - * Returns the desired page title - */ - function get_page_title() - { - if (!isset($this->module->page_title)) - { - return ''; - } - - return phpbb::$user->lang($this->module->page_title); - } - - /** - * 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; - - // Set active module to true instead of using the id - $this->active_module = true; - - $this->load_active($mode); - } - - /** - * Display module - */ - function display($page_title, $display_online_list = true) - { - page_header($page_title, $display_online_list); - - phpbb::$template->set_filenames(array( - 'body' => $this->get_tpl_name()) - ); - - page_footer(); - } - - /** - * Toggle whether this module will be displayed or not - */ - function set_display($id, $mode = false, $display = true) - { - foreach ($this->module_ary as $row_id => $item_ary) - { - if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) - { - $this->module_ary[$row_id]['display'] = (int) $display; - } - } - } - - /** - * Add custom MOD info language file - */ - function add_mod_info($module_class) - { - if (file_exists(phpbb::$user->lang_path . phpbb::$user->lang_name . '/mods')) - { - $add_files = array(); - - $dir = @opendir(phpbb::$user->lang_path . phpbb::$user->lang_name . '/mods'); - - if ($dir) - { - while (($entry = readdir($dir)) !== false) - { - if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == PHP_EXT) - { - $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen(PHP_EXT) + 1)); - } - } - closedir($dir); - } - - if (sizeof($add_files)) - { - phpbb::$user->add_lang($add_files); - } - } - } -} - -?> \ No newline at end of file -- cgit v1.2.1 From 2e17e448deed073f8614bb555a8ef20c57291c2a Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Sun, 4 Oct 2009 18:14:59 +0000 Subject: Copy 3.0.x branch to trunk git-svn-id: file:///svn/phpbb/trunk@10211 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_module.php | 883 ++++++++++++++++++++++++++++++++++++ 1 file changed, 883 insertions(+) create mode 100644 phpBB/includes/functions_module.php (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php new file mode 100644 index 0000000000..d0e7c8cfc8 --- /dev/null +++ b/phpBB/includes/functions_module.php @@ -0,0 +1,883 @@ +include_path = ($include_path !== false) ? $include_path : $phpbb_root_path . 'includes/'; + + // Make sure the path ends with / + if (substr($this->include_path, -1) !== '/') + { + $this->include_path .= '/'; + } + } + + /** + * Set custom include path for modules + * Schema for inclusion is include_path . modulebase + * + * @param string $include_path include path to be used. + * @access public + */ + function set_custom_include_path($include_path) + { + $this->include_path = $include_path; + + // Make sure the path ends with / + if (substr($this->include_path, -1) !== '/') + { + $this->include_path .= '/'; + } + } + + /** + * 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. + */ + function list_modules($p_class) + { + global $auth, $db, $user, $cache; + global $config, $phpbb_root_path, $phpEx; + + // Sanitise for future path use, it's escaped as appropriate for queries + $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); + + // Get cached modules + if (($this->module_cache = $cache->get('_modules_' . $this->p_class)) === false) + { + // Get modules + $sql = 'SELECT * + FROM ' . MODULES_TABLE . " + WHERE module_class = '" . $db->sql_escape($this->p_class) . "' + ORDER BY left_id ASC"; + $result = $db->sql_query($sql); + + $rows = array(); + while ($row = $db->sql_fetchrow($result)) + { + $rows[$row['module_id']] = $row; + } + $db->sql_freeresult($result); + + $this->module_cache = array(); + foreach ($rows as $module_id => $row) + { + $this->module_cache['modules'][] = $row; + $this->module_cache['parents'][$row['module_id']] = $this->get_parents($row['parent_id'], $row['left_id'], $row['right_id'], $rows); + } + unset($rows); + + $cache->put('_modules_' . $this->p_class, $this->module_cache); + } + + if (empty($this->module_cache)) + { + $this->module_cache = array('modules' => array(), 'parents' => array()); + } + + // We "could" build a true tree with this function - maybe mod authors want to use this... + // Functions for traversing and manipulating the tree are not available though + // We might re-structure the module system to use true trees in 3.2.x... + // $tree = $this->build_tree($this->module_cache['modules'], $this->module_cache['parents']); + + // Clean up module cache array to only let survive modules the user can access + $right_id = false; + foreach ($this->module_cache['modules'] as $key => $row) + { + // Not allowed to view module? + if (!$this->module_auth($row['module_auth'])) + { + unset($this->module_cache['modules'][$key]); + continue; + } + + // Category with no members, ignore + if (!$row['module_basename'] && ($row['left_id'] + 1 == $row['right_id'])) + { + unset($this->module_cache['modules'][$key]); + continue; + } + + // Skip branch + if ($right_id !== false) + { + if ($row['left_id'] < $right_id) + { + unset($this->module_cache['modules'][$key]); + continue; + } + + $right_id = false; + } + + // Not enabled? + if (!$row['module_enabled']) + { + // If category is disabled then disable every child too + unset($this->module_cache['modules'][$key]); + $right_id = $row['right_id']; + continue; + } + } + + // Re-index (this is needed, else we are not able to array_slice later) + $this->module_cache['modules'] = array_merge($this->module_cache['modules']); + + // Include MOD _info files for populating language entries within the menus + $this->add_mod_info($this->p_class); + + // Now build the module array, but exclude completely empty categories... + $right_id = false; + $names = array(); + + foreach ($this->module_cache['modules'] as $key => $row) + { + // Skip branch + if ($right_id !== false) + { + if ($row['left_id'] < $right_id) + { + continue; + } + + $right_id = false; + } + + // Category with no members on their way down (we have to check every level) + if (!$row['module_basename']) + { + $empty_category = true; + + // We go through the branch and look for an activated module + foreach (array_slice($this->module_cache['modules'], $key + 1) as $temp_row) + { + if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id']) + { + // Module there + if ($temp_row['module_basename'] && $temp_row['module_enabled']) + { + $empty_category = false; + break; + } + continue; + } + break; + } + + // Skip the branch + if ($empty_category) + { + $right_id = $row['right_id']; + continue; + } + } + + $depth = sizeof($this->module_cache['parents'][$row['module_id']]); + + // We need to prefix the functions to not create a naming conflict + + // Function for building 'url_extra' + $url_func = '_module_' . $row['module_basename'] . '_url'; + + // Function for building the language name + $lang_func = '_module_' . $row['module_basename'] . '_lang'; + + // Custom function for calling parameters on module init (for example assigning template variables) + $custom_func = '_module_' . $row['module_basename']; + + $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; + + $module_row = array( + 'depth' => $depth, + + 'id' => (int) $row['module_id'], + 'parent' => (int) $row['parent_id'], + 'cat' => ($row['right_id'] > $row['left_id'] + 1) ? true : false, + + 'is_duplicate' => ($row['module_basename'] && sizeof($names[$row['module_basename'] . '_' . $row['module_mode']]) > 1) ? true : false, + + 'name' => (string) $row['module_basename'], + 'mode' => (string) $row['module_mode'], + 'display' => (int) $row['module_display'], + + 'url_extra' => (function_exists($url_func)) ? $url_func($row['module_mode'], $row) : '', + + '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']), + 'langname' => $row['module_langname'], + + 'left' => $row['left_id'], + 'right' => $row['right_id'], + ); + + if (function_exists($custom_func)) + { + $custom_func($row['module_mode'], $module_row); + } + + $this->module_ary[] = $module_row; + } + + unset($this->module_cache['modules'], $names); + } + + /** + * Check if a certain main module is accessible/loaded + * By giving the module mode you are able to additionally check for only one mode within the main module + * + * @param string $module_basename The module base name, for example logs, reports, main (for the mcp). + * @param mixed $module_mode The module mode to check. If provided the mode will be checked in addition for presence. + * + * @return bool Returns true if module is loaded and accessible, else returns false + */ + function loaded($module_basename, $module_mode = false) + { + if (empty($this->loaded_cache)) + { + $this->loaded_cache = array(); + + foreach ($this->module_ary as $row) + { + if (!$row['name']) + { + continue; + } + + if (!isset($this->loaded_cache[$row['name']])) + { + $this->loaded_cache[$row['name']] = array(); + } + + if (!$row['mode']) + { + continue; + } + + $this->loaded_cache[$row['name']][$row['mode']] = true; + } + } + + if ($module_mode === false) + { + return (isset($this->loaded_cache[$module_basename])) ? true : false; + } + + return (!empty($this->loaded_cache[$module_basename][$module_mode])) ? true : false; + } + + /** + * Check module authorisation + */ + function module_auth($module_auth, $forum_id = false) + { + global $auth, $config; + + $module_auth = trim($module_auth); + + // Generally allowed to access module if module_auth is empty + if (!$module_auth) + { + return true; + } + + // With the code below we make sure only those elements get eval'd we really want to be checked + preg_match_all('/(?: + "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" | + \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' | + [(),] | + [^\s(),]+)/x', $module_auth, $match); + + $tokens = $match[0]; + for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) + { + $token = &$tokens[$i]; + + switch ($token) + { + case ')': + case '(': + case '&&': + case '||': + case ',': + break; + + default: + if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token)) + { + $token = ''; + } + break; + } + } + + $module_auth = implode(' ', $tokens); + + // Make sure $id seperation is working fine + $module_auth = str_replace(' , ', ',', $module_auth); + + $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; + + $is_auth = false; + 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) . ');'); + + return $is_auth; + } + + /** + * Set active module + */ + function set_active($id = false, $mode = false) + { + $icat = false; + $this->active_module = false; + + if (request_var('icat', '')) + { + $icat = $id; + $id = request_var('icat', ''); + } + + $category = false; + foreach ($this->module_ary as $row_id => $item_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 ( + (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || + ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) || + (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || + (!$id && !$mode && !$item_ary['cat'] && $item_ary['display']) + ) + { + if ($item_ary['cat']) + { + $id = $icat; + $icat = false; + + continue; + } + + $this->p_id = $item_ary['id']; + $this->p_parent = $item_ary['parent']; + $this->p_name = $item_ary['name']; + $this->p_mode = $item_ary['mode']; + $this->p_left = $item_ary['left']; + $this->p_right = $item_ary['right']; + + $this->module_cache['parents'] = $this->module_cache['parents'][$this->p_id]; + $this->active_module = $item_ary['id']; + $this->active_module_row_id = $row_id; + + break; + } + else if (($item_ary['cat'] && $item_ary['id'] === (int) $id) || ($item_ary['parent'] === $category && $item_ary['cat'])) + { + $category = $item_ary['id']; + } + } + } + + /** + * Loads currently active module + * + * This method loads a given module, passing it the relevant id and mode. + */ + function load_active($mode = false, $module_url = false, $execute_module = true) + { + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user; + + $module_path = $this->include_path . $this->p_class; + $icat = request_var('icat', ''); + + if ($this->active_module === false) + { + trigger_error('Module not accessible', E_USER_ERROR); + } + + 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 $module_path/{$this->p_class}_$this->p_name.$phpEx", 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 file $module_path/{$this->p_class}_$this->p_name.$phpEx does not contain correct class [{$this->p_class}_$this->p_name]", 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); + + // We pre-define the action parameter we are using all over the place + if (defined('IN_ADMIN')) + { + // Is first module automatically enabled a duplicate and the category not passed yet? + if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) + { + $icat = $this->module_ary[$this->active_module_row_id]['parent']; + } + + // Not being able to overwrite ;) + $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + } + else + { + // If user specified the module url we will use it... + if ($module_url !== false) + { + $this->module->u_action = $module_url; + } + else + { + $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; + } + + $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + } + + // Add url_extra parameter to u_action url + if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) + { + $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; + } + + // Assign the module path for re-usage + $this->module->module_path = $module_path . '/'; + + // Execute the main method for the new instance, we send the module id and mode as parameters + // Users are able to call the main method after this function to be able to assign additional parameters manually + if ($execute_module) + { + $this->module->main($this->p_name, $this->p_mode); + } + + return; + } + } + + /** + * Appending url parameter to the currently active module. + * + * This function is called for adding specific url parameters while executing the current module. + * It is doing the same as the _module_{name}_url() function, apart from being able to be called after + * having dynamically parsed specific parameters. This allows more freedom in choosing additional parameters. + * One example can be seen in /includes/mcp/mcp_notes.php - $this->p_master->adjust_url() call. + * + * @param string $url_extra Extra url parameters, e.g.: &u=$user_id + * + */ + function adjust_url($url_extra) + { + if (empty($this->module_ary[$this->active_module_row_id])) + { + return; + } + + $row = &$this->module_ary[$this->active_module_row_id]; + + // We check for the same url_extra in $row['url_extra'] to overcome doubled additions... + if (strpos($row['url_extra'], $url_extra) === false) + { + $row['url_extra'] .= $url_extra; + } + } + + /** + * Check if a module is active + */ + function is_active($id, $mode = false) + { + // If we find a name by this id and being enabled we have our active one... + foreach ($this->module_ary as $row_id => $item_ary) + { + if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display']) + { + if ($mode === false || $mode === $item_ary['mode']) + { + return true; + } + } + } + + return false; + } + + /** + * Get parents + */ + function get_parents($parent_id, $left_id, $right_id, &$all_parents) + { + global $db; + + $parents = array(); + + if ($parent_id > 0) + { + foreach ($all_parents as $module_id => $row) + { + if ($row['left_id'] < $left_id && $row['right_id'] > $right_id) + { + $parents[$module_id] = $row['parent_id']; + } + + if ($row['left_id'] > $left_id) + { + break; + } + } + } + + return $parents; + } + + /** + * Get tree branch + */ + function get_branch($left_id, $right_id, $remaining) + { + $branch = array(); + + foreach ($remaining as $key => $row) + { + if ($row['left_id'] > $left_id && $row['left_id'] < $right_id) + { + $branch[] = $row; + continue; + } + break; + } + + return $branch; + } + + /** + * Build true binary tree from given array + * Not in use + */ + function build_tree(&$modules, &$parents) + { + $tree = array(); + + foreach ($modules as $row) + { + $branch = &$tree; + + if ($row['parent_id']) + { + // Go through the tree to find our branch + $parent_tree = $parents[$row['module_id']]; + + foreach ($parent_tree as $id => $value) + { + if (!isset($branch[$id]) && isset($branch['child'])) + { + $branch = &$branch['child']; + } + $branch = &$branch[$id]; + } + $branch = &$branch['child']; + } + + $branch[$row['module_id']] = $row; + if (!isset($branch[$row['module_id']]['child'])) + { + $branch[$row['module_id']]['child'] = array(); + } + } + + return $tree; + } + + /** + * Build navigation structure + */ + function assign_tpl_vars($module_url) + { + global $template; + + $current_id = $right_id = false; + + // Make sure the module_url has a question mark set, effectively determining the delimiter to use + $delim = (strpos($module_url, '?') === false) ? '?' : '&'; + + $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 => $item_ary) + { + // Skip hidden modules + if (!$item_ary['display']) + { + continue; + } + + // Skip branch + if ($right_id !== false) + { + if ($item_ary['left'] < $right_id) + { + continue; + } + + $right_id = false; + } + + // Category with no members on their way down (we have to check every level) + if (!$item_ary['name']) + { + $empty_category = true; + + // We go through the branch and look for an activated module + foreach (array_slice($this->module_ary, $row_id + 1) as $temp_row) + { + if ($temp_row['left'] > $item_ary['left'] && $temp_row['left'] < $item_ary['right']) + { + // Module there and displayed? + if ($temp_row['name'] && $temp_row['display']) + { + $empty_category = false; + break; + } + continue; + } + break; + } + + // Skip the branch + if ($empty_category) + { + $right_id = $item_ary['right']; + continue; + } + } + + // Select first id we can get + if (!$current_id && (isset($this->module_cache['parents'][$item_ary['id']]) || $item_ary['id'] == $this->p_id)) + { + $current_id = $item_ary['id']; + } + + $depth = $item_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 . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); + + // Was not allowed in categories before - /*!$item_ary['cat'] && */ + $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; + + // Only output a categories items if it's currently selected + if (!$depth || ($depth && (in_array($item_ary['parent'], array_values($this->module_cache['parents'])) || $item_ary['parent'] == $this->p_parent))) + { + $use_tabular_offset = (!$depth) ? 't_block1' : $tabular_offset; + + $tpl_ary = array( + 'L_TITLE' => $item_ary['lang'], + 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_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($item_ary, CASE_UPPER))); + } + + $tpl_ary = array( + 'L_TITLE' => $item_ary['lang'], + 'S_SELECTED' => (isset($this->module_cache['parents'][$item_ary['id']]) || $item_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($item_ary, CASE_UPPER))); + + $current_depth = $depth; + } + } + + /** + * Returns desired template name + */ + function get_tpl_name() + { + return $this->module->tpl_name . '.html'; + } + + /** + * Returns the desired page title + */ + function get_page_title() + { + global $user; + + if (!isset($this->module->page_title)) + { + return ''; + } + + return (isset($user->lang[$this->module->page_title])) ? $user->lang[$this->module->page_title] : $this->module->page_title; + } + + /** + * 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; + + // Set active module to true instead of using the id + $this->active_module = true; + + $this->load_active($mode); + } + + /** + * Display module + */ + function display($page_title, $display_online_list = true) + { + global $template, $user; + + // Generate the page + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + { + adm_page_header($page_title); + } + else + { + page_header($page_title, $display_online_list); + } + + $template->set_filenames(array( + 'body' => $this->get_tpl_name()) + ); + + if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin']) + { + adm_page_footer(); + } + else + { + page_footer(); + } + } + + /** + * Toggle whether this module will be displayed or not + */ + function set_display($id, $mode = false, $display = true) + { + foreach ($this->module_ary as $row_id => $item_ary) + { + if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) + { + $this->module_ary[$row_id]['display'] = (int) $display; + } + } + } + + /** + * Add custom MOD info language file + */ + function add_mod_info($module_class) + { + global $user, $phpEx; + + if (file_exists($user->lang_path . $user->lang_name . '/mods')) + { + $add_files = array(); + + $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); + + if ($dir) + { + while (($entry = readdir($dir)) !== false) + { + if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx) + { + $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1)); + } + } + closedir($dir); + } + + if (sizeof($add_files)) + { + $user->add_lang($add_files); + } + } + } +} + +?> \ No newline at end of file -- cgit v1.2.1 From fccd7f0ab5ab559dc89be6af9e582a986af8bb13 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 22 Sep 2010 21:58:20 +0200 Subject: [feature/request-class] Convert any direct access to $_* to use $request PHPBB3-9716 --- phpBB/includes/functions_module.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index d0e7c8cfc8..194cba7291 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -314,6 +314,7 @@ class p_master function module_auth($module_auth, $forum_id = false) { global $auth, $config; + global $request; $module_auth = trim($module_auth); @@ -361,7 +362,7 @@ class p_master $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; $is_auth = false; - 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) . ');'); + 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\']', '$request->variable(\'\\1\', false)'), $module_auth) . ');'); return $is_auth; } -- cgit v1.2.1 From af5b9a96409d788733fcb1ff367e0c7fb0583702 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Tue, 9 Nov 2010 08:59:25 +0100 Subject: [ticket/9556] Drop php closing tags, add trailing newline Closing tags converted using Oleg's script. remove-php-end-tags.py -a . Trailing newlines added using the following where $ext is file extension. find . -type f -name "*.$ext" -print | xargs printf "e %s\nw\n" | ed -s; Extensions: php, css, html, js, xml. PHPBB3-9556 --- phpBB/includes/functions_module.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 194cba7291..09c54422b0 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -880,5 +880,3 @@ class p_master } } } - -?> \ No newline at end of file -- cgit v1.2.1 From 4844b007771f71973db2fa440d3c8ef9057d1b02 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 22 Aug 2011 03:19:17 -0400 Subject: [feature/extension-manager] Load (A/U/M)CP modules from extensions To avoid large bc breaking changes, modules in the old includes directory structure still follow the same naming conventions. Modules in extensions have to be placed in an xcp/ folder and need a _module suffix. The corresponding info file is in the same directory but with an _info suffix. PHPBB3-10323 --- phpBB/includes/functions_module.php | 84 ++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 43 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 09c54422b0..1a6b57794a 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -440,7 +440,8 @@ class p_master trigger_error('Module not accessible', E_USER_ERROR); } - if (!class_exists("{$this->p_class}_$this->p_name")) + // new modules use the full class names, old ones are always called _, e.g. acp_board + if (!class_exists($this->p_name) && !class_exists("{$this->p_class}_$this->p_name")) { if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) { @@ -453,62 +454,59 @@ class p_master { 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); } + } - if (!empty($mode)) - { - $this->p_mode = $mode; - } + 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"; + // Create a new instance of the desired module ... + $class_name = (class_exists($this->p_name)) ? $this->p_name : "{$this->p_class}_$this->p_name"; - $this->module = new $instance($this); + $this->module = new $class_name($this); - // We pre-define the action parameter we are using all over the place - if (defined('IN_ADMIN')) + // We pre-define the action parameter we are using all over the place + if (defined('IN_ADMIN')) + { + // Is first module automatically enabled a duplicate and the category not passed yet? + if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) { - // Is first module automatically enabled a duplicate and the category not passed yet? - if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) - { - $icat = $this->module_ary[$this->active_module_row_id]['parent']; - } + $icat = $this->module_ary[$this->active_module_row_id]['parent']; + } - // Not being able to overwrite ;) - $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + // Not being able to overwrite ;) + $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + } + else + { + // If user specified the module url we will use it... + if ($module_url !== false) + { + $this->module->u_action = $module_url; } else { - // If user specified the module url we will use it... - if ($module_url !== false) - { - $this->module->u_action = $module_url; - } - else - { - $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; - } - - $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; } - // Add url_extra parameter to u_action url - if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) - { - $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; - } + $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + } - // Assign the module path for re-usage - $this->module->module_path = $module_path . '/'; + // Add url_extra parameter to u_action url + if (!empty($this->module_ary) && $this->active_module !== false && $this->module_ary[$this->active_module_row_id]['url_extra']) + { + $this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra']; + } - // Execute the main method for the new instance, we send the module id and mode as parameters - // Users are able to call the main method after this function to be able to assign additional parameters manually - if ($execute_module) - { - $this->module->main($this->p_name, $this->p_mode); - } + // Assign the module path for re-usage + $this->module->module_path = $module_path . '/'; - return; + // Execute the main method for the new instance, we send the module id and mode as parameters + // Users are able to call the main method after this function to be able to assign additional parameters manually + if ($execute_module) + { + $this->module->main($this->p_name, $this->p_mode); } } -- cgit v1.2.1 From fe4b8818ec1f448d5625534e5027cfbc1177ab9a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 20:54:42 -0400 Subject: [feature/extension-manager] Always store the full class name as module basename The updater swaps out all basenames. PHPBB3-10323 --- phpBB/includes/functions_module.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 1a6b57794a..4d575a7e3a 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -441,18 +441,19 @@ class p_master } // new modules use the full class names, old ones are always called _, e.g. acp_board - if (!class_exists($this->p_name) && !class_exists("{$this->p_class}_$this->p_name")) + if (!class_exists($this->p_name)) { - if (!file_exists("$module_path/{$this->p_class}_$this->p_name.$phpEx")) + if (!file_exists("$module_path/{$this->p_name}.$phpEx")) { - trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR); + + trigger_error("Cannot find module $module_path/{$this->p_name}.$phpEx", E_USER_ERROR); } - include("$module_path/{$this->p_class}_$this->p_name.$phpEx"); + include("$module_path/{$this->p_name}.$phpEx"); - if (!class_exists("{$this->p_class}_$this->p_name")) + if (!class_exists($this->p_name)) { - 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); + trigger_error("Module file $module_path/{$this->p_name}.$phpEx does not contain correct class [{$this->p_name}]", E_USER_ERROR); } } @@ -462,7 +463,7 @@ class p_master } // Create a new instance of the desired module ... - $class_name = (class_exists($this->p_name)) ? $this->p_name : "{$this->p_class}_$this->p_name"; + $class_name = $this->p_name; $this->module = new $class_name($this); -- cgit v1.2.1 From 7b12bba95bb7c59bde65e8ea1ffb1275944fd965 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 13 Oct 2011 17:38:38 +0200 Subject: [feature/extension-manager] Allow old non-prefix basenames to work for lookups These module basenames are hardcoded in a bunch of places so they need to continue to work unless we want to rewrite all of them. PHPBB3-10323 --- phpBB/includes/functions_module.php | 46 +++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 4d575a7e3a..9226a75d4c 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -221,13 +221,15 @@ class p_master // We need to prefix the functions to not create a naming conflict // Function for building 'url_extra' - $url_func = '_module_' . $row['module_basename'] . '_url'; + $short_name = $this->get_short_name($row['module_basename']); + + $url_func = '_module_' . $short_name . '_url'; // Function for building the language name - $lang_func = '_module_' . $row['module_basename'] . '_lang'; + $lang_func = '_module_' . $short_name . '_lang'; // Custom function for calling parameters on module init (for example assigning template variables) - $custom_func = '_module_' . $row['module_basename']; + $custom_func = '_module_' . $short_name; $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; @@ -275,6 +277,11 @@ class p_master */ function loaded($module_basename, $module_mode = false) { + if (!$this->is_full_class($module_basename)) + { + $module_basename = $this->p_class . '_' . $module_basename; + } + if (empty($this->loaded_cache)) { $this->loaded_cache = array(); @@ -381,6 +388,11 @@ class p_master $id = request_var('icat', ''); } + if ($id && !is_numeric($id) && !$this->is_full_class($id)) + { + $id = $this->p_class . '_' . $id; + } + $category = false; foreach ($this->module_ary as $row_id => $item_ary) { @@ -389,9 +401,9 @@ class p_master // 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 ( - (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || + (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && (($item_ary['mode'] == $mode && !$item_ary['cat']) || ($icat && $item_ary['cat']))) || ($item_ary['parent'] === $category && !$item_ary['cat'] && !$icat && $item_ary['display']) || - (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || + (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && !$mode && !$item_ary['cat']) || (!$id && !$mode && !$item_ary['cat'] && $item_ary['display']) ) { @@ -445,7 +457,6 @@ class p_master { if (!file_exists("$module_path/{$this->p_name}.$phpEx")) { - trigger_error("Cannot find module $module_path/{$this->p_name}.$phpEx", E_USER_ERROR); } @@ -507,7 +518,8 @@ class p_master // Users are able to call the main method after this function to be able to assign additional parameters manually if ($execute_module) { - $this->module->main($this->p_name, $this->p_mode); + $short_name = preg_replace("#^{$this->p_class}_#", '', $this->p_name); + $this->module->main($short_name, $this->p_mode); } } @@ -546,7 +558,7 @@ class p_master // If we find a name by this id and being enabled we have our active one... foreach ($this->module_ary as $row_id => $item_ary) { - if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display']) + if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && $item_ary['display'] || $item_ary['name'] === $this->p_class . '_' . $id) { if ($mode === false || $mode === $item_ary['mode']) { @@ -840,7 +852,7 @@ class p_master { foreach ($this->module_ary as $row_id => $item_ary) { - if (($item_ary['name'] === $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) + if (($item_ary['name'] === $id || $item_ary['name'] === $this->p_class . '_' . $id || $item_ary['id'] === (int) $id) && (!$mode || $item_ary['mode'] === $mode)) { $this->module_ary[$row_id]['display'] = (int) $display; } @@ -878,4 +890,20 @@ class p_master } } } + + function get_short_name($basename) + { + if (substr($basename, 0, 6) === 'phpbb_') + { + return $basename; + } + + // strip xcp_ prefix from old classes + return substr($basename, strlen($this->p_class) + 1); + } + + function is_full_class($basename) + { + return (substr($basename, 0, 6) === 'phpbb_' || substr($basename, 0, strlen($this->p_class) + 1) === $this->p_class . '_'); + } } -- cgit v1.2.1 From 639e3b9f17c9bac668b4ad24bb9861d8006fa396 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2011 00:44:48 +0200 Subject: [feature/extension-manager] Support for loading language files from extensions The referenced extension needs to be explicitly specified in an add_lang_ext() call. PHPBB3-10323 --- phpBB/includes/functions_module.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 9226a75d4c..946e7d2b8d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -865,7 +865,7 @@ class p_master function add_mod_info($module_class) { global $user, $phpEx; - +/* if (file_exists($user->lang_path . $user->lang_name . '/mods')) { $add_files = array(); @@ -888,6 +888,23 @@ class p_master { $user->add_lang($add_files); } + }*/ + + global $phpbb_extension_manager; + + $finder = $phpbb_extension_manager->get_finder(); + + $lang_files = $finder + ->prefix('info_' . strtolower($module_class) . '_') + ->suffix(".$phpEx") + ->directory('/language/' . $user->lang_name) + ->default_path('language/' . $user->lang_name . '/mods/') + ->default_directory('') + ->find(); + + foreach ($lang_files as $lang_file => $ext_name) + { + $user->add_lang_ext($ext_name, $lang_file); } } -- cgit v1.2.1 From cd522a11f3f40e0429bebb7bd7cfee1b442a83ef Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2011 01:31:24 +0200 Subject: [feature/extension-manager] Properly remove old ACP language loading code PHPBB3-10323 --- phpBB/includes/functions_module.php | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 946e7d2b8d..e2b2d80b3e 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -865,30 +865,6 @@ class p_master function add_mod_info($module_class) { global $user, $phpEx; -/* - if (file_exists($user->lang_path . $user->lang_name . '/mods')) - { - $add_files = array(); - - $dir = @opendir($user->lang_path . $user->lang_name . '/mods'); - - if ($dir) - { - while (($entry = readdir($dir)) !== false) - { - if (strpos($entry, 'info_' . strtolower($module_class) . '_') === 0 && substr(strrchr($entry, '.'), 1) == $phpEx) - { - $add_files[] = 'mods/' . substr(basename($entry), 0, -(strlen($phpEx) + 1)); - } - } - closedir($dir); - } - - if (sizeof($add_files)) - { - $user->add_lang($add_files); - } - }*/ global $phpbb_extension_manager; -- cgit v1.2.1 From 81ac3698089ce86c1e8a44bafacf881d6d8def4a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 14:43:38 +0100 Subject: [feature/extension-manager] Add docblocks to new methods in functions_module PHPBB3-10323 --- phpBB/includes/functions_module.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index e2b2d80b3e..ce49c3a798 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -884,7 +884,14 @@ class p_master } } - function get_short_name($basename) + /** + * Retrieve shortened module basename for legacy basenames (with xcp_ prefix) + * + * @param string $basename A module basename + * @return string The basename if it starts with phpbb_ or the basename with + * the current p_class (e.g. acp_) stripped. + */ + protected function get_short_name($basename) { if (substr($basename, 0, 6) === 'phpbb_') { @@ -895,7 +902,13 @@ class p_master return substr($basename, strlen($this->p_class) + 1); } - function is_full_class($basename) + /** + * Checks whether the given module basename is a correct class name + * + * @param string $basename A module basename + * @return bool True if the basename starts with phpbb_ or (x)cp_, false otherwise + */ + protected function is_full_class($basename) { return (substr($basename, 0, 6) === 'phpbb_' || substr($basename, 0, strlen($this->p_class) + 1) === $this->p_class . '_'); } -- cgit v1.2.1 From 0d296785b2364f894f34171d054341cc4979223f Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 16:42:53 +0100 Subject: [feature/extension-manager] Rename default methods to core methods on finder. There are now extension_ and core_ methods for all finder settings as well as a generic method which overwrites both. PHPBB3-10323 --- phpBB/includes/functions_module.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ce49c3a798..1f451d392d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -873,9 +873,8 @@ class p_master $lang_files = $finder ->prefix('info_' . strtolower($module_class) . '_') ->suffix(".$phpEx") - ->directory('/language/' . $user->lang_name) - ->default_path('language/' . $user->lang_name . '/mods/') - ->default_directory('') + ->extension_directory('/language/' . $user->lang_name) + ->core_path('language/' . $user->lang_name . '/mods/') ->find(); foreach ($lang_files as $lang_file => $ext_name) -- cgit v1.2.1 From 7a04c9048c110f0bd21ea3e9e869e17b408d640e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 31 Dec 2011 13:32:52 +0000 Subject: [ticket/9916] Updating header license and removing Version $Id$ PHPBB3-9916 --- phpBB/includes/functions_module.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 1f451d392d..d810285313 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -2,9 +2,8 @@ /** * * @package phpBB3 -* @version $Id$ * @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -- cgit v1.2.1 From ffde8c8e06c4d37bef5cde280d520c0791ed2c67 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 6 Jan 2012 17:20:41 +0100 Subject: [ticket/10477] Normalize loaded module names to be class names or xcp_ prefixed PHPBB3-10477 --- phpBB/includes/functions_module.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index d810285313..a6015b1eac 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -804,6 +804,13 @@ class p_master */ function load($class, $name, $mode = false) { + // new modules use the full class names, old ones are always called _, e.g. acp_board + // in the latter case this function may be called as load(acp, board) + if (!class_exists($name) && substr($name, 0, strlen($class) + 1) !== $class . '_') + { + $name = $class . '_' . $name; + } + $this->p_class = $class; $this->p_name = $name; -- cgit v1.2.1 From 3f754d118d8fbd36dcefbeea470ecb267e87ace6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 12 Jan 2012 22:13:28 -0500 Subject: [ticket/10477] Document parameters to p_master#load. PHPBB3-10477 --- phpBB/includes/functions_module.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index a6015b1eac..653623a336 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -438,6 +438,8 @@ class p_master * Loads currently active module * * This method loads a given module, passing it the relevant id and mode. + * + * @param string $mode mode, as passed through to the module */ function load_active($mode = false, $module_url = false, $execute_module = true) { @@ -801,11 +803,16 @@ class p_master /** * Load module as the current active one without the need for registering it + * + * @param string $class module class (acp/mcp/ucp) + * @param string $name module name (e.g. zebra for the ucp_zebra module) + * @param string $mode mode, as passed through to the module + * */ function load($class, $name, $mode = false) { // new modules use the full class names, old ones are always called _, e.g. acp_board - // in the latter case this function may be called as load(acp, board) + // in the latter case this function may be called as load('acp', 'board') if (!class_exists($name) && substr($name, 0, strlen($class) + 1) !== $class . '_') { $name = $class . '_' . $name; -- cgit v1.2.1 From 82c05a7ed6cde2ce1a217b988382167aa94fcf03 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 13 Jan 2012 12:59:29 +0100 Subject: [ticket/10477] Correctly document module (base)name parameter PHPBB3-10477 --- phpBB/includes/functions_module.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 653623a336..b7bb770031 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -805,7 +805,8 @@ class p_master * Load module as the current active one without the need for registering it * * @param string $class module class (acp/mcp/ucp) - * @param string $name module name (e.g. zebra for the ucp_zebra module) + * @param string $name module name (class name of the module, or its basename + * phpbb_ext_foo_acp_bar_module, ucp_zebra or zebra) * @param string $mode mode, as passed through to the module * */ -- cgit v1.2.1 From 6cf7f205903767bf44d1ee1de796d5f3a00774cd Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 9 Feb 2012 01:34:37 +0200 Subject: [ticket/10634] Changing p_master::is_full_class Changing p_master::is_full_class to check allow all module types, not only current type PHPBB3-10634 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index b7bb770031..db7defdc48 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -923,6 +923,6 @@ class p_master */ protected function is_full_class($basename) { - return (substr($basename, 0, 6) === 'phpbb_' || substr($basename, 0, strlen($this->p_class) + 1) === $this->p_class . '_'); + return (preg_match('/^(phpbb|ucp|mcp|acp)_/', $basename)); } } -- cgit v1.2.1 From ccdd176b72250be2e8f72bd13147679a5f2a263b Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 16 Mar 2012 04:56:41 -0400 Subject: [task/php54-ascraeus] Bring p_master#module_auth into PHP 5 era. Split module_auth into a static and a non-static version. Call the static version statically and the non-static version non-statically. PHPBB3-10615 --- phpBB/includes/functions_module.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index db7defdc48..1c1bc42a11 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -128,7 +128,7 @@ class p_master foreach ($this->module_cache['modules'] as $key => $row) { // Not allowed to view module? - if (!$this->module_auth($row['module_auth'])) + if (!$this->module_auth_self($row['module_auth'])) { unset($this->module_cache['modules'][$key]); continue; @@ -315,9 +315,23 @@ class p_master } /** - * Check module authorisation + * Check module authorisation. + * + * This is a non-static version that uses $this->acl_forum_id + * for the forum id. + */ + function module_auth_self($module_auth) + { + return self::module_auth($module_auth, $this->acl_forum_id); + } + + /** + * Check module authorisation. + * + * This is a static version, it must be given $forum_id. + * See also module_auth_self. */ - function module_auth($module_auth, $forum_id = false) + static function module_auth($module_auth, $forum_id) { global $auth, $config; global $request; @@ -365,8 +379,6 @@ class p_master // Make sure $id seperation is working fine $module_auth = str_replace(' , ', ',', $module_auth); - $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; - $is_auth = false; 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\']', '$request->variable(\'\\1\', false)'), $module_auth) . ');'); -- cgit v1.2.1 From 92f771eb82b64bb35e0cd42534ddd0306a6aef68 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Thu, 22 Mar 2012 03:10:14 +0530 Subject: [ticket/10704] minor typo in a comment Make sure $id separation is working fine PHPBB3-10704 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index db7defdc48..ae4f0f238e 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -362,7 +362,7 @@ class p_master $module_auth = implode(' ', $tokens); - // Make sure $id seperation is working fine + // Make sure $id separation is working fine $module_auth = str_replace(' , ', ',', $module_auth); $forum_id = ($forum_id === false) ? $this->acl_forum_id : $forum_id; -- cgit v1.2.1 From 24939c822529f179a436abfa4e4e2f1b5bcb53ec Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 4 Feb 2012 17:29:10 +0000 Subject: [ticket/10601]Move Inbox the default in private messages module Did exactly as the answer here asked: http://area51.phpbb.com/phpBB/viewtopic.php?p=234111 PHPBB3-10601 --- phpBB/includes/functions_module.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ad76be9f2f..6f38dc60ce 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -759,7 +759,25 @@ class p_master } } - $u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); + $u_title = $module_url . $delim . 'i='; + // if the item has a name use it, else use its id + if (empty($item_ary['name'])) + { + $u_title .= $item_ary['id']; + } + else + { + $u_title .= $item_ary['name']; + } + // If the item is not a category append the mode + if (!$item_ary['cat']) + { + if ($item_ary['is_duplicate']) + { + $u_title .= '&icat=' . $current_id; + } + $u_title .= '&mode=' . $item_ary['mode']; + } // Was not allowed in categories before - /*!$item_ary['cat'] && */ $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; -- cgit v1.2.1 From 1d9891588182c831aeb1ce20065f6ceaa3f892b4 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 28 Nov 2012 19:37:16 +0000 Subject: [ticket/10601] Comment to help understanding the code PHPBB3-10601 --- phpBB/includes/functions_module.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 6f38dc60ce..0d387ace6d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -767,6 +767,7 @@ class p_master } else { + // if the category has a name, then use it. $u_title .= $item_ary['name']; } // If the item is not a category append the mode -- cgit v1.2.1 From 24be21636656bf636738449488da3810e489b4a7 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 13:49:56 -0500 Subject: [feature/twig] Attempt to automatically set style dir for ext modules Extension authors can change it themselves if necessary PHPBB3-11598 --- phpBB/includes/functions_module.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 0d387ace6d..5a8ac276cd 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -455,7 +455,7 @@ class p_master */ function load_active($mode = false, $module_url = false, $execute_module = true) { - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $style; $module_path = $this->include_path . $this->p_class; $icat = request_var('icat', ''); @@ -491,6 +491,24 @@ class p_master $this->module = new $class_name($this); + /* + * If this is an extension module, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $module_dir = explode('_', get_class($this->module)); + + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if (!is_null($this->style) && isset($module_dir[3]) && $module_dir[1] === 'ext') + { + $module_style_dir = 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/styles'; + + if (is_dir($module_style_dir)) + { + $style->set_style(array($module_style_dir, 'styles')); + } + } + // We pre-define the action parameter we are using all over the place if (defined('IN_ADMIN')) { -- cgit v1.2.1 From 38700a80f805ae32632d88254e714699b8435f61 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 14:09:50 -0500 Subject: [feature/twig] Fix copy/pasted code PHPBB3-11598 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 5a8ac276cd..85ff41500f 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -499,7 +499,7 @@ class p_master $module_dir = explode('_', get_class($this->module)); // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if (!is_null($this->style) && isset($module_dir[3]) && $module_dir[1] === 'ext') + if (isset($module_dir[3]) && $module_dir[1] === 'ext') { $module_style_dir = 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/styles'; -- cgit v1.2.1 From 53496e6a473f1e5563f733365cbeaf275c2fd0af Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 15:21:57 -0500 Subject: [feature/twig] acp module tpls are in ext/adm, ucp/mcp in styles/ PHPBB3-11598 --- phpBB/includes/functions_module.php | 52 +++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 85ff41500f..df0327db0f 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -455,7 +455,7 @@ class p_master */ function load_active($mode = false, $module_url = false, $execute_module = true) { - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $style; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $phpbb_style; $module_path = $this->include_path . $this->p_class; $icat = request_var('icat', ''); @@ -491,27 +491,27 @@ class p_master $this->module = new $class_name($this); - /* - * If this is an extension module, we'll try to automatically set - * the style paths for the extension (the ext author can change them - * if necessary). - */ - $module_dir = explode('_', get_class($this->module)); - - // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if (isset($module_dir[3]) && $module_dir[1] === 'ext') + // We pre-define the action parameter we are using all over the place + if (defined('IN_ADMIN')) { - $module_style_dir = 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/styles'; + /* + * If this is an extension module, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $module_dir = explode('_', get_class($this->module)); - if (is_dir($module_style_dir)) + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if (isset($module_dir[3]) && $module_dir[1] === 'ext') { - $style->set_style(array($module_style_dir, 'styles')); + $module_style_dir = $phpbb_root_path .'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/adm/style'; + + if (is_dir($module_style_dir)) + { + $phpbb_style->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), array(), ''); + } } - } - // We pre-define the action parameter we are using all over the place - if (defined('IN_ADMIN')) - { // Is first module automatically enabled a duplicate and the category not passed yet? if (!$icat && $this->module_ary[$this->active_module_row_id]['is_duplicate']) { @@ -523,6 +523,24 @@ class p_master } else { + /* + * If this is an extension module, we'll try to automatically set + * the style paths for the extension (the ext author can change them + * if necessary). + */ + $module_dir = explode('_', get_class($this->module)); + + // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... + if (isset($module_dir[3]) && $module_dir[1] === 'ext') + { + $module_style_dir = 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/styles'; + + if (is_dir($phpbb_root_path . $module_style_dir)) + { + $phpbb_style->set_style(array($module_style_dir, 'styles')); + } + } + // If user specified the module url we will use it... if ($module_url !== false) { -- cgit v1.2.1 From 0f3086a54bf2a9c83876a135738bdf130e0f0844 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Thu, 4 Jul 2013 15:24:42 -0500 Subject: [feature/twig] Spacing PHPBB3-11598 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index df0327db0f..99c24fcb19 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -504,7 +504,7 @@ class p_master // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... if (isset($module_dir[3]) && $module_dir[1] === 'ext') { - $module_style_dir = $phpbb_root_path .'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/adm/style'; + $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/adm/style'; if (is_dir($module_style_dir)) { -- cgit v1.2.1 From 5d1afb453211d42a8deacb66684c136385918192 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 24 Jul 2013 12:24:35 -0500 Subject: [ticket/11628] Remove phpbb_style (move methods to phpbb_template) PHPBB3-11628 --- phpBB/includes/functions_module.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 99c24fcb19..a5ece1ecac 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -455,7 +455,7 @@ class p_master */ function load_active($mode = false, $module_url = false, $execute_module = true) { - global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $phpbb_style; + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $user, $template; $module_path = $this->include_path . $this->p_class; $icat = request_var('icat', ''); @@ -508,7 +508,7 @@ class p_master if (is_dir($module_style_dir)) { - $phpbb_style->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), array(), ''); + $template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), array(), ''); } } @@ -537,7 +537,7 @@ class p_master if (is_dir($phpbb_root_path . $module_style_dir)) { - $phpbb_style->set_style(array($module_style_dir, 'styles')); + $template->set_style(array($module_style_dir, 'styles')); } } -- cgit v1.2.1 From 4b761f65758c40db4851983fa3a08d354da3323d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 24 Jul 2013 12:55:41 -0500 Subject: [ticket/11628] Remove third parameter ($names) from set_custom_style This was basically duplicating functionality. $names would be used if not empty, else array($name) would be used. Merged functionality into the first argument PHPBB3-11628 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index a5ece1ecac..c84e02afe6 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -508,7 +508,7 @@ class p_master if (is_dir($module_style_dir)) { - $template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), array(), ''); + $template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), ''); } } -- cgit v1.2.1 From 12c22585069066957cc3211136ebd480295d4758 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 24 Jul 2013 13:25:20 -0500 Subject: [ticket/11628] Remove template_path option on set_custom_style This was set to default 'template/' to append template/ to all the paths, but every location was actually just setting it to '' to not append anything. So removed the option entirely (additional paths can be appended to the paths being sent to the function already) PHPBB3-11628 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index c84e02afe6..8f0f6a837a 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -508,7 +508,7 @@ class p_master if (is_dir($module_style_dir)) { - $template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style'), ''); + $template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style')); } } -- cgit v1.2.1 From 8ee86b75908141c28aa4d92ba93921337cde30c3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 28 Aug 2013 13:40:35 -0500 Subject: [ticket/11791] Load adm/ events from styles/adm/event/ PHPBB3-11791 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 8f0f6a837a..80477684a8 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -508,7 +508,7 @@ class p_master if (is_dir($module_style_dir)) { - $template->set_custom_style('admin', array($module_style_dir, $phpbb_admin_path . 'style')); + $template->set_custom_style('adm', array($module_style_dir, $phpbb_admin_path . 'style')); } } -- cgit v1.2.1 From 6b71284681483534a0c5511b689af1e8a0c9cdc9 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 19 Sep 2013 19:53:57 +0200 Subject: [ticket/11700] Correctly load templates for extensions PHPBB3-11700 --- phpBB/includes/functions_module.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 80477684a8..b33f3d6866 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -499,12 +499,12 @@ class p_master * the style paths for the extension (the ext author can change them * if necessary). */ - $module_dir = explode('_', get_class($this->module)); + $module_dir = explode('\\', get_class($this->module)); - // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if (isset($module_dir[3]) && $module_dir[1] === 'ext') + // 0 vendor, 1 extension name, ... + if (isset($module_dir[1])) { - $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/adm/style'; + $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/adm/style'; if (is_dir($module_style_dir)) { @@ -973,7 +973,7 @@ class p_master */ protected function get_short_name($basename) { - if (substr($basename, 0, 6) === 'phpbb_') + if (substr($basename, 0, 6) === 'phpbb\\' || strpos($basename, '\\') !== false) { return $basename; } @@ -990,6 +990,6 @@ class p_master */ protected function is_full_class($basename) { - return (preg_match('/^(phpbb|ucp|mcp|acp)_/', $basename)); + return (strpos($basename, '\\') !== false || preg_match('/^(ucp|mcp|acp)_/', $basename)); } } -- cgit v1.2.1 From 2ab3ee7d67f99f1e6b7702b22e79c3a5af85adf8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 2 Oct 2013 22:37:16 +0200 Subject: [ticket/11871] Fallback to int ID of the module, when creating links Firefox is currently unable to correctly copy a urlencoded \ so users will be unable to post links to modules. However we can still fallback to the id instead of the name, so we do that in this case. PHPBB3-11871 --- phpBB/includes/functions_module.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index b33f3d6866..dca720c36e 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -519,7 +519,7 @@ class p_master } // Not being able to overwrite ;) - $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=' . $this->get_module_identifier($this->p_name, $this->p_id)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } else { @@ -551,7 +551,7 @@ class p_master $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; } - $this->module->u_action = append_sid($this->module->u_action, "i={$this->p_name}") . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = append_sid($this->module->u_action, 'i=' . $this->get_module_identifier($this->p_name, $this->p_id)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } // Add url_extra parameter to u_action url @@ -799,12 +799,12 @@ class p_master // if the item has a name use it, else use its id if (empty($item_ary['name'])) { - $u_title .= $item_ary['id']; + $u_title .= $item_ary['id']; } else { // if the category has a name, then use it. - $u_title .= $item_ary['name']; + $u_title .= $this->get_module_identifier($item_ary['name'], $item_ary['id']); } // If the item is not a category append the mode if (!$item_ary['cat']) @@ -982,6 +982,29 @@ class p_master return substr($basename, strlen($this->p_class) + 1); } + /** + * If the basename contains a \ we dont use that for the URL. + * + * Firefox is currently unable to correctly copy a urlencoded \ + * so users will be unable to post links to modules. + * However we can still fallback to the id instead of the name, + * so we do that in this case. + * + * @param string $basename Basename of the module + * @param int $id Id of the module + * @return mixed Identifier that should be used for + * module link creation + */ + protected function get_module_identifier($basename, $id) + { + if (strpos($basename, '\\') === false) + { + return $basename; + } + + return $id; + } + /** * Checks whether the given module basename is a correct class name * -- cgit v1.2.1 From fa31096cb98a8c26377121f26ea79520dcab00f9 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Wed, 20 Nov 2013 22:57:41 +0100 Subject: [ticket/12026] Correct path for template files Correct path for template files in MCP and UCP modules, which are added via extenstions PHPBB3-12026 --- phpBB/includes/functions_module.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index dca720c36e..ac13a99aa2 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -528,12 +528,12 @@ class p_master * the style paths for the extension (the ext author can change them * if necessary). */ - $module_dir = explode('_', get_class($this->module)); + $module_dir = explode('\\', get_class($this->module)); - // 0 phpbb, 1 ext, 2 vendor, 3 extension name, ... - if (isset($module_dir[3]) && $module_dir[1] === 'ext') + // 0 vendor, 1 extension name, ... + if (isset($module_dir[1])) { - $module_style_dir = 'ext/' . $module_dir[2] . '/' . $module_dir[3] . '/styles'; + $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/styles'; if (is_dir($phpbb_root_path . $module_style_dir)) { -- cgit v1.2.1 From fc778fe63706d21ce2fd78f10e5c8f4dec29ed3b Mon Sep 17 00:00:00 2001 From: Lukasz Date: Wed, 20 Nov 2013 23:04:56 +0100 Subject: [ticket/12026] Remove phpbb root path PHPBB3-12026 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ac13a99aa2..0d0f79a16d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -535,7 +535,7 @@ class p_master { $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/styles'; - if (is_dir($phpbb_root_path . $module_style_dir)) + if (is_dir($module_style_dir)) { $template->set_style(array($module_style_dir, 'styles')); } -- cgit v1.2.1 From a5f1dc67b9a29b80f584ca753260fb8dbe459a43 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 3 Dec 2013 10:02:53 +0100 Subject: [ticket/12026] Remove root path, its prepended later PHPBB3-12026 --- phpBB/includes/functions_module.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 0d0f79a16d..e1259eba12 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -533,9 +533,9 @@ class p_master // 0 vendor, 1 extension name, ... if (isset($module_dir[1])) { - $module_style_dir = $phpbb_root_path . 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/styles'; + $module_style_dir = 'ext/' . $module_dir[0] . '/' . $module_dir[1] . '/styles'; - if (is_dir($module_style_dir)) + if (is_dir($phpbb_root_path . $module_style_dir)) { $template->set_style(array($module_style_dir, 'styles')); } -- cgit v1.2.1 From 7740ab5dc35734177e64bed3a21a94ab11d5d0aa Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Dec 2013 11:31:24 -0600 Subject: [ticket/12006] Cleanup the module auth function token replacement code PHPBB3-12006 --- phpBB/includes/functions_module.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index e1259eba12..a8855a3be2 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -351,6 +351,15 @@ class p_master [(),] | [^\s(),]+)/x', $module_auth, $match); + // Valid tokens for auth and their replacements + $valid_tokens = array( + 'acl_([a-z0-9_]+)(,\$id)?' => '(int) $auth->acl_get(\'\\1\'\\2)', + '\$id' => '(int) $forum_id', + 'aclf_([a-z0-9_]+)' => '(int) $auth->acl_getf_global(\'\\1\')', + 'cfg_([a-z0-9_]+)' => '(int) $config[\'\\1\']', + 'request_([a-zA-Z0-9_]+)' => '$request->variable(\'\\1\', false)', + ); + $tokens = $match[0]; for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) { @@ -366,7 +375,7 @@ class p_master break; default: - if (!preg_match('#(?:acl_([a-z0-9_]+)(,\$id)?)|(?:\$id)|(?:aclf_([a-z0-9_]+))|(?:cfg_([a-z0-9_]+))|(?:request_([a-zA-Z0-9_]+))#', $token)) + if (!preg_match('#(?:' . implode(array_keys($valid_tokens), ')|(?:') . ')#', $token)) { $token = ''; } @@ -379,8 +388,17 @@ class p_master // Make sure $id separation is working fine $module_auth = str_replace(' , ', ',', $module_auth); + $module_auth = preg_replace( + // Array keys with # prepended/appended + array_map(function($value){ + return '#' . $value . '#'; + }, array_keys($valid_tokens)), + array_values($valid_tokens), + $module_auth + ); + $is_auth = false; - 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\']', '$request->variable(\'\\1\', false)'), $module_auth) . ');'); + eval('$is_auth = (int) (' . $module_auth . ');'); return $is_auth; } -- cgit v1.2.1 From 05cf83aca7a8f3ddacff932419508a65cfe48455 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Dec 2013 11:46:51 -0600 Subject: [ticket/12006] Add extension enabled check token to module auth PHPBB3-12006 --- phpBB/includes/functions_module.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index a8855a3be2..ea3b3356bb 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -334,7 +334,7 @@ class p_master static function module_auth($module_auth, $forum_id) { global $auth, $config; - global $request; + global $request, $phpbb_extension_manager; $module_auth = trim($module_auth); @@ -358,6 +358,7 @@ class p_master 'aclf_([a-z0-9_]+)' => '(int) $auth->acl_getf_global(\'\\1\')', 'cfg_([a-z0-9_]+)' => '(int) $config[\'\\1\']', 'request_([a-zA-Z0-9_]+)' => '$request->variable(\'\\1\', false)', + 'ext_([a-zA-Z0-9_/]+)' => 'array_key_exists(\'\\1\', $phpbb_extension_manager->all_enabled())', ); $tokens = $match[0]; -- cgit v1.2.1 From e3cba9ceba4994bbc4006f7107a3f5baee21e71d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 10 Jan 2014 13:14:50 -0600 Subject: [ticket/12006] Add module_auth event PHPBB3-12006 --- phpBB/includes/functions_module.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ea3b3356bb..88e3fbce2f 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -361,6 +361,20 @@ class p_master 'ext_([a-zA-Z0-9_/]+)' => 'array_key_exists(\'\\1\', $phpbb_extension_manager->all_enabled())', ); + /** + * Alter tokens for module authorisation check + * + * @event core.module_auth + * @var array valid_tokens Valid tokens and their auth check + * replacements + * @var string module_auth The module_auth of the current + * module + * @var int forum_id The current forum_id + * @since 3.1-A3 + */ + $vars = array('valid_tokens', 'module_auth', 'forum_id'); + extract($phpbb_dispatcher->trigger_event('core.module_auth', compact($vars))); + $tokens = $match[0]; for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) { -- cgit v1.2.1 From 7bac4bf9bd439f08f7aeb6ca67bdc14789a28d4c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 10 Jan 2014 13:15:37 -0600 Subject: [ticket/12006] Missing a space PHPBB3-12006 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 88e3fbce2f..cd84902acf 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -405,7 +405,7 @@ class p_master $module_auth = preg_replace( // Array keys with # prepended/appended - array_map(function($value){ + array_map(function($value) { return '#' . $value . '#'; }, array_keys($valid_tokens)), array_values($valid_tokens), -- cgit v1.2.1 From 2cf4b68351aa3abcb63f51e33e491ada097ded7c Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 17 Jan 2014 20:26:59 -0600 Subject: [ticket/12006] global $phpbb_dispatcher; PHPBB3-12006 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index cd84902acf..53055752f6 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -334,7 +334,7 @@ class p_master static function module_auth($module_auth, $forum_id) { global $auth, $config; - global $request, $phpbb_extension_manager; + global $request, $phpbb_extension_manager, $phpbb_dispatcher; $module_auth = trim($module_auth); -- cgit v1.2.1 From eb1dd47e394702460e182d82990b828aa629fc1b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 11 Mar 2014 10:38:53 +0100 Subject: [ticket/11581] Hide categories when they have no visible children PHPBB3-11581 --- phpBB/includes/functions_module.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 28af7994c8..4d0f7205b4 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -125,8 +125,17 @@ class p_master // Clean up module cache array to only let survive modules the user can access $right_id = false; + + $hide_categories = array(); foreach ($this->module_cache['modules'] as $key => $row) { + // When the module has no mode (category) we check whether it has visible children + // before listing it as well. + if (!$row['module_mode']) + { + $hide_categories[(int) $row['module_id']] = $key; + } + // Not allowed to view module? if (!$this->module_auth_self($row['module_auth'])) { @@ -161,6 +170,22 @@ class p_master $right_id = $row['right_id']; continue; } + + if ($row['module_mode']) + { + // The parent category has a visible child + // So remove it and all its parents from the hide array + unset($hide_categories[(int) $row['parent_id']]); + foreach ($this->module_cache['parents'][$row['module_id']] as $module_id => $row_id) + { + unset($hide_categories[$module_id]); + } + } + } + + foreach ($hide_categories as $module_id => $row_id) + { + unset($this->module_cache['modules'][$row_id]); } // Re-index (this is needed, else we are not able to array_slice later) -- cgit v1.2.1 From 76f7ef5c837345c80f0dcefb6787f23a9c0159e7 Mon Sep 17 00:00:00 2001 From: geetakshi Date: Mon, 24 Mar 2014 00:12:40 +0530 Subject: [ticket/11360] Updating default value of $display_online_list PHPBB3-11360 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index e043883145..ef2e009a6e 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -956,7 +956,7 @@ class p_master /** * Display module */ - function display($page_title, $display_online_list = true) + function display($page_title, $display_online_list = false) { global $template, $user; -- cgit v1.2.1 From 4b26292df26e34530e5ad2725f45033abf84b296 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 1 Apr 2014 00:06:06 +0800 Subject: [ticket/12336] Add functions_module.php core event Add functions_module.php core event to allow adjusting parameters for custom ACP, MCP, UCP modules (location: function list_modules()). PHPBB3-12336 --- phpBB/includes/functions_module.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ef2e009a6e..be066de0f0 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -80,7 +80,7 @@ class p_master function list_modules($p_class) { global $auth, $db, $user, $cache; - global $config, $phpbb_root_path, $phpEx; + global $config, $phpbb_root_path, $phpEx, $phpbb_dispatcher; // Sanitise for future path use, it's escaped as appropriate for queries $this->p_class = str_replace(array('.', '/', '\\'), '', basename($p_class)); @@ -284,6 +284,20 @@ class p_master $custom_func($row['module_mode'], $module_row); } + /** + * This event allows to modify parameters for building modules list + * + * @event core.modify_module_row + * @var string url_func Function for building 'url_extra' + * @var string lang_func Function for building the language name + * @var string custom_func Custom function for calling parameters on module init + * @var array row Array holding the basic module data + * @var array module_row Array holding the module display parameters + * @since 3.1.0-b3 + */ + $vars = array('url_func', 'lang_func', 'custom_func', 'row', 'module_row'); + extract($phpbb_dispatcher->trigger_event('core.modify_module_row', compact($vars))); + $this->module_ary[] = $module_row; } -- cgit v1.2.1 From 57146ccdd124073d70002b25d8e02868b8201b0a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 14 Oct 2013 20:10:00 +0200 Subject: [ticket/11917] Hide OAuth UCP Module when OAuth is not the selected backend PHPBB3-11917 --- phpBB/includes/functions_module.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index be066de0f0..98b2848c19 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -398,6 +398,7 @@ class p_master 'cfg_([a-z0-9_]+)' => '(int) $config[\'\\1\']', 'request_([a-zA-Z0-9_]+)' => '$request->variable(\'\\1\', false)', 'ext_([a-zA-Z0-9_/]+)' => 'array_key_exists(\'\\1\', $phpbb_extension_manager->all_enabled())', + 'authmethod_([a-z0-9_\\\\]+)' => '($config[\'auth_method\'] === \'\\1\')', ); /** -- cgit v1.2.1 From 7b5321092639b0f508fe160f5a58b834247982dd Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 17 Apr 2014 15:06:24 +0200 Subject: [ticket/12273] Fix invalid @event and @since tags PHPBB3-12273 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index be066de0f0..7531883ed9 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -409,7 +409,7 @@ class p_master * @var string module_auth The module_auth of the current * module * @var int forum_id The current forum_id - * @since 3.1-A3 + * @since 3.1.0-a3 */ $vars = array('valid_tokens', 'module_auth', 'forum_id'); extract($phpbb_dispatcher->trigger_event('core.module_auth', compact($vars))); -- cgit v1.2.1 From 9d7c36041e0dac509476069ee5bbce92e841f33e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 14 May 2014 02:16:32 +0200 Subject: [ticket/12509] Update calls to set_custom_style in forgotten places PHPBB3-12509 --- phpBB/includes/functions_module.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 04efcb7b2e..9ef0754120 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -581,7 +581,12 @@ class p_master if (is_dir($module_style_dir)) { - $template->set_custom_style('adm', array($module_style_dir, $phpbb_admin_path . 'style')); + $template->set_custom_style(array( + array( + 'name' => 'adm', + 'ext_path' => 'adm/style/', + ) + ), array($module_style_dir, $phpbb_admin_path . 'style')); } } -- cgit v1.2.1 From 9a846e447ba98b175c510d9fbe7741648296a1ba Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Mon, 26 May 2014 23:44:30 +0200 Subject: [ticket/12509] Add missing ',' in arrays PHPBB3-12509 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 9ef0754120..86d3a3a077 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -585,7 +585,7 @@ class p_master array( 'name' => 'adm', 'ext_path' => 'adm/style/', - ) + ), ), array($module_style_dir, $phpbb_admin_path . 'style')); } } -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/includes/functions_module.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 04efcb7b2e..5d456e6355 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -17,7 +21,6 @@ if (!defined('IN_PHPBB')) /** * Class handling all types of 'plugins' (a future term) -* @package phpBB3 */ class p_master { -- cgit v1.2.1 From 5a320adc75faffe27d9d0b822e30106f1d27f2c2 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 15 Jun 2014 22:03:39 +0200 Subject: [ticket/12724] Add Squiz.PHP.Eval in the legacy ruleset PHPBB3-12724 --- phpBB/includes/functions_module.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 51284af233..b7615e923b 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -456,7 +456,9 @@ class p_master ); $is_auth = false; + // @codingStandardsIgnoreStart eval('$is_auth = (int) (' . $module_auth . ');'); + // @codingStandardsIgnoreEnd return $is_auth; } -- cgit v1.2.1 From 0abc1f0f973e916f12b0c5cf0e844c991f63c552 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 23 Jun 2014 22:46:20 +0200 Subject: [ticket/12612] Prefix custom UCP module function with phpbb_ PHPBB3-12612 --- phpBB/includes/functions_module.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index b7615e923b..41c6f0118e 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -256,7 +256,7 @@ class p_master $lang_func = '_module_' . $short_name . '_lang'; // Custom function for calling parameters on module init (for example assigning template variables) - $custom_func = '_module_' . $short_name; + $custom_func = 'phpbb_module_' . $short_name; $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; @@ -286,6 +286,14 @@ class p_master { $custom_func($row['module_mode'], $module_row); } + else + { + $custom_func = '_module_' . $short_name; + if (function_exists($custom_func)) + { + $custom_func($row['module_mode'], $module_row); + } + } /** * This event allows to modify parameters for building modules list -- cgit v1.2.1 From bba23f61b334a32faf8c33b62266ae55fa4616a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 23 Jun 2014 22:54:15 +0200 Subject: [ticket/12612] Prefix module url functions with phpbb_ PHPBB3-12612 --- phpBB/includes/functions_module.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 41c6f0118e..86439ea03f 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -250,13 +250,25 @@ class p_master // Function for building 'url_extra' $short_name = $this->get_short_name($row['module_basename']); - $url_func = '_module_' . $short_name . '_url'; + $url_func = 'phpbb_module_' . $short_name . '_url'; + if (!function_exists($url_func)) + { + $url_func = '_module_' . $short_name . '_url'; + } // Function for building the language name - $lang_func = '_module_' . $short_name . '_lang'; + $lang_func = 'phpbb_module_' . $short_name . '_lang'; + if (!function_exists($lang_func)) + { + $lang_func = '_module_' . $short_name . '_lang'; + } // Custom function for calling parameters on module init (for example assigning template variables) $custom_func = 'phpbb_module_' . $short_name; + if (!function_exists($custom_func)) + { + $custom_func = '_module_' . $short_name; + } $names[$row['module_basename'] . '_' . $row['module_mode']][] = true; @@ -286,14 +298,6 @@ class p_master { $custom_func($row['module_mode'], $module_row); } - else - { - $custom_func = '_module_' . $short_name; - if (function_exists($custom_func)) - { - $custom_func($row['module_mode'], $module_row); - } - } /** * This event allows to modify parameters for building modules list -- cgit v1.2.1 From ffcf45abf32fc1343fe1d4edfd15828782ab4832 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Mon, 19 May 2014 03:07:32 +0300 Subject: [ticket/12557] Fix doc block errors found by Sami pt1 PHPBB3-12557 --- phpBB/includes/functions_module.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 86439ea03f..143d673db2 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -542,6 +542,8 @@ class p_master * This method loads a given module, passing it the relevant id and mode. * * @param string $mode mode, as passed through to the module + * @param string|false $module_url If supplied, we use this module url + * @param bool $execute_module If true, at the end we execute the main method for the new instance */ function load_active($mode = false, $module_url = false, $execute_module = true) { -- cgit v1.2.1 From 591d04157e7a346c0021855aff36fa6d061cabff Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Aug 2014 20:33:21 +0200 Subject: [ticket/12875] Find language files in the default and english language ... ... when looking for info_xcp_ files. PHPBB3-12875 --- phpBB/includes/functions_module.php | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 86439ea03f..f17333edda 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -1040,19 +1040,45 @@ class p_master */ function add_mod_info($module_class) { - global $user, $phpEx; - - global $phpbb_extension_manager; + global $config, $user, $phpEx, $phpbb_extension_manager; $finder = $phpbb_extension_manager->get_finder(); - $lang_files = $finder + // We grab the language files from the default, English and user's language. + // So we can fall back to the other files like we do when using add_lang() + $default_lang_files = $english_lang_files = $user_lang_files = array(); + + // Search for board default language if it's not the user language + if ($config['default_lang'] != $user->lang_name) + { + $default_lang_files = $finder + ->prefix('info_' . strtolower($module_class) . '_') + ->suffix(".$phpEx") + ->extension_directory('/language/' . basename($config['default_lang'])) + ->core_path('language/' . basename($config['default_lang']) . '/mods/') + ->find(); + } + + // Search for english, if its not the default or user language + if ($config['default_lang'] != 'en' && $user->lang_name != 'en') + { + $english_lang_files = $finder + ->prefix('info_' . strtolower($module_class) . '_') + ->suffix(".$phpEx") + ->extension_directory('/language/en') + ->core_path('language/en/mods/') + ->find(); + } + + // Find files in the user's language + $user_lang_files = $finder ->prefix('info_' . strtolower($module_class) . '_') ->suffix(".$phpEx") ->extension_directory('/language/' . $user->lang_name) ->core_path('language/' . $user->lang_name . '/mods/') ->find(); + $lang_files = array_unique(array_merge($user_lang_files, $english_lang_files, $default_lang_files)); foreach ($lang_files as $lang_file => $ext_name) { $user->add_lang_ext($ext_name, $lang_file); -- cgit v1.2.1 From cea0cfa6f8f41ebeb73a0a90f789bfb4190009b6 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Thu, 7 Aug 2014 13:22:07 +0300 Subject: [ticket/12557] Fix load active module description PHPBB3-12557 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 143d673db2..824afe9237 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -541,7 +541,7 @@ class p_master * * This method loads a given module, passing it the relevant id and mode. * - * @param string $mode mode, as passed through to the module + * @param string|false $mode mode, as passed through to the module * @param string|false $module_url If supplied, we use this module url * @param bool $execute_module If true, at the end we execute the main method for the new instance */ -- cgit v1.2.1 From f1419ab27e5e49d177b8ff25e0ad9c3c8f6ddf76 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 7 Aug 2014 14:06:45 +0200 Subject: [ticket/12919] Use the modules basename as identifier for extension modules PHPBB3-12919 --- phpBB/includes/functions_module.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 397e6401ff..fe9bcdb9d1 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -489,6 +489,12 @@ class p_master $id = request_var('icat', ''); } + // Restore the backslashes in class names + if (strpos($id, '-') !== false) + { + $id = str_replace('-', '\\', $id); + } + if ($id && !is_numeric($id) && !$this->is_full_class($id)) { $id = $this->p_class . '_' . $id; @@ -616,7 +622,7 @@ class p_master } // Not being able to overwrite ;) - $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=' . $this->get_module_identifier($this->p_name, $this->p_id)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=' . $this->get_module_identifier($this->p_name)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } else { @@ -648,7 +654,7 @@ class p_master $this->module->u_action = $phpbb_root_path . (($user->page['page_dir']) ? $user->page['page_dir'] . '/' : '') . $user->page['page_name']; } - $this->module->u_action = append_sid($this->module->u_action, 'i=' . $this->get_module_identifier($this->p_name, $this->p_id)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; + $this->module->u_action = append_sid($this->module->u_action, 'i=' . $this->get_module_identifier($this->p_name)) . (($icat) ? '&icat=' . $icat : '') . "&mode={$this->p_mode}"; } // Add url_extra parameter to u_action url @@ -901,7 +907,7 @@ class p_master else { // if the category has a name, then use it. - $u_title .= $this->get_module_identifier($item_ary['name'], $item_ary['id']); + $u_title .= $this->get_module_identifier($item_ary['name']); } // If the item is not a category append the mode if (!$item_ary['cat']) @@ -1106,26 +1112,24 @@ class p_master } /** - * If the basename contains a \ we dont use that for the URL. + * If the basename contains a \ we don't use that for the URL. * * Firefox is currently unable to correctly copy a urlencoded \ * so users will be unable to post links to modules. - * However we can still fallback to the id instead of the name, - * so we do that in this case. + * However we can replace them with dashes and re-replace them later * * @param string $basename Basename of the module - * @param int $id Id of the module - * @return mixed Identifier that should be used for + * @return string Identifier that should be used for * module link creation */ - protected function get_module_identifier($basename, $id) + protected function get_module_identifier($basename) { if (strpos($basename, '\\') === false) { return $basename; } - return $id; + return str_replace('\\', '-', $basename); } /** -- cgit v1.2.1 From a462f14aa367e9b8f94c4d2da35458353bad8c0f Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Tue, 28 Apr 2015 01:01:09 +0200 Subject: [ticket/13790] Update phpcs PHPBB3-13790 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index fe9bcdb9d1..eb1ff2e7ca 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -976,7 +976,7 @@ class p_master * * @param string $class module class (acp/mcp/ucp) * @param string $name module name (class name of the module, or its basename - * phpbb_ext_foo_acp_bar_module, ucp_zebra or zebra) + * phpbb_ext_foo_acp_bar_module, ucp_zebra or zebra) * @param string $mode mode, as passed through to the module * */ -- cgit v1.2.1 From 33239183aed443950d167a16e2f8148f5a5c1852 Mon Sep 17 00:00:00 2001 From: rxu Date: Wed, 27 May 2015 02:15:12 +0700 Subject: [ticket/13868] Correctly handle acp/mcp/ucp modules lang files for extensions PHPBB3-13868 --- phpBB/includes/functions_module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_module.php') diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index fe9bcdb9d1..f9ceecff63 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -1086,7 +1086,7 @@ class p_master ->core_path('language/' . $user->lang_name . '/mods/') ->find(); - $lang_files = array_unique(array_merge($user_lang_files, $english_lang_files, $default_lang_files)); + $lang_files = array_merge($english_lang_files, $default_lang_files, $user_lang_files); foreach ($lang_files as $lang_file => $ext_name) { $user->add_lang_ext($ext_name, $lang_file); -- cgit v1.2.1