<?


error_reporting(E_ALL);


dostart();

    $fname = "/home/cronlogs/rss_psxc.txt";
    
    $threads = file_get_contents($fname);
    
    $pass1 = explode(":!:!", $threads);
    
    // Now there should be a thread in each array entry of pass1
    
    for ($b=0;$b<count($pass1);$b++) {
        
        $thisline = $pass1[$b];
        
        $tdata = explode("::", $thisline);
        

        $url = $tdata[0];
        $title = $tdata[1];
        $message = $tdata[2];
        $dte = $tdata[3];
        
        //Tue, 13 Dec 2011 18:43:21 GMT
        $longdate = date("D, d M Y H:i:s O", $dte);
        
        
        doitem($title, $url, $longdate, $message);


    }

doend();



// ===============================================================================

function dostart() {

    echo '<?xml version="1.0" encoding="ISO-8859-1"?>';
    $longdate = date("D, d M Y H:i:s O");


    

    
?>

    <rss version="2.0">
        <channel>
        <lastBuildDate><? echo $longdate; ?></lastBuildDate>
        <generator>JamRSS</generator>
        <title>All the latest news, information, and file downloads from the Sony PlayStation/PsOne/PS2/PS3/PSP/PS VITA scenes!</title>
        <description>Recent Content from All the latest news, information, and file downloads from the Sony PlayStation/PsOne/PS2/PS3/PSP/PS VITA scenes!</description>
        <link>http://psx-scene.com/</link>
        <ttl>5</ttl>
        <image>
            <url>http://psx-scene.com/forums/images/black_topaz/misc/rss.png</url>
            <title>PSX-SCENE Latest News for Sony PlayStation/PsOne/PS2/PS3/PSP/PS VITA</title>

            <link>http://psx-scene.com/</link>
        </image>

        
<?

}        
  
// ===============================================================================    
        
function doitem($title, $link, $pubdate, $desc) {

    /*
    if ($creator == "xzxzxzxpmbrs") {
    for ($a=0;$a<strlen($desc);$a++) {
        
        $char = substr($desc,$a,1);
        
        echo "Char: $char : " . ord($char) . "<BR>\n";
        
    }    
    }
    */
    
    $desc = html_entity_decode($desc);
    $desc = strip_tags($desc) . " | " . $title;
    
    if (str_word_count($desc) > 30) {
        $desc = wordLimit($desc, 30);
    } 
    
    $desc .= " <a href='$link'>Read Full Post</a>";
    
?>     
        
        <item>
            <title><![CDATA[<? echo $title; ?>]]></title>
            <link><? echo $link; ?></link>
            <pubDate><? echo $pubdate; ?></pubDate>
            <description><![CDATA[<? echo $desc; ?>]]></description>

            <guid isPermaLink="true"><? echo $link; ?></guid>
        </item>

<?

}        
        
// ===============================================================================          
        
function doend() {
            
?>        

    </channel>
</rss>      

<?

}

// ===============================================================================  
        
function wordLimit($text,$limit=20){
    $explode = explode(' ',$text);
    $string  = '';
       
    $dots = '...';
    if(count($explode) <= $limit){
        $dots = '';
    }
    for($i=0;$i<$limit;$i++){
        $string .= $explode[$i]." ";
    }
       
    return $string.$dots;
}

// ===============================================================================   












?>