<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JiveBay &#187; php</title>
	<atom:link href="http://jivebay.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://jivebay.com</link>
	<description>Web Development, Code Snippets, Technology, Reviews and Random Stuff Blog</description>
	<lastBuildDate>Thu, 29 Jul 2010 13:39:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Calculating the Moon Phase Part 2</title>
		<link>http://jivebay.com/2010/01/04/calculating-the-moon-phase-part-2/</link>
		<comments>http://jivebay.com/2010/01/04/calculating-the-moon-phase-part-2/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 21:54:52 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jivebay.com/?p=627</guid>
		<description><![CDATA[Here is some PHP code to calculating the Lunar Phase of the Moon. It also tells the ecliptic latitude and longitude in degrees, the moon's distance in Earth radii, the moon's age in days from new moon and zodiac.]]></description>
			<content:encoded><![CDATA[<p>In an <a href="http://jivebay.com/2008/09/07/calculating-the-moon-phase/">older post about Calculating the Moon Phase</a>, I converted the some code I found to PHP. However the <a href="http://home.att.net/%7Esrschmitt/script_moon_phase.html">Lunar Phase Calculator</a> has some more information (ecliptic latitude and longitude in degrees, the moon&#8217;s distance in Earth radii, etc.), the other one doesn&#8217;t, so I went ahead and converted it from JavaScript to PHP.<br />
<span id="more-627"></span><br />
<code><br />
&lt;?php<br />
/*<br />
Based on the JavaScript<br />
Lunar Phase Calculator<br />
by Stephen R. Schmitt</p>
<p>http://home.att.net/~srschmitt/script_moon_phase.html</p>
<p>which was adapted from a BASIC program from the Astronomical Computing column of Sky &amp; Telescope, April 1994<br />
*/<br />
function isdayofmonth($month, $day, $year)<br />
{<br />
    $dim = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);<br />
    if ($month != 2)<br />
    {<br />
        if (1 &lt;= $day &amp;&amp; $day &lt;= $dim[$month - 1])<br />
            return true;<br />
        else<br />
            return false;<br />
    }<br />
    $feb = $dim[1];<br />
    if (isleapyear($year))<br />
    {<br />
        $feb++;// is leap year<br />
    }<br />
    if (1 &lt;= $day &amp;&amp; $day &lt;= $feb)<br />
    {<br />
        return true;<br />
    }<br />
    return false;<br />
}<br />
function isleapyear($year)<br />
{<br />
    $a = floor($year - 4 * floor($year / 4));<br />
    $b = floor($year - 100 * floor($year / 100));<br />
    $c = floor($year - 400 * floor($year / 400));<br />
    // possible leap year<br />
    if ($a == 0)<br />
    {<br />
        if ($b == 0 &amp;&amp; $c != 0)<br />
            return false;// not leap year<br />
        else<br />
            return true;// is leap year<br />
    }<br />
    return false;<br />
}<br />
// compute moon position and phase<br />
function moon_posit($month = null, $day = null, $year = null)<br />
{<br />
    $moon = array();<br />
    if(!isdayofmonth($month, $day, $year))<br />
    {<br />
        $moon[&#039;errors&#039;] = &#039;Invalid date&#039;;<br />
    }<br />
    else<br />
    {<br />
        $moon[&#039;errors&#039;] = null;<br />
        $age = 0.0;// Moon&#039;s age in days from New Moon<br />
        $distance = 0.0;// Moon&#039;s distance in Earth radii<br />
        $latitude = 0.0;// Moon&#039;s ecliptic latitude in degrees<br />
        $longitude = 0.0;// Moon&#039;s ecliptic longitude in degrees<br />
        $phase = &#039;&#039;;<br />
        $zodiac = &#039;&#039;;<br />
        $YY = 0;<br />
        $MM = 0;<br />
        $K1 = 0;<br />
        $K2 = 0;<br />
        $K3 = 0;<br />
        $JD = 0;<br />
        $IP = 0.0;<br />
        $DP = 0.0;<br />
        $NP = 0.0;<br />
        $RP = 0.0;<br />
        // calculate the Julian date at 12h UT<br />
        $YY = $year - floor((12 - $month) / 10);<br />
        $MM = $month + 9;<br />
        if ($MM &gt;= 12)<br />
        {<br />
            $MM = $MM - 12;<br />
        }<br />
        $K1 = floor(365.25 * ($YY + 4712));<br />
        $K2 = floor(30.6 * $MM + 0.5);<br />
        $K3 = floor(floor(($YY / 100) + 49) * 0.75) - 38;<br />
        $JD = $K1 + $K2 + $day + 59;// for dates in Julian calendar<br />
        if ($JD &gt; 2299160)<br />
        {<br />
            $JD = $JD - $K3;// for Gregorian calendar<br />
        }<br />
        // calculate moon&#039;s age in days<br />
        $IP = normalize(($JD - 2451550.1) / 29.530588853);<br />
        $age = $IP * 29.53;<br />
        if ($age &lt;  1.84566)<br />
            $phase = &#039;NEW&#039;;<br />
        else if ($age &lt;  5.53699)<br />
            $phase = &#039;Evening crescent&#039;;<br />
        else if ($age &lt;  9.22831)<br />
            $phase = &#039;First quarter&#039;;<br />
        else if ($age &lt; 12.91963)<br />
            $phase = &#039;Waxing gibbous&#039;;<br />
        else if ($age &lt; 16.61096)<br />
            $phase = &#039;FULL&#039;;<br />
        else if ($age &lt; 20.30228)<br />
            $phase = &#039;Waning gibbous&#039;;<br />
        else if ($age &lt; 23.99361)<br />
            $phase = &#039;Last quarter&#039;;<br />
        else if ($age &lt; 27.68493)<br />
            $phase = &#039;Morning crescent&#039;;<br />
        else<br />
            $phase = &#039;NEW&#039;;<br />
        $IP = $IP * 2 * pi();// Convert phase to radians<br />
        // calculate moon&#039;s distance<br />
        $DP = 2 * pi() * normalize(($JD - 2451562.2) / 27.55454988);<br />
        $distance = 60.4 - 3.3 * cos($DP) - 0.6 * cos(2 * $IP - $DP) - 0.5 * cos(2 * $IP);<br />
        // calculate moon&#039;s ecliptic latitude<br />
        $NP = 2 * pi() * normalize(($JD - 2451565.2) / 27.212220817);<br />
        $latitude = 5.1 * sin($NP);<br />
        // calculate moon&#039;s ecliptic longitude<br />
        $RP = normalize(($JD - 2451555.8) / 27.321582241);<br />
        $longitude = 360 * $RP + 6.3 * sin($DP) + 1.3 * sin(2 * $IP - $DP) + 0.7 * sin(2 * $IP);<br />
        if ($longitude &lt;  33.18)<br />
            $zodiac = &#039;Pisces&#039;;<br />
        else if ($longitude &lt;  51.16)<br />
            $zodiac = &#039;Aries&#039;;<br />
        else if ($longitude &lt;  93.44)<br />
            $zodiac = &#039;Taurus&#039;;<br />
        else if ($longitude &lt; 119.48)<br />
            $zodiac = &#039;Gemini&#039;;<br />
        else if ($longitude &lt; 135.30)<br />
            $zodiac = &#039;Cancer&#039;;<br />
        else if ($longitude &lt; 173.34)<br />
            $zodiac = &#039;Leo&#039;;<br />
        else if ($longitude &lt; 224.17)<br />
            $zodiac = &#039;Virgo&#039;;<br />
        else if ($longitude &lt; 242.57)<br />
            $zodiac = &#039;Libra&#039;;<br />
        else if ($longitude &lt; 271.26)<br />
            $zodiac = &#039;Scorpio&#039;;<br />
        else if ($longitude &lt; 302.49)<br />
            $zodiac = &#039;Sagittarius&#039;;<br />
        else if ($longitude &lt; 311.72)<br />
            $zodiac = &#039;Capricorn&#039;;<br />
        else if ($longitude &lt; 348.58)<br />
            $zodiac = &#039;Aquarius&#039;;<br />
        else<br />
            $zodiac = &#039;Pisces&#039;;<br />
        // so longitude is not greater than 360!<br />
        if ($longitude &gt; 360)<br />
            $longitude = $longitude - 360;<br />
        $moon[&#039;age&#039;] = round($age, 2);<br />
        $moon[&#039;distance&#039;] = round($distance, 2);<br />
        $moon[&#039;latitude&#039;] = round($latitude, 2);<br />
        $moon[&#039;longitude&#039;] = round($longitude, 2);<br />
        $moon[&#039;phase&#039;] = $phase;<br />
        $moon[&#039;zodiac&#039;] = $zodiac;<br />
    }<br />
    return $moon;<br />
}<br />
// normalize values to range 0...1<br />
function normalize($v)<br />
{<br />
    $v = $v - floor($v);<br />
    if ($v &lt; 0)<br />
    {<br />
        $v++;<br />
    }<br />
    return $v;<br />
}<br />
?&gt;<br />
</code></p>
<p>And to use it, you can do something like this<br />
<code><br />
&lt;?php<br />
include(&#039;moon2.php&#039;);<br />
$date = time();<br />
$year = date(&#039;Y&#039;, $date);<br />
$month = date(&#039;n&#039;, $date);<br />
$day = date(&#039;j&#039;, $date);<br />
$moon = moon_posit($month, $day, $year);<br />
//debug results<br />
echo &#039;&lt;pre&gt;&#039;;<br />
print_r($moon);<br />
echo &#039;&lt;/pre&gt;&#039;;<br />
if ($moon[&#039;errors&#039;] === null)<br />
{<br />
    //output and format what you want<br />
}<br />
else<br />
{<br />
    //handle error how you want, perhaps give error message and then show today&#039;&#039;s moon info<br />
}<br />
?&gt;<br />
</code></p>
<p>I haven&#8217;t figured out how to get the percentage of illumination of the moon though.</p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=627&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2010/01/04/calculating-the-moon-phase-part-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>RSS Cron Job</title>
		<link>http://jivebay.com/2009/12/14/rss-cron-job/</link>
		<comments>http://jivebay.com/2009/12/14/rss-cron-job/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:45:46 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jivebay.com/?p=233</guid>
		<description><![CDATA[Tired of your web host with limited Cron Jobs, slow caching or think the Poor Man's Cron Job sucks? Try creating an RSS feed and then let Google Reader hit your page and force a RSS Cron Job to take place.]]></description>
			<content:encoded><![CDATA[<p> If you are on shared web host, you might not have the ability to run lots of cron jobs or be limited to a certain number per hour or day. You might know about the &#8220;Poor Man&#8217;s Cron Job&#8221;, which is basically not to run a task (usually caching some data or fetching a feed, api, etc.) in the background until someone visits a page. Which isn&#8217;t ideal, because often the page will be slow or sometimes it won&#8217;t be up to date until the second visit (if you run that task after outputting the cached data).</p>
<p>Well one way to get around this is to setup an RSS feed for the data you are caching or outputting and access it with a query string such as &#8220;?rss=2.0&#8243; or <strong>http://example.com/index.php?rss=2.0</strong>. Then you can check to see if the RSS variable was passed and output a RSS feed with just enough data for a feed, no need to put sensitive data in there or anything. I would suggest putting in a <strong>ttl</strong> node in the RSS feed and set it to something the aggregators like <a href="http://www.google.com/reader">Google Reader</a>, should obey (that way they hit your page more or less frequently, depending on your needs). The <strong>item</strong> portion of an RSS feed only needs a title or a description, although its probably a good idea to put some kind of <strong>guid</strong> in there (check the <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0 spec</a> for more info on creating RSS feeds).</p>
<p>Anyway here is some sample code. It isn&#8217;t complete but gives you an idea what I mean.<br />
<code><br />
if ($_GET[&#039;rss&#039;] == 2.0)<br />
{<br />
	//create RSS 2.0 feed<br />
	header(&#039;Content-Type: text/xml&#039;);<br />
	$output = &#039;&lt;&#039; . &#039;?xml version=&quot;1.0&quot;?&#039; . &#039;&gt;&#039; . &quot;\n&quot;;<br />
	$output .= &#039;&lt;rss version=&quot;2.0&quot;&gt;&#039; . &quot;\n&quot;;<br />
	$output .= &#039;&lt;channel&gt;&#039; . &quot;\n&quot;;<br />
	//...<br />
	//process your data and output it into RSS 2.0 format<br />
	//...<br />
	$output .= &#039;&lt;/channel&gt;&#039; . &quot;\n&quot;;<br />
	$output .= &#039;&lt;/rss&gt;&#039;;<br />
}<br />
else<br />
{<br />
	//process your data as normal<br />
}<br />
</code></p>
<p>Then to make sure the page is hit often, place your RSS feed into <a href="http://www.google.com/reader">Google Reader</a> or <a href="http://www.bloglines.com/">Bloglines</a> or some other RSS aggregator. Then your site will be visited often and forced to update. No one else really needs to know about your RSS feeds, unless you want them to be public as well.</p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=233&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2009/12/14/rss-cron-job/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>phpBB 3.x RSS Hack</title>
		<link>http://jivebay.com/2009/02/02/phpbb-3x-rss-hack/</link>
		<comments>http://jivebay.com/2009/02/02/phpbb-3x-rss-hack/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 20:31:25 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpbb]]></category>

		<guid isPermaLink="false">http://jivebay.com/?p=452</guid>
		<description><![CDATA[A code snippet or hack to get phpBB 3 to have rss feeds on your forums. It's very simple to setup and you can modify it how you like for your message board.]]></description>
			<content:encoded><![CDATA[<p>Where I work we use <a href="http://www.phpbb.com/">phpBB</a> and I was surprised to see version 3 didn&#8217;t have built in RSS support. I found a mod, but it contained several files and required modifying several more files. I put together a hack that will pull the latest posts that are approved and non-reported; However, it will keep them unique to a topic. So if the last 5 posts are for a topic called &#8220;That is awesome&#8221;, it will only show a link to the last post on that topic and will look for the other latest posts from other topics.</p>
<p>It&#8217;s configurable with a item_limit (number of posts to pull) and word_limit (how long the description is). However the description is just the title for the last post, so it will most often be &#8220;RE: original post title&#8221; unless the user changes it when posting. I could of done another query in a loop to the table <strong>phpbb_posts</strong> and pulled out the corresponding <strong>post_text</strong>, but didn&#8217;t want to have the overhead. Although you could easily modify that in and cache the file for say 5 or 15 minutes. Think of this as a head start to get the feeds from your forum for whatever you plan to do with them. <img src='http://jivebay.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-452"></span></p>
<p>Create a php file at the root of your forums with this code.<br />
<code><br />
&lt;?php<br />
	//OPTIONS<br />
	$item_limit = 20;//total rss items to pull<br />
	$word_limit = 25;//word limit<br />
	//YOU SHOULDNT HAVE TO EDIT ANYTHING BELOW<br />
	require(&#039;config.php&#039;);<br />
	$db_connect = mysql_connect($dbhost, $dbuser, $dbpasswd) or die(&#039;Unable to connect to database.&#039;);<br />
	$db_select = mysql_select_db($dbname, $db_connect) or die(&#039;Could not set the database.&#039;);<br />
	header(&quot;content-type: text/xml&quot;);<br />
	//GET THE SITES DATA<br />
	$db_record_site_data = mysql_query(&#039;SELECT config_name, config_value FROM phpbb_config WHERE config_name = \&#039;script_path\&#039; OR config_name = \&#039;server_name\&#039; OR config_name = \&#039;sitename\&#039; OR config_name = \&#039;site_desc\&#039; ORDER BY config_name&#039;);<br />
	$counter = 0;<br />
	//will get the items in this order: script_path, server_name, site_desc, sitename<br />
	while ($row = mysql_fetch_array($db_record_site_data))<br />
	{<br />
		if ($counter == 0)<br />
			$script_path = $row[&#039;config_value&#039;];<br />
		else if ($counter == 1)<br />
			$site_url = &#039;http://&#039;.$row[&#039;config_value&#039;];<br />
		else if ($counter == 2)<br />
			$site_description = $row[&#039;config_value&#039;];<br />
		else if ($counter == 3)<br />
			$site_title = $row[&#039;config_value&#039;];<br />
		$counter++;<br />
	}<br />
	//GET THE RECENT TOPICS, show only approved and non-reported topics<br />
	$db_record_topic_data = mysql_query(&#039;SELECT forum_id, topic_id, topic_last_post_time, topic_title, topic_last_post_subject, topic_last_poster_name, topic_first_post_id, topic_last_post_id FROM phpbb_topics WHERE topic_approved=1 AND topic_reported=0 ORDER BY topic_last_post_time DESC LIMIT &#039; . $item_limit);<br />
	echo &#039;&lt;&#039; . &#039;?xml version=&quot;1.0&quot;?&#039; . &#039;&gt;&#039; . &quot;\n&quot;;<br />
	echo &#039;&lt;rss version=&quot;2.0&quot;&gt;&#039; . &quot;\n&quot;;<br />
	echo &#039;&lt;channel&gt;&#039; . &quot;\n&quot;;<br />
	echo &#039;&lt;title&gt;&#039; . $site_title . &#039;&lt;/title&gt;&#039; . &quot;\n&quot;;<br />
	echo &#039;&lt;link&gt;&#039; . $site_url . $script_path . &#039;&lt;/link&gt;&#039; . &quot;\n&quot;;<br />
	echo &#039;&lt;description&gt;&#039; . $site_description . &#039;&lt;/description&gt;&#039; . &quot;\n&quot;;<br />
	while ($row = mysql_fetch_array($db_record_topic_data))<br />
	{<br />
		echo &#039;&lt;item&gt;&#039; . &quot;\n&quot;;<br />
		echo &#039;&lt;title&gt;&#039; . htmlspecialchars(trim($row[&#039;topic_title&#039;]), ENT_QUOTES) . &#039;&lt;/title&gt;&#039; . &quot;\n&quot;;<br />
		echo &#039;&lt;description&gt;&#039;;<br />
		//filter description<br />
		$post_text = htmlspecialchars(trim($row[&#039;topic_last_post_subject&#039;]), ENT_QUOTES);<br />
		//word limit<br />
		$post_text = str_replace(&#039;  &#039;, &#039; &#039;, $post_text);//get rid of multispaces<br />
		$post_word_array = explode(&#039; &#039;, $post_text);<br />
		$total_words = count($post_word_array);<br />
		$total_words = min($word_limit, $total_words);<br />
		for ($x = 0; $x &lt; $total_words; $x++)<br />
		{<br />
			echo $post_word_array[$x] . &#039; &#039;;<br />
		}<br />
		//ellipsis<br />
		if ($total_words &gt; $word_limit)<br />
			echo &#039;...&#039;;<br />
		echo &#039;&lt;/description&gt;&#039; . &quot;\n&quot;;<br />
		//echo &#039;&lt;description&gt;&#039; . substr(, 0, 128) . &#039;&lt;/description&gt;&#039;;//character limit<br />
		echo &#039;&lt;link&gt;&#039; . $site_url . $script_path . &#039;viewtopic.php?f=&#039; . $row[&#039;forum_id&#039;] . &#039;&amp;amp;t=&#039; . $row[&#039;topic_id&#039;] . &#039;&amp;amp;p=&#039; . $row[&#039;topic_first_post_id&#039;] . &#039;#&#039; . $row[&#039;topic_last_post_id&#039;] . &#039;&lt;/link&gt;&#039; . &quot;\n&quot;;<br />
		echo &#039;&lt;pubdate&gt;&#039; . date(&#039;r&#039;, $row[&#039;topic_last_post_time&#039;]) . &#039;&lt;/pubdate&gt;&#039; . &quot;\n&quot;;//RFC822<br />
		echo &#039;&lt;author&gt;&#039; . htmlspecialchars(trim($row[&#039;topic_last_poster_name&#039;]), ENT_QUOTES) . &#039;&lt;/author&gt;&#039;;<br />
		echo &#039;&lt;/item&gt;&#039; . &quot;\n&quot;;<br />
	}<br />
	echo &#039;&lt;/channel&gt;&#039; . &quot;\n&quot;;<br />
	echo &#039;&lt;/rss&gt;&#039; . &quot;\n&quot;;<br />
?&gt;<br />
</code></p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=452&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2009/02/02/phpbb-3x-rss-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Calculating the Moon Phase</title>
		<link>http://jivebay.com/2008/09/07/calculating-the-moon-phase/</link>
		<comments>http://jivebay.com/2008/09/07/calculating-the-moon-phase/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 00:09:02 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jivebay.com/?p=260</guid>
		<description><![CDATA[I was searching for a algorithm to get the phase of the moon, and unfortunately the Moon Phase Class on PHP Classes is inaccurate. With some searching I was able to find 2 sites that have code to pull it off (
Lunar Phase Calculator and Moon Phase Calculation.
I modified the latter (Moon Phase Calculation and [...]]]></description>
			<content:encoded><![CDATA[<p>I was searching for a algorithm to get the phase of the moon, and unfortunately the <a href="http://www.phpclasses.org/browse/package/1201.html">Moon Phase Class</a> on PHP Classes is inaccurate. With some searching I was able to find 2 sites that have code to pull it off (<br />
<a href="http://home.att.net/~srschmitt/script_moon_phase.html">Lunar Phase Calculator</a> and <a href="http://www.voidware.com/moon_phase.htm">Moon Phase Calculation</a>.</p>
<p>I modified the latter (<a href="http://www.voidware.com/moon_phase.htm">Moon Phase Calculation</a> and used the first function listed on that page).<br />
<code><br />
&lt;?php<br />
function moon_phase($year, $month, $day)<br />
{<br />
	/*<br />
	modified from http://www.voidware.com/moon_phase.htm<br />
	*/<br />
	$c = $e = $jd = $b = 0;<br />
	if ($month &lt; 3)<br />
	{<br />
		$year--;<br />
		$month += 12;<br />
	}<br />
	++$month;<br />
	$c = 365.25 * $year;<br />
	$e = 30.6 * $month;<br />
	$jd = $c + $e + $day - 694039.09;	//jd is total days elapsed<br />
	$jd /= 29.5305882;					//divide by the moon cycle<br />
	$b = (int) $jd;						//int(jd) -&gt; b, take integer part of jd<br />
	$jd -= $b;							//subtract integer part to leave fractional part of original jd<br />
	$b = round($jd * 8);				//scale fraction from 0-8 and round<br />
	if ($b &gt;= 8 )<br />
	{<br />
		$b = 0;//0 and 8 are the same so turn 8 into 0<br />
	}<br />
	switch ($b)<br />
	{<br />
		case 0:<br />
			return &#039;New Moon&#039;;<br />
			break;<br />
		case 1:<br />
			return &#039;Waxing Crescent Moon&#039;;<br />
			break;<br />
		case 2:<br />
			return &#039;Quarter Moon&#039;;<br />
			break;<br />
		case 3:<br />
			return &#039;Waxing Gibbous Moon&#039;;<br />
			break;<br />
		case 4:<br />
			return &#039;Full Moon&#039;;<br />
			break;<br />
		case 5:<br />
			return &#039;Waning Gibbous Moon&#039;;<br />
			break;<br />
		case 6:<br />
			return &#039;Last Quarter Moon&#039;;<br />
			break;<br />
		case 7:<br />
			return &#039;Waning Crescent Moon&#039;;<br />
			break;<br />
		default:<br />
			return &#039;Error&#039;;<br />
	}<br />
}<br />
$timestamp = time();<br />
echo moon_phase(date(&#039;Y&#039;, $timestamp), date(&#039;n&#039;, $timestamp), date(&#039;j&#039;, $timestamp));<br />
?&gt;<br />
</code></p>
<p>I haven&#8217;t been able to find out how to calculate the percentage for how lit up (full) the moon is yet though.</p>
<p>I converted the other code in another blog post. <a href="http://jivebay.com/2010/01/04/calculating-the-moon-phase-part-2/">Calculating the Moon Phase Part 2</a></p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=260&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2008/09/07/calculating-the-moon-phase/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Free Weather Forecast</title>
		<link>http://jivebay.com/2008/04/08/free-weather-forecast/</link>
		<comments>http://jivebay.com/2008/04/08/free-weather-forecast/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 16:06:39 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[weather]]></category>

		<guid isPermaLink="false">http://jivebay.com/2008/04/08/free-weather-forecast/</guid>
		<description><![CDATA[I noticed on the National Weather Service&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed on the <a href="http://www.weather.gov/xml/">National Weather Service&#8217;s website</a> 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.</p>
<p>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 <strong>DWMLgen</strong> which lets you get a little more specific information or <strong>NDFDgenByDay</strong> 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.</p>
<p>For the example we are doing, we are going to keep it simple and use a single location, <strong>NDFDgenByDay</strong> and a <strong>24 hourly</strong> period. We will also set it up so that we send the longitude and latitude for <strong>Austin, TX</strong>, the current date as the start date and request 7 days worth of data.<br />
<span id="more-223"></span><br />
You&#8217;ll want to get the longitude of the location you want the forecast for. The simplest way is to use <a href="http://maps.google.com/">Google Maps</a> and type in your city and state and search. Then put your cursor slightly below the green arrow, basically as soon as it is not linking to the arrow. Now double click and the map may shift slightly. Now click on the <strong>Link to this page</strong> text and you will get a box and copy whats in the first textfield. You&#8217;ll get a huge URL like the one below.</p>
<pre>

http://maps.google.com/maps?ie=UTF8&#038;oe=utf-8&#038;client=firefox-a&#038;q=Austin,+TX,+USA&#038;ll=30.270928,-97.742615&#038;spn=0.432311,0.6427&#038;z=11
</pre>
<p>What we want is the longitude and latitude. In that long URL you&#8217;ll see <strong>&#038;ll=</strong> and after it will be the longitude and latitude separated by a comma. And in this case it is <strong>30.270928,-97.742615</strong>.</p>
<p>So let&#8217;s make the request and write it to a file. Here is the PHP to do that.<br />
<code><br />
&lt;?php<br />
//custom function to write a file<br />
simple_write_file($filename, $data)<br />
{<br />
	//write file<br />
	$fp = @fopen($filename, &#039;w&#039;); //suppress error<br />
	if ($fp)<br />
	{<br />
		flock($fp, LOCK_EX);//lock file for writing<br />
		fwrite($fp, $data);<br />
		flock($fp, LOCK_UN);//release write lock<br />
		fclose($fp);<br />
		$output = &#039;&#039;;<br />
	}<br />
	else<br />
		$output = &#039;Failed to open file.&#039;;<br />
	return $output;<br />
}<br />
$parameters = array(&#039;lat&#039; =&gt; 30.270928, &#039;lon&#039; =&gt; -97.742615, &#039;startDate&#039; =&gt; gmdate(&#039;Y-m-d&#039;), &#039;numDays&#039; =&gt; 7, &#039;format&#039; =&gt; urlencode(&#039;24 hourly&#039;));<br />
$data = file_get_contents(&#039;http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?&amp;lat=&#039;.$parameters[&#039;lat&#039;].&#039;&amp;lon=&#039;.$parameters[&#039;lon&#039;].&#039;&amp;format=&#039;.$parameters[&#039;format&#039;].&#039;&amp;startDate=&#039;.$parameters[&#039;startDate&#039;].&#039;&amp;numDays=&#039;.$parameters[&#039;numDays&#039;]);<br />
simple_write_file(&#039;forecast.xml&#039;, $data);//NOTE: this will write the error to the file if it encounters one, but this is just for testing purposes<br />
?&gt;<br />
</code></p>
<p>The NWS recommends to make a new request 15 minutes after the hour and to cache the data for an hour. So you&#8217;ll want to write the code to cache it, but for this example we can just check the file and see if it&#8217;s good and then play with that file without having to make requests each time. Now here is some PHP code using <a href="http://us2.php.net/simplexml">SimpleXML</a> to parse through the data in that file.<br />
<code><br />
&lt;?php<br />
$output = &#039;&#039;;<br />
//php5<br />
if (file_exists(&#039;forecast.xml&#039;))<br />
{<br />
	$today = date(&#039;l&#039;);<br />
	$today_index = -1;<br />
	$xmlstr = file_get_contents(&#039;forecast.xml&#039;);<br />
	$xml = simplexml_load_string($xmlstr);<br />
	$xml_weather = $xml-&gt;data-&gt;parameters;//shorthand<br />
	$count = count($xml_weather-&gt;temperature-&gt;value);<br />
	$output .= &#039;&lt;ul id=&quot;weather_forecast&quot;&gt;&#039;;<br />
	for($x = 0; $x &lt; $count; $x++)<br />
	{<br />
		$output .= &#039;&lt;li&gt;&#039;;<br />
		//convert time to timestamp<br />
		$timestamp = strtotime($xml-&gt;data-&gt;{&#039;time-layout&#039;}-&gt;{&#039;start-valid-time&#039;}[$x]);<br />
		$day = date(&#039;l&#039;, $timestamp);<br />
		//get the day of the week<br />
		$output .= &#039;&lt;strong class=&quot;day_of_week&quot;&gt;&#039;;<br />
		if ($today == $day)<br />
		{<br />
			$output .= &#039;Today&#039;;<br />
			$today_index = $x + 1;<br />
		}<br />
		else if ($today_index == $x)<br />
			$output .= &#039;Tomorrow&#039;;<br />
		else<br />
			$output .= $day;<br />
		$output .= &#039;&lt;/strong&gt;&#039;;<br />
		//store it for shorthand multiple use<br />
		$condition = $xml_weather-&gt;weather-&gt;{&#039;weather-conditions&#039;}[$x]-&gt;attributes()-&gt;{&#039;weather-summary&#039;};<br />
		//icon image<br />
		$output .= &#039; &#039;;<br />
		$output .= &#039;&lt;img src=&quot;&#039;;<br />
		$output .= basename($xml_weather-/&gt;{&#039;conditions-icon&#039;}-&gt;{&#039;icon-link&#039;}[$x]);//get the filename, we are going to host the icons on our server<br />
		$output .= &#039;&quot; alt=&quot;&#039; . htmlentities($condition, ENT_QUOTES) . &#039;&quot; /&gt;&#039;;//alt text is the condition<br />
		//conditions<br />
		$output .= &#039; &#039;;<br />
		$output .= &#039;&lt;strong class=&quot;condition&quot;&gt;&#039;;<br />
		$output .= $condition;<br />
		$output .= &#039;&lt;/strong&gt;&#039;;<br />
		//NOTE: 7th day low will usually be null, so dont bother showing the high<br />
		if ($x &lt; 6)<br />
		{<br />
			//high and low<br />
			$output .= &#039; &#039;;<br />
			$output .= &#039;&lt;span class=&quot;temperature&quot;&gt;&#039;;<br />
			$output .= &#039;&lt;span class=&quot;temperature_high&quot;&gt;&#039; . $xml_weather-&gt;temperature[0]-&gt;value[$x] . &#039;&amp;deg;&lt;/span&gt;&#039;;//high<br />
			$output .= &#039; / &#039;;<br />
			$output .= &#039;&lt;span class=&quot;temperature_low&quot;&gt;&#039; . $xml_weather-&gt;temperature[1]-&gt;value[$x] . &#039;&amp;deg;&lt;/span&gt;&#039;;//low<br />
			$output .= &#039;&#039;;<br />
		}<br />
		//NOTE: precipitation is broken into 12hr periods and the 7th day&#039;s evening precipitation will usually be null<br />
		$output .= &#039;&#039;;<br />
	}<br />
	$output .= &#039;&lt;/ul&gt;&#039;;<br />
	$output .= &#039;&lt;p class=&quot;credits&quot;&gt;Weather by &lt;a href=&quot;&#039; . $xml-&gt;head-&gt;source-&gt;credit . &#039;&quot;&gt;NOAA&lt;/a&gt;&lt;/p&gt;&#039;;<br />
}<br />
echo $output;<br />
?&gt;<br />
</code></p>
<p>The benefits to the NWS service are: you can make a request for up to 200 locations in one call, you can get weather from the past or several days ahead and use it on a commercial site.</p>
<p>Now combine this code with <a href="http://jivebay.com/2008/02/01/current-weather-conditions/">code I did before on getting current conditions</a> and you one step closer to building your own portal. <a href="http://jivebay.com/2008/02/01/free-weather-for-your-web-site/">As I mentioned before</a>, you can’t claim to have copyright on the data, but it is <a href="http://www.weather.gov/disclaimer.php">public domain information</a>.</p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=223&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2008/04/08/free-weather-forecast/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Gallery2 vs Zenphoto vs Plogger</title>
		<link>http://jivebay.com/2008/02/05/gallery2-vs-zenphoto-vs-plogger/</link>
		<comments>http://jivebay.com/2008/02/05/gallery2-vs-zenphoto-vs-plogger/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 15:26:03 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plogger]]></category>
		<category><![CDATA[zenphoto]]></category>

		<guid isPermaLink="false">http://jivebay.com/2008/02/05/gallery2-vs-zenphoto-vs-plogger/</guid>
		<description><![CDATA[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&#8217;t protect original sizes of images

Zenphoto

Multiple uploads via JavaScript (can [...]]]></description>
			<content:encoded><![CDATA[<p>Here I cover some of the features of the best open source PHP image gallery web applications.</p>
<p><a href="http://gallery.menalto.com/">Gallery 2</a></p>
<ul>
<li>Multiple uploads via JavaScript (can add more file upload boxes)</li>
<li>Uploads by e-mail, ZIP or multiple image files</li>
<li>Configurable to run from multiple sites from one install</li>
<li>Reorder album via JavaScript</li>
<li>Ratings</li>
<li>Plugins available</li>
<li>Can&#8217;t protect original sizes of images</li>
</ul>
<p><a href="http://www.zenphoto.org/">Zenphoto</a></p>
<ul>
<li>Multiple uploads via JavaScript (can add more file upload boxes)</li>
<li>Uploads by ZIP or multiple image files</li>
<li>Spam filter options (Akismet, CAPTCHA, SpamAssassin, &#8230;)</li>
<li>Reorder album via JavaScript</li>
<li>AJAX editing of albums and images</li>
<li>Ratings</li>
<li>Watermarks</li>
<li>Can&#8217;t protect original sizes of images (except with a watermark)</li>
<li>RSS feed</li>
</ul>
<p><a href="http://www.plogger.org/">Plogger</a></p>
<ul>
<li>No multiple uploads via JavaScript (can&#8217;t add more file upload boxes)</li>
<li>Uploads by ZIP or single image files</li>
<li>Import from folder (you can FTP all images to a folder and have it import the images from that folder)</li>
<li>You can protect the original size images</li>
<li>RSS feed</li>
</ul>
<p>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).</p>
<p>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&#8217;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 <a href="http://www.opensourcecms.com/">OpenSourceCMS</a> and these were the best. <a href="http://coppermine-gallery.net/">Coppermine</a> is popular but it&#8217;s too ugly and the admin is kind of confusing.</p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=200&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2008/02/05/gallery2-vs-zenphoto-vs-plogger/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PHP Forms Class with 4 hour Video Tutorial</title>
		<link>http://jivebay.com/2008/02/04/php-forms-class-with-4-hour-video-tutorial/</link>
		<comments>http://jivebay.com/2008/02/04/php-forms-class-with-4-hour-video-tutorial/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 01:26:19 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jivebay.com/2008/02/04/php-forms-class-with-4-hour-video-tutorial/</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>Manuel Lemos has made a <a href="http://video.google.com/videoplay?docid=3038413558532929368&#038;hl=en">4 hour video tutorial</a> for his popular <a href="http://www.phpclasses.org/browse/package/1.html">PHP Forms Generation and Validation class</a>. Thankfully Google Video has a download link so you can watch it when you want. <a href="http://www.phpclasses.org/">PHP Classes</a> 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. <img src='http://jivebay.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I haven&#8217;t used this yet, but it looks interesting.</p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=202&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2008/02/04/php-forms-class-with-4-hour-video-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Current Weather Conditions</title>
		<link>http://jivebay.com/2008/02/01/current-weather-conditions/</link>
		<comments>http://jivebay.com/2008/02/01/current-weather-conditions/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 16:35:52 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[weather]]></category>

		<guid isPermaLink="false">http://jivebay.com/2008/02/01/current-weather-conditions/</guid>
		<description><![CDATA[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&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>The National Weather Service provides <a href="http://www.weather.gov/data/current_obs/">Current Weather Conditions XML files</a> for many cities in the US.</p>
<p>Here is some code for PHP5 (it uses SimpleXML) on doing this (assuming you&#8217;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 <a href="http://www.php.net/manual/en/function.date-sun-info.php">date_sun_info()</a> and since the XML file gives the date, latitude and longitude, you can calculate it dynamically.<br />
<code><br />
//PHP5<br />
if (file_exists(&#039;KADS.xml&#039;))<br />
{<br />
$xmlstr = file_get_contents(&#039;KADS.xml&#039;);<br />
$xml = simplexml_load_string($xmlstr);<br />
$datetime = strtotime($xml-&gt;observation_time_rfc822);<br />
$latitude = (float)$xml-&gt;latitude;<br />
$longitude = (float)$xml-&gt;longitude;<br />
$sun_info = date_sun_info(date(&#039;Y-n-j&#039;, $datetime), $latitude, $longitude);//calculate sunrise,sunset,...<br />
echo &#039;&lt;ul id=&quot;current_conditions&quot;&gt;&#039;;<br />
echo &#039;&lt;li&gt;&#039; . date(&#039;l, F j, Y&#039;, $datetime) . &#039;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li class=&quot;weather_loc&quot;&gt;&#039; . $xml-&gt;location . &#039;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;!--&#039; . $xml-&gt;observation_time . &#039;--&gt;&#039;;<br />
echo &#039;&lt;li&gt;&lt;img src=&quot;&#039; . $xml-&gt;icon_url_base . $xml-&gt;icon_url_name . &#039;&quot; alt=&quot;&#039; . $xml-&gt;weather . &#039;&quot; /&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li class=&quot;weather_temp&quot;&gt;&lt;strong&gt;&#039; . $xml-&gt;temp_f . &#039;&amp;deg;&#039; . &#039;&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li class=&quot;weather_sum&quot;&gt;&lt;strong&gt;&#039; . $xml-&gt;weather . &#039;&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li&gt;Wind: &lt;strong&gt;&#039; . $xml-&gt;wind_dir . &#039; &#039; . round($xml-&gt;wind_mph) . &#039; mph&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li&gt;Humidity: &lt;strong&gt;&#039; . $xml-&gt;relative_humidity . &#039;%&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
if ($xml-&gt;heat_index_f != &#039;NA&#039;)<br />
	echo &#039;&lt;li&gt;Heat Index: &lt;strong&gt;&#039; . $xml-&gt;heat_index_f . &#039;&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
if ($xml-&gt;windchill_f != &#039;NA&#039;)<br />
	echo &#039;&lt;li&gt;Windchill: &lt;strong&gt;&#039; . $xml-&gt;windchill_f . &#039;&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li&gt;Barometer: &lt;strong&gt;&#039; . $xml-&gt;pressure_in . &#039;&amp;quot;&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li&gt;Visibility: &lt;strong&gt;&#039; . $xml-&gt;visibility_mi . &#039; mi&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li&gt;Dewpoint: &lt;strong&gt;&#039; . $xml-&gt;dewpoint_f . &#039;&amp;deg;&lt;/strong&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li class=&quot;weather_credit&quot;&gt;weather by &lt;a href=&quot;&#039; . $xml-&gt;credit_URL . &#039;&quot; title=&quot;&#039; . $xml-&gt;credit . &#039;&quot;&gt;NOAA&lt;/a&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;/ul&gt;&#039;;<br />
echo &#039;&lt;ul id=&quot;sunrise_sunset&quot;&gt;&#039;;<br />
echo &#039;&lt;li&gt;Sunrise: &lt;strong&gt;&#039; . date(&#039;g:i a&#039;, $sun_info[&#039;sunrise&#039;]) . &#039;&lt;/strong&gt; &lt;span class=&quot;civil_twilight&quot;&gt;Civil Twilight: &lt;strong&gt;&#039; . date(&#039;g:i a&#039;, $sun_info[&#039;civil_twilight_begin&#039;]) . &#039;&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;li&gt;Sunrise: &lt;strong&gt;&#039; . date(&#039;g:i a&#039;, $sun_info[&#039;sunset&#039;]) . &#039;&lt;/strong&gt; &lt;span class=&quot;civil_twilight&quot;&gt;Civil Twilight: &lt;strong&gt;&#039; . date(&#039;g:i a&#039;, $sun_info[&#039;civil_twilight_end&#039;]) . &#039;&lt;/strong&gt;&lt;/span&gt;&lt;/li&gt;&#039;;<br />
echo &#039;&lt;/ul&gt;&#039;;<br />
}<br />
</code></p>
<p>You will probably want to cache that output once you have it formatted how you like.</p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=152&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2008/02/01/current-weather-conditions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Class Based on Date</title>
		<link>http://jivebay.com/2007/08/01/css-class-based-on-date/</link>
		<comments>http://jivebay.com/2007/08/01/css-class-based-on-date/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 00:57:22 +0000</pubDate>
		<dc:creator>blogger</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplepie]]></category>

		<guid isPermaLink="false">http://jivebay.com/2007/08/01/css-class-based-on-date/</guid>
		<description><![CDATA[I recently saw a tutorial on SimplePie&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>I recently saw a <a href="http://simplepie.org/wiki/tutorial/use_relative_dates">tutorial on SimplePie&#8217;s site about using relative dates</a> 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. <img src='http://jivebay.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Here is the function</strong><br />
<code><br />
//CREATE CSS BASED ON DATE<br />
function create_age_css_class($date_sent)<br />
{<br />
	/**<br />
	$date_sent should be in the following format: YYYYMMDDHHMMSS<br />
	Based on doRelativeDate() By Garrett Murray, http://graveyard.maniacalrage.net/etc/relative/<br />
	**/<br />
	$in_seconds = strtotime(substr($date_sent,0,8).&#039; &#039;.<br />
							substr($date_sent,8,2).&#039;:&#039;.<br />
							substr($date_sent,10,2).&#039;:&#039;.<br />
							substr($date_sent,12,2));<br />
	$diff = time()-$in_seconds;<br />
	if ($diff &lt; 86400)<br />
		$css_class = &#039;age_today&#039;;<br />
	else if ($diff &lt; 604800)<br />
		$css_class = &#039;age_days&#039;;<br />
	else if ($diff &lt; 1209600)<br />
		$css_class = &#039;age_week&#039;;<br />
	else if ($diff &lt; 2630880)<br />
		$css_class = &#039;age_weeks&#039;;<br />
	else<br />
		$css_class = &#039;age_month&#039;;<br />
	return $css_class;<br />
}<br />
</code></p>
<p><strong>Here is how I call it</strong><br />
<code><br />
$data .= &#039;&lt;li&gt;&lt;a href=&quot;&#039;. $item-&gt;get_permalink();<br />
//SET CLASS BASED ON DATE/AGE<br />
$data .= &#039; class=&quot;&#039; . create_age_css_class($item-&gt;get_date(&#039;YmdHis&#039;)) . &#039;&quot;&#039;;<br />
$data .= &#039;&gt;&#039;;<br />
</code></p>
<p>You don&#8217;t have to use <a href="http://simplepie.org">SimplePie</a> for this function, but it&#8217;s what inspired me to modify it.</p>
<p>Now for an screenshot<br />
<img src="http://jivebay.com/wp-content/uploads/css_classbased_date.png" alt="" title="css_classbased_date" width="451" height="158" class="alignnone size-full wp-image-346" /></p>
<p>Here is the HTML I used for that<br />
<code><br />
&lt;ul id=&quot;type3&quot;&gt;<br />
&lt;li class=&quot;age_today&quot;&gt;Lorem ipsum dolor sit amet&lt;/li&gt;<br />
&lt;li class=&quot;age_days&quot;&gt;Etiam iaculis nulla iaculis mauris&lt;/li&gt;<br />
&lt;li class=&quot;age_week&quot;&gt;Suspendisse at odio&lt;/li&gt;<br />
&lt;li class=&quot;age_week&quot;&gt;Nullam volutpat aliquam lacus&lt;/li&gt;<br />
&lt;li class=&quot;age_weeks&quot;&gt;Nunc dapibus eros vitae mauris rutrum laoreet&lt;/li&gt;<br />
&lt;li class=&quot;age_weeks&quot;&gt;Suspendisse sed nisl&lt;/li&gt;<br />
&lt;li class=&quot;age_month&quot;&gt;Nulla scelerisque gravida neque&lt;/li&gt;<br />
&lt;li class=&quot;age_month&quot;&gt;Leo imperdiet metus, ut adipiscing nisi lacus et pede&lt;/li&gt;<br />
&lt;/ul&gt;<br />
</code></p>
<p>And here is the CSS used<br />
<code><br />
&lt;style type=&quot;text/css&quot;&gt;<br />
body {font-family:Verdana, Arial, Helvetica, sans-serif; color:#000; background-color:#fff;}<br />
ul {list-style:none;}<br />
#type3 .age_days {font-size:150%; color:#555;}<br />
#type3 .age_week {font-size:100%; color:#777;}<br />
#type3 .age_weeks {font-size:80%; color:#999;}<br />
#type3 .age_month {font-size:60%; color:#ccc;}<br />
&lt;/style&gt;<br />
</code></p>
<p><ins datetime="2008-10-07T14:47:25+00:00">Added screenshot and sample CSS</ins></p>
<img src="http://jivebay.com/?ak_action=api_record_view&id=158&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://jivebay.com/2007/08/01/css-class-based-on-date/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
