print_epub.drush.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * drush integration for print_epub module EPUB libraries download.
  5. */
  6. /**
  7. * Implements hook_drush_command().
  8. */
  9. function print_epub_drush_command() {
  10. $items = array();
  11. $epub_libs = array();
  12. drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
  13. $items['print-epub-download'] = array(
  14. 'description' => 'Download and extract a EPUB library.',
  15. 'arguments' => array(
  16. 'library' => dt('The EPUB library to download. Available choices: !libs.', array('!libs' => implode(', ', array_keys($epub_libs)))),
  17. ),
  18. 'options' => array(
  19. 'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
  20. ),
  21. 'aliases' => array('epubdl'),
  22. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT, // No site or config needed.
  23. );
  24. return $items;
  25. }
  26. /**
  27. * Implements of drush_hook_COMMAND_validate().
  28. */
  29. function drush_print_epub_download_validate($library = NULL) {
  30. if (is_null($library)) {
  31. $epub_libs = array();
  32. drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
  33. drush_set_error('DRUSH_EPUBDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array('!cmd' => 'print-epub-download', '!libs' => implode(', ', array_keys($epub_libs)))));
  34. }
  35. }
  36. /**
  37. * Download and extract EPUB archive.
  38. *
  39. * @param string $library
  40. * library to download
  41. */
  42. function drush_print_epub_download($library) {
  43. $epub_libs = array();
  44. drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
  45. if (isset($library) && isset($epub_libs[drupal_strtolower($library)])) {
  46. $func = $epub_libs[drupal_strtolower($library)]['callback'];
  47. $download_url = $func();
  48. if ($download_url) {
  49. _print_drush_download_lib($library, $download_url);
  50. }
  51. }
  52. else {
  53. drush_log(dt('Please specify a EPUB library. Available choices: !libs.', array('!libs' => implode(', ', array_keys($epub_libs)))), 'error');
  54. }
  55. }