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


PHP Parser::extensionSubstitution方法代码示例

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


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

示例1: expand


//.........这里部分代码省略.........
                     } else {
                         $out .= $ret['text'];
                     }
                 }
             } elseif ($contextNode->nodeName == 'comment') {
                 # HTML-style comment
                 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
                 # Not in RECOVER_COMMENTS mode (msgnw) though.
                 if (($this->parser->ot['html'] || $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() || $flags & PPFrame::STRIP_COMMENTS) && !($flags & PPFrame::RECOVER_COMMENTS)) {
                     $out .= '';
                 } elseif ($this->parser->ot['wiki'] && !($flags & PPFrame::RECOVER_COMMENTS)) {
                     # Add a strip marker in PST mode so that pstPass2() can
                     # run some old-fashioned regexes on the result.
                     # Not in RECOVER_COMMENTS mode (extractSections) though.
                     $out .= $this->parser->insertStripItem($contextNode->textContent);
                 } else {
                     # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
                     $out .= $contextNode->textContent;
                 }
             } elseif ($contextNode->nodeName == 'ignore') {
                 # Output suppression used by <includeonly> etc.
                 # OT_WIKI will only respect <ignore> in substed templates.
                 # The other output types respect it unless NO_IGNORE is set.
                 # extractSections() sets NO_IGNORE and so never respects it.
                 if (!isset($this->parent) && $this->parser->ot['wiki'] || $flags & PPFrame::NO_IGNORE) {
                     $out .= $contextNode->textContent;
                 } else {
                     $out .= '';
                 }
             } elseif ($contextNode->nodeName == 'ext') {
                 # Extension tag
                 $xpath = new DOMXPath($contextNode->ownerDocument);
                 $names = $xpath->query('name', $contextNode);
                 $attrs = $xpath->query('attr', $contextNode);
                 $inners = $xpath->query('inner', $contextNode);
                 $closes = $xpath->query('close', $contextNode);
                 if ($flags & PPFrame::NO_TAGS) {
                     $s = '<' . $this->expand($names->item(0), $flags);
                     if ($attrs->length > 0) {
                         $s .= $this->expand($attrs->item(0), $flags);
                     }
                     if ($inners->length > 0) {
                         $s .= '>' . $this->expand($inners->item(0), $flags);
                         if ($closes->length > 0) {
                             $s .= $this->expand($closes->item(0), $flags);
                         }
                     } else {
                         $s .= '/>';
                     }
                     $out .= $s;
                 } else {
                     $params = array('name' => new PPNode_DOM($names->item(0)), 'attr' => $attrs->length > 0 ? new PPNode_DOM($attrs->item(0)) : null, 'inner' => $inners->length > 0 ? new PPNode_DOM($inners->item(0)) : null, 'close' => $closes->length > 0 ? new PPNode_DOM($closes->item(0)) : null);
                     $out .= $this->parser->extensionSubstitution($params, $this);
                 }
             } elseif ($contextNode->nodeName == 'h') {
                 # Heading
                 $s = $this->expand($contextNode->childNodes, $flags);
                 # Insert a heading marker only for <h> children of <root>
                 # This is to stop extractSections from going over multiple tree levels
                 if ($contextNode->parentNode->nodeName == 'root' && $this->parser->ot['html']) {
                     # Insert heading index marker
                     $headingIndex = $contextNode->getAttribute('i');
                     $titleText = $this->title->getPrefixedDBkey();
                     $this->parser->mHeadings[] = array($titleText, $headingIndex);
                     $serial = count($this->parser->mHeadings) - 1;
                     $marker = Parser::MARKER_PREFIX . "-h-{$serial}-" . Parser::MARKER_SUFFIX;
                     $count = $contextNode->getAttribute('level');
                     $s = substr($s, 0, $count) . $marker . substr($s, $count);
                     $this->parser->mStripState->addGeneral($marker, '');
                 }
                 $out .= $s;
             } else {
                 # Generic recursive expansion
                 $newIterator = $contextNode->childNodes;
             }
         } else {
             throw new MWException(__METHOD__ . ': Invalid parameter type');
         }
         if ($newIterator !== false) {
             if ($newIterator instanceof PPNode_DOM) {
                 $newIterator = $newIterator->node;
             }
             $outStack[] = '';
             $iteratorStack[] = $newIterator;
             $indexStack[] = 0;
         } elseif ($iteratorStack[$level] === false) {
             // Return accumulated value to parent
             // With tail recursion
             while ($iteratorStack[$level] === false && $level > 0) {
                 $outStack[$level - 1] .= $out;
                 array_pop($outStack);
                 array_pop($iteratorStack);
                 array_pop($indexStack);
                 $level--;
             }
         }
     }
     --$expansionDepth;
     return $outStack[0];
 }
