function epub_get_toc in Epub 7
Same name and namespace in other branches
- 8 epub.module \epub_get_toc()
2 calls to epub_get_toc()
- epub_block_view in ./
epub.module - theme_epub_formatter_toc in includes/
epub.field.inc
File
- ./
epub.module, line 271
Code
function epub_get_toc($dir, $target = FALSE) {
$file = epub_get_nav($dir);
if ($file) {
$tocXML = simplexml_load_file($file);
$tocXML
->registerXPathNamespace('xhtml', 'http://www.w3.org/1999/xhtml');
$tocXML
->registerXPathNamespace('epub', 'http://www.idpf.org/2007/ops');
foreach ($tocXML
->xpath('//xhtml:a[@href]') as $item) {
$item[0]
->attributes()->href = rawurldecode(file_create_url(dirname($file) . '/' . $item[0]
->attributes()->href));
if ($target) {
$item[0]
->addAttribute('target', $target);
}
}
$toc = $tocXML
->xpath('//*[@epub:type="toc"]');
if ($toc) {
return $toc[0]
->asXML();
}
}
$file = epub_get_ncx($dir);
if ($file) {
$tocXML = simplexml_load_file(epub_get_ncx($dir));
$tocXML = simplexml_load_file($file);
$tocXML
->registerXPathNamespace('ncx', 'http://www.daisy.org/z3986/2005/ncx/');
foreach ($tocXML
->xpath('//@src') as $item) {
$item[0] = rawurldecode(file_create_url(dirname($file) . '/' . $item[0]));
}
$toc = $tocXML
->xpath('//ncx:navMap');
if ($toc) {
$output = new SimpleXMLElement('<nav type="toc"><h2>Contents</h2></nav>');
$html = epub_ncx_item($toc[0], $target);
return $html;
}
}
return FALSE;
}