您好,欢迎访问一九零五行业门户网

使用 NP-Gravatar 获取 Gravatar 上的头像

//creating instance:$gravatarservice = new np_service_gravatar_profiles();//changing response format to xml:$gravatarservice->setresponseformat(new np_service_gravatar_profiles_responseformat_xml());//getting profile data.$profile = $gravatarservice->getprofileinfo('foo@bar.com');//$profile is instance of np_gravatar_profile so we can access some of its properties.echo 'id: ' . $profile->id . '
';echo 'username: ' . $profile->getpreferredusername() . '
';echo 'photos:
';foreach($profile->getphotos() as $photo) { echo 'value%20.%20'>
';}//changing response format to json:$gravatarservice->setresponseformat(new np_service_gravatar_profiles_responseformat_json());//getting profile data but forcing raw zend_http_response object to be returned, //by passing boolean true for the second argument of the getprofileinfo() method:$response = $gravatarservice->getprofileinfo('foo@bar.com', true);if ($response instanceof zend_http_response) { //true! //do something}//changing response format to qr code:$gravatarservice->setresponseformat(new np_service_gravatar_profiles_responseformat_qrcode());//qr code response can not be exported np_gravatar_profile object, as that //response format type does not implement //np_service_gravatar_profiles_responseformat_parserinterface interface, //so raw zend_http_response object will allways be returned when using //that response format:$response = $gravatarservice->getprofileinfo('foo@bar.com');echo $response->getheader('content-type'); //prints image/png.
复制代码
//gravatar xml-rpc implementation requires api key for the //authentication proccess. it can be retrieved on the page //for editing profile, on wordpress.com.$apikey = 'someapikey'; $email = 'foo.bar@foobar.com'; //email address associated with the $apikey.//creating instance:$gravatarxmlrpc = new np_service_gravatar_xmlrpc($apikey, $email);//checking whether there's a gravatar account registered with supplied email addresses.$result = $gravatarxmlrpc->exists(array( 'posa.nikola@gmail.com', //that's me. :d 'foo@example.com'));$values = array_values($result);echo (bool)$values[0]; //prints true, as i do have gravatar account. :)echo (bool)$values[1]; //prints false, as that second email address probably doesn't exist.//getting user images on the current account:$images = $gravatarxmlrpc->userimages();//$image is instance of np_service_gravatar_xmlrpc_userimage, //as we didn't pass $raw parameter as true when executing //userimages() method.$image = $images[0];$imageurl = $image->geturl(); //instance of zend_uri_http.echo $image->getrating(); //prints some rating (g, pg, r or x).//saves some image to be a user image for the current account.$this->_gravatarxmlrpc->savedata('path/to/someimage.jpg', np_service_gravatar_xmlrpc::pg_rated);
复制代码
//generating gravatar url.echo 'gravatar('foo@bar.com')%20.%20'>;//generating gravatar url and specifying size and rating options.echo 'gravatar('foo@bar.com',%20array('s'=>200,%20'r'=>'pg'))%20.%20'>;//full parameter names are supported, too.echo 'gravatar('foo@bar.com',%20array('size'=>100,%20'default'=>'identicon'))%20.%20'>;//generating gravatar url and specifying file-type extension.echo 'gravatar('foo@bar.com',%20array('s'=>200),%20'jpg')%20.%20'>;//above view helper call will produce this url://http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8.jpg?s=200
复制代码
其它类似信息

推荐信息