开发者ID:mb720,项目名称:mediawiki,代码行数:101,代码来源:Preprocessor_DOM.php

示例2: tagObj

 /**
  * Parser function to extension tag adaptor
  * @param Parser $parser
  * @param PPFrame $frame
  * @param PPNode[] $args
  * @return string
  */
 public static function tagObj($parser, $frame, $args)
 {
     if (!count($args)) {
         return '';
     }
     $tagName = strtolower(trim($frame->expand(array_shift($args))));
     if (count($args)) {
         $inner = $frame->expand(array_shift($args));
     } else {
         $inner = null;
     }
     $attributes = [];
     foreach ($args as $arg) {
         $bits = $arg->splitArg();
         if (strval($bits['index']) === '') {
             $name = trim($frame->expand($bits['name'], PPFrame::STRIP_COMMENTS));
             $value = trim($frame->expand($bits['value']));
             if (preg_match('/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m)) {
                 $value = isset($m[1]) ? $m[1] : '';
             }
             $attributes[$name] = $value;
         }
     }
     $stripList = $parser->getStripList();
     if (!in_array($tagName, $stripList)) {
         // we can't handle this tag (at least not now), so just re-emit it as an ordinary tag
         $attrText = '';
         foreach ($attributes as $name => $value) {
             $attrText .= ' ' . htmlspecialchars($name) . '="' . htmlspecialchars($value) . '"';
         }
         if ($inner === null) {
             return "<{$tagName}{$attrText}/>";
         }
         return "<{$tagName}{$attrText}>{$inner}</{$tagName}>";
     }
     $params = ['name' => $tagName, 'inner' => $inner, 'attributes' => $attributes, 'close' => "</{$tagName}>"];
     return $parser->extensionSubstitution($params, $frame);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:45,代码来源:CoreParserFunctions.php

示例3: tagObj

 /**
  * Parser function to extension tag adaptor
  * @param Parser $parser
  * @param PPFrame $frame
  * @param array $args
  * @return string
  */
 public static function tagObj($parser, $frame, $args)
 {
     if (!count($args)) {
         return '';
     }
     $tagName = strtolower(trim($frame->expand(array_shift($args))));
     if (count($args)) {
         $inner = $frame->expand(array_shift($args));
     } else {
         $inner = null;
     }
     $stripList = $parser->getStripList();
     if (!in_array($tagName, $stripList)) {
         return '<span class="error">' . wfMessage('unknown_extension_tag', $tagName)->inContentLanguage()->text() . '</span>';
     }
     $attributes = array();
     foreach ($args as $arg) {
         $bits = $arg->splitArg();
         if (strval($bits['index']) === '') {
             $name = trim($frame->expand($bits['name'], PPFrame::STRIP_COMMENTS));
             $value = trim($frame->expand($bits['value']));
             if (preg_match('/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m)) {
                 $value = isset($m[1]) ? $m[1] : '';
             }
             $attributes[$name] = $value;
         }
     }
     $params = array('name' => $tagName, 'inner' => $inner, 'attributes' => $attributes, 'close' => "</{$tagName}>");
     return $parser->extensionSubstitution($params, $frame);
 }
开发者ID:whysasse,项目名称:kmwiki,代码行数:37,代码来源:CoreParserFunctions.php

示例4: expand


//.........这里部分代码省略.........
                     $newIterator = $this->virtualBracketedImplode('{{{', '|', '}}}', $bits['title'], $bits['parts']);
                 } else {
                     $ret = $this->parser->argSubstitution($bits, $this);
                     if (isset($ret['object'])) {
                         $newIterator = $ret['object'];
                     } else {
                         $out .= $ret['text'];
                     }
                 }
             } elseif ($contextNode->name == 'comment') {
                 # HTML-style comment
                 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
                 # Not in RECOVER_COMMENTS mode (msgnw) though.
                 if (($this->parser->ot['html'] || $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() || $flags & PPFrame::STRIP_COMMENTS) && !($flags & PPFrame::RECOVER_COMMENTS)) {
                     $out .= '';
                 } elseif ($this->parser->ot['wiki'] && !($flags & PPFrame::RECOVER_COMMENTS)) {
                     # Add a strip marker in PST mode so that pstPass2() can
                     # run some old-fashioned regexes on the result.
                     # Not in RECOVER_COMMENTS mode (extractSections) though.
                     $out .= $this->parser->insertStripItem($contextNode->firstChild->value);
                 } else {
                     # Recover the literal comment in RECOVER_COMMENTS and pre+no-remove
                     $out .= $contextNode->firstChild->value;
                 }
             } elseif ($contextNode->name == 'ignore') {
                 # Output suppression used by <includeonly> etc.
                 # OT_WIKI will only respect <ignore> in substed templates.
                 # The other output types respect it unless NO_IGNORE is set.
                 # extractSections() sets NO_IGNORE and so never respects it.
                 if (!isset($this->parent) && $this->parser->ot['wiki'] || $flags & PPFrame::NO_IGNORE) {
                     $out .= $contextNode->firstChild->value;
                 } else {
                     // $out .= '';
                 }
             } elseif ($contextNode->name == 'ext') {
                 # Extension tag
                 $bits = $contextNode->splitExt() + array('attr' => null, 'inner' => null, 'close' => null);
                 if ($flags & PPFrame::NO_TAGS) {
                     $s = '<' . $bits['name']->firstChild->value;
                     if ($bits['attr']) {
                         $s .= $bits['attr']->firstChild->value;
                     }
                     if ($bits['inner']) {
                         $s .= '>' . $bits['inner']->firstChild->value;
                         if ($bits['close']) {
                             $s .= $bits['close']->firstChild->value;
                         }
                     } else {
                         $s .= '/>';
                     }
                     $out .= $s;
                 } else {
                     $out .= $this->parser->extensionSubstitution($bits, $this);
                 }
             } elseif ($contextNode->name == 'h') {
                 # Heading
                 if ($this->parser->ot['html']) {
                     # Expand immediately and insert heading index marker
                     $s = '';
                     for ($node = $contextNode->firstChild; $node; $node = $node->nextSibling) {
                         $s .= $this->expand($node, $flags);
                     }
                     $bits = $contextNode->splitHeading();
                     $titleText = $this->title->getPrefixedDBkey();
                     $this->parser->mHeadings[] = array($titleText, $bits['i']);
                     $serial = count($this->parser->mHeadings) - 1;
                     $marker = Parser::MARKER_PREFIX . "-h-{$serial}-" . Parser::MARKER_SUFFIX;
                     $s = substr($s, 0, $bits['level']) . $marker . substr($s, $bits['level']);
                     $this->parser->mStripState->addGeneral($marker, '');
                     $out .= $s;
                 } else {
                     # Expand in virtual stack
                     $newIterator = $contextNode->getChildren();
                 }
             } else {
                 # Generic recursive expansion
                 $newIterator = $contextNode->getChildren();
             }
         } else {
             throw new MWException(__METHOD__ . ': Invalid parameter type');
         }
         if ($newIterator !== false) {
             $outStack[] = '';
             $iteratorStack[] = $newIterator;
             $indexStack[] = 0;
         } elseif ($iteratorStack[$level] === false) {
             // Return accumulated value to parent
             // With tail recursion
             while ($iteratorStack[$level] === false && $level > 0) {
                 $outStack[$level - 1] .= $out;
                 array_pop($outStack);
                 array_pop($iteratorStack);
                 array_pop($indexStack);
                 $level--;
             }
         }
     }
     --$expansionDepth;
     return $outStack[0];
 }
