Merged
authorDan Fuhry <dan@enanocms.org>
Sat, 15 Sep 2012 13:16:59 -0400
changeset 1364 68c17d935750
parent 1363 f1ed3e9298ae (diff)
parent 1361 26e80700ff1d (current diff)
child 1373 851b91febb85
Merged
includes/template.php
--- a/includes/clientside/static/enano-lib-basic.js	Wed Apr 25 02:03:38 2012 -0400
+++ b/includes/clientside/static/enano-lib-basic.js	Sat Sep 15 13:16:59 2012 -0400
@@ -22,15 +22,13 @@
 
 // placeholder for window.console - used if firebug isn't present
 // http://getfirebug.com/firebug/firebugx.js
-if (!window.console || !console.firebug)
-{
-		var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
-		"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
+var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
+"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
 
-		window.console = {};
-		for (var i = 0; i < names.length; ++i)
-				window.console[names[i]] = function() {}
-}
+window.console || (window.console = {});
+for (var i = 0; i < names.length; ++i)
+	if ( typeof(window.console[names[i]]) != 'function' )
+		window.console[names[i]] = function() {}
 
 console.info('Enano::JS runtime: starting system init');
 
--- a/includes/render.php	Wed Apr 25 02:03:38 2012 -0400
+++ b/includes/render.php	Sat Sep 15 13:16:59 2012 -0400
@@ -45,7 +45,14 @@
 		$text = $page->fetch_text();
 		
 		if ( !$render )
+		{
+			$code = $plugins->setHook('render_getpage_norender');
+			foreach ( $code as $cmd )
+			{
+				eval($cmd);
+			}
 			return $text;
+		}
 		
 		$text = self::render($text, $wiki, $smilies, $filter_links);
 		return $text;
@@ -54,10 +61,14 @@
 	public static function getTemplate($id, $parms)
 	{
 		global $db, $session, $paths, $template, $plugins; // Common objects
+		
+		// Verify target exists -- if not, double-bracket it to convert it to a redlink
 		if ( !isPage($paths->get_pathskey($id, 'Template')) ) 
 		{
 			return '[['.$paths->nslist['Template'].$id.']]';
 		}
+		
+		// fetch from DB or template cache
 		if(isset($paths->template_cache[$id]))
 		{
 			$text = $paths->template_cache[$id];
@@ -69,6 +80,8 @@
 			$paths->template_cache[$id] = $text;
 		}
 		
+		// noinclude is not shown within the included template, only on the template's page when you load it
+		// nodisplay is not shown on the template's page, only in the included template
 		$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
 		$text = preg_replace('/<nodisplay>(.*?)<\/nodisplay>/is', '\\1', $text);
 		
@@ -91,7 +104,7 @@
 		return $text;
 	}
 	
-	public static function fetch_template_text($id)
+	public static function fetch_template_text($id, $params)
 	{
 		global $db, $session, $paths, $template, $plugins; // Common objects
 		$fetch_ns = 'Template';
@@ -131,6 +144,11 @@
 				return '[['.$paths->nslist['Template'].$id.']]';
 			}
 		}
+		
+		$template->context_push();
+		
+		$template->assign_vars($params);
+		
 		if(isset($paths->template_cache[$id]))
 		{
 			$text = $paths->template_cache[$id];
@@ -141,6 +159,8 @@
 			$paths->template_cache[$id] = $text;
 		}
 		
+		$template->context_pop();
+		
 		if ( is_string($text) )
 		{
 			$text = preg_replace('/<noinclude>(.*?)<\/noinclude>/is', '', $text);
@@ -894,7 +914,7 @@
 				{
 					$parms = Array();
 				}
-				if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i]) )
+				if ( $tpl_code = RenderMan::fetch_template_text($matches[1][$i], $parms) )
 				{
 					// Intelligent paragraphs.
 					// If:
--- a/includes/template.php	Wed Apr 25 02:03:38 2012 -0400
+++ b/includes/template.php	Sat Sep 15 13:16:59 2012 -0400
@@ -60,6 +60,13 @@
 	
 	var $fading_button = '';
 	
+	/**
+	* Context stack. You can save and restore the var set.
+	* @var array
+	*/
+
+	var $context_stack = array('bool' => array(), 'str' => array(), 'history' => array());
+	
 	function __construct()
 	{
 		global $db, $session, $paths, $template, $plugins; // Common objects
@@ -119,6 +126,24 @@
 	}
 	
 	/**
+	* Save the current context and start a blank one.
+	*/
+	
+	function context_push()
+	{
+		array_push($this->context_stack['str'], $this->tpl_strings);
+		array_push($this->context_stack['bool'], $this->tpl_bool);
+		array_push($this->context_stack['history'], $this->vars_assign_history);
+	}
+	
+	function context_pop()
+	{
+		$this->tpl_strings = array_pop($this->context_stack['str']);
+		$this->tpl_bool = array_pop($this->context_stack['bool']);
+		$this->vars_assign_history = array_pop($this->context_stack['history']);
+	}
+	
+	/**
  	* Gets the list of available CSS files (styles) for the specified theme.
  	* @param string Theme ID
  	* @return array
--- a/includes/wikiengine/parse_mediawiki.php	Wed Apr 25 02:03:38 2012 -0400
+++ b/includes/wikiengine/parse_mediawiki.php	Sat Sep 15 13:16:59 2012 -0400
@@ -54,11 +54,15 @@
 		while ( preg_match($template_regex, $text, $match) )
 		{
 			$i++;
+			// we can go up to 5 levels of templates deep
 			if ( $i == 5 )
 				break;
 			$text = RenderMan::include_templates($text);
 		}
 		
+		//header('Content-type: text/plain');
+		//die($text);
+		
 		return array();
 	}