colorbox.drush.inc in Colorbox 8
Drush integration for colorbox.
File
drush/colorbox.drush.inc
View source
<?php
use Symfony\Component\Filesystem\Filesystem;
define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/master.zip');
define('COLORBOX_DOWNLOAD_PREFIX', 'colorbox-');
function colorbox_drush_command() {
$items = [];
$items['colorbox-plugin'] = [
'callback' => 'drush_colorbox_plugin',
'description' => dt('Download and install the Colorbox plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => [
'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'),
],
'aliases' => [
'colorboxplugin',
],
];
return $items;
}
function colorbox_drush_help($section) {
switch ($section) {
case 'drush:colorbox-plugin':
return dt('Download and install the Colorbox plugin from jacklmoore.com/colorbox, default location is the libraries directory.');
}
}
function drush_colorbox_plugin() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'libraries';
}
if (!is_dir($path)) {
drush_op('mkdir', $path);
\Drupal::logger(dt('Directory @path was created', [
'@path' => $path,
]))
->notice('notice');
}
$olddir = getcwd();
chdir($path);
if ($filepath = drush_download_file(COLORBOX_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = COLORBOX_DOWNLOAD_PREFIX . basename($filepath, '.zip');
if (is_dir($dirname) || is_dir('colorbox')) {
Filesystem::remove($dirname, TRUE);
Filesystem::remove('colorbox', TRUE);
\Drupal::logger(dt('A existing Colorbox plugin was deleted from @path', [
'@path' => $path,
]))
->notice('notice');
}
drush_tarball_extract($filename);
if ($dirname != 'colorbox') {
drush_move_dir($dirname, 'colorbox', TRUE);
$dirname = 'colorbox';
}
}
if (is_dir($dirname)) {
\Drupal::logger(dt('Colorbox plugin has been installed in @path', [
'@path' => $path,
]))
->success('success');
}
else {
\Drupal::logger(dt('Drush was unable to install the Colorbox plugin to @path', [
'@path' => $path,
]))
->error('error');
}
chdir($olddir);
}