You are here

function form_styler_plugin in jQuery form styler 7

Same name and namespace in other branches
  1. 7.2 drush/form_styler.drush.inc \form_styler_plugin()

Command to download the jQuery form styler plugin.

1 call to form_styler_plugin()
drush_form_styler_pre_pm_enable in drush/form_styler.drush.inc
Implements drush_MODULE_pre_pm_enable().
1 string reference to 'form_styler_plugin'
form_styler_drush_command in drush/form_styler.drush.inc
Implements hook_drush_command().

File

drush/form_styler.drush.inc, line 70
Drush integration for form_styler.

Code

function form_styler_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(FORM_STYLER_DOWNLOAD_URI)) {
    $filename = basename($filepath);
    $dirname = FORM_STYLER_DOWNLOAD_PREFIX . basename($filepath, '.zip');
    $dirname = 'jQueryFormStyler-1.7.8';

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

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

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

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