jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_mrtg.php] - Blame information for rev 62

 

Line No. Rev Author Line
11simandl<?php
2// Sample Pluggable datasource for PHP Weathermap 0.9
3// - read a pair of values from a database, and return it
4 
5// TARGET dbplug:databasename:username:pass:hostkey
6 
7class WeatherMapDataSource_mrtg extends WeatherMapDataSource {
8 
9 function Recognise($targetstring)
10 {
11 if(preg_match("/\.(htm|html)$/",$targetstring,$matches))
12 {
13 return TRUE;
14 }
15 else
16 {
17 return FALSE;
18 }
19 }
20 
21 function ReadData($targetstring, &$map, &$item)
22 {
23 $inbw=-1;
24 $outbw=-1;
25 $data_time = 0;
26 
27 $matches=0;
28 
29 $fd=fopen($targetstring, "r");
30 
31 if ($fd)
32 {
33 while (!feof($fd))
34 {
35 $buffer=fgets($fd, 4096);
36 
37 if (preg_match("/<\!-- cuin d (\d+) -->/", $buffer, $matches)) { $inbw=$matches[1] * 8; }
38 
39 if (preg_match("/<\!-- cuout d (\d+) -->/", $buffer, $matches)) { $outbw=$matches[1] * 8; }
40 }
41 fclose($fd);
4218simandl # $data_time = filemtime($targetstring);
431simandl }
44 else {
45 // some error code to go in here
46 debug ("MRTG ReadData: Couldn't open ($targetstring). \n"); }
47 
48 debug ("MRTG ReadData: Returning ($inbw,$outbw,$data_time)\n");
49 
50 return ( array($inbw,$outbw,$data_time) );
51 }
52}
53 
54// vim:ts=4:sw=4:
55?>

Powered by WebSVN 2.2.1