<?


error_reporting(E_ALL);


dostart();

    $fname = "/home/cronlogs/rss_psxf.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);
        
        $threadid = $tdata[0];
        $creator = $tdata[1];
        $url = $tdata[2];
        $title = $tdata[3];
        $message = $tdata[4];
        $dte = $tdata[5];
        
        //Tue, 13 Dec 2011 18:43:21 GMT
        $longdate = date("D, d M Y H:i:s O", $dte);
        
        
        doitem($title, $url, $longdate, $message, "", $creator);


    }

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" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
    
        <title>PSX-SCENE Forum Discussion for Sony PlayStation/PsOne/PS2/PS3/PSP/PS VITA</title>
        <link>http://psx-scene.com/forums/</link>
        <description>All the latest news, information, and file downloads from the Sony PlayStation/PsOne/PS2/PS3 scenes!</description>
        <language>en</language>

        <lastBuildDate><? echo $longdate; ?></lastBuildDate>
        <generator>JamRSS</generator>
        <ttl>5</ttl>
        <image>
            <url>http://psx-scene.com/forums/images/black_topaz/misc/rss.png</url>
            <title>PSX-SCENE Forum Discussion for Sony PlayStation/PsOne/PS2/PS3/PSP/PS VITA</title>

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

        
<?

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

    /*
    if ($creator == "xzxzxzxpmbrs") {
    for ($a=0;$a<strlen($desc);$a++) {
        
        $char = substr($desc,$a,1);
        
        echo "Char: $char : " . ord($char) . "<BR>\n";
        
    }    
    }
    */
    
    $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>

            <dc:creator><? echo $creator; ?></dc:creator>
            <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;
}

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












?>