@@ -118,7 +118,10 @@ private function _initUser() {
118
118
119
119
120
120
if ($ user ) {
121
- $ this ->_currentUser = $ user ;
121
+ //$this->_currentUser = $user;
122
+ // Update the user record with the new image
123
+ $ this ->_currentUser = $ this ->_updateUser ($ user , $ facebookId );
124
+
122
125
} else {
123
126
$ this ->_currentUser = $ this ->_createUser ($ facebookId );
124
127
}
@@ -184,6 +187,43 @@ private function _createUser($facebookId){
184
187
185
188
return $ data ;
186
189
}
190
+
191
+ /**
192
+ * Update the user record with an updated profile picture
193
+ *
194
+ * TODO: Need error trapping here badly
195
+ *
196
+ * @author khoople
197
+ *
198
+ * @param int $facebookId
199
+ * @return array
200
+ */
201
+ private function _updateUser ($ user , $ facebookId ) {
202
+ $ ch = curl_init ();
203
+
204
+ curl_setopt ($ ch , CURLOPT_URL , "http://graph.facebook.com/ $ facebookId/picture?type=large " );
205
+
206
+ curl_setopt ($ ch , CURLOPT_HEADER , false );
207
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
208
+ curl_setopt ($ ch , CURLOPT_NOBODY , true );
209
+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
210
+ curl_exec ($ ch );
211
+
212
+ $ url = curl_getinfo ($ ch , CURLINFO_EFFECTIVE_URL );
213
+
214
+ curl_close ($ ch );
215
+
216
+ $ data ['User ' ] = array (
217
+ 'image ' => $ url ,
218
+ 'id ' => $ user ['User ' ]['id ' ]
219
+ );
220
+
221
+ // Create the new user
222
+ $ this ->User ->Save ($ data );
223
+
224
+ return $ this ->User ->findById ($ user ['User ' ]['id ' ]);
225
+
226
+ }
187
227
188
228
/**
189
229
* Redirect user to the page where they grant access to our facebook app.
0 commit comments