Completed
Pull Request — master (#21)
by Mark
01:22
created
syntax/geotag.php 2 patches
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -27,248 +27,248 @@
 block discarded – undo
27 27
  */
28 28
 class syntax_plugin_geotag_geotag extends DokuWiki_Syntax_Plugin
29 29
 {
30
-    /**
31
-     *
32
-     * @see DokuWiki_Syntax_Plugin::getType()
33
-     */
34
-    public function getType(): string
35
-    {
36
-        return 'substition';
37
-    }
30
+	/**
31
+	 *
32
+	 * @see DokuWiki_Syntax_Plugin::getType()
33
+	 */
34
+	public function getType(): string
35
+	{
36
+		return 'substition';
37
+	}
38 38
 
39
-    /**
40
-     *
41
-     * @see DokuWiki_Syntax_Plugin::getPType()
42
-     */
43
-    public function getPType(): string
44
-    {
45
-        return 'block';
46
-    }
39
+	/**
40
+	 *
41
+	 * @see DokuWiki_Syntax_Plugin::getPType()
42
+	 */
43
+	public function getPType(): string
44
+	{
45
+		return 'block';
46
+	}
47 47
 
48
-    /**
49
-     *
50
-     * @see Doku_Parser_Mode::getSort()
51
-     */
52
-    public function getSort(): int
53
-    {
54
-        return 305;
55
-    }
48
+	/**
49
+	 *
50
+	 * @see Doku_Parser_Mode::getSort()
51
+	 */
52
+	public function getSort(): int
53
+	{
54
+		return 305;
55
+	}
56 56
 
57
-    /**
58
-     *
59
-     * @see Doku_Parser_Mode::connectTo()
60
-     */
61
-    public function connectTo($mode)
62
-    {
63
-        $this->Lexer->addSpecialPattern('\{\{geotag>.*?\}\}', $mode, 'plugin_geotag_geotag');
64
-    }
57
+	/**
58
+	 *
59
+	 * @see Doku_Parser_Mode::connectTo()
60
+	 */
61
+	public function connectTo($mode)
62
+	{
63
+		$this->Lexer->addSpecialPattern('\{\{geotag>.*?\}\}', $mode, 'plugin_geotag_geotag');
64
+	}
65 65
 
66
-    /**
67
-     *
68
-     * @see DokuWiki_Syntax_Plugin::handle()
69
-     */
70
-    public function handle($match, $state, $pos, Doku_Handler $handler): array
71
-    {
72
-        $tags = trim(substr($match, 9, -2));
73
-        // parse geotag content
74
-        preg_match("(lat[:|=]-?\d*\.\d*)", $tags, $lat);
75
-        preg_match("(lon[:|=]-?\d*\.\d*)", $tags, $lon);
76
-        preg_match("(alt[:|=]-?\d*\.?\d*)", $tags, $alt);
77
-        preg_match("/(region[:|=][\p{L}\s\w'-]*)/u", $tags, $region);
78
-        preg_match("/(placename[:|=][\p{L}\s\w'-]*)/u", $tags, $placename);
79
-        preg_match("/(country[:|=][\p{L}\s\w'-]*)/u", $tags, $country);
80
-        preg_match("(hide|unhide)", $tags, $hide);
66
+	/**
67
+	 *
68
+	 * @see DokuWiki_Syntax_Plugin::handle()
69
+	 */
70
+	public function handle($match, $state, $pos, Doku_Handler $handler): array
71
+	{
72
+		$tags = trim(substr($match, 9, -2));
73
+		// parse geotag content
74
+		preg_match("(lat[:|=]-?\d*\.\d*)", $tags, $lat);
75
+		preg_match("(lon[:|=]-?\d*\.\d*)", $tags, $lon);
76
+		preg_match("(alt[:|=]-?\d*\.?\d*)", $tags, $alt);
77
+		preg_match("/(region[:|=][\p{L}\s\w'-]*)/u", $tags, $region);
78
+		preg_match("/(placename[:|=][\p{L}\s\w'-]*)/u", $tags, $placename);
79
+		preg_match("/(country[:|=][\p{L}\s\w'-]*)/u", $tags, $country);
80
+		preg_match("(hide|unhide)", $tags, $hide);
81 81
 
82
-        $showlocation = $this->getConf('geotag_location_prefix');
83
-        if ($this->getConf('geotag_showlocation')) {
84
-            $showlocation = trim(substr($placename [0], 10));
85
-            if (strlen($showlocation) < 1) {
86
-                $showlocation = $this->getConf('geotag_location_prefix');
87
-            }
88
-        }
89
-        // read config for system setting
90
-        $style = '';
91
-        if ($this->getConf('geotag_hide')) {
92
-            $style = ' style="display: none;"';
93
-        }
94
-        // override config for the current tag
95
-        if (array_key_exists(0, $hide) && trim($hide [0]) == 'hide') {
96
-            $style = ' style="display: none;"';
97
-        } elseif (array_key_exists(0, $hide) && trim($hide [0]) == 'unhide') {
98
-            $style = '';
99
-        }
82
+		$showlocation = $this->getConf('geotag_location_prefix');
83
+		if ($this->getConf('geotag_showlocation')) {
84
+			$showlocation = trim(substr($placename [0], 10));
85
+			if (strlen($showlocation) < 1) {
86
+				$showlocation = $this->getConf('geotag_location_prefix');
87
+			}
88
+		}
89
+		// read config for system setting
90
+		$style = '';
91
+		if ($this->getConf('geotag_hide')) {
92
+			$style = ' style="display: none;"';
93
+		}
94
+		// override config for the current tag
95
+		if (array_key_exists(0, $hide) && trim($hide [0]) == 'hide') {
96
+			$style = ' style="display: none;"';
97
+		} elseif (array_key_exists(0, $hide) && trim($hide [0]) == 'unhide') {
98
+			$style = '';
99
+		}
100 100
 
101
-        $geohash = "";
102
-        try {
103
-            $geohash = $this->geohash(substr($lat[0], 4), substr($lon[0], 4));
104
-        } catch (Exception $e) {
105
-            Logger::debug("failed to create geohash for $lat[0], $lon[0]");
106
-        }
107
-        return array(
108
-            hsc(trim(substr($lat[0], 4))),
109
-            hsc(trim(substr($lon[0], 4))),
110
-            hsc(trim(substr(($alt[0] ?? ''), 4))),
111
-            $geohash,
112
-            hsc(trim(substr(($region[0] ?? ''), 7))),
113
-            hsc(trim(substr(($placename[0] ?? ''), 10))),
114
-            hsc(trim(substr(($country[0] ?? ''), 8))),
115
-            hsc($showlocation),
116
-            $style
117
-        );
118
-    }
101
+		$geohash = "";
102
+		try {
103
+			$geohash = $this->geohash(substr($lat[0], 4), substr($lon[0], 4));
104
+		} catch (Exception $e) {
105
+			Logger::debug("failed to create geohash for $lat[0], $lon[0]");
106
+		}
107
+		return array(
108
+			hsc(trim(substr($lat[0], 4))),
109
+			hsc(trim(substr($lon[0], 4))),
110
+			hsc(trim(substr(($alt[0] ?? ''), 4))),
111
+			$geohash,
112
+			hsc(trim(substr(($region[0] ?? ''), 7))),
113
+			hsc(trim(substr(($placename[0] ?? ''), 10))),
114
+			hsc(trim(substr(($country[0] ?? ''), 8))),
115
+			hsc($showlocation),
116
+			$style
117
+		);
118
+	}
119 119
 
120
-    /**
121
-     * Calculate the geohash for this lat/lon pair.
122
-     *
123
-     * @param float $lat
124
-     * @param float $lon
125
-     * @return string tha calculated geohas; can be an empty string
126
-     * @throws Exception when parsing a point geometry fails
127
-     */
128
-    private function geohash(float $lat, float $lon): string
129
-    {
130
-        if (!$geophp = plugin_load('helper', 'geophp')) {
131
-            Logger::debug('syntax_plugin_geotag_geotag::geohash: geophp plugin is not available.', $geophp);
132
-            return "";
133
-        }
134
-        $geometry = new Point($lon, $lat);
135
-        return $geometry->out('geohash');
136
-    }
120
+	/**
121
+	 * Calculate the geohash for this lat/lon pair.
122
+	 *
123
+	 * @param float $lat
124
+	 * @param float $lon
125
+	 * @return string tha calculated geohas; can be an empty string
126
+	 * @throws Exception when parsing a point geometry fails
127
+	 */
128
+	private function geohash(float $lat, float $lon): string
129
+	{
130
+		if (!$geophp = plugin_load('helper', 'geophp')) {
131
+			Logger::debug('syntax_plugin_geotag_geotag::geohash: geophp plugin is not available.', $geophp);
132
+			return "";
133
+		}
134
+		$geometry = new Point($lon, $lat);
135
+		return $geometry->out('geohash');
136
+	}
137 137
 
138
-    /**
139
-     *
140
-     * @see DokuWiki_Syntax_Plugin::render()
141
-     */
142
-    public function render($format, Doku_Renderer $renderer, $data): bool
143
-    {
144
-        if ($data === false) {
145
-            return false;
146
-        }
147
-        list ($lat, $lon, $alt, $geohash, $region, $placename, $country, $showlocation, $style) = $data;
148
-        $ddlat = $lat;
149
-        $ddlon = $lon;
150
-        if ($this->getConf('displayformat') === 'DMS') {
151
-            $lat = $this->convertLat($lat);
152
-            $lon = $this->convertLon($lon);
153
-        } else {
154
-            $lat .= 'º';
155
-            $lon .= 'º';
156
-        }
138
+	/**
139
+	 *
140
+	 * @see DokuWiki_Syntax_Plugin::render()
141
+	 */
142
+	public function render($format, Doku_Renderer $renderer, $data): bool
143
+	{
144
+		if ($data === false) {
145
+			return false;
146
+		}
147
+		list ($lat, $lon, $alt, $geohash, $region, $placename, $country, $showlocation, $style) = $data;
148
+		$ddlat = $lat;
149
+		$ddlon = $lon;
150
+		if ($this->getConf('displayformat') === 'DMS') {
151
+			$lat = $this->convertLat($lat);
152
+			$lon = $this->convertLon($lon);
153
+		} else {
154
+			$lat .= 'º';
155
+			$lon .= 'º';
156
+		}
157 157
 
158
-        if ($format == 'xhtml') {
159
-            if ($this->getConf('geotag_prevent_microformat_render')) {
160
-                return true;
161
-            }
162
-            $searchPre  = '';
163
-            $searchPost = '';
164
-            if ($this->getConf('geotag_showsearch')) {
165
-                if ($spHelper = plugin_load('helper', 'spatialhelper_search')) {
166
-                    $title      = $this->getLang('findnearby') . '&nbsp;' . $placename;
167
-                    $url        = wl(
168
-                        getID(),
169
-                        array(
170
-                            'do'  => 'findnearby',
171
-                            'lat' => $ddlat,
172
-                            'lon' => $ddlon
173
-                        )
174
-                    );
175
-                    $searchPre  = '<a href="' . $url . '" title="' . $title . '">';
176
-                    $searchPost = '<span class="a11y">' . $title . '</span></a>';
177
-                }
178
-            }
158
+		if ($format == 'xhtml') {
159
+			if ($this->getConf('geotag_prevent_microformat_render')) {
160
+				return true;
161
+			}
162
+			$searchPre  = '';
163
+			$searchPost = '';
164
+			if ($this->getConf('geotag_showsearch')) {
165
+				if ($spHelper = plugin_load('helper', 'spatialhelper_search')) {
166
+					$title      = $this->getLang('findnearby') . '&nbsp;' . $placename;
167
+					$url        = wl(
168
+						getID(),
169
+						array(
170
+							'do'  => 'findnearby',
171
+							'lat' => $ddlat,
172
+							'lon' => $ddlon
173
+						)
174
+					);
175
+					$searchPre  = '<a href="' . $url . '" title="' . $title . '">';
176
+					$searchPost = '<span class="a11y">' . $title . '</span></a>';
177
+				}
178
+			}
179 179
 
180
-            // render geotag microformat/schema.org microdata
181
-            $renderer->doc .= '<span class="geotagPrint">' . $this->getLang('geotag_desc') . '</span>';
182
-            $renderer->doc .= '<div class="h-geo geo"' . $style . ' title="' . $this->getLang('geotag_desc')
183
-                . $placename . '" itemscope itemtype="https://schema.org/Place">';
184
-            $renderer->doc .= '<span itemprop="name">' . $showlocation . '</span>:&nbsp;' . $searchPre;
185
-            $renderer->doc .= '<span itemprop="geo" itemscope itemtype="https://schema.org/GeoCoordinates">';
186
-            $renderer->doc .= '<span class="p-latitude latitude" itemprop="latitude" data-latitude="' . $ddlat . '">'
187
-                . $lat . '</span>;';
188
-            $renderer->doc .= '<span class="p-longitude longitude" itemprop="longitude" data-longitude="' . $ddlon
189
-                . '">' . $lon . '</span>';
190
-            if (!empty ($alt)) {
191
-                $renderer->doc .= ', <span class="p-altitude altitude" itemprop="elevation" data-altitude="' . $alt
192
-                    . '">' . $alt . 'm</span>';
193
-            }
194
-            $renderer->doc .= '</span>' . $searchPost . '</div>' . DOKU_LF;
195
-            return true;
196
-        } elseif ($format == 'metadata') {
197
-            // render metadata (our action plugin will put it in the page head)
198
-            $renderer->meta['geo']['lat']       = $ddlat;
199
-            $renderer->meta['geo']['lon']       = $ddlon;
200
-            $renderer->meta['geo']['placename'] = $placename;
201
-            $renderer->meta['geo']['region']    = $region;
202
-            $renderer->meta['geo']['country']   = $country;
203
-            $renderer->meta['geo']['geohash']   = $geohash;
204
-            $renderer->meta['geo']['alt']       = $alt;
205
-            return true;
206
-        } elseif ($format == 'odt') {
207
-            if (!empty ($alt)) {
208
-                $alt = ', ' . $alt . 'm';
209
-            }
210
-            $renderer->p_open();
211
-            $renderer->_odtAddImage(DOKU_PLUGIN . 'geotag/images/geotag.png', null, null, 'left', '');
212
-            $renderer->cdata($this->getLang('geotag_desc') . ' ' . $placename);
213
-            $renderer->monospace_open();
214
-            $renderer->cdata($lat . ';' . $lon . $alt);
215
-            $renderer->monospace_close();
216
-            $renderer->p_close();
217
-            return true;
218
-        }
219
-        return false;
220
-    }
180
+			// render geotag microformat/schema.org microdata
181
+			$renderer->doc .= '<span class="geotagPrint">' . $this->getLang('geotag_desc') . '</span>';
182
+			$renderer->doc .= '<div class="h-geo geo"' . $style . ' title="' . $this->getLang('geotag_desc')
183
+				. $placename . '" itemscope itemtype="https://schema.org/Place">';
184
+			$renderer->doc .= '<span itemprop="name">' . $showlocation . '</span>:&nbsp;' . $searchPre;
185
+			$renderer->doc .= '<span itemprop="geo" itemscope itemtype="https://schema.org/GeoCoordinates">';
186
+			$renderer->doc .= '<span class="p-latitude latitude" itemprop="latitude" data-latitude="' . $ddlat . '">'
187
+				. $lat . '</span>;';
188
+			$renderer->doc .= '<span class="p-longitude longitude" itemprop="longitude" data-longitude="' . $ddlon
189
+				. '">' . $lon . '</span>';
190
+			if (!empty ($alt)) {
191
+				$renderer->doc .= ', <span class="p-altitude altitude" itemprop="elevation" data-altitude="' . $alt
192
+					. '">' . $alt . 'm</span>';
193
+			}
194
+			$renderer->doc .= '</span>' . $searchPost . '</div>' . DOKU_LF;
195
+			return true;
196
+		} elseif ($format == 'metadata') {
197
+			// render metadata (our action plugin will put it in the page head)
198
+			$renderer->meta['geo']['lat']       = $ddlat;
199
+			$renderer->meta['geo']['lon']       = $ddlon;
200
+			$renderer->meta['geo']['placename'] = $placename;
201
+			$renderer->meta['geo']['region']    = $region;
202
+			$renderer->meta['geo']['country']   = $country;
203
+			$renderer->meta['geo']['geohash']   = $geohash;
204
+			$renderer->meta['geo']['alt']       = $alt;
205
+			return true;
206
+		} elseif ($format == 'odt') {
207
+			if (!empty ($alt)) {
208
+				$alt = ', ' . $alt . 'm';
209
+			}
210
+			$renderer->p_open();
211
+			$renderer->_odtAddImage(DOKU_PLUGIN . 'geotag/images/geotag.png', null, null, 'left', '');
212
+			$renderer->cdata($this->getLang('geotag_desc') . ' ' . $placename);
213
+			$renderer->monospace_open();
214
+			$renderer->cdata($lat . ';' . $lon . $alt);
215
+			$renderer->monospace_close();
216
+			$renderer->p_close();
217
+			return true;
218
+		}
219
+		return false;
220
+	}
221 221
 
222
-    /**
223
-     * convert latitude in decimal degrees to DMS+hemisphere.
224
-     *
225
-     * @param float $decimaldegrees
226
-     * @return string
227
-     * @todo move this into a shared library
228
-     */
229
-    private function convertLat(float $decimaldegrees): string
230
-    {
231
-        if (strpos($decimaldegrees, '-') !== false) {
232
-            $latPos = "S";
233
-        } else {
234
-            $latPos = "N";
235
-        }
236
-        $dms = $this->convertDDtoDMS(abs($decimaldegrees));
237
-        return hsc($dms . $latPos);
238
-    }
222
+	/**
223
+	 * convert latitude in decimal degrees to DMS+hemisphere.
224
+	 *
225
+	 * @param float $decimaldegrees
226
+	 * @return string
227
+	 * @todo move this into a shared library
228
+	 */
229
+	private function convertLat(float $decimaldegrees): string
230
+	{
231
+		if (strpos($decimaldegrees, '-') !== false) {
232
+			$latPos = "S";
233
+		} else {
234
+			$latPos = "N";
235
+		}
236
+		$dms = $this->convertDDtoDMS(abs($decimaldegrees));
237
+		return hsc($dms . $latPos);
238
+	}
239 239
 
240
-    /**
241
-     * Convert decimal degrees to degrees, minutes, seconds format
242
-     *
243
-     * @param float $decimaldegrees
244
-     * @return string dms
245
-     * @todo move this into a shared library
246
-     */
247
-    private function convertDDtoDMS(float $decimaldegrees): string
248
-    {
249
-        $dms  = floor($decimaldegrees);
250
-        $secs = ($decimaldegrees - $dms) * 3600;
251
-        $min  = floor($secs / 60);
252
-        $sec  = round($secs - ($min * 60), 3);
253
-        $dms  .= 'º' . $min . '\'' . $sec . '"';
254
-        return $dms;
255
-    }
240
+	/**
241
+	 * Convert decimal degrees to degrees, minutes, seconds format
242
+	 *
243
+	 * @param float $decimaldegrees
244
+	 * @return string dms
245
+	 * @todo move this into a shared library
246
+	 */
247
+	private function convertDDtoDMS(float $decimaldegrees): string
248
+	{
249
+		$dms  = floor($decimaldegrees);
250
+		$secs = ($decimaldegrees - $dms) * 3600;
251
+		$min  = floor($secs / 60);
252
+		$sec  = round($secs - ($min * 60), 3);
253
+		$dms  .= 'º' . $min . '\'' . $sec . '"';
254
+		return $dms;
255
+	}
256 256
 
257
-    /**
258
-     * convert longitude in decimal degrees to DMS+hemisphere.
259
-     *
260
-     * @param float $decimaldegrees
261
-     * @return string
262
-     * @todo move this into a shared library
263
-     */
264
-    private function convertLon(float $decimaldegrees): string
265
-    {
266
-        if (strpos($decimaldegrees, '-') !== false) {
267
-            $lonPos = "W";
268
-        } else {
269
-            $lonPos = "E";
270
-        }
271
-        $dms = $this->convertDDtoDMS(abs($decimaldegrees));
272
-        return hsc($dms . $lonPos);
273
-    }
257
+	/**
258
+	 * convert longitude in decimal degrees to DMS+hemisphere.
259
+	 *
260
+	 * @param float $decimaldegrees
261
+	 * @return string
262
+	 * @todo move this into a shared library
263
+	 */
264
+	private function convertLon(float $decimaldegrees): string
265
+	{
266
+		if (strpos($decimaldegrees, '-') !== false) {
267
+			$lonPos = "W";
268
+		} else {
269
+			$lonPos = "E";
270
+		}
271
+		$dms = $this->convertDDtoDMS(abs($decimaldegrees));
272
+		return hsc($dms . $lonPos);
273
+	}
274 274
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -250,7 +250,7 @@
 block discarded – undo
250 250
         $secs = ($decimaldegrees - $dms) * 3600;
251 251
         $min  = floor($secs / 60);
252 252
         $sec  = round($secs - ($min * 60), 3);
253
-        $dms  .= 'º' . $min . '\'' . $sec . '"';
253
+        $dms .= 'º' . $min . '\'' . $sec . '"';
254 254
         return $dms;
255 255
     }
256 256
 
Please login to merge, or discard this patch.
_test/syntax.test.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -24,125 +24,125 @@
 block discarded – undo
24 24
 class syntax_plugin_geotag_test extends DokuWikiTest
25 25
 {
26 26
 
27
-    protected $pluginsEnabled = array('geotag');
28
-
29
-    /**
30
-     * copy data and add pages to the index.
31
-     */
32
-    public static function setUpBeforeClass(): void
33
-    {
34
-        parent::setUpBeforeClass();
35
-        global $conf;
36
-        $conf['allowdebug'] = 1;
37
-
38
-        TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/data/');
39
-
40
-        Logger::debug("set up class syntax_plugin_geotag_test");
41
-    }
42
-
43
-    public function setUp(): void
44
-    {
45
-        parent::setUp();
46
-
47
-        global $conf;
48
-        $conf['allowdebug'] = 1;
49
-        $conf['cachetime']  = -1;
50
-
51
-        $data = array();
52
-        search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
53
-
54
-        $verbose = false;
55
-        $force   = false;
56
-        foreach ($data as $val) {
57
-            idx_addPage($val['id'], $verbose, $force);
58
-        }
59
-        if ($conf['allowdebug']) {
60
-            touch(DOKU_TMP_DATA . 'cache/debug.log');
61
-        }
62
-    }
63
-
64
-    public function tearDown(): void
65
-    {
66
-        parent::tearDown();
67
-
68
-        global $conf;
69
-        // try to get the debug log after running the test, print and clear
70
-        if ($conf['allowdebug']) {
71
-            print "\n";
72
-            readfile(DOKU_TMP_DATA . 'cache/debug.log');
73
-            unlink(DOKU_TMP_DATA . 'cache/debug.log');
74
-        }
75
-    }
76
-
77
-    public function test_geotag(): void
78
-    {
79
-        $request  = new TestRequest();
80
-        $response = $request->get(array('id' => 'minimalgeotag'), '/doku.php');
81
-
82
-        $this->assertEquals(
83
-            'minimalgeotag',
84
-            $response->queryHTML('meta[name="keywords"]')->attr('content')
85
-        );
86
-        $this->assertEquals(
87
-            '51.565696;5.324596',
88
-            $response->queryHTML('meta[name="geo.position"]')->attr('content')
89
-        );
90
-        $this->assertEquals(
91
-            '51.565696, 5.324596',
92
-            $response->queryHTML('meta[name="ICBM"]')->attr('content')
93
-        );
94
-
95
-        $this->assertTrue(
96
-            strpos($response->getContent(), 'Geotag (location) for:') !== false,
97
-            '"Geotag (location) for:" was not in the output'
98
-        );
99
-    }
100
-
101
-    public function test_fullgeotag(): void
102
-    {
103
-        $request  = new TestRequest();
104
-        $response = $request->get(array('id' => 'fullgeotag'), '/doku.php');
105
-
106
-        $this->assertEquals(
107
-            'fullgeotag',
108
-            $response->queryHTML('meta[name="keywords"]')->attr('content')
109
-        );
110
-        $this->assertEquals(
111
-            '52.132633;5.291266;9',
112
-            $response->queryHTML('meta[name="geo.position"]')->attr('content')
113
-        );
114
-        $this->assertEquals(
115
-            '52.132633, 5.291266',
116
-            $response->queryHTML('meta[name="ICBM"]')->attr('content')
117
-        );
118
-
119
-        $this->assertTrue(
120
-            strpos($response->getContent(), 'Geotag (location) for:') !== false,
121
-            '"Geotag (location) for:" was not in the output'
122
-        );
123
-    }
124
-
125
-    public function test_fullgeotagnegativecoords(): void
126
-    {
127
-        $request  = new TestRequest();
128
-        $response = $request->get(array('id' => 'fullgeotagnegativecoords'), '/doku.php');
129
-
130
-        $this->assertEquals(
131
-            'fullgeotagnegativecoords',
132
-            $response->queryHTML('meta[name="keywords"]')->attr('content')
133
-        );
134
-        $this->assertEquals(
135
-            '-52.132633;-5.291266;-9',
136
-            $response->queryHTML('meta[name="geo.position"]')->attr('content')
137
-        );
138
-        $this->assertEquals(
139
-            '-52.132633, -5.291266',
140
-            $response->queryHTML('meta[name="ICBM"]')->attr('content')
141
-        );
142
-
143
-        $this->assertTrue(
144
-            strpos($response->getContent(), 'Geotag (location) for:') !== false,
145
-            '"Geotag (location) for:" was not in the output'
146
-        );
147
-    }
27
+	protected $pluginsEnabled = array('geotag');
28
+
29
+	/**
30
+	 * copy data and add pages to the index.
31
+	 */
32
+	public static function setUpBeforeClass(): void
33
+	{
34
+		parent::setUpBeforeClass();
35
+		global $conf;
36
+		$conf['allowdebug'] = 1;
37
+
38
+		TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/data/');
39
+
40
+		Logger::debug("set up class syntax_plugin_geotag_test");
41
+	}
42
+
43
+	public function setUp(): void
44
+	{
45
+		parent::setUp();
46
+
47
+		global $conf;
48
+		$conf['allowdebug'] = 1;
49
+		$conf['cachetime']  = -1;
50
+
51
+		$data = array();
52
+		search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
53
+
54
+		$verbose = false;
55
+		$force   = false;
56
+		foreach ($data as $val) {
57
+			idx_addPage($val['id'], $verbose, $force);
58
+		}
59
+		if ($conf['allowdebug']) {
60
+			touch(DOKU_TMP_DATA . 'cache/debug.log');
61
+		}
62
+	}
63
+
64
+	public function tearDown(): void
65
+	{
66
+		parent::tearDown();
67
+
68
+		global $conf;
69
+		// try to get the debug log after running the test, print and clear
70
+		if ($conf['allowdebug']) {
71
+			print "\n";
72
+			readfile(DOKU_TMP_DATA . 'cache/debug.log');
73
+			unlink(DOKU_TMP_DATA . 'cache/debug.log');
74
+		}
75
+	}
76
+
77
+	public function test_geotag(): void
78
+	{
79
+		$request  = new TestRequest();
80
+		$response = $request->get(array('id' => 'minimalgeotag'), '/doku.php');
81
+
82
+		$this->assertEquals(
83
+			'minimalgeotag',
84
+			$response->queryHTML('meta[name="keywords"]')->attr('content')
85
+		);
86
+		$this->assertEquals(
87
+			'51.565696;5.324596',
88
+			$response->queryHTML('meta[name="geo.position"]')->attr('content')
89
+		);
90
+		$this->assertEquals(
91
+			'51.565696, 5.324596',
92
+			$response->queryHTML('meta[name="ICBM"]')->attr('content')
93
+		);
94
+
95
+		$this->assertTrue(
96
+			strpos($response->getContent(), 'Geotag (location) for:') !== false,
97
+			'"Geotag (location) for:" was not in the output'
98
+		);
99
+	}
100
+
101
+	public function test_fullgeotag(): void
102
+	{
103
+		$request  = new TestRequest();
104
+		$response = $request->get(array('id' => 'fullgeotag'), '/doku.php');
105
+
106
+		$this->assertEquals(
107
+			'fullgeotag',
108
+			$response->queryHTML('meta[name="keywords"]')->attr('content')
109
+		);
110
+		$this->assertEquals(
111
+			'52.132633;5.291266;9',
112
+			$response->queryHTML('meta[name="geo.position"]')->attr('content')
113
+		);
114
+		$this->assertEquals(
115
+			'52.132633, 5.291266',
116
+			$response->queryHTML('meta[name="ICBM"]')->attr('content')
117
+		);
118
+
119
+		$this->assertTrue(
120
+			strpos($response->getContent(), 'Geotag (location) for:') !== false,
121
+			'"Geotag (location) for:" was not in the output'
122
+		);
123
+	}
124
+
125
+	public function test_fullgeotagnegativecoords(): void
126
+	{
127
+		$request  = new TestRequest();
128
+		$response = $request->get(array('id' => 'fullgeotagnegativecoords'), '/doku.php');
129
+
130
+		$this->assertEquals(
131
+			'fullgeotagnegativecoords',
132
+			$response->queryHTML('meta[name="keywords"]')->attr('content')
133
+		);
134
+		$this->assertEquals(
135
+			'-52.132633;-5.291266;-9',
136
+			$response->queryHTML('meta[name="geo.position"]')->attr('content')
137
+		);
138
+		$this->assertEquals(
139
+			'-52.132633, -5.291266',
140
+			$response->queryHTML('meta[name="ICBM"]')->attr('content')
141
+		);
142
+
143
+		$this->assertTrue(
144
+			strpos($response->getContent(), 'Geotag (location) for:') !== false,
145
+			'"Geotag (location) for:" was not in the output'
146
+		);
147
+	}
148 148
 }
Please login to merge, or discard this patch.
_test/general.test.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -24,42 +24,42 @@
 block discarded – undo
24 24
 class general_plugin_geotag_test extends DokuWikiTest
25 25
 {
26 26
 
27
-    protected $pluginsEnabled = array('geotag');
27
+	protected $pluginsEnabled = array('geotag');
28 28
 
29
-    /**
30
-     * Simple test to make sure the plugin.info.txt is in correct format
31
-     */
32
-    public function test_plugininfo(): void
33
-    {
34
-        $file = __DIR__ . '/../plugin.info.txt';
35
-        $this->assertFileExists($file);
29
+	/**
30
+	 * Simple test to make sure the plugin.info.txt is in correct format
31
+	 */
32
+	public function test_plugininfo(): void
33
+	{
34
+		$file = __DIR__ . '/../plugin.info.txt';
35
+		$this->assertFileExists($file);
36 36
 
37
-        $info = confToHash($file);
37
+		$info = confToHash($file);
38 38
 
39
-        $this->assertArrayHasKey('base', $info);
40
-        $this->assertArrayHasKey('author', $info);
41
-        $this->assertArrayHasKey('email', $info);
42
-        $this->assertArrayHasKey('date', $info);
43
-        $this->assertArrayHasKey('name', $info);
44
-        $this->assertArrayHasKey('desc', $info);
45
-        $this->assertArrayHasKey('url', $info);
39
+		$this->assertArrayHasKey('base', $info);
40
+		$this->assertArrayHasKey('author', $info);
41
+		$this->assertArrayHasKey('email', $info);
42
+		$this->assertArrayHasKey('date', $info);
43
+		$this->assertArrayHasKey('name', $info);
44
+		$this->assertArrayHasKey('desc', $info);
45
+		$this->assertArrayHasKey('url', $info);
46 46
 
47
-        $this->assertEquals('geotag', $info['base']);
48
-        $this->assertRegExp('/^https?:\/\//', $info['url']);
49
-        $this->assertTrue(mail_isvalid($info['email']));
50
-        $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
51
-        $this->assertTrue(false !== strtotime($info['date']));
52
-    }
47
+		$this->assertEquals('geotag', $info['base']);
48
+		$this->assertRegExp('/^https?:\/\//', $info['url']);
49
+		$this->assertTrue(mail_isvalid($info['email']));
50
+		$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
51
+		$this->assertTrue(false !== strtotime($info['date']));
52
+	}
53 53
 
54
-    /**
55
-     * test if plugin is loaded.
56
-     */
57
-    public function test_plugin_geotag_isloaded(): void
58
-    {
59
-        global $plugin_controller;
60
-        $this->assertTrue(
61
-            in_array('geotag', $plugin_controller->getList()),
62
-            "geotag plugin is loaded"
63
-        );
64
-    }
54
+	/**
55
+	 * test if plugin is loaded.
56
+	 */
57
+	public function test_plugin_geotag_isloaded(): void
58
+	{
59
+		global $plugin_controller;
60
+		$this->assertTrue(
61
+			in_array('geotag', $plugin_controller->getList()),
62
+			"geotag plugin is loaded"
63
+		);
64
+	}
65 65
 }
Please login to merge, or discard this patch.
action.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -24,118 +24,118 @@
 block discarded – undo
24 24
 class action_plugin_geotag extends DokuWiki_Action_Plugin
25 25
 {
26 26
 
27
-    /**
28
-     * Register for events.
29
-     *
30
-     * @param Doku_Event_Handler $controller
31
-     *          DokuWiki's event controller object. Also available as global $EVENT_HANDLER
32
-     */
33
-    public function register(Doku_Event_Handler $controller)
34
-    {
35
-        $controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
36
-        if ($this->getConf('toolbar_icon')) {
37
-            $controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array());
38
-        }
39
-    }
27
+	/**
28
+	 * Register for events.
29
+	 *
30
+	 * @param Doku_Event_Handler $controller
31
+	 *          DokuWiki's event controller object. Also available as global $EVENT_HANDLER
32
+	 */
33
+	public function register(Doku_Event_Handler $controller)
34
+	{
35
+		$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, 'handleMetaheaderOutput');
36
+		if ($this->getConf('toolbar_icon')) {
37
+			$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insertButton', array());
38
+		}
39
+	}
40 40
 
