Passed
Pull Request — master (#14)
by Mark
02:12
created

getSort()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
/*
3
 * Copyright (c) 2016 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
if (! defined ( 'DOKU_INC' ))
18
	die ();
19
20
if (! defined ( 'DOKU_LF' ))
21
	define ( 'DOKU_LF', "\n" );
22
if (! defined ( 'DOKU_TAB' ))
23
	define ( 'DOKU_TAB', "\t" );
24
if (! defined ( 'DOKU_PLUGIN' ))
25
	define ( 'DOKU_PLUGIN', DOKU_INC . 'lib/plugins/' );
0 ignored issues
show
Bug introduced by
The constant DOKU_INC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
26
27
require_once DOKU_PLUGIN . 'syntax.php';
28
/**
29
 * adds a WMS 1.1.1 layer to your map.
30
 */
31
class syntax_plugin_openlayersmapoverlays_searchlayer 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...
32
	private $dflt = array (
33
			'id' => 'olmap',
34
			'name' => '',
35
			'search' => '',
36
			'opacity' => 0.8,
37
			'attribution' => '',
38
			'visible' => false,
39
			'layers' => '',
40
			'version' => '1.1.1',
41
			'format' => 'image/png',
42
			'transparent' => 'true'
43
	);
44
45
	/**
46
	 * (non-PHPdoc)
47
	 *
48
	 * @see DokuWiki_Syntax_Plugin::getPType()
49
	 */
50
	public function getPType() {
51
		return 'block';
52
	}
53
54
	/**
55
	 * (non-PHPdoc)
56
	 *
57
	 * @see DokuWiki_Syntax_Plugin::getType()
58
	 */
59
	public function getType() {
60
		// return 'FIXME: container|baseonly|formatting|substition|protected|disabled|paragraphs';
61
		return 'baseonly';
62
	}
63
64
	/**
65
	 * (non-PHPdoc)
66
	 *
67
	 * @see Doku_Parser_Mode::getSort()
68
	 */
69
	public function getSort() {
70
		return 902;
71
	}
72
73
	/**
74
	 * Connect to our special pattern.
75
	 *
76
	 * @see Doku_Parser_Mode::connectTo()
77
	 */
78
	public function connectTo($mode) {
79
		$this->Lexer->addSpecialPattern ( '<olmap_searchlayer ?[^>\n]*>.*?</olmap_searchlayer>',
80
				$mode, 'plugin_openlayersmapoverlays_searchlayer' );
81
	}
82
83
	/**
84
	 * (non-PHPdoc)
85
	 *
86
	 * @see DokuWiki_Syntax_Plugin::handle()
87
	 */
88
	public function handle($match, $state, $pos, Doku_Handler $handler) {
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...
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:');
0 ignored issues
show
Bug introduced by
The function dbglog was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
		/** @scrutinizer ignore-call */ 
102
  dbglog($data,'syntax_plugin_overlayer::handle: parsed data is:');
Loading history...
102
		return $data;
103
	}
104
105
	/**
106
	 * (non-PHPdoc)
107
	 *
108
	 * @see DokuWiki_Syntax_Plugin::render()
109
	 */
110
	public function render($mode, Doku_Renderer $renderer, $data) {
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
		if ($mode != 'xhtml')
112
			return false;
113
114
		static $loadedOLlib = false;
115
		if (! $loadedOLlib) {
116
			$renderer->doc .= DOKU_LF . '<script type="text/javascript" src="' . DOKU_BASE . 'lib/plugins/openlayersmapoverlays/lib/layers.js' . '"></script>';
0 ignored issues
show
Bug introduced by
The constant DOKU_BASE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
117
			$loadedOLlib = true;
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 type='text/javascript'><!--//--><![CDATA[//><!--" . DOKU_LF;
124
		$str = '{';
125
		foreach ( $data as $key => $val ) {
126
			$str .= "'" . $key . "' : '" . $val . "',";
127
		}
128
		$str .= "'type':'wms'}";
129
		$renderer->doc .= "olMapOverlays['wms" . $overlaynumber . "'] = " . $str . ";" . DOKU_LF . "//--><!]]></script>";
130
		$overlaynumber ++;
131
		return true;
132
	}
133
}
134