1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides drush integration for print_epub module EPUB libraries download.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_drush_command().
|
10
|
*/
|
11
|
function print_epub_drush_command() {
|
12
|
$items = array();
|
13
|
|
14
|
$epub_libs = array();
|
15
|
drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
|
16
|
|
17
|
$items['print-epub-download'] = array(
|
18
|
'description' => 'Download and extract a EPUB library.',
|
19
|
'arguments' => array(
|
20
|
'library' => dt('The EPUB library to download. Available choices: !libs.', array('!libs' => implode(', ', array_keys($epub_libs)))),
|
21
|
),
|
22
|
'options' => array(
|
23
|
'path' => dt('A path to the download folder. If omitted Drush will use the default location (@path).', array('@path' => 'sites/all/libraries')),
|
24
|
),
|
25
|
'aliases' => array('epubdl'),
|
26
|
// No site or config needed.
|
27
|
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_ROOT,
|
28
|
);
|
29
|
|
30
|
return $items;
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* Implements drush_hook_COMMAND_validate().
|
35
|
*/
|
36
|
function drush_print_epub_download_validate($library = NULL) {
|
37
|
if (is_null($library)) {
|
38
|
$epub_libs = array();
|
39
|
drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
|
40
|
|
41
|
drush_set_error('DRUSH_EPUBDL_MISSING_ARG', dt("Usage: drush !cmd <library>\nWhere <library> is one of the following: !libs\n\nTry 'drush !cmd --help' for more information.", array(
|
42
|
'!cmd' => 'print-epub-download',
|
43
|
'!libs' => implode(', ', array_keys($epub_libs)),
|
44
|
)));
|
45
|
}
|
46
|
}
|
47
|
|
48
|
/**
|
49
|
* Download and extract EPUB archive.
|
50
|
*
|
51
|
* @param string $library
|
52
|
* Library to download.
|
53
|
*/
|
54
|
function drush_print_epub_download($library) {
|
55
|
$epub_libs = array();
|
56
|
drush_command_invoke_all_ref('drush_epub_libs_alter', $epub_libs);
|
57
|
|
58
|
if (isset($library) && isset($epub_libs[drupal_strtolower($library)])) {
|
59
|
$func = $epub_libs[drupal_strtolower($library)]['callback'];
|
60
|
|
61
|
$download_url = $func();
|
62
|
if ($download_url) {
|
63
|
_print_drush_download_lib($library, $download_url);
|
64
|
}
|
65
|
}
|
66
|
else {
|
67
|
drush_log(dt('Please specify a EPUB library. Available choices: !libs.', array('!libs' => implode(', ', array_keys($epub_libs)))), 'error');
|
68
|
}
|
69
|
}
|