X-Git-Url: https://git.toastfreeware.priv.at/philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff_plain/81384d0adf08e1f7929bbdf0dd35b1582fb3d34c..1b96d2f3682d951792de2f8be8d23e1a4bd1d58b:/wrmap.body.php diff --git a/wrmap.body.php b/wrmap.body.php index f864714..e71b1ea 100644 --- a/wrmap.body.php +++ b/wrmap.body.php @@ -1,54 +1,44 @@ setHook('wrmap', 'wrmapParserHook'); - return true; -} +class WrMap { + /// Renders the tag + /// @param $content string - the content of the tag + /// @param $args array - the array of attribute name/value pairs for the tag + /// @param $parser Parser - the MW Parser object for the current page + /// + /// @return string - the html for rendering the map + public static function render($content, $args, $parser, $frame) { + // Get center and zoom level from $args + if (isset($args['lat'])) $latitude = floatval($args['lat']); else $latitude = 47.267648; // latitude as float value + if (isset($args['lon'])) $longitude = floatval($args['lon']); else $longitude = 11.404655; // longitude as float value + if (isset($args['zoom'])) $zoom = intval($args['zoom']); else $zoom = 10; // Google Zoom Level + $latitude_s = sprintf('%.6F', $latitude); + $longitude_s = sprintf('%.6F', $longitude); -/// Format inside ... has to be like this: -/// -/// -/// Rodelbahn|47.143241 N 11.208959 E|Birgitzer Alm -/// ... -/// -/// -/// The extension produces a format like this: -/// -/// 47.241731, 11.358994, Birgitzer Alm -/// Die Birgitzer Alm ist nett -/// 47.17607, 11.542763, Naviser Hütte -/// Die Naviser Hütte -/// -function wrmapParserHook($input, $args, $parser) { - $output = ''; // TODO: Varable coordinates - $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, %s\n", $latitude, $longitude, htmlspecialchars($name)); - } catch (Exception $e) { - return sprintf(utf8_encode('Ungültige Zeile in der Koordinatenliste: %s. %s'), htmlspecialchars($line), htmlspecialchars($e->getMessage())); + // Query database + $dbr = wfGetDB(DB_SLAVE); + $res = $dbr->select('wrsledruncache', array('page_title', 'position_latitude', 'position_longitude'), array('show_in_overview', 'not under_construction')); + $sledruns = array(); + while ($sledrun = $dbr->fetchRow($res)) $sledruns[] = $sledrun; + $dbr->freeResult($res); + + $parserOutput = $parser->getOutput(); + $parserOutput->addHeadItem('', 'googlemaps'); + $parserOutput->addModules('ext.wrmap'); + + // Create
element where the map is placed in + $output = "
\n"; + foreach ($sledruns as $sledrun) { + $lat = $sledrun['position_latitude']; + $lon = $sledrun['position_longitude']; + if (!$lat || !$lon) continue; + $output .= "

\n"; } + $output .= "

\n"; + + return $output; } - $output = $output .= "\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 - return $result->getText(); - */ - $result = $parser->recursiveTagParse($output); // TODO: Maybe this is already the solution? - return $result; + }