You are here

function drush_rnjs_plugin in Responsive Navigation 7

Command to download the responsive-nav.js plugin. Use drush --verbose for extra log detail.

1 string reference to 'drush_rnjs_plugin'
responsive_navigation_drush_command in ./responsive_navigation.drush.inc
Implements hook_drush_command().

File

./responsive_navigation.drush.inc, line 54

Code

function drush_rnjs_plugin() {
  $args = func_get_args();
  if (!empty($args[0])) {
    $path = $args[0];
  }
  else {
    $path = 'sites/all/libraries';
  }
  if (!is_dir($path)) {
    drush_op('mkdir', $path);
    drush_log(dt('Directory @path was created', array(
      '@path' => $path,
    )), 'notice');
  }
  $olddir = getcwd();
  chdir($path);
  if ($filepath = drush_download_file(RNJS_DOWNLOAD_URI)) {
    $filename = basename($filepath);
    $dirname = 'responsive-nav.js-' . basename($filepath, '.zip');

    // Github auto file naming
    if (is_dir($dirname) || is_dir('responsive_navigation')) {
      drush_delete_dir($dirname, TRUE);
      drush_delete_dir('responsive_navigation', TRUE);
      drush_log(dt('An existing responsive-nav.js plugin was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }
    drush_tarball_extract($filename);
    if ($dirname != 'responsive_navigation') {
      drush_move_dir($dirname, 'responsive_navigation', TRUE);
      $dirname = 'responsive_navigation';
    }
  }
  if (is_dir($dirname)) {
    drush_log(dt('responsive-nav.js plugin has been downloaded to @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to download the responsive-nav.js plugin to @path', array(
      '@path' => $path,
    )), 'error');
  }
  chdir($olddir);
}