From 5eee009671d773cb3ebef5beca6ad47c919ac4c7 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Wed, 19 Sep 2007 02:29:28 -0400
Subject: [PATCH] Allow vars and PHP code in templates; improved page title; fixed #1484395

---
 program/include/rcmail_template.inc |   66 +++++++++++++++++++++++++++++++--
 1 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/program/include/rcmail_template.inc b/program/include/rcmail_template.inc
index 4acc717..734032e 100644
--- a/program/include/rcmail_template.inc
+++ b/program/include/rcmail_template.inc
@@ -322,6 +322,13 @@
         join(',', $args));
     }
     
+    // add command to set page title
+    if ($this->ajax_call && !empty($this->pagetitle))
+      $out .= sprintf(
+        "this.set_pagetitle('%s');\n",
+        JQ((!empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : '') . $this->pagetitle)
+      );
+    
     return $out;
   }
   
@@ -453,10 +460,15 @@
       // include a file 
       case 'include':
         $path = realpath($this->config['skin_path'].$attrib['file']);
-        if (filesize($path) && ($fp = @fopen($path, 'r')))
+        if (filesize($path))
         {
-          $incl = fread($fp, filesize($path));
-          fclose($fp);        
+          if ($this->config['skin_include_php'])
+            $incl = $this->include_php($path);
+          else if ($fp = @fopen($path, 'r'))
+          {
+            $incl = fread($fp, filesize($path));
+            fclose($fp);
+          }
           return $this->parse_xml($incl);
         }
         break;
@@ -494,13 +506,59 @@
         }
 
         break;
-      }
+      
+      // return variable
+      case 'var':
+        $var = explode(':', $attrib['name']);
+        $name = $var[1];
+        $value = '';
+        
+        switch ($var[0])
+        {
+          case 'env':
+            $value = $this->env[$name];
+            break;
+          case 'config':
+            $value = $this->config[$name];
+            if (is_array($value) && $value[$_SESSION['imap_host']])
+              $value = $value[$_SESSION['imap_host']];
+            break;
+          case 'request':
+            $value = get_input_value($name, RCUBE_INPUT_GPC);
+            break;
+          case 'session':
+            $value = $_SESSION[$name];
+            break;
+        }
+        
+        if (is_array($value))
+          $value = join(", ", $value);
+        
+        return Q($value);
+    }
 
     return '';
   }
 
 
   /**
+   * Include a specific file and return it's contents
+   *
+   * @param string File path
+   * @return string Contents of the processed file
+   */
+  function include_php($file)
+  {
+    ob_start();
+    @include($file);
+    $out = ob_get_contents();
+    ob_end_clean();
+    
+    return $out;
+  }
+
+
+  /**
    * Create and register a button
    *
    * @param array Button attributes

--
Gitblit v1.9.1