cvs: pear /Text_Wiki/Text/Wiki/Render Xhtml.php

From: Date: Sat, 28 May 2005 20:45:34 +0000
Subject: cvs: pear /Text_Wiki/Text/Wiki/Render Xhtml.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-32189@lists.php.net to get a copy of this message
pmjones Sat May 28 16:45:34 2005 EDT Modified files: /pear/Text_Wiki/Text/Wiki/Render Xhtml.php Log: added charset and quotes support to html translation (changed internal algo from mapping html translation tabloes to using htmlspecialchars and htmlentities) http://cvs.php.net/diff.php/pear/Text_Wiki/Text/Wiki/Render/Xhtml.php?r1=1.4&r2=1.5&ty=u Index: pear/Text_Wiki/Text/Wiki/Render/Xhtml.php diff -u pear/Text_Wiki/Text/Wiki/Render/Xhtml.php:1.4 pear/Text_Wiki/Text/Wiki/Render/Xhtml.php:1.5 --- pear/Text_Wiki/Text/Wiki/Render/Xhtml.php:1.4 Mon Jan 31 09:31:47 2005 +++ pear/Text_Wiki/Text/Wiki/Render/Xhtml.php Sat May 28 16:45:34 2005 @@ -2,26 +2,58 @@ class Text_Wiki_Render_Xhtml extends Text_Wiki_Render { - var $conf = array('translate' => HTML_ENTITIES); + var $conf = array( + 'translate' => HTML_ENTITIES, + 'quotes' => ENT_COMPAT, + 'charset' => 'ISO-8859-1' + ); function pre() { - // attempt to translate HTML entities in the source before continuing. - $type = $this->getConf('translate', null); + // attempt to translate HTML entities in the source. + // get the config options. + $type = $this->getConf('translate', HTML_ENTITIES); + $quotes = $this->getConf('quotes', ENT_COMPAT); + $charset = $this->getConf('charset', 'ISO-8859-1'); - // are we translating html? - if ($type !== false && $type !== null) { - - // yes! get the translation table. - $xlate = get_html_translation_table($type); - - // remove the delimiter character it doesn't get translated - unset($xlate[$this->wiki->delim]); - - // translate! - $this->wiki->source = strtr($this->wiki->source, $xlate); - } + // have to check null and false because HTML_ENTITIES is a zero + if ($type !== null && $type !== false && $type == HTML_ENTITIES) { + // keep a copy of the translated version of the delimiter + // so we can convert it back. + $new_delim = htmlentities($this->wiki->delim, $quotes, $charset); + + // convert the entities + $this->wiki->source = htmlentities( + $this->wiki->source, + $quotes, + $charset + ); + + // re-convert the delimiter + $this->wiki->source = str_replace( + $new_delim, $this->wiki->delim, $this->wiki->source + ); + + } elseif ($type == HTML_SPECIALCHARS) { + + // keep a copy of the translated version of the delimiter + // so we can convert it back. + $new_delim = htmlspecialchars($this->wiki->delim, $quotes, + $charset); + + // convert the special chars + $this->wiki->source = htmlspecialchars( + $this->wiki->source, + $quotes, + $charset + ); + + // re-convert the delimiter + $this->wiki->source = str_replace( + $new_delim, $this->wiki->delim, $this->wiki->source + ); + } } function post()

« previous php.pear.cvs (#32189) next »