예제 #1
0
파일: user.php 프로젝트: Tapac/hotscot
 public function get_data($params)
 {
     // the user
     if (!($user = $this->getUser())) {
         //we require a user to call facebook
         v('json/fail', 'user is required');
     }
     // fields to get. flip the array so we can use isset, which is way faster than in_array
     $fields = array_flip(array_val_csv($params, 'wib_fields'));
     // get profile data
     $profile_data = FB::getProfile($user);
     // this holds our output
     $data = array();
     // get name if requested
     if (isset($fields['name'])) {
         $data['name'] = trim(array_val($profile_data, 'name'));
     }
     // get gender
     if (isset($fields['gender'])) {
         $data['gender'] = low(array_val($profile_data, 'sex'));
     }
     // birthday
     if (isset($fields['birthday'])) {
         $data['birthday'] = $profile_data['birthday'] ? $profile_data['birthday'] : null;
     }
     // about me
     if (isset($fields['about_me'])) {
         $data['about_me'] = array_val($profile_data, 'about_me');
     }
     // photo url
     if (isset($fields['photo_url'])) {
         $data['photo_url'] = array_val($profile_data, 'pic_big');
     }
     // status
     if (isset($fields['status'])) {
         $data['status'] = array_val($profile_data, array('status', 'message'));
     }
     // status
     if (isset($fields['about_me'])) {
         $data['about_me'] = array_val($profile_data, 'interests');
     }
     // friends require another API call and a bit more work
     if (isset($fields['friends'])) {
         $friends = array();
         foreach (FB::getFriendIDs($user) as $id) {
             $friends[] = 'user:'******'friends'] = $friends;
     }
     // photos
     if (isset($fields['photos'])) {
         $data['photos'] = FB::getPhotos($user);
     }
     // albums
     if (isset($fields['albums'])) {
         $data['albums'] = FB::getAlbums($user);
     }
     // output JSON-encoded data
     v('json/data', $data);
 }