First version of overview map generator. It is not tested yet and I think it will...
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 22 Nov 2008 22:02:10 +0000 (22:02 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Sat, 22 Nov 2008 22:02:10 +0000 (22:02 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/extensions/wrmap@331 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrmap.body.php [new file with mode: 0644]
wrmap.php [new file with mode: 0644]

diff --git a/wrmap.body.php b/wrmap.body.php
new file mode 100644 (file)
index 0000000..7188e4b
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+require_once dirname(__FILE__) . '/../wrgeo/wrgeo.body.php'; # for the function wrGeoGeoStringToGeo
+
+function wrMapParserFirstCallInit() {
+       global $wgParser;
+       $wgParser->setHook('wrmap', 'wrmapParserHook');
+       return true;
+}
+
+
+/// Format inside <wrmap>...</wrmap> has to be like this:
+///
+/// <wrmap>
+/// Rodelbahn|47.143241,11.208959|Birgitzer Alm
+/// ...
+/// </wrmap>
+function wrmapParserHook($input, $args, $parser) {
+       $output = '<googlemap>';
+       $lines = explode("\n", $input);
+       foreach ($lines as $line) {
+               try {
+                       $l = trim($line);
+                       if (strlen($l) == 0) continue;
+                       $columns = explode('|', $line);
+                       if (count($columns) != 3) throw new Exception(sprintf(utf8_encode('Die Anzahl der Spalten ist nicht 3 sondern %d'), count($columns)));
+                       $columns = list($type, $geo, $name) = $columns;
+                       list($latitude, $longitude) = wrGeoStringToGeo($geo);
+                       $output .= sprintf("%F,%F\n", $latitude, $longitude);
+               } catch (Exception $e) {
+                       return sprintf(utf8_encode('Ung├╝ltige Zeile in der Koordinatenliste: <em>%s</em>. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage()));
+               }
+       }
+       $output = $output .= "</googlemap>\n";
+       /*
+        global $wgTitle, $wgUser; 
+       $parser = new Parser();
+        $parserOptions = new ParserOptions();
+        $parserOptions->initialiseFromUser($wgUser);
+        $result = $parser->parse($output, $wgTitle, $parserOptions); // TODO: Make this call less complicated
+       */
+        $result = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution?
+
+       return $result->getText();
+}
+
+
+?>
diff --git a/wrmap.php b/wrmap.php
new file mode 100644 (file)
index 0000000..470237f
--- /dev/null
+++ b/wrmap.php
@@ -0,0 +1,16 @@
+<?php
+$wgExtensionCredits['parserhook'][] = array(
+       'name' => 'Winterrodeln Map',
+       'version' => '1.2.0',
+       'author' =>'Philipp Spitzer', 
+       'url' => 'http://www.winterrodeln.org', 
+       'description' => 'This extension creates a map from coordinates and uses the GoogleMaps extension to do so.'
+);
+
+
+$wgHooks['ParserFirstCallInit'][] = 'wrMapParserFirstCallInit';
+
+
+require_once dirname(__FILE__) . '/wrmap.body.php';
+
+?>