print_epub_phpepub.module 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @file
  4. * Generate a EPUB for the print_epub module using the PHPePub library.
  5. *
  6. * @ingroup print
  7. */
  8. /**
  9. * Find out the version of the PHPePub library.
  10. *
  11. * @param string $epub_tool
  12. * Filename of the tool to be analysed.
  13. *
  14. * @return string
  15. * version number of the library
  16. */
  17. function _print_epub_phpepub_version($epub_tool) {
  18. if (file_exists(DRUPAL_ROOT . '/' . $epub_tool)) {
  19. include_once DRUPAL_ROOT . '/' . $epub_tool;
  20. $phpepub_version_4_plus = strpos($epub_tool, 'autoload.php') !== FALSE;
  21. if ($phpepub_version_4_plus) {
  22. return \PHPePub\Core\EPub::VERSION;
  23. }
  24. else {
  25. if (class_exists('EPub')) {
  26. return EPub::VERSION;
  27. }
  28. }
  29. }
  30. return 'unknown';
  31. }
  32. /**
  33. * Implements hook_print_epub_available_libs_alter().
  34. */
  35. function print_epub_phpepub_print_epub_available_libs_alter(&$epub_tools) {
  36. module_load_include('inc', 'print', 'includes/print');
  37. $tools = _print_scan_libs('phpepub', '!^EPub.php$!');
  38. foreach ($tools as $tool) {
  39. $epub_tools['print_epub_phpepub|' . $tool] = 'PHPePub (' . dirname($tool) . ')';
  40. }
  41. // PHPePub >= 4.0 uses a composer autoloader.
  42. $tools = _print_scan_libs('phpepub', '!^autoload.php$!');
  43. foreach ($tools as $tool) {
  44. if (preg_match('!PHPePub.*?/vendor/autoload.php$!i', $tool)) {
  45. $epub_tools['print_epub_phpepub|' . $tool] = 'PHPePub (' . dirname(dirname($tool)) . ')';
  46. }
  47. }
  48. }