function drush_jq_maphilight_download in jQuery Map Hilight 7
Command to download the Maphilight plugin.
1 string reference to 'drush_jq_maphilight_download'
- jq_maphilight_drush_command in drush/
jq_maphilight.drush.inc - Implements hook_drush_command().
File
- drush/
jq_maphilight.drush.inc, line 74 - drush integration for maphilight, based on colorbox.drush.inc.
Code
function drush_jq_maphilight_download() {
if (!drush_shell_exec('type unzip')) {
return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
}
$args = func_get_args();
if (isset($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);
$filename = basename(MAPHILIGHT_DOWNLOAD_URI);
// Remove any existing Maphilight plugin directory
if (is_dir(MAPHILIGHT_DIRECTORY)) {
drush_shell_exec('rm -rf ' . MAPHILIGHT_DIRECTORY);
drush_log(dt('An existing Maphilight plugin was deleted from @path', array(
'@path' => $path,
)), 'notice');
}
// Remove any existing Maphilight plugin zip archive
if (is_file($filename)) {
drush_op('unlink', $filename);
}
// Download the zip archive
if (!drush_shell_exec('wget ' . MAPHILIGHT_DOWNLOAD_URI)) {
drush_shell_exec('curl -O ' . MAPHILIGHT_DOWNLOAD_URI);
}
if (is_file($filename)) {
// Decompress the zip archive
drush_shell_exec('unzip -qq -o ' . $filename);
// Remove the zip archive
drush_op('unlink', $filename);
// Rename the uncompressed directory.
drush_op('rename', MAPHILIGHT_ARCHIVE_DIR, MAPHILIGHT_DIRECTORY);
}
// Set working directory back to the previous working directory.
chdir($olddir);
if (is_dir($path . '/' . MAPHILIGHT_DIRECTORY)) {
drush_log(dt('Maphilight plugin has been downloaded to @path', array(
'@path' => $path,
)), 'success');
}
else {
drush_log(dt('Drush was unable to download the Maphilight plugin to @path', array(
'@path' => $path,
)), 'error');
}
}