You are here

function theme_epub_formatter_cover in Epub 7

1 theme call to theme_epub_formatter_cover()
epub_field_formatter_view in includes/epub.field.inc
Implements hook_field_formatter_view().

File

includes/epub.field.inc, line 197

Code

function theme_epub_formatter_cover($variables) {
  $file_url = file_create_url($variables['file']->uri);
  $filename = $variables['file']->filename;
  $fid = 'fid-' . $variables['file']->fid;
  $dir = 'public://epub_content/' . $variables['file']->fid;
  $file = drupal_realpath($variables['file']->uri);
  $output = t('<p>This eBook can\'t be opened.</p>');
  $scan = file_scan_directory($dir, '/.*\\.opf$/');
  $opf = array_shift($scan);
  if (isset($opf)) {
    $opfXML = simplexml_load_file($opf->uri);
    $namespaces = $opfXML
      ->getDocNamespaces();
    $opfXML
      ->registerXPathNamespace('opf', 'http://www.idpf.org/2007/opf');
    $element = $opfXML
      ->xpath('/opf:package/opf:metadata/opf:meta[@name="cover"]');
    if (empty($element)) {
      $variables = array(
        'path' => $GLOBALS['base_url'] . '/misc/help.png',
        'alt' => 'Book cover',
        'title' => $variables['file']->filename,
        'width' => $variables['width'],
        'attributes' => array(
          'class' => 'ebook-cover',
          'id' => $fid,
          'style' => 'border:1px solid black;',
        ),
      );
      $content = '<div class="ebook" id="' . $fid . '">' . l(theme('image', $variables), $file_url, $options = array(
        'html' => true,
      )) . '</div>';
      $content .= '<p>' . t('A cover image is not required according to the ePub standard') . '</p>';
    }
    else {
      $attributes = $element[0]
        ->attributes();
      $cover = epub_get_item($dir, (string) $attributes['content']);
      $variables = array(
        'path' => $cover,
        'alt' => 'Book cover',
        'title' => $variables['file']->filename,
        'width' => $variables['width'],
        'attributes' => array(
          '
          class' => 'ebook-cover',
          'id' => $fid,
          'style' => 'border:1px solid black;',
        ),
      );

      //$content = l($filename, $file_url);
      $content = '<div class="ebook" id="' . $fid . '">' . l(theme('image', $variables), $file_url, $options = array(
        'html' => true,
      )) . '</div>';
    }
  }
  return $content;
}