Update of /cvsroot/php-blog/serendipity/plugins/serendipity_event_xhtmlcleanup
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14686/plugins/serendipity_event_xhtmlcleanup
Modified Files:
serendipity_event_xhtmlcleanup.php
Log Message:
Thanks to Riscky we now finally kill those nasty '&' to correct '&'
links. :-)
Index: serendipity_event_xhtmlcleanup.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- serendipity_event_xhtmlcleanup.php 22 Jun 2004 13:45:47 -0000 1.2
+++ serendipity_event_xhtmlcleanup.php 24 Jun 2004 10:28:38 -0000 1.3
@@ -13,6 +13,17 @@
break;
}
+if (!function_exists('html_entity_decode')) {
+ function html_entity_decode($given_html, $quote_style = ENT_QUOTES) {
+ $trans_table = get_html_translation_table(HTML_SPECIALCHARS, $quote_style);
+ if ($trans_table["'"] != ''') { # some versions of PHP match single quotes to '
+ $trans_table["'"] = ''';
+ }
+
+ return (strtr($given_html, array_flip($trans_table)));
+ }
+}
+
class serendipity_event_xhtmlcleanup extends serendipity_event
{
var $cleanup_tag, $cleanup_checkfor, $cleanup_val;
@@ -80,6 +91,7 @@
$this->cleanup_checkfor = 'ALT';
$this->cleanup_val = '';
$eventData[$element] = preg_replace_callback('@(<img.+/>)@imsU', array($this, 'clean_tag'), $eventData[$element]);
+ $eventData[$element] = preg_replace_callback("@<a(.*)href=(\"|')([^\"']+)(\"|')@isUm", array($this, 'clean_htmlspecialchars'), $eventData[$element]);
}
}
@@ -132,6 +144,10 @@
return $data[0];
}
+
+ function clean_htmlspecialchars($given, $quote_style = ENT_QUOTES) {
+ return '<a' . $given[1] . 'href=' . $given[2] . htmlspecialchars(html_entity_decode($given[3], $quote_style), $quote_style) . $given[4];
+ }
}
/* vim: set sts=4 ts=4 expandtab : */
|