Language: php (GeSHi-highlighted)
<?php
/*
* Copyright (C) 2007 CrYpTiC MauleR <http://www.expertsrt.net/images/cm_email.gif>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License 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.
*/
//header('Content-Type: text/html');
$update_interval = 1800; /* More Often The Better (0 Will Disable Caching) */
$cache = 'amber.txt'; /* Where Cached Copy Is Stored For Speedy Display */
if ((file_exists($cache)) && (update_interval > (time() - filemtime($cache))))
{
echo file_get_contents($cache);
}
else
{
if (false !== ($data = file_get_contents('http://www.codeamber.org/js/alerts.js')))
{
$regex = '|/(\w+)/>(?:<b>)?([\w ]+)|i';
if ((preg_match_all($regex, $data, $match)) && (0 < count($match[1])))
{
ob_start();
$count = count($match[1]);
echo 'Current Alert';
if (1 !== $count)
{
echo 's';
}
echo "<br />\n";
for ($i = 0; $i < $count; $i++)
{
echo "<a href='http://www.codeamber.org/" . $match[1][$i] . "/'>"
. $match[2][$i] . "</a><br />\n";
}
echo "Powered By :<br />\n"
. "<a href='http://www.codeamber.org/'>CodeAmber.org</a>\n";
file_put_contents($cache, ob_get_contents());
ob_end_flush();
}
else
{
echo 'No Alerts';
}
}
else
{
echo 'Error Getting Alerts';
}
}
?>
This script I made for my now abandoned journal community system. It will grab the contents from the JS file and extract relevant details about the alert and create links back to the page. This way you can display the alerts to people who do not have JS enabled like NoScript users for instance. If I have time I may add the feature to grab any photo from the child's alert page to display along with their alert. Share code and modify as you will. PLEASE if you do so make sure to properly sanitize the external data retrieved as I did in the for() loop, will prevent attacks on your site and also prevent the likelihood that the data may break your layout (its happened before, one reason I added the cleaning).