Completed
Pull Request — master (#24)
by Mark
17s
created
syntax/geotag.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -24,232 +24,232 @@
 block discarded – undo
24 24
  * @author  Mark C. Prins <[email protected]>
25 25
  */
26 26
 class syntax_plugin_geotag_geotag extends DokuWiki_Syntax_Plugin {
27
-    /**
28
-     *
29
-     * @see DokuWiki_Syntax_Plugin::getType()
30
-     */
31
-    public function getType() {
32
-        return 'substition';
33
-    }
27
+	/**
28
+	 *
29
+	 * @see DokuWiki_Syntax_Plugin::getType()
30
+	 */
31
+	public function getType() {
32
+		return 'substition';
33
+	}
34 34
 
35
-    /**
36
-     *
37
-     * @see DokuWiki_Syntax_Plugin::getPType()
38
-     */
39
-    public function getPType() {
40
-        return 'block';
41
-    }
35
+	/**
36
+	 *
37
+	 * @see DokuWiki_Syntax_Plugin::getPType()
38
+	 */
39
+	public function getPType() {
40
+		return 'block';
41
+	}
42 42
 
43
-    /**
44
-     *
45
-     * @see Doku_Parser_Mode::getSort()
46
-     */
47
-    public function getSort() {
48
-        return 305;
49
-    }
43
+	/**
44
+	 *
45
+	 * @see Doku_Parser_Mode::getSort()
46
+	 */
47
+	public function getSort() {
48
+		return 305;
49
+	}
50 50
 
51
-    /**
52
-     *
53
-     * @see Doku_Parser_Mode::connectTo()
54
-     */
55
-    public function connectTo($mode) {
56
-        $this->Lexer->addSpecialPattern('\{\{geotag>.*?\}\}', $mode, 'plugin_geotag_geotag');
57
-    }
51
+	/**
52
+	 *
53
+	 * @see Doku_Parser_Mode::connectTo()
54
+	 */
55
+	public function connectTo($mode) {
56
+		$this->Lexer->addSpecialPattern('\{\{geotag>.*?\}\}', $mode, 'plugin_geotag_geotag');
57
+	}
58 58
 
59
-    /**
60
-     *
61
-     * @see DokuWiki_Syntax_Plugin::handle()
62
-     */
63
-    public function handle($match, $state, $pos, Doku_Handler $handler) {
64
-        $tags = trim(substr($match, 9, -2));
65
-        // parse geotag content
66
-        preg_match("(lat[:|=]-?\d*\.\d*)", $tags, $lat);
67
-        preg_match("(lon[:|=]-?\d*\.\d*)", $tags, $lon);
68
-        preg_match("(alt[:|=]-?\d*\.?\d*)", $tags, $alt);
69
-        preg_match("/(region[:|=][\p{L}\s\w'-]*)/u", $tags, $region);
70
-        preg_match("/(placename[:|=][\p{L}\s\w'-]*)/u", $tags, $placename);
71
-        preg_match("/(country[:|=][\p{L}\s\w'-]*)/u", $tags, $country);
72
-        preg_match("(hide|unhide)", $tags, $hide);
59
+	/**
60
+	 *
61
+	 * @see DokuWiki_Syntax_Plugin::handle()
62
+	 */
63
+	public function handle($match, $state, $pos, Doku_Handler $handler) {
64
+		$tags = trim(substr($match, 9, -2));
65
+		// parse geotag content
66
+		preg_match("(lat[:|=]-?\d*\.\d*)", $tags, $lat);
67
+		preg_match("(lon[:|=]-?\d*\.\d*)", $tags, $lon);
68
+		preg_match("(alt[:|=]-?\d*\.?\d*)", $tags, $alt);
69
+		preg_match("/(region[:|=][\p{L}\s\w'-]*)/u", $tags, $region);
70
+		preg_match("/(placename[:|=][\p{L}\s\w'-]*)/u", $tags, $placename);
71
+		preg_match("/(country[:|=][\p{L}\s\w'-]*)/u", $tags, $country);
72
+		preg_match("(hide|unhide)", $tags, $hide);
73 73
 
74
-        $showlocation = $this->getConf('geotag_location_prefix');
75
-        if($this->getConf('geotag_showlocation')) {
76
-            $showlocation = trim(substr($placename [0], 10));
77
-            if(strlen($showlocation) < 1) {
78
-                $showlocation = $this->getConf('geotag_location_prefix');
79
-            }
80
-        }
81
-        // read config for system setting
82
-        $style = '';
83
-        if($this->getConf('geotag_hide')) {
84
-            $style = ' style="display: none;"';
85
-        }
86
-        // override config for the current tag
87
-        if(array_key_exists(0, $hide) && trim($hide [0]) == 'hide') {
88
-            $style = ' style="display: none;"';
89
-        } elseif(array_key_exists(0, $hide) && trim($hide [0]) == 'unhide') {
90
-            $style = '';
91
-        }
74
+		$showlocation = $this->getConf('geotag_location_prefix');
75
+		if($this->getConf('geotag_showlocation')) {
76
+			$showlocation = trim(substr($placename [0], 10));
77
+			if(strlen($showlocation) < 1) {
78
+				$showlocation = $this->getConf('geotag_location_prefix');
79
+			}
80
+		}
81
+		// read config for system setting
82
+		$style = '';
83
+		if($this->getConf('geotag_hide')) {
84
+			$style = ' style="display: none;"';
85
+		}
86
+		// override config for the current tag
87
+		if(array_key_exists(0, $hide) && trim($hide [0]) == 'hide') {
88
+			$style = ' style="display: none;"';
89
+		} elseif(array_key_exists(0, $hide) && trim($hide [0]) == 'unhide') {
90
+			$style = '';
91
+		}
92 92
 
93
-        $data = array(
94
-            hsc(trim(substr($lat [0], 4))),
95
-            hsc(trim(substr($lon [0], 4))),
96
-            hsc(trim(substr(($alt[0] ?? ''), 4))),
97
-            $this->geohash(substr($lat [0], 4), substr($lon [0], 4)),
98
-            hsc(trim(substr(($region[0] ?? ''), 7))),
99
-            hsc(trim(substr(($placename[0] ?? ''), 10))),
100
-            hsc(trim(substr(($country [0] ?? ''), 8))),
101
-            hsc($showlocation),
102
-            $style
103
-        );
104
-        return $data;
105
-    }
93
+		$data = array(
94
+			hsc(trim(substr($lat [0], 4))),
95
+			hsc(trim(substr($lon [0], 4))),
96
+			hsc(trim(substr(($alt[0] ?? ''), 4))),
97
+			$this->geohash(substr($lat [0], 4), substr($lon [0], 4)),
98
+			hsc(trim(substr(($region[0] ?? ''), 7))),
99
+			hsc(trim(substr(($placename[0] ?? ''), 10))),
100
+			hsc(trim(substr(($country [0] ?? ''), 8))),
101
+			hsc($showlocation),
102
+			$style
103
+		);
104
+		return $data;
105
+	}
106 106
 
107
-    /**
108
-     * Calculate the geohash for this lat/lon pair.
109
-     *
110
-     * @param float $lat
111
-     * @param float $lon
112
-     */
113
-    private function geohash($lat, $lon) {
114
-        if(!$geophp = plugin_load('helper', 'geophp')) {
115
-            dbglog($geophp, 'syntax_plugin_geotag_geotag::geohash: geophp plugin is not available.');
116
-            return "";
117
-        }
118
-        $_lat     = floatval($lat);
119
-        $_lon     = floatval($lon);
120
-        $geometry = new geoPHP\Geometry\Point($_lon, $_lat);
121
-        return $geometry->out('geohash');
122
-    }
107
+	/**
108
+	 * Calculate the geohash for this lat/lon pair.
109
+	 *
110
+	 * @param float $lat
111
+	 * @param float $lon
112
+	 */
113
+	private function geohash($lat, $lon) {
114
+		if(!$geophp = plugin_load('helper', 'geophp')) {
115
+			dbglog($geophp, 'syntax_plugin_geotag_geotag::geohash: geophp plugin is not available.');
116
+			return "";
117
+		}
118
+		$_lat     = floatval($lat);
119
+		$_lon     = floatval($lon);
120
+		$geometry = new geoPHP\Geometry\Point($_lon, $_lat);
121
+		return $geometry->out('geohash');
122
+	}
123 123
 
124
-    /**
125
-     *
126
-     * @see DokuWiki_Syntax_Plugin::render()
127
-     */
128
-    public function render($mode, Doku_Renderer $renderer, $data) {
129
-        if($data === false) {
130
-            return false;
131
-        }
132
-        list ($lat, $lon, $alt, $geohash, $region, $placename, $country, $showlocation, $style) = $data;
133
-        $ddlat = $lat;
134
-        $ddlon = $lon;
135
-        if($this->getConf('displayformat') === 'DMS') {
136
-            $lat = $this->convertLat($lat);
137
-            $lon = $this->convertLon($lon);
138
-        } else {
139
-            $lat .= 'º';
140
-            $lon .= 'º';
141
-        }
124
+	/**
125
+	 *
126
+	 * @see DokuWiki_Syntax_Plugin::render()
127
+	 */
128
+	public function render($mode, Doku_Renderer $renderer, $data) {
129
+		if($data === false) {
130
+			return false;
131
+		}
132
+		list ($lat, $lon, $alt, $geohash, $region, $placename, $country, $showlocation, $style) = $data;
133
+		$ddlat = $lat;
134
+		$ddlon = $lon;
135
+		if($this->getConf('displayformat') === 'DMS') {
136
+			$lat = $this->convertLat($lat);
137
+			$lon = $this->convertLon($lon);
138
+		} else {
139
+			$lat .= 'º';
140
+			$lon .= 'º';
141
+		}
142 142
 
143
-        if($mode == 'xhtml') {
144
-            if($this->getConf('geotag_prevent_microformat_render')) {
145
-                return true;
146
-            }
147
-            $searchPre  = '';
148
-            $searchPost = '';
149
-            if($this->getConf('geotag_showsearch')) {
150
-                if($spHelper = &plugin_load('helper', 'spatialhelper_search')) {
151
-                    $title      = $this->getLang('findnearby') . '&nbsp;' . $placename;
152
-                    $url        = wl(
153
-                        getID(), array(
154
-                        'do'  => 'findnearby',
155
-                        'lat' => $ddlat,
156
-                        'lon' => $ddlon
157
-                    )
158
-                    );
159
-                    $searchPre  = '<a href="' . $url . '" title="' . $title . '">';
160
-                    $searchPost = '<span class="a11y">' . $title . '</span></a>';
161
-                }
162
-            }
143
+		if($mode == 'xhtml') {
144
+			if($this->getConf('geotag_prevent_microformat_render')) {
145
+				return true;
146
+			}
147
+			$searchPre  = '';
148
+			$searchPost = '';
149
+			if($this->getConf('geotag_showsearch')) {
150
+				if($spHelper = &plugin_load('helper', 'spatialhelper_search')) {
151
+					$title      = $this->getLang('findnearby') . '&nbsp;' . $placename;
152
+					$url        = wl(
153
+						getID(), array(
154
+						'do'  => 'findnearby',
155
+						'lat' => $ddlat,
156
+						'lon' => $ddlon
157
+					)
158
+					);
159
+					$searchPre  = '<a href="' . $url . '" title="' . $title . '">';
160
+					$searchPost = '<span class="a11y">' . $title . '</span></a>';
161
+				}
162
+			}
163 163
 
164
-            // render geotag microformat/schema.org microdata
165
-            $renderer->doc .= '<span class="geotagPrint">' . $this->getLang('geotag_desc') . '</span>';
166
-            $renderer->doc .= '<div class="h-geo geo"' . $style . ' title="' . $this->getLang('geotag_desc')
167
-                . $placename . '" itemscope itemtype="http://schema.org/Place">';
168
-            $renderer->doc .= '<span itemprop="name">' . $showlocation . '</span>:&nbsp;' . $searchPre;
169
-            $renderer->doc .= '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">';
170
-            $renderer->doc .= '<span class="p-latitude latitude" itemprop="latitude" data-latitude="' . $ddlat . '">'
171
-                . $lat . '</span>;';
172
-            $renderer->doc .= '<span class="p-longitude longitude" itemprop="longitude" data-longitude="' . $ddlon
173
-                . '">' . $lon . '</span>';
174
-            if(!empty ($alt)) {
175
-                $renderer->doc .= ', <span class="p-altitude altitude" itemprop="elevation" data-altitude="' . $alt
176
-                    . '">' . $alt . 'm</span>';
177
-            }
178
-            $renderer->doc .= '</span>' . $searchPost . '</div>' . DOKU_LF;
179
-            return true;
180
-        } elseif($mode == 'metadata') {
181
-            // render metadata (our action plugin will put it in the page head)
182
-            $renderer->meta ['geo'] ['lat']       = $ddlat;
183
-            $renderer->meta ['geo'] ['lon']       = $ddlon;
184
-            $renderer->meta ['geo'] ['placename'] = $placename;
185
-            $renderer->meta ['geo'] ['region']    = $region;
186
-            $renderer->meta ['geo'] ['country']   = $country;
187
-            $renderer->meta ['geo'] ['geohash']   = $geohash;
188
-            $renderer->meta ['geo'] ['alt']       = $alt;
189
-            return true;
190
-        } elseif($mode == 'odt') {
191
-            if(!empty ($alt)) {
192
-                $alt = ', ' . $alt . 'm';
193
-            }
194
-            $renderer->p_open();
195
-            $renderer->_odtAddImage(DOKU_PLUGIN . 'geotag/images/geotag.png', null, null, 'left', '');
196
-            $renderer->cdata($this->getLang('geotag_desc') . ' ' . $placename);
197
-            $renderer->monospace_open();
198
-            $renderer->cdata($lat . ';' . $lon . $alt);
199
-            $renderer->monospace_close();
200
-            $renderer->p_close();
201
-            return true;
202
-        }
203
-        return false;
204
-    }
164
+			// render geotag microformat/schema.org microdata
165
+			$renderer->doc .= '<span class="geotagPrint">' . $this->getLang('geotag_desc') . '</span>';
166
+			$renderer->doc .= '<div class="h-geo geo"' . $style . ' title="' . $this->getLang('geotag_desc')
167
+				. $placename . '" itemscope itemtype="http://schema.org/Place">';
168
+			$renderer->doc .= '<span itemprop="name">' . $showlocation . '</span>:&nbsp;' . $searchPre;
169
+			$renderer->doc .= '<span itemprop="geo" itemscope itemtype="http://schema.org/GeoCoordinates">';
170
+			$renderer->doc .= '<span class="p-latitude latitude" itemprop="latitude" data-latitude="' . $ddlat . '">'
171
+				. $lat . '</span>;';
172
+			$renderer->doc .= '<span class="p-longitude longitude" itemprop="longitude" data-longitude="' . $ddlon
173
+				. '">' . $lon . '</span>';
174
+			if(!empty ($alt)) {
175
+				$renderer->doc .= ', <span class="p-altitude altitude" itemprop="elevation" data-altitude="' . $alt
176
+					. '">' . $alt . 'm</span>';
177
+			}
178
+			$renderer->doc .= '</span>' . $searchPost . '</div>' . DOKU_LF;
179
+			return true;
180
+		} elseif($mode == 'metadata') {
181
+			// render metadata (our action plugin will put it in the page head)
182
+			$renderer->meta ['geo'] ['lat']       = $ddlat;
183
+			$renderer->meta ['geo'] ['lon']       = $ddlon;
184
+			$renderer->meta ['geo'] ['placename'] = $placename;
185
+			$renderer->meta ['geo'] ['region']    = $region;
186
+			$renderer->meta ['geo'] ['country']   = $country;
187
+			$renderer->meta ['geo'] ['geohash']   = $geohash;
188
+			$renderer->meta ['geo'] ['alt']       = $alt;
189
+			return true;
190
+		} elseif($mode == 'odt') {
191
+			if(!empty ($alt)) {
192
+				$alt = ', ' . $alt . 'm';
193
+			}
194
+			$renderer->p_open();
195
+			$renderer->_odtAddImage(DOKU_PLUGIN . 'geotag/images/geotag.png', null, null, 'left', '');
196
+			$renderer->cdata($this->getLang('geotag_desc') . ' ' . $placename);
197
+			$renderer->monospace_open();
198
+			$renderer->cdata($lat . ';' . $lon . $alt);
199
+			$renderer->monospace_close();
200
+			$renderer->p_close();
201
+			return true;
202
+		}
203
+		return false;
204
+	}
205 205
 
206
-    /**
207
-     * convert latitude in decimal degrees to DMS+hemisphere.
208
-     *
209
-     * @param float $decimaldegrees
210
-     * @return string
211
-     * @todo move this into a shared library
212
-     */
213
-    private function convertLat($decimaldegrees) {
214
-        if(strpos($decimaldegrees, '-') !== false) {
215
-            $latPos = "S";
216
-        } else {
217
-            $latPos = "N";
218
-        }
219
-        $dms = $this->convertDDtoDMS(abs(floatval($decimaldegrees)));
220
-        return hsc($dms . $latPos);
221
-    }
206
+	/**
207
+	 * convert latitude in decimal degrees to DMS+hemisphere.
208
+	 *
209
+	 * @param float $decimaldegrees
210
+	 * @return string
211
+	 * @todo move this into a shared library
212
+	 */
213
+	private function convertLat($decimaldegrees) {
214
+		if(strpos($decimaldegrees, '-') !== false) {
215
+			$latPos = "S";
216
+		} else {
217
+			$latPos = "N";
218
+		}
219
+		$dms = $this->convertDDtoDMS(abs(floatval($decimaldegrees)));
220
+		return hsc($dms . $latPos);
221
+	}
222 222
 
223
-    /**
224
-     * Convert decimal degrees to degrees, minutes, seconds format
225
-     *
226
-     * @param float $decimaldegrees
227
-     * @return string dms
228
-     * @todo move this into a shared library
229
-     */
230
-    private function convertDDtoDMS($decimaldegrees) {
231
-        $dms  = floor($decimaldegrees);
232
-        $secs = ($decimaldegrees - $dms) * 3600;
233
-        $min  = floor($secs / 60);
234
-        $sec  = round($secs - ($min * 60), 3);
235
-        $dms  .= 'º' . $min . '\'' . $sec . '"';
236
-        return $dms;
237
-    }
223
+	/**
224
+	 * Convert decimal degrees to degrees, minutes, seconds format
225
+	 *
226
+	 * @param float $decimaldegrees
227
+	 * @return string dms
228
+	 * @todo move this into a shared library
229
+	 */
230
+	private function convertDDtoDMS($decimaldegrees) {
231
+		$dms  = floor($decimaldegrees);
232
+		$secs = ($decimaldegrees - $dms) * 3600;
233
+		$min  = floor($secs / 60);
234
+		$sec  = round($secs - ($min * 60), 3);
235
+		$dms  .= 'º' . $min . '\'' . $sec . '"';
236
+		return $dms;
237
+	}
238 238
 
239
-    /**
240
-     * convert longitude in decimal degrees to DMS+hemisphere.
241
-     *
242
-     * @param float $decimaldegrees
243
-     * @return string
244
-     * @todo move this into a shared library
245
-     */
246
-    private function convertLon($decimaldegrees) {
247
-        if(strpos($decimaldegrees, '-') !== false) {
248
-            $lonPos = "W";
249
-        } else {
250
-            $lonPos = "E";
251
-        }
252
-        $dms = $this->convertDDtoDMS(abs(floatval($decimaldegrees)));
253
-        return hsc($dms . $lonPos);
254
-    }
239
+	/**
240
+	 * convert longitude in decimal degrees to DMS+hemisphere.
241
+	 *
242
+	 * @param float $decimaldegrees
243
+	 * @return string
244
+	 * @todo move this into a shared library
245
+	 */
246
+	private function convertLon($decimaldegrees) {
247
+		if(strpos($decimaldegrees, '-') !== false) {
248
+			$lonPos = "W";
249
+		} else {
250
+			$lonPos = "E";
251
+		}
252
+		$dms = $this->convertDDtoDMS(abs(floatval($decimaldegrees)));
253
+		return hsc($dms . $lonPos);
254
+	}
255 255
 }
Please login to merge, or discard this patch.