Advertisement
Guest User

Extended Base Formatter

a guest
Jan 31st, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. class Sedo_Demo_BbCode_Formatter_BaseFilter extends XenForo_BbCode_Formatter_Base
  3. {
  4.     protected $baseFilterAllowedTags = array();
  5.     protected $baseFilterOriginalParentTags;
  6.     protected $baseFilterInvisibleTags = false;
  7.  
  8.     public function setBaseFilterAllowedTags(array $tags)
  9.     {
  10.         $this->baseFilterAllowedTags = $tags;
  11.         $this->_tags = $this->getTags();
  12.     }
  13.  
  14.     public function setBaseFilterInvisible($value = false)
  15.     {
  16.         $this->baseFilterInvisibleTags = $value;
  17.     }
  18.  
  19.     public function getTags()
  20.     {
  21.         $tags = parent::getTags();
  22.        
  23.         if($this->baseFilterOriginalParentTags !== null)
  24.         {
  25.             return $this->_baseFilterTags($this->baseFilterOriginalParentTags);
  26.         }
  27.  
  28.         $this->baseFilterOriginalParentTags = $tags;
  29.         return $this->_baseFilterTags($tags);
  30.     }
  31.  
  32.     public function addCustomTags(array $tags)
  33.     {
  34.         $tags = $this->_baseFilterTags($tags);
  35.         return parent::addCustomTags($tags);
  36.     }  
  37.  
  38.     protected function _baseFilterTags($tags)
  39.     {
  40.         //Raw Bb Code return
  41.         if(!$this->baseFilterInvisibleTags)
  42.         {
  43.             return array_intersect_key($tags, array_flip($this->baseFilterAllowedTags));
  44.         }
  45.  
  46.         //Customized Bb Code return
  47.         foreach($tags as $bbCode => $data)
  48.         {
  49.             if(!in_array($bbCode, $this->baseFilterAllowedTags))
  50.             {
  51.                 if(!isset($tags[$bbCode]['bb_code_mode']))
  52.                 {
  53.                     //Normal Bb Code
  54.                     if(isset($tags[$bbCode]['callback']))
  55.                     {
  56.                         unset($tags[$bbCode]['callback']);
  57.                     }
  58.                     $tags[$bbCode]['replace'] = array('', '');
  59.                 }
  60.                 else
  61.                 {
  62.                     //Custom Bb Code
  63.                     $tags[$bbCode]['bb_code_mode'] = 'replace';
  64.                     $tags[$bbCode]['replace_html'] = '{text}';
  65.                 }
  66.             }
  67.         }
  68.        
  69.         return $tags;      
  70.     }
  71. }
  72. //Zend_Debug::dump($bbCodeFormatter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement