<?php
/**
* CONFIGURATION
*/
$config = array(
#Twitter Password
'username' => '',
#Twitter Username
'password' => '',
#Category to 'tweet'
'target_category' => 'cafe',
#Maximum age in minutes of posts to 'tweet'
'age_threshold' => '',
#Full location of cache file
'cache_file' => '/full/path/to/cache.file'
);
$xml = @new SimpleXMLElement('http://cdevroe.com/feed/', null, true);
if(true === ($xml instanceof SimpleXMLElement)){
foreach($xml->xpath(sprintf("//category[text()='%s']/..", $config['target_category'])) as $item){
if(true === in_array(sha1($item->title), file($config['cache_file'])){
continue;
}
if((time() - (integer)strtotime($item->pubDate)) >= ($config['age_threshold'] * 60)){
continue;
}
$curl = curl_init(
sprintf(
'http://twitter.com/statuses/update.xml?status=%s',
urlencode(
sprintf(
'%s "%s" : %s',
$config['target_category'],
$item->title,
str_replace('?p=', 'p/', $item->guid)
)
)
)
);
curl_setopt_array(
$curl,
array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_POST => true,
CURLOPT_USERPWD => sprintf('%s:%s', $config['username'], $config['password'])
)
);
curl_exec($curl);
if(200 === curl_getinfo($curl, CURLINFO_HTTP_CODE)){
file_put_contents($config['cache_file'], sprintf("%s\r\n", sha1($item->title)), FILE_APPEND);
}
}
}
?>