function _print_pdf_file_access_images in Printer, email and PDF versions 5.x
Same name and namespace in other branches
- 5.4 print_pdf/print_pdf.pages.inc \_print_pdf_file_access_images()
- 6 print_pdf/print_pdf.pages.inc \_print_pdf_file_access_images()
- 7 print_pdf/print_pdf.pages.inc \_print_pdf_file_access_images()
Convert image paths to the file:// protocol
In some Drupal setups, the use of the 'private' filesystem or Apache's configuration prevent access to the images of the page. This function tries to circumnvent those problems by accessing files in the local filesystem.
Parameters
$html: contents of the post-processed template already with the node data
See also
2 calls to _print_pdf_file_access_images()
- _print_pdf_dompdf in print_pdf/
print_pdf.pages.inc - Generate the PDF file using the dompdf library
- _print_pdf_tcpdf in print_pdf/
print_pdf.pages.inc - Generate the PDF file using the TCPDF library
File
- print_pdf/
print_pdf.pages.inc, line 116
Code
function _print_pdf_file_access_images($html) {
global $base_url, $language;
// 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) {
$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);
return $html;
}