function drush_imagelightbox_download in ImageLightbox 8
Same name and namespace in other branches
- 2.0.x imagelightbox.drush.inc \drush_imagelightbox_download()
Command to download the ImageLightBox library.
File
- ./
imagelightbox.drush.inc, line 36 - Drush integration for ImageLightBox module.
Code
function drush_imagelightbox_download($arg1 = '') {
if ($arg1 == '') {
$libraries_dir = 'libraries';
}
if (!is_dir($libraries_dir) && $arg1 == '') {
return drush_set_error('IMAGELIGHTBOX', dt('Directory @libraries_dir does not exist.', [
'@libraries_dir' => $libraries_dir,
]));
}
if (is_dir(IMAGELIGHTBOX_LIBRARY_DIR) && $arg1 == '') {
if (drush_confirm(dt('Install location @dir already exists. Do you want to overwrite it?', [
'@dir' => IMAGELIGHTBOX_LIBRARY_DIR,
]))) {
drush_delete_dir(IMAGELIGHTBOX_LIBRARY_DIR, TRUE);
}
}
if ($arg1 == 'mod_update') {
drush_shell_exec('wget --timeout=15 -O %s %s', IMAGELIGHTBOX_DELIVERED_LIBRARIES . '/imagelightbox.js', IMAGELIGHTBOX_DOWNLOAD_JS_URL);
drush_shell_exec('wget --timeout=15 -O %s %s', IMAGELIGHTBOX_DELIVERED_LIBRARIES . '/imagelightbox.min.js', IMAGELIGHTBOX_DOWNLOAD_JS_MIN_URL);
$js_file_found = drush_file_not_empty(IMAGELIGHTBOX_DELIVERED_LIBRARIES . '/imagelightbox.js');
$js_min_file_found = drush_file_not_empty(IMAGELIGHTBOX_DELIVERED_LIBRARIES . '/imagelightbox.min.js');
drush_shell_exec('cp %s/* %s', IMAGELIGHTBOX_DELIVERED_LIBRARIES, IMAGELIGHTBOX_LIBRARY_DIR);
drush_shell_exec('cp %s %s/imagelightbox.libraries.yml', IMAGELIGHTBOX_INSTALL_MODULE_LIBRARIES_YAML, IMAGELIGHTBOX_MODULE_DIR);
$log_dir = IMAGELIGHTBOX_DELIVERED_LIBRARIES;
}
elseif ($arg1 == '') {
drush_mkdir(IMAGELIGHTBOX_LIBRARY_DIR);
drush_shell_exec('wget --timeout=15 -O %s %s', IMAGELIGHTBOX_LIBRARY_DIR . '/imagelightbox.js', IMAGELIGHTBOX_DOWNLOAD_JS_URL);
drush_shell_exec('wget --timeout=15 -O %s %s', IMAGELIGHTBOX_LIBRARY_DIR . '/imagelightbox.min.js', IMAGELIGHTBOX_DOWNLOAD_JS_MIN_URL);
$js_file_found = drush_file_not_empty(IMAGELIGHTBOX_LIBRARY_DIR . '/imagelightbox.js');
$js_min_file_found = drush_file_not_empty(IMAGELIGHTBOX_LIBRARY_DIR . '/imagelightbox.min.js');
drush_shell_exec('cp %s/* %s', IMAGELIGHTBOX_DELIVERED_LIBRARIES, IMAGELIGHTBOX_LIBRARY_DIR);
drush_shell_exec('cp %s %s/imagelightbox.libraries.yml', IMAGELIGHTBOX_INSTALL_ROOT_LIBRARIES_YAML, IMAGELIGHTBOX_MODULE_DIR);
$log_dir = IMAGELIGHTBOX_LIBRARY_DIR;
}
if (!$js_file_found || !$js_min_file_found) {
return drush_set_error('IMAGELIGHTBOX', dt('imagelightbox library has not been installed.'));
}
else {
drush_log(dt('The newest ImageLightBox library has been installed in @path directory.', [
'@path' => $log_dir,
]), 'success');
}
}