You are here

function drush_jcarousel_swipe_lib_plugin in jCarousel 8.5

Command to download the jCarousel plugin.

1 string reference to 'drush_jcarousel_swipe_lib_plugin'
jcarousel_drush_command in drush/jcarousel.drush.inc
Implements hook_drush_command().

File

drush/jcarousel.drush.inc, line 119
Drush integration for jcarousel.

Code

function drush_jcarousel_swipe_lib_plugin() {
  $args = func_get_args();
  if (!empty($args[0])) {
    $path = $args[0];
  }
  else {
    $path = 'libraries';
  }

  // Create the path if it does not exist.
  if (!is_dir($path)) {
    drush_op('mkdir', $path);
    drush_log(dt('Directory @path was created', [
      '@path' => $path,
    ]), 'notice');
  }

  // Set the directory to the download location.
  $olddir = getcwd();
  chdir($path);

  // Download the zip archive.
  if ($filepath = drush_download_file(JCAROUSEL_SWIPE_DOWNLOAD_URIOAD_URI)) {
    $filename = basename($filepath);
    $dirname = basename($filepath, '.zip');

    // Remove any existing jCarousel plugin directory.
    if (is_dir($dirname) || is_dir('jcarouselSwipe')) {
      drush_delete_dir($dirname, TRUE);
      drush_delete_dir('jcarouselSwipe', TRUE);
      drush_log(dt('A existing jCarousel swipe plugin was deleted from @path', [
        '@path' => $path,
      ]), 'notice');
    }

    // Decompress the zip archive.
    drush_tarball_extract($filename, $dirname);

    // Change the directory name to "jCarousel" if needed.
    if ($dirname != 'jcarouselSwipe') {
      drush_mkdir('jcarouselSwipe');
      chdir($dirname);
      drush_move_dir('jcarouselSwipe-0.3.5', '../jcarouselSwipe', TRUE);
      chdir('..');
      drush_delete_dir($dirname);
      $dirname = 'jcarouselSwipe';
    }
  }
  if (is_dir($dirname)) {
    drush_log(dt('jCarousel swipe plugin has been installed in @path', [
      '@path' => $path,
    ]), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the jCarousel swipe plugin to @path', [
      '@path' => $path,
    ]), 'error');
  }

  // Set working directory back to the previous working directory.
  chdir($olddir);
}