function epub_get_item in Epub 8
Same name and namespace in other branches
- 7 epub.module \epub_get_item()
2 calls to epub_get_item()
- EpubCoverImage::viewElements in src/
Plugin/ Field/ FieldFormatter/ EpubCoverImage.php - Builds a renderable array for a field value.
- template_preprocess_epub_formatter_default in ./
epub.field.inc - Prepares variables for epub default templates.
File
- ./
epub.module, line 120
Code
function epub_get_item($dir, $id) {
$file = epub_get_opf($dir);
if ($file) {
$opfXML = simplexml_load_file($file);
$opfXML
->registerXPathNamespace('opf', 'http://www.idpf.org/2007/opf');
$element = $opfXML
->xpath('//opf:item[@id="' . $id . '"]');
if (empty($element)) {
return false;
}
else {
$attributes = $element[0]
->attributes();
$href = (string) $attributes['href'];
$filename = pathinfo($href);
$scan = file_scan_directory($dir, '/.*' . $filename['basename'] . '$/');
return array_shift($scan)->uri;
}
}
else {
return false;
}
}