Passed
Pull Request — master (#10)
by Mark
02:04
created

syntax_plugin_openlayersmap_osmlayer::getSort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
 * Add OSM style layer to your map.
22
 */
23
class syntax_plugin_openlayersmap_osmlayer 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
        'cors'        => null
33
    );
34
35
    /**
36
     * (non-PHPdoc)
37
     *
38
     * @see DokuWiki_Syntax_Plugin::getPType()
39
     */
40
    public function getPType(): string
41
    {
42
        return 'block';
43
    }
44
45
    /**
46
     * (non-PHPdoc)
47
     *
48
     * @see DokuWiki_Syntax_Plugin::getType()
49
     */
50
    public function getType(): string
51
    {
52
        // return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
53
        return 'baseonly';
54
    }
55
56
    /**
57
     * (non-PHPdoc)
58
     *
59
     * @see Doku_Parser_Mode::getSort()
60
     */
61
    public function getSort(): int
62
    {
63
        return 902;
64
    }
65
66
    /**
67
     * Connect to our special pattern.
68
     *
69
     * @see Doku_Parser_Mode::connectTo()
70
     */
71
    public function connectTo($mode): void
72
    {
73
        // look for: <olmap_osmlayer id="olmap" name="sport" url="http://tiles.openseamap.org/sport/${z}/${x}/${y}.png"
74
        // visible="false" opacity=0.6 attribution="Some attribution"></olmap_osmlayer>
75
        $this->Lexer->addSpecialPattern(
76
            '<olmap_osmlayer ?[^>\n]*>.*?</olmap_osmlayer>',
77
            $mode,
78
            'plugin_openlayersmap_osmlayer'
79
        );
80
    }
81
82
    /**
83
     * (non-PHPdoc)
84
     *
85
     * @see DokuWiki_Syntax_Plugin::handle()
86
     */
87
    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...
88
    {
89
        $param = array();
90
        $data  = $this->dflt;
91
92
        preg_match_all('/(\w*)="(.*?)"/us', $match, $param, PREG_SET_ORDER);
93
94
        foreach ($param as $kvpair) {
95
            list ($matched, $key, $val) = $kvpair;
96
            if (isset ($data [$key])) {
97
                $key         = strtolower($key);
98
                $data [$key] = $val;
99
            }
100
        }
101
        // dbglog($data,'syntax_plugin_overlayer::handle: parsed data is:');
102
        return $data;
103
    }
104
105
    /**
106
     * (non-PHPdoc)
107
     *
108
     * @see DokuWiki_Syntax_Plugin::render()
109
     */
110
    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...
111
    {
112
        if ($format !== 'xhtml') {
113
            return false;
114
        }
115
116
        // incremented for each olmap_osmlayer tag in the page source
117
        static $overlaynumber = 0;
118
119
        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...
120
        $renderer->doc .= DOKU_LF . '<script defer="defer" src="data:text/javascript;base64,';
0 ignored issues
show
Bug introduced by
The constant DOKU_LF was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
121
        $str           = '{';
122
        foreach ($data as $key => $val) {
123
            $str .= "'" . $key . "' : '" . $val . "',";
124
        }
125
        $str           .= '"type":"osm"}';
126
        $renderer->doc .= base64_encode("olMapOverlays['osm" . $overlaynumber . "'] = " . $str . ";")
127
            . '"></script>';
128
        $overlaynumber++;
129
        return true;
130
    }
131
}
132