Example of how to globally replace pictures with meez avatars

pillarsdotnet - October 15, 2008 - 20:51
Project:Meez Integration
Version:6.x-1.x-dev
Component:Documentation
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

On my personal website I decided to globally show the Meez Avatar instead of a user-uploadable picture. Since the process wasn't intuitively obvious (to me, at least), I thought you might want to include my example in your documentation.

The following example assumes that you are using a theme named "MYTHEMENAME" with the phptemplate theme engine.

  1. Install meez integration module
  2. Visit admin/user/profile/add/textfield to add a profile field to hold your Meez username. I filled in the form as follows:
    Category: Avatar
    Title: Meez Username
    Form name: profile_meez
    Explanation: Go to <a href="http://www.meez.com/" target=_blank>www.meez.com</a>, create an account, and build an avatar.  Then come back here and fill in your Meez username to link the newly-built avatar to your account here.
    Visibility: (*) Hidden
  3. In your theme directory, add the following to your template.php file:
    Note: if your template.php file already has a MYTHEMENAME_theme() function, just combine its contents with the one provided here.
    <?php
    /* Add custom theme hooks */
    function MYTHEMENAME_theme(&$existing, $theme, $path) {
     
    /* Add hooks for custom-themed user picture */
      
    $hooks['user_picture'] = array(
       
    'arguments' => array('account' => NULL),
       
    'preprocess functions' => array('MYTHEMENAME_preprocess_user_picture'),
       
    'template' => 'user-picture',
      );
    }
    function
    MYTHEMENAME_preprocess_user_picture(&$vars, $hook) {
     
    /* replace picture with Meez avatar */
     
    $imgattr = array('class'=>'picture');
     
    $account = $vars['account'];
     
    $data = unserialize($account->data);
      if (isset(
    $data['avatars']['head_sm'])) {
       
    $head_sm = $data['avatars']['head_sm'];
       
    $imgsrc = trim($head_sm->src);
       
    $imgattr['width'] = $head_sm->width;
       
    $imgattr['height'] = $head_sm->height;
      }
      else {
       
    $imgsrc = variable_get('user_picture_default', '');
      }

      if (isset(
    $imgsrc)) {
       
    $picture = theme('image',$imgsrc,'avatar','',$imgattr,FALSE);
        if (isset(
    $account->name)) {
         
    $name = $account->name;
         
    $alt = t("@user's profile", array('@user' => $name));
          if (!empty(
    $account->uid) && user_access('access user profiles')) {
           
    $picture= l($picture, "user/$account->uid", array('alt' => $alt, 'title' => $alt, 'html'=>TRUE));
          }
        }
       
    $vars['picture'] = $picture;
      }
    }
    ?>
  4. In your theme directory, create a file called user-picture.tpl.php and paste the following code into it:
    <?php
    if (isset($picture)) { print $picture; }
    ?>
  5. If you use APC with apc.file_update_protection = 0 then you need to restart your webserver at this point.
  6. Visit admin/settings/performance and click on the Clear Cache button.
  7. Visit admin/user/settings and make sure that Picture support is (*) Enabled.
  8. Visit admin/build/themes/settings and make sure that Display post information on is checked for at least one content type. Also check make sure that your MYTHEMENAME configuration has User pictures in posts and/or User pictures in comments checked.
  9. Visit meez.com and create an Avatar for yourself
  10. Update your My Account settings to add your Meez Username to your profile.
  11. Create a test page/comment that has Display post information enabled and your Meez Avatar should appear.

#1

pillarsdotnet - October 16, 2008 - 04:50

Added book page at http://drupal.org/node/321908

#2

greggles - October 16, 2008 - 15:22

Thanks.

The README.txt file has a lot of similar information though I think it's out of date for Drupal 6.x.

Could you provide this as a patch to README.txt for the 6.x version? I generally prefer to keep all the docs in the same place with the module.

#3

pillarsdotnet - October 16, 2008 - 17:40
Status:active» needs review

Okay, here's a patch.

AttachmentSize
meez-README.txt-improvement.diff 2.22 KB
 
 

Drupal is a registered trademark of Dries Buytaert.