<?php
mysql_connect
('localhost''mysqlusername''mysqlpassword') or die('Cannot connect to Mysql');
mysql_select_db('databasename') or die('Cannot select database');

include(
'./xml2array.php');
$cURL 'http://www.donorschoose.org/common/rss_feed.html?zone=0';

$cXML file_get_contents($cURL);
$aXML xml2array($cXML);

$aItems $aXML['rss']['channel']['item'];

foreach (
$aItems as $rsItem) {
    
$cCheckQuery "select * from tablename where cTitle='" mysql_real_escape_string($rsItem['title']['value']) . "' limit 1";
    
$oCheckResult mysql_query($cCheckQuery);
    if (
mysql_num_rows($oCheckResult) == 0) {
        
// This is new!

        // Get the ID from the URL and use that as the SID
        // donors/proposal.html?id=205131
        
list(, $nSID) = explode('?id='$rsItem['link']['value']);
        list(
$nSID, ) = explode('&'$nSID);
        if (empty(
$nSID)) {
            
$nSID 'twitter';
        } 
// ends if (empty($nSID))

        
$cURL "http://www.anrdoezrs.net/click-xxxxxx-xxxxxx?sid=" urlencode($nSID) . "&url=http%3A%2F%2Fwww.donorschoose.org%2F" urlencode($rsItem['link']['value']);
        
$cTinyURL file_get_contents('http://tinyurl.com/api-create.php?url=' $cURL);

        if (!empty(
$cTinyURL)) {
            
mysql_query("insert into tablename (cTitle, cURL) values ('" mysql_real_escape_string($rsItem['title']['value']) . "', '" mysql_real_escape_string($cTinyURL) . "')");

            if (
strlen($rsItem['title']['value']) > 115) {
                
$rsItem['title']['value'] = substr($rsItem['title']['value'], 0115) . '...';
            } 
// ends if (strlen($rsItem['title']['value']) > 115)

            
$rsItem['title']['value'] = urlencode($rsItem['title']['value']);

            
$cStatus $rsItem['title']['value'] . ': ' $cTinyURL;


            
$curl_handle=curl_init();
            
curl_setopt($curl_handleCURLOPT_URL'http://twitter.com/statuses/update.xml');
            
curl_setopt($curl_handleCURLOPT_CONNECTTIMEOUT2);
            
curl_setopt($curl_handleCURLOPT_TIMEOUT2);
            
curl_setopt($curl_handleCURLOPT_POSTFIELDS"status=$cStatus");
            
curl_setopt($curl_handleCURLOPT_USERPWD"TwitterAccount:TwitterPassword");

            
$cXML curl_exec($curl_handle);
            
curl_close($curl_handle);

            exit();
        } 
// ends

    
// ends if (mysql_num_rows($oCheckResult) == 0)
    
else {
        
// Skip it.
    
// ends else from if (mysql_num_rows($oCheckResult) == 0)
// ends foreach ($aItems as $rsItem)
?>