Every search engine hits(Google, MSN, Yahoo, etc..) is posted with the URL of the page found. Links are converted by bit.ly URL shortener. The script drives organic traffic to your site from twitter and related sites processing twitter data.
/* Install:
1.Edit index.php
2.find 3.Insert 2 lines below —
require(‘twitter.php’);
Twitter::TweetKeyword();
—
*/
define(“TWEET_USER”, “REPLACE_WITH_TWITTER_USERNAME”); // Writter username
define(“TWEET_PASS”, “REPLACE_WITH_TWITTER_PASSWORD”); // twitter password
define(“BITLY_USER”, “REPLACE_WITH_BIT.LY_USERNAME”); // bit.ly login name — HAVE TO REGISTER at bit.ly to get one for FREE
define(“BITLY_API_KEY”, “REPLACE_WITH_BIT.LY_API_KEY”); // bit.ly api key — HAVE TO REGISTER at bit.ly to get one for FREE
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($message=”,$apiUrl=’http://twitter.com/statuses/update.xml’)
{
$uName = TWEET_USER;
$pWord = TWEET_PASS;
$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,”) !== false)
{
return false;
}
else
{
return true;
}
}
function shortURL($url=”)
{
$bitly_login = BITLY_USER;
$bitly_apikey = BITLY_API_KEY;
$data = “http://api.bit.ly/shorten?version=2.0.1&longUrl=”.$url.”&login=”.$bitly_login.”&apiKey=”.$bitly_apikey;
$api_call = file_get_contents($data);
$bitlyinfo=json_decode(utf8_encode($api_call),true);
if ($bitlyinfo['errorCode']==0) {
return $bitlyinfo['results'][urldecode($url)]['shortUrl'];
} else {
return false;
}
}
function seReferer($ref = false){
$SeReferer = (is_string($ref) ? $ref : $_SERVER['HTTP_REFERER']);
if( //Check against Google, Yahoo, MSN, Ask and others
preg_match(“/[&\?](q|p|w|searchfor|as_q|as_epq|s|query)=([^&]+)/i”, $SeReferer,$pcs))
{
if(preg_match(“/https?:\/\/([^\/]+)\//i”,$SeReferer,$SeDomain)){
$SeDomain = trim(strtolower($SeDomain[1]));
$SeQuery = $pcs[2];
if(preg_match(“/[&\?](start|b|first|stq)=([0-9]*)/i”,$SeReferer,$pcs)){
$SePos = (int)trim($pcs[2]);
}}
}
if(!isset($SeQuery)){
if( //Check against DogPile
preg_match(“/\/search\/web\/([^\/]+)\//i”,$SeReferer,$pcs)
){
if(preg_match(“/https?:\/\/([^\/]+)\//i”,$SeReferer,$SeDomain)){
$SeDomain = trim(strtolower($SeDomain[1]));
$SeQuery = $pcs[1];
}
}
}
// We Do Not have a query
if(!isset($SeQuery)){ return false; }
$OldQ=$SeQuery;
$SeQuery=urldecode($SeQuery);
// The Multiple URLDecode Trick to fix DogPile %XXXX Encodes
while($SeQuery != $OldQ)
{
$OldQ=$SeQuery; $SeQuery=urldecode($SeQuery);
}
//– We have a query
return array(
“Se”=>$SeDomain,
“Query”=>$SeQuery,
“Pos”=>(int)$SePos,
“Referer”=>$SeReferer
);
}
function safedata($data)
{
$data = ereg_replace(“[\'\")(;|`,<>]“, “”, $data);
$data = trim(preg_replace(“/\s+/”, ” “, $data));
return stripslashes($data);
}
function myTwitter($url=”, $message)
{
$msg = Twitter::shortURL($url);
if ($msg == false) { return false; }
else return Twitter::sendTwitter($message.” – “.$msg);
}
function TweetKeyword()
{
$SeReferer = $_SERVER['HTTP_REFERER'];
if( !$SeReferer ){ return false; }
$se = Twitter::seReferer($SeReferer);
if ( empty($se['Query']) ) return false;
$data = strtolower(Twitter::safedata($se['Query']));
//Google cache: – HTTP: – WWW ?????????? – something we dont what
if( strpos($data, “:”) || strpos($data, “www”) || strpos($data, “.”) )
{
return false;
}
$s = empty($_SERVER["HTTPS"]) ? ” : ($_SERVER["HTTPS"] == “on”) ? “s” : “”;
$protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), “/”)) . $s;
$port = ($_SERVER["SERVER_PORT"] == “80″) ? “” : (“:”.$_SERVER["SERVER_PORT"]);
$myurl = $protocol . “://” . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];
return Twitter::myTwitter($myurl, $data);
}
}
