[[ автор и тема тут ]]
PHP код:
// DB connection
$db = mysql_connect ("localhost","!!!YOU-LOGIN!!!","!!!PASSWORD!!!");
mysql_select_db("!!!BASE-NAME!!!",$db);
// MySQL Select
$result = mysql_query ("SELECT * FROM !!!TABLE-NAME!!! WHERE twitter!='Y'", $db);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{
$myrow = mysql_fetch_array ($result);
// Get Title and URL
$id=$myrow["article_id"];
$title=$myrow["article_title"];
$url=$myrow["article_title"];
$url=preg_replace("/[^a-z0-9]/i", "-", $url);
$url="http://www.YOU-SITE.com/Article/".$url."/".$id;
// TWITTER UPDATER
// Message text
$thisposttitle = $title;
$thispostlink = $url;
$tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$thispostlink);
if (strlen($tinyurl) > 10)
{
$result = mysql_query ("UPDATE !!!TABLE-NAME!!! SET twitter='Y' WHERE article_id=$id", $db);
$sentence = '';
$sentence = $thisposttitle . ' ( ' . $tinyurl . ' )';
// Login & Pass
$twitterlogin = '!!!TWITTER-LOGIN!!!';
$twitterpw = '!!!TWITTER-PASSWORD!!!';
$twitterlogin_encrypted = base64_encode($twitterlogin.':'.$twitterpw);
// Send Message
$twit = 'status='.$sentence;
$host = 'twitter.com';
$port = 80;
$fp = fsockopen($host, $port, $err_num, $err_msg, 10);
if (!$fp)
{
echo "$err_msg ($err_num)
\n";
} else
{
echo $string;
fputs($fp, "POST /statuses/update.xml HTTP/1.1\r\n");
fputs($fp, "Authorization: Basic ".$twitterlogin_encrypted."\r\n");
fputs($fp, "User-Agent: ".$agent."\n");
fputs($fp, "Host: $host\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($twit)."\n");
fputs($fp, "Connection: close\n\n");
fputs($fp, $twit);
for ($i = 1; $i < 10; $i++){$reply = fgets($fp, 256);}
fclose($fp);
}
}
}
?>
Комментариев нет:
Отправить комментарий