e0f7d2ca380319678b93ff77873f3fe69afd9966
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / wrmap.body.php
1 <?php
2
3 class WrMap {
4         /// Renders the <wrgmap> tag
5         /// @param $content string - the content of the <wrgmap> tag
6         /// @param $args array - the array of attribute name/value pairs for the tag
7         /// @param $parser Parser - the MW Parser object for the current page
8         ///
9         /// @return string - the html for rendering the map
10         public static function render($content, $args, $parser, $frame) {
11                 // Get center and zoom level from $args
12                 if (isset($args['lat'])) $latitude = floatval($args['lat']); else $latitude = 47.267648;   // latitude as float value
13                 if (isset($args['lon'])) $longitude = floatval($args['lon']); else $longitude = 11.404655; // longitude as float value
14                 if (isset($args['zoom'])) $zoom = intval($args['zoom']); else $zoom = 10; // Google Zoom Level
15                 $latitude_s = sprintf('%.6F', $latitude);
16                 $longitude_s = sprintf('%.6F', $longitude);
17
18                 // Query database
19                 $dbr = wfGetDB(DB_SLAVE);
20                 $res = $dbr->select('wrsledruncache', array('page_title', 'position_latitude', 'position_longitude'), array('show_in_overview', 'not under_construction'));
21                 $sledruns = array();
22                 while ($sledrun = $dbr->fetchRow($res)) $sledruns[] = $sledrun;
23                 $dbr->freeResult($res);
24                 
25                 $parserOutput = $parser->getOutput();
26                 $parserOutput->addHeadItem('<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.8&amp;sensor=false"></script>', 'googlemaps');
27                 $parserOutput->addModules('ext.wrmap');
28                 
29                 // Create <div/> element where the map is placed in
30                 global $wgExtensionAssetsPath;
31                 $output = "<div class=\"wrmap\" style=\"width: 100%; height: 450px; border-style:none;\" data-center-lon=\"$longitude_s\" data-center-lat=\"$latitude_s\" data-zoom=\"$zoom\" data-img-path=\"$wgExtensionAssetsPath/wrmap/openlayers/img/\">\n";
32                 foreach ($sledruns as $sledrun) {
33                         $lat = $sledrun['position_latitude'];
34                         $lon = $sledrun['position_longitude'];
35                         if (!$lat || !$lon) continue;
36                         $title = Title::newFromText($sledrun['page_title']);
37                         $output .= "<p data-lon=\"$lon\" data-lat=\"$lat\" data-title=\"{$title->getText()}\" data-url=\"{$title->getLocalUrl()}\" />\n";
38                 }
39                 $output .= "</div>\n";
40                 
41                 return $output;
42         }
43
44 }
45
46
47 ?>