开发者ID:mb720,项目名称:mediawiki,代码行数:101,代码来源:Preprocessor_Hash.php

示例5: expand


//.........这里部分代码省略.........
             } elseif ($contextNode->nodeName == 'comment') {
                 # HTML-style comment
                 # Remove it in HTML, pre+remove and STRIP_COMMENTS modes
                 if ($this->parser->ot['html'] || $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() || $flags & PPFrame::STRIP_COMMENTS) {
                     # RTE (Rich Text Editor) - begin
                     # @author: Inez Korczyński
                     global $wgRTEParserEnabled;
                     if (!empty($wgRTEParserEnabled)) {
                         if (strlen($out) === 0 || substr($out, -1) == "\n") {
                             if (substr($contextNode->textContent, -1) == "\n") {
                                 $add = "\n";
                                 $text = substr($contextNode->textContent, 0, -1);
                             } else {
                                 $add = "";
                                 $text = $contextNode->textContent;
                             }
                             $dataIdx = RTEData::put('placeholder', array('type' => 'comment', 'wikitext' => $text));
                             $out .= RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx) . $add;
                         } else {
                             RTE::$edgeCases[] = 'COMMENT';
                             $out .= '';
                         }
                     } else {
                         $out .= '';
                     }
                     # RTE - end
                 } elseif ($this->parser->ot['wiki'] && !($flags & PPFrame::RECOVER_COMMENTS)) {
                     $out .= $this->parser->insertStripItem($contextNode->textContent);
                 } else {
                     $out .= $contextNode->textContent;
                 }
             } elseif ($contextNode->nodeName == 'ignore') {
                 # Output suppression used by <includeonly> etc.
                 # OT_WIKI will only respect <ignore> in substed templates.
                 # The other output types respect it unless NO_IGNORE is set.
                 # extractSections() sets NO_IGNORE and so never respects it.
                 if (!isset($this->parent) && $this->parser->ot['wiki'] || $flags & PPFrame::NO_IGNORE) {
                     $out .= $contextNode->textContent;
                 } else {
                     $out .= '';
                 }
             } elseif ($contextNode->nodeName == 'ext') {
                 # Extension tag
                 $xpath = new DOMXPath($contextNode->ownerDocument);
                 $names = $xpath->query('name', $contextNode);
                 $attrs = $xpath->query('attr', $contextNode);
                 $inners = $xpath->query('inner', $contextNode);
                 $closes = $xpath->query('close', $contextNode);
                 $params = array('name' => new PPNode_DOM($names->item(0)), 'attr' => $attrs->length > 0 ? new PPNode_DOM($attrs->item(0)) : null, 'inner' => $inners->length > 0 ? new PPNode_DOM($inners->item(0)) : null, 'close' => $closes->length > 0 ? new PPNode_DOM($closes->item(0)) : null);
                 $out .= $this->parser->extensionSubstitution($params, $this);
                 $RTEext_1 = true;
             } elseif ($contextNode->nodeName == 'h') {
                 # Heading
                 $s = $this->expand($contextNode->childNodes, $flags);
                 # Insert a heading marker only for <h> children of <root>
                 # This is to stop extractSections from going over multiple tree levels
                 if ($contextNode->parentNode->nodeName == 'root' && $this->parser->ot['html']) {
                     # Insert heading index marker
                     $headingIndex = $contextNode->getAttribute('i');
                     $titleText = $this->title->getPrefixedDBkey();
                     $this->parser->mHeadings[] = array($titleText, $headingIndex);
                     $serial = count($this->parser->mHeadings) - 1;
                     $marker = "{$this->parser->mUniqPrefix}-h-{$serial}-" . Parser::MARKER_SUFFIX;
                     $count = $contextNode->getAttribute('level');
                     $s = substr($s, 0, $count) . $marker . substr($s, $count);
                     $this->parser->mStripState->addGeneral($marker, '');
                 }
                 $out .= $s;
             } else {
                 # Generic recursive expansion
                 $newIterator = $contextNode->childNodes;
             }
         } else {
             wfProfileOut(__METHOD__);
             throw new MWException(__METHOD__ . ': Invalid parameter type');
         }
         if ($newIterator !== false) {
             if ($newIterator instanceof PPNode_DOM) {
                 $newIterator = $newIterator->node;
             }
             $outStack[] = '';
             $iteratorStack[] = $newIterator;
             $indexStack[] = 0;
         } elseif ($iteratorStack[$level] === false) {
             // Return accumulated value to parent
             // With tail recursion
             while ($iteratorStack[$level] === false && $level > 0) {
                 $outStack[$level - 1] .= $out;
                 array_pop($outStack);
                 array_pop($iteratorStack);
                 array_pop($indexStack);
                 $level--;
             }
         }
         $RTEext_2 = false;
     }
     --$expansionDepth;
     wfProfileOut(__METHOD__);
     return $outStack[0];
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:101,代码来源:Preprocessor_DOM.php


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