Text_Wiki
[ class tree: Text_Wiki ] [ index: Text_Wiki ] [ all elements ]

Source for file Revise.php

Documentation is available at Revise.php

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

Documentation generated on Mon, 11 Mar 2019 13:56:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.