You are here

function drush_photoswipe_plugin in PhotoSwipe 7.2

Same name and namespace in other branches
  1. 8.2 drush/photoswipe.drush.inc \drush_photoswipe_plugin()
  2. 8 drush/photoswipe.drush.inc \drush_photoswipe_plugin()
  3. 3.x drush/photoswipe.drush.inc \drush_photoswipe_plugin()

Command to download the PhotoSwipe plugin.

1 call to drush_photoswipe_plugin()
drush_photoswipe_post_pm_enable in drush/photoswipe.drush.inc
Implements drush_MODULE_post_pm_enable().
1 string reference to 'drush_photoswipe_plugin'
photoswipe_drush_command in drush/photoswipe.drush.inc
Implements hook_drush_command().

File

drush/photoswipe.drush.inc, line 57
Drush integration for PhotoSwipe.

Code

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

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

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

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

    // Remove any existing PhotoSwipe plugin directory
    if (is_dir($dirname) || is_dir('photoswipe')) {
      drush_delete_dir($dirname, TRUE);
      drush_delete_dir('photoswipe', TRUE);
      drush_log(dt('A existing PhotoSwipe plugin was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }

    // Decompress the zip archive
    drush_tarball_extract($filename);

    // Change the directory name to "photoswipe" if needed.
    if ($dirname != 'photoswipe') {
      drush_move_dir($dirname, 'photoswipe', TRUE);
      $dirname = 'photoswipe';
    }
  }
  if (is_dir($dirname)) {
    drush_log(dt('PhotoSwipe plugin has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the PhotoSwipe plugin to @path', array(
      '@path' => $path,
    )), 'error');
  }

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