jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [weathermap] - Rev 27 Go to most recent revision

Compare with Previous - Blame - Download


#!/usr/bin/php
<?php

// PHP Weathermap 0.92
// Copyright Howard Jones, 2005-2007 howie@thingy.com
// http://www.network-weathermap.com/
// Released under the GNU Public License
require_once 'Console/Getopt.php';

require_once "Weathermap.class.php";

if (!module_checks()) { die ("Quitting: Module checks failed.\n"); }

//    $weathermap_debugging=TRUE; // XXX - This needs to come out again!
$map=new Weathermap;
$map->context="cli";

$output="html";
$configfile="weathermap.conf";
$htmlfile='';
$imagefile='';
$DEBUG=0;
$dumpafter=0;
$randomdata=0;
$dumpconfig='';
$defines=array();

// **************************************************************************************
// THIS IS THE ONE LINE IN HERE YOU MIGHT HAVE TO CHANGE!
$map->rrdtool="/usr/bin/rrdtool";
// (on Windows, use / instead of \ in pathnames - c:/rrdtool/bin/rrdtool.exe for example)
// **************************************************************************************

// initialize object
$cg=new Console_Getopt();
$short_opts='';
$long_opts=array
        (
                "version",
                "help",
                "image-uri=",
                "config=",
                "output=",
                "debug",
                "define=",
                "no-data",
                "randomdata",
                "htmloutput=",
                "dumpafter",
                "bulge",
                "sizedebug",
                "dumpconfig="
        );

$args=$cg->readPHPArgv();

$ret=$cg->getopt($args, $short_opts, $long_opts);

if (PEAR::isError($ret)) { die ("Error in command line: " . $ret->getMessage() . "\n (try --help)\n"); }

$gopts=$ret[0];

if (sizeof($gopts) > 0)
{
        foreach ($gopts as $o)
        {
                switch ($o[0])
                {
                case '--config':
                        $configfile=$o[1];
                        break;

                case '--htmloutput':
                        $htmlfile=$o[1];
                        break;

                case '--dumpafter':
                        $dumpafter=1;
                        break;

                case '--image-uri':
                        $map->imageuri=$o[1];
                        break;

                case '--dumpconfig':
                        $map->dumpconfig=$o[1];
                        break;

                case '--randomdata':
                        $randomdata=1;
                        break;

                case '--debug':
                        $DEBUG=1;

                        $map->debugging=TRUE;
                        $weathermap_debugging=TRUE;
                        break;

                case '--sizedebug':
                case '--no-data':
                        $map->sizedebug=TRUE;
                        break;

                case '--bulge':
                        $map->widthmod=TRUE;
                        break;

                case '--output':
                        $imagefile=$o[1];
                        break;
                        
        case '--define':
            preg_match("/^([^=]+)=(.*)\s*$/",$o[1],$matches);
            $varname = $matches[1];
            $value = $matches[2];
            debug(">> $varname = '$value'\n");
            // save this for later, so that when the map object exists, it can be defined
            $defines[$varname]=$value;
            break;

                case '--version': 
                        print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n";
                        exit();
                        break;

                case '--help':
                        print 'PHP Network Weathermap v' . $WEATHERMAP_VERSION."\n";
                        print "Copyright Howard Jones, 2005-2007 howie@thingy.com\nReleased under the GNU Public License\nhttp://www.network-weathermap.com/\n\n";

                        print "Usage: php weathermap [options]\n\n";
                        
                        print " --config {filename}      -  filename to read from. Default weathermap.conf\n";
                        print " --output {filename}      -  filename to write image. Default weathermap.png\n";
                        print " --htmloutput {filename}  -  filename to write HTML. Default weathermap.html\n\n";
                        
                        print " --image-uri {uri}        -  URI to prefix <img> tags in HTML.\n";
                        print " --bulge                  -  Enable link-bulging mode. See manual.\n\n";
                        
                        print " --no-data                -  skip the data-reading process (just a 'grey' map)\n";
                        print " --randomdata            -  as above, but use random data\n";
                        print " --debug                  -  produce (LOTS) of debugging information during run\n";
                        print " --dump-after             -  dump all internal PHP structures (HUGE)\n";
                        print " --dumpconfig {filename}  -  filename to write a new config to (for testing)\n\n";
                        
                        print " --help                   -  show this help\n";
                        print " --version                -  show version number\n\n";
                        print "More info at http://www.network-weathermap.com/\n";
                        exit();
                        break;
                }
        }
}

if ($DEBUG)
{
        print "\n------------------------------------\n";
        print "Starting PHP-Weathermap run, with config: $configfile\n";
}

if ($map->ReadConfig($configfile))
{
        // allow command-lines to override the config file, but provide a default if neither are present
        if ($imagefile == '')
        {
                if ($map->imageoutputfile == '') { $imagefile="weathermap.png"; }
                else { $imagefile=$map->imageoutputfile; }
        }

        if ($htmlfile == '')
        {
                if ($map->htmloutputfile != '') { $htmlfile=$map->htmloutputfile; }
        }

    // feed in any command-line defaults, so that they appear as if SET lines in the config
    
    // FIXME
    foreach ($defines as $hintname=>$hint)
    {
        $map->add_hint($hintname,$hint);
    }

        if (!$map->sizedebug)
        {
                if ($randomdata == 1) { $map->RandomData(); }
                else { $map->ReadData(); }
        }

        if ($imagefile != '')
        {
                $map->DrawMap($imagefile);
                $map->imagefile=$imagefile;
        }

        if ($htmlfile != '')
        {
                $fd=fopen($htmlfile, 'w');
                fwrite($fd,
                        '<!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
                        . '</title></head><body>');

                if ($map->htmlstyle == "overlib")
                {
                        fwrite($fd,
                                "<div id=\"overDiv\" style=\"position:absolute; visibility:hidden; z-index:1000;\"></div>\n");
                        fwrite($fd,
                                "<script type=\"text/javascript\" src=\"overlib.js\"><!-- overLIB (c) Erik Bosrup --></script> \n");
                }

                fwrite($fd, $map->MakeHTML());
                fwrite($fd,
                        '<hr />Network Map created with <a href="http://www.network-weathermap.com/?vs='
                        . $WEATHERMAP_VERSION . '">PHP Network Weathermap v' . $WEATHERMAP_VERSION
                        . '</a></body></html>');
                fclose ($fd);
        }

        if ($map->dumpconfig != '')
                $map->WriteConfig($map->dumpconfig);

        if ($dumpafter == 1)
                print_r ($map);
}
else { die ("\n\nCould not read Weathermap config file. No output produced. Maybe try --help?\n"); }

// vim:ts=4:sw=4:

?>

Powered by WebSVN 2.2.1