1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Provides drush integration for print_pdf_wkhtmltopdf module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* The PDF project download URL.
|
10
|
*/
|
11
|
// Since wkhtmltopdf is a binary, a different URL is required for each platform.
|
12
|
define('WKHTMLTOPDF_LNX64_DOWNLOAD_URI', 'https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz');
|
13
|
define('WKHTMLTOPDF_LNX32_DOWNLOAD_URI', 'https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz');
|
14
|
define('WKHTMLTOPDF_WIN64_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.msvc2015-win64.exe');
|
15
|
define('WKHTMLTOPDF_WIN32_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.msvc2015-win32.exe');
|
16
|
define('WKHTMLTOPDF_OSX64_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.macos-cocoa.pkg');
|
17
|
define('WKHTMLTOPDF_OSX32_DOWNLOAD_URI', 'https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.macos-carbon.pkg');
|
18
|
|
19
|
/**
|
20
|
* Implements hook_drush_command().
|
21
|
*/
|
22
|
function print_pdf_wkhtmltopdf_drush_pdf_libs_alter(&$pdf_libs) {
|
23
|
$pdf_libs['wkhtmltopdf'] = array(
|
24
|
'callback' => '_print_pdf_wkhtmltopdf_drush_download_url',
|
25
|
);
|
26
|
}
|
27
|
|
28
|
/**
|
29
|
* Discover the correct URL of the package to download.
|
30
|
*
|
31
|
* @return string
|
32
|
* URL of the file to download, FALSE if not known
|
33
|
*/
|
34
|
function _print_pdf_wkhtmltopdf_drush_download_url() {
|
35
|
$ret = FALSE;
|
36
|
|
37
|
switch (drupal_substr(php_uname('s'), 0, 3)) {
|
38
|
case 'Lin':
|
39
|
drush_log(dt('Please note that generic Linux builds are no longer being generated. See https://wkhtmltopdf.org/downloads.html.'), 'warning');
|
40
|
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_LNX64_DOWNLOAD_URI : WKHTMLTOPDF_LNX32_DOWNLOAD_URI;
|
41
|
break;
|
42
|
|
43
|
case 'Win':
|
44
|
$ret = WKHTMLTOPDF_WIN32_DOWNLOAD_URI;
|
45
|
break;
|
46
|
|
47
|
case 'Dar':
|
48
|
$ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_OSX64_DOWNLOAD_URI : WKHTMLTOPDF_OSX32_DOWNLOAD_URI;
|
49
|
break;
|
50
|
|
51
|
default:
|
52
|
drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
|
53
|
break;
|
54
|
}
|
55
|
|
56
|
return $ret;
|
57
|
}
|