From 4c56a767b6d3a80a144a032e5b56715ee1e44cb1 Mon Sep 17 00:00:00 2001 From: Joao Ventura Date: Sun, 25 Jul 2010 17:24:54 +0000 Subject: [PATCH] Fix #726082: Remove dependency on allow_url_fopen by converting all image URLs to local files --- print_pdf/print_pdf.pages.inc | 34 +++++++++++++++++++--------------- 1 files changed, 19 insertions(+), 15 deletions(-) diff --git a/print_pdf/print_pdf.pages.inc b/print_pdf/print_pdf.pages.inc index b53f6f0..72716b8 100644 --- a/print_pdf/print_pdf.pages.inc +++ b/print_pdf/print_pdf.pages.inc @@ -43,23 +43,27 @@ function print_pdf_controller() { $print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']); $print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']); // And converted from private to public paths + switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) { + case LANGUAGE_NEGOTIATION_PATH_DEFAULT: + case LANGUAGE_NEGOTIATION_PATH: + $lang = $language->language; + break; + default: + $lang = ''; + break; + } $file_downloads = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC); if ($file_downloads == FILE_DOWNLOADS_PRIVATE) { - switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) { - case LANGUAGE_NEGOTIATION_PATH_DEFAULT: - case LANGUAGE_NEGOTIATION_PATH: - $lang = $language->language; - break; - default: - $lang = ''; - break; - } - $pattern = "!(]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files(/[^>]*?>)!is"; - $replacement = '$1file://'. realpath(file_directory_path()) .'$2'; - $print['content'] = preg_replace($pattern, $replacement, $print['content']); - $print['logo'] = preg_replace($pattern, $replacement, $print['logo']); - $print['footer_message'] = preg_replace($pattern, $replacement, $print['footer_message']); + $pattern = "!(]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?system/files/([^>]*?>)!is"; + $replacement = '$1file://'. realpath(file_directory_path()) .'/$2'; } + else { + $pattern = "!(]*?src\s*?=\s*?['\"]?)${base_url}/(?:(?:index.php)?\?q=)?(?:${lang}/)?([^>]*?>)!is"; + $replacement = '$1file://'. realpath($_SERVER["DOCUMENT_ROOT"].base_path()) .'/$2'; + } + $print['content'] = preg_replace($pattern, $replacement, $print['content']); + $print['logo'] = preg_replace($pattern, $replacement, $print['logo']); + $print['footer_message'] = preg_replace($pattern, $replacement, $print['footer_message']); // Send to printer option causes problems with PDF $print['sendtoprinter'] = ''; @@ -290,7 +294,7 @@ function _print_pdf_tcpdf($print, $html, $filename) { */ function _print_pdf_wkhtmltopdf($print, $html, $filename) { $print_pdf_pdf_tool = variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT); - $print_pdf_paper_size = drupal_strtolower(variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT)); + $print_pdf_paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT); $print_pdf_page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT); $print_pdf_content_disposition = variable_get('print_pdf_content_disposition', PRINT_PDF_CONTENT_DISPOSITION_DEFAULT); $print_pdf_wkhtmltopdf_options = variable_get('print_pdf_wkhtmltopdf_options', PRINT_PDF_WKHTMLTOPDF_OPTIONS); -- 1.7.4.1