domwindow.drush.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. * @file
  4. * drush integration for domwindow.
  5. */
  6. /**
  7. * The DOMWindow plugin URI.
  8. */
  9. define('DOMWINDOW_DOWNLOAD_URI', 'http://swip.codylindley.com/jquery.DOMWindow.js');
  10. /**
  11. * Implementation of hook_drush_command().
  12. *
  13. * In this hook, you specify which commands your
  14. * drush module makes available, what it does and
  15. * description.
  16. *
  17. * Notice how this structure closely resembles how
  18. * you define menu hooks.
  19. *
  20. * See `drush topic docs-commands` for a list of recognized keys.
  21. *
  22. * @return
  23. * An associative array describing your command(s).
  24. */
  25. function domwindow_drush_command() {
  26. $items = array();
  27. // the key in the $items array is the name of the command.
  28. $items['domwindow-plugin'] = array(
  29. 'callback' => 'drush_domwindow_plugin',
  30. 'description' => dt("Downloads the DOMWindow plugin."),
  31. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
  32. 'arguments' => array(
  33. 'path' => dt('Optional. A path where to install the DOMWindow plugin. If omitted Drush will use the default location.'),
  34. ),
  35. 'aliases' => array('domwindowplugin'),
  36. );
  37. return $items;
  38. }
  39. /**
  40. * Implementation of hook_drush_help().
  41. *
  42. * This function is called whenever a drush user calls
  43. * 'drush help <name-of-your-command>'
  44. *
  45. * @param
  46. * A string with the help section (prepend with 'drush:')
  47. *
  48. * @return
  49. * A string with the help text for your command.
  50. */
  51. function domwindow_drush_help($section) {
  52. switch ($section) {
  53. case 'drush:domwindow-plugin':
  54. return dt("Downloads the DOMWindow plugin from http://swip.codylindley.com, default location is sites/all/libraries.");
  55. }
  56. }
  57. /**
  58. * Implements drush_MODULE_post_pm_enable().
  59. */
  60. // function drush_domwindow_post_pm_enable() {
  61. // $modules = func_get_args();
  62. // if (in_array('domwindow', $modules)) {
  63. // drush_domwindow_plugin();
  64. // }
  65. // }
  66. /**
  67. * Command to download the DOMWindow plugin.
  68. */
  69. function drush_domwindow_plugin() {
  70. $filename = basename(DOMWINDOW_DOWNLOAD_URI);
  71. $dirname = drupal_strtolower(basename(DOMWINDOW_DOWNLOAD_URI, '.js'));
  72. $args = func_get_args();
  73. if (!empty($args[0])) {
  74. $path = $args[0];
  75. }
  76. else {
  77. $path = 'sites/all/libraries';
  78. }
  79. // Create the path if it does not exist.
  80. if (!is_dir($path)) {
  81. drush_op('mkdir', $path);
  82. drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
  83. }
  84. // Set the directory to the download location.
  85. $olddir = getcwd();
  86. chdir($path);
  87. // Remove any existing DOMWindow plugin directory
  88. if (is_dir($dirname)) {
  89. drush_log(dt('A existing DOMWindow plugin was overwritten at @path', array('@path' => $path)), 'notice');
  90. }
  91. else {
  92. drush_op('mkdir', $dirname);
  93. }
  94. chdir($dirname);
  95. // Remove any existing DOMWindow plugin zip archive
  96. if (is_file($filename)) {
  97. drush_op('unlink', $filename);
  98. }
  99. // Download the zip archive
  100. if (!drush_shell_exec('wget ' . DOMWINDOW_DOWNLOAD_URI)) {
  101. drush_shell_exec('curl -O ' . DOMWINDOW_DOWNLOAD_URI);
  102. }
  103. // Set working directory back to the previous working directory.
  104. chdir($olddir);
  105. if (is_dir($path)) {
  106. drush_log(dt('DOMWindow plugin has been downloaded to @path', array('@path' => $path)), 'success');
  107. }
  108. else {
  109. drush_log(dt('Drush was unable to download the DOMWindow plugin to @path', array('@path' => $path)), 'error');
  110. }
  111. }