1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
b433176d
|
Assos Assos
|
* Drush integration for colorbox.
|
6 |
85ad3d82
|
Assos Assos
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* The Colorbox plugin URI.
|
10 |
|
|
*/
|
11 |
|
|
define('COLORBOX_DOWNLOAD_URI', 'https://github.com/jackmoore/colorbox/archive/1.x.zip');
|
12 |
|
|
define('COLORBOX_DOWNLOAD_PREFIX', 'colorbox-');
|
13 |
|
|
|
14 |
|
|
/**
|
15 |
b433176d
|
Assos Assos
|
* Implements hook_drush_command().
|
16 |
85ad3d82
|
Assos Assos
|
*
|
17 |
|
|
* In this hook, you specify which commands your
|
18 |
|
|
* drush module makes available, what it does and
|
19 |
|
|
* description.
|
20 |
|
|
*
|
21 |
|
|
* Notice how this structure closely resembles how
|
22 |
|
|
* you define menu hooks.
|
23 |
|
|
*
|
24 |
|
|
* See `drush topic docs-commands` for a list of recognized keys.
|
25 |
|
|
*
|
26 |
b433176d
|
Assos Assos
|
* @codingStandardsIgnoreLine
|
27 |
39a3d70c
|
Assos Assos
|
* @return array
|
28 |
85ad3d82
|
Assos Assos
|
* An associative array describing your command(s).
|
29 |
|
|
*/
|
30 |
|
|
function colorbox_drush_command() {
|
31 |
|
|
$items = array();
|
32 |
|
|
|
33 |
b433176d
|
Assos Assos
|
// The key in the $items array is the name of the command.
|
34 |
85ad3d82
|
Assos Assos
|
$items['colorbox-plugin'] = array(
|
35 |
|
|
'callback' => 'drush_colorbox_plugin',
|
36 |
|
|
'description' => dt('Download and install the Colorbox plugin.'),
|
37 |
b433176d
|
Assos Assos
|
// No bootstrap.
|
38 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
39 |
85ad3d82
|
Assos Assos
|
'arguments' => array(
|
40 |
|
|
'path' => dt('Optional. A path where to install the Colorbox plugin. If omitted Drush will use the default location.'),
|
41 |
|
|
),
|
42 |
|
|
'aliases' => array('colorboxplugin'),
|
43 |
|
|
);
|
44 |
|
|
|
45 |
|
|
return $items;
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
/**
|
49 |
b433176d
|
Assos Assos
|
* Implements hook_drush_help().
|
50 |
85ad3d82
|
Assos Assos
|
*
|
51 |
|
|
* This function is called whenever a drush user calls
|
52 |
|
|
* 'drush help <name-of-your-command>'
|
53 |
|
|
*
|
54 |
b433176d
|
Assos Assos
|
* @codingStandardsIgnoreLine
|
55 |
39a3d70c
|
Assos Assos
|
* @param string $section
|
56 |
85ad3d82
|
Assos Assos
|
* A string with the help section (prepend with 'drush:')
|
57 |
|
|
*
|
58 |
b433176d
|
Assos Assos
|
* @codingStandardsIgnoreLine
|
59 |
39a3d70c
|
Assos Assos
|
* @return string
|
60 |
85ad3d82
|
Assos Assos
|
* A string with the help text for your command.
|
61 |
|
|
*/
|
62 |
|
|
function colorbox_drush_help($section) {
|
63 |
|
|
switch ($section) {
|
64 |
|
|
case 'drush:colorbox-plugin':
|
65 |
|
|
return dt('Download and install the Colorbox plugin from jacklmoore.com/colorbox, default location is sites/all/libraries.');
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
39a3d70c
|
Assos Assos
|
* Implements drush_MODULE_pre_pm_enable().
|
71 |
85ad3d82
|
Assos Assos
|
*/
|
72 |
39a3d70c
|
Assos Assos
|
function drush_colorbox_pre_pm_enable() {
|
73 |
b433176d
|
Assos Assos
|
$modules = drush_get_context('PM_ENABLE_MODULES');
|
74 |
|
|
if (in_array('colorbox', $modules) && !drush_get_option('skip')) {
|
75 |
|
|
drush_colorbox_plugin();
|
76 |
|
|
}
|
77 |
39a3d70c
|
Assos Assos
|
}
|
78 |
85ad3d82
|
Assos Assos
|
|
79 |
|
|
/**
|
80 |
|
|
* Command to download the Colorbox plugin.
|
81 |
|
|
*/
|
82 |
|
|
function drush_colorbox_plugin() {
|
83 |
|
|
$args = func_get_args();
|
84 |
|
|
if (!empty($args[0])) {
|
85 |
|
|
$path = $args[0];
|
86 |
|
|
}
|
87 |
|
|
else {
|
88 |
|
|
$path = 'sites/all/libraries';
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
// Create the path if it does not exist.
|
92 |
|
|
if (!is_dir($path)) {
|
93 |
|
|
drush_op('mkdir', $path);
|
94 |
|
|
drush_log(dt('Directory @path was created', array('@path' => $path)), 'notice');
|
95 |
|
|
}
|
96 |
|
|
|
97 |
b08fce64
|
Assos Assos
|
// Download colorbox plugin only if path is writable.
|
98 |
|
|
if (is_writable($path)) {
|
99 |
|
|
// Set the directory to the download location.
|
100 |
|
|
$olddir = getcwd();
|
101 |
|
|
chdir($path);
|
102 |
|
|
|
103 |
b433176d
|
Assos Assos
|
// Download the zip archive.
|
104 |
b08fce64
|
Assos Assos
|
if ($filepath = drush_download_file(COLORBOX_DOWNLOAD_URI)) {
|
105 |
|
|
$filename = basename($filepath);
|
106 |
|
|
$dirname = COLORBOX_DOWNLOAD_PREFIX . basename($filepath, '.zip');
|
107 |
|
|
|
108 |
|
|
// Remove any existing Colorbox plugin directory.
|
109 |
|
|
if (is_dir($dirname) || is_dir('colorbox')) {
|
110 |
|
|
drush_delete_dir($dirname, TRUE);
|
111 |
|
|
drush_delete_dir('colorbox', TRUE);
|
112 |
|
|
drush_log(dt('A existing Colorbox plugin was deleted from @path', array('@path' => $path)), 'notice');
|
113 |
|
|
}
|
114 |
|
|
|
115 |
b433176d
|
Assos Assos
|
// Decompress the zip archive.
|
116 |
b08fce64
|
Assos Assos
|
drush_tarball_extract($filename);
|
117 |
|
|
|
118 |
|
|
// Change the directory name to "colorbox" if needed.
|
119 |
|
|
if ($dirname != 'colorbox') {
|
120 |
|
|
drush_move_dir($dirname, 'colorbox', TRUE);
|
121 |
|
|
$dirname = 'colorbox';
|
122 |
|
|
}
|
123 |
85ad3d82
|
Assos Assos
|
}
|
124 |
|
|
|
125 |
b08fce64
|
Assos Assos
|
if (is_dir($dirname)) {
|
126 |
|
|
drush_log(dt('Colorbox plugin has been installed in @path', array('@path' => $path)), 'success');
|
127 |
|
|
}
|
128 |
|
|
else {
|
129 |
|
|
drush_log(dt('Drush was unable to install the Colorbox plugin to @path', array('@path' => $path)), 'error');
|
130 |
85ad3d82
|
Assos Assos
|
}
|
131 |
|
|
|
132 |
b08fce64
|
Assos Assos
|
// Set working directory back to the previous working directory.
|
133 |
|
|
chdir($olddir);
|
134 |
85ad3d82
|
Assos Assos
|
}
|
135 |
|
|
else {
|
136 |
b08fce64
|
Assos Assos
|
drush_log(dt('Drush was unable to install the Colorbox plugin because @path is not writable. If you enable the colorbox module before you install the plugin library, you may find that colorbox does not work until you reinstall the colorbox module.', array('@path' => $path)), 'warning');
|
137 |
85ad3d82
|
Assos Assos
|
}
|
138 |
|
|
} |