Recent Posts
C | 10 sec ago
None | 13 sec ago
None | 17 sec ago
Prolog | 21 sec ago
Python | 28 sec ago
None | 30 sec ago
None | 1 min ago
C | 1 min ago
mIRC | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
By Amer Kawar on the 31st of Oct 2009 04:14:50 PM
Download |
Raw |
Embed |
Report
<?php
/**
* Function to fix video objects embedding HTML code in Wordpress.
* This function uses DOM traversal to rebuild the <object> tag of the
* video files in an XHTML valid format.
*
* Article: HOW TO: Build a XHTML Valid Wordpress Blog with DISQUS Plugin
* URL: http://blog.thoughtpick.com/2009/10/how-to-build-xhtml-valid-wordpress.html
*
* @author: Amer Kawar
*/
function fixVideoObjects($content) {
// input the regex pattern to match <object *</object> tags
$pattern = '/<object [a-z0-9\/\- \.=_#:,"\?\'><&;]*<\/object>/i';
// use preg_match_all to fill $m array with all <object> fields found
// for each match in $m loop and replace the object only if
// it has the embed tag
for ($i = 0
; $i < count($m[0
]); $i++) {
$doc = new DOMDocument();
$doc->loadHTML($m[0][$i]);
$o = $doc->getElementsByTagName('object');
$embed_tag = $o->item(0)->getElementsByTagName('embed');
if (!is_null($embed_tag->item(0
))) {
$src = $embed_tag->item(0)->getAttribute('src');
// get the w x h, if they are null from the <object> tag, get them from
// the <embed> tag
$w = $o->item(0)->getAttribute('width');
$h = $o->item(0)->getAttribute('height');
if (is_null($w)) $w = $embed_tag->item(0)->getAttribute('width');
if (is_null($h)) $h = $embed_tag->item(0)->getAttribute('height');
$out = '<object type="application/x-shockwave-flash" '
.'style="width:'.$w.'px; '
.'height:'.$h.'px;" data="'.str_replace('&','&',$src).'">';
// find all param tags and re-echo them in XHTML 1.0 format
$params = $o->item(0)->getElementsByTagName('param');
foreach ($params as $p) {
if (!is_null($p->getAttribute('name')) && !is_null($p->getAttribute('value'))) {
$n = $p->getAttribute('name');
$v = $p->getAttribute('value');
$out .= '<param name="'.$n.'" value="'.str_replace('&','&',$v).'" />';
}
}
$out .= '</object>';
// replace object found by the re-written object
}
}
}
}
}
return $content;
}
?>
Submit a correction or amendment below.
Make A New Post