print_pdf.drush.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @file
  4. * 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. '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_pdf_download_validate($library = NULL) {
  30. if (is_null($library)) {
  31. $pdf_libs = array();
  32. drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
  33. 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('!cmd' => 'print-pdf-download', '!libs' => implode(', ', array_keys($pdf_libs)))));
  34. }
  35. }
  36. /**
  37. * Download and extract PDF archive.
  38. *
  39. * @param string $library
  40. * library to download
  41. */
  42. function drush_print_pdf_download($library) {
  43. $pdf_libs = array();
  44. drush_command_invoke_all_ref('drush_pdf_libs_alter', $pdf_libs);
  45. if (isset($library) && isset($pdf_libs[drupal_strtolower($library)])) {
  46. $func = $pdf_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 PDF library. Available choices: !libs.', array('!libs' => implode(', ', array_keys($pdf_libs)))), 'error');
  54. }
  55. }