Selasa, 11 September 2012

0 Menambahkan Fitur Tweet Longer dari twtmore.com pada Dabr


Pada file common/twitter.php, cari
function twitter_update() {
menambahkan coding dibawah ini SEBELUM if ($status) {
$callback_key = false;
if (mb_strlen($status, ‘utf-8′) > 140) {
$reply_to_id = null;
if (is_numeric((string) $_POST['in_reply_to_id'])) {
$reply_to_id = (string) $_POST['in_reply_to_id'];
}
$response = post_twtmore_tweet(user_current_username(), $status, $reply_to_id);
if (!$response) {
theme(‘error’, "<h2>Long tweet error</h2><p>An unexpected error occured while posting to twtmore. Please try again.</p><hr>");
twitter_refresh($_POST['from'] ? $_POST['from'] : ”);
return;
}

$tatus = $response->tweet->short_content;
$callback_key = $response->callback_key;
}
masih di dalam funtion yg sama, tambahkan coding di bawah ini SESUDAH $b = twitter_process($request, $post_data);
if ($callback_key) {
post_twtmore_callback($callback_key, $b->id_str);
}
kemudian tambahkan junga coding functions di dalam file common/twitter.php tersebut, terserah di taro di bagian mana, asal tidak di dalam function yg lain, taruh saja di bagian paling bawah sebelum tanda ?>
// twtmore api key
define(‘TWTMORE_API_KEY’, ‘ISI_DENGAN_API_TWTMORE_KAMU’);
function post_twtmore_tweet($username, $tweet, $reply_to_tweet_id = null)
{
// Formulate the request
$request = array(
‘apikey’ => TWTMORE_API_KEY,
‘user’ => $username,
‘tweet’ => $tweet
);
// If reply
if ($reply_to_tweet_id)
{
$request['reply_to_tweet'] = $reply_to_tweet_id;
}
// Create CURL
$url = ‘http://api.twtmore.com/v3/shorten’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
// Execute CURL
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close CURL
curl_close($ch);
// Check we have a % 200 HTTP status code, and the JSON decodes ok
if ($code == 200 && ($resp = json_decode($response)))
{
return $resp;
}
// There was an error
return false;
}
function post_twtmore_callback($callback_key, $twitter_id)
{
$request = array(
‘apikey’ => TWTMORE_API_KEY,
‘key’ => $callback_key,
‘status_id’ => $twitter_id
);
$url = ‘http://api.twtmore.com/v3/callback’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

0 Comments

Bagaimana Pendapat Anda ?