-
Notifications
You must be signed in to change notification settings - Fork 1
/
thermometer.php
799 lines (678 loc) · 25.7 KB
/
thermometer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
<?php
if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
// Thermometer image script
// Ken True - webmaster@Saratoga-weather.org
// error_reporting(E_ALL); // uncomment to run testing
// Version 1.00 - 17-Sep-2007 - Initial release
// Version 1.01 - 18-Nov-2007 - added GD test, autoscale function, updated for sce=view on IIS systems
// Version 1.02 - 23-Nov-2007 - fixed Notice: errata on min/max calculations
// Version 1.03 - 28-Feb-2008 - added support for Carterlake/AJAX/PHP template integration
// Version 1.04 - 02-Feb-2009 - added support for 'dark' template (white text instead of black)
// Version 1.05 - 21-Oct-2009 - added support for Cumulus realtime.txt
// Version 1.06 - 12-Jan-2011 - added support for new universal templates.
// Version 1.07 - 02-Apr-2011 - fixed WLrealtime offsets for WeatherLink
// Version 1.08 - 29-Jul-2011 - added support for Meteohub clientraw.txt
// Version 1.09 - 14-Jan-2012 - added support for WeatherSnoop via WSNtags/WSN-defs
// Version 1.10 - 24-Mar-2012 - added support for WeatherCat via WCTtags/WCT-defs or WCT_realtime.txt
// Version 1.11 - 03-Jul-2012 - added support for WxSolution, wview and Cumulus via CUtags.php if no realtime file
// Version 1.12 - 08-Mar-2013 - added support for Meteobridge via MBtags.php
//
// script available at http://saratoga-weather.org/scripts.php
//
// you may copy/modify/use this script as you see fit,
// no warranty is expressed or implied.
// This script reads WD clientraw.txt , VWS wflash.txt/wflash2.txt, or Cumulus realtime.txt
// gets the current, high, low temperature and draws a
// thermometer image (filled area + scale) on a transparent-background thermometer graphic
// PNG.
// usage on your page:
//
// <img src="thermometer.php" height="170" width="54" alt="current temperature, daily low/high" />
//
// New with version 1.01 - $autoScale = true; enables autoranging on output scale. The program will
// add majortick values to maximum or substract majortick values from minimum to always show the
// scale, current, minimum, maximum on the graphic.
//------------ settings ------------------
$wxSoftware = 'WD'; // 'WD' for Weather-Display, 'VWS' for Virtual Weather Station,
// 'CU' for Cumulus, 'WL' for WeatherLink, 'WXS' for WXSolution
//
$UOM = 'F'; // set to 'C' for Celsius/Centigrade, 'F'=Fahrenheit
//
$autoScale = true; // set to false to disable autoscale.
//
// you only have to set one of these correctly based on the $useWD selection
// $wxSoftware = 'WD' : set the $clientrawfile
// $wxSoftware = 'VWS': set the $wflashDir
// $wxSoftware = 'CU': set the $realtimefile
//
$clientrawfile = './clientraw.txt'; // relative file address for WD clientraw.txt
$wflashDir = './wflash/Data/'; // directory for the the VWS wflash.txt and wflash2.txt files
// // relative to directory location of this script (include
// // trailing '/' in the specification
$realtimefile = './realtime.txt'; // relative file location for Cumulus realtime.txt file
//$WLrealtime = './WLrealtime.txt'; // relative file location of WeatherLink WLrealtime.txt file
//
// settings for ranges -- adjust for your climate :-)
// Fahrenheit settings
$TmaxF = 105; // maximum °F temperature on thermometer
$TminF = 25; // minimum °F temperature on thermometer
$TincrF = 5; // increment number of degrees °F for major/minor ticks on thermometer
$TMajTickF = 10; // major tick with value when °F scale number divisible by this
// Centigrade settings
$TmaxC = 40; // maximum °C temperature on thermometer
$TminC = -10; // minimum °C temperature on thermometer
$TincrC = 2; // increment number of degrees °C for major/minor ticks on thermometer
$TMajTickC = 10; // major tick with value when °C scale number divisible by this
//
$invertColor = false; // set to true if thermometer display is over black background
$BlankGraphic = './thermometer-blank.png'; // relative file address for thermometer blank image PNG
$BlankGraphicBlack = './thermometer-blank-black.png'; // for black background use
//------------ end settings --------------
// overrides from Settings.php if available
if(file_exists("Settings.php")) { include_once("Settings.php"); }
global $SITE;
if (isset($SITE['uomTemp'])) {
$UOM = preg_replace('|°|is','',$SITE['uomTemp']);
if ($UOM <> 'F' and $UOM <> 'C') { $UOM = 'F'; }
}
if (isset($SITE['clientrawfile']) ) {$clientrawfile = $SITE['clientrawfile']; }
if (isset($SITE['wflashdir']) ) {$wflashDir = $SITE['wflashdir']; }
if (isset($SITE['realtimefile']) ) {$realtimefile = $SITE['realtimefile']; }
if (isset($SITE['WLrealtime']) ) {$WLrealtime = $SITE['WLrealtime']; }
if (isset($SITE['WCTrealtime']) ) {$WCTrealtime = $SITE['WCTrealtime']; }
if (isset($SITE['WXSrealtime']) ) {$WXSrealtime = $SITE['WXSrealtime']; }
if (isset($SITE['WVrealtime']) ) {$WVrealtime = $SITE['WVrealtime']; }
if (isset($SITE['WXsoftware']) ) {$wxSoftware = $SITE['WXsoftware']; }
$CSSstyle = '';
# was there a style selected from the form input
if (isset($_COOKIE['CSSstyle'])) {
$_SESSION['CSSstyle'] = $_COOKIE['CSSstyle'];
$CSSstyle = $_COOKIE['CSSstyle'];
} else if (isset($_SESSION['CSSstyle']) and $_SESSION['CSSstyle'] <> '' ) {
$CSSstyle = $_SESSION['CSSstyle'];
}
if (preg_match('|black|i',$CSSstyle) ) {
$invertColor = true;
}
// end of overrides from Settings.php
// -------------------begin code ------------------------------------------
if( ! function_exists("gd_info")){
die("Sorry.. this script requires the GD library in PHP to function.");
}
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'wd') { $wxSoftware = 'WD'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'vws') { $wxSoftware = 'VWS'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'cu') { $wxSoftware = 'CU'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'wl') { $wxSoftware = 'WL'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'mh') { $wxSoftware = 'MH'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'wsn') { $wxSoftware = 'WSN'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'wct') { $wxSoftware = 'WCT'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'wxs') { $wxSoftware = 'WXS'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'wv') { $wxSoftware = 'WV'; } // testing
if (isset($_REQUEST['wx']) and strtolower($_REQUEST['wx']) == 'mb') { $wxSoftware = 'MB'; } // testing
if (isset($_REQUEST['uom']) and strtolower($_REQUEST['uom']) == 'c') { $UOM = 'C'; }
if (isset($_REQUEST['uom']) and strtolower($_REQUEST['uom']) == 'f') { $UOM = 'F'; }
if (isset($_REQUEST['dark'])) {$invertColor = strtolower($_REQUEST['dark'])=='y'; }
if ($wxSoftware == 'WD' or $wxSoftware == 'MH') { // Get the Weather-Display/Meteohub clientraw.txt data file
$dataraw = file_get_contents($clientrawfile);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+[\s\t]*[\r\n]+/","\n",$dataraw);
$data = explode(" ", $dataraw);
$curtemp = CtoF($data[4],1);
$mintemp = CtoF($data[47],1);
$maxtemp = CtoF($data[46],1);
} // end Weather Display data
if ($wxSoftware == 'VWS') { // Get the VWS Weather Flash data files
$filename = "${wflashDir}wflash.txt";
$file = file($filename);
$file = implode('',$file);
$data = explode(",",$file);;
$curtemp = FtoC($data[9],1);
$filename = "${wflashDir}wflash2.txt";
$file = file($filename);
$file = implode('',$file);
$data = explode(",",$file);;
$mintemp = FtoC($data[92],1);
$maxtemp = FtoC($data[36],1);
}
if ($wxSoftware == 'CU') { // Get the Cumulus realtime.txt file
if(!isset($SITE['realtimefile']) and
isset($SITE['WXtags']) and file_exists($SITE['WXtags']) ) { // get from CUtags.php
global $WX;
include_once($SITE['WXtags']);
$inUOM = 'F';
$curtemp = 70;
$mintemp = 60;
$maxtemp = 80;
if(isset($WX['temp'])) {$curtemp = preg_replace('|,|','.',$WX['temp']); }
if(isset($WX['tempTL'])) {$mintemp = preg_replace('|,|','.',$WX['tempTL']); }
if(isset($WX['tempTH'])) {$maxtemp = preg_replace('|,|','.',$WX['tempTH']); }
if(isset($WX['tempunit']) and preg_match("|C|i",$WX['tempunit'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($curtemp,1);
$mintemp = FtoC($mintemp,1);
$maxtemp = FtoC($maxtemp,1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($curtemp,1);
$mintemp = CtoF($mintemp,1);
$maxtemp = CtoF($maxtemp,1);
}
} else { // get from realtime file
$dataraw = file_get_contents($realtimefile);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+[\s\t]*[\r\n]+/","\n",$dataraw);
$data = explode(" ", $dataraw);
$inUOM = $data[14];
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($data[2],1);
$mintemp = FtoC($data[28],1);
$maxtemp = FtoC($data[26],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($data[2],1);
$mintemp = CtoF($data[28],1);
$maxtemp = CtoF($data[26],1);
} else {
$curtemp = $data[2];
$mintemp = $data[28];
$maxtemp = $data[26];
$UOM = $inUOM;
}
} // end use realtime
}
if ($wxSoftware == 'MB') { // Process Meteobridge
if(!isset($MBrealtime)) { // get from MBtags.php
if (file_exists($SITE['WXtags'])) {
global $WX;
include_once($SITE['WXtags']);
}
$inUOM = 'F';
$curtemp = 70;
$mintemp = 60;
$maxtemp = 80;
if(preg_match("|C|i",$WX['uomTemp'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($WX['th0temp-act'],1);
$mintemp = FtoC($WX['th0temp-dmin'],1);
$maxtemp = FtoC($WX['th0temp-dmax'],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($WX['th0temp-act'],1);
$mintemp = CtoF($WX['th0temp-dmin'],1);
$maxtemp = CtoF($WX['th0temp-dmax'],1);
} elseif (isset($WX['th0temp-act'])) {
$curtemp = $WX['th0temp-act'];
$mintemp = $WX['th0temp-dmin'];
$maxtemp = $WX['th0temp-dmax'];
$UOM = $inUOM;
}
} else { // get from MB_realtime.txt
$dataraw = file_get_contents($MBrealtime);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+/",'',$dataraw);
$data = explode("|", $dataraw);
if(preg_match("/C/i",$data[14])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($data[2],1);
$mintemp = FtoC($data[28],1);
$maxtemp = FtoC($data[26],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($data[2],1);
$mintemp = CtoF($data[28],1);
$maxtemp = CtoF($data[26],1);
} else {
$curtemp = $data[2];
$mintemp = $data[28];
$maxtemp = $data[26];
$UOM = $inUOM;
}
} // end get from MB_realtime.txt
} // end Meteobridge processing
if ($wxSoftware == 'WL') { // Process WeatherLink
if(!isset($WLrealtime)) { // get from WLtags.php
if (file_exists($SITE['WXtags'])) {global $WX; include_once($SITE['WXtags']); }
$inUOM = 'F';
$curtemp = 70;
$mintemp = 60;
$maxtemp = 80;
if(preg_match("|C|i",$WX['tempUnit'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($WX['outsideTemp'],1);
$mintemp = FtoC($WX['lowOutsideTemp'],1);
$maxtemp = FtoC($WX['hiOutsideTemp'],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($WX['outsideTemp'],1);
$mintemp = CtoF($WX['lowOutsideTemp'],1);
$maxtemp = CtoF($WX['hiOutsideTemp'],1);
} elseif (isset($WX['outsideTemp'])) {
$curtemp = $WX['outsideTemp'];
$mintemp = $WX['lowOutsideTemp'];
$maxtemp = $WX['hiOutsideTemp'];
$UOM = $inUOM;
}
} else { // fetch it from the $WLrealtime
$dataraw = file_get_contents($WLrealtime);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+/",'',$dataraw);
$data = explode("|", $dataraw);
if(preg_match("/C/i",$data[14])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($data[2],1);
$mintemp = FtoC($data[28],1);
$maxtemp = FtoC($data[26],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($data[2],1);
$mintemp = CtoF($data[28],1);
$maxtemp = CtoF($data[26],1);
} else {
$curtemp = $data[2];
$mintemp = $data[28];
$maxtemp = $data[26];
$UOM = $inUOM;
}
} // end fetch it from $WLrealtime
} // end WeatherLink handling
if ($wxSoftware == 'WCT') { // Process WeatherCat
if(!isset($WCTrealtime)) { // get from WCTtags.php
if (file_exists($SITE['WXtags'])) {
global $WX;
include_once($SITE['WXtags']);
}
$inUOM = 'F';
$curtemp = 70;
$mintemp = 60;
$maxtemp = 80;
if(preg_match("|C|i",$WX['TEMPUNITS'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($WX['STAT:TEMPERATURE:CURRENT'],1);
$mintemp = FtoC($WX['STAT:TEMPERATURE:MIN:TODAY'],1);
$maxtemp = FtoC($WX['STAT:TEMPERATURE:MAX:TODAY'],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($WX['STAT:TEMPERATURE:CURRENT'],1);
$mintemp = CtoF($WX['STAT:TEMPERATURE:MIN:TODAY'],1);
$maxtemp = CtoF($WX['STAT:TEMPERATURE:MAX:TODAY'],1);
} elseif (isset($WX['STAT:TEMPERATURE:CURRENT'])) {
$curtemp = $WX['STAT:TEMPERATURE:CURRENT'];
$mintemp = $WX['STAT:TEMPERATURE:MIN:TODAY'];
$maxtemp = $WX['STAT:TEMPERATURE:MAX:TODAY'];
$UOM = $inUOM;
}
} else { // get from WCT_realtime.txt
$dataraw = file_get_contents($WCTrealtime);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+/",'',$dataraw);
$data = explode("|", $dataraw);
if(preg_match("/C/i",$data[14])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($data[2],1);
$mintemp = FtoC($data[28],1);
$maxtemp = FtoC($data[26],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($data[2],1);
$mintemp = CtoF($data[28],1);
$maxtemp = CtoF($data[26],1);
} else {
$curtemp = $data[2];
$mintemp = $data[28];
$maxtemp = $data[26];
$UOM = $inUOM;
}
} // end get from WCT_realtime.txt
} // end WeatherCat processing
if ($wxSoftware == 'WXS') { // Process WXSolution
if(!isset($WXSrealtime)) { // get from WXStags.php
if (file_exists($SITE['WXtags'])) {
global $WX;
include_once($SITE['WXtags']);
}
$inUOM = 'F';
$curtemp = 70;
$mintemp = 60;
$maxtemp = 80;
if(preg_match("|C|i",$WX['UT'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($WX['TC'],1);
$mintemp = FtoC($WX['DAY_TL'],1);
$maxtemp = FtoC($WX['DAY_TH'],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($WX['TC'],1);
$mintemp = CtoF($WX['DAY_TL'],1);
$maxtemp = CtoF($WX['DAY_TH'],1);
} elseif (isset($WX['TC'])) {
$curtemp = $WX['TC'];
$mintemp = $WX['DAY_TL'];
$maxtemp = $WX['DAY_TH'];
$UOM = $inUOM;
}
} else { // get from WXS_realtime.txt
$dataraw = file_get_contents($WCTrealtime);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+/",'',$dataraw);
$data = explode("|", $dataraw);
if(preg_match("/C/i",$data[14])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($data[2],1);
$mintemp = FtoC($data[28],1);
$maxtemp = FtoC($data[26],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($data[2],1);
$mintemp = CtoF($data[28],1);
$maxtemp = CtoF($data[26],1);
} else {
$curtemp = $data[2];
$mintemp = $data[28];
$maxtemp = $data[26];
$UOM = $inUOM;
}
} // end get from WXS_realtime.txt
} // end WXSolution processing
if ($wxSoftware == 'WV') { // Process wview
if(!isset($WVrealtime)) { // get from WVtags.php
if (file_exists($SITE['WXtags'])) {
global $WX;
include_once($SITE['WXtags']);
}
$inUOM = 'F';
$curtemp = 70;
$mintemp = 60;
$maxtemp = 80;
if(preg_match("|C|i",$WX['tempUnit'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($WX['outsideTemp'],1);
$mintemp = FtoC($WX['lowOutsideTemp'],1);
$maxtemp = FtoC($WX['hiOutsideTemp'],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($WX['outsideTemp'],1);
$mintemp = CtoF($WX['lowOutsideTemp'],1);
$maxtemp = CtoF($WX['hiOutsideTemp'],1);
} elseif (isset($WX['outsideTemp'])) {
$curtemp = $WX['outsideTemp'];
$mintemp = $WX['lowOutsideTemp'];
$maxtemp = $WX['hiOutsideTemp'];
$UOM = $inUOM;
}
} else { // get from WV_realtime.txt
$dataraw = file_get_contents($WVrealtime);
// clean up any blank lines
$dataraw = trim($dataraw);
$dataraw = preg_replace("/[\r\n]+/",'',$dataraw);
$data = explode("|", $dataraw);
if(preg_match("/C/i",$data[14])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = FtoC($data[2],1);
$mintemp = FtoC($data[28],1);
$maxtemp = FtoC($data[26],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = CtoF($data[2],1);
$mintemp = CtoF($data[28],1);
$maxtemp = CtoF($data[26],1);
} else {
$curtemp = $data[2];
$mintemp = $data[28];
$maxtemp = $data[26];
$UOM = $inUOM;
}
} // end get from WV_realtime.txt
} // end wview processing
if ($wxSoftware == 'WSN') { // Process WeatherSnoop (tags files only)
if (file_exists($SITE['WXtags'])) {
global $WX;
include_once($SITE['WXtags']);
}
$inUOM = 'F';
$curtemp = $temperature;
// $mintemp = '-';
// $maxtemp = '-';
if(preg_match("|C|i",$WX['temperature:outdoor:unit'])) {
$inUOM = 'C';
} else {
$inUOM = 'F';
}
if ($inUOM == 'F' and $UOM == 'C') {
$curtemp = $WX['temperature:outdoor:C'];
// $mintemp = FtoC($WX['lowOutsideTemp'],1);
// $maxtemp = FtoC($WX['hiOutsideTemp'],1);
} elseif ($inUOM == 'C' and $UOM == 'F') {
$curtemp = $WX['temperature:outdoor:F'];
// $mintemp = CtoF($WX['lowOutsideTemp'],1);
// $maxtemp = CtoF($WX['hiOutsideTemp'],1);
} else {
$curtemp = $WX['temperature:outdoor:'.$WX['temperature:outdoor:unit']];
// $mintemp = CtoF($WX['lowOutsideTemp'],1);
// $maxtemp = CtoF($WX['hiOutsideTemp'],1);
}
// if($mintemp == '-') {$mintemp = $curtemp;}
// if($maxtemp == '-') {$maxtemp = $curtemp;}
} // end WeatherSnoop processing
if (isset($_REQUEST['current'])) { $curtemp = $_REQUEST['current']; } // for testing
if (isset($_REQUEST['min'])) { $mintemp = $_REQUEST['min']; } // for testing
if (isset($_REQUEST['max'])) { $maxtemp = $_REQUEST['max']; } // for testing
if ($UOM == 'F') { // use Fahrenheit settings
$Tmax = $TmaxF; // maximum temperature on thermometer
$Tmin = $TminF; // minimum temperature on thermometer
$Tincr = $TincrF; // increment number of degrees for major/minor ticks on thermometer
$TMajTick = $TMajTickF;// major tick with value when scale number divisible by this
} else { // use Centigrade settings
$Tmax = $TmaxC; // maximum temperature on thermometer
$Tmin = $TminC; // minimum temperature on thermometer
$Tincr = $TincrC; // increment number of degrees for major/minor ticks on thermometer
$TMajTick = $TMajTickC;// major tick with value when scale number divisible by this
}
if($autoScale) { autoscale($curtemp,$mintemp,$maxtemp); }
genThermometer($curtemp, $mintemp,$maxtemp); // make graphic!
return;
// ----------- functions ----------------------------------------------------------
//
function genThermometer( $current,$min,$max ) {
global $UOM,$BlankGraphic,$BlankGraphicBlack,$wxSoftware,$invertColor;
global $Tmax,$Tmin,$Tincr,$TMajTick;
// draw a filled thermometer with scale, min max on a blank thermometer image
$BGfile = $invertColor?$BlankGraphicBlack:$BlankGraphic;
$image = LoadPNG($BGfile);
// settings relative to the thermometer image file defines the drawing area
// for the thermometer filling
// these settings are SPECIFICALLY for the thermometer-blank.png image background
$minX = 20; // left
$maxX = 24; // right
$minY = 20; // top
$maxY = 140;// bottom
$width = imagesx($image);
$height = imagesy($image);
$font = 1;
$bg = imagecolorallocate($image,255,255,255 );
$tx = imagecolorallocate($image,0,0,0);
$blue = imagecolorallocate($image,0,0,255);
$red = imagecolorallocate($image,255,0,0);
if ($invertColor) {
$tx = imagecolorallocate($image,255,255,255);
$blue = imagecolorallocate($image,0,192,255);
$red = imagecolorallocate($image,255,32,32);
}
$Trange = $Tmax - $Tmin; // total temperature range
$Tpct = ($current-$Tmin)/($Trange); // percent for current temperature of range
$Y = (1-$Tpct)*($maxY-$minY)+$minY; // upper location for fill
// fill the thermometer with a red bar from bottom to $Y
imagefilledrectangle( $image,
$minX,
$Y,
$maxX,
$maxY,
$red );
// Draw tick marks and scale values on right
for ($T=$Tmin;$T<=$Tmax;$T+=$Tincr) {
$Tpct = ($T-$Tmin)/($Trange);
$Y = (1-$Tpct)*($maxY-$minY)+$minY;
if ($T == 0 or ($T % $TMajTick) == 0) { // Major Tick
imagefilledrectangle( $image,
$maxX+7 ,
$Y ,
$maxX+12,
$Y +1, $tx );
imagestring($image, $font,
$maxX + 14,
$Y - (ImageFontHeight($font)/2),
sprintf( "%2d", $T),$tx);
} else { // Minor tick
imagefilledrectangle( $image,
$maxX+7,
$Y ,
$maxX+9,
$Y +1, $tx );
}
} // end do ticks legend
if(isset($min) and $min <> '-') { // put on minimum temp bar/value
// $Tpct = ($min-$Tmin)/($Trange);
$Tpct = ( ( (float)$min-$Tmin )/ $Trange );
$Y = (1-$Tpct)*($maxY-$minY)+$minY;
imagefilledrectangle( $image,
$minX - 18,
$Y ,
$minX - 5,
$Y +1, $blue );
$tstr = sprintf('%2d',round($min,0));
$tsize = strlen($tstr)*imagefontwidth($font+1);
imagestring($image, $font+1,
$minX - $tsize - 3 ,
$Y + 2 ,
$tstr,$blue);
}
if(isset($max) and $max <> '-') { // put on maximum temp bar/value
$Tpct = ($max-$Tmin)/($Trange);
$Y = (1-$Tpct)*($maxY-$minY)+$minY;
imagefilledrectangle( $image,
$minX - 18,
$Y ,
$minX - 5,
$Y +1, $red );
$tstr = sprintf('%2d',round($max,0));
$tsize = strlen($tstr)*imagefontwidth($font+1);
imagestring($image, $font+1,
$minX - $tsize - 3 ,
$Y - imagefontheight($font+1),
$tstr,$red);
}
// put legend on top with UOM
$cnt = chr(176) . $UOM; // chr(176) = degree sign in ISO-8859-1
imagestring( $image, $font+2, ($width/2)-((strlen($cnt)/2)*ImageFontWidth($font+2)),
(10-(ImageFontHeight($font+2) / 2)),
$cnt, $tx);
// write current temperature on thermometer bulb
// $tstr = sprintf('%2d',round($current,0));
// $tsize = strlen($cnt)*imagefontwidth($font);
// imagestring($image, $font,
// ($minX+$maxX)/2 - $tsize/2 -2 ,
// $maxY+6,
// $tstr,$bg);
//imagestring( $image, $font, ($width/2)-((strlen($wxSoftware)/2)*imagefontwidth($font)),
// $height-imagefontheight($font),
// $wxSoftware,$tx);
// send the image
header("content-type: image/png");
imagepng($image);
imagedestroy($image);
} // end genThermometer
// load PNG image
function LoadPNG ($imgname) {
$im = @imagecreatefrompng ($imgname); /* Attempt to open */
if (!$im) { /* See if it failed */
$im = imagecreate (150, 30); /* Create a blank image */
$bgc = imagecolorallocate ($im, 255, 255, 255);
$tc = imagecolorallocate ($im, 0, 0, 0);
imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring ($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
// CtoF: converts degrees Celcius to degress Farenheight (from Anolecomputing.com)
function CtoF($value, $precision) {
global $UOM;
if ($UOM <> 'F') {
return round($value,$precision);
} else {
return round($value = (($value * 9 / 5) + 32),$precision);
}
} // end function C_to_F
// FtoC: converts degress Farenheight to degrees Celcius (from Anolecomputing.com)
function FtoC($value, $precision) {
global $UOM;
if ($UOM == 'F') {
return round($value,$precision);
} else {
return round(($value - 32) * (5/9),$precision);
}
} // end function F to C
// autoscale function .. adjust scale to fit current conditions if need be.
function autoscale($curtemp,$mintemp,$maxtemp) {
global $Tmax,$Tmin,$Tincr,$TMajTick;
$highest = max($curtemp,$Tmax,$maxtemp);
$lowest = min($curtemp,$Tmin,$mintemp);
while ($Tmax < $highest) {
$Tmax += $TMajTick;
}
while ($Tmin > $lowest) {
$Tmin = $Tmin - $TMajTick;
}
return;
}
?>