home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / groupoffice-com-2.01 / modules / wiki / parse / main.php < prev    next >
PHP Script  |  2004-03-08  |  956b  |  41 lines

  1. <?php
  2. // $Id: main.php,v 1.1 2004/01/12 22:14:05 comsubvie Exp $
  3.  
  4. // Master parser for 'Tavi.
  5. function parseText($text, $parsers, $object_name)
  6. {
  7.   global $Entity, $ParseObject;
  8.  
  9.   $old_parse_object = $ParseObject;
  10.   $ParseObject = $object_name;          // So parsers know what they're parsing.
  11.  
  12.   $count  = count($parsers);
  13.   $result = '';
  14.  
  15.   $text = parse_elem_flag($text);    // Escape $FlgChr before pre-parsing
  16.   $text = pre_parser($text);  // Fix line continuation/breaks and code-sections 
  17.  
  18.   // Run each parse element in turn on each line of text.
  19.  
  20.   foreach(explode("\n", $text) as $line)
  21.   {
  22.     $line = $line . "\n";
  23.     for($i = 0; $i < $count; $i++)
  24.       { $line = $parsers[$i]($line); }
  25.  
  26.     $result = $result . $line;
  27.   }
  28.  
  29.   // Some stateful parsers need to perform final processing.
  30.  
  31.   $line = '';
  32.   for($i = 0; $i < $count; $i++)
  33.     { $line = $parsers[$i]($line); }
  34.  
  35.   $ParseObject = $old_parse_object;
  36.  
  37.   return $result . $line;
  38. }
  39.  
  40. ?>
  41.