DIsable AutoLinking

http://framework.zend.com/manual/en/zend.application.theory-of-operation.html

Was reading that ... I am still learning here but this seems relevant to what you all and myself have been looking for...though actually doing something with it...lol I will leave it up to you guys...

PHP:
    class My_Resource_View extends Zend_Application_Resource_ResourceAbstract
    {
        protected $_view;
 
        public function init()
        {
            // Return view so bootstrap will store it in the registry
            return $this->getView();
        }
 
        public function getView()
        {
            if (null === $this->_view) {
                $options = $this->getOptions();
                $title  = '';
                if (array_key_exists('title', $options)) {
                    $title = $options['title'];
                    unset($options['title']);
                }
 
                $view = new Zend_View($options);
                $view->doctype('XHTML1_STRICT');
                $view->headTitle($title);
                $view->headLink()->appendStylesheet('/css/site.css');
                $view->headScript()->appendfile('/js/analytics.js');
 
                $viewRenderer =
                    Zend_Controller_Action_HelperBroker::getStaticHelper(
                        'ViewRenderer'
                    );
                $viewRenderer->setView($view);
 
                $this->_view = $view;
            }
            return $this->_view;
        }
    }

if it is not relevant... sorry for getting you excited to see a reply to this thread...
 
I've spent hours to write a complex function (at least for the beginner I am) to make my Picasa BB code working and try to avoid that autolinking problem. It was working fine for a BB code like a picasa slideshow, but for a BB Code that is wrapped with another BB Code it sill had some problems. I try then another way... which didn't work but which gave me a solution, a very simple one, to solve that problem with the BB Code Manager. I'm still doing some tests with my Picasa BB Code and if every thing is ok, I will come back here :)
 
It really works well ^^ I guess it's only in forum view now, which means not in conversation or private message, but it would be very easy to update this code (see my premium bbcode for this).

So step 1: create a 'load_class_model' listener with something like this:
PHP:
<?php
class Sedo_Picasa_Listener_Model
{
    public static function listenModel($class, array &$extend)
    {

    $options = XenForo_Application::get('options');
        

            if ($class == 'XenForo_Model_Post')
              {
            $extend[] = 'Sedo_Picasa_Model_KillAutoLink';
            $extend[] = 'Sedo_Picasa_Model_Post';
              }
              

    } 
}

Step 2: create the extended Post model with something like that:
PHP:
<?php

class Sedo_Picasa_Model_Post extends XFCP_Sedo_Picasa_Model_Post
{
    public function preparePost(array $post, array $thread, array $forum, array $nodePermissions = null, array $viewingUser = null)
    {
        $response = parent::preparePost($post, $thread, $forum, $nodePermissions, $viewingUser);

        if (isset($response['message']))
        {
            $response['message'] = $this->ProtectMyBbCode($response['message'], 'picasa');
        }
        
        return $response;
    }        
}

Step 3: create the extended KillAutoLink Model with a code similar to the following one:
PHP:
<?php
class Sedo_Picasa_Model_KillAutoLink extends XFCP_Sedo_Picasa_Model_KillAutoLink
{
    public static function ProtectMyBbCode($message, $tag)
    {
        $search = '#(\[' . $tag . '(?:.+?)?\])\[url\](.+?\[/' . $tag . '\])\[/url\]#i';
        $replace = '$1$2';

        $message = preg_replace($search, $replace, $message);
        
        return $message;
    }
}
?>

The BB Code manager is working fine after this, grabbing the correct content and attributes for every BB Codes inside a same post :)

I will release soon the picasa BB code to complete this.
 
As I said the above solution only works now with bbcode used in forum view. Now I have to make it work with post preview to avoid problems. I will in the next release of the picasa bbcode and will publish the solution here.

