Location: PHPKode > scripts > Homeland Security Threat Level Block > homeland-security-threat-level-block/block-HomelandSecurity.php
<?
// phpNuke homeland security block
// by jon roig - 03-20-2003
// hide@address.com // http://jonroig.com
// this code (such as it is!) is released under the GPL

// SETUP INFO
// you'll need to register with tinetics to access their service. It's free, though....
// you should also set up the correct path to your data file

// TINETICS.COM USERNAME/PASSWORD
$config["tUsername"] = "";
$config["tPassword"] = "";

// CACHE FILE LOCATION
$config["dataPath"] = "YOUR FILE PATH HERE/blocks/homeland_security/homeland_data/homeland_data.txt";

// where the graphics files are located -- leave on the trailing slash. Located in blocks by default
$config["graphicsPath"] = "blocks/homeland_security/homeland_graphics/";


// THE STUFF BENEATH THIS LINE YOU PROBABLY WON'T NEED TO MESS WITH... 

// frequency in which the cache file is updated (in minutes). Default is 240 minutes -- we want to be nice to the server, right?
$config["cacheFrequency"] = 240;

// the actual method which accesses the service. You probably won't need to mess with this....
$config["methodURL"] = "http://www.tinetics.com/webservices/securitylevel.cfc?method=getsecuritylevel&username=".$config["tUsername"]."&password=".$config["tPassword"];



// redirect if the user is coming in the wrong way
if (eregi("block-HomelandSecurity.php",$PHP_SELF)) {
    Header("Location: index.php");
    die();
}

// check the file to make sure it exists and has data
if(file_exists($config["dataPath"]))
	{
	// get the date and time from the last update
	//$homelandLastUpdated = fileatime($config["dataPath"]);
	$homelandCacheAge = ceil(time() - filemtime($config["dataPath"]));
	
	
	if ($homelandCacheAge > ($config["cacheFrequency"]*60))
		{
		
		// access the webservice and update the cache
		// access the service itself via fopen
		if(!($securityLevelService = file($config["methodURL"])))
			$error = "Cannot access the service...";

		// now loop through the resulting array and add it all into a single string
		foreach($securityLevelService as $lines) {$service_data .= $lines;}
		
		// this is the most retarded implementation imaginable, but rather than mess with pear and whatnot for such a small
		// thing (especially when various soap methods vary in terms of their availability), I figured it'd keep it simple...
		// instead of the high fallutin' XML handling, we're just going to strip that stuff out
		$homelandSecurityLevel = trim($service_data);
		$homelandSecurityLevel = str_replace("<wddxPacket version='1.0'><header/><data><string>", "", $homelandSecurityLevel);
		$homelandSecurityLevel = str_replace("</string></data></wddxPacket>", "", $homelandSecurityLevel);
		if(!($hsl = fopen($config["dataPath"], "w")))
			$error = "Cannot open cache file...";
		fwrite ($hsl, $homelandSecurityLevel);
		fclose ($hsl);
		}
	else
		{
		// just read from the cache
		if(!($hsl = fopen($config["dataPath"], "r+")))
			$error = "Cannot open cache file...";
		$homelandSecurityLevel = fread($hsl, filesize($config["dataPath"]));
		}
	
 	}


else
	{
	// AHHhh... can't access the file!
	$error = "Cannot access cache file";
	}
	

// generate an explanation
switch ($homelandSecurityLevel)
	{
	case "SEVERE":
		$homelandSecurityLevelExplanation = "Severe Risk of Terrorist Attacks";
		break;
	case "HIGH":
		$homelandSecurityLevelExplanation = "High Risk of Terrorist Attacks";
		break;
	case "ELEVATED":
		$homelandSecurityLevelExplanation = "Significant Risk of Terrorist Attacks";
		break;
	case "GUARDED":
		$homelandSecurityLevelExplanation = "General Risk of Terrorist Attacks";
		break;
	case "LOW":
		$homelandSecurityLevelExplanation = "Low Risk of Terrorist Attacks";
		break;
	default:
		$homelandSecurityLevelExplanation = "Error!";
		break;
	}

// now output the data
$content = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td align=\"center\">";
$content .= "<a href=\"http://www.dhs.gov/dhspublic/display?theme=29\" target=\"DHS\">";
$content .= "<img src=\"".$config["graphicsPath"].$homelandSecurityLevel.".jpg\" align=\"center\" border=\"0\" alt=\"$homelandSecurityLevelExplanation\"></a>";
$content .= $error;
$content .= "</td></tr></table>";
$content .= "<!-- homeland security block by jon roig (hide@address.com). more info at http://jonroig.com -->";
?>
Return current item: Homeland Security Threat Level Block