News:

Wondering if this will always be free?  See why free is better.

Main Menu

query for user avatar

Started by Eudemon, March 08, 2012, 10:08:15 PM

Previous topic - Next topic

Eudemon

when user upload avatar to server, a row is created in attachments table

when their avatar is shown in post, a query should be used to get the info from that table right

i'm trying to find that query string(s)

did a search of keyword "{db_prefix}attachments" in source folder
found a bunch, not sure which one

All Colours Sam

Take a look at Sources/Load.php  loadMemberData() and loadMemberContext()  thats where all the data is loaded, the avatar is a tricky one since not all users upload an avatar, some of them use a generic one or uses an external url:


'avatar' => array(
'name' => $profile['avatar'],
'image' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? '<img class="avatar" src="' . (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) . '" alt="" />' : '') : (stristr($profile['avatar'], 'http://') ? '<img class="avatar" src="' . $profile['avatar'] . '"' . $avatar_width . $avatar_height . ' alt="" />' : '<img class="avatar" src="' . $modSettings['avatar_url'] . '/' . htmlspecialchars($profile['avatar']) . '" alt="" />'),
'href' => $profile['avatar'] == '' ? ($profile['id_attach'] > 0 ? (empty($profile['attachment_type']) ? $scripturl . '?action=dlattach;attach=' . $profile['id_attach'] . ';type=avatar' : $modSettings['custom_avatar_url'] . '/' . $profile['filename']) : '') : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar']),
'url' => $profile['avatar'] == '' ? '' : (stristr($profile['avatar'], 'http://') ? $profile['avatar'] : $modSettings['avatar_url'] . '/' . $profile['avatar'])
),

Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Eudemon

found it in loadMemberData function

two strings
LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
one under ($set == 'normal')
one under ($set == 'profile')

thanks

Eudemon

oh wait, what about the query string when user upload avatar in forum profile
a query should be called to add an entry to attachments table or overwrite(update) if there exist one?

All Colours Sam

That would be funciotn createAttachment()  in Sources/Subs-Post.php
Oh, wouldn't it be great if I *was* crazy? ...then the world would be okay
Suki

Eudemon

hmm, looks like the query within createAttachment function handles normal post attachments too

if you're wondering what i'm doing with these:
i have 2 sites (different domain) use one database in different prefix tables
the second site uses some of first site's tables, to share member data, pm etc
however i didn't share the attachments table
to make avatar shared i used the same paths both site for uploaded avatars
and the second site avatar query point to first site's table
right now can't change the query for upload avatar
i guess i should disable avatar in second site and tell everyone to make avatar changes in the first site and it will appear in the second site

Advertisement: