function display_logins(&$qa_content, $useraccount, $mylogins)
    {
        if (!empty($mylogins)) {
            require_once $this->directory . 'qa-open-login.php';
            // display the logins already linked to this user account
            $qa_content['custom_mylogins'] = '<h2>' . qa_lang_html('plugin_open/associated_logins') . '</h2><p>' . qa_lang_html('plugin_open/split_accounts_note') . '</p>';
            $qa_content['form_mylogins'] = array('tags' => 'ENCTYPE="multipart/form-data" METHOD="POST" ACTION="' . qa_self_html() . '" CLASS="open-login-accounts"', 'style' => 'wide', 'hidden' => array('dosplit' => '1'));
            $data = array();
            foreach ($mylogins as $i => $login) {
                $del_html = '';
                $s = qa_open_login_get_new_source($login['source'], $login['identifier']);
                if ($useraccount['sessionsource'] != $s) {
                    $del_html = '<a href="javascript://" onclick="OP_unlink(\'' . $login['source'] . '_' . md5($login['identifier']) . '\')" class="opacxdel qa-form-light-button-reject" title="' . qa_lang_html('plugin_open/unlink_this_account') . '">&nbsp;</a>';
                }
                $data["f{$i}"] = array('label' => qa_open_login::printCode(ucfirst($login['source']), empty($login['ohandle']) ? ucfirst($login['source']) : $login['ohandle'], 'menu', 'view', false) . $del_html, 'type' => 'static', 'style' => 'tall');
            }
            $qa_content['form_mylogins']['fields'] = $data;
            $qa_content['customscriptu'] = '<script type="text/javascript">
				function OP_unlink(id) {
					$(".qa-main form.open-login-accounts>input[name=dosplit]").attr("value", id);
					$(".qa-main form.open-login-accounts").submit();
				}
			</script>';
        }
    }
/**
 * Overrides the default mechanism of logging in from external sources.
 *
 * Adds a different way of tracking the sessions and performs some 
 * additional tasks when creating an user account (setting new fields,
 * extra checks, etc).
 */
function qa_log_in_external_user($source, $identifier, $fields)
{
    require_once QA_INCLUDE_DIR . 'qa-db-users.php';
    $remember = qa_opt('open_login_remember') ? true : false;
    $users = qa_db_user_login_find($source, $identifier);
    $countusers = count($users);
    if ($countusers > 1) {
        qa_fatal_error('External login mapped to more than one user');
    }
    // should never happen
    /*
     * To allow for more than one account from the same openid/openauth provider to be 
     * linked to an Q2A user, we need to override the way session source is stored
     * Supposing userid 01 is linked to 2 yahoo accounts, the session source will be
     * something like 'yahoo-xyz' when logging in with the first yahoo account and
     * 'yahoo-xyt' when logging in with the other.
     */
    $aggsource = qa_open_login_get_new_source($source, $identifier);
    // prepare some data
    if (empty($fields['handle'])) {
        $ohandle = ucfirst($source);
    } else {
        $ohandle = preg_replace('/[\\@\\+\\/]/', ' ', $fields['handle']);
    }
    $oemail = null;
    if (strlen(@$fields['email']) && $fields['confirmed']) {
        // only if email is confirmed
        $oemail = $fields['email'];
    }
    if ($countusers) {
        // user exists so log them in
        //always update email and handle
        if ($oemail) {
            qa_db_user_login_set__open($source, $identifier, 'oemail', $oemail);
        }
        qa_db_user_login_set__open($source, $identifier, 'ohandle', $ohandle);
        qa_set_logged_in_user($users[0]['userid'], $users[0]['handle'], $remember, $aggsource);
    } else {
        // create and log in user
        require_once QA_INCLUDE_DIR . 'qa-app-users-edit.php';
        qa_db_user_login_sync(true);
        $users = qa_db_user_login_find($source, $identifier);
        // check again after table is locked
        if (count($users) == 1) {
            //always update email and handle
            if ($oemail) {
                qa_db_user_login_set__open($source, $identifier, 'oemail', $oemail);
            }
            qa_db_user_login_set__open($source, $identifier, 'ohandle', $ohandle);
            qa_db_user_login_sync(false);
            qa_set_logged_in_user($users[0]['userid'], $users[0]['handle'], $remember, $aggsource);
        } else {
            $handle = qa_handle_make_valid(@$fields['handle']);
            // check if email address already exists
            $emailusers = array();
            if (strlen(@$fields['email']) && $fields['confirmed']) {
                // only if email is confirmed
                $emailusers = qa_db_user_find_by_email_or_oemail__open($fields['email']);
                if (count($emailusers)) {
                    // unset regular email to prevent duplicates
                    unset($fields['email']);
                }
            }
            $userid = qa_create_new_user((string) @$fields['email'], null, $handle, isset($fields['level']) ? $fields['level'] : QA_USER_LEVEL_BASIC, @$fields['confirmed']);
            qa_db_user_set($userid, 'oemail', $oemail);
            qa_db_user_login_add($userid, $source, $identifier);
            qa_db_user_login_set__open($source, $identifier, 'oemail', $oemail);
            qa_db_user_login_set__open($source, $identifier, 'ohandle', $ohandle);
            qa_db_user_login_sync(false);
            $profilefields = array('name', 'location', 'website', 'about');
            foreach ($profilefields as $fieldname) {
                if (strlen(@$fields[$fieldname])) {
                    qa_db_user_profile_set($userid, $fieldname, $fields[$fieldname]);
                }
            }
            if (strlen(@$fields['avatar'])) {
                qa_set_user_avatar($userid, $fields['avatar']);
            }
            qa_set_logged_in_user($userid, $handle, $remember, $aggsource);
            return count($emailusers);
        }
    }
    return 0;
}