public function getUser($login)
    {
        if (empty($login)) {
            return new AnonymousUser();       
        }
        
        //use the cache if available. Don't use the cache for the special me user
        if ($this->useCache && $login != 'me') {
            $cacheFilename = "user_$login";
            if ($this->cache === NULL) {
                  $this->cache = new DiskCache(CACHE_DIR . "/Facebook", $this->cacheLifetime, TRUE);
                  $this->cache->setSuffix('.json');
                  $this->cache->preserveFormat();
            }

            if ($this->cache->isFresh($cacheFilename)) {
                $data = $this->cache->read($cacheFilename);
            } else {

                //get the data
                $url = sprintf("https://graph.facebook.com/%s?%s", $login, http_build_query(array(
                'fields'=>'id,first_name,last_name,email,picture,gender',
                'access_token'=>$this->access_token
                )));

                if ($data = @file_get_contents($url)) {
                    $this->cache->write($data, $cacheFilename);
                }
                
            }
        } else {
            //get the data
            $url = sprintf("https://graph.facebook.com/%s?%s", $login, http_build_query(array(
            'fields'=>'id,first_name,last_name,email,picture,gender',
            'access_token'=>$this->access_token
            )));

            $data = @file_get_contents($url);
        }
        
		if ($data) {
            $json = @json_decode($data, true);

            if (isset($json['id'])) {
                $user = new FacebookUser($this);
                $user->setUserID($json['id']);
                $user->setFirstName($json['first_name']);
                $user->setLastName($json['last_name']);
                if (isset($json['email'])) {
                    $user->setEmail($json['email']);
                }
                return $user;
            }        
        }
        
        return false;
    }
Example #2
0
 private function parseUser($entry)
 {
     $user = new FacebookUser();
     $user->setUserID($entry['id']);
     $user->setName($entry['name']);
     $user->setImageURL(ImageLoader::cacheImage('https://graph.facebook.com/' . $entry['id'] . '/picture?type=square', array()));
     return $user;
 }