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

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