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. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Paul M. Jones <pmjones@ciaweb.net>                          |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: revise.php,v 1.2 2004/01/31 15:52:08 pmjones Exp $
  20.  
  21.  
  22. /**
  23. * This class implements a Text_Wiki_Rule to find source text marked for
  24. * revision.
  25. *
  26. @author Paul M. Jones <pmjones@ciaweb.net>
  27. *
  28. @package Text_Wiki
  29. *
  30. */
  31.  
  32.     
  33.     
  34.     /**
  35.     * 
  36.     * The regular expression used to parse the source text and find
  37.     * matches conforming to this rule.  Used by the parse() method.
  38.     * 
  39.     * @access public
  40.     * 
  41.     * @var string 
  42.     * 
  43.     * @see parse()
  44.     * 
  45.     */
  46.     
  47.     var $regex = "/\@\@({*?.*}*?)\@\@/U";
  48.     
  49.     
  50.     /**
  51.     * 
  52.     * The characters to use as marking text to be stricken.
  53.     * 
  54.     * @access public
  55.     * 
  56.     * @var string 
  57.     * 
  58.     * @see parse()
  59.     *
  60.     */
  61.     
  62.     var $delmark = '---';
  63.     
  64.     
  65.     /**
  66.     * 
  67.     * The characters to use as marking text to be added.
  68.     * 
  69.     * @access public
  70.     * 
  71.     * @var string 
  72.     * 
  73.     * @see parse()
  74.     * 
  75.     */
  76.     
  77.     var $insmark = '+++';
  78.     
  79.     
  80.     /**
  81.     * 
  82.     * Generates a replacement for the matched text.  Token options are:
  83.     * 
  84.     * 'type' => ['start'|'end'] The starting or ending point of the
  85.     * inserted text.  The text itself is left in the source.
  86.     * 
  87.     * @access public
  88.     *
  89.     * @param array &$matches The array of matches from parse().
  90.     *
  91.     * @return string A pair of delimited tokens to be used as a
  92.     *  placeholder in the source text surrounding the teletype text.
  93.     *
  94.     */
  95.     
  96.     function process(&$matches)
  97.     {
  98.         $output '';
  99.         $src $matches[1];
  100.         $delmark $this->delmark;
  101.         $insmark $this->insmark;
  102.         
  103.         // '---' must be before '+++' (if they both appear)
  104.         $del strpos($src$delmark);
  105.         $ins strpos($src$insmark);
  106.         
  107.         // if neither is found, return right away
  108.         if ($del === false && $ins === false{
  109.             return $matches[0];
  110.         }
  111.         
  112.         // handle text to be deleted
  113.         if ($del !== false{
  114.             
  115.             // move forward to the end of the deletion mark
  116.             $del += strlen($delmark);
  117.             
  118.             if ($ins === false{
  119.                 // there is no insertion text following
  120.                 $text substr($src$del);
  121.             else {
  122.                 // there is insertion text following,
  123.                 // mitigate the length
  124.                 $text substr($src$del$ins $del);
  125.             }
  126.             
  127.             $output .= $this->addToken(array('type' => 'del_start'));
  128.             $output .= $text;
  129.             $output .= $this->addToken(array('type' => 'del_end'));
  130.         }
  131.         
  132.         // handle text to be inserted
  133.         if ($ins !== false{
  134.             
  135.             // move forward to the end of the insert mark
  136.             $ins += strlen($insmark);
  137.             $text substr($src$ins);
  138.             
  139.             $output .= $this->addToken(array('type' => 'ins_start'));
  140.             $output .= $text;
  141.             $output .= $this->addToken(array('type' => 'ins_end'));
  142.         }
  143.         
  144.         return $output;
  145.     }
  146.     
  147.     
  148.     /**
  149.     * 
  150.     * Renders a token into text matching the requested format.
  151.     * 
  152.     * @access public
  153.     * 
  154.     * @param array $options The "options" portion of the token (second
  155.     *  element).
  156.     * 
  157.     * @return string The text rendered from the token options.
  158.     * 
  159.     */
  160.     
  161.     function renderXhtml($options)
  162.     {
  163.         if ($options['type'== 'del_start'{
  164.             return '<del>';
  165.         }
  166.         
  167.         if ($options['type'== 'del_end'{
  168.             return '</del>';
  169.         }
  170.         
  171.         if ($options['type'== 'ins_start'{
  172.             return '<ins>';
  173.         }
  174.         
  175.         if ($options['type'== 'ins_end'{
  176.             return '</ins>';
  177.         }
  178.     }
  179. }
  180. ?>

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