I use the serendipity_event_metadesc plugin and found a small bug by generating the content of <meta name="description" content=xxx">
Usually, i start every entry with an image and was wondering, why the description was filled up with html-entities and code like >a class='serendipity_image_link' ...
I found out, that in serendipity_event_metadesc.php at line 83 and following, the code for extraction the description out of the entry had a problem. He was looking for <p>-tags which normally don't exist in blog-entries. Using substr() seems to convert all html-tags to entities, so calling strip_tags() did not help. (But it was never called BTW, because the function exited not founding the first <p>-tag.
So I changed this code
Code: Select all
function extract_description($text) {
$x = strpos($text, '<p>');
if ($x === false) {
return substr($text, 0, 120);
}
$y = strpos($text, '</p>');
if ($y === false) {
return substr($text, 0, 120);
}
$title = substr($text, $x+3, $y-($x+3));
$title = strip_tags($title);
return $title;
}Code: Select all
function extract_description($text) {
$text = strip_html($text);
$text = substr($text, 0, 120);
return $text;
}Code: Select all
/**
* Remove HTML tags, including invisible text such as style and
* script code, and embedded objects. Add line breaks around
* block-level tags to prevent word joining after tag removal.
* http://nadeausoftware.com/articles/2007/09/php_tip_how_strip_html_tags_web_page
*/
function strip_html_tags($text) {
$text = preg_replace(
array(
// Remove invisible content
'@<iframe[^>]*?>.*?</iframe>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
// Add line breaks before and after blocks
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',
),
array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
"\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
"\n\$0", "\n\$0",
),
$text );
return strip_tags($text);
}
function extract_description($text) {
$text = $this->strip_html_tags($text);
$text = substr($text, 0, 120);
$text = str_replace('"','',$text);
return $text;
}In my case the plugin is now working much better. It would be nice, if someone could review the code and then submit it to SVN.
Edit: replaced HEAD with IFRAME