-<?php
-if (get_magic_quotes_gpc()) {
-
- $_REQUEST = array_map('stripslashes', $_REQUEST);
- $_GET = array_map('stripslashes', $_GET);
- $_POST = array_map('stripslashes', $_POST);
- $_COOKIE = array_map('stripslashes', $_COOKIE);
-
-}
-class twitter{
- var $username='';
- var $password='';
- var $user_agent='API';
- var $type='json';
-
- var $headers=array('Expect:', 'X-Twitter-Client: ','X-Twitter-Client-Version: ','X-Twitter-Client-URL: ');
- var $responseInfo=array();
- var $suppress_response_code = false;
- var $debug = false;
- public $timeout = 5;
- public $connecttimeout = 5;
-
- function twitter($username = '', $password = '', $type = 'json')
- {
- if ($username != '' && $password != '') {
- $this->username = $username;
- $this->password = $password;
- $this->type = $type;
- }
- }
-
- function veverify()
- {
- $request = API_URL . '/account/verify_credentials.' . $this->type;
- return $this->objectify( $this->process($request, false, 0) );
- }
-
- /**** Get user theme ****/
- function getTheme()
- {
- $twit = $this->veverify();
- $theme = array( 'background-color' => $twit->profile_background_color, 'background-image-url' => $twit->profile_background_image_url, 'background-tile' => $twit->profile_background_tile == true ? 'repeat' : 'no-repeat', 'link-color' => $twit->profile_link_color, 'sidebar-border-color' => $twit->profile_sidebar_border_color, 'sidebar-fill-color' => $twit->profile_sidebar_fill_color, 'text-color' => $twit->profile_text_color);
- return $theme;
- }
-
-
- /**** Status Methods ****/
-
- function showStatus( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/statuses/show/'.$id . '.' . $this->type;
- return $this->objectify( $this->process($request) );
- }
-
- function update( $status, $replying_to = false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $args = array();
- if( $status )
- $args['status'] = $status;
- if( $replying_to )
- $args['in_reply_to_status_id'] = $replying_to;
- $args['source'] = 'API';
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/statuses/update.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request, true) );
- }
-
- function deleteStatus( $id ) {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/statuses/destroy/' . $id . '.' . $this->type;
- return $this->objectify( $this->process( $request, true ) );
- }
-
-
- /**** Timeline Methods ****/
-
- function publicTimeline( $sinceid = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $qs='';
- if( $sinceid !== false )
- $qs = '?since_id=' . intval($sinceid);
- $request = API_URL . '/statuses/public_timeline.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
- }
-
- function userTimeline($page=false,$id=false,$count=false,$since_id=false)
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $args = array();
- if( $id )
- $args['id'] = $id;
- if( $count )
- $args['count'] = (int) $count;
- if( $since_id )
- $args['since_id'] = (int) $since_id;
- if( $page )
- $args['page'] = (int) $page;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- if( $id === false )
- $request = API_URL . '/statuses/user_timeline.' . $this->type . $qs;
- else
- $request = API_URL . '/statuses/user_timeline/' . rawurlencode($id) . '.' . $this->type . $qs;
- $response = $this->process($request);
- if($response == false){
- return 'protected';
- }
- return $this->objectify($response);
-
- }
-
- function friendsTimeline( $page = false, $since_id = false, $count = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $args = array();
- if( $count )
- $args['count'] = $count;
- if( $since_id )
- $args['since_id'] = $since_id;
- if( $page )
- $args['page'] = (int) $page;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/statuses/friends_timeline.' . $this->type . $qs;
- return $this->objectify( $this->process($request) );
-
- }
-
- function replies( $page = false, $since_id = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $args = array();
- if( $page )
- $args['page'] = (int) $page;
- if( $since_id )
- $args['since_id'] = $since_id;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/statuses/mentions.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
-
- }
-
-
- /**** Direct Message Methods ****/
-
- function directMessages( $page = false, $since_id = false, $count = null )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $qs='?';
- $qsparams = array();
- if( $since_id )
- $qsparams['since_id'] = $since_id;
- if( $page )
- $qsparams['page'] = (int) $page;
-
- $request = API_URL . '/direct_messages.' . $this->type . '?' . $this->arrToStr($qsparams);
-
- return $this->objectify( $this->process($request) );
- }
-
- function sentDirectMessage( $page = false, $since = false, $since_id = false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $qs = '?';
- $qsparams = array();
- if( $since !== false )
- $qsparams['since'] = rawurlencode($since);
- if( $since_id )
- $qsparams['since_id'] = (int) $since_id;
- if( $page )
- $qsparams['page'] = (int) $page;
-
- $request = API_URL . '/direct_messages/sent.' . $this->type . '?' . $this->arrToStr($qsparams);
- return $this->objectify( $this->process($request) );
- }
-
- function sendDirectMessage( $user, $text )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/direct_messages/new.' . $this->type;
- $postargs = 'user=' . rawurlencode($user) . '&text=' . rawurlencode($text);
-
- return $this->objectify( $this->process($request, $postargs) );
- }
-
- function deleteDirectMessage( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/direct_messages/destroy/' . $id . '.' . $this->type;
- return $this->objectify( $this->process( $request, true ) );
- }
-
-
- /**** User Methods ****/
-
- function showUser( $id = false , $email = false, $user_id = false, $screen_name=false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- if (!$id)
- $id = $this->username;
- if( $user_id ) :
- $qs = '?user_id=' . $user_id;
- elseif ( $screen_name ) :
- $qs = '?screen_name=' . (string) $screen_name;
- elseif ( $email ) :
- $qs = '?email=' . (string) $email;
- else :
- $qs = $id;
-
-endif;
-
-$request = API_URL . '/users/show/' . $qs . '.' . $this->type;
-
-return $this->objectify( $this->process($request) );
- }
-
- function friends( $id = false, $page = false , $count = 30 )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $args = array();
- if( $id )
- $args['id'] = $id;
- if( $count )
- $args['count'] = (int) $count;
- $args['cursor'] = $page ? $page : -1; // ¸ü»»ÁËÅжϱí´ïʽ
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . ($id ? "/statuses/friends/$id.$this->type" : "/statuses/friends.$this->type");
- $request .= $qs;
- return $this->objectify( $this->process($request) );
- }
-
- function relationship($target, $source = false){
- if($target == $this->username){
- return -1;
- }
- $args = array();
- $args['target_screen_name'] = $target;
- if($source){
- $args['source_screen_name'] = $source;
- }
- $request = API_TWITTER."/1/friendships/show.$this->type".$this->_glue($args);
- return $this->objectify($this->process($request));
- }
-
- function followers( $id = false, $page = false , $count = 30 )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $args = array();
- if( $id )
- $args['id'] = $id;
- if( $count )
- $args['count'] = (int) $count;
- $args['cursor'] = $page ? $page : -1; // ¸ü»»ÁËÅжϱí´ïʽ
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . ($id ? "/statuses/followers/$id.$this->type" : "/statuses/followers.$this->type");
- $request .= $qs;
-
- return $this->objectify( $this->process($request) );
- }
-
- /****** Favorites ******/
-
- function getFavorites( $page=false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- if( $page != false )
- $qs = '?page=' . $page;
-
- $request = API_URL . '/favorites.' . $this->type . $qs;
- return $this->objectify( $this->process($request) );
- }
-
- function makeFavorite( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/favorites/create/' . $id . '.' . $this->type;
- return $this->objectify( $this->process($request, $args) );
- }
-
- function removeFavorite( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/favorites/destroy/' . $id . '.' . $this->type;
- return $this->objectify( $this->process($request, true) );
- }
-
-
- /**** Friendship Methods ****/
-
- function isFriend( $user_a, $user_b )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $args = array();
- $args['user_a'] = $user_a;
- $args['user_b'] = $user_b;
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/friendships/exists.' . $this->type . $qs;
- return $this->objectify( $this->process($request) );
- }
-
- function followUser( $id, $notifications = false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/friendships/create/' . $id . '.' . $this->type;
- if( $notifications )
- $request .= '?follow=true';
-
- return $this->objectify( $this->process($request, true) );
- }
-
- function destroyUser( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/friendships/destroy/' . $id . '.' . $this->type;
- return $this->objectify( $this->process($request, true) );
- }
-
- /****** Block Methods ******/
- function blockingList($page = false){
- $url = API_URL."/blocks/blocking.$this->type";
- if($page){
- $url .= "?page=$page";
- }
- return $this->objectify($this->process($url));
- }
-
- function blockingIDs(){
- $url = API_URL."blocks/blocking/ids.$this->type";
- return $this->objectify($this->process($url));
- }
-
- function blockUser($id)
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
- $request = API_URL . '/blocks/create/' . $id . '.' . $this->type;
- $args = array();
- $arps['post_method'] = 1;
- $result = $this->curl_process($request, $args);
- if($result->error == 'Not found'){
- return false;
- }else{
- return $result;
- }
- }
-
- function unblockUser($id)
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
- $request = API_URL . '/blocks/destroy/' . $id . '.' . $this->type;
- $args = array();
- $arps['post_method'] = 1;
- $result = $this->curl_process($request, $args);
- if($result->error == 'Not found'){
- return false;
- }else{
- return $result;
- }
- }
-
- function isBlocked($id)
- {
- $request = API_URL . '/blocks/exists/' . $id . '.' . $this->type;
- $result = $this->curl_process($request);
- if($result->error == 'Not found'){
- return "false";
- }else{
- return $result;
- }
- }
-
- /****** Trends ******/
- function trends(){
- $url = "http://search.twitter.com/trends.$this->type";
- return $this->curl_process($url);
- }
-
- /* ---------- Spam ---------- */
- function reportSpam($screen_name){
- $url = API_TWITTER."/1/report_spam.$this->type";
- $args = array();
- $args['screen_name'] = $screen_name;
- return $this->curl_process($url, $args);
- }
-
- /****** Social Graph ******/
-
- function socialGraphFollowing( $id = false)
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/friends/ids';
- if( $id )
- $request .= '/' . (int) $id . '.' . $this->type;
-
- return $this->objectify( $this->process($request) );
- }
-
- function socialGraphFollowedBy( $id = false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/followers/ids';
- if( $id )
- $request .= '/' . (int) $id . '.' . $this->type;
-
- return $this->objectify( $this->process($request) );
- }
-
-
- /****** Account Methods ******/
-
- function updateDevice( $device )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- if( !in_array( $device, array('im','sms','none') ) )
- return false;
-
- $qs = '?device=' . $device;
- $request = API_URL . '/account/update_delivery_device.' . $this->type . $qs;
- return $this->objectify( $this->process( $request ) );
- }
-
- function updateAvatar( $file )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- // Adding @ ensures the POST will be raw multipart data encoded. This MUST be a file, not a URL. Handle it outside of the class.
- $postdata = array( 'image' => "@$file");
- $request = API_URL . '/account/update_profile_image.' . $this->type;
- return $this->objectify( $this->process( $request, $postdata ) );
- }
-
- function updateBackground( $file )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- // Adding @ ensures the POST will be raw multipart data encoded. This MUST be a file, not a URL. Handle it outside of the class.
- $postdata = array( 'image' => "@$file");
- $request = API_URL . '/account/update_profile_background_image.' . $this->type;
- return $this->objectify( $this->process( $request, $postdata ) );
- }
-
- function updateProfile( $fields = array() )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $postdata = array();
- foreach( $fields as $pk => $pv ) :
- switch( $pk )
- {
- case 'name' :
- $postdata[$pk] = (string) substr( $pv, 0, 20 );
- break;
- case 'email' :
- if( preg_match( '/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $pv ) )
- $postdata[$pk] = (string) $pv;
- break;
- case 'url' :
- $postdata[$pk] = (string) substr( $pv, 0, 100 );
- break;
- case 'location' :
- $postdata[$pk] = (string) substr( $pv, 0, 30 );
- break;
- case 'description' :
- $postdata[$pk] = (string) substr( $pv, 0, 160 );
- break;
- default :
- break;
- }
-endforeach;
-
-$request = API_URL . '/account/update_profile.' . $this->type;
-return $this->objectify( $this->process( $request, $postdata ) );
- }
-
- function updateColors( $colors = array() )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $postdata = array();
- foreach( $colors as $ck => $cv ) :
- if( preg_match('/^(?:(?:[a-f\d]{3}){1,2})$/i', $hex) ) :
- $postdata[$ck] = (string) $cv;
-endif;
-endforeach;
-
-$request = API_URL . '/account/update_profile_colors.' . $this->type;
-return $this->objectify( $this->process( $request, $postdata ) );
- }
-
-
- /**** Search Method ****/
-
- function search( $q = false, $page = false, $rpp = false)
- {
- if( !$q )
- return false;
- $qs = '?q='.urlencode($q);
- if( $page )
- $qs .= '&page='.$page;
- if($rpp){
- $qs .= '&rpp='.$rpp;
- }
- $searchApiUrl = strpos(API_URL, "twitter.com") > 0 ? "http://search.twitter.com" : API_URL;
- $request = $searchApiUrl . '/search.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
- }
-
- /**** List Method ****/
-
- function createdLists( $username = '', $cursor = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $args = array();
- if( $cursor )
- $args['cursor'] = $cursor;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/' . $username . '/lists.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
-
- }
-
- function followedLists( $username = '', $cursor = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $args = array();
- if( $cursor )
- $args['cursor'] = $cursor;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/' . $username . '/lists/subscriptions.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
-
- }
-
- function beAddedLists( $username = '', $cursor = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- $args = array();
- if( $cursor )
- $args['cursor'] = $cursor;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . '/' . $username . '/lists/memberships.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
-
- }
-
- //id¸ñʽ£ºusername/listname Àý:bang590/temp ÏÂͬ
- function listStatus( $id, $page = false, $since_id = false )
- {
- if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
- return false;
-
- if (!$id) {
- return false;
- }
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $args = array();
- if( $page )
- $args['page'] = (int) $page;
- if( $since_id )
- $args['since_id'] = $since_id;
-
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/$username/lists/$listname/statuses." . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
-
- }
-
- function listInfo( $id ) {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- if (!$id) {
- return false;
- }
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $request = API_URL . "/$username/lists/$listname." . $this->type;
- return $this->objectify( $this->process($request) );
- }
-
- function isFollowedList( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $request = API_URL . "/$username/$listname/subscribers/$this->username." . $this->type;
- return $this->objectify( $this->process($request) );
- }
-
-
- function listMembers( $id, $cursor = false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $args = array();
- if( $cursor )
- $args['cursor'] = $cursor;
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/1/$username/$listname/members." . $this->type . $qs;
- return $this->objectify( $this->process($request) );
- }
-
- function listFollowers( $id, $cursor = false )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $args = array();
- if( $cursor )
- $args['cursor'] = $cursor;
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/1/$username/$listname/subscribers." . $this->type . $qs;
- return $this->objectify( $this->process($request) );
- }
-
- function followList( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $request = API_URL . "/1/$username/$listname/subscribers." . $this->type;
- return $this->objectify( $this->process($request, true) );
- }
-
- function unfollowList( $id )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $request = API_URL . "/1/$username/$listname/subscribers." . $this->type;
- return $this->objectify( $this->process($request, "DELETE") );
- }
-
- function createList( $name, $description, $isProtect)
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $mode = $isProtect ? "private" : "public";
- $args = array();
- if( $name )
- $args['name'] = $name;
- if( $description )
- $args['description'] = $description;
- if( $isProtect )
- $args['mode'] = $mode;
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/$this->username/lists." . $this->type . $qs;
-
- return $this->objectify( $this->process($request, true) );
- }
-
- function editList( $prename, $name, $description, $isProtect)
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $mode = $isProtect ? "private" : "public";
- $args = array();
- if( $name )
- $args['name'] = $name;
- if( $description )
- $args['description'] = $description;
- if( $isProtect )
- $args['mode'] = $mode;
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/$this->username/lists/$prename." . $this->type . $qs;
-
- return $this->objectify( $this->process($request, true) );
- }
-
- function deleteList( $id)
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $request = API_URL . "/$username/lists/$listname." . $this->type;
-
- return $this->objectify( $this->process($request, "DELETE") );
- }
-
-
- function deleteListMember( $id, $memberid )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $arr = explode('/', $id);
- if (count($arr) != 2) return false;
- $username = $arr[0];
- $listname = $arr[1];
-
- $args = array();
- if( $memberid )
- $args['id'] = $memberid;
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/$username/$listname/members." . $this->type . $qs;
-
- return $this->objectify( $this->process($request, "DELETE") );
- }
-
- function addListMember( $listid, $memberid )
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $args = array();
- if( $memberid )
- $args['id'] = $memberid;
- $qs = '';
- if( !empty( $args ) )
- $qs = $this->_glue( $args );
-
- $request = API_URL . "/$this->username/$listid/members." . $this->type . $qs;
- return $this->objectify( $this->process($request, true) );
- }
-
- /* ---------- Retweet ---------- */
- function getRetweeters($id, $count = false){
- $url = "http://api.twitter.com/1/statuses/retweets/$id.$this->type";
- if($count != false){
- $url .= "?count=$count";
- }
- return $this->objectify($this->process($url, $args));
- }
-
- function retweet($id){
- $url = "http://api.twitter.com/1/statuses/retweet/$id.$this->type";
- $args = array();
- $args['post_method'] = true;
- return $this->curl_process($url, $args);
- }
-
- function retweets($id, $count = false){
- $url = "http://api.twitter.com/1/statuses/retweets/id.$this->type";
- if($count){
- $url .= "?count=".($count > 100 ? 100 : $count);
- }
- return $this->curl_process($url);
- }
-
- function retweeted_by_me($page = false, $count = 20, $since_id = false, $max_id = false){
- $url = "http://api.twitter.com/1/statuses/retweeted_by_me.$this->type";
- $args = array();
- if($since_id){
- $args['since_id'] = $since_id;
- }
- if($max_id){
- $args['max_id'] = $max_id;
- }
- if($count){
- $args['count'] = $count;
- }
- if($page){
- $args['page'] = $page;
- }
- $url .= $this->_glue($args);
- return $this->curl_process($url);
- }
-
- function retweeted_to_me($page = false, $count = false, $since_id = false, $max_id = false){
- $url = "http://api.twitter.com/1/statuses/retweeted_to_me.$this->type";
- $args = array();
- if($since_id){
- $args['since_id'] = $since_id;
- }
- if($max_id){
- $args['max_id'] = $max_id;
- }
- if($count){
- $args['count'] = $count;
- }
- if($page){
- $args['page'] = $page;
- }
- $url .= $this->_glue($args);
- return $this->curl_process($url);
- }
-
- function retweets_of_me($page = false, $count = false, $since_id = false, $max_id = false){
- $url = "http://api.twitter.com/1/statuses/retweets_of_me.$this->type";
- $args = array();
- if($since_id){
- $args['since_id'] = $since_id;
- }
- if($max_id){
- $args['max_id'] = $max_id;
- }
- if($count){
- $args['count'] = $count;
- }
- if($page){
- $args['page'] = $page;
- }
- $url .= $this->_glue($args);
- return $this->curl_process($url);
- }
-
- /**** Twitese Method ****/
-
- function rank( $page = false, $count = false )
- {
- $args = array();
- if( $page )
- $args['page'] = $page;
- if( $count )
- $args['count'] = $count;
- $qs = $this->_glue( $args );
-
- $request = TWITESE_API_URL . '/rank.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
- }
-
- function browse( $page = false, $count = false )
- {
- $args = array();
- if( $page )
- $args['page'] = $page;
- if( $count )
- $args['count'] = $count;
- $qs = $this->_glue( $args );
-
- $request = TWITESE_API_URL . '/browse.' . $this->type . $qs;
-
- return $this->objectify( $this->process($request) );
- }
- /**** API Rate Limit ****/
- function ratelimit()
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
- $request = API_URL . '/account/rate_limit_status.' . $this->type;
- return $this->objectify( $this->process($request) );
- }
-
- function ratelimit_status()
- {
- return $this->ratelimit();
- }
-
- /**** Upload Photo ****/
- /****
- function twitgooUpload( $image ) {
- $postdata = array( 'media' => "@$image", 'username' => $this->username, 'password' => $this->password);
- $request = 'http://twitgoo.com/api/upload';
- $this->type = 'xml';
- return $this->objectify( $this->process( $request, $postdata ) );
- }
- ****/
- function imglyUpload( $image ) {
- $postdata = array( 'media' => "@$image", 'username' => $this->username, 'password' => $this->password);
- $request = 'http://img.ly/api/upload';
- $this->type = 'xml';
- $this->ssl_mode = 1;
- return $this->objectify( $this->process( $request, $postdata ) );
- }
-
- /****** Tests ******/
-
- function twitterAvailable()
- {
- if( !in_array( $this->type, array( 'xml','json' ) ) )
- return false;
-
- $request = API_URL . '/help/test.' . $this->type;
- if( $this->objectify( $this->process($request) ) == 'ok' )
- return true;
-
- return false;
- }
-
-
- /**** request method ****/
- function process($url,$postargs=false,$ssl_mode=0)
- {
- if ($this->debug) {
- echo $url;
- }
- $url = ( $this->suppress_response_code ) ? $url . '&suppress_response_code=true' : $url;
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
-
- if($postargs !== false)
- {
- curl_setopt ($ch, CURLOPT_POST, true);
- curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
- if ($postargs === "DELETE") {
- curl_setopt ($ch, CURLOPT_POSTFIELDS, "_method=DELETE");
- }
- }
-
-
- if($this->username !== false && $this->password !== false)
- curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password );
-
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- // curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl_mode);
-
- $response = curl_exec($ch);
-
- $this->responseInfo=curl_getinfo($ch);
- curl_close($ch);
- if(intval($this->responseInfo['http_code'] ) == 200)
- return $response;
- else
- return false;
- }
-
- function curl_process($url, $postargs = false)
- {
- $url = ( $this->suppress_response_code ) ? $url . '&suppress_response_code=true' : $url;
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array("Expect:"));
-
- if($postargs !== false)
- {
- if(isset($postargs['post_method'])){
- curl_setopt ($ch, CURLOPT_POST, true);
- }else{
- curl_setopt ($ch, CURLOPT_POST, true);
- curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
- if ($postargs === "DELETE") {
- curl_setopt ($ch, CURLOPT_POSTFIELDS, "_method=DELETE");
- }
- }
- }
-
- if($this->username !== false && $this->password !== false)
- curl_setopt($ch, CURLOPT_USERPWD, $this->username.':'.$this->password );
-
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
- curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-
- $response = curl_exec($ch);
-
- $this->responseInfo = curl_getinfo($ch);
- curl_close($ch);
-
- if($response === false){
- return false;
- }
- if($this->type == 'xml'){
- return @simplexml_load_string($response);
- }else if($this->type == 'json'){
- return @json_decode($response);
- }
- }
-
- // Ôö¼Ó $api_type ²ÎÊý
- function objectify( $data )
- {
- if($date === false){
- return;
- }
- if( $this->type == 'json' ) {
- $result = @json_decode( $data );
- if ($this->debug) {
- echo '<pre>';
- print_r($result);
- echo '</pre>';
- }
- if (isset($result->error)) {
- if (substr_count($result->request, 'user_timeline') && $result->error == 'Not authorized') {
- return 'protected';
- }
- return false;
- }
- else return $result;
- }else if( $this->type == 'xml' ){
- if( function_exists('simplexml_load_string') ) {
- $obj = @simplexml_load_string( $data );
- }
- if ($this->debug) {
- echo '<pre>';
- print_r($obj);
- echo '</pre>';
- }
- if (isset($obj->error) || !$obj) return false;
- else return $obj;
- }
- else
- return false;
- }
-
- function arrToStr($postargs) {
- $post_str = '';
- foreach ($postargs as $key=>$value) {
- $post_str .= $key . "=" . $value . "&";
- }
- $post_str = substr($post_str, 0,-1);
- return $post_str;
- }
-
- function _glue( $array )
- {
- $query_string = '';
- foreach( $array as $key => $val ) :
- $query_string .= $key . '=' . rawurlencode( $val ) . '&';
-endforeach;
-
-return '?' . substr( $query_string, 0, strlen( $query_string )-1 );
- }
-}
-?>