Ejemplo n.º 1
0
 /**
  * Execute the token
  *
  * @param  Zend_Markup_Token $token
  * @return string
  */
 protected function _execute(Zend_Markup_Token $token)
 {
     // first return the normal text tags
     if ($token->getType() == Zend_Markup_Token::TYPE_NONE) {
         return $this->_filter($token->getTag());
     }
     // if the token doesn't have a notation, return the plain text
     if (!isset($this->_markups[$token->getName()])) {
         $oldToken = $this->_token;
         $return = $this->_filter($token->getTag()) . $this->_render($token) . $token->getStopper();
         $this->_token = $oldToken;
         return $return;
     }
     $name = $this->_getMarkupName($token);
     $markup = !$name ? false : $this->_markups[$name];
     $empty = is_array($markup) && array_key_exists('empty', $markup) && $markup['empty'];
     // check if the tag has content
     if (!$empty && !$token->hasChildren()) {
         return '';
     }
     // check for the context
     if (is_array($markup) && !in_array($markup['group'], $this->_groups[$this->_group])) {
         $oldToken = $this->_token;
         $return = $this->_filter($token->getTag()) . $this->_render($token) . $token->getStopper();
         $this->_token = $oldToken;
         return $return;
     }
     // check for the filter
     if (!isset($markup['filter']) || !$markup['filter'] instanceof Zend_Filter_Interface && $markup['filter'] !== false) {
         $this->_markups[$name]['filter'] = $this->getDefaultFilter();
     }
     // save old values to reset them after the work is done
     $oldFilter = $this->_filter;
     $oldGroup = $this->_group;
     $return = '';
     // set the filter and the group
     $this->_filter = $this->getFilter($name);
     if ($group = $this->_getGroup($token)) {
         $this->_group = $group;
     }
     // callback
     if (is_array($markup) && $markup['type'] & self::TYPE_CALLBACK) {
         // load the callback if the tag doesn't exist
         if (!$markup['callback'] instanceof Zend_Markup_Renderer_TokenConverterInterface) {
             $class = $this->getPluginLoader()->load($name);
             $markup['callback'] = new $class();
             if (!$markup['callback'] instanceof Zend_Markup_Renderer_TokenConverterInterface) {
                 require_once 'Zend/Markup/Renderer/Exception.php';
                 throw new Zend_Markup_Renderer_Exception("Callback for tag '{$name}' found, but it isn't valid.");
             }
             if (method_exists($markup['callback'], 'setRenderer')) {
                 $markup['callback']->setRenderer($this);
             }
         }
         if ($markup['type'] && !$empty) {
             $return = $markup['callback']->convert($token, $this->_render($token));
         } else {
             $return = $markup['callback']->convert($token, null);
         }
     } else {
         // replace
         if ($markup['type'] && !$empty) {
             $return = $this->_executeReplace($token, $markup);
         } else {
             $return = $this->_executeSingleReplace($token, $markup);
         }
     }
     // reset to the old values
     $this->_filter = $oldFilter;
     $this->_group = $oldGroup;
     return $return;
 }