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 / Revise.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.3 KB  |  145 lines

  1. <?php
  2.  
  3. /**
  4. * Parses for text marked as revised (insert/delete).
  5. * @category Text
  6. * @package Text_Wiki
  7. * @author Paul M. Jones <pmjones@php.net>
  8. * @license LGPL
  9. * @version $Id: Revise.php,v 1.3 2005/02/23 17:38:29 pmjones Exp $
  10. */
  11.  
  12. /**
  13. * Parses for text marked as revised (insert/delete).
  14. *
  15. * @category Text
  16. * @package Text_Wiki
  17. * @author Paul M. Jones <pmjones@php.net>
  18. */
  19.  
  20. class Text_Wiki_Parse_Revise extends Text_Wiki_Parse {
  21.     
  22.     
  23.     /**
  24.     * 
  25.     * The regular expression used to parse the source text and find
  26.     * matches conforming to this rule.  Used by the parse() method.
  27.     * 
  28.     * @access public
  29.     * 
  30.     * @var string
  31.     * 
  32.     * @see parse()
  33.     * 
  34.     */
  35.     
  36.     var $regex = "/\@\@({*?.*}*?)\@\@/U";
  37.     
  38.     
  39.     /**
  40.     * 
  41.     * Config options.
  42.     * 
  43.     * @access public
  44.     * 
  45.     * @var array
  46.     *
  47.     */
  48.     
  49.     var $conf = array(
  50.         'delmark' => '---',
  51.         'insmark' => '+++'
  52.     );
  53.     
  54.     
  55.     /**
  56.     * 
  57.     * Generates a replacement for the matched text.  Token options are:
  58.     * 
  59.     * 'type' => ['start'|'end'] The starting or ending point of the
  60.     * inserted text.  The text itself is left in the source.
  61.     * 
  62.     * @access public
  63.     *
  64.     * @param array &$matches The array of matches from parse().
  65.     *
  66.     * @return string A pair of delimited tokens to be used as a
  67.     * placeholder in the source text surrounding the teletype text.
  68.     *
  69.     */
  70.     
  71.     function process(&$matches)
  72.     {
  73.         $output = '';
  74.         $src = $matches[1];
  75.         $delmark = $this->getConf('delmark'); // ---
  76.         $insmark = $this->getConf('insmark'); // +++
  77.         
  78.         // '---' must be before '+++' (if they both appear)
  79.         $del = strpos($src, $delmark);
  80.         $ins = strpos($src, $insmark);
  81.         
  82.         // if neither is found, return right away
  83.         if ($del === false && $ins === false) {
  84.             return $matches[0];
  85.         }
  86.         
  87.         // handle text to be deleted
  88.         if ($del !== false) {
  89.             
  90.             // move forward to the end of the deletion mark
  91.             $del += strlen($delmark);
  92.             
  93.             if ($ins === false) {
  94.                 // there is no insertion text following
  95.                 $text = substr($src, $del);
  96.             } else {
  97.                 // there is insertion text following,
  98.                 // mitigate the length
  99.                 $text = substr($src, $del, $ins - $del);
  100.             }
  101.             
  102.             $output .= $this->wiki->addToken(
  103.                 $this->rule, array('type' => 'del_start')
  104.             );
  105.             
  106.             $output .= $text;
  107.             
  108.             $output .= $this->wiki->addToken(
  109.                 $this->rule, array('type' => 'del_end')
  110.             );
  111.         }
  112.         
  113.         // handle text to be inserted
  114.         if ($ins !== false) {
  115.             
  116.             // move forward to the end of the insert mark
  117.             $ins += strlen($insmark);
  118.             $text = substr($src, $ins);
  119.             
  120.             $output .= $this->wiki->addToken(
  121.                 $this->rule, array('type' => 'ins_start')
  122.             );
  123.             
  124.             $output .= $text;
  125.             
  126.             $output .= $this->wiki->addToken(
  127.                 $this->rule, array('type' => 'ins_end')
  128.             );
  129.         }
  130.         
  131.         return $output;
  132.     }
  133. }
  134. ?>