From ececb2d98cab538bf3feab67bb6faa865b5e468f Mon Sep 17 00:00:00 2001 From: Garvin Hicking Date: Thu, 16 Apr 2009 16:47:51 +0000 Subject: [PATCH] . --- docs/NEWS | 2 +- include/functions_comments.inc.php | 2 + .../lang_en.inc.php | 2 + .../serendipity_event_xhtmlcleanup.php | 47 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/NEWS b/docs/NEWS index 4aab9148..3e2ac672 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -4,7 +4,7 @@ Version 1.5 () ------------------------------------------------------------------------ * Enhance xhtml cleanup plugin to also work on - tags. (garvinhicking) + tags and fix youtube html. (garvinhicking) * Changed bookmarklet to work with Chrome, thanks to Oliver Gassner & TextPattern :-) (garvinhicking) diff --git a/include/functions_comments.inc.php b/include/functions_comments.inc.php index a18425e3..7eef369a 100644 --- a/include/functions_comments.inc.php +++ b/include/functions_comments.inc.php @@ -893,6 +893,8 @@ function serendipity_insertComment($id, $commentInfo, $type = 'NORMAL', $source if ($GLOBALS['tb_logging']) { fclose($fp); } + + return $cid; } /** diff --git a/plugins/serendipity_event_xhtmlcleanup/lang_en.inc.php b/plugins/serendipity_event_xhtmlcleanup/lang_en.inc.php index 7d526aee..31af3ac8 100644 --- a/plugins/serendipity_event_xhtmlcleanup/lang_en.inc.php +++ b/plugins/serendipity_event_xhtmlcleanup/lang_en.inc.php @@ -12,5 +12,7 @@ @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, HTML entities derived from UTF-8 characters will be properly converted and not double-encoded in your output.'); +@define('PLUGIN_EVENT_XHTMLCLEANUP_YOUTUBE', 'Cleanup Youtube player code?'); +@define('PLUGIN_EVENT_XHTMLCLEANUP_YOUTUBE_DESC', 'If enabled, the by default XHTML invalid youtube object tags will get stripped of the embed part. Browser will still properly playback the video.'); ?> diff --git a/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php b/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php index 3febaddf..d5fe1815 100644 --- a/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php +++ b/plugins/serendipity_event_xhtmlcleanup/serendipity_event_xhtmlcleanup.php @@ -71,6 +71,7 @@ class serendipity_event_xhtmlcleanup extends serendipity_event } $conf_array[] = 'xhtml_parse'; $conf_array[] = 'utf8_parse'; + $conf_array[] = 'youtube'; $propbag->add('configuration', $conf_array); } @@ -99,6 +100,11 @@ class serendipity_event_xhtmlcleanup extends serendipity_event $propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_XHTML); $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_XHTML_DESC); $propbag->add('default', 'true'); + } elseif ($name == 'youtube') { + $propbag->add('type', 'boolean'); + $propbag->add('name', PLUGIN_EVENT_XHTMLCLEANUP_YOUTUBE); + $propbag->add('description', PLUGIN_EVENT_XHTMLCLEANUP_YOUTUBE_DESC); + $propbag->add('default', 'true'); } else { $propbag->add('type', 'boolean'); $propbag->add('name', constant($name)); @@ -122,6 +128,11 @@ class serendipity_event_xhtmlcleanup extends serendipity_event 'title', 'author', ); + static $youtube = null; + if ($youtube === null) { + $youtube = serendipity_db_bool($this->get_config('youtube')); + } + $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { @@ -149,6 +160,10 @@ class serendipity_event_xhtmlcleanup extends serendipity_event $eventData[$element] = xhtml_cleanup($eventData[$element]); $eventData[$element] = preg_replace_callback('@()@imsU', array($this, 'clean_tag'), $eventData[$element]); $eventData[$element] = preg_replace_callback("@<(a|iframe|param)(.*)(href|src|value)=(\"|')([^\"']+)(\"|')@isUm", array($this, 'clean_htmlspecialchars'), $eventData[$element]); + + if ($youtube) { + $this->youtubify($eventData[$element]); + } } } @@ -178,6 +193,38 @@ class serendipity_event_xhtmlcleanup extends serendipity_event } } + function youtubify(&$text) { + $text = preg_replace_callback('@(.*)@imsU', array($this, 'youtubify_regex'), $text); + } + + function youtubify_regex($matches) { + if (!preg_match('@@imsU', $matches[2], $m); + $movie = $m[1]; + + if (empty($movie)) { + preg_match('@@imsU', $matches[2], $m); + $movie = $m[1]; + } + + $appendix = preg_replace('@@imsU', '', $matches[2]); + $appendix = str_replace('', '', $appendix); + + $out = '' + . '' + . $appendix . ''; + $out .= "\n\n\n\n"; + + return $out; + } + // Takes an input tag and search for ommitted attributes. Expects a single tag (array, index 0) function clean_tag($data) { // Restore tags from preg_replace_callback buffer, as those can't be passed in the function header