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_template.php |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 455bbcf..3825080 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -287,6 +287,11 @@
     public function send($templ = null, $exit = true)
     {
         if ($templ != 'iframe') {
+            // prevent from endless loops
+            if ($this->app->plugins->is_processing('render_page')) {
+                raise_error(array('code' => 505, 'type' => 'php', 'message' => 'Recursion alert: ignoring output->send()'), true, false);
+                return;
+            }
             $this->parse($templ, false);
         }
         else {
@@ -294,6 +299,10 @@
             $this->write();
         }
 
+        // set output asap
+        ob_flush();
+        flush();
+        
         if ($exit) {
             exit;
         }
@@ -371,6 +380,9 @@
         // parse for specialtags
         $output = $this->parse_conditions($templ);
         $output = $this->parse_xml($output);
+        
+        // trigger generic hook where plugins can put additional content to the page
+        $hook = $this->app->plugins->exec_hook("render_page", array('template' => $name, 'content' => $output));
 
         // add debug console
         if ($this->config['debug_level'] & 8) {
@@ -379,7 +391,8 @@
                 <form action="/" name="debugform" style="display:inline"><textarea name="console" id="dbgconsole" rows="20" cols="40" wrap="off" style="display:none;width:400px;border:none;font-size:x-small" spellcheck="false"></textarea></form></div>'
             );
         }
-        $output = $this->parse_with_globals($output);
+        
+        $output = $this->parse_with_globals($hook['content']);
         $this->write(trim($output));
         if ($exit) {
             exit;

--
Gitblit v1.9.1