jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_time.php] - Blame information for rev 99

 

Line No. Rev Author Line
185simandl<?php
2 
3class WeatherMapDataSource_time extends WeatherMapDataSource {
4 
5 function Recognise($targetstring)
6 {
7 if(preg_match("/^time:(.*)$/",$targetstring,$matches))
8 {
9 if(preg_match("/^[234]\./",phpversion()))
10 {
11 warn("Time DS Plugin recognised a TARGET, but needs PHP5+ to run. [WMTIME01]\n");
12 return FALSE;
13 }
14 return TRUE;
15 }
16 else
17 {
18 return FALSE;
19 }
20 }
21 
22 // function ReadData($targetstring, $configline, $itemtype, $itemname, $map)
23 function ReadData($targetstring, &$map, &$item)
24 {
25 $data[IN] = NULL;
26 $data[OUT] = NULL;
27 $data_time=0;
28 $itemname = $item->name;
29 
30 $matches=0;
31 
32 if(preg_match("/^time:(.*)$/",$targetstring,$matches))
33 {
34 $timezone = $matches[1];
35 $timezone_l = strtolower($timezone);
36 
37 $timezone_identifiers = DateTimeZone::listIdentifiers();
38 
39 foreach ($timezone_identifiers as $tz)
40 {
41 if(strtolower($tz) == $timezone_l)
42 {
43 debug ("Time ReadData: Timezone exists: $tz\n");
44 $dateTime = new DateTime("now", new DateTimeZone($tz));
45 
46 $item->add_note("time_time12",$dateTime->format("h:i"));
47 $item->add_note("time_time12ap",$dateTime->format("h:i A"));
48 $item->add_note("time_time24",$dateTime->format("H:i"));
49 $item->add_note("time_timezone",$tz);
50 $data[IN] = $dateTime->format("H");
51 $data_time = time();
52 $data[OUT] = $dateTime->format("i");
53 $matches++;
54 }
55 }
56 if($matches==0)
57 {
58 warn ("Time ReadData: Couldn't recognize $timezone as a valid timezone name [WMTIME02]\n");
59 }
60 }
61 else {
62 // some error code to go in here
63 warn ("Time ReadData: Couldn't recognize $targetstring \n");
64 }
65 
66 debug ("Time ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[OUT]).",$data_time)\n");
67 
68 return( array($data[IN], $data[OUT], $data_time) );
69 }
70}
71 
72// vim:ts=4:sw=4:
73?>

Powered by WebSVN 2.2.1