private function export_attachments(array $attachments, post_entity $post, renderer_base $output, bool $canexport) : array {
        global $CFG;

        $urlfactory = $this->related['urlfactory'];
        $enableplagiarism = $CFG->enableplagiarism;
        $forum = $this->related['forum'];
        $context = $this->related['context'];

        if ($enableplagiarism) {
            require_once($CFG->libdir . '/plagiarismlib.php' );
        }

        return array_map(function($attachment) use (
            $output,
            $enableplagiarism,
            $canexport,
            $context,
            $forum,
            $post,
            $urlfactory
        ) {
            $exporter = new stored_file_exporter($attachment, ['context' => $context]);
            $exportedattachment = $exporter->export($output);
            $exporturl = $canexport ? $urlfactory->get_export_attachment_url_from_post_and_attachment($post, $attachment) : null;

            if ($enableplagiarism) {
                $plagiarismhtml = plagiarism_get_links([
                    'userid' => $post->get_author_id(),
                    'file' => $attachment,
                    'cmid' => $forum->get_course_module_record()->id,
                    'course' => $forum->get_course_id(),
                    'forum' => $forum->get_id()
                ]);
            } else {
                $plagiarismhtml = null;
            }

            $exportedattachment->urls = [
                'export' => $exporturl ? $exporturl->out(false) : null
            ];
            $exportedattachment->html = [
                'plagiarism' => $plagiarismhtml
            ];

            return $exportedattachment;
        }, $attachments);
    }