Advance Profile Kit with Meez Module
cocogodiva - November 25, 2008 - 19:58
| Project: | Meez Integration |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I installed Adv Profile Kit and it's great, is there a way to intergrate the Meez Module with Advance Profile Kit? If the Meez is !empty then "display" user_meez, if "empty" then display uploaded picture. How can I make this work, I haven't been able to figure out how to get this to display. Thanks in advance for your assistance.

#1
The easiest way would be fore the Meez module to implement the author pane hook as described here: http://drupal.org/node/326809 . Then you could just edit advanced_profile_author-pane.tpl.php to choose between the images.
Michelle
#2
Michelle,
Thank you for getting back to me. I apologize for my ignorance, but I'm still getting my wings with Drupal & php, but can you clarify the following for me.
function MODULENAME_preprocess_author_pane(&$variables) = I would change to
"function meez_preprocess_author_pane(&$variables)"?
$variables['MODULENAME_VARIABLENAME'] = MODULENAME_FUNCTION($account);= I would change to
$variables['meez_meezuser'] = meez_FUNCTION($account); / I'm not sure if I change "FUNCTION" and if so to what?
Then save the file as meez.
Also is there anything else that I missed about that I should be changing in the code below and I couldn't locate "advanced_profile_author-pane.tpl.php
Thank you so much again for your help.
<?php
/**
* Implementation of hook_preprocess_author_pane().
*/
function MODULENAME_preprocess_author_pane(&$variables) {
// The full user object for the author
$account = $variables['account'];
$image_path = $variables['image_path'];
$variables['MODULENAME_VARIABLENAME'] = MODULENAME_FUNCTION($account);
}
#3
Well, I moved this here in the hopes that Greg could help you out. I've never even heard of the Meez module before this and am not familiar with its code. Basically you want this added to the meez module:
<?php
/**
* Implementation of hook_preprocess_author_pane().
*/
function meez_preprocess_author_pane(&$variables) {
// The full user object for the author
$account = $variables['account'];
$variables['meez_avatar'] = meez_FUNCTION_TO_GET_AVATAR_HERE($account);
}
?>
I have no idea what the function to get the avatar is. Assuming there is one, of course. That's why I moved it to this queue. :)
advanced_profile_author-pane.tpl.php is in the advanced profile kit module. You'd need to change:
<?php if (!empty($picture)): ?><?php print $picture; ?>
<?php endif; ?>
to something like:
<?php if (!empty($meez_avatar)): ?><?php print $meez_avatar; ?>
<?php elseif (!empty($picture)): ?>
<?php print $picture; ?>
<?php endif; ?>
(Untested just typed in the browser.)
Michelle
#4
Alternately, if Greg doesn't want to add this, you can just put that as yet unknown function call right in advanced_profile_author-pane.tpl.php in place of the variable. :)
Michelle
#5
Michelle.
You are super quick! When I grow up I want to be just like you :-)! I checked the APK & the only thing that I see close to advanced_profile_author-pan.tpl.php is advance_profile_userinfo.tpl and this is what's inside "$picture - returned from theme_user_picture". In the theme there's user-picture.tpl , the following code is ..
<?phpif (isset($picture)) { print $picture; }
?>
You are correct there is a get_avatar function. the code for the meez module is below.
Your #1 FAN :-)
Coco
<?php
// $Id: meez.module,v 1.2.2.1 2007/12/22 19:38:49 greggles Exp $
/**
* Implementation of hook_help().
*/
function meez_help($section) {
switch ($section) {
case 'admin/help#meez':
return t('Allows users to use their meez avatar for your site.');
case 'admin/settings/meez':
return '
'. t('Configure meez.') .'
';
}
}
/**
* Implementation of hook_menu().
*/
function meez_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/meez',
'title' => t('Meez Configuration'),
'description' => t('Configure how the Meez module interacts with your site.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('meez_admin_settings'),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
/**
* Implementation of meez_admin_settings form.
*/
function meez_admin_settings() {
if (user_access('administer site configuration')) {
$form["general"]["meez_profile_field"] = array('#type' => 'textfield',
'#title' => t('Meez profile field name'), '#size' => 50, '#maxlength' => 50,
'#default_value' => variable_get('meez_profile_field', 'profile_meez'),
'#description' => t('The profile field where users store their meez name.'),
);
$form["general"]["meez_avatar_types"] = array('#type' => 'textfield',
'#title' => t('Meez avatar types'), '#size' => 50, '#maxlength' => 50,
'#default_value' => variable_get('meez_avatar_types','head_sm,head_lg,body_sm,body_lg,anim'),
'#description' => t('A comma separated list of the types of avatars that you would like to have imported. Do not separate with spaces. The complete set would be head_sm,head_lg,body_sm,body_lg,anim.'),
);
$form["general"]["meez_avatar_user_page"] = array('#type' => 'textfield',
'#title' => t('Meez avatar to show on the user page'), '#size' => 50, '#maxlength' => 50,
'#default_value' => variable_get('meez_avatar_user_page','body_sm'),
'#description' => t('The avatar to show on the user profile page (e.g. user/1). Leave blank to disable this feature.'),
);
}
return system_settings_form($form);
}
/**
* Implementation of hook_user
*/
function meez_user($op, &$edit, &$account, $category = NULL){
// Load avatars from MEEZ in case there was a change.
switch ($op) {
case 'register':
case 'update':
case 'insert':
// Get the location of the meez in the profile.
$meez_profile_field = variable_get('meez_profile_field', 'profile_meez');
$avatars = array();
// Maybe it's in the edit
if (isset($edit[$meez_profile_field])) {
$avatars = meez_get_avatars($edit[$meez_profile_field]);
$edit = array_merge($edit,array('avatars' => $avatars));
}
break;
case 'view':
if (strlen(variable_get('meez_avatar_user_page','body_sm'))) {
if ($account->avatars[variable_get('meez_avatar_user_page','body_sm')]->src) {
$picture = $account->avatars[variable_get('meez_avatar_user_page','body_sm')]->src;
}
else if (variable_get('user_picture_default', '')) {
$picture = variable_get('user_picture_default', '');
}
if (isset($picture)) {
$alt = t("@user's profile", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
$picture = theme('image', trim($picture), $alt, $alt, '', FALSE);
if (!empty($account->uid) && user_access('access user profiles')) {
$picture = l($picture, "user/$account->uid", array('title' => t("View @user's profile.", array('@user' => $account->name))), NULL, NULL, FALSE, TRUE);
}
$item = array('title' => '',
'value' => $picture,
'class' => 'picture',
);
$fields['My Avatar']['meez_subfield'] = $item;
return $fields;
}
else {
return;
}
}
break;
}
}
/**
* Iterates through a user defined list of avatars to grab
* and then calls the function to grab them.
*/
function meez_get_avatars($av_username=""){
$avatars = array();
$avatar_types = explode(',', variable_get('meez_avatar_types','head_sm,head_lg,body_sm,body_lg,anim'));
if(!empty($av_username)){
foreach($avatar_types as $type){
$avatars[trim($type)] = meez_call_meez_api($av_username,$type);
}
}
return($avatars);
}
/**
* Connect with http://www.meez.com and get a user's meez avatar based on his/her meez username
*/
function meez_call_meez_api($username,$type) {
$meez_api = 'http://partner.meez.com/avatar-ws/partner/getMeezImageURL.jsp';
$avatar_types = array();
$avatar_types = meez_get_types();
$meez_api .= "?username=".$username.
"&viewname=".$avatar_types[$type]->viewname.
"&imageformat=".$avatar_types[$type]->imageformat.
"&width=".$avatar_types[$type]->width.
"&height=".$avatar_types[$type]->height;
$result = drupal_http_request($meez_api);
switch ($result->code) {
case 304:
case 301:
case 200:
case 302:
case 307:
$meez = $avatar_types[$type];
$meez->src = strip_tags($result->data);
$meez->alt = "avatar";
break;
default:
watchdog('meez', t('The meez import seems to be broken, due to "%error".', array('%error' => theme('placeholder', $result->code .' '. $result->error))), WATCHDOG_WARNING);
drupal_set_message(t('The meez import seems to be broken, because of error "%error".', array('%error' => theme('placeholder', $result->code .' '. $result->error))));
}
return $meez;
}
/**
*
*/
function meez_get_types() {
$avatar_types = array();
$avatar_types["head_sm"] = new stdClass();
$avatar_types["head_sm"]->viewname = "headshot";
$avatar_types["head_sm"]->imageformat = "JPG";
$avatar_types["head_sm"]->width = "48";
$avatar_types["head_sm"]->height = "48";
$avatar_types["head_lg"] = new stdClass();
$avatar_types["head_lg"]->viewname = "headshot";
$avatar_types["head_lg"]->imageformat = "JPG";
$avatar_types["head_lg"]->width = "100";
$avatar_types["head_lg"]->height = "100";
$avatar_types["body_sm"] = new stdClass();
$avatar_types["body_sm"]->viewname = "bodyshot";
$avatar_types["body_sm"]->imageformat = "JPG";
$avatar_types["body_sm"]->width = "175";
$avatar_types["body_sm"]->height = "260";
$avatar_types["body_lg"] = new stdClass();
$avatar_types["body_lg"]->viewname = "bodyshot";
$avatar_types["body_lg"]->imageformat = "JPG";
$avatar_types["body_lg"]->width = "300";
$avatar_types["body_lg"]->height = "400";
$avatar_types["anim"] = new stdClass();
$avatar_types["anim"]->viewname = "bodyshot";
$avatar_types["anim"]->imageformat = "AGIF";
$avatar_types["anim"]->width = "300";
$avatar_types["anim"]->height = "400";
return $avatar_types;
}
#6
Oh, sorry, I missed that you were using an old version of APK. The hook I gave you will only work with the current version. You can call Meez's code from within the userinfo template but you'll have to modify the one in the module because there were issues with that old version not recognizing the version in your theme.
Michelle
#7
The current meez_get_avatars function isn't about returning the path to the image...it's about getting the image tag for the image.
Providing this support will require some refactoring of the code.
@cocogodiva - can you review and test this code? You would need to use the newly created meez_get_img function to get the image file.
#8
Just to be clear, what my code above is expecting is the equivalent of theme_user_picture(). Not that it _has_ to be that but that's what I was assuming would be put there. So it's basically saying use the Meez HTML if there is any and use the default $picture if there isn't.
Michelle
#9
Greggles,
Of course I can review and test the could.
Just to verify, the ++ in patch are the snippets of code that I will need to add to the meez module and will I be adding the meez_get_img function to meez module (do I need to remove the function meez_get_avatars or can it remain?). I will also need to add the meez_get_img function to the userinfo template?
@Michelle.. since the advance_profile_userinfo.tpl doesn't exist, I will need to add the following code in the advance_profile_userinfo.tpl - where currently it reads "$picture - returned from theme_user_picture", I will need to replace that with this
<?phpif (!empty($meez_avatar)):
?>
<?phpprint $meez_avatar;
?>
<?phpelseif (!empty($picture)):
?>
<?phpprint $picture;
?>
<?phpendif;
?>
I'm off to fiddle with the code. You guys ROCK!
#10
@cocogodiva - As I said, the hook for Meez to create the variable won't work in old versions of APK. That was added as part of the rewrite. You will need to add the full function call yourself.
Michelle
#11
Greggles,
I've been away but I will be testing the patch shortly. I'll keep you posted.