Posts Tagged ‘php’

Free Weather Forecast

Tuesday, April 8th, 2008
Posted in Web Development • Tags: , ,

I noticed on the National Weather Service’s website they now allow you to grab the forecast by REST, whereas before they only supported SOAP requests. This makes grabbing the forecast much simpler than it was before.

If you use SOAP there are many methods to grab the data, but if you use REST there are only 2. With REST you can either use DWMLgen which lets you get a little more specific information or NDFDgenByDay which is a little simpler and lets you pick either 12 hour or 24 hour increments (so you can get each day broken in half as in day and night or the full day). The response is sent back as XML for either method so you can format the data how you like.

For the example we are doing, we are going to keep it simple and use a single location, NDFDgenByDay and a 24 hourly period. We will also set it up so that we send the longitude and latitude for Austin, TX, the current date as the start date and request 7 days worth of data.
(more…)

Gallery2 vs Zenphoto vs Plogger

Tuesday, February 5th, 2008
Posted in Web Apps • Tags: , ,

Here I cover some of the features of the best open source PHP image gallery web applications.

Gallery 2

  • Multiple uploads via JavaScript (can add more file upload boxes)
  • Uploads by e-mail, ZIP or multiple image files
  • Configurable to run from multiple sites from one install
  • Reorder album via JavaScript
  • Ratings
  • Plugins available
  • Can’t protect original sizes of images

Zenphoto

  • Multiple uploads via JavaScript (can add more file upload boxes)
  • Uploads by ZIP or multiple image files
  • Spam filter options (Akismet, CAPTCHA, SpamAssassin, …)
  • Reorder album via JavaScript
  • AJAX editing of albums and images
  • Ratings
  • Watermarks
  • Can’t protect original sizes of images (except with a watermark)
  • RSS feed

Plogger

  • No multiple uploads via JavaScript (can’t add more file upload boxes)
  • Uploads by ZIP or single image files
  • Import from folder (you can FTP all images to a folder and have it import the images from that folder)
  • You can protect the original size images
  • RSS feed

All of these have a clean interface and design, search, EXIF data, subfolder/album creation, cruft-free URLs (for SEO), and comments (Gallery requires the comments plugin to be enabled).

It comes down to what your needs are, if you want something that can run on multiple sites Gallery 2 is the app to choose. If you have to protect your original size images you’ll want to use Plogger. I personally think Zenphoto has the most to offer and the best design out of the bunch, but they are all very well done. I went through all the ones on OpenSourceCMS and these were the best. Coppermine is popular but it’s too ugly and the admin is kind of confusing.

PHP Forms Class with 4 hour Video Tutorial

Monday, February 4th, 2008
Posted in Web Development • Tags:

Manuel Lemos has made a 4 hour video tutorial for his popular PHP Forms Generation and Validation class. Thankfully Google Video has a download link so you can watch it when you want. PHP Classes has quite a few other nice classes on their site, however the site is kind of confusing to use. Basically you have to register (which is free), then login and then pick what server to use (they balance their servers by doing this) then you can get whatever files you want. Anyone willing to make that long a tutorial is pretty cool in my book. :) I haven’t used this yet, but it looks interesting.

Current Weather Conditions

Friday, February 1st, 2008
Posted in Web Development • Tags: ,

The National Weather Service provides Current Weather Conditions XML files for many cities in the US.

Here is some code for PHP5 (it uses SimpleXML) on doing this (assuming you’ve already grabbed the XML file from their site and have a way to cache it). It even has some code calculating the sunrise, sunset and civil twilight which PHP5 can do with date_sun_info() and since the XML file gives the date, latitude and longitude, you can calculate it dynamically.

