home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Text / Wiki / Parse / Default / Heading.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  2.4 KB  |  107 lines

  1. <?php
  2.  
  3. /**
  4. * Parses for heading text.
  5. * @category Text
  6. * @package Text_Wiki
  7. * @author Paul M. Jones <pmjones@php.net>
  8. * @license LGPL
  9. * @version $Id: Heading.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
  10. */
  11.  
  12. /**
  13. * Parses for heading text.
  14. * This class implements a Text_Wiki_Parse to find source text marked to
  15. * be a heading element, as defined by text on a line by itself prefixed
  16. * with a number of plus signs (+). The heading text itself is left in
  17. * the source, but is prefixed and suffixed with delimited tokens marking
  18. * the start and end of the heading.
  19. *
  20. * @category Text
  21. * @package Text_Wiki
  22. * @author Paul M. Jones <pmjones@php.net>
  23. */
  24.  
  25. class Text_Wiki_Parse_Heading extends Text_Wiki_Parse {
  26.     
  27.     
  28.     /**
  29.     * 
  30.     * The regular expression used to parse the source text and find
  31.     * matches conforming to this rule.  Used by the parse() method.
  32.     * 
  33.     * @access public
  34.     * 
  35.     * @var string
  36.     * 
  37.     * @see parse()
  38.     * 
  39.     */
  40.     
  41.     var $regex = '/^(\+{1,6}) (.*)/m';
  42.     
  43.     var $conf = array(
  44.         'id_prefix' => 'toc'
  45.     );
  46.     
  47.     /**
  48.     * 
  49.     * Generates a replacement for the matched text.  Token options are:
  50.     * 
  51.     * 'type' => ['start'|'end'] The starting or ending point of the
  52.     * heading text.  The text itself is left in the source.
  53.     * 
  54.     * @access public
  55.     *
  56.     * @param array &$matches The array of matches from parse().
  57.     *
  58.     * @return string A pair of delimited tokens to be used as a
  59.     * placeholder in the source text surrounding the heading text.
  60.     *
  61.     */
  62.     
  63.     function process(&$matches)
  64.     {
  65.         // keep a running count for header IDs.  we use this later
  66.         // when constructing TOC entries, etc.
  67.         static $id;
  68.         if (! isset($id)) {
  69.             $id = 0;
  70.         }
  71.         
  72.         $prefix = htmlspecialchars($this->getConf('id_prefix'));
  73.         
  74.         $start = $this->wiki->addToken(
  75.             $this->rule, 
  76.             array(
  77.                 'type' => 'start',
  78.                 'level' => strlen($matches[1]),
  79.                 'text' => $matches[2],
  80.                 'id' => $prefix . $id ++
  81.             )
  82.         );
  83.         
  84.         $end = $this->wiki->addToken(
  85.             $this->rule, 
  86.             array(
  87.                 'type' => 'end',
  88.                 'level' => strlen($matches[1])
  89.             )
  90.         );
  91.         
  92.         return $start . $matches[2] . $end . "\n";
  93.     }
  94. }
  95. ?>