From 14f1e581faa3b66e7689c55c1e9c0485c0872b1e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 9 Jun 2011 05:13:26 +0200 Subject: [feature/extension-manager] Extension Manager & Finder Extensions RFC: http://area51.phpbb.com/phpBB/viewtopic.php?f=84&t=41499 Ticket: http://tracker.phpbb.com/browse/PHPBB3-10323 PHPBB3-10323 --- phpBB/includes/extension/base.php | 35 ++++ phpBB/includes/extension/finder.php | 246 +++++++++++++++++++++++++++ phpBB/includes/extension/interface.php | 27 +++ phpBB/includes/extension/manager.php | 301 +++++++++++++++++++++++++++++++++ 4 files changed, 609 insertions(+) create mode 100644 phpBB/includes/extension/base.php create mode 100644 phpBB/includes/extension/finder.php create mode 100644 phpBB/includes/extension/interface.php create mode 100644 phpBB/includes/extension/manager.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php new file mode 100644 index 0000000000..0e6c89491d --- /dev/null +++ b/phpBB/includes/extension/base.php @@ -0,0 +1,35 @@ +extension_manager = $extension_manager; + $this->phpbb_root_path = $phpbb_root_path; + $this->cache = $cache; + $this->phpEx = $phpEx; + + $this->query = array( + 'default_path' => false, + 'default_suffix' => false, + 'default_directory' => false, + 'suffix' => false, + 'directory' => false, + ); + + $this->cached_queries = ($this->cache) ? $this->cache->get('_extension_finder') : false; + } + + /** + * Sets a default path to be searched in addition to extensions + * + * @param string $default_path The path relative to / + * @return phpbb_extension_finder This object for chaining calls + */ + public function default_path($default_path) + { + $this->query['default_path'] = $default_path; + return $this; + } + + /** + * Sets a suffix all files found in extensions must match + * + * Automatically sets the default_suffix if its value does not differ from + * the current suffix. + * + * @param string $default_path 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; + return $this; + } + + /** + * Sets a suffix all files found in the default path must match + * + * @param string $default_suffix A filename suffix + * @return phpbb_extension_finder This object for chaining calls + */ + public function default_suffix($default_suffix) + { + $this->query['default_suffix'] = $default_suffix; + return $this; + } + + /** + * Sets a directory all files found in extensions must be contained in + * + * Automatically sets the default_directory if its value does not differ from + * the current directory. + * + * @param string $directory + * @return phpbb_extension_finder This object for chaining calls + */ + public function directory($directory) + { + if (strlen($directory) > 1 && $directory[strlen($directory) - 1] === '/') + { + $directory = substr($directory, 0, -1); + } + + if ($this->query['default_directory'] === $this->query['directory']) + { + $this->query['default_directory'] = $directory; + } + + $this->query['directory'] = $directory; + return $this; + } + + /** + * Sets a directory all files found in the default path must be contained in + * + * @param string $default_directory + * @return phpbb_extension_finder This object for chaining calls + */ + public function default_directory($default_directory) + { + if (strlen($default_directory) > 1 && $default_directory[strlen($default_directory) - 1] === '/') + { + $default_directory = substr($default_directory, 0, -1); + } + + $this->query['default_directory'] = $default_directory; + return $this; + } + + /** + * Finds auto loadable php classes matching the configured options. + * + * The php file extension is automatically added to suffixes. + * + * @param bool $cache Whether the result should be cached + * @return array An array of found class names + */ + public function get_classes($cache = true) + { + $this->query['suffix'] .= $this->phpEx; + $this->query['default_suffix'] .= $this->phpEx; + + $files = $this->get_files($cache); + + $classes = array(); + foreach ($files as $file) + { + $file = preg_replace('#^includes/#', '', $file); + + $classes[] = 'phpbb_' . str_replace('/', '_', substr($file, 0, -strlen($this->phpEx))); + } + return $classes; + } + + /** + * Finds all files matching the configured options. + * + * @param bool $cache Whether the result should be cached + * @return array An array of found class names + */ + public function get_files($cache = true) + { + $query = md5(serialize($this->query)); + + if ($cache && isset($this->cached_queries[$query])) + { + return $this->cached_queries[$query]; + } + + $files = array(); + + $extensions = $this->extension_manager->all_enabled(); + + if ($this->query['default_path']) + { + $extensions['/'] = $this->phpbb_root_path . $this->query['default_path']; + } + + foreach ($extensions as $name => $path) + { + if (!file_exists($path)) + { + continue; + } + + if ($name === '/') + { + $prefix = $this->query['default_path']; + $name = ''; + $suffix = $this->query['default_suffix']; + $directory = $this->query['default_directory']; + } + else + { + $prefix = 'ext/'; + $name .= '/'; + $suffix = $this->query['suffix']; + $directory = $this->query['directory']; + } + + // match only first directory if leading slash is given + $directory_pattern = ($directory && $directory[0] === '/') ? '#^' : '#' . DIRECTORY_SEPARATOR; + $directory_pattern .= preg_quote($directory . DIRECTORY_SEPARATOR, '#') . '#'; + + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); + foreach ($iterator as $file_info) + { + if (!$file_info->isDir()) + { + $relative_path = $iterator->getInnerIterator()->getSubPathname(); + + if ((!$suffix || substr($relative_path, -strlen($suffix)) == $suffix) && + (!$directory || preg_match($directory_pattern, DIRECTORY_SEPARATOR . $relative_path))) + { + $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $prefix . $name . $relative_path); + } + } + } + } + + if ($cache && $this->cache) + { + $this->cached_queries[$query] = $files; + $this->cache->put('_extension_finder', $this->cached_queries); + } + + return $files; + } +} diff --git a/phpBB/includes/extension/interface.php b/phpBB/includes/extension/interface.php new file mode 100644 index 0000000000..40a5a066a3 --- /dev/null +++ b/phpBB/includes/extension/interface.php @@ -0,0 +1,27 @@ +phpbb_root_path = $phpbb_root_path; + $this->db = $db; + $this->cache = $cache; + $this->phpEx = $phpEx; + $this->extension_table = $extension_table; + + if (false === ($this->extensions = $this->cache->get('_extensions'))) + { + $this->load_extensions(); + } + } + + /** + * Loads all extension information from the database + * + * @return null + */ + protected function load_extensions() + { + $sql = 'SELECT * + FROM ' . $this->extension_table; + + $result = $this->db->sql_query($sql); + $extensions = $this->db->sql_fetchrowset($result); + + $this->extensions = array(); + foreach ($extensions as $extension) + { + $extension['ext_path'] = $this->get_extension_path($extension['ext_name']); + $this->extensions[$extension['ext_name']] = $extension; + } + + ksort($this->extensions); + $this->cache->put('_extensions', $this->extensions); + } + + /** + * Generates the path to an extension + * + * @param string $name The name of the extension + * @return string Path to an extension + */ + public function get_extension_path($name) + { + return $this->phpbb_root_path . 'ext/' . basename($name) . '/'; + } + + /** + * Instantiates the extension meta class for the given name. + * + * @param string $name The extension name + * @return phpbb_extension_interface Instance of the extension meta class or + * phpbb_extension_base if the class does not exist + */ + public function get_extension($name) + { + $extension_class_name = 'phpbb_ext_' . $name; + + if (class_exists($extension_class_name)) + { + return new $extension_class_name; + } + else + { + return new phpbb_extension_base; + } + } + + /** + * Enables an extension + * + * Calls the enable method on the extension's meta class to allow it to + * make database changes and execute other initialisation code. + * + * @param string $name The extension's name + * @return null + */ + public function enable($name) + { + // ignore extensions that are already enabled + if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']) + { + return; + } + + $extension = $this->get_extension($name); + $extension->enable(); + + $extension_data = array( + 'ext_name' => $name, + 'ext_active' => true, + ); + + $this->extensions[$name] = $extension_data; + $this->extensions[$name]['ext_path'] = $this->get_extension_path($extension_data['ext_name']); + ksort($this->extensions); + + $sql = 'UPDATE ' . $this->extension_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " + WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + $sql = 'INSERT INTO ' . $this->extension_table . ' + ' . $this->db->sql_build_array('INSERT', $extension_data); + $this->db->sql_query($sql); + } + } + + /** + * Disables an extension + * + * Calls the disable method on the extension's meta class to allow it to + * process the event. + * + * @param string $name The extension's name + * @return null + */ + public function disable($name) + { + // ignore extensions that are already disabled + if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active']) + { + return; + } + + $extension = $this->get_extension($name); + $extension->disable(); + + $extension_data = array( + 'ext_active' => false, + ); + $this->extensions[$name]['ext_active'] = false; + ksort($this->extensions); + + $sql = 'UPDATE ' . $this->extension_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " + WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + } + + /** + * Purge an extension + * + * Disables the extension first if active, and then calls purge on the + * extension's meta class to delete the extension's database content. + * + * @param string $name The extension's name + * @return null + */ + public function purge($name) + { + // ignore extensions that do not exist + if (!isset($this->extensions[$name])) + { + return; + } + + // disable first if necessary + if ($this->extensions[$name]['ext_active']) + { + $this->disable($name); + } + + $extension = $this->get_extension($name); + $extension->purge(); + + unset($this->extensions[$name]); + + $sql = 'DELETE FROM ' . $this->extension_table . " + WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + } + + /** + * Retrieves a list of all available extensions on the filesystem + * + * @return array An array with extension names as keys and paths to the + * extension as values + */ + public function all_available() + { + $available = array(); + + $iterator = new DirectoryIterator($this->phpbb_root_path . 'ext/'); + foreach ($iterator as $file_info) + { + $path = $this->phpbb_root_path . 'ext/' . $file_info->getBasename() . '/'; + if (!$file_info->isDot() && $file_info->isDir() && file_exists($path)) + { + $available[$file_info->getBasename()] = $path; + } + } + ksort($available); + return $available; + } + + /** + * Retrieves all configured extensions. + * + * All enabled and disabled extensions are considered configured. A purged + * extension that is no longer in the database is not configured. + * + * @return array An array with extension names as keys and and the + * database stored extension information as values + */ + public function all_configured() + { + return $this->extensions; + } + + /** + * Retrieves all enabled extensions. + * + * @return array An array with extension names as keys and and the + * database stored extension information as values + */ + public function all_enabled() + { + $enabled = array(); + foreach ($this->extensions as $name => $data) + { + if ($data['ext_active']) + { + $enabled[$name] = $data['ext_path']; + } + } + return $enabled; + } + + /** + * Retrieves all disabled extensions. + * + * @return array An array with extension names as keys and and the + * database stored extension information as values + */ + public function all_disabled() + { + $disabled = array(); + foreach ($this->extensions as $name => $data) + { + if (!$data['ext_active']) + { + $disabled[$name] = $data['ext_path']; + } + } + return $disabled; + } + + /** + * Instantiates a phpbb_extension_finder. + * + * @return phpbb_extension_finder An extension finder instance + */ + public function get_finder() + { + return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->phpEx); + } +} -- cgit v1.2.1 From 956860c21d2285ac325a48d6caf1e4fa45aca922 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 15 Aug 2011 20:07:35 -0400 Subject: [feature/extension-manager] Never cache extension finder queries in debug mode During development the detection of files should happen immediately and performance is less of a concern. PHPBB3-10323 --- phpBB/includes/extension/finder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index fb532e52f8..4180b84dd3 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -179,7 +179,7 @@ class phpbb_extension_finder { $query = md5(serialize($this->query)); - if ($cache && isset($this->cached_queries[$query])) + if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) { return $this->cached_queries[$query]; } -- cgit v1.2.1 From f6632fcfd08650f13560529a6a04c152aefd4e3c Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 22 Aug 2011 02:17:00 -0400 Subject: [feature/extension-manager] Add filename prefix matching in extension finder PHPBB3-10323 --- phpBB/includes/extension/finder.php | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 4180b84dd3..fbc8a3aefb 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -50,8 +50,10 @@ class phpbb_extension_finder $this->query = array( 'default_path' => false, 'default_suffix' => false, + 'default_prefix' => false, 'default_directory' => false, 'suffix' => false, + 'prefix' => false, 'directory' => false, ); @@ -76,7 +78,7 @@ class phpbb_extension_finder * Automatically sets the default_suffix if its value does not differ from * the current suffix. * - * @param string $default_path A filename suffix + * @param string $suffix A filename suffix * @return phpbb_extension_finder This object for chaining calls */ public function suffix($suffix) @@ -102,6 +104,38 @@ class phpbb_extension_finder return $this; } + /** + * Sets a prefix all files found in extensions must match + * + * Automatically sets the default_prefix if its value does not differ from + * the current prefix. + * + * @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->query['prefix'] = $prefix; + return $this; + } + + /** + * Sets a prefix all files found in the default path must match + * + * @param string $default_prefix A filename prefix + * @return phpbb_extension_finder This object for chaining calls + */ + public function default_prefix($default_prefix) + { + $this->query['default_prefix'] = $default_prefix; + return $this; + } + /** * Sets a directory all files found in extensions must be contained in * @@ -202,16 +236,18 @@ class phpbb_extension_finder if ($name === '/') { - $prefix = $this->query['default_path']; + $location = $this->query['default_path']; $name = ''; $suffix = $this->query['default_suffix']; + $prefix = $this->query['default_prefix']; $directory = $this->query['default_directory']; } else { - $prefix = 'ext/'; + $location = 'ext/'; $name .= '/'; $suffix = $this->query['suffix']; + $prefix = $this->query['prefix']; $directory = $this->query['directory']; } @@ -226,10 +262,11 @@ class phpbb_extension_finder { $relative_path = $iterator->getInnerIterator()->getSubPathname(); - if ((!$suffix || substr($relative_path, -strlen($suffix)) == $suffix) && + if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) && + (!$prefix || substr($file_info->getFilename(), 0, strlen($prefix)) === $prefix) && (!$directory || preg_match($directory_pattern, DIRECTORY_SEPARATOR . $relative_path))) { - $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $prefix . $name . $relative_path); + $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . $relative_path); } } } -- cgit v1.2.1 From 897063d3e269a7c11ef6d6602abc37ec30266a72 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 14:46:38 -0400 Subject: [feature/extension-manager] Add missing sql_freeresult call PHPBB3-10323 --- phpBB/includes/extension/manager.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 736c706e77..d167bc6847 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -63,6 +63,7 @@ class phpbb_extension_manager $result = $this->db->sql_query($sql); $extensions = $this->db->sql_fetchrowset($result); + $this->db->sql_freeresult($result); $this->extensions = array(); foreach ($extensions as $extension) -- cgit v1.2.1 From c7a986eccdac183cc81b3da486092f4ab82109ba Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 17:17:40 -0400 Subject: [feature/extension-manager] Use an incremental process for enable and purge The enable or purge operation of an extension could take a long time if an expensive operation needs to be executed on a large set of data. To allow this to succeed from a web interface with max_execution_time set in the webserver's php configuration, subsequent requests must continue the operation started earlier. So individual enable and purge implementations must be able to spread their work across multiple steps. PHPBB3-10323 --- phpBB/includes/extension/base.php | 22 ++++++++- phpBB/includes/extension/interface.php | 39 +++++++++++++++- phpBB/includes/extension/manager.php | 85 ++++++++++++++++++++++++++++------ 3 files changed, 128 insertions(+), 18 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index 0e6c89491d..8228364d44 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -16,20 +16,38 @@ if (!defined('IN_PHPBB')) } /** +* A base class for extensions without custom enable/disbale/purge code. * * @package extension */ class phpbb_extension_base implements phpbb_extension_interface { - public function enable() + /** + * Single enable step that does nothing + * + * @return false Indicates no further steps are required + */ + public function enable_step($old_state) { + return false; } + /** + * Empty disable method + * + * @return null + */ public function disable() { } - public function purge() + /** + * Single purge step that does nothing + * + * @return false Indicates no further steps are required + */ + public function purge_step($old_state) { + return false; } } diff --git a/phpBB/includes/extension/interface.php b/phpBB/includes/extension/interface.php index 40a5a066a3..7d0ecd72c7 100644 --- a/phpBB/includes/extension/interface.php +++ b/phpBB/includes/extension/interface.php @@ -16,12 +16,47 @@ if (!defined('IN_PHPBB')) } /** +* The interface extension meta classes have to implement to run custom code +* on enable/disable/purge. * * @package extension */ interface phpbb_extension_interface { - public function enable(); + /** + * enable_step is executed on enabling an extension until it returns false. + * + * Calls to this function can be made in subsequent requests, when the + * function is invoked through a webserver with a too low max_execution_time. + * + * @param mixed $old_state The return value of the previous call + * of this method, or false on the first call + * @return mixed Returns false after last step, otherwise + * temporary state which is passed as an + * argument to the next step + */ + public function enable_step($old_state); + + /** + * Disables the extension. + * + * Must be a quick operation, that finishes within max_execution_time. + * + * @return null + */ public function disable(); - public function purge(); + + /** + * purge_step is executed on purging an extension until it returns false. + * + * Calls to this function can be made in subsequent requests, when the + * function is invoked through a webserver with a too low max_execution_time. + * + * @param mixed $old_state The return value of the previous call + * of this method, or false on the first call + * @return mixed Returns false after last step, otherwise + * temporary state which is passed as an + * argument to the next step + */ + public function purge_step($old_state); } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index d167bc6847..a1863040d0 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -109,28 +109,34 @@ class phpbb_extension_manager } /** - * Enables an extension + * Runs a step of the extension enabling process. * - * Calls the enable method on the extension's meta class to allow it to - * make database changes and execute other initialisation code. + * Allows the exentension to enable in a long running script that works + * in multiple steps across requests. State is kept for the extension + * in the extensions table. * - * @param string $name The extension's name - * @return null + * @param string $name The extension's name + * @return bool Whether another run of enable_step is required */ - public function enable($name) + public function enable_step($name) { // ignore extensions that are already enabled if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']) { - return; + return false; } + $old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false; + $extension = $this->get_extension($name); - $extension->enable(); + $state = $extension->enable_step($old_state); + + $active = ($state === false); $extension_data = array( - 'ext_name' => $name, - 'ext_active' => true, + 'ext_name' => $name, + 'ext_active' => $active, + 'ext_state' => serialize($state), ); $this->extensions[$name] = $extension_data; @@ -148,6 +154,22 @@ class phpbb_extension_manager ' . $this->db->sql_build_array('INSERT', $extension_data); $this->db->sql_query($sql); } + + return !$active; + } + + /** + * Enables an extension + * + * This method completely enables an extension. But it could be long running + * so never call this in a script that has a max_execution time. + * + * @param string $name The extension's name + * @return null + */ + public function enable($name) + { + while ($this->enable_step($name)); } /** @@ -172,9 +194,10 @@ class phpbb_extension_manager $extension_data = array( 'ext_active' => false, + 'ext_state' => serialize(false), ); $this->extensions[$name]['ext_active'] = false; - ksort($this->extensions); + $this->extensions[$name]['ext_state'] = serialize(false); $sql = 'UPDATE ' . $this->extension_table . ' SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " @@ -191,12 +214,12 @@ class phpbb_extension_manager * @param string $name The extension's name * @return null */ - public function purge($name) + public function purge_step($name) { // ignore extensions that do not exist if (!isset($this->extensions[$name])) { - return; + return false; } // disable first if necessary @@ -205,14 +228,48 @@ class phpbb_extension_manager $this->disable($name); } + $old_state = unserialize($this->extensions[$name]['ext_state']); + $extension = $this->get_extension($name); - $extension->purge(); + $state = $extension->purge_step($old_state); + + // continue until the state is false + if ($state !== false) + { + $extension_data = array( + 'ext_state' => serialize($state), + ); + $this->extensions[$name]['ext_state'] = serialize($state); + + $sql = 'UPDATE ' . $this->extension_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " + WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + return true; + } unset($this->extensions[$name]); $sql = 'DELETE FROM ' . $this->extension_table . " WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); + + return false; + } + + /** + * Purge an extension + * + * Purges an extension completely at once. This process could run for a while + * so never call this in a script that has a max_execution time. + * + * @param string $name The extension's name + * @return null + */ + public function purge($name) + { + while ($this->purge_step($name)); } /** -- cgit v1.2.1 From 7435f344e20ae4dce875b46746f46ddc874e41f3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:16:57 -0400 Subject: [feature/extension-manager] Add docblocks for query members of extension finder PHPBB3-10323 --- phpBB/includes/extension/finder.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index fbc8a3aefb..b3cdbd6ab9 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -27,7 +27,16 @@ class phpbb_extension_finder protected $cache; protected $phpEx; + /** + * @var array An associative array, containing all search parameters set in + * methods + */ protected $query; + + /** + * @var array A map from md5 hashes of serialized queries to their + * previously retrieved results. + */ protected $cached_queries; /** -- cgit v1.2.1 From 34f11a1039745ee1de48f1818f781ae1ee2b85ac Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:24:15 -0400 Subject: [feature/extension-manager] Correct usage of false cache return value PHPBB3-10323 --- phpBB/includes/extension/finder.php | 5 +++++ phpBB/includes/extension/manager.php | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index b3cdbd6ab9..d25823ca43 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -283,6 +283,11 @@ class phpbb_extension_finder if ($cache && $this->cache) { + if ($this->cached_queries === false) + { + $this->cached_queries = array(); + } + $this->cached_queries[$query] = $files; $this->cache->put('_extension_finder', $this->cached_queries); } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index a1863040d0..e1e7571573 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -45,7 +45,9 @@ class phpbb_extension_manager $this->phpEx = $phpEx; $this->extension_table = $extension_table; - if (false === ($this->extensions = $this->cache->get('_extensions'))) + $this->extensions = $this->cache->get('_extensions'); + + if ($this->extensions === false) { $this->load_extensions(); } -- cgit v1.2.1 From 64827a6623c9a916d41c2ef5bf2c2092a3008722 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:43:45 -0400 Subject: [feature/extension-manager] Test creation of new extension finder cache PHPBB3-10323 --- phpBB/includes/extension/finder.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index d25823ca43..b3cdbd6ab9 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -283,11 +283,6 @@ class phpbb_extension_finder if ($cache && $this->cache) { - if ($this->cached_queries === false) - { - $this->cached_queries = array(); - } - $this->cached_queries[$query] = $files; $this->cache->put('_extension_finder', $this->cached_queries); } -- cgit v1.2.1 From bd1366d62d018c6b71ea24b1f9915d89d4a240a5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:44:43 -0400 Subject: [feature/extension-manager] Use _ext for cache - avoids conflict with file ext PHPBB3-10323 --- phpBB/includes/extension/finder.php | 4 ++-- phpBB/includes/extension/manager.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index b3cdbd6ab9..7ba477582c 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -66,7 +66,7 @@ class phpbb_extension_finder 'directory' => false, ); - $this->cached_queries = ($this->cache) ? $this->cache->get('_extension_finder') : false; + $this->cached_queries = ($this->cache) ? $this->cache->get('_ext_finder') : false; } /** @@ -284,7 +284,7 @@ class phpbb_extension_finder if ($cache && $this->cache) { $this->cached_queries[$query] = $files; - $this->cache->put('_extension_finder', $this->cached_queries); + $this->cache->put('_ext_finder', $this->cached_queries); } return $files; diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index e1e7571573..45250e623a 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -45,7 +45,7 @@ class phpbb_extension_manager $this->phpEx = $phpEx; $this->extension_table = $extension_table; - $this->extensions = $this->cache->get('_extensions'); + $this->extensions = $this->cache->get('_ext'); if ($this->extensions === false) { @@ -75,7 +75,7 @@ class phpbb_extension_manager } ksort($this->extensions); - $this->cache->put('_extensions', $this->extensions); + $this->cache->put('_ext', $this->extensions); } /** -- cgit v1.2.1 From 739e9eb58e7e9b899955b714aa3fc8bbe6a30ebc Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:57:21 -0400 Subject: [feature/extension-manager] Make the cache variable name for extensions dynamic Allows multiple instances to use cache simultaneously. PHPBB3-10323 --- phpBB/includes/extension/finder.php | 10 +++++++--- phpBB/includes/extension/manager.php | 11 +++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 7ba477582c..e94a94c733 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -26,6 +26,7 @@ class phpbb_extension_finder protected $phpbb_root_path; protected $cache; protected $phpEx; + protected $cache_name; /** * @var array An associative array, containing all search parameters set in @@ -48,13 +49,16 @@ class phpbb_extension_finder * @param string $phpbb_root_path Path to the phpbb root directory * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $phpEx php file extension + * @param string $cache_name The name of the cache variable, defaults to + * _ext_finder */ - public function __construct(phpbb_extension_manager $extension_manager, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $phpEx = '.php') + public function __construct(phpbb_extension_manager $extension_manager, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $phpEx = '.php', $cache_name = '_ext_finder') { $this->extension_manager = $extension_manager; $this->phpbb_root_path = $phpbb_root_path; $this->cache = $cache; $this->phpEx = $phpEx; + $this->cache_name = $cache_name; $this->query = array( 'default_path' => false, @@ -66,7 +70,7 @@ class phpbb_extension_finder 'directory' => false, ); - $this->cached_queries = ($this->cache) ? $this->cache->get('_ext_finder') : false; + $this->cached_queries = ($this->cache) ? $this->cache->get($this->cache_name) : false; } /** @@ -284,7 +288,7 @@ class phpbb_extension_finder if ($cache && $this->cache) { $this->cached_queries[$query] = $files; - $this->cache->put('_ext_finder', $this->cached_queries); + $this->cache->put($this->cache_name, $this->cached_queries); } return $files; diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 45250e623a..443eaf011b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -27,6 +27,7 @@ class phpbb_extension_manager protected $extensions; protected $extension_table; protected $phpbb_root_path; + protected $cache_name; /** * Creates a manager and loads information from database @@ -36,16 +37,18 @@ class phpbb_extension_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension * @param phpbb_cache_driver_interface $cache A cache instance or null + * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(dbal $db, $extension_table, $phpbb_root_path, $phpEx = '.php', phpbb_cache_driver_interface $cache = null) + public function __construct(dbal $db, $extension_table, $phpbb_root_path, $phpEx = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->cache = $cache; $this->phpEx = $phpEx; $this->extension_table = $extension_table; + $this->cache_name = $cache_name; - $this->extensions = $this->cache->get('_ext'); + $this->extensions = $this->cache->get($this->cache_name); if ($this->extensions === false) { @@ -75,7 +78,7 @@ class phpbb_extension_manager } ksort($this->extensions); - $this->cache->put('_ext', $this->extensions); + $this->cache->put($this->cache_name, $this->extensions); } /** @@ -356,6 +359,6 @@ class phpbb_extension_manager */ public function get_finder() { - return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->phpEx); + return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->phpEx, $this->cache_name . '_finder'); } } -- cgit v1.2.1 From c785ef7aa7953c5e533e48b11ef13d6b1f344813 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 20:14:23 -0400 Subject: [feature/extension-manager] Make sure the extension manager works without cache Includes a test for manager without a cache PHPBB3-10323 --- phpBB/includes/extension/manager.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 443eaf011b..a6c8ebb3d0 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -48,7 +48,7 @@ class phpbb_extension_manager $this->extension_table = $extension_table; $this->cache_name = $cache_name; - $this->extensions = $this->cache->get($this->cache_name); + $this->extensions = ($this->cache) ? $this->cache->get($this->cache_name) : false; if ($this->extensions === false) { @@ -78,7 +78,11 @@ class phpbb_extension_manager } ksort($this->extensions); - $this->cache->put($this->cache_name, $this->extensions); + + if ($this->cache) + { + $this->cache->put($this->cache_name, $this->extensions); + } } /** -- cgit v1.2.1 From 0ea4de41711e1b4be601d01882ff52011cf9bf48 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 22:21:20 -0400 Subject: [feature/extension-manager] Add support for directories to the extension finder PHPBB3-10323 --- phpBB/includes/extension/finder.php | 51 ++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index e94a94c733..bcdcc61d76 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -216,14 +216,38 @@ class phpbb_extension_finder return $classes; } + /** + * Finds all directories matching the configured options + * + * @param bool $cache Whether the result should be cached + * @return array An array of paths to found directories + */ + public function get_directories($cache = true) + { + return $this->find($cache, true); + } + /** * Finds all files matching the configured options. * * @param bool $cache Whether the result should be cached - * @return array An array of found class names + * @return array An array of paths to found files */ public function get_files($cache = true) { + return $this->find($cache, false); + } + + /** + * Finds all file system entries matching the configured options + * + * @param bool $cache Whether the result should be cached + * @param bool $is_dir Whether the found items should be directories + * @return array An array of paths to found items + */ + protected function find($cache = true, $is_dir = false) + { + $this->query['is_dir'] = $is_dir; $query = md5(serialize($this->query)); if (!defined('DEBUG') && $cache && isset($this->cached_queries[$query])) @@ -265,18 +289,33 @@ class phpbb_extension_finder } // match only first directory if leading slash is given - $directory_pattern = ($directory && $directory[0] === '/') ? '#^' : '#' . DIRECTORY_SEPARATOR; - $directory_pattern .= preg_quote($directory . DIRECTORY_SEPARATOR, '#') . '#'; + if ($directory === '/') + { + $directory_pattern = '^' . preg_quote(DIRECTORY_SEPARATOR, '#'); + } + else if ($directory && $directory[0] === '/') + { + $directory_pattern = '^' . preg_quote($directory . DIRECTORY_SEPARATOR, '#'); + } + else + { + $directory_pattern = preg_quote(DIRECTORY_SEPARATOR . $directory . DIRECTORY_SEPARATOR, '#'); + } + $directory_pattern = '#' . $directory_pattern . '#'; $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($iterator as $file_info) { - if (!$file_info->isDir()) + if ($file_info->isDir() == $is_dir) { - $relative_path = $iterator->getInnerIterator()->getSubPathname(); + $relative_path = ($is_dir) ? $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR: + $iterator->getInnerIterator()->getSubPathname(); + + $item_name = ($is_dir) ? basename($iterator->getInnerIterator()->getSubPath()) : + $file_info->getFilename(); if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) && - (!$prefix || substr($file_info->getFilename(), 0, strlen($prefix)) === $prefix) && + (!$prefix || substr($item_name, 0, strlen($prefix)) === $prefix) && (!$directory || preg_match($directory_pattern, DIRECTORY_SEPARATOR . $relative_path))) { $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . $relative_path); -- cgit v1.2.1 From fd4259919188df2d7e4667108bf86d9bd22a8e2b Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 22:32:20 -0400 Subject: [feature/extension-manager] Correct formatting of documentation PHPBB3-10323 --- phpBB/includes/extension/finder.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index bcdcc61d76..1c1f150673 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -29,14 +29,15 @@ class phpbb_extension_finder protected $cache_name; /** - * @var array An associative array, containing all search parameters set in - * methods + * An associative array, containing all search parameters set in methods. + * @var array */ protected $query; /** - * @var array A map from md5 hashes of serialized queries to their - * previously retrieved results. + * A map from md5 hashes of serialized queries to their previously retrieved + * results. + * @var array */ protected $cached_queries; -- cgit v1.2.1 From 7d16007d6a1c042389039ab9ab59c073ecd7c933 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 22:51:15 -0400 Subject: [feature/extension-manager] Prepend the phpbb_root_path if necessary. PHPBB3-10323 --- phpBB/includes/extension/finder.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 1c1f150673..ee08b0a82a 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -205,7 +205,7 @@ class phpbb_extension_finder $this->query['suffix'] .= $this->phpEx; $this->query['default_suffix'] .= $this->phpEx; - $files = $this->get_files($cache); + $files = $this->find($cache, false); $classes = array(); foreach ($files as $file) @@ -225,7 +225,7 @@ class phpbb_extension_finder */ public function get_directories($cache = true) { - return $this->find($cache, true); + return $this->find_with_root_path($cache, true); } /** @@ -236,7 +236,27 @@ class phpbb_extension_finder */ public function get_files($cache = true) { - return $this->find($cache, false); + return $this->find_with_root_path($cache, false); + } + + /** + * A wrapper around the general find which prepends a root path to results + * + * @param bool $cache Whether the result should be cached + * @param bool $is_dir Whether the found items should be directories + * @return array An array of paths to found items + */ + protected function find_with_root_path($cache = true, $is_dir = false) + { + $items = $this->find($cache, $is_dir); + + $result = array(); + foreach ($items as $item) + { + $result[] = $this->phpbb_root_path . $item; + } + + return $result; } /** -- cgit v1.2.1 From 6c6a7d7992460e301615bcc1e13bee92ecc65724 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 30 Aug 2011 00:06:15 -0400 Subject: [feature/extension-manager] Extract extension provider functionality from cron PHPBB3-10323 --- phpBB/includes/extension/provider.php | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 phpBB/includes/extension/provider.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/provider.php b/phpBB/includes/extension/provider.php new file mode 100644 index 0000000000..9b5ec56d30 --- /dev/null +++ b/phpBB/includes/extension/provider.php @@ -0,0 +1,65 @@ +extension_manager = $extension_manager; + + $this->items = $this->find(); + } + + /** + * Finds template paths using the extension manager. + * + * @return array List of task names + */ + abstract function find(); + + /** + * Retrieve an iterator over all items + * + * @return ArrayIterator An iterator for the array of template paths + */ + public function getIterator() + { + return new ArrayIterator($this->items); + } +} -- cgit v1.2.1 From 6ea6d50ccb9607429486a01d3144c7d32322e1b5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 30 Aug 2011 01:15:43 -0400 Subject: [feature/extension-manager] Don't cache the phpbb_root_path in the ext manager Otherwise the paths are incorrect from e.g. adm/ PHPBB3-10323 --- phpBB/includes/extension/finder.php | 2 ++ phpBB/includes/extension/manager.php | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index ee08b0a82a..9a0727a50c 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -161,6 +161,8 @@ class phpbb_extension_finder */ public function directory($directory) { + $directory = preg_replace('#(?:^|/)\./#', '/', $directory); + if (strlen($directory) > 1 && $directory[strlen($directory) - 1] === '/') { $directory = substr($directory, 0, -1); diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index a6c8ebb3d0..ef714638c3 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -93,7 +93,7 @@ class phpbb_extension_manager */ public function get_extension_path($name) { - return $this->phpbb_root_path . 'ext/' . basename($name) . '/'; + return 'ext/' . basename($name) . '/'; } /** @@ -315,7 +315,13 @@ class phpbb_extension_manager */ public function all_configured() { - return $this->extensions; + $configured = array(); + foreach ($this->extensions as $name => $data) + { + $data['ext_path'] = $this->phpbb_root_path . $data['ext_path']; + $configured[$name] = $data; + } + return $configured; } /** @@ -331,7 +337,7 @@ class phpbb_extension_manager { if ($data['ext_active']) { - $enabled[$name] = $data['ext_path']; + $enabled[$name] = $this->phpbb_root_path . $data['ext_path']; } } return $enabled; @@ -350,7 +356,7 @@ class phpbb_extension_manager { if (!$data['ext_active']) { - $disabled[$name] = $data['ext_path']; + $disabled[$name] = $this->phpbb_root_path . $data['ext_path']; } } return $disabled; -- cgit v1.2.1 From 520a5f92953d350880355dbe46217d2b41edd2bd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 31 Aug 2011 17:49:48 -0400 Subject: [feature/extension-manager] Refactoring the structure of extension provider PHPBB3-10323 --- phpBB/includes/extension/provider.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/provider.php b/phpBB/includes/extension/provider.php index 9b5ec56d30..3939c2ef07 100644 --- a/phpBB/includes/extension/provider.php +++ b/phpBB/includes/extension/provider.php @@ -24,9 +24,9 @@ abstract class phpbb_extension_provider implements IteratorAggregate { /** * Array holding all found items - * @var array + * @var array|null */ - protected $items = array(); + protected $items = null; /** * An extension manager to search for items in extensions @@ -42,8 +42,6 @@ abstract class phpbb_extension_provider implements IteratorAggregate public function __construct(phpbb_extension_manager $extension_manager) { $this->extension_manager = $extension_manager; - - $this->items = $this->find(); } /** @@ -51,7 +49,7 @@ abstract class phpbb_extension_provider implements IteratorAggregate * * @return array List of task names */ - abstract function find(); + abstract protected function find(); /** * Retrieve an iterator over all items @@ -60,6 +58,11 @@ abstract class phpbb_extension_provider implements IteratorAggregate */ public function getIterator() { + if ($this->items === null) + { + $this->items = $this->find(); + } + return new ArrayIterator($this->items); } } -- cgit v1.2.1 From f61ee5d6f59272540f22d76f39d72a30d9b65ae3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 1 Sep 2011 18:53:12 -0400 Subject: [feature/extension-manager] Make sure the directory pattern matches on windows PHPBB3-10323 --- phpBB/includes/extension/finder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 9a0727a50c..5b04ff776d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -318,11 +318,11 @@ class phpbb_extension_finder } else if ($directory && $directory[0] === '/') { - $directory_pattern = '^' . preg_quote($directory . DIRECTORY_SEPARATOR, '#'); + $directory_pattern = '^' . preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#'); } else { - $directory_pattern = preg_quote(DIRECTORY_SEPARATOR . $directory . DIRECTORY_SEPARATOR, '#'); + $directory_pattern = preg_quote(DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#'); } $directory_pattern = '#' . $directory_pattern . '#'; -- cgit v1.2.1 From cffc676f17d2a2dc3ed45088c5ce3c2e5bd1d64f Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 29 Sep 2011 16:34:17 +0200 Subject: [feature/extension-manager] Find dirs with SELF_FIRST setting on iterator PHPBB3-10323 --- phpBB/includes/extension/finder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 5b04ff776d..af01bfdde6 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -326,7 +326,7 @@ class phpbb_extension_finder } $directory_pattern = '#' . $directory_pattern . '#'; - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { if ($file_info->isDir() == $is_dir) -- cgit v1.2.1 From fbc2442ccdb8f448f0211ff547536ddcade229fb Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 29 Sep 2011 17:20:42 +0200 Subject: [feature/extension-manager] Correctly detect and handle directories in finder PHPBB3-10323 --- phpBB/includes/extension/finder.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index af01bfdde6..d599dfb86d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -326,22 +326,30 @@ class phpbb_extension_finder } $directory_pattern = '#' . $directory_pattern . '#'; - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { if ($file_info->isDir() == $is_dir) { - $relative_path = ($is_dir) ? $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR: - $iterator->getInnerIterator()->getSubPathname(); - - $item_name = ($is_dir) ? basename($iterator->getInnerIterator()->getSubPath()) : - $file_info->getFilename(); + if ($is_dir) + { + $relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($file_info->getFilename()) . DIRECTORY_SEPARATOR; + if ($relative_path[0] !== DIRECTORY_SEPARATOR) + { + $relative_path = DIRECTORY_SEPARATOR . $relative_path; + } + } + else + { + $relative_path = DIRECTORY_SEPARATOR . $iterator->getInnerIterator()->getSubPathname(); + } + $item_name = $file_info->getFilename(); if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) && (!$prefix || substr($item_name, 0, strlen($prefix)) === $prefix) && - (!$directory || preg_match($directory_pattern, DIRECTORY_SEPARATOR . $relative_path))) + (!$directory || preg_match($directory_pattern, $relative_path))) { - $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . $relative_path); + $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)); } } } -- cgit v1.2.1 From 724f40f0f4fdfc47764a069cc91f045f0c67f4fb Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 13 Oct 2011 21:19:35 +0200 Subject: [feature/extension-manager] extension finder now saves ext it found a file in PHPBB3-10323 --- phpBB/includes/extension/finder.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index d599dfb86d..0c8c5d337c 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -210,7 +210,7 @@ class phpbb_extension_finder $files = $this->find($cache, false); $classes = array(); - foreach ($files as $file) + foreach ($files as $file => $ext_name) { $file = preg_replace('#^includes/#', '', $file); @@ -253,7 +253,7 @@ class phpbb_extension_finder $items = $this->find($cache, $is_dir); $result = array(); - foreach ($items as $item) + foreach ($items as $item => $ext_name) { $result[] = $this->phpbb_root_path . $item; } @@ -289,6 +289,8 @@ class phpbb_extension_finder foreach ($extensions as $name => $path) { + $ext_name = $name; + if (!file_exists($path)) { continue; @@ -349,7 +351,7 @@ class phpbb_extension_finder (!$prefix || substr($item_name, 0, strlen($prefix)) === $prefix) && (!$directory || preg_match($directory_pattern, $relative_path))) { - $files[] = str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1)); + $files[str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1))] = $ext_name; } } } -- 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/extension/finder.php | 2 +- phpBB/includes/extension/manager.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 0c8c5d337c..6084d2672a 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -268,7 +268,7 @@ class phpbb_extension_finder * @param bool $is_dir Whether the found items should be directories * @return array An array of paths to found items */ - protected function find($cache = true, $is_dir = false) + public function find($cache = true, $is_dir = false) { $this->query['is_dir'] = $is_dir; $query = md5(serialize($this->query)); diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index ef714638c3..0b3189df96 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -89,11 +89,12 @@ class phpbb_extension_manager * Generates the path to an extension * * @param string $name The name of the extension + * @param bool $phpbb_relative Whether the path should be relative to phpbb root * @return string Path to an extension */ - public function get_extension_path($name) + public function get_extension_path($name, $phpbb_relative = false) { - return 'ext/' . basename($name) . '/'; + return (($phpbb_relative) ? $this->phpbb_root_path : '') . 'ext/' . basename($name) . '/'; } /** -- cgit v1.2.1 From f53892c838dfa3638a47b60b394a948db4873466 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2011 00:52:36 +0200 Subject: [feature/extension-manager] Add prefix to extension meta data / install classes PHPBB3-10323 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 0b3189df96..07e98735f8 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -106,7 +106,7 @@ class phpbb_extension_manager */ public function get_extension($name) { - $extension_class_name = 'phpbb_ext_' . $name; + $extension_class_name = 'phpbb_ext_' . $name . '_ext'; if (class_exists($extension_class_name)) { -- cgit v1.2.1 From 4fb9f2101de8de8dc08ef0a1c44f81c5443f3d7a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 14 Oct 2011 01:30:50 +0200 Subject: [feature/extension-manager] Support extensions in subdirectories of ext/ PHPBB3-10323 --- phpBB/includes/extension/manager.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 07e98735f8..981fa43ab2 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -94,7 +94,9 @@ class phpbb_extension_manager */ public function get_extension_path($name, $phpbb_relative = false) { - return (($phpbb_relative) ? $this->phpbb_root_path : '') . 'ext/' . basename($name) . '/'; + $name = str_replace('.', '', $name); + + return (($phpbb_relative) ? $this->phpbb_root_path : '') . 'ext/' . $name . '/'; } /** @@ -106,7 +108,7 @@ class phpbb_extension_manager */ public function get_extension($name) { - $extension_class_name = 'phpbb_ext_' . $name . '_ext'; + $extension_class_name = 'phpbb_ext_' . str_replace('/', '_', $name) . '_ext'; if (class_exists($extension_class_name)) { @@ -292,13 +294,17 @@ class phpbb_extension_manager { $available = array(); - $iterator = new DirectoryIterator($this->phpbb_root_path . 'ext/'); + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/')); foreach ($iterator as $file_info) { - $path = $this->phpbb_root_path . 'ext/' . $file_info->getBasename() . '/'; - if (!$file_info->isDot() && $file_info->isDir() && file_exists($path)) + if ($file_info->isFile() && $file_info->getFilename() == 'ext' . $this->phpEx) { - $available[$file_info->getBasename()] = $path; + $ext_name = $iterator->getInnerIterator()->getSubPath(); + + $ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name); + + $available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/'; } } ksort($available); -- cgit v1.2.1 From 64bf03f4ca363f0f4b237a4cb32cde4f48cd158e Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 13:07:14 +0100 Subject: [feature/extension-manager] Fix "disbale" typo in comment PHPBB3-10323 --- phpBB/includes/extension/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index 8228364d44..fed120c51b 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -16,7 +16,7 @@ if (!defined('IN_PHPBB')) } /** -* A base class for extensions without custom enable/disbale/purge code. +* A base class for extensions without custom enable/disable/purge code. * * @package extension */ -- cgit v1.2.1 From 7ee9a07179d880c788b6ccb0a136c9a957fd918c Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 13:10:09 +0100 Subject: [feature/extension-manager] Correct default path comment & remove double strlen PHPBB3-10323 --- phpBB/includes/extension/finder.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 6084d2672a..d84d27b9c4 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -77,7 +77,7 @@ class phpbb_extension_finder /** * Sets a default path to be searched in addition to extensions * - * @param string $default_path The path relative to / + * @param string $default_path The path relative to phpbb_root_path * @return phpbb_extension_finder This object for chaining calls */ public function default_path($default_path) @@ -162,8 +162,9 @@ class phpbb_extension_finder public function directory($directory) { $directory = preg_replace('#(?:^|/)\./#', '/', $directory); + $dir_len = strlen($directory); - if (strlen($directory) > 1 && $directory[strlen($directory) - 1] === '/') + if ($dir_len > 1 && $directory[$dir_len - 1] === '/') { $directory = substr($directory, 0, -1); } -- cgit v1.2.1 From ef33bd72d04cf778ced3432c026e982cd3571dab Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 13:14:15 +0100 Subject: [feature/extension-manager] Clarify class finding method docblock PHPBB3-10323 --- phpBB/includes/extension/finder.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index d84d27b9c4..d6d3b176d3 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -196,10 +196,13 @@ class phpbb_extension_finder } /** - * Finds auto loadable php classes matching the configured options. + * Finds classes matching the configured options if they follow phpBB naming rules. * * The php file extension is automatically added to suffixes. * + * Note: If a file is matched but contains a class name not following the + * phpBB naming rules an incorrect class name will be returned. + * * @param bool $cache Whether the result should be cached * @return array An array of found class names */ -- cgit v1.2.1 From acc42bb2e9ea2556b47030c3c83c0bfac551eea5 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 13:16:32 +0100 Subject: [feature/extension-manager] Clarify is_dir parameter description PHPBB3-10323 --- phpBB/includes/extension/finder.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index d6d3b176d3..ee8ff2ccf4 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -249,7 +249,8 @@ class phpbb_extension_finder * A wrapper around the general find which prepends a root path to results * * @param bool $cache Whether the result should be cached - * @param bool $is_dir Whether the found items should be directories + * @param bool $is_dir Directories will be returned when true, only files + * otherwise * @return array An array of paths to found items */ protected function find_with_root_path($cache = true, $is_dir = false) @@ -269,7 +270,8 @@ class phpbb_extension_finder * Finds all file system entries matching the configured options * * @param bool $cache Whether the result should be cached - * @param bool $is_dir Whether the found items should be directories + * @param bool $is_dir Directories will be returned when true, only files + * otherwise * @return array An array of paths to found items */ public function find($cache = true, $is_dir = false) -- cgit v1.2.1 From 10fa711f0046b667c3291c36f210f1c740fb685a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 14:37:57 +0100 Subject: [feature/extension-manager] Add more info on suffixes in extension finder PHPBB3-10323 --- phpBB/includes/extension/finder.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index ee8ff2ccf4..f3a9900a67 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -87,7 +87,11 @@ class phpbb_extension_finder } /** - * Sets a suffix all files found in extensions 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. * * Automatically sets the default_suffix if its value does not differ from * the current suffix. @@ -109,6 +113,10 @@ class phpbb_extension_finder /** * Sets a suffix all files found in the default path 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 * @return phpbb_extension_finder This object for chaining calls */ -- cgit v1.2.1 From eab7374f3ff157d7606f16ff548219430417e68b Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 14:38:31 +0100 Subject: [feature/extension-manager] Clarify comment on ext meta class instantiator PHPBB3-10323 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 981fa43ab2..29cd89fb34 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -100,7 +100,7 @@ class phpbb_extension_manager } /** - * Instantiates the extension meta class for the given name. + * Instantiates the extension meta class for the extension with the given name * * @param string $name The extension name * @return phpbb_extension_interface Instance of the extension meta class or -- 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/extension/finder.php | 168 +++++++++++++++++++++--------------- 1 file changed, 98 insertions(+), 70 deletions(-) (limited to 'phpBB/includes/extension') 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 -- cgit v1.2.1 From 21117c69f313929d23592e3e705de3e4974afaa0 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 17:30:23 +0100 Subject: [feature/extension-manager] Add documentation on caching in ext finder PHPBB3-10323 --- phpBB/includes/extension/finder.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 5850ebe406..a1e6b2b347 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -26,6 +26,13 @@ class phpbb_extension_finder protected $phpbb_root_path; protected $cache; protected $phpEx; + + /** + * The cache variable name used to store $this->cached_queries in $this->cache. + * + * Allows the use of multiple differently configured finders with the same cache. + * @var string + */ protected $cache_name; /** -- cgit v1.2.1 From 5068c0588733f80a8433aea1cd6f763819caa9f7 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Fri, 18 Nov 2011 18:15:39 +0100 Subject: [feature/extension-manager] Split disabling extensions up into steps as well PHPBB3-10323 --- phpBB/includes/extension/base.php | 10 +++++--- phpBB/includes/extension/interface.php | 7 ++++-- phpBB/includes/extension/manager.php | 46 +++++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index fed120c51b..d9159d57d2 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -25,6 +25,7 @@ class phpbb_extension_base implements phpbb_extension_interface /** * Single enable step that does nothing * + * @param mixed $old_state State returned by previous call of this method * @return false Indicates no further steps are required */ public function enable_step($old_state) @@ -33,17 +34,20 @@ class phpbb_extension_base implements phpbb_extension_interface } /** - * Empty disable method + * Single disable step that does nothing * - * @return null + * @param mixed $old_state State returned by previous call of this method + * @return false Indicates no further steps are required */ - public function disable() + public function disable_step($old_state) { + return false; } /** * Single purge step that does nothing * + * @param mixed $old_state State returned by previous call of this method * @return false Indicates no further steps are required */ public function purge_step($old_state) diff --git a/phpBB/includes/extension/interface.php b/phpBB/includes/extension/interface.php index 7d0ecd72c7..b37cd24d77 100644 --- a/phpBB/includes/extension/interface.php +++ b/phpBB/includes/extension/interface.php @@ -40,11 +40,14 @@ interface phpbb_extension_interface /** * Disables the extension. * - * Must be a quick operation, that finishes within max_execution_time. + * Calls to this function can be made in subsequent requests, when the + * function is invoked through a webserver with a too low max_execution_time. * + * @param mixed $old_state The return value of the previous call + * of this method, or false on the first call * @return null */ - public function disable(); + public function disable_step($old_state); /** * purge_step is executed on purging an extension until it returns false. diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 29cd89fb34..bcdd21f7f1 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -128,7 +128,7 @@ class phpbb_extension_manager * in the extensions table. * * @param string $name The extension's name - * @return bool Whether another run of enable_step is required + * @return bool False if enabling is finished, true otherwise */ public function enable_step($name) { @@ -191,18 +191,36 @@ class phpbb_extension_manager * process the event. * * @param string $name The extension's name - * @return null + * @return bool False if disabling is finished, true otherwise */ - public function disable($name) + public function disable_step($name) { // ignore extensions that are already disabled if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active']) { - return; + return false; } + $old_state = unserialize($this->extensions[$name]['ext_state']); + $extension = $this->get_extension($name); - $extension->disable(); + $state = $extension->disable_step($old_state); + + // continue until the state is false + if ($state !== false) + { + $extension_data = array( + 'ext_state' => serialize($state), + ); + $this->extensions[$name]['ext_state'] = serialize($state); + + $sql = 'UPDATE ' . $this->extension_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " + WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + + return true; + } $extension_data = array( 'ext_active' => false, @@ -215,6 +233,22 @@ class phpbb_extension_manager SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); + + return false; + } + + /** + * Disables an extension + * + * Disables an extension completely at once. This process could run for a + * while so never call this in a script that has a max_execution time. + * + * @param string $name The extension's name + * @return null + */ + public function disable($name) + { + while ($this->disable_step($name)); } /** @@ -224,7 +258,7 @@ class phpbb_extension_manager * extension's meta class to delete the extension's database content. * * @param string $name The extension's name - * @return null + * @return bool False if purging is finished, true otherwise */ public function purge_step($name) { -- cgit v1.2.1 From 658db65cb477b790f217e0b8c6d202fbb1a8836c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 19 Nov 2011 22:04:43 +0100 Subject: [ticket/10323] make finder work with PHP 5.2 PHPBB3-10323 --- phpBB/includes/extension/finder.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index a1e6b2b347..11eb682f46 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -377,9 +377,14 @@ class phpbb_extension_finder } $directory_pattern = '#' . $directory_pattern . '#'; - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST); + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { + if (in_array($file_info, array('.', '..'))) + { + continue; + } + if ($file_info->isDir() == $is_dir) { if ($is_dir) -- cgit v1.2.1 From 813b5344e6fa245f174692de71a4fb44f239786d Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 20 Nov 2011 02:08:37 +0100 Subject: [ticket/10323] slight potential performance improvement PHPBB3-10323 --- phpBB/includes/extension/finder.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 11eb682f46..f4a0b7a371 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -380,7 +380,8 @@ class phpbb_extension_finder $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { - if (in_array($file_info, array('.', '..'))) + $filename = $file_info->getFilename(); + if ($filename == '.' || $filename == '..') { continue; } @@ -389,7 +390,7 @@ class phpbb_extension_finder { if ($is_dir) { - $relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($file_info->getFilename()) . DIRECTORY_SEPARATOR; + $relative_path = $iterator->getInnerIterator()->getSubPath() . DIRECTORY_SEPARATOR . basename($filename) . DIRECTORY_SEPARATOR; if ($relative_path[0] !== DIRECTORY_SEPARATOR) { $relative_path = DIRECTORY_SEPARATOR . $relative_path; @@ -399,10 +400,9 @@ class phpbb_extension_finder { $relative_path = DIRECTORY_SEPARATOR . $iterator->getInnerIterator()->getSubPathname(); } - $item_name = $file_info->getFilename(); if ((!$suffix || substr($relative_path, -strlen($suffix)) === $suffix) && - (!$prefix || substr($item_name, 0, strlen($prefix)) === $prefix) && + (!$prefix || substr($filename, 0, strlen($prefix)) === $prefix) && (!$directory || preg_match($directory_pattern, $relative_path))) { $files[str_replace(DIRECTORY_SEPARATOR, '/', $location . $name . substr($relative_path, 1))] = $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/extension/base.php | 2 +- phpBB/includes/extension/finder.php | 2 +- phpBB/includes/extension/interface.php | 2 +- phpBB/includes/extension/manager.php | 2 +- phpBB/includes/extension/provider.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index d9159d57d2..9d076eb6c5 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -3,7 +3,7 @@ * * @package extension * @copyright (c) 2011 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 * */ diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index f4a0b7a371..e5e5e4983e 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -3,7 +3,7 @@ * * @package extension * @copyright (c) 2011 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 * */ diff --git a/phpBB/includes/extension/interface.php b/phpBB/includes/extension/interface.php index b37cd24d77..74ecb9b762 100644 --- a/phpBB/includes/extension/interface.php +++ b/phpBB/includes/extension/interface.php @@ -3,7 +3,7 @@ * * @package extension * @copyright (c) 2011 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 * */ diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index bcdd21f7f1..438578e7e7 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -3,7 +3,7 @@ * * @package extension * @copyright (c) 2011 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 * */ diff --git a/phpBB/includes/extension/provider.php b/phpBB/includes/extension/provider.php index 3939c2ef07..d0541fa007 100644 --- a/phpBB/includes/extension/provider.php +++ b/phpBB/includes/extension/provider.php @@ -3,7 +3,7 @@ * * @package extension * @copyright (c) 2011 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 5ccd6b0c7a2952f01b636e7319ed8ae4be8faa77 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 9 Feb 2012 01:03:17 +0100 Subject: [ticket/10614] Tweak list output, show state, purge cache, handle missing exts PHPBB3-10614 --- phpBB/includes/extension/manager.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 438578e7e7..b7f76d0400 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -132,6 +132,12 @@ class phpbb_extension_manager */ public function enable_step($name) { + $ext_path = $this->get_extension_path($name); + if (!file_exists($ext_path)) + { + throw new InvalidArgumentException('The provided extension does not exist.'); + } + // ignore extensions that are already enabled if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']) { @@ -152,7 +158,7 @@ class phpbb_extension_manager ); $this->extensions[$name] = $extension_data; - $this->extensions[$name]['ext_path'] = $this->get_extension_path($extension_data['ext_name']); + $this->extensions[$name]['ext_path'] = $ext_path; ksort($this->extensions); $sql = 'UPDATE ' . $this->extension_table . ' @@ -195,6 +201,12 @@ class phpbb_extension_manager */ public function disable_step($name) { + $ext_path = $this->get_extension_path($name); + if (!file_exists($ext_path)) + { + throw new InvalidArgumentException('The provided extension does not exist.'); + } + // ignore extensions that are already disabled if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active']) { @@ -262,6 +274,12 @@ class phpbb_extension_manager */ public function purge_step($name) { + $ext_path = $this->get_extension_path($name); + if (!file_exists($ext_path)) + { + throw new InvalidArgumentException('The provided extension does not exist.'); + } + // ignore extensions that do not exist if (!isset($this->extensions[$name])) { -- cgit v1.2.1 From 36728d3414e513f0b4aede75d53316e208e5eceb Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 9 Feb 2012 01:36:06 +0100 Subject: [ticket/10614] Refactor list command to use manager API PHPBB3-10614 --- phpBB/includes/extension/manager.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index b7f76d0400..b8643b39ee 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -61,7 +61,7 @@ class phpbb_extension_manager * * @return null */ - protected function load_extensions() + public function load_extensions() { $sql = 'SELECT * FROM ' . $this->extension_table; @@ -173,6 +173,8 @@ class phpbb_extension_manager $this->db->sql_query($sql); } + $this->cache->destroy($this->cache_name); + return !$active; } @@ -231,6 +233,8 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); + $this->cache->destroy($this->cache_name); + return true; } @@ -246,6 +250,8 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); + $this->cache->destroy($this->cache_name); + return false; } @@ -310,6 +316,8 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); + $this->cache->destroy($this->cache_name); + return true; } @@ -319,6 +327,8 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); + $this->cache->destroy($this->cache_name); + return false; } -- cgit v1.2.1 From 68e4c667fa5f29f7974b83549a2a9bb8bbd8abc5 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 9 Feb 2012 01:37:53 +0100 Subject: [ticket/10614] Remove ext manager exceptions for now PHPBB3-10614 --- phpBB/includes/extension/manager.php | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index b8643b39ee..12b626d69f 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -132,12 +132,6 @@ class phpbb_extension_manager */ public function enable_step($name) { - $ext_path = $this->get_extension_path($name); - if (!file_exists($ext_path)) - { - throw new InvalidArgumentException('The provided extension does not exist.'); - } - // ignore extensions that are already enabled if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']) { @@ -158,7 +152,7 @@ class phpbb_extension_manager ); $this->extensions[$name] = $extension_data; - $this->extensions[$name]['ext_path'] = $ext_path; + $this->extensions[$name]['ext_path'] = $this->get_extension_path($extension_data['ext_name']); ksort($this->extensions); $sql = 'UPDATE ' . $this->extension_table . ' @@ -203,12 +197,6 @@ class phpbb_extension_manager */ public function disable_step($name) { - $ext_path = $this->get_extension_path($name); - if (!file_exists($ext_path)) - { - throw new InvalidArgumentException('The provided extension does not exist.'); - } - // ignore extensions that are already disabled if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active']) { @@ -280,12 +268,6 @@ class phpbb_extension_manager */ public function purge_step($name) { - $ext_path = $this->get_extension_path($name); - if (!file_exists($ext_path)) - { - throw new InvalidArgumentException('The provided extension does not exist.'); - } - // ignore extensions that do not exist if (!isset($this->extensions[$name])) { -- cgit v1.2.1 From 78de29b7ce5b8c1c34749bb68813840f7e6c4b7b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 9 Feb 2012 01:39:45 +0100 Subject: [ticket/10614] Check if cache exists before destroying it PHPBB3-10614 --- phpBB/includes/extension/manager.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 12b626d69f..56092410f2 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -167,7 +167,10 @@ class phpbb_extension_manager $this->db->sql_query($sql); } - $this->cache->destroy($this->cache_name); + if ($this->cache) + { + $this->cache->destroy($this->cache_name); + } return !$active; } @@ -221,7 +224,10 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $this->cache->destroy($this->cache_name); + if ($this->cache) + { + $this->cache->destroy($this->cache_name); + } return true; } @@ -238,7 +244,10 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $this->cache->destroy($this->cache_name); + if ($this->cache) + { + $this->cache->destroy($this->cache_name); + } return false; } @@ -298,7 +307,10 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $this->cache->destroy($this->cache_name); + if ($this->cache) + { + $this->cache->destroy($this->cache_name); + } return true; } @@ -309,7 +321,10 @@ class phpbb_extension_manager WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; $this->db->sql_query($sql); - $this->cache->destroy($this->cache_name); + if ($this->cache) + { + $this->cache->destroy($this->cache_name); + } return false; } -- cgit v1.2.1 From 2814021d3ff3be4d57166ac8da224807cabb5367 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 11 Feb 2012 15:08:05 -0500 Subject: [ticket/10614] Unbreak all_available on extension manager. By default RecursiveIteratorIterator skips all directories. This results in extension manager not finding any extensions. Add RecursiveIteratorIterator::SELF_FIRST to correct this. PHPBB3-10614 --- phpBB/includes/extension/manager.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 56092410f2..c38f0df32e 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -354,7 +354,8 @@ class phpbb_extension_manager $available = array(); $iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/')); + new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/'), + RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { if ($file_info->isFile() && $file_info->getFilename() == 'ext' . $this->phpEx) -- cgit v1.2.1 From 41870c40954bdd0faad2ce4b01fb416a03eed4e0 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 21 Feb 2012 18:32:08 +0100 Subject: [ticket/10663] Extension finder should not find subdirs with directory filter The directory filter pattern now has a $ in the end, do avoid subdirectories from being matched as well. PHPBB3-10663 --- phpBB/includes/extension/finder.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index e5e5e4983e..23b9f1c658 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -375,6 +375,10 @@ class phpbb_extension_finder { $directory_pattern = preg_quote(DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $directory) . DIRECTORY_SEPARATOR, '#'); } + if ($is_dir) + { + $directory_pattern .= '$'; + } $directory_pattern = '#' . $directory_pattern . '#'; $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); -- cgit v1.2.1 From a0131b45f56847f7e5c44a6db66cd7359967585f Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 8 Feb 2012 00:08:17 -0500 Subject: [ticket/10586] Extension front controller Handle extension front pages PHPBB3-10586 --- phpBB/includes/extension/controller_interface.php | 31 +++++++++++++++++++++++ phpBB/includes/extension/manager.php | 22 ++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 phpBB/includes/extension/controller_interface.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php new file mode 100644 index 0000000000..bcc8972db4 --- /dev/null +++ b/phpBB/includes/extension/controller_interface.php @@ -0,0 +1,31 @@ +phpbb_root_path . "ext/$name/"); + } + + /** + * Check to see if a given extension is enabled + * + * @param string $name Extension name to check + * @return bool Depending on whether or not the extension is enabled + */ + public function enabled($name) + { + return isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']; + } /** * Instantiates a phpbb_extension_finder. -- cgit v1.2.1 From e45452d1b3d39220ebd9b20390b9cc23ef64d3dd Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 18 Feb 2012 11:24:27 -0500 Subject: [ticket/10586] Sanitize periods from class names, use manager to get path. PHPBB3-10586 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index b94379141c..6f1c885ea9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -437,7 +437,7 @@ class phpbb_extension_manager */ public function available($name) { - return file_exists($this->phpbb_root_path . "ext/$name/"); + return file_exists($this->get_extension_path($name, true)); } /** -- cgit v1.2.1 From 18c541dfee6ec7db0e04c939bc103cefe9dab9d7 Mon Sep 17 00:00:00 2001 From: Dhruv Goel Date: Fri, 23 Mar 2012 00:27:29 +0530 Subject: [ticket/10703] Added a condition to check if ext directory exists The existence of ext directory is checked, if not present a proper error message that file doesn't exist is printed out. No Fatal Error messages. PHPBB3-10703 --- phpBB/includes/extension/manager.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index c38f0df32e..dac0e5f947 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -352,6 +352,10 @@ class phpbb_extension_manager public function all_available() { $available = array(); + if (!is_dir($this->phpbb_root_path . 'ext/')) + { + return $available; + } $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($this->phpbb_root_path . 'ext/'), -- cgit v1.2.1 From 56f75dbf93b0476f88c866abcae129fa3b61fc2c Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 27 Mar 2012 19:57:32 -0400 Subject: [ticket/10586] Tidy up comments PHPBB3-10586 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 6f1c885ea9..f103983fcd 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -432,7 +432,7 @@ class phpbb_extension_manager /** * Check to see if a given extension is available on the filesystem * - * @param string $name Extension name to check + * @param string $name Extension name to check NOTE: Can be user input * @return bool Depending on whether or not the extension is available */ public function available($name) -- cgit v1.2.1 From cb7dabbffc7ea5e2acffaa6fed96ea682f93581d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:13:59 -0400 Subject: [ticket/10586] Change the interface to an abstract class This allows the common phpBB objects to be automatically accessible to extensions without the author having to globalize and assign each one himself. This is better because it also gives purpose to the phpbb_extension_controller class; instead of just being the way to ensure a handle() method is present, it also does this work for us. PHPBB3-10586 --- phpBB/includes/extension/controller.php | 85 +++++++++++++++++++++++ phpBB/includes/extension/controller_interface.php | 31 --------- 2 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 phpBB/includes/extension/controller.php delete mode 100644 phpBB/includes/extension/controller_interface.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php new file mode 100644 index 0000000000..985aded862 --- /dev/null +++ b/phpBB/includes/extension/controller.php @@ -0,0 +1,85 @@ +request =& $request; + $this->db =& $db; + $this->user =& $user; + $this->template =& $template; + $this->config =& $config; + + $this->phpEx = $phpEx; + $this->phpbb_root_path = $phpbb_root_path; + } + + /** + * Handle the request to display a page from an extension + * + * @return null + */ + abstract public function handle(); +} diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php deleted file mode 100644 index bcc8972db4..0000000000 --- a/phpBB/includes/extension/controller_interface.php +++ /dev/null @@ -1,31 +0,0 @@ - Date: Wed, 28 Mar 2012 16:21:17 -0400 Subject: [ticket/10586] Make the abstract class implement the original interface PHPBB3-10586 --- phpBB/includes/extension/controller.php | 2 +- phpBB/includes/extension/controller_interface.php | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 phpBB/includes/extension/controller_interface.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 985aded862..e7d4427c87 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -20,7 +20,7 @@ if (!defined('IN_PHPBB')) * * @package extension */ -abstract class phpbb_extension_controller +abstract class phpbb_extension_controller implements phpbb_extension_controller_interface { /** * @var phpbb_request Request class object diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php new file mode 100644 index 0000000000..bcc8972db4 --- /dev/null +++ b/phpBB/includes/extension/controller_interface.php @@ -0,0 +1,31 @@ + Date: Wed, 28 Mar 2012 16:23:40 -0400 Subject: [ticket/10586] Do not pass as reference PHPBB3-10586 --- phpBB/includes/extension/controller.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index e7d4427c87..6e47948156 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -66,12 +66,11 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ global $request, $db, $user, $template, $config; global $phpEx, $phpbb_root_path; - $this->request =& $request; - $this->db =& $db; - $this->user =& $user; - $this->template =& $template; - $this->config =& $config; - + $this->request = $request; + $this->db = $db; + $this->user = $user; + $this->template = $template; + $this->config = $config; $this->phpEx = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } -- cgit v1.2.1 From 7b091f18a83f4bc31fc00ef067b55db48137ef47 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:37:42 -0400 Subject: [ticket/10586] Remove handle() from abstract class, undo change in index.php PHPBB3-10586 --- phpBB/includes/extension/controller.php | 7 ------- phpBB/includes/extension/controller_interface.php | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 6e47948156..8861ec2696 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -74,11 +74,4 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ $this->phpEx = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } - - /** - * Handle the request to display a page from an extension - * - * @return null - */ - abstract public function handle(); } diff --git a/phpBB/includes/extension/controller_interface.php b/phpBB/includes/extension/controller_interface.php index bcc8972db4..2b88925388 100644 --- a/phpBB/includes/extension/controller_interface.php +++ b/phpBB/includes/extension/controller_interface.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) interface phpbb_extension_controller_interface { /** - * handle the request to display a page from an extension + * Handle the request to display a page from an extension * * @return null */ -- cgit v1.2.1 From afc55b4c08ca891e11e2aba15dce1f9b5b7c481a Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 28 Mar 2012 16:50:18 -0400 Subject: [ticket/10586] Added visibility indication to __construct() PHPBB3-10586 --- phpBB/includes/extension/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 8861ec2696..c7fd439a19 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -61,7 +61,7 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ * Constructor method that provides the common phpBB objects as inherited class * properties for automatic availability in extension controllers */ - function __construct() + public function __construct() { global $request, $db, $user, $template, $config; global $phpEx, $phpbb_root_path; -- cgit v1.2.1 From b3f46b9565117940b79c7530a1c21336cd072073 Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sat, 31 Mar 2012 21:20:18 +0300 Subject: [ticket/10735] Changing locator paths structure Changing locator paths to 2 dimensional array PHPBB3-10735 --- phpBB/includes/extension/finder.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 23b9f1c658..87ca40917d 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -270,11 +270,12 @@ class phpbb_extension_finder * Finds all directories matching the configured options * * @param bool $cache Whether the result should be cached + * @param bool $extension_keys Whether the result should have extension name as array key * @return array An array of paths to found directories */ - public function get_directories($cache = true) + public function get_directories($cache = true, $extension_keys = false) { - return $this->find_with_root_path($cache, true); + return $this->find_with_root_path($cache, true, $extension_keys); } /** @@ -294,16 +295,25 @@ class phpbb_extension_finder * @param bool $cache Whether the result should be cached * @param bool $is_dir Directories will be returned when true, only files * otherwise + * @param bool $extension_keys If true, result will be associative array + * with extension name as key * @return array An array of paths to found items */ - protected function find_with_root_path($cache = true, $is_dir = false) + protected function find_with_root_path($cache = true, $is_dir = false, $extension_keys = false) { $items = $this->find($cache, $is_dir); $result = array(); foreach ($items as $item => $ext_name) { - $result[] = $this->phpbb_root_path . $item; + if ($extension_keys) + { + $result[$ext_name] = $this->phpbb_root_path . $item; + } + else + { + $result[] = $this->phpbb_root_path . $item; + } } return $result; -- cgit v1.2.1 From 85bcdbad468cd255a02d6c48b2dcd1d128978eed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 21 Jul 2012 16:19:01 +0200 Subject: [ticket/11012] Normalize $phpEx member vars to $php_ext PHPBB3-11012 --- phpBB/includes/extension/controller.php | 6 +++--- phpBB/includes/extension/finder.php | 14 +++++++------- phpBB/includes/extension/manager.php | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index c7fd439a19..ec051c756f 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -50,7 +50,7 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ /** * @var string PHP Extension */ - protected $phpEx; + protected $php_ext; /** * @var string Relative path to board root @@ -64,14 +64,14 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ public function __construct() { global $request, $db, $user, $template, $config; - global $phpEx, $phpbb_root_path; + global $php_ext, $phpbb_root_path; $this->request = $request; $this->db = $db; $this->user = $user; $this->template = $template; $this->config = $config; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->phpbb_root_path = $phpbb_root_path; } } diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 87ca40917d..fb19b98429 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -25,7 +25,7 @@ class phpbb_extension_finder protected $extension_manager; protected $phpbb_root_path; protected $cache; - protected $phpEx; + protected $php_ext; /** * The cache variable name used to store $this->cached_queries in $this->cache. @@ -56,16 +56,16 @@ class phpbb_extension_finder * extensions and their locations * @param string $phpbb_root_path Path to the phpbb root directory * @param phpbb_cache_driver_interface $cache A cache instance or null - * @param string $phpEx php file extension + * @param string $php_ext php file extension * @param string $cache_name The name of the cache variable, defaults to * _ext_finder */ - public function __construct(phpbb_extension_manager $extension_manager, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $phpEx = '.php', $cache_name = '_ext_finder') + public function __construct(phpbb_extension_manager $extension_manager, $phpbb_root_path = '', phpbb_cache_driver_interface $cache = null, $php_ext = '.php', $cache_name = '_ext_finder') { $this->extension_manager = $extension_manager; $this->phpbb_root_path = $phpbb_root_path; $this->cache = $cache; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->cache_name = $cache_name; $this->query = array( @@ -251,8 +251,8 @@ class phpbb_extension_finder */ public function get_classes($cache = true) { - $this->query['extension_suffix'] .= $this->phpEx; - $this->query['core_suffix'] .= $this->phpEx; + $this->query['extension_suffix'] .= $this->php_ext; + $this->query['core_suffix'] .= $this->php_ext; $files = $this->find($cache, false); @@ -261,7 +261,7 @@ class phpbb_extension_finder { $file = preg_replace('#^includes/#', '', $file); - $classes[] = 'phpbb_' . str_replace('/', '_', substr($file, 0, -strlen($this->phpEx))); + $classes[] = 'phpbb_' . str_replace('/', '_', substr($file, 0, -strlen($this->php_ext))); } return $classes; } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 537c19aff8..86d8fab64b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -23,7 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_extension_manager { protected $cache; - protected $phpEx; + protected $php_ext; protected $extensions; protected $extension_table; protected $phpbb_root_path; @@ -35,16 +35,16 @@ class phpbb_extension_manager * @param dbal $db A database connection * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. - * @param string $phpEx php file extension + * @param string $php_ext php file extension * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(dbal $db, $extension_table, $phpbb_root_path, $phpEx = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(dbal $db, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->cache = $cache; - $this->phpEx = $phpEx; + $this->php_ext = $php_ext; $this->extension_table = $extension_table; $this->cache_name = $cache_name; @@ -362,7 +362,7 @@ class phpbb_extension_manager RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file_info) { - if ($file_info->isFile() && $file_info->getFilename() == 'ext' . $this->phpEx) + if ($file_info->isFile() && $file_info->getFilename() == 'ext' . $this->php_ext) { $ext_name = $iterator->getInnerIterator()->getSubPath(); @@ -432,7 +432,7 @@ class phpbb_extension_manager } return $disabled; } - + /** * Check to see if a given extension is available on the filesystem * @@ -462,6 +462,6 @@ class phpbb_extension_manager */ public function get_finder() { - return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->phpEx, $this->cache_name . '_finder'); + return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } } -- cgit v1.2.1 From a35ad4e689c204c52d23c07b701433325c27b0dc Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 2 Aug 2012 12:38:49 +0200 Subject: [ticket/11041] Correctly import PHP file extension from global space. 85bcdbad468cd255a02d6c48b2dcd1d128978eed shouldn't have changed imports of "global $phpEx". PHPBB3-11041 --- phpBB/includes/extension/controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index ec051c756f..2b8c50aafb 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -64,14 +64,14 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ public function __construct() { global $request, $db, $user, $template, $config; - global $php_ext, $phpbb_root_path; + global $phpEx, $phpbb_root_path; $this->request = $request; $this->db = $db; $this->user = $user; $this->template = $template; $this->config = $config; - $this->php_ext = $php_ext; + $this->php_ext = $phpEx; $this->phpbb_root_path = $phpbb_root_path; } } -- cgit v1.2.1 From fe579cac8385381f52a26cd61a2de29a71434f2b Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 14 Aug 2012 09:57:17 -0400 Subject: [ticket/11054] Fixed documentation syntax for @var in extension/controller.php PHPBB3-11054 --- phpBB/includes/extension/controller.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 2b8c50aafb..1099bc128e 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -23,37 +23,44 @@ if (!defined('IN_PHPBB')) abstract class phpbb_extension_controller implements phpbb_extension_controller_interface { /** - * @var phpbb_request Request class object + * Request class object + * @var phpbb_request */ protected $request; /** - * @var dbal DBAL class object + * DBAL class object + * @var dbal */ protected $db; /** - * @var user User class object + * User class object + * @var user */ protected $user; /** - * @var phpbb_template Template class object + * Template class object + * @var phpbb_template */ protected $template; /** - * @var array Config array + * Config array + * @var array */ protected $config; /** - * @var string PHP Extension + * PHP Extension + * @var string */ protected $php_ext; /** - * @var string Relative path to board root + * Relative path to board root + * @var string */ protected $phpbb_root_path; -- cgit v1.2.1 From 0b70c3d0d6e96854ab517244e8ae745c24b862f4 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 14 Aug 2012 10:02:16 -0400 Subject: [ticket/11054] The user class is phpbb_user PHPBB3-11054 --- phpBB/includes/extension/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 1099bc128e..3e9eadf2dd 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -36,7 +36,7 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ /** * User class object - * @var user + * @var phpbb_user */ protected $user; -- cgit v1.2.1 From b729609fb29ba653b168a8bcb2e071e3bd72dda6 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 15 Aug 2012 09:15:18 -0400 Subject: [ticket/11054] Fixed $config var description PHPBB3-11054 --- phpBB/includes/extension/controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/controller.php b/phpBB/includes/extension/controller.php index 3e9eadf2dd..f97b69c7ed 100644 --- a/phpBB/includes/extension/controller.php +++ b/phpBB/includes/extension/controller.php @@ -47,8 +47,8 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_ protected $template; /** - * Config array - * @var array + * Config object + * @var phpbb_config */ protected $config; -- cgit v1.2.1 From 7a954d352ef1fe84256ad691135b6c6bf0d4bcc5 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 28 Apr 2012 18:13:28 +0100 Subject: [ticket/10631] Fixing some items mentioned in PR PHPBB3-10631 --- phpBB/includes/extension/manager.php | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 86d8fab64b..2eebebf9b2 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,4 +464,68 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } + + /** + * Gets and processes the contents of the composer.json file. + * + * TODO: Add authors, fix it + * + * @param string $name Extension name to check + * @return array All the existing metadata keys + */ + public function get_meta_data($name) + { + // Find out where the composer.json is + $ext_filepath = get_extension_path($name); + $md_filepath = $phpbb_root_path . $ext_filepath . '/composer.json'; + + // Read the composer.json and decode it + $metadatafile = file_get_contents($filepath); + $metadata = json_decode($metadatafile, true); + + // What keys are required + $required_md_keys = array( + $metadata['name'], + $metadata['type'], + $metadata['description'], + $metadata['version'], + $metadata['license'], + $medadata['require']['phpbb'], + $metadata['extra']['dispay-name'], + ); + + // Check for required keys and trigger and error if it doesn't exist + foreach ($required_md_keys as $md_key) + { + if (empty($md_key)) + { + trigger_error('Not all required items exist in the composer.json'); + } + else + { + $existing_required_keys += $md_key; + } + } + + // Which keys are optional + $optional_md_keys = array( + $metadata['require']['php'], + $metadata['time'], + $metadata['homepage'], + ); + + $existing_optional_keys = array(); + + foreach ($optional_md_keys as $md_key) + { + if (!empty($md_key)) + { + $existing_optional_keys += $md_key; + } + } + + $keys = array_merge($existing_optional_keys, $existing_required_keys); + + return $keys; + } } -- cgit v1.2.1 From a0e283d7b025325476c3c44f033410b47a87c621 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 19:56:02 +0100 Subject: [ticket/10631] Adding extension metadata manager class PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 368 ++++++++++++++++++++++++++ 1 file changed, 368 insertions(+) create mode 100644 phpBB/includes/extension/metadata_manager.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php new file mode 100644 index 0000000000..b58f1c6498 --- /dev/null +++ b/phpBB/includes/extension/metadata_manager.php @@ -0,0 +1,368 @@ +phpbb_root_path = $phpbb_root_path; + $this->db = $db; + $this->phpEx = $phpEx; + $this->extension_manager = $extension_manager; + $this->ext_name = $ext_name; + $this->template = $template; + $this->metadata = array(); + $this->metadata_file = ''; + } + + /** + * Processes and gets the metadata requested + * + * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. + * @param bool $template_output True if you want the requested metadata assigned to template vars + * @return array Contains all of the requested metadata + */ + public function get_meta_data($element = 'all', $template_output = false) + { + // TODO: Check ext_name exists and is an extension that exists + if (!$this->set_meta_data_file()) + { + return false; + } + + switch ($element) + { + case 'all': + default: + if (!$this->clean_metadata_array()) + { + return false; + } + + if ($template_output) + { + $this->output_template_data(); + } + + return $this->metadata; + break; + + case 'name': + if($this->validate_name) + { + if ($template_output) + { + $this->template->assign_vars(array( + 'MD_NAME' => htmlspecialchars($this->metadata['name']), + )); + } + return $this->metadata['name']; + } + else + { + return false; + } + break; + // TODO: Add remaining cases + } + } + + /** + * Sets the filepath of the metadata file + * + * @return null + */ + private function set_meta_data_file() + { + $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); + $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; + + $this->metadata_file = $metadata_filepath; + + if(!file_exists($this->metadata_file)) + { + return false; + } + else + { + return true; + } + } + + /** + * This array handles the validation and cleaning of the array + * + * @return array Contains the cleaned and validated metadata array + */ + private function clean_metadata_array() + { + if (!$this->validate_name() || !$this->validate_type() || !$this->validate_license() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + { + return false; + } + + $this->check_for_optional(true); + +// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors +// $this->metadata = $metadata_finished; + $metadata_finished = $this->metadata; + + return $metadata_finished; + } + + /** + * Validates the contents of the name field + * + * @return bool True when passes validation + */ + private function validate_name() + { + if(preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the type field + * + * @return bool True when passes validation + */ + private function validate_type() + { + if ($this->metadata['type'] != 'phpbb3-extension') + { + return false; + } + else + { + return true; + } + } + + /** + * Validates the contents of the description field + * + * @return bool True when passes validation + */ + private function validate_description() + { + if(preg_match('^{10,}$', $this->metadata['description'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the version field + * + * @return bool True when passes validation + */ + private function validate_version() + { + if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the license field + * + * @return bool True when passes validation + */ + private function validate_license() + { + if ($this->metadata['license'] != 'GPLv2') + { + return false; + } + else + { + return true; + } + } + + /** + * Validates the contents of the phpbb requirement field + * + * @return bool True when passes validation + */ + private function validate_require_phpbb() + { + if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>') + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the display name field + * + * @return bool True when passes validation + */ + private function validate_extra_display_name() + { + if(preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Checks which optional fields exist + * + * @return boolean False if any that exist fail validation, otherwise true. + */ + public function check_for_optional() + { + if ((isset($this->metadata['require']['php']) && !$this->validate_require_php()) || (isset($this->metadata['time']) && !$this->validate_time()) || (isset($this->metadata['validate_homepage']) && !$this->validate_homepage())) + { + return false; + } + } + + /** + * Validates the contents of the php requirement field + * + * @return bool True when passes validation + */ + private function validate_require_php() + { + + } + + /** + * Validates the contents of the time field + * + * @return bool True when passes validation + */ + private function validate_time() + { + + } + + /** + * Validates the contents of the homepage field + * + * @return bool True when passes validation + */ + private function validate_homepage() + { + + } + + /** + * Validates the contents of the authors field + * + * @return bool True when passes validation + */ + private function validate_authors() + { + + } + + /** + * Gets the contents of the composer.json file and can also assign template vars + * + * @return array Contains everything from the meta data file. Do not use without validating and cleaning first + */ + private function fetch_metadata() + { + // Read it + $metadata_file = file_get_contents($metadata_filepath); + $metadata = json_decode($metadata_file, true) + + $this->metadata = $metadata; + + return $metadata; + } + + /** + * Outputs the metadata into the template + * + * @return null + */ + public function output_template_data() + { + $template->assign_vars(array( + 'MD_NAME' => htmlspecialchars($this->metadata['name']), + 'MD_TYPE' => htmlspecialchars($this->metadata['type']), + 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), + 'MD_HOMEPAGE' => $this->metadata['homepage'], + 'MD_VERSION' => htmlspecialchars($this->metadata['version']), + 'MD_TIME' => htmlspecialchars($this->metadata['time']), + 'MD_LICENSE' => htmlspecialchars($this->metadata['license']), + 'MD_REQUIRE_PHP' => htmlspecialchars($this->metadata['require']['php']), + 'MD_REQUIRE_PHPBB' => htmlspecialchars($this->metadata['require']['phpbb']), + 'MD_DISPLAY_NAME' => htmlspecialchars($this->metadata['extra']['display-name']), + )); + + foreach ($this->metadata['authors'] as $author) + { + $template->assign_block_vars('md_authors', array( + 'AUTHOR_NAME' => htmlspecialchars($author['name']), + 'AUTHOR_EMAIL' => $author['email'], + 'AUTHOR_HOMEPAGE' => $author['homepage'], + 'AUTHOR_ROLE' => htmlspecialchars($author['role']), + )); + } + + return; + } -- cgit v1.2.1 From ac883e26528736c74f96b5bc692f685bdb25fd57 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 19:57:02 +0100 Subject: [ticket/10631] Remove the now un-used method PHPBB3-10631 --- phpBB/includes/extension/manager.php | 65 ------------------------------------ 1 file changed, 65 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 2eebebf9b2..287e3828f9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,68 +464,3 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } - - /** - * Gets and processes the contents of the composer.json file. - * - * TODO: Add authors, fix it - * - * @param string $name Extension name to check - * @return array All the existing metadata keys - */ - public function get_meta_data($name) - { - // Find out where the composer.json is - $ext_filepath = get_extension_path($name); - $md_filepath = $phpbb_root_path . $ext_filepath . '/composer.json'; - - // Read the composer.json and decode it - $metadatafile = file_get_contents($filepath); - $metadata = json_decode($metadatafile, true); - - // What keys are required - $required_md_keys = array( - $metadata['name'], - $metadata['type'], - $metadata['description'], - $metadata['version'], - $metadata['license'], - $medadata['require']['phpbb'], - $metadata['extra']['dispay-name'], - ); - - // Check for required keys and trigger and error if it doesn't exist - foreach ($required_md_keys as $md_key) - { - if (empty($md_key)) - { - trigger_error('Not all required items exist in the composer.json'); - } - else - { - $existing_required_keys += $md_key; - } - } - - // Which keys are optional - $optional_md_keys = array( - $metadata['require']['php'], - $metadata['time'], - $metadata['homepage'], - ); - - $existing_optional_keys = array(); - - foreach ($optional_md_keys as $md_key) - { - if (!empty($md_key)) - { - $existing_optional_keys += $md_key; - } - } - - $keys = array_merge($existing_optional_keys, $existing_required_keys); - - return $keys; - } -} -- cgit v1.2.1 From 10cba1426d7119a98c55cbefe2cfb1fd7de9b057 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 23:32:34 +0100 Subject: [ticket/10631] Some tidying up PHPBB3-10631 --- phpBB/includes/extension/manager.php | 1 + phpBB/includes/extension/metadata_manager.php | 71 +++++---------------------- 2 files changed, 12 insertions(+), 60 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 287e3828f9..86d8fab64b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,3 +464,4 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } +} diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index b58f1c6498..db8d09b696 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -39,7 +39,7 @@ class phpbb_extension_metadata_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; @@ -84,7 +84,7 @@ class phpbb_extension_metadata_manager break; case 'name': - if($this->validate_name) + if ($this->validate_name) { if ($template_output) { @@ -106,7 +106,7 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file * - * @return null + * @return boolean Set to true if it exists */ private function set_meta_data_file() { @@ -115,7 +115,7 @@ class phpbb_extension_metadata_manager $this->metadata_file = $metadata_filepath; - if(!file_exists($this->metadata_file)) + if (!file_exists($this->metadata_file)) { return false; } @@ -153,14 +153,7 @@ class phpbb_extension_metadata_manager */ private function validate_name() { - if(preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name'])) - { - return true; - } - else - { - return false; - } + return preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name']); } /** @@ -170,14 +163,7 @@ class phpbb_extension_metadata_manager */ private function validate_type() { - if ($this->metadata['type'] != 'phpbb3-extension') - { - return false; - } - else - { - return true; - } + return $this->metadata['type'] != 'phpbb3-extension'; } /** @@ -187,14 +173,7 @@ class phpbb_extension_metadata_manager */ private function validate_description() { - if(preg_match('^{10,}$', $this->metadata['description'])) - { - return true; - } - else - { - return false; - } + return preg_match('^{10,}$', $this->metadata['description']); } /** @@ -204,14 +183,7 @@ class phpbb_extension_metadata_manager */ private function validate_version() { - if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version'])) - { - return true; - } - else - { - return false; - } + return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version']); } /** @@ -221,14 +193,7 @@ class phpbb_extension_metadata_manager */ private function validate_license() { - if ($this->metadata['license'] != 'GPLv2') - { - return false; - } - else - { - return true; - } + return $this->metadata['license'] != 'GPLv2'; } /** @@ -238,14 +203,7 @@ class phpbb_extension_metadata_manager */ private function validate_require_phpbb() { - if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>') - { - return true; - } - else - { - return false; - } + return (preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>'); } /** @@ -255,14 +213,7 @@ class phpbb_extension_metadata_manager */ private function validate_extra_display_name() { - if(preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name'])) - { - return true; - } - else - { - return false; - } + return preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name']); } /** -- cgit v1.2.1 From 3e6761b0266dfc67f6b41fea50d377b7621dffe0 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:16:00 +0100 Subject: [ticket/10631] Fixing and finishing the extension metadata class. PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 67 +++++++++++++++++---------- 1 file changed, 43 insertions(+), 24 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index db8d09b696..6ec5a0f76d 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -28,7 +28,7 @@ class phpbb_extension_metadata_manager protected $phpbb_root_path; protected $ext_name; protected $template; - protected $metadata; + public $metadata; protected $metadata_file; /** @@ -55,13 +55,13 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param bool $template_output True if you want the requested metadata assigned to template vars + * @param boolean $template_output True if you want the requested metadata assigned to template vars * @return array Contains all of the requested metadata */ - public function get_meta_data($element = 'all', $template_output = false) + public function get_metadata($element = 'all', $template_output = false) { // TODO: Check ext_name exists and is an extension that exists - if (!$this->set_meta_data_file()) + if (!$this->set_metadata_file()) { return false; } @@ -99,7 +99,7 @@ class phpbb_extension_metadata_manager return false; } break; - // TODO: Add remaining cases + // TODO: Add remaining cases as needed } } @@ -108,7 +108,7 @@ class phpbb_extension_metadata_manager * * @return boolean Set to true if it exists */ - private function set_meta_data_file() + private function set_metadata_file() { $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; @@ -141,15 +141,14 @@ class phpbb_extension_metadata_manager // TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors // $this->metadata = $metadata_finished; - $metadata_finished = $this->metadata; - return $metadata_finished; + return $this->metadata; } /** * Validates the contents of the name field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_name() { @@ -159,7 +158,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the type field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_type() { @@ -169,7 +168,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the description field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_description() { @@ -179,27 +178,28 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the version field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_version() { - return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version']); + return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}', $this->metadata['version']); } /** * Validates the contents of the license field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_license() { - return $this->metadata['license'] != 'GPLv2'; + // Nothing to validate except existence + return isset($this->metadata['version']); } /** * Validates the contents of the phpbb requirement field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_require_phpbb() { @@ -209,7 +209,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the display name field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_extra_display_name() { @@ -232,41 +232,60 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the php requirement field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_require_php() { - + return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb'] } /** * Validates the contents of the time field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_time() { - + // Need to validate + return true; } /** * Validates the contents of the homepage field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_homepage() { - + return preg_match('([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']) } /** * Validates the contents of the authors field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_authors() { + // Need to validate + $number_authors = sizeof($this->metadata['authors']); // Might be helpful later on + + if (!isset($this->metadata['authors']['1'])) + { + return false; + } + else + { + foreach ($this->metadata['authors'] as $author) + { + if (!isset($author['name'])) + { + return false; + } + } + } + return true; } /** -- cgit v1.2.1 From dd4f07f9bb864bdac8b6c4009d166f1df6411419 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:18:11 +0100 Subject: [ticket/10631] Template shouldn't be required PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 6ec5a0f76d..fea66c86fe 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -27,7 +27,6 @@ class phpbb_extension_metadata_manager protected $db; protected $phpbb_root_path; protected $ext_name; - protected $template; public $metadata; protected $metadata_file; @@ -39,14 +38,13 @@ class phpbb_extension_metadata_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->phpEx = $phpEx; $this->extension_manager = $extension_manager; $this->ext_name = $ext_name; - $this->template = $template; $this->metadata = array(); $this->metadata_file = ''; } @@ -58,7 +56,7 @@ class phpbb_extension_metadata_manager * @param boolean $template_output True if you want the requested metadata assigned to template vars * @return array Contains all of the requested metadata */ - public function get_metadata($element = 'all', $template_output = false) + public function get_metadata($element = 'all', $template_output = false, phpbb_template $template) { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -77,7 +75,7 @@ class phpbb_extension_metadata_manager if ($template_output) { - $this->output_template_data(); + $this->output_template_data($template); } return $this->metadata; @@ -88,7 +86,7 @@ class phpbb_extension_metadata_manager { if ($template_output) { - $this->template->assign_vars(array( + $template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), )); } @@ -309,7 +307,7 @@ class phpbb_extension_metadata_manager * * @return null */ - public function output_template_data() + public function output_template_data(phpbb_template $template) { $template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), -- cgit v1.2.1 From 3ba59c6362c955d1f9b59278f7dd19cdacecff99 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 18:11:56 -0500 Subject: [ticket/10631] Various tidbits and cleanup on the acp extensions manager PHPBB3-10631 --- phpBB/includes/extension/manager.php | 13 ++++++ phpBB/includes/extension/metadata_manager.php | 64 ++++++++++++++++++--------- 2 files changed, 56 insertions(+), 21 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 86d8fab64b..e7ceef6ad5 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -22,6 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_manager { + protected $db; protected $cache; protected $php_ext; protected $extensions; @@ -120,6 +121,18 @@ class phpbb_extension_manager } } + /** + * Instantiates the metadata manager for the extension with the given name + * + * @param string $name The extension name + * @param string $template The template manager + * @return phpbb_extension_metadata_manager Instance of the metadata manager + */ + public function get_extension_metadata($name, phpbb_template $template) + { + return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->phpEx, $template); + } + /** * Runs a step of the extension enabling process. * diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index fea66c86fe..a9dcd89592 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -26,6 +26,7 @@ class phpbb_extension_metadata_manager protected $extension_manager; protected $db; protected $phpbb_root_path; + protected $template; protected $ext_name; public $metadata; protected $metadata_file; @@ -38,11 +39,12 @@ class phpbb_extension_metadata_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php') + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->phpEx = $phpEx; + $this->template = $template; $this->extension_manager = $extension_manager; $this->ext_name = $ext_name; $this->metadata = array(); @@ -56,7 +58,7 @@ class phpbb_extension_metadata_manager * @param boolean $template_output True if you want the requested metadata assigned to template vars * @return array Contains all of the requested metadata */ - public function get_metadata($element = 'all', $template_output = false, phpbb_template $template) + public function get_metadata($element = 'all', $template_output = false) { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -64,6 +66,11 @@ class phpbb_extension_metadata_manager return false; } + if (!$this->fetch_metadata()) + { + return false; + } + switch ($element) { case 'all': @@ -82,7 +89,7 @@ class phpbb_extension_metadata_manager break; case 'name': - if ($this->validate_name) + if ($this->validate_name()) { if ($template_output) { @@ -90,6 +97,7 @@ class phpbb_extension_metadata_manager 'MD_NAME' => htmlspecialchars($this->metadata['name']), )); } + return $this->metadata['name']; } else @@ -129,7 +137,7 @@ class phpbb_extension_metadata_manager * @return array Contains the cleaned and validated metadata array */ private function clean_metadata_array() - { + { if (!$this->validate_name() || !$this->validate_type() || !$this->validate_license() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) { return false; @@ -150,7 +158,7 @@ class phpbb_extension_metadata_manager */ private function validate_name() { - return preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name']); + return preg_match('#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', $this->metadata['name']); } /** @@ -160,7 +168,7 @@ class phpbb_extension_metadata_manager */ private function validate_type() { - return $this->metadata['type'] != 'phpbb3-extension'; + return $this->metadata['type'] == 'phpbb3-extension'; } /** @@ -170,7 +178,7 @@ class phpbb_extension_metadata_manager */ private function validate_description() { - return preg_match('^{10,}$', $this->metadata['description']); + return preg_match('#^{10,}$#', $this->metadata['description']); } /** @@ -180,7 +188,7 @@ class phpbb_extension_metadata_manager */ private function validate_version() { - return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}', $this->metadata['version']); + return preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}#', $this->metadata['version']); } /** @@ -201,7 +209,7 @@ class phpbb_extension_metadata_manager */ private function validate_require_phpbb() { - return (preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>'); + return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb'], '3.1.0', '>=')); } /** @@ -211,7 +219,7 @@ class phpbb_extension_metadata_manager */ private function validate_extra_display_name() { - return preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name']); + return preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); } /** @@ -234,7 +242,7 @@ class phpbb_extension_metadata_manager */ private function validate_require_php() { - return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb'] + return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['php']) && version_compare($this->metadata['require']['php'], phpversion(), '>=')); } /** @@ -255,7 +263,7 @@ class phpbb_extension_metadata_manager */ private function validate_homepage() { - return preg_match('([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']) + return preg_match('#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']); } /** @@ -287,19 +295,32 @@ class phpbb_extension_metadata_manager } /** - * Gets the contents of the composer.json file and can also assign template vars + * Gets the contents of the composer.json file * - * @return array Contains everything from the meta data file. Do not use without validating and cleaning first + * @return bool True of false (if loading succeeded or failed) */ private function fetch_metadata() { - // Read it - $metadata_file = file_get_contents($metadata_filepath); - $metadata = json_decode($metadata_file, true) - - $this->metadata = $metadata; - - return $metadata; + if (!file_exists($this->metadata_file)) + { + return false; + } + else + { + if (!($file_contents = file_get_contents($this->metadata_file))) + { + return false; + } + + if (($metadata = json_decode($file_contents, true)) === NULL) + { + return false; + } + + $this->metadata = $metadata; + + return true; + } } /** @@ -334,3 +355,4 @@ class phpbb_extension_metadata_manager return; } +} -- cgit v1.2.1 From bf6e91b5f3f6d56c1a38cbff0ccf206f13202e50 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 20:24:20 -0500 Subject: [ticket/10631] Fixing some more issues PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 35 ++++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index a9dcd89592..ddec918732 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -82,7 +82,7 @@ class phpbb_extension_metadata_manager if ($template_output) { - $this->output_template_data($template); + $this->output_template_data(); } return $this->metadata; @@ -138,7 +138,7 @@ class phpbb_extension_metadata_manager */ private function clean_metadata_array() { - if (!$this->validate_name() || !$this->validate_type() || !$this->validate_license() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + if (!$this->validate_name() || !$this->validate_type() || !$this->validate_licence() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) { return false; } @@ -178,7 +178,7 @@ class phpbb_extension_metadata_manager */ private function validate_description() { - return preg_match('#^{10,}$#', $this->metadata['description']); + return true;//preg_match('#^{10,}$#', $this->metadata['description']); } /** @@ -196,10 +196,10 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_license() + private function validate_licence() { // Nothing to validate except existence - return isset($this->metadata['version']); + return isset($this->metadata['licence']); } /** @@ -219,7 +219,7 @@ class phpbb_extension_metadata_manager */ private function validate_extra_display_name() { - return preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); + return true;//preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); } /** @@ -328,31 +328,32 @@ class phpbb_extension_metadata_manager * * @return null */ - public function output_template_data(phpbb_template $template) + public function output_template_data() { - $template->assign_vars(array( + + $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), - 'MD_HOMEPAGE' => $this->metadata['homepage'], + 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', 'MD_VERSION' => htmlspecialchars($this->metadata['version']), 'MD_TIME' => htmlspecialchars($this->metadata['time']), - 'MD_LICENSE' => htmlspecialchars($this->metadata['license']), - 'MD_REQUIRE_PHP' => htmlspecialchars($this->metadata['require']['php']), - 'MD_REQUIRE_PHPBB' => htmlspecialchars($this->metadata['require']['phpbb']), - 'MD_DISPLAY_NAME' => htmlspecialchars($this->metadata['extra']['display-name']), + 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), + 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); foreach ($this->metadata['authors'] as $author) { - $template->assign_block_vars('md_authors', array( + $this->template->assign_block_vars('md_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), 'AUTHOR_EMAIL' => $author['email'], - 'AUTHOR_HOMEPAGE' => $author['homepage'], - 'AUTHOR_ROLE' => htmlspecialchars($author['role']), + 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', + 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - + return; } } -- cgit v1.2.1 From 74492b3cdda9538263484a6f2a2042ac1900228a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 14:01:13 -0500 Subject: [ticket/10631] Use display name if available PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index ddec918732..6af02e47b7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -55,7 +55,7 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param boolean $template_output True if you want the requested metadata assigned to template vars + * @param boolean $template_output True if you want the requested metadata assigned to template vars (only works on the 'all" case * @return array Contains all of the requested metadata */ public function get_metadata($element = 'all', $template_output = false) @@ -89,20 +89,17 @@ class phpbb_extension_metadata_manager break; case 'name': - if ($this->validate_name()) + return ($this->validate_name()) ? $this->metadata['name'] : false; + break; + + case 'display-name': + if ($this->validate_extra_display_name()) { - if ($template_output) - { - $template->assign_vars(array( - 'MD_NAME' => htmlspecialchars($this->metadata['name']), - )); - } - - return $this->metadata['name']; + return $this->metadata['extra']['display-name']; } else { - return false; + return ($this->validate_name()) ? $this->metadata['name'] : false; } break; // TODO: Add remaining cases as needed -- cgit v1.2.1 From 8bbab088dd5830d8dd1151a3684dde5c197ba268 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:17:42 -0500 Subject: [ticket/10631] Validation for extensions PHPBB3-10631 --- phpBB/includes/extension/manager.php | 7 +- phpBB/includes/extension/metadata_manager.php | 298 ++++++++++++++++---------- 2 files changed, 184 insertions(+), 121 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index e7ceef6ad5..9dfc0a067c 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -23,6 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_extension_manager { protected $db; + protected $config; protected $cache; protected $php_ext; protected $extensions; @@ -34,16 +35,18 @@ class phpbb_extension_manager * Creates a manager and loads information from database * * @param dbal $db A database connection + * @param phpbb_config $config phpbb_config * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(dbal $db, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(dbal $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; + $this->config = $config; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -130,7 +133,7 @@ class phpbb_extension_manager */ public function get_extension_metadata($name, phpbb_template $template) { - return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->phpEx, $template); + return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } /** diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 6af02e47b7..0e0b609a68 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -31,18 +31,71 @@ class phpbb_extension_metadata_manager public $metadata; protected $metadata_file; + /** + * Array of validation regular expressions, see __call() + * + * @var mixed + */ + protected $validation = array( + 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', + 'type' => '#^phpbb3-extension$#', + 'description' => '#.*#', + 'version' => '#.+#', + 'licence' => '#.+#', + 'extra' => array( + 'display-name' => '#.*#', + ), + ); + + /** + * Magic method to catch validation calls + * + * @param string $name + * @param mixed $arguments + * @return int + */ + public function __call($name, $arguments) + { + // Validation Magic methods + if (strpos($name, 'validate_') === 0) + { + // Remove validate_ + $name = substr($name, 9); + + // Replace underscores with dashes (underscores are not used) + $name = str_replace('_', '-', $name); + + if (strpos($name, 'extra-') === 0) + { + // Remove extra_ + $name = substr($name, 6); + + if (isset($this->validation['extra'][$name])) + { + // Extra means it's optional, so return true if it does not exist + return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; + } + } + else if (isset($this->validation[$name])) + { + return preg_match($this->validation[$name], $this->metadata[$name]); + } + } + } + /** * Creates the metadata manager - * + * * @param dbal $db A database connection * @param string $extension_manager An instance of the phpbb extension manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; + $this->config = $config; $this->phpEx = $phpEx; $this->template = $template; $this->extension_manager = $extension_manager; @@ -53,12 +106,11 @@ class phpbb_extension_metadata_manager /** * Processes and gets the metadata requested - * - * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param boolean $template_output True if you want the requested metadata assigned to template vars (only works on the 'all" case - * @return array Contains all of the requested metadata + * + * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. + * @return bool|array Contains all of the requested metadata or bool False if not valid */ - public function get_metadata($element = 'all', $template_output = false) + public function get_metadata($element = 'all') { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -66,34 +118,37 @@ class phpbb_extension_metadata_manager return false; } + // Fetch the metadata if (!$this->fetch_metadata()) { return false; } - switch ($element) + // Clean the metadata + if (!$this->clean_metadata_array()) + { + return false; + } + + switch ($element) { case 'all': default: - if (!$this->clean_metadata_array()) + // Validate the metadata + if (!$this->validate_metadata_array()) { return false; } - if ($template_output) - { - $this->output_template_data(); - } - return $this->metadata; break; - + case 'name': return ($this->validate_name()) ? $this->metadata['name'] : false; break; - + case 'display-name': - if ($this->validate_extra_display_name()) + if (isset($this->metadata['extra']['display-name']) && $this->validate_extra_display_name()) { return $this->metadata['extra']['display-name']; } @@ -108,7 +163,7 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file - * + * * @return boolean Set to true if it exists */ private function set_metadata_file() @@ -129,122 +184,156 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation and cleaning of the array - * - * @return array Contains the cleaned and validated metadata array + * Gets the contents of the composer.json file + * + * @return bool True of false (if loading succeeded or failed) */ - private function clean_metadata_array() - { - if (!$this->validate_name() || !$this->validate_type() || !$this->validate_licence() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + private function fetch_metadata() + { + if (!file_exists($this->metadata_file)) { return false; } - - $this->check_for_optional(true); + else + { + if (!($file_contents = file_get_contents($this->metadata_file))) + { + return false; + } -// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors -// $this->metadata = $metadata_finished; + if (($metadata = json_decode($file_contents, true)) === NULL) + { + return false; + } - return $this->metadata; - } + $this->metadata = $metadata; - /** - * Validates the contents of the name field - * - * @return boolean True when passes validation - */ - private function validate_name() - { - return preg_match('#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', $this->metadata['name']); + return true; + } } /** - * Validates the contents of the type field - * - * @return boolean True when passes validation + * This array handles the validation and cleaning of the array + * + * @return array Contains the cleaned and validated metadata array */ - private function validate_type() + private function clean_metadata_array() { - return $this->metadata['type'] == 'phpbb3-extension'; - } +// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors +// $this->metadata = $metadata_finished; - /** - * Validates the contents of the description field - * - * @return boolean True when passes validation - */ - private function validate_description() - { - return true;//preg_match('#^{10,}$#', $this->metadata['description']); + return $this->metadata; } /** - * Validates the contents of the version field - * - * @return boolean True when passes validation + * This array handles the validation of strings + * + * @return bool True if validation succeeded, False if failed */ - private function validate_version() + public function validate_metadata_array() { - return preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}#', $this->metadata['version']); + $validate = array( + 'name', + 'type', + 'licence', + 'description', + 'version', + 'extra_display-name', + ); + + foreach ($validate as $type) + { + $type = 'validate_' . $type; + + if (!$this->$type()) + { + return false; + } + } + + return true; } /** - * Validates the contents of the license field - * - * @return boolean True when passes validation + * This array handles the verification that this extension can be enabled on this board + * + * @return bool True if validation succeeded, False if failed */ - private function validate_licence() + public function validate_enable() { - // Nothing to validate except existence - return isset($this->metadata['licence']); + $validate = array( + 'require_phpbb', + 'require_php', + ); + + foreach ($validate as $type) + { + $type = 'validate_' . $type; + + if (!$this->$type()) + { + return false; + } + } + + return true; } + /** * Validates the contents of the phpbb requirement field - * + * * @return boolean True when passes validation */ private function validate_require_phpbb() { - return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb'], '3.1.0', '>=')); + if (!isset($this->metadata['require']['phpbb'])) + { + return true; + } + + return $this->_validate_version($this->metadata['require']['phpbb'], $this->config['version']); } /** - * Validates the contents of the display name field - * + * Validates the contents of the php requirement field + * * @return boolean True when passes validation */ - private function validate_extra_display_name() + private function validate_require_php() { - return true;//preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); + if (!isset($this->metadata['require']['php'])) + { + return true; + } + + return $this->_validate_version($this->metadata['require']['php'], phpversion()); } /** - * Checks which optional fields exist - * - * @return boolean False if any that exist fail validation, otherwise true. - */ - public function check_for_optional() + * Version validation helper + * + * @param string $string The string for comparing to a version + * @param string $current_version The version to compare to + * @return bool True/False if meets version requirements + */ + private function _validate_version($string, $current_version) { - if ((isset($this->metadata['require']['php']) && !$this->validate_require_php()) || (isset($this->metadata['time']) && !$this->validate_time()) || (isset($this->metadata['validate_homepage']) && !$this->validate_homepage())) + // Allow them to specify their own comparison operator (ex: <3.1.2, >=3.1.0) + $comparison_matches = false; + preg_match('#[=<>]+#', $string, $comparison_matches); + + if (!empty($comparison_matches)) { - return false; + return version_compare($current_version, str_replace(array($comparison_matches[0], ' '), '', $string), $comparison_matches[0]); } - } - /** - * Validates the contents of the php requirement field - * - * @return boolean True when passes validation - */ - private function validate_require_php() - { - return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['php']) && version_compare($this->metadata['require']['php'], phpversion(), '>=')); + return version_compare($current_version, $string, '>='); } /** * Validates the contents of the time field - * + * * @return boolean True when passes validation */ private function validate_time() @@ -255,7 +344,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the homepage field - * + * * @return boolean True when passes validation */ private function validate_homepage() @@ -265,7 +354,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the authors field - * + * * @return boolean True when passes validation */ private function validate_authors() @@ -291,38 +380,9 @@ class phpbb_extension_metadata_manager return true; } - /** - * Gets the contents of the composer.json file - * - * @return bool True of false (if loading succeeded or failed) - */ - private function fetch_metadata() - { - if (!file_exists($this->metadata_file)) - { - return false; - } - else - { - if (!($file_contents = file_get_contents($this->metadata_file))) - { - return false; - } - - if (($metadata = json_decode($file_contents, true)) === NULL) - { - return false; - } - - $this->metadata = $metadata; - - return true; - } - } - /** * Outputs the metadata into the template - * + * * @return null */ public function output_template_data() @@ -350,7 +410,7 @@ class phpbb_extension_metadata_manager 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - + return; } } -- cgit v1.2.1 From 4314284de12ceac5ae0792f3f4014b765d75d332 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:22:48 -0500 Subject: [ticket/10631] Remove code duplication PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 33 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 0e0b609a68..c5e9baf1e7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -232,22 +232,29 @@ class phpbb_extension_metadata_manager */ public function validate_metadata_array() { - $validate = array( - 'name', - 'type', - 'licence', - 'description', - 'version', - 'extra_display-name', - ); - - foreach ($validate as $type) + foreach ($this->validation as $name => $regex) { - $type = 'validate_' . $type; + if (is_array($regex)) + { + foreach ($regex as $extra_name => $extra_regex) + { + $type = 'validate_' . $name . '_' . $extra_name; - if (!$this->$type()) + if (!$this->$type()) + { + return false; + } + } + } + else { - return false; + + $type = 'validate_' . $name; + + if (!$this->$type()) + { + return false; + } } } -- cgit v1.2.1 From 8df9963fcc7e2962b6b4e1e32e809f2d8fe00835 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:39:13 -0500 Subject: [ticket/10631] Additional validation PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 76 +++++++++------------------ 1 file changed, 25 insertions(+), 51 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index c5e9baf1e7..d2dc72e5fc 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -42,6 +42,7 @@ class phpbb_extension_metadata_manager 'description' => '#.*#', 'version' => '#.+#', 'licence' => '#.+#', + //'homepage' => '#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(? array( 'display-name' => '#.*#', ), @@ -76,7 +77,7 @@ class phpbb_extension_metadata_manager return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; } } - else if (isset($this->validation[$name])) + else if (isset($this->validation[$name]) && isset($this->metadata[$name])) { return preg_match($this->validation[$name], $this->metadata[$name]); } @@ -258,6 +259,29 @@ class phpbb_extension_metadata_manager } } + return $this->validate_authors(); + } + + /** + * Validates the contents of the authors field + * + * @return boolean True when passes validation + */ + private function validate_authors() + { + if (empty($this->metadata['authors'])) + { + return false; + } + + foreach ($this->metadata['authors'] as $author) + { + if (!isset($author['name'])) + { + return false; + } + } + return true; } @@ -338,55 +362,6 @@ class phpbb_extension_metadata_manager return version_compare($current_version, $string, '>='); } - /** - * Validates the contents of the time field - * - * @return boolean True when passes validation - */ - private function validate_time() - { - // Need to validate - return true; - } - - /** - * Validates the contents of the homepage field - * - * @return boolean True when passes validation - */ - private function validate_homepage() - { - return preg_match('#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']); - } - - /** - * Validates the contents of the authors field - * - * @return boolean True when passes validation - */ - private function validate_authors() - { - // Need to validate - $number_authors = sizeof($this->metadata['authors']); // Might be helpful later on - - if (!isset($this->metadata['authors']['1'])) - { - return false; - } - else - { - foreach ($this->metadata['authors'] as $author) - { - if (!isset($author['name'])) - { - return false; - } - } - } - - return true; - } - /** * Outputs the metadata into the template * @@ -394,7 +369,6 @@ class phpbb_extension_metadata_manager */ public function output_template_data() { - $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), -- cgit v1.2.1 From 106c105113886f9a9e603dbb11549c06049b255f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 18:22:35 -0500 Subject: [ticket/10631] Fix some issues as noted in github comments, significantly simplified validation PHPBB3-10631 --- phpBB/includes/extension/manager.php | 2 +- phpBB/includes/extension/metadata_manager.php | 144 ++++++++------------------ 2 files changed, 44 insertions(+), 102 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 9dfc0a067c..9342c936f9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -131,7 +131,7 @@ class phpbb_extension_manager * @param string $template The template manager * @return phpbb_extension_metadata_manager Instance of the metadata manager */ - public function get_extension_metadata($name, phpbb_template $template) + public function get_extension_metadata_manager($name, phpbb_template $template) { return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index d2dc72e5fc..aa163b1190 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -28,62 +28,9 @@ class phpbb_extension_metadata_manager protected $phpbb_root_path; protected $template; protected $ext_name; - public $metadata; + protected $metadata; protected $metadata_file; - /** - * Array of validation regular expressions, see __call() - * - * @var mixed - */ - protected $validation = array( - 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', - 'type' => '#^phpbb3-extension$#', - 'description' => '#.*#', - 'version' => '#.+#', - 'licence' => '#.+#', - //'homepage' => '#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(? array( - 'display-name' => '#.*#', - ), - ); - - /** - * Magic method to catch validation calls - * - * @param string $name - * @param mixed $arguments - * @return int - */ - public function __call($name, $arguments) - { - // Validation Magic methods - if (strpos($name, 'validate_') === 0) - { - // Remove validate_ - $name = substr($name, 9); - - // Replace underscores with dashes (underscores are not used) - $name = str_replace('_', '-', $name); - - if (strpos($name, 'extra-') === 0) - { - // Remove extra_ - $name = substr($name, 6); - - if (isset($this->validation['extra'][$name])) - { - // Extra means it's optional, so return true if it does not exist - return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; - } - } - else if (isset($this->validation[$name]) && isset($this->metadata[$name])) - { - return preg_match($this->validation[$name], $this->metadata[$name]); - } - } - } - /** * Creates the metadata manager * @@ -136,7 +83,7 @@ class phpbb_extension_metadata_manager case 'all': default: // Validate the metadata - if (!$this->validate_metadata_array()) + if (!$this->validate()) { return false; } @@ -145,17 +92,17 @@ class phpbb_extension_metadata_manager break; case 'name': - return ($this->validate_name()) ? $this->metadata['name'] : false; + return ($this->validate('name')) ? $this->metadata['name'] : false; break; case 'display-name': - if (isset($this->metadata['extra']['display-name']) && $this->validate_extra_display_name()) + if (isset($this->metadata['extra']['display-name'])) { return $this->metadata['extra']['display-name']; } else { - return ($this->validate_name()) ? $this->metadata['name'] : false; + return ($this->validate('name')) ? $this->metadata['name'] : false; } break; // TODO: Add remaining cases as needed @@ -216,7 +163,7 @@ class phpbb_extension_metadata_manager /** * This array handles the validation and cleaning of the array * - * @return array Contains the cleaned and validated metadata array + * @return array Contains the cleaned metadata array */ private function clean_metadata_array() { @@ -227,40 +174,44 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation of strings - * - * @return bool True if validation succeeded, False if failed - */ - public function validate_metadata_array() - { - foreach ($this->validation as $name => $regex) - { - if (is_array($regex)) - { - foreach ($regex as $extra_name => $extra_regex) - { - $type = 'validate_' . $name . '_' . $extra_name; + * Validate fields + * + * @param string $name ("all" for display and enable validation + * "display" for name, type, and authors + * "name", "type") + * @return Bool False if validation fails, true if valid + */ + public function validate($name = 'display') + { + // Basic fields + $fields = array( + 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', + 'type' => '#^phpbb3-extension$#', + 'licence' => '#.+#', + 'version' => '#.+#', + ); + + if (isset($fields[$name])) + { + return (isset($this->metadata[$name])) ? (bool) preg_match($this->validation[$name], $this->metadata[$name]) : false; + } - if (!$this->$type()) - { - return false; - } - } - } - else + // Validate all fields + if ($name == 'all') + { + foreach ($fields as $field => $data) { - - $type = 'validate_' . $name; - - if (!$this->$type()) + if (!$this->validate($field)) { return false; } } + + return $this->validate_authors(); } - return $this->validate_authors(); - } + return true; + } /** * Validates the contents of the authors field @@ -292,19 +243,10 @@ class phpbb_extension_metadata_manager */ public function validate_enable() { - $validate = array( - 'require_phpbb', - 'require_php', - ); - - foreach ($validate as $type) + // Check for phpBB, PHP versions + if (!$this->validate_require_phpbb || !$this->validate_require_php) { - $type = 'validate_' . $type; - - if (!$this->$type()) - { - return false; - } + return false; } return true; @@ -372,10 +314,10 @@ class phpbb_extension_metadata_manager $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), - 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), + 'MD_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', - 'MD_VERSION' => htmlspecialchars($this->metadata['version']), - 'MD_TIME' => htmlspecialchars($this->metadata['time']), + 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', + 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', @@ -386,7 +328,7 @@ class phpbb_extension_metadata_manager { $this->template->assign_block_vars('md_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), - 'AUTHOR_EMAIL' => $author['email'], + 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); -- cgit v1.2.1 From 89f4cf6a8c10f9b0875cf7f278016aff67eb38fc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 19:46:21 -0500 Subject: [ticket/10631] Use exceptions for errors. Build action list dynamically. PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 72 +++++++++++++-------------- 1 file changed, 36 insertions(+), 36 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index aa163b1190..126331ce1c 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -56,27 +56,18 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @return bool|array Contains all of the requested metadata or bool False if not valid + * @return array Contains all of the requested metadata, throws an exception on failure */ public function get_metadata($element = 'all') { // TODO: Check ext_name exists and is an extension that exists - if (!$this->set_metadata_file()) - { - return false; - } + $this->set_metadata_file(); // Fetch the metadata - if (!$this->fetch_metadata()) - { - return false; - } + $this->fetch_metadata(); // Clean the metadata - if (!$this->clean_metadata_array()) - { - return false; - } + $this->clean_metadata_array(); switch ($element) { @@ -112,46 +103,42 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file * - * @return boolean Set to true if it exists + * @return boolean Set to true if it exists, throws an exception on failure */ private function set_metadata_file() { $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); - $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; + $metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json'; $this->metadata_file = $metadata_filepath; if (!file_exists($this->metadata_file)) { - return false; - } - else - { - return true; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); } } /** * Gets the contents of the composer.json file * - * @return bool True of false (if loading succeeded or failed) + * @return bool True if success, throws an exception on failure */ private function fetch_metadata() { if (!file_exists($this->metadata_file)) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); } $this->metadata = $metadata; @@ -161,7 +148,7 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation and cleaning of the array + * This array handles the cleaning of the array * * @return array Contains the cleaned metadata array */ @@ -179,7 +166,7 @@ class phpbb_extension_metadata_manager * @param string $name ("all" for display and enable validation * "display" for name, type, and authors * "name", "type") - * @return Bool False if validation fails, true if valid + * @return Bool True if valid, throws an exception if invalid */ public function validate($name = 'display') { @@ -193,21 +180,34 @@ class phpbb_extension_metadata_manager if (isset($fields[$name])) { - return (isset($this->metadata[$name])) ? (bool) preg_match($this->validation[$name], $this->metadata[$name]) : false; + if (!isset($this->metadata[$name])) + { + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + } + + if (!preg_match($fields[$name], $this->metadata[$name])) + { + throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + } } // Validate all fields if ($name == 'all') + { + $this->validate('display'); + + $this->validate_enable(); + } + + // Validate display fields + if ($name == 'display') { foreach ($fields as $field => $data) { - if (!$this->validate($field)) - { - return false; - } + $this->validate($field); } - return $this->validate_authors(); + $this->validate_authors(); } return true; @@ -216,20 +216,20 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the authors field * - * @return boolean True when passes validation + * @return boolean True when passes validation, throws exception if invalid */ private function validate_authors() { if (empty($this->metadata['authors'])) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); } } @@ -244,7 +244,7 @@ class phpbb_extension_metadata_manager public function validate_enable() { // Check for phpBB, PHP versions - if (!$this->validate_require_phpbb || !$this->validate_require_php) + if (!$this->validate_require_phpbb() || !$this->validate_require_php()) { return false; } -- cgit v1.2.1 From 2a7e1292919ed1397a3f1951e510d84565d002d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:28:04 -0500 Subject: [ticket/10631] Simplify exceptions PHPBB-10631 --- phpBB/includes/extension/exception.php | 27 +++++++++++++++++++++++++++ phpBB/includes/extension/metadata_manager.php | 16 ++++++++-------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 phpBB/includes/extension/exception.php (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/exception.php b/phpBB/includes/extension/exception.php new file mode 100644 index 0000000000..e08a8912ea --- /dev/null +++ b/phpBB/includes/extension/exception.php @@ -0,0 +1,27 @@ +getMessage(); + } +} \ No newline at end of file diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 126331ce1c..27b04d4c08 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -114,7 +114,7 @@ class phpbb_extension_metadata_manager if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } } @@ -127,18 +127,18 @@ class phpbb_extension_metadata_manager { if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); + throw new phpbb_extension_exception('file_get_contents failed on ' . $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); + throw new phpbb_extension_exception('json_decode failed on ' . $this->metadata_file); } $this->metadata = $metadata; @@ -182,12 +182,12 @@ class phpbb_extension_metadata_manager { if (!isset($this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); } if (!preg_match($fields[$name], $this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + throw new phpbb_extension_exception("Meta field '$name' is invalid."); } } @@ -222,14 +222,14 @@ class phpbb_extension_metadata_manager { if (empty($this->metadata['authors'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); + throw new phpbb_extension_exception("Required meta field 'authors' has not been set."); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); + throw new phpbb_extension_exception("Required meta field 'author name' has not been set."); } } -- cgit v1.2.1 From 747c16240fd56be0e24b4c54f01c82aa0a78b91e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:40:54 -0500 Subject: [ticket/10631] get_extension_metadata_manager -> create_extension_metadata_manager PHPBB3-10631 --- phpBB/includes/extension/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 9342c936f9..9a518c215f 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -131,7 +131,7 @@ class phpbb_extension_manager * @param string $template The template manager * @return phpbb_extension_metadata_manager Instance of the metadata manager */ - public function get_extension_metadata_manager($name, phpbb_template $template) + public function create_extension_metadata_manager($name, phpbb_template $template) { return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } -- cgit v1.2.1 From 500879520c40a71f0b83799ab3e59c86c12a801a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 28 Jul 2012 14:59:55 -0500 Subject: [ticket/10631] Metadata manager tests PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 59 ++++++++++++++------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 27b04d4c08..c7f52b7c02 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -178,36 +178,37 @@ class phpbb_extension_metadata_manager 'version' => '#.+#', ); - if (isset($fields[$name])) + switch ($name) { - if (!isset($this->metadata[$name])) - { - throw new phpbb_extension_exception("Required meta field '$name' has not been set."); - } - - if (!preg_match($fields[$name], $this->metadata[$name])) - { - throw new phpbb_extension_exception("Meta field '$name' is invalid."); - } - } - - // Validate all fields - if ($name == 'all') - { - $this->validate('display'); + case 'all': + $this->validate('display'); - $this->validate_enable(); - } + $this->validate_enable(); + break; - // Validate display fields - if ($name == 'display') - { - foreach ($fields as $field => $data) - { - $this->validate($field); - } + case 'display': + foreach ($fields as $field => $data) + { + $this->validate($field); + } - $this->validate_authors(); + $this->validate_authors(); + break; + + default: + if (isset($fields[$name])) + { + if (!isset($this->metadata[$name])) + { + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); + } + + if (!preg_match($fields[$name], $this->metadata[$name])) + { + throw new phpbb_extension_exception("Meta field '$name' is invalid."); + } + } + break; } return true; @@ -218,7 +219,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation, throws exception if invalid */ - private function validate_authors() + public function validate_authors() { if (empty($this->metadata['authors'])) { @@ -258,7 +259,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_require_phpbb() + public function validate_require_phpbb() { if (!isset($this->metadata['require']['phpbb'])) { @@ -273,7 +274,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_require_php() + public function validate_require_php() { if (!isset($this->metadata['require']['php'])) { -- cgit v1.2.1 From 7b643fe8a5fd3b92bb4db9eacb27645417004709 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 5 Aug 2012 19:00:20 -0500 Subject: [ticket/10631] Make failure to meet ext enable requirements clearer Turn the blocks red on the details page if requirement is not met. Also changing a how the errors come up when trying to enable/disable an extension when they cannot be. PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index c7f52b7c02..8a68e464a7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -320,8 +320,13 @@ class phpbb_extension_metadata_manager 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), - 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', - 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + + 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'MD_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), + + 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'MD_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), + 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); -- cgit v1.2.1 From 323bbf9b523984a592dc17bf35d2bb91a435be1b Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:06:23 +0100 Subject: [ticket/10631] Adjust prefixes to be easier to understand PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 8a68e464a7..1e3bbe48c9 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -313,26 +313,26 @@ class phpbb_extension_metadata_manager public function output_template_data() { $this->template->assign_vars(array( - 'MD_NAME' => htmlspecialchars($this->metadata['name']), - 'MD_TYPE' => htmlspecialchars($this->metadata['type']), - 'MD_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', - 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', - 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', - 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', - 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), + 'META_NAME' => htmlspecialchars($this->metadata['name']), + 'META_TYPE' => htmlspecialchars($this->metadata['type']), + 'META_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', + 'META_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', + 'META_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', + 'META_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', + 'META_LICENCE' => htmlspecialchars($this->metadata['licence']), - 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', - 'MD_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), + 'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), - 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', - 'MD_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), + 'META_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'META_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), - 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', + 'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); foreach ($this->metadata['authors'] as $author) { - $this->template->assign_block_vars('md_authors', array( + $this->template->assign_block_vars('meta_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', -- cgit v1.2.1 From f05a175e3955d1dc1d2b85b9929ca4b30340ad4a Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:38:03 +0100 Subject: [ticket/10631] Fixing a few extension admin issues PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 1e3bbe48c9..8c570830fe 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -60,7 +60,6 @@ class phpbb_extension_metadata_manager */ public function get_metadata($element = 'all') { - // TODO: Check ext_name exists and is an extension that exists $this->set_metadata_file(); // Fetch the metadata @@ -339,7 +338,5 @@ class phpbb_extension_metadata_manager 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - - return; } } -- cgit v1.2.1 From 81f7f28cc33d896973c2912097103ea84fa14114 Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Sat, 1 Sep 2012 21:30:35 +0100 Subject: [ticket/10631] Removing un-needed TODOs that are no longer needed. PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 8c570830fe..ea85bd3c4e 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -95,7 +95,6 @@ class phpbb_extension_metadata_manager return ($this->validate('name')) ? $this->metadata['name'] : false; } break; - // TODO: Add remaining cases as needed } } @@ -153,9 +152,6 @@ class phpbb_extension_metadata_manager */ private function clean_metadata_array() { -// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors -// $this->metadata = $metadata_finished; - return $this->metadata; } -- cgit v1.2.1 From d7a626c70bdfd7aea5e10ec891230cbd2e94f862 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 25 Jun 2012 23:27:08 -0400 Subject: [ticket/10933] Expanded prose documentation for phpbb_extension_provider. PHPBB3-10933 --- phpBB/includes/extension/provider.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/extension') diff --git a/phpBB/includes/extension/provider.php b/phpBB/includes/extension/provider.php index d0541fa007..45b55e5cab 100644 --- a/phpBB/includes/extension/provider.php +++ b/phpBB/includes/extension/provider.php @@ -16,7 +16,15 @@ if (!defined('IN_PHPBB')) } /** -* Provides a set of items found in extensions +* Provides a set of items found in extensions. +* +* This abstract class is essentially a wrapper around item-specific +* finding logic. It handles storing the extension manager via constructor +* for the finding logic to use to find the items, and provides an +* iterator interface over the items found by the finding logic. +* +* Items could be anything, for example template paths or cron task names. +* Derived classes completely define what the items are. * * @package extension */ @@ -45,7 +53,7 @@ abstract class phpbb_extension_provider implements IteratorAggregate } /** - * Finds template paths using the extension manager. + * Finds items using the extension manager. * * @return array List of task names */ -- cgit v1.2.1