1 |
0ece262b
|
Assos Assos
|
<?php
|
2 |
a2bb1a14
|
Assos Assos
|
|
3 |
0ece262b
|
Assos Assos
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Drush integration for Views Slideshow.
|
6 |
|
|
*
|
7 |
|
|
* Specifically downloading of required and optional JavaScript libraries.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
/**
|
11 |
|
|
* Implements hook_drush_command().
|
12 |
|
|
*/
|
13 |
|
|
function views_slideshow_cycle_drush_command() {
|
14 |
|
|
$items = array();
|
15 |
|
|
|
16 |
|
|
// The key in the $items array is the name of the command.
|
17 |
|
|
$items['views-slideshow-cycle-cycle'] = array(
|
18 |
|
|
'description' => dt('Download and install the jQuery Cycle library.'),
|
19 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
20 |
|
|
'arguments' => array(
|
21 |
|
|
'path' => dt('Optional. The path to install the jQuery Cycle library in. If omitted Drush will use the default location.'),
|
22 |
|
|
),
|
23 |
|
|
'aliases' => array('dl-cycle'),
|
24 |
|
|
);
|
25 |
|
|
$items['views-slideshow-cycle-json2'] = array(
|
26 |
|
|
'description' => dt('Download and install the JSON2 library.'),
|
27 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
28 |
|
|
'arguments' => array(
|
29 |
|
|
'path' => dt('Optional. The path to install the JSON2 library in. If omitted Drush will use the default location.'),
|
30 |
|
|
),
|
31 |
|
|
'aliases' => array('dl-json2'),
|
32 |
|
|
);
|
33 |
|
|
$items['views-slideshow-cycle-hoverintent'] = array(
|
34 |
|
|
'description' => dt('Download and install the jquery.hoverIntent library.'),
|
35 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
36 |
|
|
'arguments' => array(
|
37 |
|
|
'path' => dt('Optional. The path to install the jquery.hoverIntent library in. If omitted Drush will use the default location.'),
|
38 |
|
|
),
|
39 |
|
|
'aliases' => array('dl-hoverintent'),
|
40 |
|
|
);
|
41 |
|
|
$items['views-slideshow-cycle-pause'] = array(
|
42 |
|
|
'description' => dt('Download and install the jQuery.pause library.'),
|
43 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
44 |
|
|
'arguments' => array(
|
45 |
|
|
'path' => dt('Optional. The path to install the jQuery.pause library in. If omitted Drush will use the default location.'),
|
46 |
|
|
),
|
47 |
|
|
'aliases' => array('dl-pause'),
|
48 |
|
|
);
|
49 |
7547bb19
|
Assos Assos
|
$items['views-slideshow-cycle-easing'] = array(
|
50 |
|
|
'description' => dt('Download and install the jQuery.easing library.'),
|
51 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
52 |
|
|
'arguments' => array(
|
53 |
|
|
'path' => dt('Optional. The path to install the jQuery.easing library in. If omitted Drush will use the default location.'),
|
54 |
|
|
),
|
55 |
|
|
'aliases' => array('dl-easing'),
|
56 |
|
|
);
|
57 |
0ece262b
|
Assos Assos
|
$items['views-slideshow-cycle-lib'] = array(
|
58 |
|
|
'description' => dt('Download and install the jQuery Cycle, jQuery hoverIntent and JSON2 libraries.'),
|
59 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
|
60 |
|
|
'aliases' => array('dl-cycle-lib'),
|
61 |
|
|
);
|
62 |
|
|
return $items;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Implements hook_drush_help().
|
67 |
|
|
*/
|
68 |
|
|
function views_slideshow_cycle_drush_help($section) {
|
69 |
|
|
switch ($section) {
|
70 |
|
|
case 'drush:views-slideshow-cycle-cycle':
|
71 |
|
|
return dt('Download and install the jQuery Cycle library from http://malsup.github.com/jquery.cycle.all.js, default location is libraries/jquery.cycle.');
|
72 |
|
|
|
73 |
|
|
case 'drush:views-slideshow-cycle-hoverintent':
|
74 |
|
|
return dt('Download and install the jQuery hoverIntent library from https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js, default location is libraries/jquery.cycle.');
|
75 |
|
|
|
76 |
|
|
case 'drush:views-slideshow-cycle-pause':
|
77 |
|
|
return dt('Download and install the jQuery pause library from https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js, default location is libraries/jquery.pause.');
|
78 |
|
|
|
79 |
7547bb19
|
Assos Assos
|
case 'drush:views-slideshow-cycle-easing':
|
80 |
|
|
return dt('Download and install the jQuery pause library from http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js, default location is libraries/jquery.easing.');
|
81 |
|
|
|
82 |
0ece262b
|
Assos Assos
|
case 'drush:views-slideshow-cycle-json2':
|
83 |
|
|
return dt('Download and install the JSON2 library from https://github.com/douglascrockford/JSON-js/, default location is libraries/json2.');
|
84 |
|
|
|
85 |
|
|
case 'drush:views-slideshow-cycle-lib':
|
86 |
|
|
return dt('Download and install the jQuery Cycle, jQuery hoverIntent and JSON2 libraries.');
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* Command to download the jQuery Cycle library.
|
92 |
|
|
*/
|
93 |
|
|
function drush_views_slideshow_cycle_cycle() {
|
94 |
|
|
_drush_views_slideshow_cycle_install_library(
|
95 |
|
|
'jQuery Cycle',
|
96 |
|
|
'libraries/jquery.cycle',
|
97 |
|
|
'jquery.cycle.all.js',
|
98 |
|
|
'http://malsup.github.com/jquery.cycle.all.js',
|
99 |
|
|
func_get_args()
|
100 |
|
|
);
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Command to download the JSON2 library.
|
105 |
|
|
*/
|
106 |
|
|
function drush_views_slideshow_cycle_json2() {
|
107 |
|
|
_drush_views_slideshow_cycle_install_library(
|
108 |
|
|
'JSON2',
|
109 |
|
|
'libraries/json2',
|
110 |
|
|
'json2.js',
|
111 |
|
|
'https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js',
|
112 |
|
|
func_get_args()
|
113 |
|
|
);
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
/**
|
117 |
|
|
* Command to download the jQuery.hoverIntent library.
|
118 |
|
|
*/
|
119 |
|
|
function drush_views_slideshow_cycle_hoverintent() {
|
120 |
|
|
_drush_views_slideshow_cycle_install_library(
|
121 |
|
|
'jQuery HoverIntent',
|
122 |
|
|
'libraries/jquery.hoverIntent',
|
123 |
|
|
'jquery.hoverIntent.js',
|
124 |
|
|
'https://raw.githubusercontent.com/briancherne/jquery-hoverIntent/master/jquery.hoverIntent.js',
|
125 |
|
|
func_get_args()
|
126 |
|
|
);
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
/**
|
130 |
|
|
* Command to download the jQuery.pause library.
|
131 |
|
|
*/
|
132 |
|
|
function drush_views_slideshow_cycle_pause() {
|
133 |
|
|
_drush_views_slideshow_cycle_install_library(
|
134 |
|
|
'jQuery Pause',
|
135 |
|
|
'libraries/jquery.pause',
|
136 |
|
|
'jquery.pause.js',
|
137 |
|
|
'https://raw.githubusercontent.com/tobia/Pause/master/jquery.pause.js',
|
138 |
|
|
func_get_args()
|
139 |
|
|
);
|
140 |
|
|
}
|
141 |
|
|
|
142 |
7547bb19
|
Assos Assos
|
/**
|
143 |
|
|
* Command to download the jQuery.pause library.
|
144 |
|
|
*/
|
145 |
|
|
function drush_views_slideshow_cycle_easing() {
|
146 |
|
|
_drush_views_slideshow_cycle_install_library(
|
147 |
|
|
'jQuery easing',
|
148 |
|
|
'libraries/jquery.easing',
|
149 |
|
|
'jquery.easing.1.3.js',
|
150 |
|
|
'http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js',
|
151 |
|
|
func_get_args()
|
152 |
|
|
);
|
153 |
|
|
}
|
154 |
|
|
|
155 |
0ece262b
|
Assos Assos
|
/**
|
156 |
|
|
* Command to download all libraries.
|
157 |
|
|
*/
|
158 |
|
|
function drush_views_slideshow_cycle_lib() {
|
159 |
|
|
drush_views_slideshow_cycle_cycle();
|
160 |
|
|
drush_views_slideshow_cycle_json2();
|
161 |
|
|
drush_views_slideshow_cycle_hoverintent();
|
162 |
|
|
drush_views_slideshow_cycle_pause();
|
163 |
7547bb19
|
Assos Assos
|
drush_views_slideshow_cycle_easing();
|
164 |
0ece262b
|
Assos Assos
|
}
|
165 |
|
|
|
166 |
|
|
/**
|
167 |
|
|
* Implements drush_MODULE_pre_pm_enable().
|
168 |
|
|
*/
|
169 |
|
|
function drush_views_slideshow_cycle_pre_pm_enable() {
|
170 |
|
|
$modules = drush_get_context('PM_ENABLE_MODULES');
|
171 |
|
|
if (in_array('views_slideshow_cycle', $modules) && !drush_get_option('skip')) {
|
172 |
|
|
drush_views_slideshow_cycle_lib();
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
/**
|
177 |
|
|
* Helper function to download a library in the given directory.
|
178 |
|
|
*/
|
179 |
|
|
function _drush_views_slideshow_cycle_install_library($name, $path, $filename, $url, $args) {
|
180 |
|
|
// Check if path provided as an arg and use that instead of default if so.
|
181 |
|
|
if (!empty($args[0])) {
|
182 |
|
|
$path = $args[0];
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
// Create the path if it does not exist.
|
186 |
|
|
if (!is_dir($path)) {
|
187 |
|
|
drush_op('mkdir', $path, 0755, TRUE);
|
188 |
|
|
drush_log(dt('Directory @path was created', array('@path' => $path)), 'success');
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
// Be sure we can write in the directory.
|
192 |
|
|
$perms = substr(sprintf('%o', fileperms($path)), -4);
|
193 |
|
|
if ($perms !== '0755') {
|
194 |
|
|
drush_shell_exec('chmod 755 ' . $path);
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
$dir = getcwd();
|
198 |
|
|
|
199 |
|
|
// Download the JavaScript file.
|
200 |
|
|
if (is_file($path . '/' . $filename)) {
|
201 |
|
|
drush_log(dt('@name appears to be already installed.', array(
|
202 |
|
|
'@name' => $name,
|
203 |
|
|
)), 'ok');
|
204 |
|
|
}
|
205 |
|
|
elseif (drush_op('chdir', $path) && drush_shell_exec('wget --no-check-certificate ' . $url)) {
|
206 |
|
|
drush_log(dt('The latest version of @name has been downloaded to @path', array(
|
207 |
|
|
'@name' => $name,
|
208 |
|
|
'@path' => $path,
|
209 |
|
|
)), 'success');
|
210 |
|
|
}
|
211 |
|
|
else {
|
212 |
|
|
drush_log(dt('Drush was unable to download the @name library to @path', array(
|
213 |
|
|
'@name' => $name,
|
214 |
|
|
'@path' => $path,
|
215 |
|
|
)), 'error');
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
chdir($dir);
|
219 |
|
|
|
220 |
|
|
// Restore the previous permissions.
|
221 |
|
|
drush_shell_exec('chmod ' . $perms . ' ' . $path);
|
222 |
|
|
} |