From 52572aa7ad4714ab7875802c0b70b03150cd9c86 Mon Sep 17 00:00:00 2001 From: Kevin Kaland <kevin@wizonesolutions.com> Date: Mon, 31 Dec 2012 15:17:25 +0100 Subject: [PATCH] Issue #1876832: Fix pdftk path check. --- fillpdf.admin.inc | 2 +- fillpdf.module | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fillpdf.admin.inc b/fillpdf.admin.inc index 1634645..892c028 100644 --- a/fillpdf.admin.inc +++ b/fillpdf.admin.inc @@ -36,7 +36,7 @@ function fillpdf_settings($form, &$form_state) { } // Check for pdftk. - $status = fillpdf_pdftk_check(variable_get('fillpdf_pdftk_path', 'pdftk')); + $status = fillpdf_pdftk_check(fillpdf_pdftk_path()); if ($status === FALSE) { $options['pdftk'] .= '<div class="messages warning">' . t('pdftk is not properly installed.') . '</div>'; } diff --git a/fillpdf.module b/fillpdf.module index c20b8aa..a0698b7 100644 --- a/fillpdf.module +++ b/fillpdf.module @@ -710,7 +710,7 @@ function fillpdf_execute_merge($method, $fields, $fillpdf, $mode = 'url', $flatt $xfdffile = file_save_data($xfdf, $xfdfname, FILE_EXISTS_RENAME); // Now feed this to pdftk and save the result to a variable - $path_to_pdftk = variable_get('fillpdf_pdftk_path', 'pdftk'); + $path_to_pdftk = fillpdf_pdftk_path(); ob_start(); passthru($path_to_pdftk . ' ' . escapeshellarg(drupal_realpath($filename)) . ' fill_form ' . escapeshellarg(drupal_realpath($xfdffile->uri)) . ' output - ' . ($flatten ? 'flatten ' : '') . 'drop_xfa'); $data = ob_get_clean(); @@ -807,7 +807,7 @@ function fillpdf_execute_parse($method, $fillpdf, $mode = 'url') { break; } - $path_to_pdftk = variable_get('fillpdf_pdftk_path', 'pdftk'); + $path_to_pdftk = fillpdf_pdftk_path(); $status = fillpdf_pdftk_check($path_to_pdftk); if ($status === FALSE) { drupal_set_message(t('pdftk not properly installed.'), 'error'); @@ -1014,3 +1014,13 @@ function fillpdf_pdftk_check($pdftk_path = 'pdftk') { return TRUE; } +// This is a convenience wrapper around variable_get(). It lets us **also** +// return "pdftk" if the variable is empty, not just unset. +function fillpdf_pdftk_path() { + $path_to_pdftk = variable_get('fillpdf_pdftk_path', 'pdftk'); + if ($path_to_pdftk) { + return $path_to_pdftk; + } + return 'pdftk'; +} + -- GitLab