Commit d094f841 authored by Robert Lyon's avatar Robert Lyon
Browse files

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: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent 340687dd
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -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+)(?:&amp;|&|%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