Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
authorDan
Wed, 11 Jul 2007 13:08:34 -0400
changeset 63 2c57d3018a88
parent 62 9dc4fded30e6
child 64 60e450d2e8c3
Fixed recursive template inclusion and spaces in template tags ({{Foo template}})
includes/render.php
--- a/includes/render.php	Wed Jul 11 13:00:19 2007 -0400
+++ b/includes/render.php	Wed Jul 11 13:08:34 2007 -0400
@@ -255,7 +255,15 @@
       }
     }
     
-    $text = RenderMan::include_templates($text);
+    $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
+    $i = 0;
+    while ( preg_match($template_regex, $text) )
+    {
+      $i++;
+      if ( $i == 5 )
+        break;
+      $text = RenderMan::include_templates($text);
+    }
     
     $text = process_tables($text);
     
@@ -450,10 +458,11 @@
   
   /**
    * Parses a partial template tag in wikitext, and return an array with the parameters.
-   * @param string The portion of the template tag that contains the parameters. Example:
+   * @param string The portion of the template tag that contains the parameters.
+   * @example
    * <code>
-   * foo = lorem ipsum
-   * bar = dolor sit amet
+   foo = lorem ipsum
+   bar = dolor sit amet
    * </code>
    * @return array Example:
    * [foo] => lorem ipsum
@@ -519,11 +528,12 @@
   function include_templates($text)
   {
     global $db, $session, $paths, $template, $plugins; // Common objects
-    $template_regex = "/\{\{([A-z0-9_-]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
+    $template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
     if ( $count = preg_match_all($template_regex, $text, $matches) )
     {
       for ( $i = 0; $i < $count; $i++ )
       {
+        $matches[1][$i] = sanitize_page_id($matches[1][$i]);
         $parmsection = trim($matches[2][$i]);
         if ( !empty($parmsection) )
         {