1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Instagram PHP |
---|
5 | * @author Galen Grover <galenjr@gmail.com> |
---|
6 | * @license http://opensource.org/licenses/mit-license.php The MIT License |
---|
7 | */ |
---|
8 | |
---|
9 | |
---|
10 | include_once(INSTAGRAM_ROOT.'/Core/Proxy.php'); |
---|
11 | include_once(INSTAGRAM_ROOT.'/Core/BaseObjectAbstract.php'); |
---|
12 | include_once(INSTAGRAM_ROOT.'/Collection/MediaCollection.php'); |
---|
13 | include_once(INSTAGRAM_ROOT.'/Collection/UserCollection.php'); |
---|
14 | |
---|
15 | |
---|
16 | /** |
---|
17 | * User class |
---|
18 | * |
---|
19 | * @see Instagram->getUser() |
---|
20 | * {@link https://github.com/galen/PHP-Instagram-API/blob/master/Examples/user.php} |
---|
21 | * {@link http://galengrover.com/projects/PHP-Instagram-API/Examples/?example=user.php} |
---|
22 | */ |
---|
23 | class Instagram_User extends Instagram_Core_BaseObjectAbstract { |
---|
24 | |
---|
25 | /** |
---|
26 | * Get the user's username |
---|
27 | * |
---|
28 | * @return string |
---|
29 | * @access public |
---|
30 | */ |
---|
31 | public function getUserName() { |
---|
32 | return $this->data->username; |
---|
33 | } |
---|
34 | |
---|
35 | /** |
---|
36 | * Get the user's full name |
---|
37 | * |
---|
38 | * @return string|null |
---|
39 | * @access public |
---|
40 | */ |
---|
41 | public function getFullName( $forced = false ) { |
---|
42 | return isset( $this->data->full_name ) ? $this->data->full_name : ( $forced ? $this->data->username : null ); |
---|
43 | } |
---|
44 | |
---|
45 | /** |
---|
46 | * Get the user's profile picture |
---|
47 | * |
---|
48 | * @return string |
---|
49 | * @access public |
---|
50 | */ |
---|
51 | public function getProfilePicture() { |
---|
52 | return $this->data->profile_picture; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Get the user's biography |
---|
57 | * |
---|
58 | * @return string |
---|
59 | * @access public |
---|
60 | */ |
---|
61 | public function getBio() { |
---|
62 | return $this->data->bio; |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Get the user's website |
---|
67 | * |
---|
68 | * @return string |
---|
69 | * @access public |
---|
70 | */ |
---|
71 | public function getWebsite() { |
---|
72 | return $this->data->website; |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * Get the user's counts |
---|
77 | * |
---|
78 | * @return StdClass|null |
---|
79 | * @access public |
---|
80 | */ |
---|
81 | public function getCounts() { |
---|
82 | if ( !$this->isCompleteUser() ) { |
---|
83 | $this->updateData(); |
---|
84 | } |
---|
85 | return isset( $this->data->counts ) ? $this->data->counts : null; |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Get the user's following count |
---|
90 | * |
---|
91 | * @return int |
---|
92 | * @access public |
---|
93 | */ |
---|
94 | public function getFollowsCount() { |
---|
95 | return (int)$this->getCounts()->follows; |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Get the user's followers count |
---|
100 | * |
---|
101 | * @return int |
---|
102 | * @access public |
---|
103 | */ |
---|
104 | public function getFollowersCount() { |
---|
105 | return (int)$this->getCounts()->followed_by; |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * Get the user's media count |
---|
110 | * |
---|
111 | * @return int |
---|
112 | * @access public |
---|
113 | */ |
---|
114 | public function getMediaCount() { |
---|
115 | return (int)$this->getCounts()->media; |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * Update user data |
---|
120 | * |
---|
121 | * Sometimes user object are incomplete. For instance when getting a media object's comments |
---|
122 | * the users associated with the comments won't have all their data |
---|
123 | * |
---|
124 | * @access public |
---|
125 | */ |
---|
126 | public function updateData() { |
---|
127 | $this->setData( $this->proxy->getUser( $this->getApiId() ) ); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * Return if the user is complete |
---|
132 | * |
---|
133 | * @see Instagram_User::updateData() |
---|
134 | * |
---|
135 | * @return bool |
---|
136 | * @access protected |
---|
137 | */ |
---|
138 | protected function isCompleteUser() { |
---|
139 | return isset( $this->data->counts ); |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * Get the user's media |
---|
144 | * |
---|
145 | * This can be paginated with the next_max_id param obtained from Instagram_Collection_MediaCollection->getNext() |
---|
146 | * |
---|
147 | * @return Instagram_Collection_MediaCollection |
---|
148 | * @access public |
---|
149 | */ |
---|
150 | public function getMedia( array $params = null ) { |
---|
151 | return new Instagram_Collection_MediaCollection( $this->proxy->getUserMedia( $this->getApiId(), $params ), $this->proxy ); |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * Get all user's media |
---|
156 | * |
---|
157 | * @return Instagram_Collection_MediaCollection |
---|
158 | * @access public |
---|
159 | */ |
---|
160 | public function getAllMedia() { |
---|
161 | $main = $this->getMedia(); |
---|
162 | $next = $main->getNext(); |
---|
163 | |
---|
164 | while ( $next !== null ) { |
---|
165 | $temp = $this->getMedia( array('max_id' => $next) ); |
---|
166 | $next = $temp->getNext(); |
---|
167 | $main->addData( $temp ); |
---|
168 | } |
---|
169 | |
---|
170 | return $main; |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * Get the users that the user follows |
---|
175 | * |
---|
176 | * This can be paginated with the next_cursor param obtained from Instagram_Collection_UserCollection->getNext() |
---|
177 | * |
---|
178 | * @return Instagram_Collection_UserCollection |
---|
179 | * @access public |
---|
180 | */ |
---|
181 | public function getFollows( array $params = null ) { |
---|
182 | return new Instagram_Collection_UserCollection( $this->proxy->getUserFollows( $this->getApiId(), $params ), $this->proxy ); |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * Get the user's that follow this user |
---|
187 | * |
---|
188 | * This can be paginated with the next_cursor param obtained from Instagram_Collection_UserCollection->getNext() |
---|
189 | * |
---|
190 | * @return Instagram_Collection_UserCollection |
---|
191 | * @access public |
---|
192 | */ |
---|
193 | public function getFollowers( array $params = null ) { |
---|
194 | return new Instagram_Collection_UserCollection( $this->proxy->getUserFollowers( $this->getApiId(), $params ), $this->proxy ); |
---|
195 | } |
---|
196 | |
---|
197 | /** |
---|
198 | * Magic toString method |
---|
199 | * |
---|
200 | * Get the user's username |
---|
201 | * |
---|
202 | * @return Instagram_Collection_Collection |
---|
203 | * @access public |
---|
204 | */ |
---|
205 | public function __toString() { |
---|
206 | return $this->getUserName(); |
---|
207 | } |
---|
208 | |
---|
209 | } |
---|
210 | ?> |
---|