From 2a3e4ec39f6792166bd0028dfec035230931810d Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Tue, 27 Sep 2005 12:18:34 +0000 Subject: [PATCH] Enhance xhtmlcleanup plugin to re-decode UTF-8 entities. --- include/admin/comments.inc.php | 80 +++++++++++-------- .../serendipity_event_xhtmlcleanup.php | 52 +++++++++++- 2 files changed, 93 insertions(+), 39 deletions(-) diff --git a/include/admin/comments.inc.php b/include/admin/comments.inc.php index 2435934..ee0a063 100644 --- a/include/admin/comments.inc.php +++ b/include/admin/comments.inc.php @@ -285,92 +285,102 @@ function highlightComment(id, checkvalue) { $i = 0; foreach ($sql as $rs) { $i++; - if (empty($rs['author'])) { - $rs['author'] = ANONYMOUS; - } - - $fullBody = $rs['body']; - $summary = serendipity_mb('substr', $rs['body'], 0, $summaryLength); + $comment = array( + 'fullBody' => $rs['body'], + 'summary' => serendipity_mb('substr', $rs['body'], 0, $summaryLength), + 'status' => $rs['status'], + 'type' => $rs['type'], + 'id' => $rs['id'], + 'title' => $rs['title'], + 'timestamp' => $rs['timestamp'], + 'referer' => $rs['referer'], + 'url' => $rs['url'], + 'ip' => $rs['ip'], + 'email' => $rs['email'], + 'author' => (empty($rs['author']) ? ANONYMOUS : $rs['author']), + 'entry_id' => $rs['entry_id'] + ); - if (strlen($fullBody) > strlen($summary) ) { - $summary .= ' ...'; - $excerpt = true; + if (strlen($comment['fullBody']) > strlen($comment['summary']) ) { + $comment['summary'] .= ' ...'; + $comment['excerpt'] = true; // When summary is not the full body, strip HTML tags from summary, as it might break and leave unclosed HTML. - $fullBody = nl2br(htmlspecialchars($fullBody)); - $summary = nl2br(strip_tags($summary)); + $comment['fullBody'] = nl2br(htmlspecialchars($comment['fullBody'])); + $comment['summary'] = nl2br(strip_tags($comment['summary'])); } else { - $excerpt = false; + $comment['excerpt'] = false; - $fullBody = $summary = nl2br(htmlspecialchars($fullBody)); + $comment['fullBody'] = $comment['summary'] = nl2br(htmlspecialchars($comment['fullBody'])); } + serendipity_plugin_api::hook_event('backend_view_comment', $comment); $class = 'serendipity_admin_list_item_' . (($i % 2 == 0 ) ? 'even' : 'uneven'); - $header_class = ($rs['status'] == 'pending' ? 'serendipityAdminMsgNote' : ''); + $header_class = ($comment['status'] == 'pending' ? 'serendipityAdminMsgNote' : ''); ?> - - '. $rs['title'] .', '. ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime('%b %e %Y, %H:%M', $rs['timestamp']))?> + + '. $comment['title'] .', '. ON . ' ' . serendipity_mb('ucfirst', serendipity_strftime('%b %e %Y, %H:%M', $comment['timestamp']))?> - + - - + +
: : : - +
IP: : - +
  : - +
-
- +
+
- - <?php echo APPROVE ?> + + <?php echo APPROVE ?> - - <?php echo VIEW; ?> + + <?php echo VIEW; ?> - <?php echo EDIT; ?> - ")' title="" class="serendipityIconLink"><?php echo DELETE; ?> + <?php echo EDIT; ?> + ")' title="" class="serendipityIconLink"><?php echo DELETE; ?> diff --git a/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php b/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php index 39df915..b1986c5 100644 --- a/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php +++ b/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php @@ -10,6 +10,8 @@ if (file_exists($probelang)) { @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!'); +@define('PLUGIN_EVENT_XHTMLCLEANUP_UTF8', 'Cleanup UTF-8 entities?'); +@define('PLUGIN_EVENT_XHTMLCLEANUP_UTF8_DESC', 'If enabled, HTMLentities derived from UTF-8 characters will be properly converted and not double-encoded in your output.'); if (!function_exists('html_entity_decode')) { function html_entity_decode($given_html, $quote_style = ENT_QUOTES) { @@ -35,7 +37,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.3'); + $propbag->add('version', '1.4'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', @@ -43,7 +45,11 @@ class serendipity_event_xhtmlcleanup extends serendipity_event )); $propbag->add('groups', array('BACKEND_TEMPLATES')); $propbag->add('cachable_events', array('frontend_display' => true)); - $propbag->add('event_hooks', array('frontend_display' => true)); + $propbag->add('event_hooks', array( + 'frontend_display' => true, + 'frontend_display:html:per_entry' => true, + 'backend_view_comment' => true + )); $this->markup_elements = array( array( @@ -69,6 +75,7 @@ class serendipity_event_xhtmlcleanup extends serendipity_event $conf_array[] = $element['name']; } $conf_array[] = 'xhtml_parse'; + $conf_array[] = 'utf8_parse'; $propbag->add('configuration', $conf_array); } @@ -87,7 +94,12 @@ class serendipity_event_xhtmlcleanup extends serendipity_event function introspect_config_item($name, &$propbag) { - if ($name == 'xhtml_parse') { + if ($name == 'utf8_parse') { + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_UTF8); + $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_UTF8_DESC); + $propbag->add('default', 'true'); + } elseif ($name == 'xhtml_parse') { $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_XHTML); $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_XHTML_DESC); @@ -102,13 +114,32 @@ class serendipity_event_xhtmlcleanup extends serendipity_event return true; } + function fixUTFEntity(&$string) { + $string = preg_replace('/&#(x[a-f0-9]{1,4}|[0-9]{1,5});/', '&#$1;', $string); + return true; + } + function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; - + static $convert_fields = array( + 'fullBody', + 'summary', + 'title', + 'author', + ); $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { + case 'backend_view_comment': + if (serendipity_db_bool($this->get_config('utf8_parse'))) { + foreach($convert_fields AS $convert_field) { + $this->fixUTFEntity($eventData[$convert_field]); + } + } + return true; + break; + case 'frontend_display': $this->cleanup_parse = serendipity_db_bool($this->get_config('xhtml_parse')); foreach ($this->markup_elements as $temp) { @@ -124,6 +155,19 @@ class serendipity_event_xhtmlcleanup extends serendipity_event } } + if (serendipity_db_bool($this->get_config('utf8_parse'))) { + $this->fixUTFEntity($eventData['author']); + $this->fixUTFEntity($eventData['comment']); + } + + return true; + break; + + case 'frontend_display:html:per_entry': + if (serendipity_db_bool($this->get_config('utf8_parse'))) { + $this->fixUTFEntity($eventData['title']); + } + return true; break; -- 2.39.5