-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.twitter.php
867 lines (734 loc) · 26.7 KB
/
class.twitter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
<?php
/**
* Wrapper class around the Twitter API for PHP
* Based on the class originally developed by David Billingham
* and accessible at http://twitter.slawcup.com/twitter.class.phps
* @author David Billingham <david@slawcup.com>
* @author Aaron Brazell <aaron@technosailor.com>
* @author Keith Casey <caseysoftware@gmail.com>
* @version 1.1
* @package php-twitter
* @subpackage classes
*/
class twitter{
/**
* Authenticating Twitter user
* @var string
*/
var $username='';
/**
* Autenticating Twitter user password
* @var string
*/
var $password='';
/**
* Recommend setting a user-agent so Twitter knows how to contact you inc case of abuse. Include your email
* @var string
*/
var $user_agent='Twit2Busch';
/**
* Can be set to JSON (requires PHP 5.2 or the json pecl module) or XML - json|xml
* @var string
*/
var $type='json';
/**
* It is unclear if Twitter header preferences are standardized, but I would suggest using them.
* More discussion at http://tinyurl.com/3xtx66
* @var array
*/
var $headers=array('Expect:', 'X-Twitter-Client: ','X-Twitter-Client-Version: ','X-Twitter-Client-URL: ');
/**
* @var array
*/
var $responseInfo=array();
/**
* @var boolean
*/
var $suppress_response_code = false;
/**
* @var boolean
*/
var $debug = false;
function twitter()
{
// Nothing
}
/****** Statuses ******/
/**
* Send a status update to Twitter.
* @param string $status total length of the status update must be 140 chars or less.
* @return string|boolean
*/
function update( $status, $replying_to = false )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/statuses/update.' . $this->type;
//$status = $this->shorturl($status);
$postargs = array( 'status' => $status );
if( $replying_to )
$postargs['in_reply_to_status_id'] = (int) $replying_to;
return $this->objectify( $this->process($request, $postargs) );
}
/**
* Get @ replies
* @param integer Optional. Paging of tweets. Number specifies which page of results
* @param string $since (HTTP-formatted date) Optional. Narrows the resulting list of direct messages to just those sent after the specified date.
* @param integer $since_id Optional. Returns results posted that have an ID greater than $since_id
* @return string
**/
function getReplies( $page = false, $since = 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 )
$args['since'] = (string) $since;
if( $since_id )
$args['since_id'] = (int) $since_id;
$qs = '';
if( !empty( $args ) )
$qs = $this->_glue( $args );
$request = 'http://twitter.com/statuses/replies.' . $this->type . $qs;
return $this->objectify( $this->process( $request ) );
}
/**
* Destroy a tweet
* @param integer $id Required.
* @return string
**/
function deleteStatus( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/statuses/destroy/' . (int) $id . '.' . $this->type;
return $this->objectify( $this->process( $request, true ) );
}
/**
* Send an unauthenticated request to Twitter for the public timeline.
* Returns the last 20 updates by default
* @param boolean|integer $sinceid Returns only public statuses with an ID greater of $sinceid
* @return string
*/
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 = 'http://twitter.com/statuses/public_timeline.' . $this->type . $qs;
return $this->objectify( $this->process($request) );
}
/**
* Send an authenticated request to Twitter for the timeline of authenticating user.
* Returns the last 20 updates by default
* @param boolean|integer $id Specifies the ID or screen name of the user for whom to return the friends_timeline. (set to false if you want to use authenticated user).
* @param boolean|integer $since Narrows the returned results to just those statuses created after the specified date.
* @deprecated integer $count. As of July 7 2008, Twitter has requested the limitation of the count keyword. Therefore, we deprecate
* @return string
*/
function userTimeline($id=false,$count=20,$since=false,$since_id=false,$page=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 )
$args['since'] = (string) $since;
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 = 'http://twitter.com/statuses/user_timeline.' . $this->type . $qs;
else
$request = 'http://twitter.com/statuses/user_timeline/' . rawurlencode($id) . '.' . $this->type . $qs;
return $this->objectify( $this->process($request) );
}
/**
* Returns a single status, specified by the id parameter below. The status's author will be returned inline.
* @param integer $id The id number of the tweet to be returned.
* @return string
*/
function showStatus( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/statuses/show/'.intval($id) . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/**
* Returns the authenticating user's friends, each with current status inline. It's also possible to request another user's friends list via the id parameter below.
* @param integer|string $id Optional. The user ID or name of the Twitter user to query.
* @param integer $page Optional.
* @return string
*/
function friends( $id = false, $page = false )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$args = array();
if( $id )
$args['id'] = $page;
if( $page )
$args['page'] = (int) $page;
$qs = '';
if( !empty( $args ) )
$qs = $this->_glue( $args );
$request = ( $id ) ? 'http://twitter.com/statuses/friends/' . $id . '.' . $this->type . $qs : 'http://twitter.com/statuses/friends.' . $this->type . $qs;
return $this->objectify( $this->process($request) );
}
/**
* Returns the authenticating user's followers, each with current status inline.
* @param integer $page Optional.
* @return string
*/
function followers( $page = false )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/statuses/followers.' . $this->type;
if( $page )
$request .= '?page=' . (int) $page;
return $this->objectify( $this->process($request) );
}
/****** Favorites ******/
/**
* Retrieves favorited tweets
* @param integer|string $id Required. The username or ID of the user to be fetched
* @param integer $page Optional. Tweets are returned in 20 tweet blocks. This int refers to the page/block
* @return string
*/
function getFavorites( $id, $page=false )
{
if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
return false;
if( $page != false )
$qs = '?page=' . $page;
$request = 'http://twitter.com/favorites.' . $this->type . $qs;
return $this->objectify( $this->process($request) );
}
/**
* Favorites a tweet
* @param integer $id Required. The ID number of a tweet to be added to the authenticated user favorites
* @return string
*/
function makeFavorite( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/favorites/create/' . $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/**
* Unfavorites a tweet
* @param integer $id Required. The ID number of a tweet to be removed to the authenticated user favorites
* @return string
*/
function removeFavorite( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/favorites/destroy/' . $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/****** Friendships ******/
/**
* Checks to see if a friendship already exists
* @param string|integer $user_a Required. The username or ID of a Twitter user
* @param string|integer $user_b Required. The username or ID of a Twitter user
* @return string
*/
function isFriend( $user_a, $user_b )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$qs = '?user_a=' . rawurlencode( $user_a ) . '&' . rawurlencode( $user_b );
$request = 'http://twitter.com/friendships/exists.' . $this->type . $qs;
return $this->objectify( $this->process($request) );
}
/**
* Sends a request to follow a user specified by ID
* @param integer|string $id The twitter ID or screenname of the user to follow
* @param boolean $notifications Optional. If true, you will recieve notifications from the users updates
* @return string
*/
function followUser( $id, $notifications = false )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/friendships/create/' . (int) $id . '.' . $this->type;
if( $notifications )
$request .= '?follow=true';
return $this->objectify( $this->process($request) );
}
/**
* Unfollows a user
* @param integer|string $id the username or ID of a person you want to unfollow
* @return string
*/
function leaveUser( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/friendships/destroy/' . $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/****** Blocks ******/
/**
* Blocks a user
* @param integer|string $id the username or ID of a person you want to block
* @return string
*/
function blockUser( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/blocks/create/' . $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/**
* Unblocks a user
* @param integer|string $id the username or ID of a person you want to unblock
* @return string
*/
function unblockUser()
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/blocks/destroy/' . $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/****** Social Graph ******/
/**
* Returns a list of IDs of all friends for the specified user
* @param integer $id Required. User ID to request list of friend IDs for
* return string
*/
/* @todo same as friends()? */
function socialGraphFollowing( $id = false)
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/friends/ids';
if( $id )
$request .= '/' . (int) $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/**
* Returns a list of IDs of all followers for the specified user
* @param integer $id Required. User ID to request list of friend IDs for
* return string
*/
/* @todo same as followers() */
function socialGraphFollowedBy( $id = false )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/followers/ids';
if( $id )
$request .= '/' . (int) $id . '.' . $this->type;
return $this->objectify( $this->process($request) );
}
/****** Users ******/
/**
* Returns extended information of a given user, specified by ID or screen name as per the required
* id parameter below. This information includes design settings, so third party developers can theme
* their widgets according to a given user's preferences.
* @param integer $id Optional. The user ID.
* @param string $email Optional. The email address of the user being requested (can use in place of $id)
* @param integer $user_id Optional. The user ID (can use in place of $id)
* @param string $screen_name Optional. The screen name of the user being requested (can use in place of $id)
* @return string
*/
function showUser( $id, $email = false, $user_id = false, $screen_name=false )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
if( $user_id ) :
$qs = '?user_id=' . (int) $user_id;
elseif ( $screen_name ) :
$qs = '?screen_name=' . (string) $screen_name;
elseif ( $email ) :
$qs = '?email=' . (string) $email;
else :
$qs = (int) $id;
endif;
$request = 'http://twitter.com/users/show/' . $qs . $this->type;
return $this->objectify( $this->process($request) );
}
/****** Direct Messages ******/
/**
* Returns a list of the direct messages sent to the authenticating user.
* @param string $since (HTTP-formatted date) Optional. Narrows the resulting list of direct messages to just those sent after the specified date.
* @param int $count DEPRECATED. Remains for Backwards Compat
* @param integer $since_id
* @param integer $page
* @deprecated $count
* @return string
*/
function directMessages( $since = false, $count = null, $since_id = false, $page = false )
{
if( !in_array( $this->type, array( 'xml','json','rss','atom' ) ) )
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 = 'http://twitter.com/direct_messages.' . $this->type . implode( '&', $qsparams );
return $this->objectify( $this->process($request) );
}
/**
* Returns a list of the sent direct messages from the authenticating user.
* @param string $since (HTTP-formatted date) Optional. Narrows the resulting list of direct messages to just those sent after the specified date.
* @param integer $since_id
* @param integer $page
* @deprecated $count
* @return string
*/
function sentDirectMessage( $since = false, $since_id = false, $page = 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 = 'http://twitter.com/direct_messages/sent.' . $this->type . implode( '&', $qsparams );
return $this->objectify( $this->process($request) );
}
/**
* Sends a new direct message to the specified user from the authenticating user. Requires both the user
* and text parameters below.
* @param string|integer Required. The ID or screen name of the recipient user.
* @param string $user The text of your direct message. Be sure to URL encode as necessary, and keep it under 140 characters.
* @return string
*/
function sendDirectMessage( $user, $text )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/direct_messages/new.' . $this->type;
$postargs = 'user=' . rawurlencode($user) . '&text=' . rawurlencode($text);
return $this->objectify( $this->process($request, $postargs) );
}
/**
* Deletes a direct message
* @param integer $id Required
* @return string
*/
function deleteDirectMessage( $id )
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/direct_messages/destroy/' . (int) $id . '.' . $this->type;
return $this->objectify( $this->process( $request ) );
}
/****** Account ******/
/**
* Updates delivery device
* @param string $device Required. Must be of type 'im', 'sms' or 'none'
* @return string
*/
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 = 'http://twitter.com/account/update_delivery_device.' . $this->type . $qs;
return $this->objectify( $this->process( $request ) );
}
/**
* @param binary Required. Use your script to pass a binary image (GIF, JPG, PNG <700kb) to update Twitter profile avatar
* @return string
*/
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 = 'http://twitter.com/account/update_profile_image.' . $this->type;
return $this->objectify( $this->process( $request, $postdata ) );
}
/**
* @param binary Required. Use your script to pass a binary image (GIF, JPG, PNG <800kb) to update Twitter profile avatar. Images over 2048px wide will be scaled down
* @return string
*/
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 = 'http://twitter.com/account/update_profile_background_image.' . $this->type;
return $this->objectify( $this->process( $request, $postdata ) );
}
/**
* @param array Requires. Pass an array of all optional members: name, email, url, location, or description. Email address must be valid if passed. Refer to Twitter RESTful API instructions on length allowed for other members
* @return string
*/
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 = 'http://twitter.com/account/update_profile.' . $this->type;
return $this->objectify( $this->process( $request, $postdata ) );
}
/**
* Pass an array of values to Twitter to update Twitter profile colors
* @param array Required. All array members are optional. Optional color fields are: profile_background_color, profile_text_color, profile_link_color, profile_sidebar_fill_color, profile_sidebar_border_color
* @return string
*/
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 = 'http://twitter.com/account/update_profile_colors.' . $this->type;
return $this->objectify( $this->process( $request, $postdata ) );
}
/**
* Rate Limit API Call. Sometimes Twitter needs to degrade. Use this non-ratelimited API call to work your logic out
* @return integer|boolean
*/
function ratelimit()
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/account/rate_limit_status.' . $this->type;
return $this->objectify( $out );
}
/**
* Rate Limit statuses (extended). Provides helper data like remaining-hits, hourly limit, reset time and reset time in seconds
* @deprecated
*/
function ratelimit_status()
{
return $this->ratelimit();
}
/****** Tests ******/
/**
* Detects if Twitter is up or down. Chances are, it will be down. ;-) Here's a hint - display CPM ads whenever Twitter is down
* @return boolean
*/
function twitterAvailable()
{
if( !in_array( $this->type, array( 'xml','json' ) ) )
return false;
$request = 'http://twitter.com/help/test.' . $this->type;
if( $this->objectify( $this->process($request) ) == 'ok' )
return true;
return false;
}
/**
* Any prescheduled maintenance?
* @deprecated
* @return false
*/
function maintenanceSchedule()
{
return false;
}
/****** Private and Helpers Methods ******/
/**
* Uses the http://is.gd API to produce a shortened URL. Pluggable by extending the twitter class
* @param string $url The URL needing to be shortened
* @return string
*/
function shorturl( $url )
{
// Using is.gd because it's good
$request = 'http://is.gd/api.php?longurl=' . $url;
return $this->process( $request );
}
/**
* Internal function where all the juicy curl fun takes place
* this should not be called by anything external unless you are
* doing something else completely then knock youself out.
* @access private
* @param string $url Required. API URL to request
* @param string $postargs Optional. Urlencoded query string to append to the $url
*/
function process($url,$postargs=false)
{
$url = ( $this->suppress_response_code ) ? $url . '&suppress_response_code=true' : $url;
$ch = curl_init($url);
if($postargs !== false)
{
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postargs);
}
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_NOBODY, 0);
if( $this->debug ) :
curl_setopt($ch, CURLOPT_HEADER, true);
else :
curl_setopt($ch, CURLOPT_HEADER, false);
endif;
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
$response = curl_exec($ch);
$this->responseInfo=curl_getinfo($ch);
curl_close($ch);
if( $this->debug ) :
$debug = preg_split("#\n\s*\n|\r\n\s*\r\n#m", $response);
echo'<pre>' . $debug[0] . '</pre>'; exit;
endif;
if( intval( $this->responseInfo['http_code'] ) == 200 )
return $response;
else
return false;
}
/***DEPRECATED***/
/**
* Returns a list of the users currently featured on the site with their current statuses inline.
* @deprecated
* @return string
*/
function featured()
{
return false;
}
/**
* Updates Geo location
* @deprecated
* @param string $location Required.
* @return string
*/
function updateLocation( $location )
{
return $this->updateProfile( array( 'location' => $location ) );
}
/**
* Send an authenticated request to Twitter for the timeline of authenticating users friends.
* Returns the last 20 updates by default
* @deprecated true
* @param boolean|integer $id Specifies the ID or screen name of the user for whom to return the friends_timeline. (set to false if you want to use authenticated user).
* @param boolean|integer $since Narrows the returned results to just those statuses created after the specified date.
* @return string
*/
function friendsTimeline( $id = false, $since = false, $since_id = false, $count = 20, $page = false )
{
return $this->userTimeline( $id, $count, $since, $since_id, $page );
}
/**
* Function to prepare data for return to client
* @access private
* @param string $data
*/
function objectify( $data )
{
if( $this->type == 'json' )
return json_decode( $data );
else if( $this->type == 'xml' )
{
if( function_exists('simplexml_load_string') ) :
$obj = simplexml_load_string( $data );
endif;
return $obj;
}
else
return false;
}
/**
* Function to piece together a cohesive query string
* @access private
* @param array $array
* @return string
*/
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 );
}
}
/**
* Wrapper class around the Twitter Search (formerly, and affectionately known as Summize)
* @author Aaron Brazell <aaron@technosailor.com>
* @author Keith Casey <caseysoftware@gmail.com>
* @version 1.1
* @package php-twitter
* @subpackage classes
*/
class summize extends twitter
{
/**
* Can be set to JSON (requires PHP 5.2 or the json pecl module) or Atom - json|atom
* @var string
*/
var $stype='json';
function search( $terms=false, $callback=false )
{
if( !$terms )
return false;
$qs = array();
$request = 'http://search.twitter.com/search.' . $this->stype;
$qs[] = 'q=' . rawurlencode( $terms );
if( $callback && $this->stype == 'json' )
$qs[] = 'callback=' . $callback;
return $this->objectify( $this->process($request . '?' . implode('&',$qs) ) );
}
function trends( $callback = false )
{
$qs = ( $callback ) ? '?callback=' . $callback : '';
$request = 'http://search.twitter.com/trends.' . $this->stype . $qs;
return $this->objectify( $this->process( $request ) );
}
}
?>