View source
<?php
include_once 'responsive_navigation_common.inc';
function responsive_navigation_drush_command() {
$items = array();
$items['rnjs-plugin'] = array(
'callback' => 'drush_rnjs_plugin',
'description' => dt("Downloads the responsive-nav.js plugin."),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to install the responsive-nav.js plugin. If omitted Drush will use the default location.'),
),
'aliases' => array(
'rnjsplugin',
),
);
$items['rm-rnjs-plugin'] = array(
'callback' => 'drush_rmrnjs_plugin',
'description' => dt("Deletes the responsive-nav.js plugin."),
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
'arguments' => array(
'path' => dt('Optional. A path where to delete the responsive-nav.js plugin. If omitted Drush will use the default location.'),
),
'aliases' => array(
'rmrnjsplugin',
),
);
return $items;
}
function responsive_navigation_drush_help($section) {
switch ($section) {
case 'drush:rnjs-plugin':
return dt("Downloads the responsive-nav.js plugin, default location is sites/all/libraries.");
}
}
function drush_rnjs_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(RNJS_DOWNLOAD_URI)) {
$filename = basename($filepath);
$dirname = 'responsive-nav.js-' . basename($filepath, '.zip');
if (is_dir($dirname) || is_dir('responsive_navigation')) {
drush_delete_dir($dirname, TRUE);
drush_delete_dir('responsive_navigation', TRUE);
drush_log(dt('An existing responsive-nav.js plugin was deleted from @path', array(
'@path' => $path,
)), 'notice');
}
drush_tarball_extract($filename);
if ($dirname != 'responsive_navigation') {
drush_move_dir($dirname, 'responsive_navigation', TRUE);
$dirname = 'responsive_navigation';
}
}
if (is_dir($dirname)) {
drush_log(dt('responsive-nav.js plugin has been downloaded to @path', array(
'@path' => $path,
)), 'success');
}
else {
drush_log(dt('Drush was unable to download the responsive-nav.js plugin to @path', array(
'@path' => $path,
)), 'error');
}
chdir($olddir);
}
function drush_rmrnjs_plugin() {
$args = func_get_args();
if (!empty($args[0])) {
$path = $args[0];
}
else {
$path = 'sites/all/libraries';
}
if (!is_dir($path)) {
drush_log(dt('Directory @path was not found.', array(
'@path' => $path,
)), 'error');
}
$olddir = getcwd();
chdir($path);
if (is_dir('responsive_navigation')) {
drush_log(dt('The responsive_navigation directory was found at @path. Attempting to delete it.', array(
'@path' => $path,
)), 'notice');
if (drush_delete_dir('responsive_navigation', TRUE)) {
drush_log(dt('The responsive_navigation directory has been deleted in @path', array(
'@path' => $path,
)), 'success');
}
else {
drush_log(dt('Drush was unable to delete the responsive_navigation directory in @path', array(
'@path' => $path,
)), 'error');
}
}
else {
drush_log(dt('Drush was unable to find the responsive_navigation directory in @path', array(
'@path' => $path,
)), 'error');
}
chdir($olddir);
}