The final functioning product:
[php]
<?php
/*
HNE RSS Aggragator - October 7, 2013
Haslage Net Enterprises
http://www.haslage.net/
Credits: Anthony Haslage & JimL (PHPHelp.Com)
Features (Requires PHP5 & CURL):
- Saves the file locally to get around blocked remote file inclusions.
- Converts time from milliseconds to seconds.
- Offers variables to offset timezones.
======================================================================
LICENSE
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
To read the license please visit http://www.gnu.org/copyleft/gpl.html
*/
// File to be downloaded.
$ch = curl_init(“http://www.website.com/data.xml”);
// Location to save data (Create the file & CHMOD 777).
$fp = fopen(“data-output.html”, “w”);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
// Location to load data (Should be the same as where the data was previously saved).
$xml = file_get_contents(‘data-output.html’);
$results = new SimpleXMLElement($xml);
// HTML before all items.
print “”;
foreach ($results->items->item as $item)
{
$time = (float) $item->time / 1000; // Convert from milliseconds to seconds.
$end = ((float) $item->time + (float) $item->duration) / 1000; // Add begin time and duration to produce end time, then convert from milliseconds to seconds.
$tz = (float) $item->utc_offset / 1000; // Convert from milliseconds to seconds.
$timetz = $time + $tz; // Add start time and timezone to correct offset.
$endtz = $end + $tz; // Add end time and timezone to correct offset.
$dt = new DateTime("@$timetz"); // Convert UNIX timestamp to PHP DateTime
$newtime = $dt->format('M. j, Y @ g:i A'); // Display date and time begin
$ee = new DateTime("@$endtz"); // Convert UNIX timestamp to PHP DateTime
$newend = $ee->format('g:i A'); // Display time end
$venue = $item->venue->name; // List venue since code does not like printing variables more than one level into XML tree.
// For output testing purposes.
// print “Time Begin: $time
Time End: $end
Timezone: $tz
”;
// print “Time (ADJ): $timetz
Date Begin: $newtime
Date End: $newend
”;
// print “Name: $item->name
Description: $item->description
URL: $item->event_url
Location: $item->venue->name
”;
print "<li><a href=\"$item->event_url\" target=\"newwindow\" title=\"$item->description\">$item->name - $newtime to $newend ($venue)</a></li>\n";
// print “
”; var_dump($item); // For variable testing purposes.
}
// HTML after all items.
print “”;
?>
[/php]