xref: /plugin/openlayersmap/action.php (revision e64c85aa47a2d01b5f37f42e2c7b864893e14462)
138a47c60SMark Prins<?php
238a47c60SMark Prins/*
357f8d5bbSMark Prins * Copyright (c) 2008-2021 Mark C. Prins <mprins@users.sf.net>
438a47c60SMark Prins *
538a47c60SMark Prins * Permission to use, copy, modify, and distribute this software for any
638a47c60SMark Prins * purpose with or without fee is hereby granted, provided that the above
738a47c60SMark Prins * copyright notice and this permission notice appear in all copies.
838a47c60SMark Prins *
938a47c60SMark Prins * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1038a47c60SMark Prins * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1138a47c60SMark Prins * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1238a47c60SMark Prins * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1338a47c60SMark Prins * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1438a47c60SMark Prins * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1538a47c60SMark Prins * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1657f8d5bbSMark Prins *
1757f8d5bbSMark Prins * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
1838a47c60SMark Prins */
1938a47c60SMark Prins
2038a47c60SMark Prins/**
2138a47c60SMark Prins * Plugin OL Maps: Allow Display of a OpenLayers Map in a wiki page.
2238a47c60SMark Prins * Toolbar button.
2338a47c60SMark Prins * @author Mark Prins
2438a47c60SMark Prins */
2538a47c60SMark Prinsclass action_plugin_openlayersmap extends DokuWiki_Action_Plugin {
2638a47c60SMark Prins
2738a47c60SMark Prins    /**
2838a47c60SMark Prins     * plugin should use this method to register its handlers with the DokuWiki's event controller
2938a47c60SMark Prins     *
3038a47c60SMark Prins     * @param    $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER
3138a47c60SMark Prins     */
3257f8d5bbSMark Prins    public function register(Doku_Event_Handler $controller) {
3357f8d5bbSMark Prins        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array());
3436057442SMark Prins        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'insertCSSSniffer');
3538a47c60SMark Prins    }
3638a47c60SMark Prins
3738a47c60SMark Prins    /**
3835f7d0b1SMark Prins     * Inserts the toolbar button.
39554f43b5SMark Prins     * @param Doku_Event $event the DokuWiki event
4038a47c60SMark Prins     */
4157f8d5bbSMark Prins    public function insertButton(Doku_Event $event, $param) {
4238a47c60SMark Prins        $strOpen       = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" ';
43*e64c85aaSMark Prins        $strOpen       .= 'lon="5.1" zoom="12" controls="1" ';
446914b920SMark Prins        $strOpen       .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n';
4538a47c60SMark Prins        $strOpen       .= '~~ Plugin olmap help.\n';
4638a47c60SMark Prins        $strOpen       .= '~~ Required in the above tag are values for: id (unique on this page), width, heigth.\n';
4757f8d5bbSMark Prins        $strOpen       .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you';
4857f8d5bbSMark Prins        $strOpen       .= '~~ want the map to start.\n\n';
4938a47c60SMark Prins        $strOpen       .= '~~ Below is an example of a POI, you can add as many as you want. ';
5057f8d5bbSMark Prins        $strOpen       .= '~~ More examples: https://dokuwiki.org/plugin:openlayersmap \n';
5138a47c60SMark Prins        $event->data[] = array(
5238a47c60SMark Prins            'type'   => 'format',
5338a47c60SMark Prins            'title'  => $this->getLang('openlayersmap'),
5438a47c60SMark Prins            'icon'   => '../../plugins/openlayersmap/toolbar/map.png',
5538a47c60SMark Prins            'open'   => $strOpen,
5657f8d5bbSMark Prins            'sample' => '50.0117,5.1287,-90,.8,marker-green.png,Pont de Barbouillons; Daverdisse \\\\ external link:
5757f8d5bbSMark Prins                        [[https://test.com|test.com]] \\\\ internal link: [[::start]]\\\\ **DW Formatting** \n',
5838a47c60SMark Prins            'close'  => '</olmap>\n',
5938a47c60SMark Prins        );
6038a47c60SMark Prins    }
6157f8d5bbSMark Prins
6236057442SMark Prins    /** add a snippet of javascript into the head to do a css operation we can check for later on.*/
6357f8d5bbSMark Prins    public function insertCSSSniffer(Doku_Event $event, $param) {
64a201fe4aSMark Prins        $event->data["script"][] = array("_data" => "document.documentElement.className += ' olCSSsupported';");
6536057442SMark Prins    }
6638a47c60SMark Prins}
67