Issues (93)

action.php (1 issue)

1
<?php
2
3
use dokuwiki\Extension\ActionPlugin;
4
use dokuwiki\Extension\EventHandler;
5
use dokuwiki\Extension\Event;
6
7
/*
8
 * Copyright (c) 2008 Mark C. Prins <[email protected]>
9
 *
10
 * Permission to use, copy, modify, and distribute this software for any
11
 * purpose with or without fee is hereby granted, provided that the above
12
 * copyright notice and this permission notice appear in all copies.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21
 *
22
 * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
23
 */
24
/**
25
 * Action for Plugin OL Maps: Allow Display of a OpenLayers Map in a wiki page.
26
 * @author Mark Prins
27
 */
28
class action_plugin_openlayersmap extends ActionPlugin
29
{
30
    /**
31
     * Plugin uses this method to register its handlers with the DokuWiki's event controller.
32
     *
33
     * @param $controller DokuWiki's event controller object. Also available as global $EVENT_HANDLER
0 ignored issues
show
Documentation Bug introduced by
The doc comment DokuWiki's at position 0 could not be parsed: Unknown type name 'DokuWiki's' at position 0 in DokuWiki's.
Loading history...
34
     */
35
    final public function register(EventHandler $controller): void
36
    {
37
        $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton');
38
        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'insertCSSSniffer');
39
        $controller->register_hook('PLUGIN_POPULARITY_DATA_SETUP', 'AFTER', $this, 'popularity');
40
    }
41
42
    /**
43
     * Inserts the toolbar button.
44
     * @param Event $event the DokuWiki event
45
     */
46
    final public function insertButton(Event $event): void
47
    {
48
        $strOpen = '<olmap id="olMapOne" width="550px" height="450px" lat="50.0" ';
49
        $strOpen .= 'lon="5.1" zoom="12" controls="1" ';
50
        $strOpen .= 'baselyr="OpenStreetMap" gpxfile="" kmlfile="" geojsonfile="" summary="" >\n';
51
        $strOpen .= '~~ Plugin olmap help.\n';
52
        $strOpen .= '~~ Required in the above tag are values for: id (unique on this page), width, heigth.\n';
53
        $strOpen .= '~~ Also you will want to enter zoomlevel and lat, lon values that make sense for where you';
54
        $strOpen .= '~~ want the map to start.\n\n';
55
        $strOpen .= '~~ Below is an example of a POI, you can add as many as you want. ';
56
        $strOpen .= '~~ More examples: https://dokuwiki.org/plugin:openlayersmap \n';
57
        $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
                        [[https://test.com|test.com]] \\\\ internal link: [[::start]]\\\\ **DW Formatting** \n', 'close' => '</olmap>\n'];
59
    }
60
61
    /**
62
     * Add a snippet of javascript into the head to do a css operation we can check for later on.
63
     * @param Event $event the DokuWiki event
64
     */
65
    final public function insertCSSSniffer(Event $event): void
66
    {
67
        $event->data["script"][] = ["_data" => "document.documentElement.className += ' olCSSsupported';"];
68
    }
69
70
    /**
71
     * Add openlayersmap popularity data.
72
     *
73
     * @param Event $event the DokuWiki event
74
     */
75
    final public function popularity(Event $event): void
76
    {
77
        $versionInfo = getVersionData();
78
        $plugin_info = $this->getInfo();
79
        $event->data['openlayersmap']['version'] = $plugin_info['date'];
80
        $event->data['openlayersmap']['dwversion'] = $versionInfo['date'];
81
        $event->data['openlayersmap']['combinedversion'] = $versionInfo['date'] . '_' . $plugin_info['date'];
82
    }
83
}
84