Project

General

Profile

Paste
Download (1.95 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / print / print_pdf / lib_handlers / print_pdf_wkhtmltopdf / print_pdf_wkhtmltopdf.drush.inc @ 76bdcd04

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', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz');
13
define('WKHTMLTOPDF_LNX32_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-i386.tar.xz');
14
define('WKHTMLTOPDF_WIN64_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3.2/wkhtmltox-0.12.3.2_msvc2013-win64.exe');
15
define('WKHTMLTOPDF_WIN32_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3.2/wkhtmltox-0.12.3.2_msvc2013-win32.exe');
16
define('WKHTMLTOPDF_OSX64_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_osx-cocoa-x86-64.pkg');
17
define('WKHTMLTOPDF_OSX32_DOWNLOAD_URI', 'http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_osx-carbon-i386.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
      $ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_LNX64_DOWNLOAD_URI : WKHTMLTOPDF_LNX32_DOWNLOAD_URI;
40
      break;
41

    
42
    case 'Win':
43
      $ret = WKHTMLTOPDF_WIN32_DOWNLOAD_URI;
44
      break;
45

    
46
    case 'Dar':
47
      $ret = (php_uname('m') == 'x86_64') ? WKHTMLTOPDF_OSX64_DOWNLOAD_URI : WKHTMLTOPDF_OSX32_DOWNLOAD_URI;
48
      break;
49

    
50
    default:
51
      drush_log(dt('wkhtmltopdf is not supported in this system, please choose another library.'), 'error');
52
      break;
53
  }
54

    
55
  return $ret;
56
}