includes/wikiengine/Render/Xhtml.php
changeset 1 fe660c52c48f
child 78 4df25dfdde63
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 <?php
       
     2 // vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
       
     3 /**
       
     4  * Format class for the Xhtml rendering
       
     5  *
       
     6  * PHP versions 4 and 5
       
     7  *
       
     8  * @category   Text
       
     9  * @package    Text_Wiki
       
    10  * @author     Paul M. Jones <pmjones@php.net>
       
    11  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
       
    12  * @version    CVS: $Id: Xhtml.php,v 1.9 2006/02/10 22:31:50 toggg Exp $
       
    13  * @link       http://pear.php.net/package/Text_Wiki
       
    14  */
       
    15 
       
    16 /**
       
    17  * Format class for the Xhtml rendering
       
    18  *
       
    19  * @category   Text
       
    20  * @package    Text_Wiki
       
    21  * @author     Paul M. Jones <pmjones@php.net>
       
    22  * @license    http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1
       
    23  * @version    Release: @package_version@
       
    24  * @link       http://pear.php.net/package/Text_Wiki
       
    25  */
       
    26 class Text_Wiki_Render_Xhtml extends Text_Wiki_Render {
       
    27 
       
    28     var $conf = array(
       
    29     	'translate' => HTML_ENTITIES,
       
    30     	'quotes'    => ENT_COMPAT,
       
    31     	'charset'   => 'ISO-8859-1'
       
    32     );
       
    33 
       
    34     function pre()
       
    35     {
       
    36         $this->wiki->source = $this->textEncode($this->wiki->source);
       
    37     }
       
    38 
       
    39     function post()
       
    40     {
       
    41         return;
       
    42     }
       
    43 
       
    44 
       
    45     /**
       
    46     * Method to render text
       
    47     *
       
    48     * @access public
       
    49     * @param string $text the text to render
       
    50     * @return rendered text
       
    51     *
       
    52     */
       
    53 
       
    54     function textEncode($text)
       
    55     {
       
    56         // attempt to translate HTML entities in the source.
       
    57         // get the config options.
       
    58         $type = $this->getConf('translate', HTML_ENTITIES);
       
    59         $quotes = $this->getConf('quotes', ENT_COMPAT);
       
    60         $charset = $this->getConf('charset', 'ISO-8859-1');
       
    61 
       
    62         // have to check null and false because HTML_ENTITIES is a zero
       
    63         if ($type === HTML_ENTITIES) {
       
    64 
       
    65             // keep a copy of the translated version of the delimiter
       
    66             // so we can convert it back.
       
    67             $new_delim = htmlentities($this->wiki->delim, $quotes, $charset);
       
    68       
       
    69             // convert the entities.  we silence the call here so that
       
    70             // errors about charsets don't pop up, per counsel from
       
    71             // Jan at Horde.  (http://pear.php.net/bugs/bug.php?id=4474)
       
    72             $text = @htmlentities(
       
    73               $text,
       
    74               $quotes,
       
    75               $charset
       
    76             );
       
    77             
       
    78             // Mod for Enano: undo any HTML cleaning - we will take care of this ourselves
       
    79             $text = str_replace(Array('&lt;', '&gt;', '&quot;', '&amp;', '&#039;'),
       
    80                                 Array('<',    '>',    '"',      '&',     "'"     ),
       
    81                                 $text);
       
    82             
       
    83             // re-convert the delimiter
       
    84             $text = str_replace(
       
    85               $new_delim, $this->wiki->delim, $text
       
    86             );
       
    87 
       
    88         } elseif ($type === HTML_SPECIALCHARS) {
       
    89     
       
    90           // keep a copy of the translated version of the delimiter
       
    91           // so we can convert it back.
       
    92           $new_delim = htmlspecialchars($this->wiki->delim, $quotes,
       
    93               $charset);
       
    94     
       
    95           // convert the entities.  we silence the call here so that
       
    96           // errors about charsets don't pop up, per counsel from
       
    97           // Jan at Horde.  (http://pear.php.net/bugs/bug.php?id=4474)
       
    98           $text = @htmlspecialchars(
       
    99             $text,
       
   100             $quotes,
       
   101             $charset
       
   102           );
       
   103     
       
   104           // re-convert the delimiter
       
   105           $text = str_replace(
       
   106             $new_delim, $this->wiki->delim, $text
       
   107           );
       
   108         }
       
   109         return $text;
       
   110     }
       
   111 }
       
   112 ?>