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

XF 1.4 Anchor and Goto BBCode

Discussion in 'XenForo Questions and Support' started by Robust, Mar 7, 2015.

  1. Robust

    Robust Well-Known Member

  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
     
  3. Robust

    Robust Well-Known Member

    @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.
     
  4. cclaerhout

    cclaerhout Well-Known Member

    The TinyMCE Quattro addon has one. If you want to check its code, click here and go to line 269.
     
  5. Robust

    Robust Well-Known Member

    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
     
  6. cclaerhout

    cclaerhout Well-Known Member

    @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.
     

Share This Page