/
plurk_api.php
2053 lines (1718 loc) · 57.6 KB
/
plurk_api.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
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* load dependencies.
*/
require('config.php');
require('constant.php');
/**
* This is a PHP Plurk API.
* @package php-plurk-api
* @category API
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://code.google.com/p/php-plurk-api
*
*/
Class plurk_api {
/**
* User name
* @var string $username
*/
protected $username;
/**
* Password
* @var string $password
*/
protected $password;
/**
* API KEY
* @var $api_key
*/
protected $api_key;
/**
* the array send to Plurk.com
* @var $post_array
*/
protected $post_array;
/**
* Login status
* @var bool $is_login
*/
protected $is_login = FALSE;
/**
* Current HTTP Status Code
* @var int $http_status
*/
protected $http_status;
/**
* Current HTTP Server Response
* @var JSON object $http_response
*/
protected $http_response;
/**
* User infomation
* @var JSON object $user_info
*/
protected $user_info;
/**
* cookie file path.
* if you must login as multi users, you need to set cookie path for each users.
* @var string $cookie_path
*/
protected $cookie_path = NULL;
/**
* log file path.
* set your custom log path.
* @var string $log_path
*/
protected $log_path = NULL;
/**
* String contains proxy host and port for CURL connection
* @var string $proxy
*/
protected $proxy = NULL;
/**
* String contains proxy authentication for CURL connection
* @var string $proxy_auth
*/
protected $proxy_auth = NULL;
/**
* The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
* @var int $connect_timeout
*/
protected $connect_timeout = 30;
/**
* The maximum number of seconds to allow cURL functions to execute.
* @var int $timeout
*/
protected $timeout = 30;
function __construct() {}
/**
* function set_log_path
* set log path
*
* @param string $log_path
*/
function set_log_path($log_path = NULL)
{
$this->log_path = $log_path;
}
/**
* funciton log
*
* @param $message
*/
function log($message = NULL, $method = NULL)
{
if( ! isset($this->log_path)) $this->log_path = PLURK_LOG_PATH;
if( ! file_exists($this->log_path)) touch($this->log_path);
$date = date("Y-m-d H:i:s");
$username = $this->username;
$array = print_r($this->post_array, TRUE);
error_log("date: $date\nmethod: $method\nusername: $username\nmessage: $message\ndata_dump: $array\n", 3, $this->log_path);
}
/**
* function plurk
* Connect to Plurk
*
* @param $url
* @param $array
* @return JSON object
*/
function plurk($url, $array)
{
$ch = curl_init();
$this->post_array = $array;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS , http_build_query($array));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, PLURK_AGENT);
if( ! isset($this->cookie_path))
$this->cookie_path = PLURK_COOKIE_PATH;
if($url == PLURK_LOGIN)
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_path);
else
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_path);
if(isset($this->proxy))
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
if(isset($this->proxy_auth))
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $this->proxy_auth);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
$response = curl_exec($ch);
$this->http_response = $response;
$this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response_obj = json_decode($response);
curl_close($ch);
if ($this->http_status != '200')
{
if(isset($response_obj->error_text))
$this->log($response_obj->error_text, __METHOD__);
}
return $response_obj;
}
/**
* function set_proxy
* Set proxy server options while connecting to Plurk API
*
* @param string $host Proxy server host
* @param string $port Proxy server port
* @param string $username Username for proxy server authentication. Could be ignored if no need.
* @param string $password Password for proxy server authentication. Could be ignored if no need.
*/
function set_proxy($host = '', $port = 0, $username = '', $password = '')
{
if($host != '' && $port != 0)
$this->proxy = "http://$host:$port";
if($username != '' && $password != '')
$this->proxy_auth = "$username:$password";
}
/**
* function set_cookie_path
* set curl cookie path
*
* @param string $cookie_path
*/
function set_cookie_path($cookie_path = NULL)
{
if( ! file_exists($cookie_path)) touch($cookie_path);
$this->cookie_path = $cookie_path;
}
/**
* function set_timeout
* The maximum number of seconds to allow cURL functions to execute.
*
* @param type $timeout
*/
function set_timeout($timeout = 30)
{
$this->timeout = $timeout;
}
/**
* function set_connect_timeout
* The number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
*
* @param type $connect_timeout
*/
function set_connect_timeout($connect_timeout = 30)
{
$this->connect_timeout = $connect_timeout;
}
/**
* function register
* Register a new Plurk account. Should be HTTPS
*
* @param string $nick_name The user's nick name. Should be longer than 3 characters. Should be ASCII. Nick name can only contain letters, numbers and _.
* @param string $full_name Can't be empty.
* @param string $password Should be longer than 3 characters.
* @param string $gender Should be male or female.
* @param string $date_of_birth Should be YYYY-MM-DD, example 1985-05-13.
* $param string $email (Optional) Must be a valid email.
* @return JSON object
* @see /API/Users/register
*/
function register($nick_name = NULL, $full_name = NULL, $password = '', $gender = 'male', $date_of_birth = '1985-05-13', $email = NULL)
{
if( ! isset($nick_name))
$this->log('nick name can not be empty.', __METHOD__);
if( ! isset($full_name))
$this->log('full name can not be empty.', __METHOD__);
if( ! in_array(strtolower($gender), array('male','female')))
$this->log('should be male or female.', __METHOD__);
$array = array(
'api_key' => $this->api_key,
'nick_name' => $nick_name,
'full_name' => $full_name,
'password' => $password,
'gender' => $gender,
'date_of_birth' => $date_of_birth
);
if(isset($email)) $array['email'] = $email;
$result = $this->plurk(PLURK_REGISTER, $array);
return $result;
}
/**
* function login
* Login an already created user. Login creates a session cookie, which can be used to access the other methods.
*
* @param $api_key Your Plurk API key.
* @param $username The user's nick name or email.
* @param $password The user's password.
* @return boolean
* @see /API/Users/login
*/
function login($api_key = '', $username = '', $password = '')
{
$this->username = $username;
$array = array(
'username' => $username,
'password' => $password,
'api_key' => $api_key,
);
$result = $this->plurk(PLURK_LOGIN, $array);
($this->http_status == '200') ? $this->is_login = TRUE : $this->is_login = FALSE;
if($this->is_login)
{
$this->password = $password;
$this->api_key = $api_key;
$this->user_info = $result;
}
return $this->is_login;
}
/**
* function login
* Logout current user.
*
* @return boolean
* @see /API/Users/logout
*/
function logout()
{
$array = array(
'api_key' => $this->api_key,
);
$this->plurk(PLURK_LOGOUT, $array);
($this->http_status == '200') ? $this->is_login = FALSE : $this->is_login = TRUE;
return ! $this->is_login;
}
/**
* function update
* Update a user's information (such as email, password or privacy). Should be HTTPS
*
* @param string $current_password User's current password.
* @param string $full_name Change full name.
* @param string $new_password Change password.
* @param string $email Change email.
* @param string $display_name User's display name, can be empty and full unicode. Must be shorter than 15 characters.
* @param string $privacy User's privacy settings. The option can be world (whole world can view the profile), only_friends (only friends can view the profile) or only_me (only the user can view own plurks).
* @param string $date_of_birth Should be YYYY-MM-DD, example 1985-05-13.
* @return boolean
* @see /API/Users/update
*/
function update($current_password = NULL, $full_name = NULL, $new_password = NULL, $email = NULL, $display_name = NULL, $privacy = NULL, $date_of_birth = NULL)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
if( ! isset($full_name))
$this->log('full name can not be empty.', __METHOD__);
if(isset($privacy))
{
if( ! in_array($privacy, array('world', 'only_friends', 'only_me')))
$this->log("User's privacy must be world, only_friends or only_me.");
}
$array = array(
'api_key' => $this->api_key,
'current_password' => $current_password,
);
if(isset($full_name)) $array['full_name'] = $full_name;
if(isset($new_password)) $array['new_password'] = $new_password;
if(isset($display_name)) $array['display_name'] = $display_name;
if(isset($email)) $array['email'] = $email;
if(isset($privacy)) $array['prvacy'] = $privacy;
if(isset($date_of_birth)) $array['date_of_birth'] = $date_of_birth;
$result = $this->plurk(PLURK_UPDATE, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function update_picture
* update a user's profile picture. You can read more about how to render an avatar via user data.
*
* @param string $profile_image The new profile image.
* @return JSON object
* @see /API/Users/updatePicture
*/
function update_picture($profile_image = '')
{
// RFC 1867
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array['api_key'] = $this->api_key;
$array['profile_image'] = "@" . $profile_image;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PLURK_UPDATE_PICTURE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, PLURK_AGENT);
(isset($this->cookie_path)) ? $cookie_path = $this->cookie_path : $cookie_path = PLURK_COOKIE_PATH;
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
$response = curl_exec($ch);
$this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->http_response = $response;
return json_decode($response);
}
/**
* function get_karma_stats
* Returns info about a user's karma, including current karma, karma growth, karma graph and the latest reason why the karma has dropped.
*
* karma_trend:
* Returns a list of 30 recent karma updates. Each update is a string '[[unixtimestamp]]-[[karma_value]]', e.g. a valid entry is '1282046402-97.85'
* karma_fall_reason:
* Why did karma drop? This value is a string and can be: friends_rejections, inactivity, too_short_responses
*
* http://www.plurk.com/API#/API/Users/getKarmaStats
* @return JSON object
* @see /API/Users/getKarmaStats
*/
function get_karma_stats()
{
$array = array(
'api_key' => $this->api_key,
);
return $this->plurk(PLURK_GET_KARMASTATS, $array);
}
/**
* function realtime_get_user_channel
*
* Return's a JSON object with an URL that you should listen to, e.g.
* {"comet_server": "http://comet03.plurk.com/comet/1235515351741/?channel=generic-4-f733d8522327edf87b4d1651e6395a6cca0807a0",
* "channel_name": "generic-4-f733d8522327edf87b4d1651e6395a6cca0807a0"}
*
* for Comet channel specification:
* http://www.plurk.com/API#/API/Realtime/getUserChannel
*
* @return JSON object
* @see /API/Realtime/getUserChannel
*/
function realtime_get_user_channel()
{
$array = array(
'api_key' => $this->api_key,
);
return $this->plurk(PLURK_REALTIME_GET_USER_CHANNEL, $array);
}
/**
* function realtime_get_commet_channel
*
* You'll get an URL from /API/Realtime/getUserChannel and you do GET requests to this URL to get new data.
* Your request will sleep for about 50 seconds before returning a response if there is no new data added to your channel.
* You won't get notifications on responses that the logged in user adds, but you will get notifications for new plurks.
*
* @param string $comet_server full path with channel name
* @param string $new_offset only fetch new messages from a given offset. .
* @return JSON object
*/
function realtime_get_commet_channel($comet_server = NULL, $new_offset = NULL)
{
if(isset($new_offset))
$comet_url = $comet_server . '&offset=' . $new_offset;
else
$comet_url = $comet_server;
/**
* the "$comet_url" should look like
* http://comet03.plurk.com/comet/1235515351741/?channel=generic-4-f733d8522327edf87b4d1651e6395a6cca0807a0
*/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $comet_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, PLURK_AGENT);
(isset($this->cookie_path)) ? $cookie_path = $this->cookie_path : $cookie_path = PLURK_COOKIE_PATH;
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
$response = curl_exec($ch);
$this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->http_response = $response;
// return raw response, cause plurk server will return "CometChannel.scriptCallback({"new_offset": 5090486,"data": ... "new_plurk", "owner_id": 5320351}]});"
return $response;
}
/**
* function get_plurks_polling
*
* @param time $offset Return plurks newer than offset, use timestamp.
* @param int $limit The max number of plurks to be returned (default 50).
* @return JSON object
* @see /API/Polling/getPlurks
*/
function get_plurks_polling($offset = NULL, $limit = 50)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$offset = (isset($offset)) ? $offset : array_shift(explode("+", date("c")));
$array = array(
'api_key' => $this->api_key,
'offset' => $offset,
'limit' => $limit,
);
return $this->plurk(PLURK_POLLING_GET_PLURK, $array);
}
/**
* function get_plurks_polling_unread_count
* Use this call to find out if there are unread plurks on a user's timeline.
*
* @return int
* @see /API/Polling/getUnreadCount
*/
function get_plurks_polling_unread_count()
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
);
return $this->plurk(PLURK_POLLING_GET_UNREAD_COUNT, $array);
}
/**
* function get_plurk
*
* @param int $plurk_id The unique id of the plurk. Should be passed as a number, and not base 36 encoded.
* @return JSON object
* @see /API/Timeline/getPlurk
*/
function get_plurk($plurk_id = 0)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'plurk_id' => $plurk_id,
);
return $this->plurk(PLURK_TIMELINE_GET_PLURK, $array);
}
/**
* function get_plurks
*
* @param time $offset Return plurks older than offset, use timestamp.
* @param int $limit How many plurks should be returned? Default is 20.
* @param boolean $only_user Setting it to true will only return user plurks.
* @param boolean $only_responded Setting it to true will only return responded plurks.
* @param boolean $only_private Setting it to true will only return private plurks.
* @param boolean $only_favorite Setting it to true will only return favorite plurks.
* @return JSON object
* @see /API/Timeline/getPlurks
*/
function get_plurks($offset = NULL, $limit = 20, $only_user = NULL, $only_responded = NULL, $only_private = NULL, $only_favorite = NULL)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$offset = (isset($offset)) ? $offset : array_shift(explode("+", date("c")));
/* format 2010-01-18T11:24:43 */
$array = array(
'api_key' => $this->api_key,
'offset' => $offset,
'limit' => $limit
);
if(isset($only_user)) $array['only_user'] = $only_user;
if(isset($only_responded)) $array['only_responded'] = $only_responded;
if(isset($only_private)) $array['only_private'] = $only_private;
if(isset($only_favorite)) $array['only_favorite'] = $only_favorite;
return $this->plurk(PLURK_TIMELINE_GET_PLURKS, $array);
}
/**
* function get_unread_plurks
*
* @param time $offset Return plurks older than offset, use timestamp
* @param int $limit Limit the number of plurks that is retunred.
* @return JSON object
* @see /API/Timeline/getUnreadPlurks
*/
function get_unread_plurks($offset = NULL ,$limit = 10)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$offset = (isset($offset)) ? $offset : array_shift(explode("+", date("c")));
$array = array(
'api_key' => $this->api_key,
'offset' => $date,
'limit' => $limit
);
$result = $this->plurk(PLURK_TIMELINE_GET_UNREAD_PLURKS, $array);
return $result;
}
/**
* function add_Plurk
*
* @param string $lang The plurk's language.
* @param string $qualifier The Plurk's qualifier, must be in English. please see documents/README
* @param string $content The Plurk's text.
* @param $limited_to Limit the plurk only to some users (also known as private plurking). limited_to should be a Array list of friend ids, e.g. limited_to = array(3,4,66,34) will only be plurked to these user ids.
* @param string $lang The plurk's language.
* @param int $no_commetns If set to 1, then responses are disabled for this plurk. If set to 2, then only friends can respond to this plurk.
* @return JSON object
* @see /API/Timeline/plurkAdd
*/
function add_plurk($lang = 'en', $qualifier = 'says', $content = 'test from plurk-api', $limited_to = NULL, $no_comments = 0)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
if (mb_strlen($content, 'UTF-8') > 140)
{
$this->log('this message should shorter than 140 characters.', __METHOD__);
}
$array = array(
'api_key' => $this->api_key,
'qualifier' => $qualifier,
'content' => $content,
'lang' => $lang,
'no_comments' => $no_comments
);
// roga.2009-12-14: need to confirm.
if (isset($limited_to)) $array['limited_to'] = json_encode($limited_to);
$result = $this->plurk(PLURK_TIMELINE_PLURK_ADD, $array);
return $result;
}
/**
* function delete_plurk
*
* @param int $plurk_id: The id of the plurk.
* @return boolean
* @see /API/Timeline/plurkDelete
*/
function delete_plurk($plurk_id = 0)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'plurk_id' => $plurk_id
);
$result = $this->plurk(PLURK_TIMELINE_PLURK_DELETE, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function edit_plurk
*
* @param int $plurk_id The id of the plurk.
* @param string $content The content of plurk.
* @return JSON object
* @see /API/Timeline/plurkEdit
*/
function edit_plurk($plurk_id = 0, $content = '')
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
if (mb_strlen($content, 'UTF-8') > 140)
{
$this->log('this message should shorter than 140 characters.', __METHOD__);
}
$array = array(
'api_key' => $this->api_key,
'plurk_id' => $plurk_id,
'content' => $content
);
$result = $this->plurk(PLURK_TIMELINE_PLURK_EDIT, $array);
return $result;
}
/**
* function mute_plurks
*
* @param $ids The plurk ids, eg. array(123,456,789)
* @return boolean
* @see /API/Timeline/mutePlurks
*/
function mute_plurks($ids)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'ids' => json_encode($ids),
);
$this->plurk(PLURK_TIMELINE_MUTE_PLURKS, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function unmute_plurks
*
* @param $ids The plurk ids, eg. array(123,456,789)
* @return boolean
* @see /API/Timeline/unmutePlurks
*/
function unmute_plurks($ids)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'ids' => json_encode($ids),
);
$result = $this->plurk(PLURK_TIMELINE_UNMUTE_PLURKS, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function favorite_plurk
*
* @param $ids The plurk ids, eg. array(123,456,789)
* @return boolean
* @see /API/Timeline/favoritePlurks
*/
function favorite_plurk($ids)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'ids' => json_encode($ids),
);
$this->plurk(PLURK_TIMELINE_FAVORITE_PLURKS, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function unfavorite_plurk
*
* @param $ids The plurk ids, eg. array(123,456,789)
* @return boolean
* @see /API/Timeline/unfavoritePlurks
*/
function unfavorite_plurk($ids)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'ids' => json_encode($ids),
);
$this->plurk(PLURK_TIMELINE_UNFAVORITE_PLURKS, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function mark_plurk_as_read
*
* @param $ids The plurk ids, eg. array(123,456,789)
* @return boolean
* @see /API/Timeline/markAsRead
*/
function mark_plurk_as_read($ids)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'ids' => json_encode($ids),
);
$this->plurk(PLURK_TIMELINE_MARK_AS_READ, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function upload_picture
* to upload a picture to Plurk, you should do a multipart/form-data POST request
* to /API/Timeline/uploadPicture. This will add the picture to Plurk's CDN network
* and return a image link that you can add to /API/Timeline/plurkAdd
*
* @param string $upload_image
* @return JSON object
* @see /API/Timeline/uploadPicture
*/
function upload_picture($upload_image = '')
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array['api_key'] = $this->api_key;
$array['image'] = "@" . $upload_image;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, PLURK_TIMELINE_UPLOAD_PICTURE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $array);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, PLURK_AGENT);
(isset($this->cookie_path)) ? $cookie_path = $this->cookie_path : $cookie_path = PLURK_COOKIE_PATH;
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path);
$response = curl_exec($ch);
$this->http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->http_response = $response;
return json_decode($response);
}
/**
* function get_responses
*
* @param int $plurk_id: The plurk that the responses should be added to.
* @param int $offset: Only fetch responses from an offset, should be 5, 10 or 15.
* @return JSON object
* @see /API/Responses/get
*/
function get_responses($plurk_id = 0, $offset = 0)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'plurk_id' => $plurk_id,
'offset' => $offset
);
return $this->plurk(PLURK_GET_RESPONSE, $array);
}
/**
* function add_response
*
* @param int $plurk_id The plurk that the responses should be added to.
* @param string $content The response's text.
* @param string $qualifier The Plurk's qualifier, please see documents/README
* @return JSON object
* @see /API/Responses/responseAdd
*/
function add_response($plurk_id = 0, $content = '', $qualifier = 'says')
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
if (mb_strlen($content, 'UTF-8') > 140)
{
$this->log('this message should shorter than 140 characters.', __METHOD__);
}
$array = array(
'api_key' => $this->api_key,
'plurk_id' => $plurk_id,
'content' => $content,
'qualifier' => $qualifier
);
$result = $this->plurk(PLURK_ADD_RESPONSE, $array);
return $result;
}
/**
* function delete_response
*
* @param int $response_id The plurk that the responses should be added to.
* @param int $plurk_id The plurk that the response belongs to.
* @return boolean
* @see /API/Responses/responseDelete
*/
function delete_response($plurk_id = 0, $response_id = 0)
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array(
'api_key' => $this->api_key,
'plurk_id' => $plurk_id,
'response_id' => $response_id
);
$result = $this->plurk(PLURK_DELERE_RESPONSE, $array);
return ($this->http_status == '200') ? TRUE : FALSE;
}
/**
* function get_own_profile
*
* @return JSON object
* @see /API/Profile/getOwnProfile
*/
function get_own_profile()
{
if( ! $this->is_login) $this->log(PLURK_NOT_LOGIN, __METHOD__);
$array = array('api_key' => $this->api_key);
$result = $this->plurk(PLURK_GET_OWN_PROFILE, $array);
$this->user_info = $result;
return $result;
}
/**
* function get_public_profile
*
* @param int $user_id The user_id of the public profile. Can be integer (like 34) or nick name (like amix).
* @return JSON object
* @see /API/Profile/getPublicProfile
*/
function get_public_profile($user_id = 0)
{
$array = array(
'api_key' => $this->api_key,
'user_id' => $user_id
);
return $this->plurk(PLURK_GET_PUBLIC_PROFILE, $array);
}
/**
* function get_friends
*
* @param int $user_id The user_id of the public profile. (integer)
* @param int $offset The offset, can be 10, 20, 30 etc.
* @return JSON objects
* @see /API/FriendsFans/getFriendsByOffset
*/
function get_friends($user_id = 0, $offset = 0)
{
$array = array(
'api_key' => $this->api_key,
'user_id' => $user_id,
'offset' => $offset
);
return $this->plurk(PLURK_GET_FRIENDS, $array);
}
/**
* function get_fans
*
* @param int $user_id The user_id of the public profile. (integer)
* @param int $offset The offset, can be 10, 20, 30 etc.
* @return JSON object