@@ -128,7 +128,7 @@ public function login($username, $password) {
128
128
*/
129
129
public function logout () {
130
130
// Make sure we're logged in and have a valid access token.
131
- if (!$ this -> auth_token || ! $ this -> username ) {
131
+ if (!userVerified () ) {
132
132
return FALSE ;
133
133
}
134
134
@@ -217,6 +217,17 @@ public function register($username, $password, $email, $birthday) {
217
217
return $ result ;
218
218
}
219
219
220
+ /**
221
+ * Checks if the user is logged in and has a valid auth token.
222
+ *
223
+ * @return TRUE if the user is verified, FALSE otherwise
224
+ */
225
+ public function userVerified ()
226
+ {
227
+ return ($ this ->auth_token && $ this ->username );
228
+ }
229
+
230
+
220
231
/**
221
232
* Retrieves general user, friend, and snap updates.
222
233
*
@@ -227,7 +238,7 @@ public function register($username, $password, $email, $birthday) {
227
238
* @return mixed
228
239
* The data returned by the service or FALSE on failure.
229
240
*/
230
- public function getUpdates ($ force = FALSE ) {
241
+ public function getUpdates ($ force = FALSE ) {
231
242
if (!$ force ) {
232
243
$ result = $ this ->cache ->get ('updates ' );
233
244
if ($ result ) {
@@ -236,7 +247,7 @@ public function getUpdates($force = FALSE) {
236
247
}
237
248
238
249
// Make sure we're logged in and have a valid access token.
239
- if (!$ this -> auth_token || ! $ this -> username ) {
250
+ if (!userVerified () ) {
240
251
return FALSE ;
241
252
}
242
253
@@ -319,7 +330,7 @@ function getFriendStories($force = FALSE) {
319
330
}
320
331
321
332
// Make sure we're logged in and have a valid access token.
322
- if (!$ this -> auth_token || ! $ this -> username ) {
333
+ if (!userVerified () ) {
323
334
return FALSE ;
324
335
}
325
336
@@ -372,7 +383,7 @@ public function findFriends($numbers, $country = 'US') {
372
383
$ batches = array_chunk (array_flip ($ numbers ), 30 , TRUE );
373
384
374
385
// Make sure we're logged in and have a valid access token.
375
- if (!$ this -> auth_token || ! $ this -> username ) {
386
+ if (!userVerified () ) {
376
387
return FALSE ;
377
388
}
378
389
@@ -444,7 +455,7 @@ public function getAddedFriends() {
444
455
*/
445
456
public function addFriend ($ username ) {
446
457
// Make sure we're logged in and have a valid access token.
447
- if (!$ this -> auth_token || ! $ this -> username ) {
458
+ if (!userVerified () ) {
448
459
return FALSE ;
449
460
}
450
461
@@ -482,7 +493,7 @@ public function addFriend($username) {
482
493
*/
483
494
public function addFriends ($ usernames ) {
484
495
// Make sure we're logged in and have a valid access token.
485
- if (!$ this -> auth_token || ! $ this -> username ) {
496
+ if (!userVerified () ) {
486
497
return FALSE ;
487
498
}
488
499
@@ -530,7 +541,7 @@ public function addFriends($usernames) {
530
541
*/
531
542
public function deleteFriend ($ username ) {
532
543
// Make sure we're logged in and have a valid access token.
533
- if (!$ this -> auth_token || ! $ this -> username ) {
544
+ if (!userVerified () ) {
534
545
return FALSE ;
535
546
}
536
547
@@ -565,7 +576,7 @@ public function deleteFriend($username) {
565
576
*/
566
577
public function setDisplayName ($ username , $ display ) {
567
578
// Make sure we're logged in and have a valid access token.
568
- if (!$ this -> auth_token || ! $ this -> username ) {
579
+ if (!userVerified () ) {
569
580
return FALSE ;
570
581
}
571
582
@@ -599,7 +610,7 @@ public function setDisplayName($username, $display) {
599
610
*/
600
611
public function block ($ username ) {
601
612
// Make sure we're logged in and have a valid access token.
602
- if (!$ this -> auth_token || ! $ this -> username ) {
613
+ if (!userVerified () ) {
603
614
return FALSE ;
604
615
}
605
616
@@ -632,7 +643,7 @@ public function block($username) {
632
643
*/
633
644
public function unblock ($ username ) {
634
645
// Make sure we're logged in and have a valid access token.
635
- if (!$ this -> auth_token || ! $ this -> username ) {
646
+ if (!userVerified () ) {
636
647
return FALSE ;
637
648
}
638
649
@@ -666,7 +677,7 @@ public function unblock($username) {
666
677
*/
667
678
public function getMedia ($ id ) {
668
679
// Make sure we're logged in and have a valid access token.
669
- if (!$ this -> auth_token || ! $ this -> username ) {
680
+ if (!userVerified () ) {
670
681
return FALSE ;
671
682
}
672
683
@@ -712,7 +723,7 @@ public function getMedia($id) {
712
723
*/
713
724
public function sendEvents ($ events , $ snap_info = array ()) {
714
725
// Make sure we're logged in and have a valid access token.
715
- if (!$ this -> auth_token || ! $ this -> username ) {
726
+ if (!userVerified () ) {
716
727
return FALSE ;
717
728
}
718
729
@@ -837,7 +848,7 @@ public function markSnapShot($id, $time = 1) {
837
848
*/
838
849
public function upload ($ type , $ data ) {
839
850
// Make sure we're logged in and have a valid access token.
840
- if (!$ this -> auth_token || ! $ this -> username ) {
851
+ if (!userVerified () ) {
841
852
return FALSE ;
842
853
}
843
854
@@ -887,7 +898,7 @@ public function upload($type, $data) {
887
898
*/
888
899
public function send ($ media_id , $ recipients , $ time = 3 ) {
889
900
// Make sure we're logged in and have a valid access token.
890
- if (!$ this -> auth_token || ! $ this -> username ) {
901
+ if (!userVerified () ) {
891
902
return FALSE ;
892
903
}
893
904
@@ -925,7 +936,7 @@ public function send($media_id, $recipients, $time = 3) {
925
936
*/
926
937
public function setStory ($ media_id , $ media_type , $ time = 3 ) {
927
938
// Make sure we're logged in and have a valid access token.
928
- if (!$ this -> auth_token || ! $ this -> username ) {
939
+ if (!userVerified () ) {
929
940
return FALSE ;
930
941
}
931
942
@@ -964,7 +975,7 @@ public function setStory($media_id, $media_type, $time = 3) {
964
975
*/
965
976
public function getStory ($ media_id , $ key , $ iv ) {
966
977
// Make sure we're logged in and have a valid access token.
967
- if (!$ this -> auth_token || ! $ this -> username ) {
978
+ if (!userVerified () ) {
968
979
return FALSE ;
969
980
}
970
981
@@ -993,7 +1004,7 @@ public function getStory($media_id, $key, $iv) {
993
1004
*/
994
1005
public function getStoryThumb ($ media_id , $ key , $ iv ) {
995
1006
// Make sure we're logged in and have a valid access token.
996
- if (!$ this -> auth_token || ! $ this -> username ) {
1007
+ if (!userVerified () ) {
997
1008
return FALSE ;
998
1009
}
999
1010
@@ -1020,7 +1031,7 @@ public function getStoryThumb($media_id, $key, $iv) {
1020
1031
*/
1021
1032
public function markStoryViewed ($ id , $ screenshot_count = 0 ) {
1022
1033
// Make sure we're logged in and have a valid access token.
1023
- if (!$ this -> auth_token || ! $ this -> username ) {
1034
+ if (!userVerified () ) {
1024
1035
return FALSE ;
1025
1036
}
1026
1037
@@ -1059,7 +1070,7 @@ public function markStoryViewed($id, $screenshot_count = 0) {
1059
1070
*/
1060
1071
public function getBests ($ friends ) {
1061
1072
// Make sure we're logged in and have a valid access token.
1062
- if (!$ this -> auth_token || ! $ this -> username ) {
1073
+ if (!userVerified () ) {
1063
1074
return FALSE ;
1064
1075
}
1065
1076
@@ -1097,7 +1108,7 @@ public function getBests($friends) {
1097
1108
*/
1098
1109
public function clearFeed () {
1099
1110
// Make sure we're logged in and have a valid access token.
1100
- if (!$ this -> auth_token || ! $ this -> username ) {
1111
+ if (!userVerified () ) {
1101
1112
return FALSE ;
1102
1113
}
1103
1114
@@ -1128,7 +1139,7 @@ public function clearFeed() {
1128
1139
*/
1129
1140
public function updatePrivacy ($ setting ) {
1130
1141
// Make sure we're logged in and have a valid access token.
1131
- if (!$ this -> auth_token || ! $ this -> username ) {
1142
+ if (!userVerified () ) {
1132
1143
return FALSE ;
1133
1144
}
1134
1145
@@ -1161,7 +1172,7 @@ public function updatePrivacy($setting) {
1161
1172
*/
1162
1173
public function updateEmail ($ email ) {
1163
1174
// Make sure we're logged in and have a valid access token.
1164
- if (!$ this -> auth_token || ! $ this -> username ) {
1175
+ if (!userVerified () ) {
1165
1176
return FALSE ;
1166
1177
}
1167
1178
0 commit comments