NWS Public Alert Messenger PHP Script by Mike Challis
(old title)NOAA Top Weather Advisory Alerter PHP Script
Free PHP Scripts - www.642weather.com/weather/scripts.php
More Info        - www.642weather.com/weather/scripts-noaa-top-weather-alerter.php
Download         - www.642weather.com/weather/scripts/noaa-top-weather-alerter.zip
Live Demo        - www.642weather.com/weather/rss-weather-alerter.php
Contact Mike     - www.642weather.com/weather/contact_us.php
Donate:          https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2319642  

Version: 2.10 - 15-Mar-2010 - see changelog.txt for changes

Support thread at weather-watch forum:
http://www.weather-watch.com/smf/index.php/topic,40805.0.html

You are free to use and modify the code

Partially based on a variation of the following scripts:
RSS Top Warning PHP Script by Ken True http://saratoga-weather.org/scripts.php
PHP NOAA Advisory Text by Tom Chaplin http://www.carterlake.org/weatherphp.php
warnscroll.php by Jim McMurry - jcweather.us
Twitter Script from Martin at http://www.hebwx.co.uk/

Includes most of the features of the NOAA RSS Top Warning 2009 PHP Script
http://www.weather-watch.com/smf/index.php/topic,40256.0.html

This php code provided "as is", and Long Beach Weather (Michael Challis)
disclaims any and all warranties, whether express or implied, including
(without limitation) any implied warranties of merchantability or
fitness for a particular purpose.


################
# What does it do?
# ##############

Ever want to receive severe weather alerts by cell phone, blackberry, Facebook, Twitter, or email?  now you can.

This PHP script is used to check the NOAA RSS Weather Alert feeds on a timed schedule,
then alert you if an alert status changes in the zone you have set.
The alert message is short enough to send to cell phone, blackberry, Facebook, Twitter, or emai.
Supports sending messages by Email and Twitter, each method can be enabled or disabled.
Messages can be customized in the script settings.
A log file is optional.

This is the current order of the top warning selection as of Version 1.13 - 01-Sep-2009

1 evacuation
2 tornado
3 warning
4 watch
5 advisory
6 fire
7 statement
8 emergency
9 hazard
10 alert
11 outage
12 outlook
13 air
14 forecast

There are about 127 possible messages, so if you have multiple alerts, it may not always appear to select your best choice, it cannot be perfect.



################
# What do I need?
# ##############

PHP 5 with CURL support is required
.. Web server hosting account with PHP support and ability to send emails from PHP
.. Ability to schedule a cron job or a scheduler program on your PC that can request a URL every 15 minutes.
.. Your PHP server MUST allow PHP scripts permission to write files.
.. PHP safe_mode is recommended to be off

################
# How to use it:
# ##############

1) Set your settings in the "settings" section in the PHP script.
Be sure to set the NOAA zone and your email address.
Also set the settings to customize the messages for Email and Twitter. 
Each method (email, twitter) can be enabled or disabled. 

2) Upload the rss-weather-alerter.php PHP file to your web server

3) Test from a URL, see if you can see the HTML output:
Example: http://www.yoursite.com/rss-weather-alerter.php

4) It is recommended that you test an email/twitter to make sure the script is working.
   Enable the email or twitter setting. 
   Click the URL, example: http://www.yoursite.com/rss-weather-alerter.php
   Check if you receive your message or not.

5) After testing if you receive your message or not, 
   you need to secure the script because you do not want people clicking the URL and flooding you with emails and twitters!
   There are 3 ways to secure it... make sure you do this step, don't just "set it and forget it":

   Method 1) (recommended) Use the setting $require_post to require post authentication to send messages.
             This method will allow the script to be clicked on, but it will only send the messages on your schedule.

   Method 2) Use the setting $flood_filter_enabled.
             This method will allow the script to be clicked on, but it will only send the messages on your schedule.

   Method 3) Move it to a private non-public web server folder, then the only way you can call it is from a cron job.
         

6) Schedule automatic timed message sending: 
There are a few ways to do this, I use method 1 but not every web host allows it.
Log into your web server control panel, find the "cron" settings.
Wiki page for cron: http://en.wikipedia.org/wiki/Cron
Schedule a server cron job to run this PHP file every every 15 minutes. The following methods correspond to the method you select in step 5 above.

Method 1: (recommended)
Example using cron and CURL with post authentication: (be sure to set 'your_username' and 'your_password' same as in PHP script settings)
00,15,30,45 * * * * /usr/bin/curl -d 'username=your_username&password=your_password' http://www.642weather.com/weather/rss-weather-alerter.php >/dev/null 2>&1 

Method 2:
Example using cron and CURL:
00,15,30,45 * * * * /usr/bin/curl http://www.642weather.com/weather/rss-weather-alerter.php >/dev/null 2>&1

Method 3:
Example using cron and PHP: (change '/path/to/' to your server path)
00,15,30,45 * * * * php /path/to/rss-weather-alerter.php 2>&1 > /dev/null

Method 4: 
Use Windows Task Scheduler and a Scheduled HTTP Request 
to the URL http://www.yourwebsite.com/rss-weather-alerter.php every 15 minutes
Instructions here:
http://www.642weather.com/weather/wxblog/php-scripts/scheduled-http-request-windows-task-scheduler/


Note:
Some users have file permissions problems with the cache files:
Here are some tips:
(Do this only if you are having file permissions errors!)
Create the file in Notepad or similar text editor. The file can be empty. 
adv-alert-email-XXXXX.txt (substitute XXXXX for your NOAA zone code in UPPER CASE)
rss-advisory-XXXXX.txt 
Upload it to your server and CHMOD it to 666
You may continue to have problems if your server has "safe_mode on" or other restrictions on file create, file write functions.
In that case, please consult your web host tech support.

Twitter usage:
See readme.txt inside TweetWX642 folder


###########################################
How to send these messages to Facebook: 
(Requires a Facebook and a Twitter account) 
###########################################
Log into Facebook and go to this app:
http://www.facebook.com/selectivetwitter
Click settings and add your Twitter username, then grant permissions.
End a tweet with #fb when you want it to update your Facebook status - simple.

I made a Facebook page for 642weather, then made a personal profile for myself, I am the admin of the page now.
Pages and profiles are two different things.

-----------------------------------------
Live Example
-----------------------------------------
You can see my script in use here: (it will not email you though, because it only emails me.)
http://www.642weather.com/weather/rss-weather-alerter.php


-----------------------------------------
Donate
-----------------------------------------
A paypal donate button is on my scripts page
www.642weather.com.com/weather/scripts.php
or use this direct link:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=2319642


