From bd2c77dfec2dfd937f15fbb0782ec69fa791283d Mon Sep 17 00:00:00 2001 From: Robert Lyon Date: Mon, 6 May 2019 14:00:40 +1200 Subject: [PATCH] Bug 1698699: Rewrite path to PDF in HTML export This patch rewrites the path to the html export version of the PDF file behatnotneeded Change-Id: I8d534af41258d219046e5f3586bf904777242cb9 Signed-off-by: Robert Lyon (cherry picked from commit d094f841794de2bf137a031fa44845c0a3441df2) (cherry picked from commit 9b29d17eab9bb07240300c380d37ae63849d2e16) --- htdocs/export/html/lib.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/htdocs/export/html/lib.php b/htdocs/export/html/lib.php index 9f63e6de4a..4e3609d992 100644 --- a/htdocs/export/html/lib.php +++ b/htdocs/export/html/lib.php @@ -732,6 +732,13 @@ class HtmlExportOutputFilter { $html ); + // Links to pdf block files + $html = preg_replace_callback( + '#(?<=[\'"])(' . $wwwroot . ')?/?artefact/file/blocktype/pdf/viewer\.php\?.*?file=(\d+)(?:&|&|%26).*?(?=[\'"])#', + array($this, 'replace_pdf_link'), + $html + ); + // Thumbnails require_once('file.php'); $html = preg_replace_callback( @@ -828,6 +835,28 @@ class HtmlExportOutputFilter { return $this->get_export_path_for_file($artefact, $options); } + /** + * Callback to replace links to artefact/file/blocktype/pdf/viewer.php to point to the + * correct file in the HTML export + */ + private function replace_pdf_link($matches) { + $artefactid = $matches[2]; + try { + $artefact = artefact_instance_from_id($artefactid); + } + catch (ArtefactNotFoundException $e) { + return ''; + } + + // If artefact type not something that would be served by download.php, + // replace link with nothing + if ($artefact->get_plugin_name() != 'file') { + return ''; + } + + return $this->get_export_path_for_file($artefact, array()); + } + /** * Callback to replace links to thumb.php to point to the correct file in * the HTML export -- GitLab