• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Change profile URL for user @ tags

#1
I'm running a Xenforo forum that is inbuilt into my own PHP website using my own user log in (with a bridge for XF login) and profile pages: AUSFIFA | Forums

I've managed to change all username links so that they point to my own profile pages instead of Xenforo's.

So rather than "forums/index.php?members/kani.1/", it would point to "profile.php?user=Kani".

The only problem is I can't figure out how to change the URL for when you tag a user. So if you type @AUSFIFA, I want it to link my own profile page instead of Xenforo's.

I've looked everywhere in the code but can't seem to find what I need to be changing.

Thanks.
 
#3
It just uses the standard link system, so edit/extend the member route class.

Liam
I don't really do much work on Xenforo so I'm not sure where I'm meant to be looking. Can you elaborate please?

Where can I find the member route class?

Thanks for the swift response!
 
#5
library/XenForo/Route/Prefix/Members.php

Edit the buildLink method.

Liam
Yep ended up finding it, although one small issue. It prefaces anything the buildLink method returns with "ausfifa.com/forums/index.php?members"? I need to access the site's root directory for profile.php.
 
Last edited:
#6
The buildLink method inside the member route class only gives me the end of the string which is just the ID of the user to serve their profile.

I can't seem to find the method which deals with the entire URL.
 
Last edited:

katsulynx

Well-known member
#7
You could essentially just replace Line 32
PHP:
return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'user_id', 'username');
with
PHP:
return 'members.php?='.$data['user_id'];
Even though it's not recommended to edit XenForo-Files directly.
 
#8
You could essentially just replace Line 32
PHP:
return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'user_id', 'username');
with
PHP:
return 'members.php?='.$data['user_id'];
Even though it's not recommended to edit XenForo-Files directly.
Yeah I did exactly that, the issue is this method only returns the very end of the URL rather than the entire thing. No matter what you return in the method, it always begins with "ausfifa.com/forums/index.php?members". I need to modify the entire URL since my profile page is on the root level of the website: ausfifa.com/profile.php?user=Kani
 

Jeremy

Well-known member
#13
When tagging a user it is actually converted into a BBCode. So when I tag you, @AUSFIFA, it really turns into [USER=71955]AUSFIFA[/USER]. You can exploit this for yourself by extending the formatter that returns BBCode.

This guide will help you along the way for proper implementation:
https://xenforo.com/community/threa...b-code-in-xenforo-a-comprehensive-guide.6320/

However, you want to overwrite renderTagUser or overwrite the tag definition. If you want, something like this should work:

PHP:
<?php

class MyAddon_BbCode_Formatter_BbCode_Base extends XFCP_MyAddon_BbCode_Formatter_BbCode_Base
{
    public function getTags()
    {
        $tags = parent::getTags();
        $tags['user'] = array(
            'hasOption' => true,
            'stopSmilies' => true,
            'callback' => array($this, 'myRenderTagUser')
        );
        
        return $tags;
    }
    
    public function myRenderTagUser(array $tag, array $rendererStates)
    {
        $content = $this->renderSubTree($tag['children'], $rendererStates);
        if ($content === '')
        {
            return '';
        }

        $userId = intval($tag['option']);
        if (!$userId)
        {
            return $content;
        }

        $username = $this->stringifyTree($tag['children']);

        return $this->_wrapInHtml('<a href="http://yoururl.com/members.php?u=' . htmlspecialchars($username) . '" class="username" data-user="' . $userId . ', ' . htmlspecialchars($username) . '">', '</a>', $content);
    }
}
 
#14
When tagging a user it is actually converted into a BBCode. So when I tag you, @AUSFIFA, it really turns into [USER=71955]AUSFIFA[/USER]. You can exploit this for yourself by extending the formatter that returns BBCode.

This guide will help you along the way for proper implementation:
https://xenforo.com/community/threa...b-code-in-xenforo-a-comprehensive-guide.6320/

However, you want to overwrite renderTagUser or overwrite the tag definition. If you want, something like this should work:

PHP:
<?php

class MyAddon_BbCode_Formatter_BbCode_Base extends XFCP_MyAddon_BbCode_Formatter_BbCode_Base
{
    public function getTags()
    {
        $tags = parent::getTags();
        $tags['user'] = array(
            'hasOption' => true,
            'stopSmilies' => true,
            'callback' => array($this, 'myRenderTagUser')
        );
       
        return $tags;
    }
   
    public function myRenderTagUser(array $tag, array $rendererStates)
    {
        $content = $this->renderSubTree($tag['children'], $rendererStates);
        if ($content === '')
        {
            return '';
        }

        $userId = intval($tag['option']);
        if (!$userId)
        {
            return $content;
        }

        $username = $this->stringifyTree($tag['children']);

        return $this->_wrapInHtml('<a href="http://yoururl.com/members.php?u=' . htmlspecialchars($username) . '" class="username" data-user="' . $userId . ', ' . htmlspecialchars($username) . '">', '</a>', $content);
    }
}
Works great but it's including the @ tag in the URL for me? So instead of:
http://www.ausfifa.com/profile.php?user=Member

It comes up as:
http://www.ausfifa.com/profile.php?user=@Member
 

Jeremy

Well-known member
#17
You can disable the keeping of the @ in the options if you prefer the display without it, but that doesn't work retroactively.