You are here

function epub_get_item in Epub 7

Same name and namespace in other branches
  1. 8 epub.module \epub_get_item()
2 calls to epub_get_item()
theme_epub_formatter_cover in includes/epub.field.inc
theme_epub_formatter_default in includes/epub.field.inc

File

./epub.module, line 201

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 file_create_url(array_shift($scan)->uri);
    }
  }
  else {
    return FALSE;
  }
}