View source
<?php
define('PHOTOSWIPE_DOWNLOAD_URL', 'https://github.com/dimsemenov/PhotoSwipe/archive/v4.0.5.zip');
define('PHOTOSWIPE_DOWNLOAD_PREFIX', 'PhotoSwipe-');
function photoswipe_drush_command() {
$items = array();
$items['photoswipe-plugin'] = array(
'callback' => 'drush_photoswipe_plugin',
'description' => dt('Download and install the PhotoSwipe plugin.'),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the PhotoSwipe plugin. If omitted Drush will use the default location.'),
),
'aliases' => array(
'photoswipeplugin',
),
);
return $items;
}
function photoswipe_drush_help($section) {
switch ($section) {
case 'drush:photoswipe-plugin':
return dt('Download and install the PhotoSwipe plugin from GitHub, default location is sites/all/libraries.');
}
}
function drush_photoswipe_post_pm_enable() {
$modules = func_get_args();
if (in_array('photoswipe', $modules)) {
drush_photoswipe_plugin();
}
}
function drush_photoswipe_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(PHOTOSWIPE_DOWNLOAD_URL)) {
$filename = basename($filepath);
$dirname = PHOTOSWIPE_DOWNLOAD_PREFIX . ltrim(basename($filepath, '.zip'), 'v');
if (is_dir($dirname) || is_dir('photoswipe')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('photoswipe', TRUE);
drush_log(dt('A existing PhotoSwipe plugin was deleted from @path', array(
'@path' => $path,
)), 'notice');
}
drush_tarball_extract($filename);
if ($dirname != 'photoswipe') {
drush_move_dir($dirname, 'photoswipe', TRUE);
$dirname = 'photoswipe';
}
}
if (is_dir($dirname)) {
drush_log(dt('PhotoSwipe plugin has been installed in @path', array(
'@path' => $path,
)), 'success');
}
else {
drush_log(dt('Drush was unable to install the PhotoSwipe plugin to @path', array(
'@path' => $path,
)), 'error');
}
chdir($olddir);
}