Commit 0b05b59f authored by jcnventura's avatar jcnventura

Issue #1158678: PDF image access via the local system is now configurable (default off).

parent f161a3f1
......@@ -176,6 +176,12 @@ function print_pdf_settings() {
'#default_value' => variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT),
'#description' => t('Choose the page orientation of the generated PDF.'),
);
$form['settings']['print_pdf_images_via_file'] = array(
'#type' => 'checkbox',
'#title' => t('Access images via local file access'),
'#default_value' => variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT),
'#description' => t("Enabling this option will make the tool use local file access for image files. This option is not recommended to use in conjunction with modules like imagecache which generate the image after it's first accessed. However, it may be necessary in low-end hosting services where the web server is not allowed to open URLs and the user can't modify that configuration setting."),
);
$form['settings']['print_pdf_autoconfig'] = array(
'#type' => 'checkbox',
'#title' => t('Auto-configure the PDF tool settings'),
......
......@@ -41,6 +41,7 @@ function print_pdf_uninstall() {
variable_del('print_pdf_content_disposition');
variable_del('print_pdf_paper_size');
variable_del('print_pdf_page_orientation');
variable_del('print_pdf_images_via_file');
variable_del('print_pdf_font_family');
variable_del('print_pdf_font_size');
variable_del('print_pdf_link_text');
......
......@@ -28,6 +28,7 @@ define('PRINT_PDF_PDF_TOOL_DEFAULT', 0);
define('PRINT_PDF_CONTENT_DISPOSITION_DEFAULT', 2);
define('PRINT_PDF_PAPER_SIZE_DEFAULT', 'A4');
define('PRINT_PDF_PAGE_ORIENTATION_DEFAULT', 'portrait');
define('PRINT_PDF_IMAGES_VIA_FILE_DEFAULT', 0);
define('PRINT_PDF_AUTOCONFIG_DEFAULT', 1);
define('PRINT_PDF_FONT_FAMILY_DEFAULT', 'dejavusans');
define('PRINT_PDF_FONT_SIZE_DEFAULT', 10);
......@@ -628,6 +629,10 @@ function print_pdf_link_allowed($args) {
*/
function _print_pdf_tcpdf_version() {
$print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT);
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
// prevent TCPDF default configs
define('K_TCPDF_EXTERNAL_CONFIG', TRUE);
}
require_once(DRUPAL_ROOT . '/' . $print_pdf_pdf_tool);
$pdf = new TCPDF();
......
......@@ -126,10 +126,10 @@ function print_pdf_generate_html($print, $html, $filename = NULL) {
*/
function _print_pdf_file_access_images($html) {
global $base_url, $language;
$print_pdf_images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
// TODO: This needs to be rewritten from scratch for Drupal 7
/*
// And converted from private to public paths
switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) {
case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
case LANGUAGE_NEGOTIATION_PATH:
......@@ -139,15 +139,18 @@ function _print_pdf_file_access_images($html) {
$lang = '';
break;
}
// Always convert private to local paths
$file_downloads = variable_get('file_default_scheme', 'public');
if ($file_downloads == 'private') {
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is";
$replacement = '$1file://' . realpath(file_directory_path()) . '/$2';
$html = preg_replace($pattern, $replacement, $html);
}
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
$replacement = '$1file://' . dirname($_SERVER['SCRIPT_FILENAME']) . '/$2';
$html = preg_replace($pattern, $replacement, $html);
elseif ($print_pdf_images_via_file) {
$pattern = "!(<img\s[^>]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is";
$replacement = '$1file://' . dirname($_SERVER['SCRIPT_FILENAME']) . '/$2';
$html = preg_replace($pattern, $replacement, $html);
}
*/
return $html;
}
......@@ -477,9 +480,8 @@ function theme_print_pdf_tcpdf_header($vars) {
$ratio = 0;
$logo = '';
$logo_ret = preg_match('!src\s*=\s*(\'.*?\'|".*?"|[^\s]*)!i', $tpl_logo[1], $matches);
if ($logo_ret) {
$logo = trim($matches[1], '\'"');
if (preg_match('!src\s*=\s*(?:\'(.*?)\'|"(.*?)"|([^\s]*))!i', $tpl_logo[1], $logo_url)) {
$logo = $logo_url[1];
$size = getimagesize($logo);
$ratio = $size ? ($size[0] / $size[1]) : 0;
}
......@@ -487,9 +489,9 @@ function theme_print_pdf_tcpdf_header($vars) {
// set header font
$pdf->setHeaderFont($vars['font']);
// set header margin
$pdf->SetHeaderMargin(5);
$pdf->setHeaderMargin(5);
// set header data
$pdf->SetHeaderData($logo, 10 * $ratio, html_entity_decode($tpl_title[1], ENT_QUOTES, 'UTF-8'), html_entity_decode(strip_tags($tpl_site_name[1]), ENT_QUOTES, 'UTF-8'));
$pdf->setHeaderData($logo, 10 * $ratio, html_entity_decode($tpl_title[1], ENT_QUOTES, 'UTF-8'), html_entity_decode(strip_tags($tpl_site_name[1]), ENT_QUOTES, 'UTF-8'));
return $pdf;
}
......
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