Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: AJ32 on August 16, 2008, 11:48:19 PM

Title: Get a specific user's avatar?
Post by: AJ32 on August 16, 2008, 11:48:19 PM
I'm writing a mod for my SMF 2.0 Beta 3.1 forum, and I need to get a specific user's avatar.
Is there a function in function_db, or a database query, etc. that will do this?

Thanks.  :)
Title: Re: Get a specific user's avatar?
Post by: Nathaniel on August 18, 2008, 08:56:48 AM
If you call the 'loadMemberContext($user_id)' function from 'Subs.php', then you can access a whole lot of information about each user. After you call the function, you can access the information from the $memberContext[] array, indexed by user ids. You want the $memberContext[$user_id]['avatar']['href'] or $memberContext[$user_id]['avatar']['image'] variables to get the avatar information. Its all setup by the 'loadMemberContext()'.
Title: Re: Get a specific user's avatar?
Post by: AJ32 on August 18, 2008, 10:36:09 AM
Thank you, but the picture still doesn't seem to come up, it's probably a problem in my code...


require_once($sourcedir . "/subs.php");

foreach($UserArray as $user)
{
loadMemberContext($user['ID']);

echo '<tr>
<td class="windowbg">
'.$memberContext[$user['ID']].'
</td>';
        }



Thanks!
Title: Re: Get a specific user's avatar?
Post by: Nathaniel on August 18, 2008, 05:22:28 PM
I just realised that you also have to call the loadMemberData() function for each member as well. ;)

Also, you need to use the $memberContext[$user['id']]['avatar']['image'] information.

Try this:
   echo '
   <table>';
   foreach($UserArray as $user)
   {
      loadMemberData($user['id']);
      loadMemberContext($user['id']);
     
      echo '
         <tr>
             <td class="windowbg">
            '.$memberContext[$user['id']]['avatar']['image'].'
             </td>
         </tr>';
      }
   echo '
   </table>';
Title: Re: Get a specific user's avatar?
Post by: AJ32 on August 18, 2008, 05:31:45 PM
Ah, that worked, thank you!

One of the things I wasn't doing was making $memberContext a global! ;)


Thanks!