Moved avatar code to function

Fixed bug with global avatars (array was only loaded once)
Added fix to only retrieve users with a gravatar when generating the
cache unless the forum is forcing gravatar use.

Really need punbb to pass more user details to the avatar function