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


PHP Sanitizer::validateAttributes方法代码示例

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


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

示例1: validateTagAttributes

 /**
  * Take an array of attribute names and values and normalize or discard
  * illegal values for the given element type.
  *
  * - Discards attributes not on a whitelist for the given element
  * - Unsafe style attributes are discarded
  * - Invalid id attributes are re-encoded
  *
  * @param array $attribs
  * @param string $element
  * @return array
  *
  * @todo Check for legal values where the DTD limits things.
  * @todo Check for unique id attribute :P
  */
 static function validateTagAttributes($attribs, $element)
 {
     return Sanitizer::validateAttributes($attribs, Sanitizer::attributeWhitelist($element));
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:19,代码来源:Sanitizer.php

示例2: parserHook

 /**
  * Parser hook
  *
  * @param string $text
  * @param array $args
  * @param Parser $parser
  * @return string
  */
 public static function parserHook($text, $args = array(), $parser)
 {
     global $wgUseTidy;
     // Don't trim leading spaces away, just the linefeeds
     $out = preg_replace('/^\\n+/', '', rtrim($text));
     // Convert deprecated attributes
     if (isset($args['enclose'])) {
         if ($args['enclose'] === 'none') {
             $args['inline'] = true;
         }
         unset($args['enclose']);
     }
     $lexer = isset($args['lang']) ? $args['lang'] : '';
     $result = self::highlight($out, $lexer, $args);
     if (!$result->isGood()) {
         $parser->addTrackingCategory('syntaxhighlight-error-category');
     }
     $out = $result->getValue();
     // HTML Tidy will convert tabs to spaces incorrectly (bug 30930).
     // But the conversion from tab to space occurs while reading the input,
     // before the conversion from 	 to tab, so we can armor it that way.
     if ($wgUseTidy) {
         $out = str_replace("\t", '	', $out);
     }
     // Allow certain HTML attributes
     $htmlAttribs = Sanitizer::validateAttributes($args, array('style', 'class', 'id', 'dir'));
     if (!isset($htmlAttribs['class'])) {
         $htmlAttribs['class'] = self::HIGHLIGHT_CSS_CLASS;
     } else {
         $htmlAttribs['class'] .= ' ' . self::HIGHLIGHT_CSS_CLASS;
     }
     if (!(isset($htmlAttribs['dir']) && $htmlAttribs['dir'] === 'rtl')) {
         $htmlAttribs['dir'] = 'ltr';
     }
     if (isset($args['inline'])) {
         // Enforce inlineness. Stray newlines may result in unexpected list and paragraph processing
         // (also known as doBlockLevels()).
         $out = str_replace("\n", ' ', $out);
         $out = Html::rawElement('code', $htmlAttribs, $out);
     } else {
         // Not entirely sure what benefit this provides, but it was here already
         $htmlAttribs['class'] .= ' ' . 'mw-content-' . $htmlAttribs['dir'];
         // Unwrap Pygments output to provide our own wrapper. We can't just always use the 'nowrap'
         // option (pass 'inline'), since it disables other useful things like line highlighting.
         // Tolerate absence of quotes for Html::element() and wgWellFormedXml=false.
         $m = array();
         if (preg_match('/^<div class="?mw-highlight"?>(.*)<\\/div>$/s', trim($out), $m)) {
             $out = trim($m[1]);
         } else {
             throw new MWException('Unexpected output from Pygments encountered');
         }
         // Use 'nowiki' strip marker to prevent list processing (also known as doBlockLevels()).
         // However, leave the wrapping <div/> outside to prevent <p/>-wrapping.
         $marker = $parser->mUniqPrefix . '-syntaxhighlightinner-' . sprintf('%08X', $parser->mMarkerIndex++) . $parser::MARKER_SUFFIX;
         $parser->mStripState->addNoWiki($marker, $out);
         $out = Html::openElement('div', $htmlAttribs) . $marker . Html::closeElement('div');
     }
     // Register CSS
     $parser->getOutput()->addModuleStyles('ext.pygments');
     return $out;
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:69,代码来源:SyntaxHighlight_GeSHi.class.php


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