xref: /plugin/openlayersmap/action.php (revision 1bf2087afea41da3bca940b5346a73dd27d06bd3)
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');
35*1bf2087aSMark Prins        $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
3638a47c60SMark Prins    }
3738a47c60SMark Prins
3838a47c60SMark Prins    /**
3935f7d0b1SMark Prins     * Inserts the toolbar button.
40554f43b5SMark Prins     * @param Doku_Event $event the DokuWiki event
4138a47c60SMark Prins     */
4257f8d5bbSMark Prins    public function insertButton(Doku_Event $event, $param) {
4338a47c60SMark Prins        $strOpen       = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" ';
44e64c85aaSMark Prins        $strOpen       .= 'lon="5.1" zoom="12" controls="1" ';
456914b920SMark Prins        $strOpen       .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n';
4638a47c60SMark Prins        $strOpen       .= '~~ Plugin olmap help.\n';
4738a47c60SMark Prins        $strOpen       .= '~~ Required in the above tag are values for: id (unique on this page), width, heigth.\n';
4857f8d5bbSMark Prins        $strOpen       .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you';
4957f8d5bbSMark Prins        $strOpen       .= '~~ want the map to start.\n\n';
5038a47c60SMark Prins        $strOpen       .= '~~ Below is an example of a POI, you can add as many as you want. ';
5157f8d5bbSMark Prins        $strOpen       .= '~~ More examples: https://dokuwiki.org/plugin:openlayersmap \n';
5238a47c60SMark Prins        $event->data[] = array(
5338a47c60SMark Prins            'type'   => 'format',
5438a47c60SMark Prins            'title'  => $this->getLang('openlayersmap'),
5538a47c60SMark Prins            'icon'   => '../../plugins/openlayersmap/toolbar/map.png',
5638a47c60SMark Prins            'open'   => $strOpen,
5757f8d5bbSMark Prins            'sample' => '50.0117,5.1287,-90,.8,marker-green.png,Pont de Barbouillons; Daverdisse \\\\ external link:
5857f8d5bbSMark Prins                        [[https://test.com|test.com]] \\\\ internal link: [[::start]]\\\\ **DW Formatting** \n',
5938a47c60SMark Prins            'close'  => '</olmap>\n',
6038a47c60SMark Prins        );
6138a47c60SMark Prins    }
6257f8d5bbSMark Prins
6336057442SMark Prins    /** add a snippet of javascript into the head to do a css operation we can check for later on.*/
6457f8d5bbSMark Prins    public function insertCSSSniffer(Doku_Event $event, $param) {
65a201fe4aSMark Prins        $event->data["script"][] = array("_data" => "document.documentElement.className += ' olCSSsupported';");
6636057442SMark Prins    }
67*1bf2087aSMark Prins
68*1bf2087aSMark Prins    /**
69*1bf2087aSMark Prins     * Add openlayersmap popularity data.
70*1bf2087aSMark Prins     *
71*1bf2087aSMark Prins     * @param Doku_Event $event
72*1bf2087aSMark Prins     *          the DokuWiki event
73*1bf2087aSMark Prins     */
74*1bf2087aSMark Prins    final public function popularity(Doku_Event $event): void {
75*1bf2087aSMark Prins        global $updateVersion;
76*1bf2087aSMark Prins        $plugin_info                                     = $this->getInfo();
77*1bf2087aSMark Prins        $event->data['openlayersmap']['version']         = $plugin_info['date'];
78*1bf2087aSMark Prins        $event->data['openlayersmap']['dwversion']       = $updateVersion;
79*1bf2087aSMark Prins        $event->data['openlayersmap']['combinedversion'] = $updateVersion . '_' . $plugin_info['date'];
80*1bf2087aSMark Prins    }
8138a47c60SMark Prins}
82