View source
<?php
define('FORM_STYLER_DOWNLOAD_URI', 'https://github.com/Dimox/jQueryFormStyler/archive/master.zip');
define('FORM_STYLER_DOWNLOAD_PREFIX', 'form_styler-');
function form_styler_drush_command() {
$items = array();
$items['form-styler-plugin'] = array(
'callback' => 'form_styler_plugin',
'description' => dt('Download and install the Form styler plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the form styler plugin. If omitted Drush will use the default location.'),
),
'aliases' => array(
'fsplugin',
),
);
return $items;
}
function form_styler_drush_help($section) {
switch ($section) {
case 'drush:form-styler-plugin':
return dt('Download and install the Form styler plugin from Dimox/jQueryFormStyler, default location is sites/all/libraries.');
}
}
function drush_form_styler_pre_pm_enable() {
$modules = drush_get_context('PM_ENABLE_MODULES');
if (in_array('form_styler', $modules) && !drush_get_option('skip')) {
form_styler_plugin();
}
}
function form_styler_plugin() {
$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');
}
$olddir = getcwd();
chdir($path);
if ($filepath = drush_download_file(FORM_STYLER_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = FORM_STYLER_DOWNLOAD_PREFIX . basename($filepath, '.zip');
$dirname = 'jQueryFormStyler-master';
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');
}
drush_tarball_extract($filename);
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');
}
chdir($olddir);
}