You are here

function imagezoom_drush_download in Image Zoom 7.2

Drush command to download the elevateZoom-Plus library.

1 string reference to 'imagezoom_drush_download'
imagezoom_drush_command in ./imagezoom.drush.inc
Implements hook_drush_command().

File

./imagezoom.drush.inc, line 41
Drush integration for Image Zoom.

Code

function imagezoom_drush_download() {
  $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');
  }
  if (is_writable($path)) {
    $olddir = getcwd();
    chdir($path);
    if ($filepath = drush_download_file(IMAGEZOOM_DOWNLOAD_URI)) {
      $filename = basename($filepath);
      $dirname = IMAGEZOOM_DOWNLOAD_PREFIX . basename($filepath, '.zip');
      if (is_dir($dirname) || is_dir('elevatezoom-plus')) {
        drush_delete_dir($dirname, TRUE);
        drush_delete_dir('elevatezoom-plus', TRUE);
        drush_log(dt('The existing elevateZoom-Plus library was deleted from @path', array(
          '@path' => $path,
        )), 'notice');
      }
      drush_tarball_extract($filename);
      if ($dirname != 'elevatezoom-plus') {
        drush_move_dir($dirname, 'elevatezoom-plus', TRUE);
        $dirname = 'elevatezoom-plus';
      }
    }
    if (is_dir($dirname)) {
      drush_log(dt('The elevateZoom-Plus library has been installed in @path', array(
        '@path' => $path,
      )), 'success');
    }
    else {
      drush_log(dt('Drush was unable to install the elevateZoom-Plus library to @path', array(
        '@path' => $path,
      )), 'error');
    }
    chdir($olddir);
  }
  else {
    drush_log(dt('Drush was unable to install the elevateZoom-Plus library because @path is not writable.', array(
      '@path' => $path,
    )), 'warning');
  }
}