|
From: <ma...@sc...> - 2006-05-01 07:50:00
|
Update of /cvsroot/meshdb/www/db2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1414/www/db2 Modified Files: google.php Log Message: changed defaults, bit of tweaking Index: google.php =================================================================== RCS file: /cvsroot/meshdb/www/db2/google.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- google.php 14 Apr 2006 17:42:11 -0000 1.7 +++ google.php 1 May 2006 07:49:50 -0000 1.8 @@ -19,6 +19,18 @@ /* give up, leaving only the error */ exit(0); } + + /* either buffer when zipping or echo text directly */ + function output($data) { + + global $zip, $kml_text; + if ($zip == 1) { + $kml_text .= $data; + } else { + echo $data; + } + + } /* restrict to one node */ if (isset($HTTP_GET_VARS['nodeid'])) { @@ -26,7 +38,7 @@ } /* show links to peers */ - $links = 0; + $links = 1; if (isset($HTTP_GET_VARS['links'])) { $links = $HTTP_GET_VARS['links']; } @@ -37,7 +49,7 @@ $maxdays = $HTTP_GET_VARS['maxdays']; } - /* send as zip file */ + /* send as zip file (speed vs bandwidth) */ $zip = 0; if (isset($HTTP_GET_VARS['zip'])) { $zip = $HTTP_GET_VARS['zip']; @@ -49,8 +61,13 @@ $save = $HTTP_GET_VARS['save']; } + /* dont default to having folders if only one node */ + $folders = 1; + if (isset($nodeid)) { + $folders = 0; + } + /* categorise by status */ - $folders = 0; if (isset($HTTP_GET_VARS['folders'])) { $folders = $HTTP_GET_VARS['folders']; } @@ -74,17 +91,39 @@ if (isset($nodeid)) { $query = $query . " and a.nodeid=$nodeid"; } else { - $query = $query . " order by a.status, a.nodename"; + if ($folders == 1) { + $query = $query . " order by a.status, a.nodename"; + } else { + $query = $query . " order a.nodename"; + } } /* get all nodes (query from hell to trim out garbage nodes) */ $result = mysql_query($query, $db) or nice_die(mysql_error($db)); + + /* start empty */ + $kml_text = ""; + + /* send headers if not buffering for zip */ + if ($zip == 0) { + if ($save == 1) { + //header("Content-Type: application/vnd.google-earth.kml+xml"); + /* above is broken, wont force download in mozilla (works in ie), below works for both */ + header("Content-Type: text/plain"); + header("Content-disposition: attachment; filename=brismesh.kml"); /* save as filename */ + } else { + header("Content-Type: application/vnd.google-earth.kml+xml"); + } + } + + /* cache control - comment out if testing */ + header("Last-Modified: ".gmdate("D, d M Y H:i:s", $gmt_updated)." GMT"); /* xml header (no nice_die() after here) */ - $kml_text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; - $kml_text .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"; - $kml_text .= "<Document>\n"; + output("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + output("<kml xmlns=\"http://earth.google.com/kml/2.0\">\n"); + output("<Document>\n"); /* 0 used to mark "not found" later */ $rows = 0; @@ -134,51 +173,51 @@ } /* generate the next icon style */ - $kml_text .= " <Style id=\"$validStyles[$i]\">\n"; - $kml_text .= " <IconStyle id=\"iconStyle_$validStyles[$i]\">\n"; - $kml_text .= " <Icon>\n"; - $kml_text .= " <href>$pallette</href>\n"; - $kml_text .= " <x>$offsetx</x>\n"; - $kml_text .= " <y>$offsety</y>\n"; - $kml_text .= " <w>$sizex</w>\n"; - $kml_text .= " <h>$sizey</h>\n"; - $kml_text .= " </Icon>\n"; - $kml_text .= " </IconStyle>\n"; + output(" <Style id=\"$validStyles[$i]\">\n"); + output(" <IconStyle id=\"iconStyle_$validStyles[$i]\">\n"); + output(" <Icon>\n"); + output(" <href>$pallette</href>\n"); + output(" <x>$offsetx</x>\n"); + output(" <y>$offsety</y>\n"); + output(" <w>$sizex</w>\n"); + output(" <h>$sizey</h>\n"); + output(" </Icon>\n"); + output(" </IconStyle>\n"); - /* default label seems to be fine, so no change for now */ - //$kml_text .= " <LabelStyle id=\"labelStyle_$validStyles[$i]\">\n"; - //$kml_text .= " <color>7fffaaff</color>\n"; - //$kml_text .= " <scale>1.5</scale>\n"; - //$kml_text .= " </LabelStyle>\n"; + /* default label font seems to be fine, so no change for now */ + //output(" <LabelStyle id=\"labelStyle_$validStyles[$i]\">\n"); + //output(" <color>7fffaaff</color>\n"); + //output(" <scale>1.5</scale>\n"); + //output(" </LabelStyle>\n"); /* style for line extrused from ground to $alt */ - $kml_text .= " <LineStyle id=\"lineStyle_$validStyles[$i]\">\n"; - $kml_text .= " <color>ff0000ff</color>\n"; - $kml_text .= " <width>3</width>\n"; - $kml_text .= " </LineStyle>\n"; - $kml_text .= " </Style>\n"; + output(" <LineStyle id=\"lineStyle_$validStyles[$i]\">\n"); + output(" <color>ff0000ff</color>\n"); + output(" <width>3</width>\n"); + output(" </LineStyle>\n"); + output(" </Style>\n"); } /* style for intra node links */ - $kml_text .= " <Style id=\"linkStyle\">\n"; - $kml_text .= " <LineStyle id=\"lineStyle_linkStyle\">\n"; - $kml_text .= " <color>7fff0000</color>\n"; - $kml_text .= " <width>3</width>\n"; - $kml_text .= " </LineStyle>\n"; - $kml_text .= " <IconStyle id=\"iconStyle_linkStyle\">\n"; - $kml_text .= " <Icon>\n"; - $kml_text .= " <href>root://icons/palette-5.png</href>\n"; - $kml_text .= " <x>96</x>\n"; - $kml_text .= " <y>64</y>\n"; - $kml_text .= " <w>32</w>\n"; - $kml_text .= " <h>32</h>\n"; - $kml_text .= " </Icon>\n"; - $kml_text .= " </IconStyle>\n"; - $kml_text .= " </Style>\n"; + output(" <Style id=\"linkStyle\">\n"); + output(" <LineStyle id=\"lineStyle_linkStyle\">\n"); + output(" <color>7fff0000</color>\n"); + output(" <width>3</width>\n"); + output(" </LineStyle>\n"); + output(" <IconStyle id=\"iconStyle_linkStyle\">\n"); + output(" <Icon>\n"); + output(" <href>root://icons/palette-5.png</href>\n"); + output(" <x>96</x>\n"); + output(" <y>64</y>\n"); + output(" <w>32</w>\n"); + output(" <h>32</h>\n"); + output(" </Icon>\n"); + output(" </IconStyle>\n"); + output(" </Style>\n"); /* default enclosing folder */ - $kml_text .= "<Folder><name>BrisMESH Nodes</name>\n"; + output("<Folder><name>BrisMESH Nodes</name>\n"); $last_status = ""; while (($row = mysql_fetch_assoc($result))) { @@ -202,11 +241,17 @@ /* skip invalid values (out of zone coords) */ if ($lat == 0 || $lon == 0) { - $kml_text .= "<!-- zero lat=$lat OR lon=$lon, skipping node ".$row['nodeid']." -->/n"; + output("<!-- zero lat=$lat OR lon=$lon, skipping node ".$row['nodeid']." -->/n"); + continue; + } + + /* skip invalid values (wrong sign on lat / lon) */ + if ($lat > 0 || $lon < 0) { + output("<!-- bogus lat=$lat OR lon=$lon, skipping node ".$row['nodeid']." (probably wrong sign) -->/n"); continue; } - /* find the style to use */ + /* find the style to use, or use #default */ $style = "#default"; $i = array_search($row['status'], $validStyles); if (isset($i)) { @@ -219,34 +264,34 @@ */ if ($folders == 1 && !isset($nodeid) && $last_status != $row['status']) { if ($last_status != "") { - $kml_text .= "</Folder>\n"; + output("</Folder>\n"); } - $kml_text .= "<Folder><name>".$row['status']."</name>\n"; + output("<Folder><name>".$row['status']."</name>\n"); $last_status = $row['status']; } /* display the row */ - $kml_text .= " <Placemark>\n"; - $kml_text .= " <description><![CDATA[Contact's Name: " . htmlspecialchars($row['contactname']) . "<br>View <a href=\"http://www.itee.uq.edu.au/~mesh/db-srtm/view.php?nodeid=".$row['nodeid']."\">Node Details</a> on BrisMESH<br>Last Updated: ".$updated."]]></description>\n"; - $kml_text .= " <name><![CDATA[" . $row['nodename'] . "]]></name>\n"; - $kml_text .= " <styleUrl>$style</styleUrl>\n"; - $kml_text .= " <LookAt>\n"; - $kml_text .= " <longitude>$lon</longitude>\n"; - $kml_text .= " <latitude>$lat</latitude>\n"; - $kml_text .= " <range>" . 500 . "</range>\n"; - $kml_text .= " <tilt>0</tilt>\n"; - $kml_text .= " <heading>3</heading>\n"; - $kml_text .= " </LookAt>\n"; + output(" <Placemark>\n"); + output(" <description><![CDATA[Contact's Name: " . htmlspecialchars($row['contactname']) ."<br>View <a href=\"http://www.itee.uq.edu.au/~mesh/db-srtm/view.php?nodeid=".$row['nodeid']."\">Node #".$row['nodeid']."</a> on BrisMESH<br>Last Updated: ".$updated."]]></description>\n"); + output(" <name><![CDATA[" . $row['nodename'] . "]]></name>\n"); + output(" <styleUrl>$style</styleUrl>\n"); + output(" <LookAt>\n"); + output(" <longitude>$lon</longitude>\n"); + output(" <latitude>$lat</latitude>\n"); + output(" <range>" . 500 . "</range>\n"); + output(" <tilt>0</tilt>\n"); + //output(" <heading>3</heading>\n"); + output(" </LookAt>\n"); /* point on the map */ - $kml_text .= " <Point>\n"; - $kml_text .= " <extrude>1</extrude>\n"; - $kml_text .= " <altitudeMode>relativeToGround</altitudeMode>\n"; - $kml_text .= " <coordinates>$lon,$lat,$alt</coordinates>\n"; - $kml_text .= " </Point>\n"; + output(" <Point>\n"); + output(" <extrude>1</extrude>\n"); + output(" <altitudeMode>relativeToGround</altitudeMode>\n"); + output(" <coordinates>$lon,$lat,$alt</coordinates>\n"); + output(" </Point>\n"); /* finish placemark */ - $kml_text .= " </Placemark>\n"; + output(" </Placemark>\n"); /* add links as placemarks */ if ($links == 1) { @@ -279,17 +324,17 @@ } /* emit the link placemark */ - $kml_text .= " <Placemark>\n"; - $kml_text .= " <name>link_".$row2['nodeid']."_to_".$row2['peerid']."</name>\n"; - $kml_text .= " <styleUrl>#linkStyle</styleUrl>\n"; - $kml_text .= " <LineString>\n"; - $kml_text .= " <altitudeMode>relativeToGround</altitudeMode>\n"; - $kml_text .= " <coordinates>\n"; - $kml_text .= " $lon1, $lat1, $alt1\n"; - $kml_text .= " $lon2, $lat2, $alt2\n"; - $kml_text .= " </coordinates>\n"; - $kml_text .= " </LineString>\n"; - $kml_text .= " </Placemark>\n"; + output(" <Placemark>\n"); + output(" <name>link_".$row2['nodeid']."_to_".$row2['peerid']."</name>\n"); + output(" <styleUrl>#linkStyle</styleUrl>\n"); + output(" <LineString>\n"); + output(" <altitudeMode>relativeToGround</altitudeMode>\n"); + output(" <coordinates>\n"); + output(" $lon1, $lat1, $alt1\n"); + output(" $lon2, $lat2, $alt2\n"); + output(" </coordinates>\n"); + output(" </LineString>\n"); + output(" </Placemark>\n"); } @@ -309,36 +354,23 @@ /* if we got no rows, display an error */ if ($rows == 0) { if (isset($nodeid)) { - $kml_text .= "<Folder><name>Node ".$nodeid." not valid.</name></Folder>"; + output("<Folder><name>Node ".$nodeid." not valid.</name></Folder>"); } else { - $kml_text .= "<Folder><name>no results available</name></Folder>"; + output("<Folder><name>no results available</name></Folder>"); } } if ($folders) { - $kml_text .= "</Folder>\n"; + output("</Folder>\n"); } /* xml footer */ - $kml_text .= "</Folder>\n"; - $kml_text .= "</Document>\n"; - $kml_text .= "</kml>\n"; - - /* cache control - comment out if testing */ - header("Last-Modified: ".gmdate("D, d M Y H:i:s", $gmt_updated)." GMT"); + output("</Folder>\n"); + output("</Document>\n"); + output("</kml>\n"); - if ($zip == 0) { - - /* send headers */ - header("Content-Type: application/vnd.google-earth.kml+xml"); - if ($save == 1) { - header("Content-disposition: attachment; filename=brismesh.kml"); - } - - /* send plain text */ - echo $kml_text; - - } else { + /* zip the buffered text */ + if ($zip == 1) { /* instantiate the zipfile */ $theZip = new zipfile; @@ -347,13 +379,18 @@ $theZip->add_file($kml_text, "doc.kml"); /* content type */ - header('Content-Type: application/vnd.google-earth.kmz'); if ($save == 1) { - header("Content-disposition: attachment; filename=brismesh.kmz"); + //header('Content-Type: application/vnd.google-earth.kmz'); + /* above is broken, wont force download in mozilla (works in ie), below works for both */ + header("Content-Type: application/octet-stream"); + header("Content-disposition: attachment; filename=brismesh.kmz"); /* save as filename */ + } else { + header('Content-Type: application/vnd.google-earth.kmz'); } /* send zip */ print ($theZip->file); } -?> + +?> \ No newline at end of file |