print_epub_phpepub.pages.inc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Generates the EPUB version using PHPePub
  5. *
  6. * This file is included by the print_epub_phpepub module and includes the
  7. * functions that interface with the PHPePub library
  8. *
  9. * @ingroup print
  10. */
  11. /**
  12. * Implements hook_print_epub_generate().
  13. */
  14. function print_epub_phpepub_print_epub_generate($html, $meta, $filename = NULL) {
  15. global $language, $base_url;
  16. module_load_include('inc', 'print', 'includes/print');
  17. $epub_tool = explode('|', variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT));
  18. $images_via_file = variable_get('print_epub_images_via_file', PRINT_EPUB_IMAGES_VIA_FILE_DEFAULT);
  19. require_once(DRUPAL_ROOT . '/' . $epub_tool[1]);
  20. // Try to use local file access for image files
  21. $html = _print_access_images_via_file($html, $images_via_file);
  22. // set document information
  23. $epub = new EPub();
  24. $epub->setTitle(html_entity_decode($meta['title'], ENT_QUOTES, 'UTF-8'));
  25. $epub->setIdentifier($meta['url'], EPub::IDENTIFIER_URI);
  26. $epub->setLanguage($language->language);
  27. if (isset($meta['name'])) {
  28. $epub->setAuthor(strip_tags($meta['name']), strip_tags($meta['name']));
  29. }
  30. $epub->setPublisher(variable_get('site_name', 'Drupal'), $base_url);
  31. $epub->setSourceURL($meta['url']);
  32. @$epub->addChapter("Chapter", "epub.html", $html, FALSE);
  33. $epub->finalize(); // Finalize the book, and build the archive.
  34. // Close and output EPUB document
  35. $epub->sendBook(empty($filename) ? 'page' : $filename);
  36. return TRUE;
  37. }