Skip to content

Commit

Permalink
Replaced Flash embedding with HTML5 version in XmlRenderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mermshaus committed Jun 23, 2012
1 parent 54ab4a5 commit a7b148b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/Kaloa/Renderer/Xml/Rule/YouTubeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,8 @@ public function render()
$id = $node->getAttribute('id');

$xml = <<<EOT
<div class="blog_youtube_container" style="width: 400px; height: 300px;">
<object type="application/x-shockwave-flash"
class="blog_youtube"
style="display: block; width: 100%; height: 100%;"
data="http://www.youtube.com/v/$id"
>
<param name="movie"
value="http://www.youtube.com/v/$id&amp;hl=en&amp;fs=0"
/>
</object>
<div class="videoWrapper">
<iframe src="http://www.youtube.com/embed/$id" frameborder="0"></iframe>
</div>
EOT;

Expand Down
18 changes: 17 additions & 1 deletion src/Kaloa/Renderer/XmlRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ protected function decodeEntitiesFromXml($xmlString)
return $retVal;
}

/**
* http://www.php.net/manual/en/domdocument.savexml.php#95252
*/
protected function xml2xhtml($xml)
{
return preg_replace_callback('#<(\w+)([^>]*)\s*/>#s', create_function('$m', '
$xhtml_tags = array("br", "hr", "input", "frame", "img", "area", "link", "col", "base", "basefont", "param");
return in_array($m[1], $xhtml_tags) ? "<$m[1]$m[2] />" : "<$m[1]$m[2]></$m[1]>";
'), $xml);
}

public function registerRule(AbstractRule $rule, $weight = 0)
{
if (!isset($this->rules[$weight])) {
Expand Down Expand Up @@ -81,7 +92,12 @@ public function render($xmlCode)
}
}

return preg_replace('!<root[^>]*>(.*)</root>!s', '$1', $xmldoc->saveXML($xmldoc->documentElement));
$s = preg_replace('!<root[^>]*>(.*)</root>!s', '$1', $xmldoc->saveXML($xmldoc->documentElement));

// Handle self-closing tags
$s = $this->xml2xhtml($s);

return $s;
}

public function firePreSaveEvent($xmlCode)
Expand Down

0 comments on commit a7b148b

Please sign in to comment.