Switch more PHP files to use the DBAL.
Switch more PHP files to use the DBAL.

File last commit:

d3dc8cc67273
749c3253f5e9
Show More
twitter.php
63 lines | 1.9 KiB | text/x-php | PhpLexer
<?php
function twitterpost($message, $user=TWITTER_USER, $password=TWITTER_PASS)
{
global $dbConnection, $info, $error;
if( $user == '' ) {
# preserve existing twitterpost(message) style posting until OAuth has been vetted.
$user = TWITTER_USER;
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, TWITTER_HOST);
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=".urlencode($message));
curl_setopt($curl_handle, CURLOPT_USERPWD, urlencode($user).":".urlencode($password));
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if(empty($buffer))
{
adminlog("Twitter post failed for user $user!", MTS_TWITTER, MTA_ADD);
}
return !empty($buffer);
} else {
# OAuth Mode
$row = $dbConnection->executeQuery('SELECT id, username, oauth_token, oauth_token_secret FROM twitter_user WHERE username = ?', array($user))->fetch();
$username = $row->username;
$oauth_token = $row->oauth_token;
$oauth_token_secret = $row->oauth_token_secret;
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $oauth_token, $oauth_token_secret);
$parameters = array('status' => $message );
$status = $connection->post('statuses/update', $parameters);
switch( $connection->http_code ) {
case 200:
adminlog("Twitter post succeeded for user $username!", MTS_TWITTER, MTA_ADD);
return true;
default:
adminlog("Twitter post failed for user $username!", MTS_TWITTER, MTA_ADD);
return false;
}
}
}
function setOAuthTokens($userid,$oauth_token,$oauth_token_secret, $username) {
global $mtdb;
$id = (int)$userid;
if ($dbConnection->executeUpdate('UPDATE twitter_user SET oauth_token = ?, oauth_token_secret = ?, username = ? WHERE id = ?', array($oauth_token, $oauth_token_secret, $username, $id)))
return true;
return false;
}
?>