But here is another solution to avoid this auto-linking problem. I've made a kind of framework with two functions:
  • The one you are using for the bbcode callback (you will have to follow the framework)
  • The one that will try to avoid the auto-linking problem (you won't need to modify it)
To allow this framework you will have to edit the library/KingK/BbCodeManager/BbCode/Formatter/base.php to add this little piece of code (at the end for example):
Code:
    protected $_Parser;
 
    public function getParser()
    {
        if (!isset($this->_Parser))
        {
            $this->_Parser = new XenForo_BbCode_Parser($this);
        }
        return $this->_Parser;
    }


To get the framework, download the above archive. There are two files in it:
  1. framework with comments
  2. framework without no comment
Remember, the framework is not perfect, it's just a patch. I think the first method is better (once the preview problem would have been corrected). But both method can be used at the same time (see next release of picasa bbcode).
 

Attachments

I've found a solution, a clean one this time, to disable the autolinking with external bbcodes. The problems was coming from the bbcodes formatters class order. When a post is created, the first class to be called is the abstract one, then the autolinking one, then the main one... with all customized XFCP classes. So the solution is to:
  1. Extend the autolinking class with a getTags function (even if the original autolinking class doesn't have this function, the abstract one has)
  2. Add the new tag to the Tags list with replacing its original callback using this variable: $this->_generalTagCallback
  3. After this, two solutions:
    1. simply extend the $_disableAutoLink variable
    2. create a global variable with a customized tags list, add an array to the customized tags to inform if the autolinking function for this tag must be disabled, extend the function autoLinkTag() and check if the current parsing tag is in the customized tags list and if the autolinking function must be disabled. If it must be disable, simply use "$rendererStates['stopAutoLink'] = true;" before redirecting to the parent class
The code for my personal version of the Customized Bbcodes addon:
PHP:
<?php
 
class KingK_BbCodeManager_BbCode_Formatter_BbCode_AutoLink extends XFCP_KingK_BbCodeManager_BbCode_Formatter_BbCode_AutoLink
{
    protected $__customTags = null;
 
    public function getTags()
    {
        $parentTags = parent::getTags();
           
        if($this->__customTags === null)
        {
            $this->_bakeCustomTags();
        }
       
        if($this->__customTags !== null)
        {
            $tags = array_merge((array) $parentTags, (array) $this->__customTags);
           
            foreach ($tags AS $tagName => &$tag)
            {
                unset($tag['replace'], $tag['callback'], $tag['trimLeadingLinesAfter']);
                if (!empty($this->_overrideCallbacks[$tagName]))
                {
                    $override = $this->_overrideCallbacks[$tagName];
                    if (is_array($override) && $override[0] == '$this')
                    {
                        $override[0] = $this;
                    }
   
                    $tag['callback'] = $override;
                }
                else if ($this->_generalTagCallback)
                {
                    $tag['callback'] = $this->_generalTagCallback;
                }
            }
 
            $this->_tags = $tags;
            return $tags;
        }
 
        return $parentTags;
    }
 
 
    public function _bakeCustomTags()
    {
        $customTags = XenForo_Model::create('KingK_BbCodeManager_Model_CustomBbCode')->getAllCustomBbCodes('strict');
 
        if(!is_array($customTags))
        {
            return false;
        }
 
        $allCustomTags = array();
 
        foreach($customTags AS $custom)
        {
            if((boolean)$custom['active'])
            {
                $allCustomTags[$custom['tag']]['active'] = true;
               
                if($custom['stopAutoLink'])
                {
                    $allCustomTags[$custom['tag']]['stopAutoLink'] = true;   
                }
 
                      if($custom['plainChildren'])
                      {
                          $allCustomTags[$custom['tag']]['plainChildren'] = true;
                      }
                     
                      if($custom['stopSmilies'])
                      {
                          $allCustomTags[$custom['tag']]['stopSmilies'] = true;
                      }
                     
                      if($custom['stopLineBreakConversion'])
                      {
                          $allCustomTags[$custom['tag']]['stopLineBreakConversion'] = true;
                      }
                  }
        }
        $this->__customTags = $allCustomTags;
    }
   
    public function autoLinkTag(array $tag, array $rendererStates)
    {
        if (is_array($this->__customTags)
        && isset($this->__customTags[$tag['tag']]['stopAutoLink'])
        && $this->__customTags[$tag['tag']]['stopAutoLink'] === true
        )
        {
            $rendererStates['stopAutoLink'] = true;
        }
 
        return parent::autoLinkTag($tag, $rendererStates);
    }   
}

=> With this class (which requires a new field inside the database) the disable autolinking is manage from the bbcode configuration. For those who are using customized callback for bbcodes, it's not possible to directly disable the autolinking inside the callback (same problem as described at the beginning of the post). It's of course still possible to use the new option "disable autolinking" from the bbcode configuration.

For those who are using my addon "stop-autolinking-patch", this new solution will prevent to use many regex when display pages BUT I still need to find a solution to modify the XenForo parser properly (if it's possible which I'm not sure) to replace the normal tags inside a bbcode option to some special tags. For example:
From:
Code:
[myBbCode=[specialTag]Caption[/specialTag]]content[/myBbCode]
To:
Code:
[myBbCode={specialTag}Caption{/specialTag}]content[/myBbCode]
 

Attachments

  • ex.webp
    ex.webp
    36.7 KB · Views: 19
Top Bottom