Completed
Push — master ( 4ff427...097360 )
by Mark
02:38
created

syntax/findnearby.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * Copyright (c) 2014-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_PLUGIN')) {
21
	define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
22
}
23
require_once (DOKU_PLUGIN . 'syntax.php');
24
25
/**
26
 * DokuWiki Plugin dokuwikispatial (findnearby Syntax Component).
27
 *
28
 * @license BSD license
29
 * @author Mark C. Prins <[email protected]>
30
 */
31
class syntax_plugin_spatialhelper_findnearby extends DokuWiki_Syntax_Plugin {
32
	/**
33
	 *
34
	 * @see DokuWiki_Syntax_Plugin::getType()
35
	 */
36
	public function getType() {
37
		return 'substition';
38
	}
39
40
	/**
41
	 * Return 'normal' so this syntax can be rendered inline.
42
	 *
43
	 * @see DokuWiki_Syntax_Plugin::getPType()
44
	 */
45
	public function getPType() {
46
		return 'normal';
47
	}
48
49
	/**
50
	 *
51
	 * @see Doku_Parser_Mode::getSort()
52
	 */
53
	public function getSort() {
54
		return 307;
55
	}
56
57
	/**
58
	 * define our special pattern: {{findnearby>Some linkt text or nothing}}.
59
	 *
60
	 * @see Doku_Parser_Mode::connectTo()
61
	 */
62
	public function connectTo($mode) {
63
		$this->Lexer->addSpecialPattern('\{\{findnearby>.*?\}\}', $mode, 'plugin_spatialhelper_findnearby');
64
	}
65
66
	/**
67
	 * look up the page's geo metadata and pass that on to render.
68
	 *
69
	 * @see DokuWiki_Syntax_Plugin::handle()
70
	 */
71
	public function handle($match, $state, $pos, Doku_Handler $handler) {
72
		$data = array();
73
		$data [0] = trim(substr($match, strlen('{{findnearby>'), - 2));
74
		if (strlen($data [0]) < 1) {
75
			$data [0] = $this->getLang('search_findnearby');
76
		}
77
		$meta = p_get_metadata(getID(), 'geo');
78
		if ($meta) {
79
			if ($meta ['lat'] && $meta ['lon']) {
80
				$data [1] = array(
81
						'do' => 'findnearby',
82
						'lat' => $meta ['lat'],
83
						'lon' => $meta ['lon']
84
				);
85
			} elseif ($meta ['geohash']) {
86
				$data [1] = array(
87
						'do' => 'findnearby',
88
						'geohash' => $meta ['geohash']
89
				);
90
			}
91
			return $data;
92
		}
93
		return false;
94
	}
95
96
	/**
97
	 * Render a link to a search page.
98
	 *
99
	 * @see DokuWiki_Syntax_Plugin::render()
100
	 */
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
101
	public function render($mode, Doku_Renderer $renderer, $data) {
102
		if ($data === false) {
103
					return false;
104
		}
105
106
		if ($mode == 'xhtml') {
107
			$renderer->doc .= '<a href="' . wl(getID(), $data [1]) . '" class="findnearby">' . hsc($data [0]) . '</a>';
108
			return true;
109
		// } elseif ($mode == 'metadata') {
110
		} elseif ($mode == 'odt') {
111
			// don't render anything in ODT
112
			return true;
113
		}
114
		return false;
115
	}
116
}
117