xref: /plugin/openlayersmap/action.php (revision 57f8d5bb7862220bc86367226edbe0c27b689270)
138a47c60SMark Prins<?php
238a47c60SMark Prins/*
3*57f8d5bbSMark 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.
16*57f8d5bbSMark Prins *
17*57f8d5bbSMark 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     */
32*57f8d5bbSMark Prins    public function register(Doku_Event_Handler $controller) {
33*57f8d5bbSMark 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     */
41*57f8d5bbSMark Prins    public function insertButton(Doku_Event $event, $param) {
4238a47c60SMark Prins        $strOpen       = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" ';
438a442ab1SMark Prins        $strOpen       .= 'lon="5.1" zoom="12" statusbar="1" controls="1" poihoverstyle="0" ';
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';
47*57f8d5bbSMark Prins        $strOpen       .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you';
48*57f8d5bbSMark 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. ';
50*57f8d5bbSMark 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,
56*57f8d5bbSMark Prins            'sample' => '50.0117,5.1287,-90,.8,marker-green.png,Pont de Barbouillons; Daverdisse \\\\ external link:
57*57f8d5bbSMark Prins                        [[https://test.com|test.com]] \\\\ internal link: [[::start]]\\\\ **DW Formatting** \n',
5838a47c60SMark Prins            'close'  => '</olmap>\n',
5938a47c60SMark Prins        );
6038a47c60SMark Prins    }
61*57f8d5bbSMark Prins
6236057442SMark Prins    /** add a snippet of javascript into the head to do a css operation we can check for later on.*/
63*57f8d5bbSMark Prins    public function insertCSSSniffer(Doku_Event $event, $param) {
6436057442SMark Prins        $event->data["script"][] = array(
6536057442SMark Prins            "type"  => "text/javascript",
6636057442SMark Prins            "_data" => "document.documentElement.className += ' olCSSsupported';",
6736057442SMark Prins        );
6836057442SMark Prins    }
6938a47c60SMark Prins}
70