You are here

function download_shariff_library in Shariff Social Media Buttons 7

Command to download the Shariff library.

1 string reference to 'download_shariff_library'
shariff_drush_command in drush/shariff.drush.inc
Implements hook_drush_command().

File

drush/shariff.drush.inc, line 59
drush integration for Shariff.

Code

function download_shariff_library() {
  $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(SHARIFF_LIBRARY_DOWNLOAD_URI)) {
    $filename = basename($filepath);
    $dirname = basename($filepath, '.zip');

    // Remove any existing Shariff library directory.
    if (is_dir($dirname) || is_dir('shariff')) {
      drush_delete_dir($dirname, TRUE);
      drush_delete_dir('shariff', TRUE);
      drush_log(dt('Existing Shariff library was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }

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

    // Change the directory name to "shariff" if needed.
    if (is_dir('master')) {
      drush_move_dir('master/shariff-master', 'shariff', TRUE);

      // Removes leftover master dir.
      drush_delete_dir('master', TRUE);
    }
    $dirname = 'shariff';
  }
  if (is_dir($dirname)) {
    drush_log(dt('The Shariff library has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the Shariff library to @path', array(
      '@path' => $path,
    )), 'error');
  }

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