//PHP5
if (file_exists('KADS.xml'))
{
$xmlstr = file_get_contents('KADS.xml');
$xml = simplexml_load_string($xmlstr);
$datetime = strtotime($xml->observation_time_rfc822);
$latitude = (float)$xml->latitude;
$longitude = (float)$xml->longitude;
$sun_info = date_sun_info(date('Y-n-j', $datetime), $latitude, $longitude);//calculate sunrise,sunset,...
echo '<ul id="current_conditions">';
echo '<li>' . date('l, F j, Y', $datetime) . '</li>';
echo '<li class="weather_loc">' . $xml->location . '</li>';
echo '<!--' . $xml->observation_time . '-->';
echo '<li><img src="' . $xml->icon_url_base . $xml->icon_url_name . '" alt="' . $xml->weather . '" /></li>';
echo '<li class="weather_temp"><strong>' . $xml->temp_f . '&deg;' . '</strong></li>';
echo '<li class="weather_sum"><strong>' . $xml->weather . '</strong></li>';
echo '<li>Wind: <strong>' . $xml->wind_dir . ' ' . round($xml->wind_mph) . ' mph</strong></li>';
echo '<li>Humidity: <strong>' . $xml->relative_humidity . '%</strong></li>';
if ($xml->heat_index_f != 'NA')
echo '<li>Heat Index: <strong>' . $xml->heat_index_f . '</strong></li>';
if ($xml->windchill_f != 'NA')
echo '<li>Windchill: <strong>' . $xml->windchill_f . '</strong></li>';
echo '<li>Barometer: <strong>' . $xml->pressure_in . '&quot;</strong></li>';
echo '<li>Visibility: <strong>' . $xml->visibility_mi . ' mi</strong></li>';
echo '<li>Dewpoint: <strong>' . $xml->dewpoint_f . '&deg;</strong></li>';
echo '<li class="weather_credit">weather by <a href="' . $xml->credit_URL . '" title="' . $xml->credit . '">NOAA</a></li>';
echo '</ul>';
echo '<ul id="sunrise_sunset">';
echo '<li>Sunrise: <strong>' . date('g:i a', $sun_info['sunrise']) . '</strong> <span class="civil_twilight">Civil Twilight: <strong>' . date('g:i a', $sun_info['civil_twilight_begin']) . '</strong></span></li>';
echo '<li>Sunrise: <strong>' . date('g:i a', $sun_info['sunset']) . '</strong> <span class="civil_twilight">Civil Twilight: <strong>' . date('g:i a', $sun_info['civil_twilight_end']) . '</strong></span></li>';
echo '</ul>';
}

You will probably want to cache that output once you have it formatted how you like.

CSS Class Based on Date

Wednesday, August 1st, 2007
Posted in Web Development • Tags: , ,

I recently saw a tutorial on SimplePie’s site about using relative dates and I modified the function to output a CSS class rather than text. That way you can make newer stories bold, brighter, or bigger and older stories dimmed out or smaller. Use your imagination with CSS. :)

Here is the function

//CREATE CSS BASED ON DATE
function create_age_css_class($date_sent)
{
/**
$date_sent should be in the following format: YYYYMMDDHHMMSS
Based on doRelativeDate() By Garrett Murray, http://graveyard.maniacalrage.net/etc/relative/
**/
$in_seconds = strtotime(substr($date_sent,0,8).' '.
substr($date_sent,8,2).':'.
substr($date_sent,10,2).':'.
substr($date_sent,12,2));
$diff = time()-$in_seconds;
if ($diff < 86400)
$css_class = 'age_today';
else if ($diff < 604800)
$css_class = 'age_days';
else if ($diff < 1209600)
$css_class = 'age_week';
else if ($diff < 2630880)
$css_class = 'age_weeks';
else
$css_class = 'age_month';
return $css_class;
}

Here is how I call it

$data .= '<li><a href="'. $item->get_permalink();
//SET CLASS BASED ON DATE/AGE
$data .= ' class="' . create_age_css_class($item->get_date('YmdHis')) . '"';
$data .= '>';

You don’t have to use SimplePie for this function, but its what inspired me to modify it.