jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [weathermap] - Blame information for rev 7

 

Line No. Rev Author Line
12simandl#!/usr/bin/php
21simandl 
3<?php
4 
5// PHP Weathermap 0.91
6// Copyright Howard Jones, 2005-2007 howie@thingy.com
7// http://www.network-weathermap.com/
8// Released under the GNU Public License
9require_once 'Console/Getopt.php';
10 
11require_once "Weathermap.class.php";
12 
13if (!module_checks()) { die ("Quitting: Module checks failed.\n"); }
14 
15// $weathermap_debugging=TRUE; // XXX - This needs to come out again!
16$map=new Weathermap;
17$map->context="cli";
18 
19$output="html";
20$configfile="weathermap.conf";
21$htmlfile='';
22$imagefile='';
23$DEBUG=0;
24$dumpafter=0;
25$randomdata=0;
26$dumpconfig='';
27$defines=array();
28 
29// **************************************************************************************
30// THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE!
312simandl$map->rrdtool="/usr/bin/rrdtool";
321simandl// (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example)
33// **************************************************************************************
34 
35// initialize object
36$cg=new Console_Getopt();
37$short_opts='';
38$long_opts=array
39 (
40 "version",
41 "help",
42 "image-uri=",
43 "config=",
44 "output=",
45 "debug",
46 "define=",
47 "no-data",
48 "randomdata",
49 "htmloutput=",
50 "dumpafter",
51 "bulge",
52 "sizedebug",
53 "dumpconfig="
54 );
55 
56$args=$cg->readPHPArgv();
57 
58$ret=$cg->getopt($args, $short_opts, $long_opts);
59 
60if (PEAR::isError($ret)) { die ("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); }
61 
62$gopts=$ret[0];
63 
64if (sizeof($gopts) > 0)
65{
66 foreach ($gopts as $o)
67 {
68 switch ($o[0])
69 {
70 case '--config':
71 $configfile=$o[1];
72 break;
73 
74 case '--htmloutput':
75 $htmlfile=$o[1];
76 break;
77 
78 case '--dumpafter':
79 $dumpafter=1;
80 break;
81 
82 case '--image-uri':
83 $map->imageuri=$o[1];
84 break;
85 
86 case '--dumpconfig':
87 $map->dumpconfig=$o[1];
88 break;
89 
90 case '--randomdata':
91 $randomdata=1;
92 break;
93 
94 case '--debug':
95 $DEBUG=1;
96 
97 $map->debugging=TRUE;
98 $weathermap_debugging=TRUE;
99 break;
100 
101 case '--sizedebug':
102 case '--no-data':
103 $map->sizedebug=TRUE;
104 break;
105 
106 case '--bulge':
107 $map->widthmod=TRUE;
108 break;
109 
110 case '--output':
111 $imagefile=$o[1];
112 break;
113 
114 case '--define':
115 preg_match("/^([^=]+)=(.*)\s*$/",$o[1],$matches);
116 $varname = $matches[1];
117 $value = $matches[2];
118 debug(">> $varname = '$value'\n");
119 // save this for later, so that when the map object exists, it can be defined
120 $defines[$varname]=$value;
121 break;
122 
123 case '--version':
124 print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n";
125 exit();
126 break;
127 
128 case '--help':
129 print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n";
130 print "Copyright Howard Jones, 2005-2007 howie@thingy.com\nReleased under the GNU Public License\nhttp://www.network-weathermap.com/\n\n";
131 
132 print "Usage: php weathermap [options]\n\n";
133 
134 print " --config {filename} - filename to read from. Default weathermap.conf\n";
135 print " --output {filename} - filename to write image. Default weathermap.png\n";
136 print " --htmloutput {filename} - filename to write HTML. Default weathermap.html\n\n";
137 
138 print " --image-uri {uri} - URI to prefix <img> tags in HTML.\n";
139 print " --bulge - Enable link-bulging mode. See manual.\n\n";
140 
141 print " --no-data - skip the data-reading process (just a 'grey' map)\n";
142 print " --random-data - as above, but use random data\n";
143 print " --debug - produce (LOTS) of debugging information during run\n";
144 print " --dump-after - dump all internal PHP structures (HUGE)\n";
145 print " --dumpconfig {filename} - filename to write a new config to (for testing)\n\n";
146 
147 print " --help - show this help\n";
148 print " --version - show version number\n\n";
149 print "More info at http://www.network-weathermap.com/\n";
150 exit();
151 break;
152 }
153 }
154}
155 
156if ($DEBUG)
157{
158 print "\n------------------------------------\n";
159 print "Starting PHP-Weathermap run, with config: $configfile\n";
160}
161 
162if ($map->ReadConfig($configfile))
163{
164 // allow command-lines to override the config file, but provide a default if neither are present
165 if ($imagefile == '')
166 {
167 if ($map->imageoutputfile == '') { $imagefile="weathermap.png"; }
168 else { $imagefile=$map->imageoutputfile; }
169 }
170 
171 if ($htmlfile == '')
172 {
173 if ($map->htmloutputfile != '') { $htmlfile=$map->htmloutputfile; }
174 }
175 
176 // feed in any command-line defaults, so that they appear as if SET lines in the config
177 
178 // FIXME
179 foreach ($defines as $hintname=>$hint)
180 {
181 $map->add_hint($hintname,$hint);
182 }
183 
184 if (!$map->sizedebug)
185 {
186 if ($randomdata == 1) { $map->RandomData(); }
187 else { $map->ReadData(); }
188 }
189 
190 if ($imagefile != '')
191 {
192 $map->DrawMap($imagefile);
193 $map->imagefile=$imagefile;
194 }
195 
196 if ($htmlfile != '')
197 {
198 $fd=fopen($htmlfile, 'w');
199 fwrite($fd,
200 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="refresh" content="300" /><title>' . $map->title
201 . '</title></head><body>');
202 
203 if ($map->htmlstyle == "overlib")
204 {
205 fwrite($fd,
206 "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n");
207 fwrite($fd,
208 "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n");
209 }
210 
211 fwrite($fd, $map->MakeHTML());
212 fwrite($fd,
213 '<hr />Network Map created with <a href="http://www.network-weathermap.com/?vs='
214 . $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION
215 . '</a></body></html>');
216 fclose ($fd);
217 }
218 
219 if ($map->dumpconfig != '')
220 $map->WriteConfig($map->dumpconfig);
221 
222 if ($dumpafter == 1)
223 print_r ($map);
224}
225else { die ("\n\nCould not read Weathermap config file. No output produced. Maybe try --help?\n"); }
226 
227// vim:ts=4:sw=4:
228 
229?>

Powered by WebSVN 2.2.1