diff options
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/acp/acp_modules.php | 10 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_search.php | 8 | ||||
-rw-r--r-- | phpBB/includes/captcha/captcha_factory.php | 5 | ||||
-rw-r--r-- | phpBB/includes/cron/task/provider.php | 8 | ||||
-rw-r--r-- | phpBB/includes/extension/finder.php | 168 | ||||
-rw-r--r-- | phpBB/includes/functions_module.php | 5 |
6 files changed, 112 insertions, 92 deletions
diff --git a/phpBB/includes/acp/acp_modules.php b/phpBB/includes/acp/acp_modules.php index a4e140ecfe..e51b440d4d 100644 --- a/phpBB/includes/acp/acp_modules.php +++ b/phpBB/includes/acp/acp_modules.php @@ -544,12 +544,10 @@ class acp_modules $finder = $phpbb_extension_manager->get_finder(); $modules = $finder - ->suffix('_module') - ->directory("/$module_class") - ->default_path("includes/$module_class/info/") - ->default_suffix('') - ->default_prefix($module_class . '_') - ->default_directory('') + ->extension_suffix('_module') + ->extension_directory("/$module_class") + ->core_path("includes/$module_class/info/") + ->core_prefix($module_class . '_') ->get_classes(); foreach ($modules as $module) diff --git a/phpBB/includes/acp/acp_search.php b/phpBB/includes/acp/acp_search.php index 0c34d02ac7..049a70647f 100644 --- a/phpBB/includes/acp/acp_search.php +++ b/phpBB/includes/acp/acp_search.php @@ -559,11 +559,9 @@ class acp_search $finder = $phpbb_extension_manager->get_finder(); return $finder - ->suffix('_backend') - ->directory('/search') - ->default_path('includes/search/') - ->default_suffix('') - ->default_directory('') + ->extension_suffix('_backend') + ->extension_directory('/search') + ->core_path('includes/search/') ->get_classes(); /* diff --git a/phpBB/includes/captcha/captcha_factory.php b/phpBB/includes/captcha/captcha_factory.php index 2779a23d34..e039e92054 100644 --- a/phpBB/includes/captcha/captcha_factory.php +++ b/phpBB/includes/captcha/captcha_factory.php @@ -68,10 +68,9 @@ class phpbb_captcha_factory $finder = $phpbb_extension_manager->get_finder(); $captcha_plugin_classes = $finder - ->directory('/captcha') + ->extension_directory('/captcha') ->suffix('_plugin') - ->default_path('includes/captcha/plugins/') - ->default_directory('') + ->core_path('includes/captcha/plugins/') ->get_classes(); foreach ($captcha_plugin_classes as $class) diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 3f07bac051..e6ae0f75ec 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -40,11 +40,9 @@ class phpbb_cron_task_provider extends phpbb_extension_provider $finder = $this->extension_manager->get_finder(); return $finder - ->suffix('_task') - ->directory('/cron') - ->default_path('includes/cron/task/core/') - ->default_suffix('') - ->default_directory('') + ->extension_suffix('_task') + ->extension_directory('/cron') + ->core_path('includes/cron/task/core/') ->get_classes(); } } diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index f3a9900a67..5850ebe406 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -62,106 +62,120 @@ class phpbb_extension_finder $this->cache_name = $cache_name; $this->query = array( - 'default_path' => false, - 'default_suffix' => false, - 'default_prefix' => false, - 'default_directory' => false, - 'suffix' => false, - 'prefix' => false, - 'directory' => false, + 'core_path' => false, + 'core_suffix' => false, + 'core_prefix' => false, + 'core_directory' => false, + 'extension_suffix' => false, + 'extension_prefix' => false, + 'extension_directory' => false, ); $this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false; } /** - * Sets a default path to be searched in addition to extensions + * Sets a core path to be searched in addition to extensions * - * @param string $default_path The path relative to phpbb_root_path + * @param string $core_path The path relative to phpbb_root_path * @return phpbb_extension_finder This object for chaining calls */ - public function default_path($default_path) + public function core_path($core_path) { - $this->query['default_path'] = $default_path; + $this->query['core_path'] = $core_path; return $this; } /** - * Sets a suffix all files found in extensions must match. + * Sets the suffix all files found in extensions and core must match. * * There is no default file extension, so to find PHP files only, you will * have to specify .php as a suffix. However when using get_classes, the .php * file extension is automatically added to suffixes. * - * Automatically sets the default_suffix if its value does not differ from - * the current suffix. - * * @param string $suffix A filename suffix * @return phpbb_extension_finder This object for chaining calls */ public function suffix($suffix) { - if ($this->query['default_suffix'] === $this->query['suffix']) - { - $this->query['default_suffix'] = $suffix; - } - - $this->query['suffix'] = $suffix; + $this->core_suffix($suffix); + $this->extension_suffix($suffix); return $this; } /** - * Sets a suffix all files found in the default path must match + * Sets a suffix all files found in extensions must match * * There is no default file extension, so to find PHP files only, you will * have to specify .php as a suffix. However when using get_classes, the .php * file extension is automatically added to suffixes. * - * @param string $default_suffix A filename suffix + * @param string $extension_suffix A filename suffix * @return phpbb_extension_finder This object for chaining calls */ - public function default_suffix($default_suffix) + public function extension_suffix($extension_suffix) { - $this->query['default_suffix'] = $default_suffix; + $this->query['extension_suffix'] = $extension_suffix; return $this; } /** - * Sets a prefix all files found in extensions must match + * Sets a suffix all files found in the core path must match * - * Automatically sets the default_prefix if its value does not differ from - * the current prefix. + * There is no default file extension, so to find PHP files only, you will + * have to specify .php as a suffix. However when using get_classes, the .php + * file extension is automatically added to suffixes. + * + * @param string $core_suffix A filename suffix + * @return phpbb_extension_finder This object for chaining calls + */ + public function core_suffix($core_suffix) + { + $this->query['core_suffix'] = $core_suffix; + return $this; + } + + /** + * Sets the prefix all files found in extensions and core must match * * @param string $prefix A filename prefix * @return phpbb_extension_finder This object for chaining calls */ public function prefix($prefix) { - if ($this->query['default_prefix'] === $this->query['prefix']) - { - $this->query['default_prefix'] = $prefix; - } + $this->core_prefix($prefix); + $this->extension_prefix($prefix); + return $this; + } - $this->query['prefix'] = $prefix; + /** + * Sets a prefix all files found in extensions must match + * + * @param string $extension_prefix A filename prefix + * @return phpbb_extension_finder This object for chaining calls + */ + public function extension_prefix($extension_prefix) + { + $this->query['extension_prefix'] = $extension_prefix; return $this; } /** - * Sets a prefix all files found in the default path must match + * Sets a prefix all files found in the core path must match * - * @param string $default_prefix A filename prefix + * @param string $core_prefix A filename prefix * @return phpbb_extension_finder This object for chaining calls */ - public function default_prefix($default_prefix) + public function core_prefix($core_prefix) { - $this->query['default_prefix'] = $default_prefix; + $this->query['core_prefix'] = $core_prefix; return $this; } /** - * Sets a directory all files found in extensions must be contained in + * Sets a directory all files found in extensions and core must be contained in * - * Automatically sets the default_directory if its value does not differ from + * Automatically sets the core_directory if its value does not differ from * the current directory. * * @param string $directory @@ -169,38 +183,52 @@ class phpbb_extension_finder */ public function directory($directory) { - $directory = preg_replace('#(?:^|/)\./#', '/', $directory); - $dir_len = strlen($directory); - - if ($dir_len > 1 && $directory[$dir_len - 1] === '/') - { - $directory = substr($directory, 0, -1); - } - - if ($this->query['default_directory'] === $this->query['directory']) - { - $this->query['default_directory'] = $directory; - } + $this->core_directory($directory); + $this->extension_directory($directory); + return $this; + } - $this->query['directory'] = $directory; + /** + * Sets a directory all files found in extensions must be contained in + * + * @param string $extension_directory + * @return phpbb_extension_finder This object for chaining calls + */ + public function extension_directory($extension_directory) + { + $this->query['extension_directory'] = $this->sanitise_directory($extension_directory); return $this; } /** - * Sets a directory all files found in the default path must be contained in + * Sets a directory all files found in the core path must be contained in * - * @param string $default_directory + * @param string $core_directory * @return phpbb_extension_finder This object for chaining calls */ - public function default_directory($default_directory) + public function core_directory($core_directory) + { + $this->query['core_directory'] = $this->sanitise_directory($core_directory); + return $this; + } + + /** + * Removes occurances of /./ and makes sure path ends without trailing slash + * + * @param string $directory A directory pattern + * @return string A cleaned up directory pattern + */ + protected function sanitise_directory($directory) { - if (strlen($default_directory) > 1 && $default_directory[strlen($default_directory) - 1] === '/') + $directory = preg_replace('#(?:^|/)\./#', '/', $directory); + $dir_len = strlen($directory); + + if ($dir_len > 1 && $directory[$dir_len - 1] === '/') { - $default_directory = substr($default_directory, 0, -1); + $directory = substr($directory, 0, -1); } - $this->query['default_directory'] = $default_directory; - return $this; + return $directory; } /** @@ -216,8 +244,8 @@ class phpbb_extension_finder */ public function get_classes($cache = true) { - $this->query['suffix'] .= $this->phpEx; - $this->query['default_suffix'] .= $this->phpEx; + $this->query['extension_suffix'] .= $this->phpEx; + $this->query['core_suffix'] .= $this->phpEx; $files = $this->find($cache, false); @@ -296,9 +324,9 @@ class phpbb_extension_finder $extensions = $this->extension_manager->all_enabled(); - if ($this->query['default_path']) + if ($this->query['core_path']) { - $extensions['/'] = $this->phpbb_root_path . $this->query['default_path']; + $extensions['/'] = $this->phpbb_root_path . $this->query['core_path']; } foreach ($extensions as $name => $path) @@ -312,19 +340,19 @@ class phpbb_extension_finder if ($name === '/') { - $location = $this->query['default_path']; + $location = $this->query['core_path']; $name = ''; - $suffix = $this->query['default_suffix']; - $prefix = $this->query['default_prefix']; - $directory = $this->query['default_directory']; + $suffix = $this->query['core_suffix']; + $prefix = $this->query['core_prefix']; + $directory = $this->query['core_directory']; } else { $location = 'ext/'; $name .= '/'; - $suffix = $this->query['suffix']; - $prefix = $this->query['prefix']; - $directory = $this->query['directory']; + $suffix = $this->query['extension_suffix']; + $prefix = $this->query['extension_prefix']; + $directory = $this->query['extension_directory']; } // match only first directory if leading slash is given 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) |