Created
November 30, 2008 17:30
-
-
Save jim/30487 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('TWITTER_USERNAME', 'testfacer'); // your twitter username | |
define('TWITTER_PASSWORD', 'testfacer'); // your twitter password | |
// post to twitter for these sections | |
// separate more than one with just a comma: 'articles,about,etc' | |
define('TWITTER_SECTIONS', 'articles'); | |
// setup a callback so we're notified when an article is edited | |
if (@txpinterface == 'admin') { | |
global $txpcfg; | |
register_callback("write_tweet", 'article' , 'edit'); | |
} | |
// callback to check for an article to tweet | |
function write_tweet($event, $step) | |
{ | |
include_once txpath.'/publish/taghandlers.php'; | |
$rs = safe_row("ID, Title, Section", 'textpattern', "status=4 AND custom_10='' AND TIMEDIFF(now(),LastMod)<'00:00:30' ORDER BY LastMod ASC"); | |
if (count($rs)>0 && in_array($rs['Section'], explode(',', TWITTER_SECTIONS))){ | |
postToTwitter(TWITTER_USERNAME,TWITTER_PASSWORD,$rs['Title'].": ".permlinkurl_id($rs['ID'])); | |
safe_update("textpattern", "custom_10 = 'yes'", "id = ".$rs['ID']); | |
} | |
} | |
// call the twitter API | |
function postToTwitter($username,$password,$message){ | |
$host = "http://twitter.com/statuses/update.xml?status=".urlencode(stripslashes(urldecode($message))); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $host); | |
curl_setopt($ch, CURLOPT_VERBOSE, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); | |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$result = curl_exec ($ch); //Ojo, hay un espacio en exec | |
$resultArray = curl_getinfo($ch); | |
curl_close($ch); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment