MyBB Community Forums

Full Version: Avatars
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

Our website has a PHP script which was initially designed a long time ago for SMF:

        /**
         * Determine the URL of this user's avatar. The algorithm has been ported from Simple Machine
         * Forum's Subs.php, so it should work more or less equal to the forum.
         *
         * @param userId Id of the user to retrieve the avatar url from
         * @return string The user's avatar.
         */
        public static function determineUserAvatar($userId = false) {
            if ($userId == false) {
                if (!isset ($_SESSION ['user_info']['user_id']))
                    return 'https://domain.com/images/no_avatar.jpg';
                
                $userId = $_SESSION ['user_info']['user_id'];
            }
            
            $avatar = $_SERVER ['abc_cache'] -> get ('avatar_' . $userId);
            if ($avatar !== false && !defined('abc_CLEAR_CACHE'))
                return $avatar;
            
            $database = Database::getInstance();
            $result = $database -> query('
                SELECT
                    smf_members.id_member,
                    smf_members.avatar,
                    smf_attachments.id_attach
                FROM
                    abc_website.users_links
                LEFT JOIN
                    abc_forum.smf_members ON smf_members.id_member = users_links.forum_id
                LEFT JOIN
                    abc_forum.smf_attachments ON smf_attachments.id_member = users_links.forum_id
                WHERE
                    users_links.user_id = ' . (int)($userId));
            
            if ($result === false || $result -> num_rows == 0) {
                $_SERVER ['abc_cache'] -> set ('avatar_' . $userId, 'https://domain.com/images/no_avatar.jpg', 3600);
                return 'https://domain.com/images/no_avatar.jpg';
            }
            
            $avatarInfo = $result -> fetch_assoc();
            $avatarImage = '';
            
            if (strlen($avatarInfo['avatar']) > 0)
                $avatarImage = $avatarInfo['avatar'];
            else if (is_numeric ($avatarInfo ['id_attach']) && $avatarInfo ['id_member'] != 0)
                $avatarImage = 'https://forum.domain.com/index.php?action=dlattach;attach=' . $avatarInfo['id_attach'] . ';type=avatar';
            else
                $avatarImage = 'https://domain.com/images/no_avatar.jpg';
            
            $_SERVER ['abc_cache'] -> set ('avatar_' . $userId, $avatarImage, 3600);
            
            return $avatarImage;
        }

We're now using MyBB - what changes need to be made to reflect MyBB rather than SMF?

Thanks.
what exactly is the purpose of the above code ?
(05-26-2016, 02:20 PM).m. Wrote: [ -> ]what exactly is the purpose of the above code ?

To fetch the user's avatar from our MyBB installation which is used on another part of our website (which isn't running MyBB, but in-house PHP).
Anyone?
Very good question. Although maybe I would suggest posting in smf forums (I don't recommend mentioning the switch to mybb) Just ask how to fetch avatars
(05-30-2016, 05:28 AM)izakgewdrick Wrote: [ -> ]Very good question. Although maybe I would suggest posting in smf forums (I don't  recommend  mentioning the switch to mybb) Just ask how to fetch avatars

Thanks, I'll try that

In the mean time, does anyone else have any thoughts?