includes/render.php
changeset 91 8079b0288e8e
parent 85 7c68a18a27be
child 133 af0f6ec48de3
--- a/includes/render.php	Sun Aug 12 14:56:52 2007 -0400
+++ b/includes/render.php	Tue Aug 14 15:13:40 2007 -0400
@@ -408,7 +408,7 @@
   function sanitize_html($text)
   {
     $text = htmlspecialchars($text);
-    $allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([^.]+)--');
+    $allowed_tags = Array('b', 'i', 'u', 'pre', 'code', 'tt', 'br', 'p', 'nowiki', '!--([\w\W]+)--');
     foreach($allowed_tags as $t)
     {
       $text = preg_replace('#&lt;'.$t.'&gt;(.*?)&lt;/'.$t.'&gt;#is', '<'.$t.'>\\1</'.$t.'>', $text);
@@ -418,6 +418,52 @@
     return $text;
   }
   
+  /**
+   * Parses internal links (wikilinks) in a block of text.
+   * @param string Text to process
+   * @return string
+   */
+  
+  function parse_internal_links($text)
+  {
+    
+    // stage 1 - links with alternate text
+    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\|(.+?)\]\]/', $text, $matches);
+    foreach ( $matches[0] as $i => $match )
+    {
+      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+      
+      $url = makeUrl($pid_clean, false, true);
+      $inner_text = $matches[2][$i];
+      $quot = '"';
+      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+      
+      $link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
+      
+      $text = str_replace($match, $link, $text);
+    }
+    
+    // stage 2 - links with no alternate text
+    preg_match_all('/\[\[([^\[\]<>\{\}\|]+)\]\]/', $text, $matches);
+    foreach ( $matches[0] as $i => $match )
+    {
+      list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+      $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
+      
+      $url = makeUrl($matches[1][$i], false, true);
+      $inner_text = htmlspecialchars(get_page_title($pid_clean));
+      $quot = '"';
+      $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';
+      
+      $link = "<a href={$quot}{$url}{$quot}{$exists}>{$inner_text}</a>";
+      
+      $text = str_replace($match, $link, $text);
+    }
+    
+    return $text;
+  }
+  
   /* *
    * Replaces template inclusions with the templates
    * @param string $message The text to format