reactivated project (dev: http://git-dev.pk910.de)
[phpgitweb.git] / htdocs / lib / ContentProvider.class.php
index cd88b91e8b025b8e7347f849bc41f7fa22a8ce25..0fc9685b54c27f3b73ee29460506ee183f2b43c7 100644 (file)
  */
 
 class ContentProvider {
-    private static $template_cache = array();
+       private static $template_cache = array();
        private static $overall_content = array();
        
        private $template, $subtemplate;
        private $content = array();
        
-    public function __construct($template, $subtemplate, $content = null) {
+       public function __construct($template, $subtemplate, $content = null) {
                $this->template = $template;
                $this->subtemplate = $subtemplate;
                
@@ -31,7 +31,7 @@ class ContentProvider {
                        $this->content = $content;
                }
        }
-    
+       
        public function set($name, $value) {
                $this->content[strtolower($name)] = $value;
        }
@@ -41,6 +41,8 @@ class ContentProvider {
                        return;
                if(!array_key_exists(strtolower($name), $this->content))
                        $this->content[strtolower($name)] = array();
+               if(!is_array($this->content[strtolower($name)]))
+                       $this->content[strtolower($name)] = array($this->content[strtolower($name)]);
                $this->content[strtolower($name)][] = $value;
        }
        
@@ -76,12 +78,12 @@ class ContentProvider {
                case "year":
                        $rep = date("Y");
                        break;
-               case "title":
-                       $rep = GitConfig::GITWEB_TITLE;
-                       break;
                case "rendertime":
                        $rep = "%rendertime%"; //gets replaced later
                        break;
+               case "template_path":
+                       $rep = 'templates/'.(GitConfig::TEMPLATE_NAME ? GitConfig::TEMPLATE_NAME : 'default');
+                       break;
                default:
                        if(array_key_exists($var, $this->content)) {
                                $rep = $this->resolve_content($this->content[$var]);
@@ -113,7 +115,9 @@ class ContentProvider {
                else {
                        $template_html = $this->load_template($this->template, $subtemplate);
                }
-               $template_html = preg_replace_callback('/%([^%]*)%/', array($this, "replace_placeholder"), $template_html);
+               $template_html = preg_replace('/([\r\n]*)$/mD', '', $template_html);
+               $template_html = preg_replace_callback('/%([^%\n]*)%/', array($this, "replace_placeholder"), $template_html);
+               $template_html = preg_replace_callback('/%([^%\n]*)%/', array($this, "replace_placeholder"), $template_html);
                
                return $template_html;
        }