XF 1.4 Anchor and Goto BBCode

It is following the base href of the page.

What you need is to include the current page URI in the link so it doesn't fall back to the base href. Unfortunately there is no token for this that you can use in the replacement. A PHP Callback is necessary. You could also use javascript but a callback is better.

I can code this up for you if you need help with it.
 
@Jake Bunce Trying to learn PHP :P So I whipped this up with some research and some knowledge, it's far from a callback so let me know if I went about this the wrong way (negative impact on performance, not efficient, redundant, anything like that)

Listener:

Code:
<?php

class GamingForums_BbCode_Listener_BbCode
{
    public static function listen($class, array &$extend)
    {
        if($class == 'XenForo_BbCode_Formatter_Base')
        {
            $extend[] = 'GamingForums_BbCode_Formatter_Base';
        }
    }
}

Code:
<?php

class GamingForums_BbCode_Formatter_Base extends XenForo_BbCode_Formatter_Base
{
    protected $_tags;

    public function getTags()
    {
        $requestPaths = XenForo_Application::get('requestPaths');

        $this->_tags = parent::getTags();
        $this->_tags['goto'] = array(
            'hasOption' => true,
            'replace' => array('<a href="' . $requestPaths['fullUri'] . '#%s">', '</a>')
        );
        $this->_tags['anchor'] = array(
            'hasOption' => true,
            'replace' => array('<a id="%s">', '</a>')
        );
        return $this->_tags;
    }
}

It does seem to work.
 
The above code does seem to work, but the anchor needs text in. Anything I can do to allow an empty anchor tag (since it just needs to be invisible)? I could hide it using CSS if there is no other way I guess, but I'd prefer a way to have empty tags.

@cclaerhout Understanding that is wayy past my expertise :p
 
@Robust
To create an anchor (no option):
Code:
[anchor]test[/anchor]
To go to this anchor (with option):
Code:
[anchor=#test]Click here[/anchor]

P.S: some of the fomatter code will not work on a default XenForo install, more precisely everything between this conditional:
PHP:
if($jsonResponse)
{
//...
}

This part purpose is only to get the correct url when a new post is inserted using ajax.
 
Top Bottom