print_pdf.drush.inc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * Provide drush integration for print_pdf module PDF libraries download.
  5. */
  6. /**
  7. * Implements hook_drush_command().
  8. */
  9. function print_pdf_drush_command() {
  10. $items = array();
  11. $pdf_libs = array();
  12. drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
  13. $items['print-pdf-download'] = array(
  14. 'description' => 'Download and extract a PDF library.',
  15. 'arguments' => array(
  16. 'library' => dt('The PDF library to download. Available choices: !libs.', array('!libs' => implode(', ', array_keys($pdf_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('pdfdl'),
  22. // No site or config needed.
  23. 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
  24. );
  25. return $items;
  26. }
  27. /**
  28. * Implements drush_hook_COMMAND_validate().
  29. */
  30. function drush_print_pdf_download_validate($library = NULL) {
  31. if (is_null($library)) {
  32. $pdf_libs = array();
  33. drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
  34. drush_set_error('DRUSH_PDFDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array(
  35. '!cmd' => 'print-pdf-download',
  36. '!libs' => implode(', ', array_keys($pdf_libs)),
  37. )));
  38. }
  39. }
  40. /**
  41. * Download and extract PDF archive.
  42. *
  43. * @param string $library
  44. * Library to download.
  45. */
  46. function drush_print_pdf_download($library) {
  47. $pdf_libs = array();
  48. drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
  49. if (isset($library) && isset($pdf_libs[drupal_strtolower($library)])) {
  50. $func = $pdf_libs[drupal_strtolower($library)]['callback'];
  51. $download_url = $func();
  52. if ($download_url) {
  53. _print_drush_download_lib($library, $download_url);
  54. }
  55. }
  56. else {
  57. drush_log(dt('Please specify a PDF library. Available choices: !libs.', array('!libs' => implode(', ', array_keys($pdf_libs)))), 'error');
  58. }
  59. }