public function PdfFormat::removeImageTokens in Printer and PDF versions for Drupal 8+ 8
Same name and namespace in other branches
- 2.x modules/printable_pdf/src/Plugin/PrintableFormat/PdfFormat.php \Drupal\printable_pdf\Plugin\PrintableFormat\PdfFormat::removeImageTokens()
Remove tokens from images so we just get the path.
1 call to PdfFormat::removeImageTokens()
- PdfFormat::getResponse in modules/
printable_pdf/ src/ Plugin/ PrintableFormat/ PdfFormat.php - Returns the response object for this format plugin.
File
- modules/
printable_pdf/ src/ Plugin/ PrintableFormat/ PdfFormat.php, line 261
Class
- PdfFormat
- Provides a plugin to display a PDF version of a page.
Namespace
Drupal\printable_pdf\Plugin\PrintableFormatCode
public function removeImageTokens($subject) {
// We only need to do this for absolute paths, not external images, so
// search for mentions of DRUPAL_ROOT.
$next_pos = strpos($subject, DRUPAL_ROOT);
while ($next_pos !== FALSE) {
$have_matches = preg_match('/[\\s\'"]/', substr($subject, $next_pos), $matches, PREG_OFFSET_CAPTURE);
$path_end = $have_matches ? $matches[0][1] : strlen($subject) - $next_pos + 1;
$query_start = strpos(substr($subject, $next_pos, $path_end), '?');
if ($query_start !== false) {
$subject = substr($subject, 0, $next_pos + $query_start) . substr($subject, $next_pos + $path_end);
}
$next_pos = strpos($subject, DRUPAL_ROOT, $next_pos + $path_end - $query_start + 1);
}
return $subject;
}