You are here

function drush_download_placeholder_library in Form Placeholder 7

Command to download the jQuery Placeholder plugin.

1 string reference to 'drush_download_placeholder_library'
form_placeholder_drush_command in ./form_placeholder.drush.inc
Implements hook_drush_command().

File

./form_placeholder.drush.inc, line 30
Drush integration for Form Placeholder.

Code

function drush_download_placeholder_library() {
  if (!module_exists('libraries')) {
    return drush_log(dt("Libraries module doesn't exists."), 'error');
  }
  $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);
  $placeholder_library = libraries_info('jquery.placeholder');
  if ($filepath = drush_download_file($placeholder_library['download url'])) {
    $filename = basename($filepath);
    $dirname = 'jquery-placeholder-' . $placeholder_library['version'];

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

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

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

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