Zend Framework: Zend_View_Helper_Gravatar Component Proposal
| Proposed Component Name | Zend_View_Helper_Gravatar |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_View_Helper_Gravatar |
| Proposers | Marcin Morawski |
| Zend Liaison | TBD |
| Revision | 1.0 - 1 January 2008: Initial Draft. (wiki revision: 24) |
Table of Contents
1. Overview
This view helper receives avatars from Gravatar service.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will return the different closing tag of img dependencies on DOCTYPE of websites.
- This component will check whether email adress is valid.
- This component will not check whether the default imgage option is valid url or is one of the options available(identicon, monsterid, wavatar or 404)
4. Dependencies on Other Framework Components
- Zend_View_Helper_HtmlElement
- Zend_View_Exception
5. Theory of Operation
6. Milestones / Tasks
Milestone 1: [DONE] Proposal finished
Milestone 2: [DONE] Proposal accepted
Milestone 3: [DONE] Working implementation
Milestone 4: [DONE] Unit tests
Milestone 5: [DONE] Documentation
Milestone 6: [DONE] Moved to core
7. Class Index
- Zend_View_Helper_Gravatar
8. Use Cases
9. Class Skeletons
Labels:
None
24 Comments
comments.show.hideDec 18, 2009
Shaun Farrell
Marcin, If you need help on this I will be more than glad to help develop this view helper. One suggestion I would have is to default the avatar to 80px. And check to see if the size of the image is between 1 and 512px
Gravatar Doc - "You can specify a "size" or "s" parameter to the URL between 1 and 512 (pixels.) If you omit this step we use a default size of 80 pixels."
Dec 20, 2009
Marcin Morawski
Thanks for the suggestion.
I changed this. Now default size of image is 80. I also add a validator, so you must set a value between 1 and 512.
This class is finished. You can download it.
I added this class as attachment to this wiki page.
If you want help me you can help me with write documentation and unit test. Of course you can also check this class, but i think, that this class is completed and work nicely
.
Jan 30, 2010
Benjamin Steininger
Would be nice if it supports ssl via api-url: https://secure.gravatar.com/
Mentioned here: http://blog.gravatar.com/#post-150
And what about the rating-parameter ?
Jan 31, 2010
Marcin Morawski
Done
May 12, 2010
Colin Guthrie
Awesome
I was just about to write a similar class and figured I'd check first. Glad I did 
Would be nice to get this added to the main distribution.
Jul 21, 2010
Dolf Schimmel (Freeaqingme)
Why do you want to not use SSL by default?
Jul 22, 2010
Marc Bennewitz (private)
Using the secure url should be part of the options and if not specified it should be auto selected.
Default to:
Jul 31, 2010
Marcin Morawski
implemented
Aug 18, 2010
Marc Bennewitz (private)
Today I looked your code on incubator and I have 2 small explanatory notes:
1. options must be underscored
2. the secure option need 3 different values true, false and null for autodetect
else getSecure returns the wrong value
Aug 18, 2010
Marc Bennewitz (private)
Oh - additionally the main gravator method should return $this ever
and the class should implement the magic method __toString().
Than the following also works:
Aug 19, 2010
Marcin Morawski
I'll do it and:
I remove third parameter(attribs for image). And move it to second parameter(atttribs key).
Then I can use setOptions method to set all options for this class.
Aug 19, 2010
Marc Bennewitz (private)
html attributes should be still separated from gravatar options.
-> Some JS-Libs define special html attributes and this could overlap with gravatar options.
Aug 22, 2010
Marcin Morawski
I was thinking about something like this:
$this->gravatar()->setOptions(
array(
'img_size' => 80,
'default_img' => Zend_View_Helper_Gravatar::DEFAULT_WAVATAR,
........
'attribs' => array('class' => 'gravatar', 'title' => 'title value')
));
Then html attributes are seperated.
I now that html attributes have other function than options for gravatar. Pass it to one parameter may be confusing(even with key attribs).
Aug 22, 2010
Marc Bennewitz (private)
Than your gravatar view helper would be the only view helper (extending HtmlElement) where the attrib parameter must be an option.
-> It should be similar to other view helper based on html element.
Jul 22, 2010
Colin Guthrie
For most uses, this is not needed and add unnecessary overhead at the client side. It also means that round-robin DNS names (e.g. using 0.gravatar.com, 1.gravatar.com etc.) is not possible. Using different host names is something Google recommends as part of it's "Page Speed" metrics. There is obviously a practical limit, but 2 or 3 different domains for loading e.g. 10-20 Gravatars each would seem sensible. Sadly there is only one SSL URL so this technique cannot be used on SSL.
So that is one reason why it may not be nice to be on by default., but that is not to say that it cannot be auto-detected: e.g. if the request is a secure one, then use secure with Gravatar as Marc suggests above.
Aug 18, 2010
Marc Bennewitz (private)
Browsers displays a warning if a ssl page loads insecure content (like the gravatar image)
Aug 18, 2010
Colin Guthrie
Yes I know, that's why I said it should be autodetected rather than on by default. I was trying to point out all the reasons why using SSL by default (even if the request is non-ssl) would be a bad idea. I fully appreciate the need to use SSL on an SSL request.
Aug 01, 2010
Georgy Turevich
Why do you use validation in "view" helper? Typically, validation is used in the model-layer.
I think, it must be removed or must be optional and disabled by default
Aug 02, 2010
Marcin Morawski
Yes, you are right.
I fix it.
Aug 03, 2010
Dolf Schimmel (Freeaqingme)
The CR Team advises accepting this proposal as-is.
Aug 10, 2010
Shahar Evron
Hi,
This looks very good. I needed something just like this and didn't know about your proposal, so I suggested this: http://framework.zend.com/svn/framework/laboratory/Zend_View_Helper_Gravatar/library/Zend/View/Helper/Gravatar.php - I will drop my implementation since it looks like you already did the thinking and got reviewed, but maybe you can take a look at my implementation and borrow something
BTW I don't think it's the view helper's job to validate the email address. My assumption is that an email address being used from a gravater was already validated in the past by the app - e.g. if used for user comments, you probably validate the user's email when accepting the comment in the form or before saving to the DB.
In any case an invalid email address will result in falling back to the default image, and not in some security problem. So I think validating here would be waste of CPU cycles.
Shahar.
Aug 11, 2010
Marcin Morawski
Thanks for sharing.
I borrowed some ideas.
I also don't check email address and image size.
You check image size, but i think that this value also should be set from model/configuration file.
Moreover, if you pass invalid value, this not destroy your application. You get only very small or very big avatar(1px or 512px)
Aug 24, 2010
Marcin Morawski
Last Changes:
Sep 19, 2010
Adam Dyson
I am in the process of building a blog extension for the Magento platform and I just happened to stumble across this page. Thanks for all your efforts, it came in very handy! I've made some minor adjustments to suit my needs, maybe they'll be of some help.