当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Markup_Token::addChild方法代码示例

本文整理汇总了PHP中Zend_Markup_Token::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Markup_Token::addChild方法的具体用法?PHP Zend_Markup_Token::addChild怎么用?PHP Zend_Markup_Token::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend_Markup_Token的用法示例。


在下文中一共展示了Zend_Markup_Token::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _createTree

 /**
  * Parse the token array into a tree
  *
  * @param array $tokens
  *
  * @return void
  */
 public function _createTree()
 {
     foreach ($this->_tokens as $token) {
         // first we want to know if this tag is a stopper, or at least a searched one
         if ($this->_isStopper($token['tag'])) {
             // find the stopper
             $oldItems = array();
             while (!in_array($token['tag'], $this->_tags[$this->_current->getName()]['stoppers'])) {
                 $oldItems[] = clone $this->_current;
                 $this->_current = $this->_current->getParent();
             }
             // we found the stopper, so stop the tag
             $this->_current->setStopper($token['tag']);
             $this->_removeFromSearchedStoppers($this->_current);
             $this->_current = $this->_current->getParent();
             // add the old items again if there are any
             if (!empty($oldItems)) {
                 foreach (array_reverse($oldItems) as $item) {
                     /* @var $token Zend_Markup_Token */
                     $this->_current->addChild($item);
                     $item->setParent($this->_current);
                     $this->_current = $item;
                 }
             }
         } else {
             if ($token['type'] == Zend_Markup_Token::TYPE_TAG) {
                 if ($token['tag'] == self::NEWLINE) {
                     // this is a newline tag, add it as a token
                     $this->_current->addChild(new Zend_Markup_Token("\n", Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
                 } elseif (isset($token['name']) && $token['name'][0] == '/') {
                     // this is a stopper, add it as a empty token
                     $this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
                 } elseif (isset($this->_tags[$this->_current->getName()]['parse_inside']) && !$this->_tags[$this->_current->getName()]['parse_inside']) {
                     $this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
                 } else {
                     // add the tag
                     $child = new Zend_Markup_Token($token['tag'], $token['type'], $token['name'], $token['attributes'], $this->_current);
                     $this->_current->addChild($child);
                     // add stoppers for this tag, if its has stoppers
                     if ($this->_getType($token['name']) == self::TYPE_DEFAULT) {
                         $this->_current = $child;
                         $this->_addToSearchedStoppers($this->_current);
                     }
                 }
             } else {
                 // no tag, just add it as a simple token
                 $this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
             }
         }
     }
 }
开发者ID:arendasistemasintegrados,项目名称:mateusleme,代码行数:58,代码来源:Bbcode.php

示例2: _createTree

 /**
  * Create a tree from the tokenized text
  *
  * @return void
  */
 protected function _createTree()
 {
     $inside = true;
     foreach ($this->_tokens as $key => $token) {
         // first check if the token is a stopper
         if ($this->_isStopper($token, $this->_current)) {
             if ($this->_current->getName() == 'li') {
                 // list items are handled differently
                 if (isset($this->_tokens[$key + 1]) && $this->_tokens[$key + 1]['type'] == Zend_Markup_Token::TYPE_TAG && $this->_tokens[$key + 1]['name'] == 'list') {
                     // the next item is a correct tag
                     $this->_current->setStopper($token['tag']);
                     $this->_current = $this->_current->getParent();
                 } else {
                     // close the list
                     $this->_current->setStopper($token['tag']);
                     $this->_current = $this->_current->getParent()->getParent();
                     // go up in the tree until we found the end
                     while ($this->_isStopper($token, $this->_current)) {
                         $this->_current->setStopper($token['tag']);
                         $this->_current = $this->_current->getParent();
                     }
                 }
             } else {
                 // go up in the tree until we found the end of stoppers
                 while ($this->_isStopper($token, $this->_current)) {
                     $this->_current->setStopper($token['tag']);
                     if (!empty($token['attributes'])) {
                         foreach ($token['attributes'] as $name => $value) {
                             $this->_current->addAttribute($name, $value);
                         }
                     }
                     $this->_current = $this->_current->getParent();
                 }
             }
             $inside = true;
         } elseif ($token['type'] == Zend_Markup_Token::TYPE_TAG && $inside) {
             if ($token['name'] == 'break') {
                 // add the newline and continue parsing
                 $this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
             } else {
                 // handle a list item
                 if ($token['name'] == 'list') {
                     $attributes = array();
                     if (isset($token['attributes']['list'])) {
                         $attributes['list'] = $token['attributes']['list'];
                         unset($token['attributes']['list']);
                     }
                     if ($this->_current->getName() != 'list') {
                         // the list isn't started yet, create it
                         $child = new Zend_Markup_Token('', Zend_Markup_Token::TYPE_TAG, 'list', $attributes, $this->_current);
                         $this->_current->addChild($child);
                         $this->_current = $child;
                     }
                     $token['name'] = 'li';
                 } elseif ($token['name'] == 'img' || $token['name'] == 'url') {
                     $inside = false;
                 }
                 // add the token
                 $child = new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_TAG, $token['name'], $token['attributes'], $this->_current);
                 $this->_current->addChild($child);
                 $this->_current = $child;
             }
         } else {
             // simply add the token as text
             $this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
         }
     }
 }
开发者ID:sepano,项目名称:open-social-media-monitoring,代码行数:73,代码来源:Textile.php


注:本文中的Zend_Markup_Token::addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。