here is the code I've implemented to get around the duplicate issue.
The issue arose when the latest thread was not the current status of the twitter account, so I updated the code to search the entire feed page for the thread title. It now checks the contents of your twitter page and looks for a match with the title of the first item in the RSS feed, if it finds it it does not try to repost. If it does not find a match it will call the twitter API and submit the message.
I then had an issue where it was posting <![CDATA[
thread title]]. I discovered that this only occurred when there was an apostrophe in the thread title, so I added a replace command to strip out the CDATA text.
There was also an issue where if your server did not receive a response from the twitter page in a timely fashion the script would not find a match for the latest title thread and would repost. I added a line in the script to search for your account name in the page, and if it finds it then call the twitter API. This ensures that there is no more double posting.
You need to replace the contents of the twitask.php file in the includes\cron folder with the script below. You need to replace the ACCOUNTNAME text in the line
http://twitter.com/ACCOUNTNAME with the name of your twitter account. this needs to be in the same case as the account name appears on your twitter page.
PHP Code:
<?php
// vBulletin2Twitter Provided Via http://ahealthforum.com
// Inspiration from Reuqests and various free open source scripts
// twitask.php may not be reproduced without prior written permission
// See vbtotwitt.php for open source script usage
//
// Set error status
error_reporting(E_ALL & ~E_NOTICE);
// Check database connection
if (!is_object($vbulletin->db))
{
exit;
}
include_once('vbtotwitt.php');
$u = $vbulletin->options['vb2twitter_u'];
$p = $vbulletin->options['vb2twitter_p'];
$twurl = 'http://twitter.com/statuses/update.xml';
$f = $vbulletin->options['vb2twitter_f'];
$rss = new lastRSS;
if ($rs = $rss->get($f)){
$title = $rs[items][0][title];
$url = $rs[items][0][link];
} else { die('Error: RSS file not found, dude.'); }
$title = str_replace("<![CDATA[", "", "$title");
$title = str_replace("]]>", "", "$title");
$title = str_replace("&", "and", "$title");
$tiny_url = file_get_contents("http://tinyurl.com/api-create.php?url=" . $url);
$status = $title . " " . $tiny_url;
echo $status; //just for status if you are directly viewing the script
$twitterfeed = file_get_contents("http://twitter.com/ACCOUNTNAME");
$stringtocheckfor = $title;
if(strstr($twitterfeed,$stringtocheckfor)) {
echo "<br />status update already exists";
} else {
$accountstring = $vbulletin->options['vb2twitter_u'];
if(strstr($twitterfeed,$accountstring)) {
$curl_handle = curl_init();
curl_setopt($curl_handle,CURLOPT_URL,"$twurl");
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle,CURLOPT_POST,1);
curl_setopt($curl_handle,CURLOPT_POSTFIELDS,"status=$status");
curl_setopt($curl_handle,CURLOPT_USERPWD,"$u:$p");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer)){echo '<br/>message';}else{echo '<br/>success';}
// log message
$logmsg = 'Twitter Update';
// Output Log Status
log_cron_action($logmsg, $nextitem);
} else {
echo '<br />twitter page not found';
}
}
?>
If you have $cronimage in your footer template and have the twitter scheduled task set to run every minute each time a new thread is started the title will be updated. You will also need to set the refresh time on your RSS feed in vboptions to 0 if you want to ensure that every new thread is updated to your twitted feed. If the refresh time is 60 minutes you will only have the latest thread submitted every hour when the RSS cache is refreshed.
I've been running with the above script and options for the last several days and have eliminated the duplicate posting issues.