1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Drush integration for Superfish.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* The Superfish plugin URI.
|
10
|
*/
|
11
|
define('SUPERFISH_DOWNLOAD_URI', 'https://github.com/mehrpadin/Superfish-for-Drupal/archive/1.x.zip');
|
12
|
|
13
|
/**
|
14
|
* Implements hook_drush_command().
|
15
|
*
|
16
|
* In this hook, you specify which commands your
|
17
|
* drush module makes available, what it does and
|
18
|
* description.
|
19
|
*
|
20
|
* Notice how this structure closely resembles how
|
21
|
* you define menu hooks.
|
22
|
*
|
23
|
* See `drush topic docs-commands` for a list of recognized keys.
|
24
|
*
|
25
|
* @return
|
26
|
* An associative array describing your command(s).
|
27
|
*/
|
28
|
function superfish_drush_command() {
|
29
|
$items = array();
|
30
|
|
31
|
// the key in the $items array is the name of the command.
|
32
|
$items['superfish-plugin'] = array(
|
33
|
'callback' => 'drush_superfish_plugin',
|
34
|
'description' => dt("Downloads the Superfish plugin."),
|
35
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
|
36
|
'arguments' => array(
|
37
|
'path' => dt('Optional. A path where to install the Superfish plugin. If omitted Drush will use the default location.'),
|
38
|
),
|
39
|
'aliases' => array('superfishplugin'),
|
40
|
);
|
41
|
|
42
|
return $items;
|
43
|
}
|
44
|
|
45
|
/**
|
46
|
* Implements hook_drush_help().
|
47
|
*
|
48
|
* This function is called whenever a drush user calls
|
49
|
* 'drush help <name-of-your-command>'
|
50
|
*
|
51
|
* @param
|
52
|
* A string with the help section (prepend with 'drush:')
|
53
|
*
|
54
|
* @return
|
55
|
* A string with the help text for your command.
|
56
|
*/
|
57
|
function superfish_drush_help($section) {
|
58
|
switch ($section) {
|
59
|
case 'drush:superfish-plugin':
|
60
|
return dt("Downloads the Superfish plugin, default location is sites/all/libraries.");
|
61
|
}
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Command to download the Superfish plugin.
|
66
|
*/
|
67
|
function drush_superfish_plugin() {
|
68
|
$args = func_get_args();
|
69
|
if (!empty($args[0])) {
|
70
|
$path = $args[0];
|
71
|
}
|
72
|
else {
|
73
|
$path = 'sites/all/libraries';
|
74
|
}
|
75
|
|
76
|
// Create the path if it does not exist.
|
77
|
if (!is_dir($path)) {
|
78
|
drush_op('mkdir', $path);
|
79
|
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
|
80
|
}
|
81
|
|
82
|
// Set the directory to the download location.
|
83
|
$olddir = getcwd();
|
84
|
chdir($path);
|
85
|
|
86
|
// Download the zip archive
|
87
|
if ($filepath = drush_download_file(SUPERFISH_DOWNLOAD_URI)) {
|
88
|
$filename = basename($filepath);
|
89
|
$dirname = 'Superfish-for-Drupal-' . basename($filepath, '.zip');
|
90
|
|
91
|
// Remove any existing Superfish plugin directory
|
92
|
if (is_dir($dirname) || is_dir('superfish')) {
|
93
|
drush_delete_dir($dirname, TRUE);
|
94
|
drush_delete_dir('superfish', TRUE);
|
95
|
drush_log(dt('A existing Superfish plugin was deleted from @path', array('@path' => $path)), 'notice');
|
96
|
}
|
97
|
|
98
|
// Decompress the zip archive
|
99
|
drush_tarball_extract($filename);
|
100
|
|
101
|
// Change the directory name to "superfish" if needed.
|
102
|
if ($dirname != 'superfish') {
|
103
|
drush_move_dir($dirname, 'superfish', TRUE);
|
104
|
$dirname = 'superfish';
|
105
|
}
|
106
|
}
|
107
|
|
108
|
if (is_dir($dirname)) {
|
109
|
drush_log(dt('Superfish plugin has been uploaded to @path', array('@path' => $path)), 'success');
|
110
|
}
|
111
|
else {
|
112
|
drush_log(dt('Drush was unable to upload the Superfish plugin to @path', array('@path' => $path)), 'error');
|
113
|
}
|
114
|
|
115
|
// Set working directory back to the previous working directory.
|
116
|
chdir($olddir);
|
117
|
}
|