document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2.  
  3. /**
  4. * First, locate your "twitter.php" file in "/common/twitter.php" and replace it with the following one
  5. *
  6. * @see http://code.google.com/p/dabr/source/browse/trunk/common/twitter.php
  7. * https://github.com/twtmore/twtmore-api-samples/blob/master/php/dabr/dabr.php
  8. * http://bluetuut.blogspot.com/
  9.  
  10. **/
  11.  
  12. function twitter_update() {
  13.  
  14. twitter_ensure_post_action();
  15. $status = stripslashes(trim($_POST['status']));
  16.  
  17. $callback_key = false;
  18. if (mb_strlen($status, 'utf-8') > 140) {
  19.  
  20. $reply_to_id = null;
  21. if (is_numeric((string) $_POST['in_reply_to_id'])) {
  22. $reply_to_id = (string) $_POST['in_reply_to_id'];
  23. }
  24.  
  25. $response = post_twtmore_tweet(user_current_username(), $status, $reply_to_id);
  26.  
  27. if (!$response) {
  28.  
  29. theme('error', "<h2>twtmore error</h2><p>An unexpected error occured while posting to twtmore. Please try again.</p><hr>");
  30. twitter_refresh($_POST['from'] ? $_POST['from'] : '');
  31. return;
  32. }
  33.  
  34. $status = $response->tweet->short_content;
  35. $callback_key = $response->callback_key;
  36. }
  37.  
  38. if ($status) {
  39.  
  40. $request = API_URL.'statuses/update.json';
  41. $post_data = array('source' => 'dabr', 'status' => $status);
  42. $in_reply_to_id = (string) $_POST['in_reply_to_id'];
  43. if (is_numeric($in_reply_to_id)) {
  44. $post_data['in_reply_to_status_id'] = $in_reply_to_id;
  45. }
  46. // Geolocation parameters
  47. list($lat, $long) = explode(',', $_POST['location']);
  48. $geo = 'N';
  49. if (is_numeric($lat) && is_numeric($long)) {
  50. $geo = 'Y';
  51. $post_data['lat'] = $lat;
  52. $post_data['long'] = $long;
  53. // $post_data['display_coordinates'] = 'false';
  54.  
  55. // Turns out, we don't need to manually send a place ID
  56. /* $place_id = twitter_get_place($lat, $long);
  57. if ($place_id) {
  58.  
  59. // $post_data['place_id'] = $place_id;
  60. }
  61. */
  62. }
  63. setcookie_year('geo', $geo);
  64. $b = twitter_process($request, $post_data);
  65.  
  66. if ($callback_key) {
  67.  
  68. // After you post to twitter
  69. post_twtmore_callback($callback_key, $b->id_str);
  70. }
  71. }
  72.  
  73. twitter_refresh($_POST['from'] ? $_POST['from'] : '');
  74. }
  75.  
  76. /**
  77. * Now just add ALL of the following code (the two functions and the DEFINE()) to the bottom of your twitter.php file
  78. * DONT FORGET TO FILL IN YOUR API KEY!!
  79. **/
  80.  
  81. /***********************
  82. ** TWTMORE FUNCTIONS **
  83. ***********************/
  84.  
  85. define('TWTMORE_API_KEY', '__PUT_YOUR_API_KEY_HERE__');
  86.  
  87. /**
  88. * Use this function to post a tweet to twtmore, and then to Twitter API after.
  89. *
  90. * @see http://dev.twtmore.com/docs/api/shorten
  91. *
  92. * @param $tweet - The text of the tweet, > 140 characters
  93. * @param $username - The username of the user posting the tweet, eg "tarnfeld" or "twtmore"
  94. * @param $reply_to_user - If this tweet is replying, this is the username for that user
  95. * @param $reply_to_tweet_id - If this tweet is replying, this is the ID of the twitter status it is replying to
  96. *
  97. * @return StdClass Object or FALSE
  98. *
  99. */
  100. function post_twtmore_tweet($username, $tweet, $reply_to_tweet_id = null)
  101. {
  102.  
  103. // Formulate the request
  104. $request = array(
  105. 'apikey' => TWTMORE_API_KEY,
  106. 'user' => $username,
  107. 'tweet' => $tweet
  108. );
  109.  
  110. // If reply
  111. if ($reply_to_tweet_id)
  112. {
  113. $request['reply_to_tweet'] = $reply_to_tweet_id;
  114. }
  115.  
  116. // Create CURL
  117. $url = 'http://api.twtmore.com/v3/shorten';
  118. $ch = curl_init($url);
  119. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  120. curl_setopt($ch, CURLOPT_POST, true);
  121. curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  122.  
  123. // Execute CURL
  124. $response = curl_exec($ch);
  125. $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  126.  
  127. // Close CURL
  128. curl_close($ch);
  129.  
  130. // Check we have a % 200 HTTP status code, and the JSON decodes ok
  131. if ($code == 200 && ($resp = json_decode($response)))
  132. {
  133. return $resp;
  134. }
  135.  
  136. // There was an error
  137. return false;
  138. }
  139.  
  140. /**
  141. * Use this AFTER you post to twtmore AND you post to twitter and have the TWITTER STATUS ID
  142. *
  143. * @see http://dev.twtmore.com/docs/api/callback
  144. *
  145. * @param $callback_key - The "callback_key" part of the post_twtmore_tweet() response
  146. * @param $twitter_id - The TWITTER ID (eg: 123368090347114496) - "id_str" from the TWITTER API
  147. */
  148. function post_twtmore_callback($callback_key, $twitter_id)
  149. {
  150. $request = array(
  151. 'apikey' => TWTMORE_API_KEY,
  152. 'key' => $callback_key,
  153. 'status_id' => $twitter_id
  154. );
  155.  
  156. $url = 'http://api.twtmore.com/v3/callback';
  157. $ch = curl_init($url);
  158. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  159. curl_setopt($ch, CURLOPT_POST, true);
  160. curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  161.  
  162. // Execute CURL
  163. $response = curl_exec($ch);
  164. $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  165.  
  166. // We don't return anything because this API method doesn't return anything important...
  167. }
  168.  
  169.  
');