xref: /plugin/diagrams/helper.php (revision 317bdfc2bd4bf051cf5d349bd5d8d27dc2a0b6c5)
1<?php
2/**
3 * DokuWiki Plugin diagrams (Helper Component)
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Innovakom + CosmoCode <dokuwiki@cosmocode.de>
7 */
8class helper_plugin_diagrams extends \dokuwiki\Extension\Plugin
9{
10    /**
11     * Check if the given SVG is a diagrams.net diagram
12     *
13     * This is done by ensuring that the service host is part of the SVG header
14     *
15     * @param string $svg The raw SVG data (first 500 bytes are enough)
16     * @return bool
17     */
18    public function isDiagram($svg) {
19        $svg = substr($svg, 0, 500); // makes checking a tiny bit faster
20        $confServiceUrl = $this->getConf('service_url'); // like "https://diagrams.xyz.org/?embed=1&..."
21        $serviceHost = parse_url($confServiceUrl, PHP_URL_HOST); // Host-Portion of the Url, e.g. "diagrams.xyz.org"
22        return strpos($svg, 'embed.diagrams.net') || strpos($svg, 'draw.io') || strpos($svg, $serviceHost);
23    }
24}
25
26