0

I'm using Drupal 7 with Blog and Comments and user pictures enabled. The theme is Bartik.

The user pictures are also used in the Flash game that is embedded in my website, so I can't just turn them off.

I'm looking for a way to hide user avatars from guests and web crawlers.

The background is that I've gotten a bill for EUR 1000,- from Getty Images, because one of the users has supposedly used their picture as avatar. I'm not looking for any lawyer or pseudo-lawyer advices here, just for the way to hide user pictures from web crawlers.

I've tried searching in the theme file for picture and bartik_preprocess, but haven't find any hints yet:

# grep -r bartik_preprocess .
./themes/bartik/template.php:function bartik_preprocess_html(&$variables) {
./themes/bartik/template.php:function bartik_preprocess_maintenance_page(&$variables) {
./themes/bartik/template.php:function bartik_preprocess_node(&$variables) {
./themes/bartik/template.php:function bartik_preprocess_block(&$variables) {

and print_r($variables); in the above functions does not contain a "picture".

Also I've tried setting $account->picture = NULL; in the hook_user_view($account, $view_mode, $langcode) hook, but then the picture is hidden for everyone including registered users and also this is for user profiles only, not for blog comments.

2
  • What is the URL for the Avatars? Maybe you can add it to your robots.txt with wildcards * pretty simple? It's not a 100% proof solution, I know, but you can't google them anymore... Oct 18, 2011 at 10:24
  • I don't believe, that Getty Images (or other sue-sharks) web crawler would comply to robots.txt or use a correct User-Agent string. Currently I check for a specific cookie with mod_rewrite: serverfault.com/questions/322477/… Oct 19, 2011 at 8:34

1 Answer 1

2

None of the core themes have all the preprocess functions or template file in use. The best way to find what's available to use is with the devel_themer module.

Here's what devel_themer gave me:

enter image description here

This says we can use template_preprocess_user_image() or user-picture.tpl.php. When doing logic such as this, it's standard to use preprocess functions. When you're changing HTML structure you use template files.

So you can add the following function to your theme and it should hide all user pictures for anonymous users (web scrapers are considered anonymous users).

function YOURTHEME_preprocess_user_picture(&$variables) {
  // this is the currently logged in user
  $user = $variables['user'];

  // this is the user the picture belongs to
  $account = $variables['account'];

  // If the current user is anonymous don't show the user picture
  if ($user->uid == 0) {
    $variables['user_picture'] = NULL;
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.