Passed
Pull Request — master (#14)
by Mark
03:14 queued 16s
created

syntax_plugin_openlayersmap_wmslayer::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 4
dl 0
loc 16
rs 9.9666
1
<?php
2
/*
3
 * Copyright (c) 2012-2020 Mark C. Prins <[email protected]>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 *
17
 * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
18
 */
19
20
/**
21
 * adds a WMS 1.3.0 layer to your map.
22
 */
23
class syntax_plugin_openlayersmap_wmslayer extends DokuWiki_Syntax_Plugin
0 ignored issues
show
Bug introduced by
The type DokuWiki_Syntax_Plugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
{
25
    private $dflt = array(
26
        'id'          => 'olmap',
27
        'name'        => '',
28
        'url'         => '',
29
        'opacity'     => 0.8,
30
        'attribution' => '',
31
        'visible'     => false,
32
        'layers'      => '',
33
        'version'     => '1.3.0',
34
        'format'      => 'image/png',
35
        'transparent' => 'true'
36
    );
37
38
    /**
39
     * (non-PHPdoc)
40
     *
41
     * @see DokuWiki_Syntax_Plugin::getPType()
42
     */
43
    public function getPType(): string
44
    {
45
        return 'block';
46
    }
47
48
    /**
49
     * (non-PHPdoc)
50
     *
51
     * @see DokuWiki_Syntax_Plugin::getType()
52
     */
53
    public function getType(): string
54
    {
55
        // return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
56
        return 'baseonly';
57
    }
58
59
    /**
60
     * (non-PHPdoc)
61
     *
62
     * @see Doku_Parser_Mode::getSort()
63
     */
64
    public function getSort(): int
65
    {
66
        return 902;
67
    }
68
69
    /**
70
     * Connect to our special pattern.
71
     *
72
     * @see Doku_Parser_Mode::connectTo()
73
     */
74
    public function connectTo($mode): void
75
    {
76
        // look for: <olmap_wmslayer id="olmap" name="cloud" url="http://openweathermap.org/t/tile.cgi?SERVICE=WMS"
77
        // attribution="OpenWeatherMap" visible="true" layers="GLBETA_PR"></olmap_wmslayer>
78
        $this->Lexer->addSpecialPattern(
79
            '<olmap_wmslayer ?[^>\n]*>.*?</olmap_wmslayer>',
80
            $mode,
81
            'plugin_openlayersmap_wmslayer'
82
        );
83
    }
84
85
    /**
86
     * (non-PHPdoc)
87
     *
88
     * @see DokuWiki_Syntax_Plugin::handle()
89
     */
90
    public function handle($match, $state, $pos, Doku_Handler $handler): array
0 ignored issues
show
Bug introduced by
The type Doku_Handler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
91
    {
92
        $param = array();
93
        $data  = $this->dflt;
94
95
        preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
96
97
        foreach ($param as $kvpair) {
98
            list ($matched, $key, $val) = $kvpair;
99
            if (isset ($data [$key])) {
100
                $key         = strtolower($key);
101
                $data [$key] = $val;
102
            }
103
        }
104
        // dbglog($data,'syntax_plugin_overlayer::handle: parsed data is:');
105
        return $data;
106
    }
107
108
    /**
109
     * (non-PHPdoc)
110
     *
111
     * @see DokuWiki_Syntax_Plugin::render()
112
     */
113
    public function render($format, Doku_Renderer $renderer, $data): bool
0 ignored issues
show
Bug introduced by
The type Doku_Renderer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
114
    {
115
        if ($format !== 'xhtml') {
116
            return false;
117
        }
118
119
        // incremented for each olmap_wmslayer tag in the page source
120
        static $overlaynumber = 0;
121
122
        list ($id, $url, $name, $visible) = $data;
0 ignored issues
show
Comprehensibility Best Practice introduced by
This list assign is not used and could be removed.
Loading history...
123
        $renderer->doc .= DOKU_LF . '<script defer="defer" src="data:text/javascript;base64,';
124
        $str           = '{';
125
        foreach ($data as $key => $val) {
126
            $str .= "'" . $key . "' : '" . $val . "',";
127
        }
128
        $str           .= "'type':'wms'}";
129
        $renderer->doc .= base64_encode("olMapOverlays['wms" . $overlaynumber . "'] = " . $str . ";")
130
            . '"></script>';
131
        $overlaynumber++;
132
        return true;
133
    }
134
}