Example #1
0
 function process($contents)
 {
     // First, substitute macros
     if (preg_match_all('/{([a-z-]+)\\s*([^}]*?)}/s', $contents, $matches)) {
         list($strings, $funcs, $args) = $matches;
         for ($i = 0; $i < sizeof($strings); $i++) {
             $replace = Wiki::runMacro($funcs[$i], $args[$i]);
             $contents = str_replace($strings[$i], $replace, $contents);
         }
     }
     // Finally, add Wiki-links
     if (preg_match_all('#(.*?)\\b([A-Z]+[a-z]+[A-Z\\d][A-Za-z\\d]*)\\b(.*?)#s', $contents, $matches)) {
         list(, $pre_text, $nodes, $post_text) = $matches;
         $self = $_SERVER['SCRIPT_NAME'];
         $tmp = '';
         for ($i = 0; $i < sizeof($nodes); $i++) {
             $spaced = Wiki::formatWord($nodes[$i]);
             $replace = "<a href=\"{$self}/{$nodes[$i]}\">{$spaced}</a>";
             $tmp .= $pre_text[$i] . $replace . $post_text[$i];
         }
         $contents = $tmp;
     }
     return nl2br($contents);
 }