print_epub_phpepub.module 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. * Implements hook_requirements().
  10. */
  11. function print_epub_phpepub_requirements($phase) {
  12. $requirements = array();
  13. $t = get_t();
  14. switch ($phase) {
  15. // At runtime, make sure that a EPUB generation tool is selected
  16. case 'runtime':
  17. $print_epub_epub_tool = variable_get('print_epub_epub_tool', PRINT_EPUB_EPUB_TOOL_DEFAULT);
  18. if (!empty($print_epub_epub_tool)) {
  19. $tool = explode('|', $print_epub_epub_tool);
  20. if (is_file($tool[1]) && is_readable($tool[1])) {
  21. if (basename($tool[1]) == 'EPub.php') {
  22. $version = _print_epub_phpepub_version($tool[1]);
  23. $requirements['print_epub_tool_version'] = array(
  24. 'title' => $t('Printer, email and EPUB versions - EPUB generation library'),
  25. 'value' => $t('PHPePub') . ' ' . $version,
  26. );
  27. }
  28. }
  29. }
  30. break;
  31. }
  32. return $requirements;
  33. }
  34. /**
  35. * Find out the version of the PHPePub library
  36. *
  37. * @param string $epub_tool
  38. * Filename of the tool to be analysed.
  39. *
  40. * @return string
  41. * version number of the library
  42. */
  43. function _print_epub_phpepub_version($epub_tool) {
  44. require_once(DRUPAL_ROOT . '/' . $epub_tool);
  45. return EPub::VERSION;
  46. }
  47. /**
  48. * Implements hook_print_epub_available_libs_alter().
  49. */
  50. function print_epub_phpepub_print_epub_available_libs_alter(&$epub_tools) {
  51. module_load_include('inc', 'print', 'includes/print');
  52. $tools = _print_scan_libs('phpepub', '!^EPub.php$!');
  53. foreach ($tools as $tool) {
  54. $epub_tools['print_epub_phpepub|' . $tool] = 'PHPePub (' . dirname($tool) . ')';
  55. }
  56. }