OSDN Git Service

xctcc/embrr
[embrj/master.git] / lib / twitteroauth.php
1 <?php
2 /*
3  * Abraham Williams (abraham@abrah.am) http://abrah.am
4  *
5  * Basic lib to work with Twitter's OAuth beta. This is untested and should not
6  * be used in production code. Twitter's beta could change at anytime.
7  *
8  * Code based on:
9  * Fire Eagle code - http://github.com/myelin/fireeagle-php-lib
10  * twitterlibphp - http://github.com/jdp/twitterlibphp
11  */
12
13 /* API Settings
14  *
15  * These are the URLs embrr use for all API calls,
16  * DO NOT change unless you know what you're doing!
17  */
18 define('API_URL', 'https://api.twitter.com/1.1');
19 define('UPLOAD_URL', 'https://upload.twitter.com/1.1');
20
21 /**
22  * Twitter OAuth class
23  */
24 class TwitterOAuth {
25         /* Contains the last HTTP status code returned */
26         public $http_code;
27         /* Contains the last API call */
28         public $last_api_call;
29         /* Set up the API root URL */
30         public $host = API_URL;
31         /* Set timeout default */
32         public $timeout = 5;
33         /* Set connect timeout */
34         public $connecttimeout = 30;
35         /* Verify SSL Cert */
36         public $ssl_verifypeer = FALSE;
37
38         public $source = 'embr';
39
40         // user info
41         public $username;
42         public $screen_name;
43         public $user_id;
44         
45         //for debug use
46         public $curl_info;
47         public $http_header;
48
49         /**
50          * Set API URLS
51          */
52         function accessTokenURL()  { return 'https://api.twitter.com/oauth/access_token'; }
53         function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; }
54         function authorizeURL()    { return 'https://api.twitter.com/oauth/authorize'; }
55         function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; }
56
57         /**
58          * Debug helpers
59          */
60         function lastStatusCode() { return $this->http_status; }
61         function lastAPICall() { return $this->last_api_call; }
62
63         /**
64          * construct TwitterOAuth object
65          */
66         function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
67                 $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
68                 $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
69                 if (!empty($oauth_token) && !empty($oauth_token_secret)) {
70                         $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
71                         $this->screen_name = $_SESSION['access_token']['screen_name'];
72                         $this->username = $_SESSION['access_token']['screen_name'];
73                         $this->user_id = $_SESSION['access_token']['user_id'];
74                 } else {
75                         $this->token = NULL;
76                 }
77         }
78
79
80         /**
81          * Get a request_token from Twitter
82          *
83          * @returns a key/value array containing oauth_token and oauth_token_secret
84          */
85         function getRequestToken($oauth_callback = NULL) {
86                 $parameters = array();
87                 if (!empty($oauth_callback)) {
88                         $parameters['oauth_callback'] = $oauth_callback;
89                 } 
90                 $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters);
91                 $token = OAuthUtil::parse_parameters($request);
92                 $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
93                 return $token;
94         }
95
96         /**
97          * Get the authorize URL
98          *
99          * @returns a string
100          */
101         function getAuthorizeURL($token) {
102                 if (is_array($token)) {
103                         $token = $token['oauth_token'];
104                 }
105                 return $this->authorizeURL() . "?oauth_token={$token}";
106         }
107
108         /**
109          * Exchange the request token and secret for an access token and
110          * secret, to sign API calls.
111          *
112          * @returns array("oauth_token" => the access token,
113          *                "oauth_token_secret" => the access secret)
114          */
115         function getAccessToken($oauth_verifier = FALSE) {
116                 $parameters = array();
117                 if (!empty($oauth_verifier)) {
118                         $parameters['oauth_verifier'] = $oauth_verifier;
119                 }
120                 $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
121                 $token = OAuthUtil::parse_parameters($request);
122                 $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
123                 return $token;
124         }
125
126         /**
127          * GET wrappwer for oAuthRequest.
128          */
129         function get($url, $parameters = array(), $host=NULL) {
130                 $response = $this->oAuthRequest($url, 'GET', $parameters, NULL, $host);
131                 if($response == false){
132                         return false;
133                 }
134                 return json_decode($response);
135         }
136
137         /**
138          * POST wreapper for oAuthRequest.
139          */
140         function post($url, $parameters = array(), $multipart = NULL, $host = NULL) {
141                 $response = $this->oAuthRequest($url, 'POST', $parameters, $multipart, $host);
142                 if($response === false){
143                         return false;
144                 }
145                 return json_decode($response);
146         }
147
148         /**
149          * Format and sign an OAuth / API request, then make an HTTP request
150          */
151         function oAuthRequest($url, $method, $parameters, $multipart=NULL, $host=NULL) {
152                 if ($url[0] == '/') { //non-twitter.com api shall offer the entire url.
153                         if ($host == NULL) {
154                                 $host = $this->host;
155                         }
156                         $url = "{$host}{$url}.json";
157                 }
158                 $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters);
159                 $request->sign_request($this->sha1_method, $this->consumer, $this->token);
160                 $request->set_http_header($multipart);
161                 
162                 $ci = curl_init();
163                 /* Curl settings */
164                 curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
165                 curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
166                 curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
167                 curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
168
169                 switch ($method) {
170                 case 'GET':
171                         curl_setopt($ci, CURLOPT_URL, $request->to_url());
172                         curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
173                         break;
174                 case 'POST':
175                         $postfields = $multipart ? $multipart : $request->to_postdata();
176                         curl_setopt($ci, CURLOPT_URL, $request->get_normalized_http_url());
177                         curl_setopt($ci, CURLOPT_HTTPHEADER, $request->http_header);
178                         curl_setopt($ci, CURLOPT_POST, TRUE);
179                         if (!empty($postfields)) {
180                                 curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
181                         }
182                 }
183
184                 $response = curl_exec($ci);
185                 $this->http_header = $request->http_header;
186                 $this->curl_info = curl_getinfo($ci);
187                 $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
188                 $this->last_api_call = curl_getinfo($ci, CURLINFO_EFFECTIVE_URL);
189                 
190                 curl_close ($ci);
191                 
192                 return $response;
193         }
194         
195
196         /* ---------- API METHODS ---------- */
197         /*                                   */
198         /* ---------- Block ---------- */
199         function mutesList($cursor=-1, $skip_status = true){
200                 $url = '/mutes/users/list';
201                 $args = array();
202                 if($cursor)
203                         $args['cursor'] = $cursor;
204                 $args['skip_status'] = $skip_status;
205                 return $this->get($url, $args);
206         }
207
208         function blockingList($id, $cursor=-1, $skip_status = true){
209                 $url = '/blocks/list';
210                 $args = array();
211                 if($id)
212                         $args['screen_name'] = $id;
213                 if($cursor)
214                         $args['cursor'] = $cursor;
215                 $args['skip_status'] = $skip_status;
216                 return $this->get($url, $args);
217         }
218
219         function blockUser($id){
220                 $url = "/blocks/create";
221                 $args = array();
222                 $args['screen_name'] = $id;
223                 return $this->post($url, $args);
224         }
225
226         function unblockUser($id){
227                 $url = "/blocks/destroy";
228                 $args = array();
229                 $args['screen_name'] = $id;
230                 return $this->post($url, $args);
231         }
232
233         /* ---------- Messages ---------- */
234         function deleteDirectMessage($id){
235                 $url = "/direct_messages/destroy";
236                 $args = array();
237                 $args['id'] = $id;
238                 return $this->post($url, $args);
239         }
240
241         function directMessages($since_id = false, $max_id = false, $count = false, $include_entities = true){
242                 $url = '/direct_messages';
243                 $args = array();
244                 if( $since_id )
245                         $args['since_id'] = $since_id;
246                 if( $max_id )
247                         $args['max_id'] = $max_id;
248                 if( $count )
249                         $args['count'] = $count;
250                 if($include_entities)
251                         $args['include_entities'] = $include_entities;
252                 return $this->get($url, $args);
253         }
254
255         function newDirectMessage($id = false, $message = false){ //TODO: Use this to send DMs
256                 $url = '/direct_messages/new';
257                 $args = array();
258                 if ($id)
259                         $args['screen_name'] = $id;
260                 if ($message)
261                         $args['text'] = $message;
262                 return $this->post($url, $args);
263         }
264
265         function sentDirectMessages($since_id = false, $max_id = false, $count = false, $include_entities = true){
266                 $url = '/direct_messages/sent';
267                 $args = array();
268                 if($since_id)
269                         $args['since_id'] = $since_id;
270                 if( $max_id )
271                         $args['max_id'] = $max_id;
272                 if( $count )
273                         $args['count'] = $count;
274                 if($include_entities)
275                         $args['include_entities'] = $include_entities;
276                 return $this->get($url, $args);
277         }
278
279         /* ---------- List ---------- */
280         function addListMember($listid, $id, $memberid){
281                 $url = "/lists/members/create_all";
282                 $args = array();
283                 if($listid)
284                         $args['slug'] = $listid;
285                 if($id)
286                         $args['owner_screen_name'] = $id;
287                 if($memberid){
288                         $args['screen_name'] = $memberid;
289                 }
290                 return $this->post($url, $args);
291         }
292
293         function beAddedLists($username = '', $cursor = false){
294                 $url = "/lists/memberships";
295                 $args = array();
296                 if($username)
297                         $args['screen_name'] = $username;
298                 if($cursor){
299                         $args['cursor'] = $cursor;
300                 }
301                 return $this->get($url, $args);
302         }
303
304         function createList($name, $description, $isPortect){
305                 $url = "/lists/create";
306                 $args = array();
307                 if($name)
308                         $args['name'] = $name;
309                 if($description)
310                         $args['description'] = $description;
311                 if($isProtect)
312                         $args['mode'] = 'private';
313                 
314                 return $this->post($url, $args);
315         }
316
317         function myLists($username = false, $user_id = false, $count = false){
318                 $url = "/lists/ownerships";
319                 $args = array();
320                 if($username){
321                         $args['screen_name'] = $username;
322                 } else {
323                         $args['screen_name'] = $this->username;
324                 }
325                 
326                 return $this->get($url, $args);
327         }
328
329         function deleteList($slug){
330                 $url = "/lists/destroy";
331                 $args = array();
332                 $args['slug'] = $slug;
333                 $args['owner_screen_name'] = $this->username;
334                 return $this->post($url, $args);
335         }
336
337         function deleteListMember($slug, $owner, $memberid){
338                 $url = "/lists/members/destroy_all";
339                 $args = array();
340                 $args['slug'] = $slug;
341                 $args['owner_screen_name'] = $owner;
342                 $args['user_id'] = $memberid;
343                 
344                 return $this->post($url, $args);
345         }
346
347         function editList($prename, $name, $description, $isProtect){
348                 $url = "/lists/update";
349                 $args = array();
350                 if($prename)
351                         $args['slug'] = $prename;
352                 if($name)
353                         $args['name'] = $name;
354                 if($description)
355                         $args['description'] = $description;
356                 if($isProtect)
357                         $args['mode'] = "private";
358                 return $this->post($url, $args);
359         }
360
361         function followedLists($username = '', $cursor = false){
362                 $url = "/lists/subscriptions";
363                 $args = array();
364                 if($username)
365                         $args['screen_name'] = $username;
366                 if($cursor)
367                         $args['cursor'] = $cursor;
368                 return $this->get($url, $args);
369         }
370
371         function followList($id){
372                 $url = "/lists/subscribers/create";
373                 $arr = explode("/", $id);
374                 $args = array();
375                 $args['slug'] = $arr[1];
376                 $args['owner_screen_name'] = $arr[0];
377                 return $this->post($url, $args);
378         }
379
380         function isFollowedList($id){
381                 $url = "/lists/subscribers/show";
382                 $arr = explode('/', $id);
383                 $args = array();
384                 $args['owner_screen_name'] = $arr[0];
385                 $args['slug'] = $arr[1];
386                 $args['screen_name'] = $this->username;
387                 return isset($this->get($url, $args)->screen_name);
388         }
389
390         function listFollowers($id, $cursor = false, $skip_status = true){
391                 $url = "/lists/subscribers";
392                 $arr = explode('/', $id);
393                 $args = array();
394                 $args['slug'] = $arr[1];
395                 $args['owner_screen_name'] = $arr[0];
396                 if($cursor){
397                         $args['cursor'] = $cursor;
398                 }
399                 $args['skip_status'] = $skip_status;
400                 return $this->get($url, $args);
401         }
402
403         function listInfo($id){
404                 $arr = explode('/', $id);
405                 $url = "/lists/show";
406                 $args = array();
407                 $args['slug'] = $arr[1];
408                 $args['owner_screen_name'] = $arr[0];
409                 return $this->get($url, $args);
410         }
411
412         function listMembers($id, $cursor = false, $skip_status = true){
413                 $url = "/lists/members";
414                 $arr = explode("/", $id);
415                 $args = array();
416                 $args['slug'] = $arr[1];
417                 $args['owner_screen_name'] = $arr[0];
418                 if($cursor){
419                         $args['cursor'] = $cursor;
420                 }
421                 $args['skip_status'] = $skip_status;
422                 return $this->get($url, $args);
423
424         }
425
426         function listStatus($id, $since_id = false, $max_id = false, $include_rts = true, $include_entities = true){
427                 $arr = explode('/', $id);
428                 $url = "/lists/statuses";
429                 $args = array();
430                 $args['slug'] = $arr[1];
431                 $args['owner_screen_name'] = $arr[0];
432                 if($since_id)
433                         $args['since_id'] = $since_id;
434                 if($max_id)
435                         $args['max_id'] = $max_id;
436                 if($include_rts)
437                         $args['include_rts'] = $include_rts;
438                 if($include_entities)
439                         $args['include_entities'] = $include_entities;
440                 return $this->get($url, $args);
441         }
442
443         function unfollowList($id){
444                 $url = "/lists/subscribers/destroy";
445                 $arr = explode("/", $id);
446                 $args = array();
447                 $args['slug'] = $arr[1];
448                 $args['owner_screen_name'] = $arr[0];
449                 return $this->post($url, $args);
450         }
451
452         /* ---------- Friendship ---------- */
453         function destroyUser($id){
454                 $url = "/friendships/destroy";
455                 $args = array();
456                 $args['screen_name'] = $id;
457                 return $this->post($url, $args);
458         }
459
460         function followers($id = false, $cursor = -1, $skip_status = true){ // GET statuses/friends is removed, try GET followers/list instead
461                 $url = '/followers/list';
462                 $args = array();
463                 if( $id )
464                         $args['screen_name'] = $id;
465                 if($cursor)
466                         $args['cursor'] = $cursor;
467                 $args['skip_status'] = $skip_status;
468                 return $this->get($url, $args);
469         }
470
471         function followUser($id, $notifications = false){
472                 $url = "/friendships/create";
473                 $args = array();
474                 $args['screen_name'] = $id;
475                 if($notifications)
476                         $args['follow'] = true;
477                 return $this->post($url, $args);
478         }
479
480         function friends($id = false, $cursor = -1, $skip_status = true){ // GET statuses/friends is removed, try GET friends/list instead
481                 $url = '/friends/list';
482                 $args = array();
483                 if( $id )
484                         $args['screen_name'] = $id;
485                 if($cursor)
486                         $args['cursor'] = $cursor;
487                 $args['skip_status'] = $skip_status;
488                 return $this->get($url, $args);
489         }
490         
491         function relationship($target_screen_name, $source_screen_name = false){
492                 $url = '/friendships/show';
493                 $args = array();
494                 $args['target_screen_name'] = $target_screen_name;
495                 $args['source_screen_name'] = $source_screen_name ? $source_screen_name : $this->username;
496                 return $this->get($url, $args);
497         }
498
499         function showUser($screen_name = false, $user_id = false, $include_entities = true){
500                 $url = '/users/show';
501                 $args = array();
502                 if($screen_name)
503                         $args['screen_name'] = $screen_name;
504                 else
505                         $args['user_id'] = $user_id ? $user_id : $this->user_id;
506                 return $this->get($url, $args);
507         }
508
509         function muteUser($screen_name){
510                 $url = "/mutes/users/create";
511                 $args = array();
512                 $args['screen_name'] = $screen_name;
513                 return $this->post($url, $args);
514         }
515
516         function unmuteUser($screen_name){
517                 $url = "/mutes/users/destroy";
518                 $args = array();
519                 $args['screen_name'] = $screen_name;
520                 return $this->post($url, $args);
521         }
522
523         /* ---------- Ratelimit ---------- */
524         /* this API changed a lot due to the
525          * update of twitter's limit policy,
526          * get only status limits here by
527          * default                        */
528         function ratelimit($resources = "statuses"){
529                 $url = '/application/rate_limit_status';
530                 $args = array();
531                 $args['resources'] = $resources;
532                 return $this->get($url, $args);
533         }
534
535         /* ---------- Retweet ---------- */
536         function retweet($id){
537                 $url = "/statuses/retweet/$id";
538                 return $this->post($url);
539         }
540
541         function retweets($id, $count = 20){
542                 if($count > 100){
543                         $count = 100;
544                 }
545                 $url = "/statuses/retweets/$id";
546                 $args = array();
547                 $args['count'] = $count;
548                 return $this->get($url,$args);
549         }
550
551         function retweets_of_me($count = false, $since_id = false, $max_id = false, $include_entities = true){
552                 $url = '/statuses/retweets_of_me';
553                 $args = array();
554                 if($since_id)
555                         $args['since_id'] = $since_id;
556                 if($max_id)
557                         $args['max_id'] = $max_id;
558                 if($count)
559                         $args['count'] = $count;
560                 if($include_entities)
561                         $args['include_entities'] = $include_entities;
562                 return $this->get($url, $args);
563         }
564
565         /* ---------- Search ---------- */
566         function savedSearches(){
567                 $url = '/saved_searches/list';
568                 return $this->get($url);
569         }
570
571         function deleteSavedSearch($ssid){
572                 $url = "/saved_searches/destroy/{$ssid}";
573                 return $this->post($url);
574         }
575
576         function saveSearch($query){
577                 $url = "/saved_searches/create";
578                 $args = array();
579                 $args['query'] = $query;
580                 return $this->post($url, $args);
581         }
582
583         function search($q = false, $since_id = false, $max_id = false, $include_entities = true){
584                 $url = '/search/tweets';
585                 if(!$q) {
586                         return false;
587                 } else {
588                         $args = array();
589                         $args['q'] = $q;
590                 }
591                 if($since_id){
592                         $args['since_id'] = $since_id;
593                 }
594                 if($max_id){
595                         $args['max_id'] = $max_id;
596                 }
597                 if($include_entities){
598                         $args['include_entities'] = $include_entities;
599                 }
600                 return $this->get($url, $args);
601         }
602
603         /* ---------- Spam ---------- */
604         function reportSpam($screen_name){
605                 $url = '/users/report_spam';
606                 $args = array();
607                 $args['screen_name'] = $screen_name;
608                 return $this->post($url, $args);
609         }
610
611         /* ---------- Timeline ---------- */
612         function deleteStatus($id){
613                 $url = "/statuses/destroy/$id";
614                 return $this->post($url);
615         }
616
617         function homeTimeline($since_id = false, $max_id = false, $count = false, $include_entities = true) {
618                 $url = '/statuses/home_timeline';
619                 $args = array();
620                 if($max_id)
621                         $args['max_id'] = $max_id;
622                 if($since_id)
623                         $args['since_id'] = $since_id;
624                 if($count)
625                         $args['count'] = $count;
626                 else
627                         $args['count'] = 30;
628                 if($include_entities)
629                         $args['include_entities'] = $include_entities;
630                 return $this->get($url, $args);
631         }
632         
633         function getFavorites($userid = false, $sinceid = false, $maxid = false, $count = false, $include_entities = true){
634                 $url = '/favorites/list';
635                 $args = array();
636                 if($userid)
637                         $args['screen_name'] = $userid;
638                 if($sinceid)
639                         $args['since_id'] = $sinceid;
640                 if($maxid)
641                         $args['max_id'] = $maxid;
642                 if($count)
643                         $args['count'] = $count;
644                 if($include_entities)
645                         $args['include_entities'] = $include_entities;
646                 return $this->get($url, $args);
647         }
648
649         function makeFavorite($id){
650                 $url = "/favorites/create";
651                 $args = array();
652                 if($id)
653                         $args['id'] = $id;
654                 return $this->post($url, $args);
655         }
656
657         function removeFavorite($id){
658                 $url = "/favorites/destroy";
659                 $args = array();
660                 if($id)
661                         $args['id'] = $id;
662                 return $this->post($url, $args);
663         }
664
665         function replies($since_id = false, $max_id = false, $count = false, $include_entities = true){
666                 $url = '/statuses/mentions_timeline';
667                 $args = array();
668                 if($max_id)
669                         $args['max_id'] = $max_id;
670                 if($since_id)
671                         $args['since_id'] = $since_id;
672                 if($count)
673                         $args['count'] = $count;
674                 if($include_entities)
675                         $args['include_entities'] = $include_entities;
676                 return $this->get($url, $args);
677         }
678
679         function showStatus($id,$include_entities = true){
680                 $url = "/statuses/show";
681                 $args = array();
682                 if($id)
683                         $args['id'] = $id;
684                 if($include_entities)
685                         $args['include_entities'] = $include_entities;
686                 return $this->get($url,$args);
687         }
688
689         function update($status, $replying_to = false,$include_entities = true, $media_ids = false){
690                 try{
691                         $url = '/statuses/update';
692                         $args = array();
693                         $args['status'] = $status;
694                         if($replying_to)
695                                 $args['in_reply_to_status_id'] = $replying_to;
696                         if($include_entities)
697                                 $args['include_entities'] = $include_entities;
698                         if($media_ids)
699                                 $args['media_ids'] = $media_ids;
700                         return $this->post($url, $args);
701                 }catch(Exception $ex){
702                         echo $ex->getLine." : ".$ex->getMessage();
703                 }
704         }
705
706         function userTimeline($id = false, $since_id = false, $max_id = false, $count = false, $include_rts = true, $include_entities = true){
707                 $url = '/statuses/user_timeline';
708                 $args = array();
709                 if($max_id)
710                         $args['max_id'] = $max_id;
711                 if($id)
712                         $args['screen_name'] = $id;
713                 if($count)
714                         $args['count'] = $count;
715                 if($since_id)
716                         $args['since_id'] = $since_id;
717                 if($include_rts)
718                         $args['include_rts'] = $include_rts;
719                 if($include_entities)
720                         $args['include_entities'] = $include_entities;
721                 $response = $this->get($url, $args);
722                 return $response;
723         }
724
725         function trends_closest($lat = false, $long=false) {
726                 $url = "/trends/closest";
727                 $args = array();
728                 if ($lat)
729                         $args['lat'] = $lat;
730                 if ($long)
731                         $args['long'] = $long;
732                 return $this->get($url, $args);
733         }
734         
735         function trends_place($id = 1) {
736                 $url = "/trends/place";
737                 $args = array();
738                 if ($id)
739                         $args['id'] = $id;
740                 return $this->get($url, $args);
741         }
742         /* ---------- Misc. ---------- */
743         function veverify($skip_status = false){
744                 $url = '/account/verify_credentials';
745                 $args = array('skip_status' => $skip_status);
746                 return $this->get($url,$args);
747         }
748         
749         function updateProfile($fields = array(), $skip_status = true){
750                 $url = '/account/update_profile';
751                 $args = array();
752                 foreach( $fields as $pk => $pv ){
753                         switch( $pk ){
754                         case 'name' :
755                                 $args[$pk] = (string) substr( $pv, 0, 20 );
756                                 break;
757                         case 'url' :
758                                 $args[$pk] = (string) substr( $pv, 0, 100 );
759                                 break;
760                         case 'location' :
761                                 $args[$pk] = (string) substr( $pv, 0, 30 );
762                                 break;
763                         case 'description' :
764                                 $args[$pk] = (string) substr( $pv, 0, 160 );
765                                 break;
766                         default :
767                                 break;
768                         }
769                         $args['skip_status'] = $skip_status;
770                 }
771                 return $this->post($url, $args);
772         }
773         
774         /* media */
775         function updateProfileImage($image, $skip_status = true) {
776                 $url = '/account/update_profile_image';
777                 $args = array();
778                 if($image){
779                         $args['image']=$image;
780                         $args['skip_status']=$skip_status;
781                 }
782                 return $this->post($url, $args);
783         }
784         
785         function updateProfileBackground($image, $tile = false, $skip_status = true) {
786                 $url = '/account/update_profile_background_image';
787                 $args = array();
788                 if($image){
789                         $args['image']=$image;
790                 }
791                 if($tile){
792                         $args['tile']=($tile === 'true');
793                 }
794                 $args['skip_status']=$skip_status;
795                 return $this->post($url, $args);
796         }
797         
798         function uploadMedia($image) {
799                 $url = '/media/upload';
800                 $args = array();
801                 $mul = array();
802                 $mul['media'] = $image;
803                 return $this->post($url,$args,$mul,UPLOAD_URL);
804         }
805 }
806