xref: /plugin/openlayersmap/action.php (revision a760825c0aa6eee7ec491397b3516b6237e4ad78)
138a47c60SMark Prins<?php
2*a760825cSgithub-actions[bot]
3*a760825cSgithub-actions[bot]use dokuwiki\Extension\ActionPlugin;
4*a760825cSgithub-actions[bot]use dokuwiki\Extension\EventHandler;
5*a760825cSgithub-actions[bot]use dokuwiki\Extension\Event;
6*a760825cSgithub-actions[bot]
738a47c60SMark Prins/*
8bea711feSMark Prins * Copyright (c) 2008 Mark C. Prins <mprins@users.sf.net>
938a47c60SMark Prins *
1038a47c60SMark Prins * Permission to use, copy, modify, and distribute this software for any
1138a47c60SMark Prins * purpose with or without fee is hereby granted, provided that the above
1238a47c60SMark Prins * copyright notice and this permission notice appear in all copies.
1338a47c60SMark Prins *
1438a47c60SMark Prins * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1538a47c60SMark Prins * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1638a47c60SMark Prins * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1738a47c60SMark Prins * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1838a47c60SMark Prins * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1938a47c60SMark Prins * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
2038a47c60SMark Prins * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2157f8d5bbSMark Prins *
2257f8d5bbSMark Prins * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
2338a47c60SMark Prins */
2438a47c60SMark Prins/**
25bea711feSMark Prins * Action for Plugin OL Maps: Allow Display of a OpenLayers Map in a wiki page.
2638a47c60SMark Prins * @author Mark Prins
2738a47c60SMark Prins */
28*a760825cSgithub-actions[bot]class action_plugin_openlayersmap extends ActionPlugin
29bea711feSMark Prins{
3038a47c60SMark Prins    /**
31bea711feSMark Prins     * Plugin uses this method to register its handlers with the DokuWiki's event controller.
3238a47c60SMark Prins     *
3338a47c60SMark Prins     * @param $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER
3438a47c60SMark Prins     */
35*a760825cSgithub-actions[bot]    final public function register(EventHandler $controller): void
36bea711feSMark Prins    {
37bea711feSMark Prins        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton');
3836057442SMark Prins        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'insertCSSSniffer');
391bf2087aSMark Prins        $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
4038a47c60SMark Prins    }
4138a47c60SMark Prins
4238a47c60SMark Prins    /**
4335f7d0b1SMark Prins     * Inserts the toolbar button.
44554f43b5SMark Prins     * @param Doku_Event $event the DokuWiki event
4538a47c60SMark Prins     */
46*a760825cSgithub-actions[bot]    final public function insertButton(Event $event): void
47bea711feSMark Prins    {
4838a47c60SMark Prins        $strOpen = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" ';
49e64c85aaSMark Prins        $strOpen .= 'lon="5.1" zoom="12" controls="1" ';
506914b920SMark Prins        $strOpen .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n';
5138a47c60SMark Prins        $strOpen .= '~~ Plugin olmap help.\n';
5238a47c60SMark Prins        $strOpen .= '~~ Required in the above tag are values for: id (unique on this page), width, heigth.\n';
5357f8d5bbSMark Prins        $strOpen .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you';
5457f8d5bbSMark Prins        $strOpen .= '~~ want the map to start.\n\n';
5538a47c60SMark Prins        $strOpen .= '~~ Below is an example of a POI, you can add as many as you want. ';
5657f8d5bbSMark Prins        $strOpen .= '~~ More examples: https://dokuwiki.org/plugin:openlayersmap \n';
57*a760825cSgithub-actions[bot]        $event->data[] = ['type' => 'format', 'title' => $this->getLang('openlayersmap'), 'icon' => '../../plugins/openlayersmap/toolbar/map.png', 'open' => $strOpen, 'sample' => '50.0117,5.1287,-90,.8,marker-green.png,Pont de Barbouillons; Daverdisse \\\\ external link:
58*a760825cSgithub-actions[bot]                        [[https://test.com|test.com]] \\\\ internal link: [[::start]]\\\\ **DW Formatting** \n', 'close' => '</olmap>\n'];
5938a47c60SMark Prins    }
6057f8d5bbSMark Prins
61bea711feSMark Prins    /**
62bea711feSMark Prins     * Add a snippet of javascript into the head to do a css operation we can check for later on.
63bea711feSMark Prins     * @param Doku_Event $event the DokuWiki event
64bea711feSMark Prins     */
65*a760825cSgithub-actions[bot]    final public function insertCSSSniffer(Event $event): void
66bea711feSMark Prins    {
67*a760825cSgithub-actions[bot]        $event->data["script"][] = ["_data" => "document.documentElement.className += ' olCSSsupported';"];
6836057442SMark Prins    }
691bf2087aSMark Prins
701bf2087aSMark Prins    /**
711bf2087aSMark Prins     * Add openlayersmap popularity data.
721bf2087aSMark Prins     *
73bea711feSMark Prins     * @param Doku_Event $event the DokuWiki event
741bf2087aSMark Prins     */
75*a760825cSgithub-actions[bot]    final public function popularity(Event $event): void
76bea711feSMark Prins    {
77bea711feSMark Prins        $versionInfo = getVersionData();
781bf2087aSMark Prins        $plugin_info = $this->getInfo();
791bf2087aSMark Prins        $event->data['openlayersmap']['version'] = $plugin_info['date'];
80bea711feSMark Prins        $event->data['openlayersmap']['dwversion'] = $versionInfo['date'];
81bea711feSMark Prins        $event->data['openlayersmap']['combinedversion'] = $versionInfo['date'] . '_' . $plugin_info['date'];
821bf2087aSMark Prins    }
8338a47c60SMark Prins}
84