1 |
c8740e19
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* drush integration for highlightjs.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* The highlightjs plugin URI.
|
10 |
|
|
*/
|
11 |
|
|
define('HIGHLIGHTJS_DOWNLOAD_URI', 'https://github.com/components/highlightjs/archive/master.zip');
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Implementation of 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 highlight_js_drush_command() {
|
29 |
|
|
$items = array();
|
30 |
|
|
|
31 |
|
|
// The key in the $items array is the name of the command.
|
32 |
|
|
$items['highlightjs-plugin'] = array(
|
33 |
|
|
'callback' => 'drush_highlightjs_plugin',
|
34 |
|
|
'description' => dt('Download and install the highlight js plugin.'),
|
35 |
|
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUSH, // No bootstrap.
|
36 |
|
|
'arguments' => array(
|
37 |
|
|
'path' => dt('Optional. A path where to install the highlight js plugin. If omitted Drush will use the default location.'),
|
38 |
|
|
),
|
39 |
|
|
'aliases' => array('highlightjs'),
|
40 |
|
|
);
|
41 |
|
|
|
42 |
|
|
return $items;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Implementation of 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 highlight_js_drush_help($section) {
|
58 |
|
|
switch ($section) {
|
59 |
|
|
case 'drush:highlightjs-plugin':
|
60 |
|
|
return dt('Download and install the highlight js plugin, default location is sites/all/libraries.');
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Command to download the highlightjs plugin.
|
66 |
|
|
*/
|
67 |
|
|
function drush_highlightjs_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(HIGHLIGHTJS_DOWNLOAD_URI)) {
|
88 |
|
|
$filename = basename($filepath);
|
89 |
|
|
$dirname = 'highlightjs-master';
|
90 |
|
|
|
91 |
|
|
// Remove any existing highlightjs plugin directory.
|
92 |
|
|
if (is_dir($dirname) || is_dir('highlightjs')) {
|
93 |
|
|
drush_delete_dir($dirname, TRUE);
|
94 |
|
|
drush_delete_dir('highlightjs', TRUE);
|
95 |
|
|
drush_log(dt('A existing highlight js 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 "highlightjs" if needed.
|
102 |
|
|
if ($dirname != 'highlightjs') {
|
103 |
|
|
drush_move_dir($dirname, 'highlightjs', TRUE);
|
104 |
|
|
$dirname = 'highlightjs';
|
105 |
|
|
}
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
if (is_dir($dirname)) {
|
109 |
|
|
drush_log(dt('highlight js plugin has been installed in @path', array('@path' => $path)), 'success');
|
110 |
|
|
}
|
111 |
|
|
else {
|
112 |
|
|
drush_log(dt('Drush was unable to install the highlightjs plugin to @path', array('@path' => $path)), 'error');
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
// Set working directory back to the previous working directory.
|
116 |
|
|
chdir($olddir);
|
117 |
|
|
} |