Use NP-Gravatar to get the avatar on 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. '"/>
';
- }
- // 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 ".
- // The Gravatar XML-RPC implementation requires API key for
- // 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 ').' "/>;
- // Generating Gravatar URL and specifying size and rating options.
- Echo 'gravatar ('foo @ bar.com ', array ('s' => 200, 'R' => 'PG'). '"/>;
- // Full parameter names are supported, too.
- Echo 'gravatar ('foo @ bar.com ', array ('size' => 100, 'default' => 'identicon'). '"/>;
- // Generating Gravatar URL and specifying file-type extension.
- Echo 'gravatar ('foo @ bar.com ', array ('s' => 200), 'jpg ').' "/>;
- // Above view helper call will produce this URL:
- // Http://www.gravatar.com/avatar/f3ada405ce890b6f8204094deb12d8a8.jpg? S = 200
|