From a366a323b5d78f453b4988be576e6520957c9488 Mon Sep 17 00:00:00 2001 From: thomascube <thomas@roundcube.net> Date: Mon, 13 Jul 2009 14:52:15 -0400 Subject: [PATCH] Prevent from endless loops in render_page hook --- program/include/rcube_plugin_api.php | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/program/include/rcube_plugin_api.php b/program/include/rcube_plugin_api.php index 588f35e..b05758a 100644 --- a/program/include/rcube_plugin_api.php +++ b/program/include/rcube_plugin_api.php @@ -39,7 +39,8 @@ private $objectsmap = array(); private $template_contents = array(); - private $required_plugins = array('filesystem_attachments'); + private $required_plugins = array('filesystem_attachments'); + private $active_hook = false; /** * This implements the 'singleton' design pattern @@ -61,8 +62,7 @@ */ private function __construct() { - $rcmail = rcmail::get_instance(); - $this->dir = realpath($rcmail->config->get('plugins_dir')); + $this->dir = INSTALL_PATH . $this->url; } @@ -90,7 +90,7 @@ if (class_exists($plugin_name, false)) { $plugin = new $plugin_name($this); // check inheritance and task specification - if (is_subclass_of($plugin, 'rcube_plugin') && (!$plugin->task || $plugin->task == $rcmail->task)) { + if (is_subclass_of($plugin, 'rcube_plugin') && (!$plugin->task || preg_match('/('.$plugin->task.')/i', $rcmail->task))) { $plugin->init(); $this->plugins[] = $plugin; } @@ -180,6 +180,7 @@ public function exec_hook($hook, $args = array()) { $args += array('abort' => false); + $this->active_hook = $hook; foreach ((array)$this->handlers[$hook] as $callback) { $ret = call_user_func($callback, $args); @@ -190,6 +191,7 @@ break; } + $this->active_hook = false; return $args; } @@ -258,13 +260,26 @@ } } + + /** + * Check if a plugin hook is currently processing. + * Mainly used to prevent loops and recursion. + * + * @param string Hook to check (optional) + * @return boolean True if any/the given hook is currently processed, otherwise false + */ + public function is_processing($hook = null) + { + return $this->active_hook && (!$hook || $this->active_hook == $hook); + } + /** * Include a plugin script file in the current HTML page */ public function include_script($fn) { if ($this->output->type == 'html') { - $src = $this->ressource_url($fn); + $src = $this->resource_url($fn); $this->output->add_header(html::tag('script', array('type' => "text/javascript", 'src' => $src))); } } @@ -275,7 +290,7 @@ public function include_stylesheet($fn) { if ($this->output->type == 'html') { - $src = $this->ressource_url($fn); + $src = $this->resource_url($fn); $this->output->add_header(html::tag('link', array('rel' => "stylesheet", 'type' => "text/css", 'href' => $src))); } } @@ -294,13 +309,13 @@ private function template_container_hook($attrib) { $container = $attrib['name']; - return array('content' => $this->template_contents[$container]); + return array('content' => $attrib['content'] . $this->template_contents[$container]); } /** * Make the given file name link into the plugins directory */ - private function ressource_url($fn) + private function resource_url($fn) { if ($fn[0] != '/' && !preg_match('|^https?://|i', $fn)) return $this->url . $fn; -- Gitblit v1.9.1