print_epub.api.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the EPUB version module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Generate a EPUB version of the provided HTML.
  12. *
  13. * @param string $html
  14. * HTML content of the EPUB.
  15. * @param array $meta
  16. * Meta information to be used in the EPUB
  17. * - url: original URL
  18. * - name: author's name
  19. * - title: Page title
  20. * - node: node object.
  21. * @param string $filename
  22. * (optional) Filename of the generated EPUB.
  23. *
  24. * @return string|null
  25. * generated EPUB page, or NULL in case of error
  26. *
  27. * @see print_epub_controller_html()
  28. * @ingroup print_hooks
  29. */
  30. function hook_print_epub_generate($html, $meta, $filename = NULL) {
  31. $epub = new EPUB();
  32. $epub->writeHTML($html);
  33. if ($filename) {
  34. $epub->Output($filename);
  35. return TRUE;
  36. }
  37. else {
  38. return $epub->Output();
  39. }
  40. }
  41. /**
  42. * Alters the list of available EPUB libraries.
  43. *
  44. * During the configuration of the EPUB library to be used, the module needs
  45. * to discover and display the available libraries. This function should use
  46. * the internal _print_scan_libs() function which will scan both the module
  47. * and the libraries directory in search of the unique file pattern that can
  48. * be used to identify the library location.
  49. *
  50. * @param array $epub_tools
  51. * An associative array using as key the format 'module|path', and as value
  52. * a string describing the discovered library, where:
  53. * - module: the machine name of the module that handles this library.
  54. * - path: the path where the library is installed, relative to DRUPAL_ROOT.
  55. * If the recommended path is used, it begins with sites/all/libraries.
  56. * As a recommendation, the value should contain in parantheses the path
  57. * where the library was found, to allow the user to distinguish between
  58. * multiple install paths of the same library version.
  59. *
  60. * @ingroup print_hooks
  61. */
  62. function hook_print_epub_available_libs_alter(&$epub_tools) {
  63. module_load_include('inc', 'print', 'includes/print');
  64. $tools = _print_scan_libs('foo', '!^foo.php$!');
  65. foreach ($tools as $tool) {
  66. $epub_tools['print_epub_foo|' . $tool] = 'foo (' . dirname($tool) . ')';
  67. }
  68. }
  69. /**
  70. * Alters the EPUB filename.
  71. *
  72. * Changes the value of the EPUB filename variable, just before it is used to
  73. * create the file. When altering the variable, do not suffix it with the
  74. * '.epub' extension, as the module will do that automatically.
  75. *
  76. * @param string $epub_filename
  77. * Current value of the epub_filename variable, after processing tokens and
  78. * any transliteration steps.
  79. * @param string $path
  80. * original alias/system path of the page being converted to EPUB.
  81. *
  82. * @ingroup print_hooks
  83. */
  84. function hook_print_epub_filename_alter(&$epub_filename, &$path) {
  85. $epub_filename = $path . '/foo';
  86. }
  87. /**
  88. * @} End of "addtogroup hooks".
  89. */