From 402c89e092fbedd8538c8de66b2fb136b6a64fcf Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Fri, 19 Aug 2005 12:39:39 +0000 Subject: [PATCH] Make htmlspecialchars after parsing (config value) --- .../serendipity_event_xhtmlcleanup.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php b/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php index fe4bdb9..a9719a5 100644 --- a/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php +++ b/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php @@ -8,6 +8,8 @@ if (file_exists($probelang)) { @define('PLUGIN_EVENT_XHTMLCLEANUP_NAME', 'Fix common XHTML errors'); @define('PLUGIN_EVENT_XHTMLCLEANUP_DESC', 'This plugin corrects common issues with XHTML markup in entries. It assists in keeping your blog XHTML compliant.'); +@define('PLUGIN_EVENT_XHTMLCLEANUP_XHTML', 'Encode XML-parsed data?'); +@define('PLUGIN_EVENT_XHTMLCLEANUP_XHTML_DESC', 'This plugin uses a XML parsing method to ensure XHTML validity of your code. This xml parsing may convert already valid entities to unescaped entities, so the plugin encodes all entities after the parsing. Set this flag to OFF if that introduces double encoding for you!'); if (!function_exists('html_entity_decode')) { function html_entity_decode($given_html, $quote_style = ENT_QUOTES) { @@ -23,7 +25,7 @@ if (!function_exists('html_entity_decode')) { class serendipity_event_xhtmlcleanup extends serendipity_event { var $title = PLUGIN_EVENT_XHTMLCLEANUP_NAME; - var $cleanup_tag, $cleanup_checkfor, $cleanup_val; + var $cleanup_tag, $cleanup_checkfor, $cleanup_val, $cleanup_parse; function introspect(&$propbag) { @@ -33,7 +35,7 @@ class serendipity_event_xhtmlcleanup extends serendipity_event $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking'); - $propbag->add('version', '1.1'); + $propbag->add('version', '1.2'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -66,6 +68,7 @@ class serendipity_event_xhtmlcleanup extends serendipity_event foreach($this->markup_elements as $element) { $conf_array[] = $element['name']; } + $conf_array[] = 'xhtml_parse'; $propbag->add('configuration', $conf_array); } @@ -84,10 +87,18 @@ class serendipity_event_xhtmlcleanup extends serendipity_event function introspect_config_item($name, &$propbag) { - $propbag->add('type', 'boolean'); - $propbag->add('name', constant($name)); - $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name))); - $propbag->add('default', 'true'); + if ($name == 'xhtml_parse') { + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_XHTML); + $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_XHTML_DESC); + $propbag->add('default', 'true'); + } else { + $propbag->add('type', 'boolean'); + $propbag->add('name', constant($name)); + $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name))); + $propbag->add('default', 'true'); + } + return true; } @@ -99,6 +110,7 @@ class serendipity_event_xhtmlcleanup extends serendipity_event if (isset($hooks[$event])) { switch($event) { case 'frontend_display': + $this->cleanup_parse = serendipity_db_bool($this->get_config('xhtml_parse')); foreach ($this->markup_elements as $temp) { if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']])) { $element = $temp['element']; @@ -150,7 +162,7 @@ class serendipity_event_xhtmlcleanup extends serendipity_event // Reconstruct XHTML tag. $atts = ' '; foreach($vals[0]['attributes'] AS $att => $att_con) { - $atts .= strtolower($att) . '="' . $att_con . '" '; + $atts .= strtolower($att) . '="' . ($this->cleanup_parse ? htmlspecialchars($att_con) : $att_con) . '" '; } return '<' . strtolower($tag) . $atts . ' />'; @@ -165,4 +177,3 @@ class serendipity_event_xhtmlcleanup extends serendipity_event } /* vim: set sts=4 ts=4 expandtab : */ -?> -- 2.39.5