Skip to end of metadata
Go to start of metadata

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
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Dec 18, 2009

    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."

    1. Dec 20, 2009

      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.

  2. Jan 30, 2010

    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 ?

    1. Jan 31, 2010

      Done

  3. May 12, 2010

    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.

  4. Jul 21, 2010

    Why do you want to not use SSL by default?

    1. Jul 22, 2010

      Using the secure url should be part of the options and if not specified it should be auto selected.

      • add option secure
        Default to:
      1. Jul 31, 2010

        implemented

        1. Aug 18, 2010

          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

          1. Aug 18, 2010

            Oh - additionally the main gravator method should return $this ever
            and the class should implement the magic method __toString().

            Than the following also works:

            1. Aug 19, 2010

              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.

              1. Aug 19, 2010

                html attributes should be still separated from gravatar options.
                -> Some JS-Libs define special html attributes and this could overlap with gravatar options.

                1. Aug 22, 2010

                  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).

                  1. Aug 22, 2010

                    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.

    2. Jul 22, 2010

      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.

      1. Aug 18, 2010

        Browsers displays a warning if a ssl page loads insecure content (like the gravatar image)

        1. Aug 18, 2010

          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.

  5. Aug 01, 2010

    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

    1. Aug 02, 2010

      Yes, you are right.
      I fix it.

  6. Aug 03, 2010

    Community Review Team Recommendation

    The CR Team advises accepting this proposal as-is.

  7. Aug 10, 2010

    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.

    1. Aug 11, 2010

      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)

  8. Aug 24, 2010

    Last Changes:

    • added __toString method
    • added setOptions method
    • restored third parameter(html attributes)
    • now gravatar method returns object
    • fixed set/getSecure
    • changed name of keys options
    • modified Wiki page
  9. Sep 19, 2010

    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.