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 / Render / Xhtml.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  2.7 KB  |  108 lines

  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.             // re-convert the delimiter
  79.             $text = str_replace(
  80.                 $new_delim, $this->wiki->delim, $text
  81.             );
  82.  
  83.         } elseif ($type === HTML_SPECIALCHARS) {
  84.  
  85.             // keep a copy of the translated version of the delimiter
  86.             // so we can convert it back.
  87.             $new_delim = htmlspecialchars($this->wiki->delim, $quotes,
  88.                 $charset);
  89.  
  90.             // convert the entities.  we silence the call here so that
  91.             // errors about charsets don't pop up, per counsel from
  92.             // Jan at Horde.  (http://pear.php.net/bugs/bug.php?id=4474)
  93.             $text = @htmlspecialchars(
  94.                 $text,
  95.                 $quotes,
  96.                 $charset
  97.             );
  98.  
  99.             // re-convert the delimiter
  100.             $text = str_replace(
  101.                 $new_delim, $this->wiki->delim, $text
  102.             );
  103.         }
  104.         return $text;
  105.     }
  106. }
  107. ?>
  108.