RSS, Atom & RDF Date Parsing in Magpie RSS

Date formatting for Magpie RSS. This bit of code is simply to verify the date on the posts using the RSS Feeds within the database. I had a hard time converting the RFC822 date over to ISO8601 but I had fun doing it. I’m also sure that I’ll go back and clean the code even more…

I’m planning on implementing it within the next few days to stop the blogs that do not update thier site but update the list. This isn’t the remedy but it’s the only thing that I can do at the moment. Within the next few months I’ll try to implement an automatic RSS Feed update for the entire directory. Something I’ve tried to program before but to no avail… The database is huge and in order to cache the files that it needs to sort, it gets hung up once it gets past 100 Feeds…

$x=0;
$today_date = time();
$now = date("m.d.y h:m", $today_date);

$nm='';
$nm.= $now[0];
$nm.= $now[1];

$nd='';
$nd.=$now[3];
$nd.=$now[4];

$published=$item['published'];
if ($published != '')
{
$x=1;
}

$published2=$item['pubdate'];
if ($published2 != '' && $x == 0)
{
$published2 = date("m.d.Y h:i:s a", strtotime($published2));
$x=2;
}

$published3=$item['dc']['date'];
if ($published3!= '' && $x == 0)
{
$x=3;
}

$published4=$item['itemposttime'];
if ($published4!= '' && $x == 0)
{
$x=4;
}

$published5=$item['issued'];
if ($published5!= '' && $x == 0)
{
$x=5;
}

if($x==1)
{

$ampm='am';
$m='';
$m.= $published[5];
$m.= $published[6];

$d='';
$d.=$published[8];
$d.=$published[9];

$y='';
$y.=$published[0];
$y.=$published[1];
$y.=$published[2];
$y.=$published[3];

$h='';
$h.=$published[11];
$h.=$published[12];

if ($h>12)
{
$h=$h-12;
$ampm='pm';
}

$h.=":";
$h.=$published[14];
$h.=$published[15];
$h.=$ampm;

}

if($x==2)
{
$ampm='am';
$m='';
$m.= $published2[0];
$m.= $published2[1];

$d='';
$d.=$published2[3];
$d.=$published2[4];

$y='';
$y.=$published2[6];
$y.=$published2[7];
$y.=$published2[8];
$y.=$published2[9];

$h='';
$h.=$published2[11];
$h.=$published2[12];

if ($h>12)
{
$h=$h-12;
$ampm='pm';
}

$h.=":";
$h.=$published2[14];
$h.=$published2[15];
$h.=$ampm;
}

if($x==3)
{
$ampm='am';

$m='';
$m.= $published3[5];
$m.= $published3[6];

$d='';
$d.=$published3[8];
$d.=$published3[9];

$y='';
$y.=$published3[0];
$y.=$published3[1];
$y.=$published3[2];
$y.=$published3[3];

$h='';
$h.=$published3[11];
$h.=$published3[12];
if ($h>12)
{
$h=$h-12;
$ampm='pm';
}
$h.=":";
$h.=$published3[14];
$h.=$published3[15];
$h.=$ampm;
}

if ($x==4)
{
$ampm='am';

$m='';
$m.= $published4[5];
$m.= $published4[6];

$d='';
$d.=$published4[8];
$d.=$published4[9];

$y='';
$y.=$published4[0];
$y.=$published4[1];
$y.=$published4[2];
$y.=$published4[3];

$h='';
$h.=$published4[11];
$h.=$published4[12];
if ($h>12)
{
$h=$h-12;
$ampm='pm';
}
$h.=":";
$h.=$published4[14];
$h.=$published4[15];
$h.=$ampm;
}

if ($x==5)
{
$ampm='am';

$m='';
$m.= $published5[5];
$m.= $published5[6];

$d='';
$d.=$published5[8];
$d.=$published5[9];

$y='';
$y.=$published5[0];
$y.=$published5[1];
$y.=$published5[2];
$y.=$published5[3];

$h='';
$h.=$published5[11];
$h.=$published5[12];
if ($h>12)
{
$h=$h-12;
$ampm='pm';
}
$h.=":";
$h.=$published5[14];
$h.=$published5[15];
$h.=$ampm;
}

if($d!='')
{$old_post=$d;
}
else
{$old_post=$nd-3;
}
$yesterday=$nd-2;

blah blah blah...

Have fun copying and pasting :D

Oh! and if you think you can make the code better, knock yourself out… I’m open to ideas…


About this entry