41
-    /**
42
-     * Retrieve metadata and add to the head of the page using appropriate meta tags.
43
-     *
44
-     * @param Doku_Event $event
45
-     *                          the DokuWiki event. $event->data is a two-dimensional
46
-     *                          array of all meta headers. The keys are meta, link and script.
47
-     * @param mixed      $param ignored
48
-     *
49
-     * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
50
-     */
51
-    public function handleMetaheaderOutput(Doku_Event $event, $param)
52
-    {
53
-        global $ID;
54
-        $title     = p_get_metadata($ID, 'title', true);
55
-        $geotags   = p_get_metadata($ID, 'geo', true);
56
-        $region    = $geotags ['region'];
57
-        $lat       = $geotags ['lat'];
58
-        $lon       = $geotags ['lon'];
59
-        $alt       = $geotags ['alt'];
60
-        $country   = $geotags ['country'];
61
-        $placename = $geotags ['placename'];
62
-        $geohash   = $geotags ['geohash'];
41
+	/**
42
+	 * Retrieve metadata and add to the head of the page using appropriate meta tags.
43
+	 *
44
+	 * @param Doku_Event $event
45
+	 *                          the DokuWiki event. $event->data is a two-dimensional
46
+	 *                          array of all meta headers. The keys are meta, link and script.
47
+	 * @param mixed      $param ignored
48
+	 *
49
+	 * @see http://www.dokuwiki.org/devel:event:tpl_metaheader_output
50
+	 */
51
+	public function handleMetaheaderOutput(Doku_Event $event, $param)
52
+	{
53
+		global $ID;
54
+		$title     = p_get_metadata($ID, 'title', true);
55
+		$geotags   = p_get_metadata($ID, 'geo', true);
56
+		$region    = $geotags ['region'];
57
+		$lat       = $geotags ['lat'];
58
+		$lon       = $geotags ['lon'];
59
+		$alt       = $geotags ['alt'];
60
+		$country   = $geotags ['country'];
61
+		$placename = $geotags ['placename'];
62
+		$geohash   = $geotags ['geohash'];
63 63
 
64
-        if (!empty ($region)) {
65
-            $event->data ['meta'] [] = array(
66
-                'name'    => 'geo.region',
67
-                'content' => $region
68
-            );
69
-        }
70
-        if (!empty ($placename)) {
71
-            $event->data ['meta'] [] = array(
72
-                'name'    => 'geo.placename',
73
-                'content' => $placename
74
-            );
75
-        }
76
-        if (!(empty ($lat) && empty ($lon))) {
77
-            if (!empty ($alt)) {
78
-                $event->data ['meta'] [] = array(
79
-                    'name'    => 'geo.position',
80
-                    'content' => $lat . ';' . $lon . ';' . $alt
81
-                );
82
-            } else {
83
-                $event->data ['meta'] [] = array(
84
-                    'name'    => 'geo.position',
85
-                    'content' => $lat . ';' . $lon
86
-                );
87
-            }
88
-        }
89
-        if (!empty ($country)) {
90
-            $event->data ['meta'] [] = array(
91
-                'name'    => 'geo.country',
92
-                'content' => $country
93
-            );
94
-        }
95
-        if (!(empty ($lat) && empty ($lon))) {
96
-            $event->data ['meta'] [] = array(
97
-                'name'    => "ICBM",
98
-                'content' => $lat . ', ' . $lon
99
-            );
100
-            // icbm is generally useless without a DC.title,
101
-            // so we copy that from title unless it's empty...
102
-            if (!(empty ($title))) {
103
-                /*
64
+		if (!empty ($region)) {
65
+			$event->data ['meta'] [] = array(
66
+				'name'    => 'geo.region',
67
+				'content' => $region
68
+			);
69
+		}
70
+		if (!empty ($placename)) {
71
+			$event->data ['meta'] [] = array(
72
+				'name'    => 'geo.placename',
73
+				'content' => $placename
74
+			);
75
+		}
76
+		if (!(empty ($lat) && empty ($lon))) {
77
+			if (!empty ($alt)) {
78
+				$event->data ['meta'] [] = array(
79
+					'name'    => 'geo.position',
80
+					'content' => $lat . ';' . $lon . ';' . $alt
81
+				);
82
+			} else {
83
+				$event->data ['meta'] [] = array(
84
+					'name'    => 'geo.position',
85
+					'content' => $lat . ';' . $lon
86
+				);
87
+			}
88
+		}
89
+		if (!empty ($country)) {
90
+			$event->data ['meta'] [] = array(
91
+				'name'    => 'geo.country',
92
+				'content' => $country
93
+			);
94
+		}
95
+		if (!(empty ($lat) && empty ($lon))) {
96
+			$event->data ['meta'] [] = array(
97
+				'name'    => "ICBM",
98
+				'content' => $lat . ', ' . $lon
99
+			);
100
+			// icbm is generally useless without a DC.title,
101
+			// so we copy that from title unless it's empty...
102
+			if (!(empty ($title))) {
103
+				/*
104 104
                  * don't specify the DC namespace as this is incomplete; it should be done at the
105 105
                  * template level as it also needs a 'profile' attribute on the head/container,
106 106
                  * see: http://dublincore.org/documents/dc-html/#sect-3.1.1
107 107
                  * $event->data ['link'] [] = array ('rel' => 'schema.DC',
108 108
                  * 'href' => 'http://purl.org/dc/elements/1.1/');
109 109
                  */
110
-                $event->data ['meta'] [] = array(
111
-                    'name'    => "DC.title",
112
-                    'content' => $title
113
-                );
114
-            }
115
-        }
116
-        if (!empty ($geohash)) {
117
-            $event->data ['meta'] [] = array(
118
-                'name'    => 'geo.geohash',
119
-                'content' => $geohash
120
-            );
121
-        }
122
-    }
110
+				$event->data ['meta'] [] = array(
111
+					'name'    => "DC.title",
112
+					'content' => $title
113
+				);
114
+			}
115
+		}
116
+		if (!empty ($geohash)) {
117
+			$event->data ['meta'] [] = array(
118
+				'name'    => 'geo.geohash',
119
+				'content' => $geohash
120
+			);
121
+		}
122
+	}
123 123
 
