function _svg_embed_get_svg in SVG Embed 7
Helper function to read the SCG, localise it and prepare it for output.
Parameters
stdClass $file:
string $langcode:
bool $include_fallback:
Return value
string
2 calls to _svg_embed_get_svg()
- svg_embed_fallback_png in ./
svg_embed.module - Menu callback to localise and convert the SVG to PNG which will then be delivered to the requesting browser.
- svg_embed_filter_svg_embed_process in ./
svg_embed.module - Implements hook_filter_FILTER_process().
File
- ./
svg_embed.module, line 288 - SVG Embed. Provides a filter for text formats that includes and on the fly translates SVG files into text fields.
Code
function _svg_embed_get_svg($file, $langcode, $include_fallback = TRUE) {
$svg = file_get_contents($file->uri);
if (!empty($svg)) {
$xml = new SimpleXMLElement($svg);
if (!empty($xml)) {
if ($langcode != LANGUAGE_NONE) {
_svg_embed_translate($xml, $langcode);
}
if ($include_fallback && class_exists('Imagick')) {
$fallback = $xml
->addChild('image');
$fallback
->addAttribute('src', url('svg-embed/' . $langcode . '/' . $file->fid . '/fallback.png'));
}
$svg = $xml
->asXML();
$svg_tag = strpos($svg, '<svg');
return $include_fallback ? substr($svg, $svg_tag) : $svg;
}
}
return '';
}