<?php
include "config.php";
if($username != '' && $password != '')
{
$sql = mysql_query("SELECT * FROM messages WHERE (date='".date('Y-m-d')."' OR everyday=1) AND hour='".date('G')."' AND minute='".date('i')."'");
while($each = mysql_fetch_array($sql)) {
$result = Twitter::sendTwitter(stripslashes($username),stripslashes($password),$each['message']);
if($each['date']) mysql_query("DELETE FROM messages WHERE id='".$each['id']."'");
}
}
mysql_query("DELETE FROM messages WHERE date!='' AND date<'".date('Y-m-d')."'");
class Twitter
{
function Twitter() {
die('Cannot instantiate this class(Twitter) in: '.__FILE__);
}
/**
* Attempts to contact twitter and post a message
*
* @param string $uname = Twitter User Name
* @param string $pWord = Twitter Password
* @param string $message = The message to post through the communication system
* @param string $apiUrl = Twitter API Url. (Optional - defaulted to standard XML API)
* @return boolean
**/
function sendTwitter($uName='',$pWord='',$message='',$apiUrl='http://twitter.com/statuses/update.xml')
{
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$apiUrl");
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=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$uName:$pWord");
//Attempt to send
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if(strpos($buffer,'<error>') !== false)
{
return false;
}
else
{
return true;
}
}
}
?>
|