tags with a pretty portable SVG reference. Thanks to Jeff Schiller for the portable SVG object/embed and the isASVInstalled() js function.
Author: Rob Russell
Version: 1.0
Author URI: http://rr.latenightpc.com/wp/
*/
function make_svg_inlay($attributes_list)
{
// defaults
$src = '';
$nosvg = '
SVG inlay image not availble.
';
$container_attribute_string = '';
// unpack the attributes for the svg embed/object and its container
foreach($attributes_list as $attribute)
{
$aname = $attribute->name();
// src, data and nosvg are special
if ($aname == 'src')
{
$src = $attribute->value();
}
elseif ($aname == 'data')
{
$src = $attribute->value();
}
elseif ($aname == 'nosvg')
{
$nosvg = $attribute->value();
}
else
{
// all other attributes apply to the container div
$container_attribute_string .= $aname . '="' . $attribute->value() . '" ';
}
}
$output = '
';
return $output;
}
function replace_tags_callback($match,$tag_name = 'svginlay')
{
//
if (0)
{
$dom = DOMDocument::loadHTML($match[0]);
$elements = $dom->getElementsByTagName($tag_name );
$element = $elements[0];
return make_svg_inlay($element->attributes());
// return make_svg_inlay($element->getAttribute('src'),$element->getAttribute('alt'),$element->getAttribute('class'));
}
else
{
// PHP 4.3
$dom = domxml_open_mem($match[0]);
$elements = $dom->get_elements_by_tagname($tag_name);
$element = $elements[0];
return make_svg_inlay($element->attributes());
}
}
function replace_svginlay_tags($text)
{
$tag_name = 'svginlay';
$text = preg_replace_callback('@<'. $tag_name . '[\/\!]*?[^<>]*?>@si','replace_tags_callback',$text);
return $text;
}
// Highlight text and comments:
add_filter('the_content', 'replace_svginlay_tags');
add_filter('the_excerpt', 'replace_svginlay_tags');
// The filter could be done on comments as well, but this is insanely
// dangerous to your site and your visitors. The input must be scrubbed
// and all that before doing this. There's probably something to do with
// tags allowed in responses, too
// add_filter('comment_text', 'replace_svginlay_tags');
?>