Difference between revisions of "Extensions/miniville"
(add code for miniville xml status parse and table renderer) |
(new code) |
||
Line 28: | Line 28: | ||
xml_parse_into_struct($p, $c, $vals, $index); | xml_parse_into_struct($p, $c, $vals, $index); | ||
xml_parser_free($p); | xml_parser_free($p); | ||
− | $htmltxt = "<table $style class=\"diff\">\n"; | + | $url=""; |
+ | $htmltxt = "<table $style class=\"diff\" cellpadding=2>\n"; | ||
for ($i=0; $i < count($vals); $i+=1) { | for ($i=0; $i < count($vals); $i+=1) { | ||
if($vals[$i]["level"]==2) { | if($vals[$i]["level"]==2) { | ||
− | $htmltxt .= "<tr><td>".ucfirst(strtolower($vals[$i]["tag"]))."</td><td>".$vals[$i]["value"]."</td></tr>\n"; | + | $t=strtolower($vals[$i]["tag"]); |
+ | $x=""; | ||
+ | if($t == "host") { | ||
+ | $url="http://".$vals[$i]["value"]."/"; | ||
+ | $x="<a href=\"".$url."\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "population") { | ||
+ | $x="<a href=\"".$url."\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "unemployment") { | ||
+ | $x="<a href=\"".$url."ind\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "transport") { | ||
+ | $x="<a href=\"".$url."tra\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "criminality") { | ||
+ | $x="<a href=\"".$url."sec\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "pollution") { | ||
+ | $x="<a href=\"".$url."env\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "incomes") { | ||
+ | $x="<a href=\"".$url."com\">".ucfirst($t)."</url>"; | ||
+ | } | ||
+ | if($t == "ranking") { | ||
+ | $x=ucfirst($t); | ||
+ | } | ||
+ | if(strlen($x)!=0) { | ||
+ | $htmltxt .= "<tr><td>".$x."</td><td>".$vals[$i]["value"]."</td></tr>\n"; | ||
+ | } else { | ||
+ | // $htmltxt .= "<tr><td>".ucfirst(strtolower($vals[$i]["tag"]))."</td><td>".$vals[$i]["value"]."</td></tr>\n"; | ||
+ | } | ||
} | } | ||
} | } | ||
Line 38: | Line 70: | ||
} | } | ||
?> | ?> | ||
− | |||
</pre> | </pre> |
Latest revision as of 13:39, 6 October 2007
Implement a miniville XML status parser
- Requires libexpat to be compiled into PHP
Usage: <miniville>[villename]</miniville>
Optionally add a 'style=""' parameter to the tag, so it can style the table.
<?php $wgExtensionFunctions[] = "wfMiniville"; function wfMiniville() { global $wgParser; $wgParser->setHook( "miniville", "render_miniville_xml" ); } function render_miniville_xml ( $ville_name , $argv, $parser ) { $style=""; if(isset($argv["style"])) { $style="style=\"".$argv["style"]."\""; } $c = file_get_contents("http://$ville_name.miniville.fr/xml",FALSE,NULL,0,1024); if(strstr($c,"<html>")!=FALSE) { return("<p>$ville_name not found</p>\n"); } $p = xml_parser_create(); xml_parse_into_struct($p, $c, $vals, $index); xml_parser_free($p); $url=""; $htmltxt = "<table $style class=\"diff\" cellpadding=2>\n"; for ($i=0; $i < count($vals); $i+=1) { if($vals[$i]["level"]==2) { $t=strtolower($vals[$i]["tag"]); $x=""; if($t == "host") { $url="http://".$vals[$i]["value"]."/"; $x="<a href=\"".$url."\">".ucfirst($t)."</url>"; } if($t == "population") { $x="<a href=\"".$url."\">".ucfirst($t)."</url>"; } if($t == "unemployment") { $x="<a href=\"".$url."ind\">".ucfirst($t)."</url>"; } if($t == "transport") { $x="<a href=\"".$url."tra\">".ucfirst($t)."</url>"; } if($t == "criminality") { $x="<a href=\"".$url."sec\">".ucfirst($t)."</url>"; } if($t == "pollution") { $x="<a href=\"".$url."env\">".ucfirst($t)."</url>"; } if($t == "incomes") { $x="<a href=\"".$url."com\">".ucfirst($t)."</url>"; } if($t == "ranking") { $x=ucfirst($t); } if(strlen($x)!=0) { $htmltxt .= "<tr><td>".$x."</td><td>".$vals[$i]["value"]."</td></tr>\n"; } else { // $htmltxt .= "<tr><td>".ucfirst(strtolower($vals[$i]["tag"]))."</td><td>".$vals[$i]["value"]."</td></tr>\n"; } } } $htmltxt .= "</table>\n"; return $htmltxt; } ?>