Commit ab3fb881 authored by jcnventura's avatar jcnventura

Issue #1538026 partly by pirog: use PDF temporary dirs in Drupal's file system path.

parent 58556571
......@@ -16,9 +16,10 @@ define('PRINT_PDF_DOMPDF_FONT_SUBSETTING_DEFAULT', FALSE);
function print_pdf_dompdf_pdf_tool_info() {
return array(
'name' => 'dompdf',
'url' => 'http://code.google.com/p/dompdf/downloads/list',
'expand_css' => FALSE,
'write_dirs' => array(
'lib/fonts',
'public_dirs' => array(
'fonts',
),
);
}
......@@ -55,57 +56,9 @@ function print_pdf_dompdf_menu() {
}
/**
* Implements hook_requirements().
* Implements hook_pdf_tool_version().
*/
function print_pdf_dompdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (!empty($print_pdf_pdf_tool)) {
$tool = explode('|', $print_pdf_pdf_tool);
if (is_file($tool[1]) && is_readable($tool[1])) {
if (basename($tool[1]) == 'dompdf_config.inc.php') {
$version = _print_pdf_dompdf_version($tool[1]);
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('dompdf') . ' ' . $version,
);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$directory = dirname($tool[1]) . '/lib/fonts';
if (!is_dir($directory) || !is_writable($directory)) {
$requirements['print_pdf_tool'] = array(
'title' => $t('DOMPDF font cache directory'),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => 'dompdf', '%libdir' => $directory)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
}
break;
}
return $requirements;
}
/**
* Find out the version of the dompdf library
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
*
* @return string
* version number of the dompdf library
*/
function _print_pdf_dompdf_version($pdf_tool) {
function print_pdf_dompdf_pdf_tool_version($pdf_tool) {
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
// Poor man's way to find dompdf version
......
......@@ -32,6 +32,7 @@ function print_pdf_dompdf_print_pdf_generate($html, $meta, $filename = NULL) {
define('DOMPDF_TEMP_DIR', file_directory_temp());
define('DOMPDF_UNICODE_ENABLED', $unicode);
define('DOMPDF_ENABLE_FONTSUBSETTING', $font_subsetting);
define('DOMPDF_FONT_CACHE', 'public://print_pdf/print_pdf_dompdf/fonts/');
}
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
......
......@@ -13,67 +13,22 @@
function print_pdf_mpdf_pdf_tool_info() {
return array(
'name' => 'mPDF',
'url' => 'http://www.mpdf1.com/mpdf/download',
'expand_css' => FALSE,
'write_dirs' => array(
'graph_cache',
'public_dirs' => array(
'ttfontdata',
'tmp',
),
'tool_dirs' => array(
'graph_cache',
),
);
}
/**
* Implements hook_requirements().
*/
function print_pdf_mpdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (!empty($print_pdf_pdf_tool)) {
$tool = explode('|', $print_pdf_pdf_tool);
if (is_file($tool[1]) && is_readable($tool[1])) {
if (basename($tool[1]) == 'mpdf.php') {
$version = _print_pdf_mpdf_version($tool[1]);
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('mPDF') . ' ' . $version,
);
foreach (array('graph_cache', 'ttfontdata', 'tmp') as $dir) {
$directory = dirname($tool[1]) . '/' . $dir;
if (!is_dir($directory) || !is_writable($directory)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('mPDF library'),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => 'mPDF', '%libdir' => $directory)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
}
break;
}
return $requirements;
}
/**
* Find out the version of the mpdf library
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
*
* @return string
* version number of the mpdf library
* Implements hook_pdf_tool_version().
*/
function _print_pdf_mpdf_version($pdf_tool) {
function print_pdf_mpdf_pdf_tool_version($pdf_tool) {
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
if (defined('mPDF_VERSION')) {
......
......@@ -22,6 +22,11 @@ function print_pdf_mpdf_print_pdf_generate($html, $meta, $filename = NULL) {
$content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT);
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
define('_MPDF_TTFONTDATAPATH', 'public://print_pdf/print_pdf_mpdf/ttfontdata/');
define("_MPDF_TEMP_PATH", 'public://print_pdf/print_pdf_mpdf/tmp/');
}
require_once(DRUPAL_ROOT . '/' . $pdf_tool[1]);
$format = ($page_orientation == "landscape") ? $paper_size . "-L" : $paper_size;
......
......@@ -17,9 +17,13 @@ define('PRINT_PDF_TCPDF_FONT_SUBSETTING_DEFAULT', FALSE);
function print_pdf_tcpdf_pdf_tool_info() {
return array(
'name' => 'TCPDF',
'min_version' => '5.9.001',
'url' => 'http://sourceforge.net/projects/tcpdf/files/latest',
'expand_css' => TRUE,
'write_dirs' => array(
'public_dirs' => array(
'cache',
),
'tool_dirs' => array(
'images',
),
);
......@@ -73,69 +77,9 @@ function print_pdf_tcpdf_menu() {
}
/**
* Implements hook_requirements().
*/
function print_pdf_tcpdf_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
// At runtime, make sure that a PDF generation tool is selected
case 'runtime':
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (!empty($print_pdf_pdf_tool)) {
$tool = explode('|', $print_pdf_pdf_tool);
if (is_file($tool[1]) && is_readable($tool[1])) {
if (basename($tool[1]) == 'tcpdf.php') {
$version = _print_pdf_tcpdf_version($tool[1]);
if (version_compare($version, '5.9.001', '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported TCPDF version'),
'description' => $t('The currently selected version of TCPDF (@version) is not supported. Please update to a !url.', array('@version' => $version, '!url' => l($t('newer version'), 'http://sourceforge.net/projects/tcpdf/files/latest'))),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('TCPDF') . ' ' . $version,
);
}
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
foreach (array('cache', 'images') as $dir) {
$directory = dirname($tool[1]) . '/' . $dir;
if (!is_dir($directory) || !is_writable($directory)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('TCPDF directory'),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => 'TCPDF', '%libdir' => $directory)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
}
}
break;
}
return $requirements;
}
/**
* Find out the version of the TCPDF library
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
*
* @return string
* version number of the tcpdf library
* Implements hook_pdf_tool_version().
*/
function _print_pdf_tcpdf_version($pdf_tool) {
function print_pdf_tcpdf_pdf_tool_version($pdf_tool) {
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
// prevent TCPDF default configs
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
......
......@@ -31,7 +31,7 @@ function print_pdf_tcpdf_print_pdf_generate($html, $meta, $filename = NULL) {
define('K_PATH_MAIN', dirname($_SERVER['SCRIPT_FILENAME']));
define('K_PATH_URL', $base_url);
define('K_PATH_FONTS', $pdf_tool_path . '/fonts/');
define('K_PATH_CACHE', $pdf_tool_path . '/cache/');
define('K_PATH_CACHE', 'public://print_pdf/print_pdf_tcpdf/cache/');
define('K_PATH_IMAGES', '');
define('K_BLANK_IMAGE', $pdf_tool_path . '/images/_blank.png');
define('K_CELL_HEIGHT_RATIO', 1.25);
......
......@@ -15,8 +15,9 @@ define('PRINT_PDF_WKHTMLTOPDF_OPTIONS', "--footer-font-size 7 --footer-right '[p
function print_pdf_wkhtmltopdf_pdf_tool_info() {
return array(
'name' => 'wkhtmltopdf',
'min_version' => '0.9.6',
'url' => 'http://code.google.com/p/wkhtmltopdf/downloads/list',
'expand_css' => FALSE,
'write_dirs' => array(),
);
}
......@@ -55,30 +56,13 @@ function print_pdf_wkhtmltopdf_requirements($phase) {
if (is_file($tool[1]) && is_readable($tool[1])) {
if (drupal_substr(basename($tool[1], '.exe'), 0, 11) == 'wkhtmltopdf') {
if (function_exists('is_executable') && !is_executable($tool[1])) {
$requirements['print_pdf_tool'] = array(
$requirements['print_pdf_wkhtmltopdf'] = array(
'title' => $t('wkhtmltopdf library'),
'value' => $t('Non-executable permissions'),
'description' => $t('You must modify the permissions of the wkhtmltopdf file (%file) to make it executable.', array('%file' => $tool[1])),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$version = _print_pdf_wkhtmltopdf_version($tool[1]);
if (version_compare($version, '0.9.6', '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported wkhtmltopdf version'),
'description' => $t('The currently selected version of wkhtmltopdf (@version) is not supported. Please update to a !url.', array('@version' => $version, '!url' => l($t('newer version'), 'http://code.google.com/p/wkhtmltopdf/'))),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('wkhtmltopdf') . ' ' . $version,
);
}
}
}
}
}
......@@ -88,15 +72,9 @@ function print_pdf_wkhtmltopdf_requirements($phase) {
}
/**
* Find out the version of the wkhtmltopdf library
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
*
* @return string
* version number of the wkhtmltopdf library
* Implements hook_pdf_tool_version().
*/
function _print_pdf_wkhtmltopdf_version($pdf_tool) {
function print_pdf_wkhtmltopdf_pdf_tool_version($pdf_tool) {
$descriptor = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$cmd = '"' . realpath($pdf_tool) . '" --version';
......@@ -121,7 +99,7 @@ function print_pdf_wkhtmltopdf_print_pdf_available_libs_alter(&$pdf_tools) {
$tools = _print_scan_libs('wkhtmltopdf', '!^wkhtmltopdf!');
foreach ($tools as $tool) {
$version = _print_pdf_wkhtmltopdf_version($tool);
$version = print_pdf_wkhtmltopdf_pdf_tool_version($tool);
$pdf_tools['print_pdf_wkhtmltopdf|' . $tool] = 'wkhtmltopdf ' . $version . ' (' . $tool . ')';
}
......
......@@ -16,25 +16,51 @@
* @return
* Associative array with the following data:
* - name: name of the PDF library.
* - min_version: minimum version of the PDF library supported by the
* module.
* - url: URL where the PDF library can be downloaded from.
* - expand_css: boolean flag indicating whether to expand the CSS files
* in the HTML passed to the PDF library, or to leave it as a list of
* include directives.
* - write_dirs: directories to which the tool requires write-access.
* - public_dirs: directories to which the tool requires write-access,
* with configurable locations.
* - tool_dirs: directories to which the tool requires write-access, but
* can't be configured, and are relative to the tool's root path.
*
* @ingroup print_hooks
*/
function hook_pdf_tool_info() {
return array(
'name' => 'foopdf',
'min_version' => '1.0',
'url' => 'http://www.pdf.tool/download',
'expand_css' => FALSE,
'write_dirs' => array(
'public_dirs' => array(
'fonts',
'cache',
'tmp',
),
'tool_dirs' => array(
'xyz',
),
);
}
/**
* Find out the version of the PDF library
*
* @param string $pdf_tool
* Filename of the tool to be analysed.
*
* @return string
* version number of the library
*/
function hook_pdf_tool_version() {
require_once(DRUPAL_ROOT . '/' . $pdf_tool);
return '1.0';
}
/**
* Generate a PDF version of the provided HTML.
*
......
......@@ -49,6 +49,27 @@ function print_pdf_permission() {
);
}
/**
* Implements hook_init().
*/
function print_pdf_init() {
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
if (function_exists($function)) {
$info = $function();
}
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directory = 'public://print_pdf/' . $tool[0] . '/' . $dir;
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
}
}
}
}
/**
* Implements hook_menu().
*/
......@@ -134,8 +155,14 @@ function print_pdf_requirements($phase) {
);
}
else {
// Tool is defined, get some data from it's handler module
$tool = explode('|', $print_pdf_pdf_tool);
$function = $tool[0] . '_pdf_tool_info';
if (function_exists($function)) {
$info = $function();
}
// Is the file there?
if (!is_file($tool[1]) || !is_readable($tool[1])) {
$requirements['print_pdf_tool'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
......@@ -144,6 +171,55 @@ function print_pdf_requirements($phase) {
'severity' => REQUIREMENT_ERROR,
);
}
else {
// Get the version number
$function = $tool[0] . '_pdf_tool_version';
if (function_exists($function)) {
$version = $function($tool[1]);
}
if (isset($info['min_version']) && version_compare($version, $info['min_version'], '<')) {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $t('Unsupported %lib version', array('%lib' => $info['name'])),
'description' => $t('The currently selected version of %lib (@version) is not supported. Please update to a !url.',
array('%lib' => $info['name'], '@version' => $version, '!url' => l($t('newer version'), $info['url']))),
'severity' => REQUIREMENT_ERROR,
);
}
else {
$requirements['print_pdf_tool_version'] = array(
'title' => $t('Printer, email and PDF versions - PDF generation library'),
'value' => $info['name'] . ' ' . $version,
);
}
}
// If auto-config is on, check for write access to the appropriate dirs
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
$directories = array();
if (isset($info['public_dirs'])) {
foreach ($info['public_dirs'] as $dir) {
$directories[] = 'public://print_pdf/' . $tool[0] . '/' . $dir;
}
}
if (isset($info['tool_dirs'])) {
foreach ($info['tool_dirs'] as $dir) {
$directories[] = dirname($tool[1]) . '/' . $dir;
}
}
foreach ($directories as $dir) {
if (!is_dir($dir) || !is_writable($dir)) {
$requirements['print_pdf_tool_' . $dir] = array(
'title' => $t('%lib directory', array('%lib' => $info['name'])),
'value' => $t('Non-writable permissions'),
'description' => $t('You must change the %libdir permissions to be writable, as %lib requires write-access to that directory.', array('%lib' => $info['name'], '%libdir' => $dir)),
'severity' => REQUIREMENT_ERROR,
);
}
}
}
}
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment