aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/hook
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2013-01-04 10:49:57 +0100
committerMarc Alexander <admin@m-a-styles.de>2013-01-04 10:49:57 +0100
commit5d091e2d8f5079a8ce8dc14500c29f6642c40e98 (patch)
treef4c73527be7e6f5e783351edc306e929a8946b31 /phpBB/includes/hook
parent4a8b1a6e050bba7f8f73f689bbca4185ab27cf8c (diff)
parent228580b6743b9650996284dd04a3f5de6c2447ca (diff)
downloadforums-5d091e2d8f5079a8ce8dc14500c29f6642c40e98.tar
forums-5d091e2d8f5079a8ce8dc14500c29f6642c40e98.tar.gz
forums-5d091e2d8f5079a8ce8dc14500c29f6642c40e98.tar.bz2
forums-5d091e2d8f5079a8ce8dc14500c29f6642c40e98.tar.xz
forums-5d091e2d8f5079a8ce8dc14500c29f6642c40e98.zip
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into feature/avatars
Conflicts: phpBB/includes/ucp/ucp_groups.php
Diffstat (limited to 'phpBB/includes/hook')
-rw-r--r--phpBB/includes/hook/finder.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/phpBB/includes/hook/finder.php b/phpBB/includes/hook/finder.php
new file mode 100644
index 0000000000..065e685514
--- /dev/null
+++ b/phpBB/includes/hook/finder.php
@@ -0,0 +1,84 @@
+<?php
+/**
+*
+* @package extension
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* The hook finder locates installed hooks.
+*
+* @package phpBB3
+*/
+class phpbb_hook_finder
+{
+ protected $phpbb_root_path;
+ protected $cache;
+ protected $php_ext;
+
+ /**
+ * Creates a new finder instance.
+ *
+ * @param string $phpbb_root_path Path to the phpbb root directory
+ * @param string $php_ext php file extension
+ * @param phpbb_cache_driver_interface $cache A cache instance or null
+ */
+ public function __construct($phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null)
+ {
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->cache = $cache;
+ $this->php_ext = $php_ext;
+ }
+
+ /**
+ * Finds all hook files.
+ *
+ * @param bool $cache Whether the result should be cached
+ * @return array An array of paths to found hook files
+ */
+ public function find($cache = true)
+ {
+ if (!defined('DEBUG') && $cache && $this->cache)
+ {
+ $hook_files = $this->cache->get('_hooks');
+ if ($hook_files !== false)
+ {
+ return $hook_files;
+ }
+ }
+
+ $hook_files = array();
+
+ // Now search for hooks...
+ $dh = @opendir($this->phpbb_root_path . 'includes/hooks/');
+
+ if ($dh)
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($this->php_ext) + 1)) === '.' . $this->php_ext)
+ {
+ $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1));
+ }
+ }
+ closedir($dh);
+ }
+
+ if ($cache && $this->cache)
+ {
+ $this->cache->put('_hooks', $hook_files);
+ }
+
+ return $hook_files;
+ }
+}