124
-    /**
125
-     * Inserts the toolbar button.
126
-     *
127
-     * @param Doku_Event $event
128
-     *          the DokuWiki event
129
-     */
130
-    public function insertButton(Doku_Event $event, $param)
131
-    {
132
-        $event->data [] = array(
133
-            'type'   => 'format',
134
-            'title'  => $this->getLang('toolbar_desc'),
135
-            'icon'   => '../../plugins/geotag/images/geotag.png',
136
-            'open'   => '{{geotag>lat:',
137
-            'sample' => '52.2345',
138
-            'close'  => ', lon:7.521, alt: , placename: , country: , region: }}'
139
-        );
140
-    }
124
+	/**
125
+	 * Inserts the toolbar button.
126
+	 *
127
+	 * @param Doku_Event $event
128
+	 *          the DokuWiki event
129
+	 */
130
+	public function insertButton(Doku_Event $event, $param)
131
+	{
132
+		$event->data [] = array(
133
+			'type'   => 'format',
134
+			'title'  => $this->getLang('toolbar_desc'),
135
+			'icon'   => '../../plugins/geotag/images/geotag.png',
136
+			'open'   => '{{geotag>lat:',
137
+			'sample' => '52.2345',
138
+			'close'  => ', lon:7.521, alt: , placename: , country: , region: }}'
139
+		);
140
+	}
141 141
 }
Please login to merge, or discard this patch.