Login  |  Register
X
Username
Password
Forgot your password? 

NOTE 2009: Another old thing that is undoubtedly useless these days, thou it was fun at the time.



I was browsing over at the MovableType Forums and I came across this thread where a guy wanted to link his stylesheet to the output of the Terrorism Alert Plugin. The idea was that his site would have a different skin for each alert level, updated by the plugin on every rebuild.

He was helped to do this by the usual astonishingly bright and creative crew over there.

But, it got me to thinking, what if some poor soul was dependent upon MY stylesheets to know how terrorized to be??? I mean, I only post irregularly, and what if the terror alert went up to red in between postings, and my reader didn't realize he was supposed to be scared to death!

Or what if the alert level went down between rebuilds, and the poor reader didn't know he could relax about teror attacks and start being scared witless by SARS and the economy!

Nope. That would never do. So, the only answer was to cook up a PHP version of the terror alert script, so that my site will be up to date ... even if something happens to me. Remember, "just because you're paranoid doesn't mean people aren't out to get you!"

That's a demo in the upper right corner of this entry, and there's another bit of terror business using this script in the left sidebar.

Okay, well, I realized that I had cooked up a slow, heavy-handed way to "scrape" the DHS site and extract the alert level, so we wouldn't want to invoke it with every hit, nor would we wish to overtax the government server (so to speak). So I threw in a little scratch file that would hold the current information, and allow you to set the time between updates - in the case below, it's four hours, but it's easy to change to a higher or lower frequency.

Just put a blank file named "alert.dat" in the same directory as the script, and chmod it to 777. That way, most of your hits are taking the info from that file and it's very fast. You only scrape the government once every four hours.

Other than that, the script below is very straightforward - the output statements here just echo the alert level and its definition, change the background color to the alert color, and display the graphic image, but you could just as easily make them stylesheet declarations, file pointers, or anything else. I've included the graphics and colors just so you can comment out what you don't want, and use the code for templates for what you do want.

There is a little demo here.

So, if you're into this sort of thing, just copy the PHP below, paste it inline as I did at the beginning of the entry, or in a separate window as above, or make an include, and in any case proceed to scare yourself silly

<?

$myCheckInt = (60*60*4); //time between checking DHS = 4 hours

$filename = "alert.dat"; //put this empty file in directory, chmod 777

$myURL = "http://www.dhs.gov/dhspublic/display?theme=29&content=320";

$file_last_modified = filemtime($filename);
$currentTime = time();

$f_pointer = fopen($filename, "r");
$f_read = fread($f_pointer, filesize($filename));
fclose($f_pointer);

if (($currentTime - $file_last_modified) > $myCheckInt || $f_read =="")
{
     if (!($siteContent = file($myURL)))
          die ("failed to access info!");
     foreach($siteContent as $line)
     {
          if (preg_match("/img name="dhsadvisory"/", $line))
               $theLine = $line;
     }
     $f_pointer = fopen($filename, "w");
     fwrite($f_pointer, $theLine);
     fclose($f_pointer);

} else {

$theLine = $f_read;}

if (preg_match("/alt="Red Advisory"/", $theLine))
{
     echo "Red Advisory: Severe risk of terrorist attacks.<br><br>";
     echo "<img height="40" width="125" border="0" src="dhs-advisory-severe.gif">";
     echo "<body bgcolor="#CC0000">";
}

if (preg_match("/alt="Orange Advisory"/", $theLine))
{
     echo "Orange Advisory: High risk of terrorist attacks.<br><br>";
     echo "<img height="40" width="125" border="0" src="dhs-advisory-high.gif">";
     echo "<body bgcolor="#FF9900">";
}

if (preg_match("/alt="Yellow Advisory"/", $theLine))
{
     echo "Yellow Advisory: Elevated condition; Significant risk of terrorist attacks.<br><br>";
     echo "<img height="40" width="125" border="0" src="dhs-advisory-elevated.gif">";
     echo "<body bgcolor="#FFFF00">";
}

if (preg_match("/alt="Blue Advisory"/", $theLine))
{
     echo "Blue Advisory: Guarded condition; General risk of terrorist attack.<br><br>";
     echo "<img height="40" width="125" border="0" src="dhs-advisory-guarded.gif">";
     echo "<body bgcolor="#0033CC">";
}

if (preg_match("/alt="Green Advisory"/", $theLine))
{
     echo "Blue Advisory: Low risk of terrorist attacks.<br><br>";
     echo "<img height="40" width="125" border="0" src="dhs-advisory-low.gif">";
     echo "<body bgcolor="#009900">";
}

?>

Comments

9 Responses to PHP Script For Terror Alert Level
  1. Oscar Says:

    I’ll take comments anywhere I can get ‘em Rori, and I’m glad you enjoyed my little excursion into the world of the “wars on things.”

  2. Rori Says:

    Yeah, I am breaking my own rule and commenting on an old entry, but this had me ROTFL!

  3. t35t5 Says:

    oijojlo

  4. Oscar Says:

    Cool! What a beautiful blog you have!

    The whole reason I throw together these little scripts is the pleasure in seeing what people like you can do with them.

  5. @feckless Says:

    had to come by & say thanks for this - i had quite a bit of fun with it. installed the real thing first, then one thing led to another & now people can come & set their own terror level (& my colors are much prettier smile

    so, thanks again.

  6. Oscar Says:

    Hi, I answered your question over on the forums, but in case you’re checking here first, I think you probably didn’t add the file “alert.dat” to your directory. Just upload a blank text file and set the permissions to 777. Then try the script again. If that doesn’t work, just let me know

  7. singlerep Says:

    I can’t get this to work. I keep getting “Warning: stat failed for alert.dat (errno=2 - No such file or directory) in ~home/index.php on line 17” Sorry to be dumb but can you help me?

  8. Page 1 of 1 pages


Trackbacks

  1. : feckless(net): PHP Script For Terror Alert Level fun with terror alerts. & why not?
    Tracked at 2003 04 19 05:04:57




Tell us your thoughts...
And (as you probably know) if you want a pic to show with your comment, go get a gravatar!

Smilies

Please be kind enough to submit the word you see below:




Next entry: World Population Plugin for MT

Previous entry: Reedology - New Version

PHP Script For Terror Alert Level

Posted by Oscar on Thu, 4/3/03 at 02:58 AM
Filed under: • MT & Web Design
Comments: 9 Comments/Trackbacks






OFH Solo Banjo/Guitar mp3's
pretty good if you like pickin'



Loading images
loading
Tranjo Demonstration Jerry Reeds Sassy Last Old Shovel - ROMP 2007 The Man In The Middle - ROMP 2007 Sittin On Top Of The World - ROMP 2007 Dixie Breakdown - ROMP 2007 Home Sweet Home Sound Check - ROMP 2007 Do I Ever Cross Your Mind - ROMP 2007 Drive-In Helium Brothers Montage 2009 Ridin On That Midnight Train - ROMP 2007 Lumberyard Blues Hey Hey Hey - ROMP 2007 Close By - ROMP 2007 Uncle Johns Band I Aint Broke - ROMP 2007 Midnight Moonlight Wishful Thinking