How to get onlinestatus on custom profile nodes?
hadishon - April 23, 2006 - 06:03
| Project: | Onlinestatus Indicator |
| Version: | 5.x-1.0 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
How can I get the onlinestatus to show on custom profile nodes (http://drupal.org/node/35728)?

#1
When you open the Users Profilepage, the module calls theme('onlinestatus_profile',$user).
If you are satisfied with the standard output of my module, use this code.
If not look at the theme_onlinestatus_profile function:
function theme_onlinestatus_profile($user) {$items = array();
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','onlinestatus').'/style.css);</style>');
foreach (onlinestatus_get_messengers(true) as $messenger => $title) {
if (empty ($user->$messenger)) {
continue;
}
$status = onlinestatus_messenger('status', $messenger, $user);
$image = theme('onlinestatus_indicator', $user, $messenger);
$url = onlinestatus_messenger('url', $messenger, $user);
$items[] = array(
'value' => sprintf('%s <a href="%s">%s (%s)</a>', $image, $url, $user->$messenger, $status),
);
}
return array(t('Online Status') => $items);
}
onlinestatus_get_messengers(true) returns an associative array with all active Messangers.
$user->$messenger could be $user->icq for example and contains the users ICQ UID.
Possible Values are: aim, icq, gtalk, jabber, msn, skype, yahoo, xfire
onlinestatus_messenger('status', $messenger, $user) returns 'online','offline', or 'unknown'
theme('onlinestatus_indicator', $user, $messenger) return an image (red flower for offline ICQ users for example)
onlinestatus_messenger('url', $messenger, $user) creates an URL that launches up your Messenger so you can talk to the user.
I had not tried to use this module in an custom profile page yet, i will tried this out soon and add a documentation Page for it.
#2
I don't know how to call drupal functions yet. I tried a few things, they all didn't work. These are what I tried:
<?php print t('onlinestatus_profile',$user); ?><?php print theme('onlinestatus_profile',$user); ?><?phpfunction theme_onlinestatus_profile($user) {
$items = array();
drupal_set_html_head('<style type="text/css">@import url('.drupal_get_path('module','onlinestatus').'/style.css);</style>');
foreach (onlinestatus_get_messengers(true) as $messenger => $title) {
if (empty ($user->$messenger)) {
continue;
}
$status = onlinestatus_messenger('status', $messenger, $user);
$image = theme('onlinestatus_indicator', $user, $messenger);
$url = onlinestatus_messenger('url', $messenger, $user);
$items[] = array(
'value' => sprintf('%s <a href="%s">%s (%s)</a>', $image, $url, $user->$messenger, $status),
);
}
return array(t('Online Status') => $items);
}
?>
The standard display is fine, I just need to get it to display on a custom profile node.
Thanks
#3
I'm currently working on a complete documentation, in the meanwhile some snipplets:
Show the Users AIM Account:
<div class="fields">AIM: <?php print $user->aim ?></div>Show the Users AIM Onlinstatus Indicator:
<?php print theme('onlinestatus_indicator', $user, 'aim') ?>The same Output as the original theme(onlinestatus_profile):
<?phpforeach (onlinestatus_get_messengers(true) as $messenger => $title) {
if (empty ($user->$messenger)) {
continue;
}
$status = onlinestatus_messenger('status', $messenger,$user);
$image = theme('onlinestatus_indicator', $user, $messenger);
$url = onlinestatus_messenger('url', $messenger, $user);
echo sprintf('<div>%s <a href="%s">%s (%s)</a></div>', $image, $url, $user->$messenger, $status);
}
?>
#4
This is the code I used, although it seems a bit hackish and unnecessary.
<?php$onlinestatus = theme_onlinestatus_profile($user);
$services = $onlinestatus['Online Status'];
foreach ($services as $service) {
print $service['value'];
}
?>
#5
closing the open strong tag above - hope this works
#6
#7
I've tried the code listed here, but it returns the online status of the current user instead of the online status of the user who's profile is being viewed. Is there an update to this code?