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


PHP Sanitizer::removeHTMLcomments方法代码示例

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


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

示例1: removeHTMLtags

 /**
  * Cleans up HTML, removes dangerous tags and attributes, and
  * removes HTML comments
  * @param string $text
  * @param callable $processCallback Callback to do any variable or parameter
  *   replacements in HTML attribute values
  * @param array|bool $args Arguments for the processing callback
  * @param array $extratags For any extra tags to include
  * @param array $removetags For any tags (default or extra) to exclude
  * @return string
  */
 public static function removeHTMLtags($text, $processCallback = null, $args = array(), $extratags = array(), $removetags = array())
 {
     extract(self::getRecognizedTagData($extratags, $removetags));
     # Remove HTML comments
     $text = Sanitizer::removeHTMLcomments($text);
     $bits = explode('<', $text);
     $text = str_replace('>', '&gt;', array_shift($bits));
     if (!MWTidy::isEnabled()) {
         $tagstack = $tablestack = array();
         foreach ($bits as $x) {
             $regs = array();
             # $slash: Does the current element start with a '/'?
             # $t: Current element name
             # $params: String between element name and >
             # $brace: Ending '>' or '/>'
             # $rest: Everything until the next element of $bits
             if (preg_match(self::ELEMENT_BITS_REGEX, $x, $regs)) {
                 list(, $slash, $t, $params, $brace, $rest) = $regs;
             } else {
                 $slash = $t = $params = $brace = $rest = null;
             }
             $badtag = false;
             if (isset($htmlelements[$t = strtolower($t)])) {
                 # Check our stack
                 if ($slash && isset($htmlsingleonly[$t])) {
                     $badtag = true;
                 } elseif ($slash) {
                     # Closing a tag... is it the one we just opened?
                     MediaWiki\suppressWarnings();
                     $ot = array_pop($tagstack);
                     MediaWiki\restoreWarnings();
                     if ($ot != $t) {
                         if (isset($htmlsingleallowed[$ot])) {
                             # Pop all elements with an optional close tag
                             # and see if we find a match below them
                             $optstack = array();
                             array_push($optstack, $ot);
                             MediaWiki\suppressWarnings();
                             $ot = array_pop($tagstack);
                             MediaWiki\restoreWarnings();
                             while ($ot != $t && isset($htmlsingleallowed[$ot])) {
                                 array_push($optstack, $ot);
                                 MediaWiki\suppressWarnings();
                                 $ot = array_pop($tagstack);
                                 MediaWiki\restoreWarnings();
                             }
                             if ($t != $ot) {
                                 # No match. Push the optional elements back again
                                 $badtag = true;
                                 MediaWiki\suppressWarnings();
                                 $ot = array_pop($optstack);
                                 MediaWiki\restoreWarnings();
                                 while ($ot) {
                                     array_push($tagstack, $ot);
                                     MediaWiki\suppressWarnings();
                                     $ot = array_pop($optstack);
                                     MediaWiki\restoreWarnings();
                                 }
                             }
                         } else {
                             MediaWiki\suppressWarnings();
                             array_push($tagstack, $ot);
                             MediaWiki\restoreWarnings();
                             # <li> can be nested in <ul> or <ol>, skip those cases:
                             if (!isset($htmllist[$ot]) || !isset($listtags[$t])) {
                                 $badtag = true;
                             }
                         }
                     } else {
                         if ($t == 'table') {
                             $tagstack = array_pop($tablestack);
                         }
                     }
                     $newparams = '';
                 } else {
                     # Keep track for later
                     if (isset($tabletags[$t]) && !in_array('table', $tagstack)) {
                         $badtag = true;
                     } elseif (in_array($t, $tagstack) && !isset($htmlnest[$t])) {
                         $badtag = true;
                         # Is it a self closed htmlpair ? (bug 5487)
                     } elseif ($brace == '/>' && isset($htmlpairs[$t])) {
                         $badtag = true;
                     } elseif (isset($htmlsingleonly[$t])) {
                         # Hack to force empty tag for unclosable elements
                         $brace = '/>';
                     } elseif (isset($htmlsingle[$t])) {
                         # Hack to not close $htmlsingle tags
                         $brace = null;
//.........这里部分代码省略.........
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:101,代码来源:Sanitizer.php

示例2: splitSummaryContent

	/**
	 * Split summary of a wikilog article from the contents.
	 * If summary is part of the parser output, use it; otherwise, try to
	 * extract it from the content text (section zero, before the first
	 * heading).
	 *
	 * @param $parserOutput ParserOutput object.
	 * @return Two-element array with summary and content. Summary may be
	 *   NULL if nonexistent.
	 */
	public static function splitSummaryContent( $parserOutput ) {
		global $wgUseTidy;

		$content = Sanitizer::removeHTMLcomments( $parserOutput->getText() );

		if ( isset( $parserOutput->mExtWikilog ) && $parserOutput->mExtWikilog->mSummary ) {
			# Parser output contains wikilog output and summary, use it.
			$summary = Sanitizer::removeHTMLcomments( $parserOutput->mExtWikilog->mSummary );
		} else {
			# Try to extract summary from the content text.
			$blocks = preg_split( '/<(h[1-6]).*?>.*?<\\/\\1>/i', $content, 2 );
			if ( count( $blocks ) > 1 ) {
				# Long article with multiple sections, use only the first one.
				$summary = $blocks[0];
				# It is possible for the regex to split on a heading that is
				# not a child of the root element (e.g. <div><h2>...</h2>
				# </div> leaving an open <div> tag). In order to handle such
				# cases, we pass the summary through tidy if it is available.
				if ( $wgUseTidy ) {
					$summary = MWTidy::tidy( $summary );
				}
			} else {
				# Short article with a single section, use no summary and
				# leave to the caller to decide what to do.
				$summary = null;
			}
		}

		return array( $summary, $content );
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:40,代码来源:WikilogUtils.php

示例3: removeHTMLtags

 /**
  * Cleans up HTML, removes dangerous tags and attributes, and
  * removes HTML comments
  * @private
  * @param $text String
  * @param $processCallback Callback to do any variable or parameter replacements in HTML attribute values
  * @param $args Array for the processing callback
  * @param $extratags Array for any extra tags to include
  * @param $removetags Array for any tags (default or extra) to exclude
  * @return string
  */
 static function removeHTMLtags($text, $processCallback = null, $args = array(), $extratags = array(), $removetags = array())
 {
     global $wgUseTidy;
     static $htmlpairsStatic, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags, $htmllist, $listtags, $htmlsingleallowed, $htmlelementsStatic, $staticInitialised;
     wfProfileIn(__METHOD__);
     if (!$staticInitialised) {
         $htmlpairsStatic = array('b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rt', 'rb', 'rp', 'p', 'span', 'abbr', 'dfn', 'kbd', 'samp', 'thead', 'tbody', 'tfoot');
         $htmlsingle = array('br', 'hr', 'li', 'dt', 'dd');
         $htmlsingleonly = array('br', 'hr');
         $htmlnest = array('table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'dl', 'font', 'big', 'small', 'sub', 'sup', 'span');
         $tabletags = array('td', 'th', 'tr');
         $htmllist = array('ul', 'ol');
         $listtags = array('li');
         global $wgAllowImageTag;
         if ($wgAllowImageTag) {
             $htmlsingle[] = 'img';
             $htmlsingleonly[] = 'img';
         }
         $htmlsingleallowed = array_unique(array_merge($htmlsingle, $tabletags));
         $htmlelementsStatic = array_unique(array_merge($htmlsingle, $htmlpairsStatic, $htmlnest));
         # Convert them all to hashtables for faster lookup
         $vars = array('htmlpairsStatic', 'htmlsingle', 'htmlsingleonly', 'htmlnest', 'tabletags', 'htmllist', 'listtags', 'htmlsingleallowed', 'htmlelementsStatic');
         foreach ($vars as $var) {
             ${$var} = array_flip(${$var});
         }
         $staticInitialised = true;
     }
     # Populate $htmlpairs and $htmlelements with the $extratags and $removetags arrays
     $extratags = array_flip($extratags);
     $removetags = array_flip($removetags);
     $htmlpairs = array_merge($extratags, $htmlpairsStatic);
     $htmlelements = array_diff_key(array_merge($extratags, $htmlelementsStatic), $removetags);
     # Remove HTML comments
     $text = Sanitizer::removeHTMLcomments($text);
     $bits = explode('<', $text);
     $text = str_replace('>', '&gt;', array_shift($bits));
     if (!$wgUseTidy) {
         $tagstack = $tablestack = array();
         foreach ($bits as $x) {
             $regs = array();
             # $slash: Does the current element start with a '/'?
             # $t: Current element name
             # $params: String between element name and >
             # $brace: Ending '>' or '/>'
             # $rest: Everything until the next element of $bits
             if (preg_match('!^(/?)(\\w+)([^>]*?)(/{0,1}>)([^<]*)$!', $x, $regs)) {
                 list(, $slash, $t, $params, $brace, $rest) = $regs;
             } else {
                 $slash = $t = $params = $brace = $rest = null;
             }
             $badtag = false;
             if (isset($htmlelements[$t = strtolower($t)])) {
                 # Check our stack
                 if ($slash && isset($htmlsingleonly[$t])) {
                     $badtag = true;
                 } elseif ($slash) {
                     # Closing a tag... is it the one we just opened?
                     $ot = @array_pop($tagstack);
                     if ($ot != $t) {
                         if (isset($htmlsingleallowed[$ot])) {
                             # Pop all elements with an optional close tag
                             # and see if we find a match below them
                             $optstack = array();
                             array_push($optstack, $ot);
                             $ot = @array_pop($tagstack);
                             while ($ot != $t && isset($htmlsingleallowed[$ot])) {
                                 array_push($optstack, $ot);
                                 $ot = @array_pop($tagstack);
                             }
                             if ($t != $ot) {
                                 # No match. Push the optional elements back again
                                 $badtag = true;
                                 while ($ot = @array_pop($optstack)) {
                                     array_push($tagstack, $ot);
                                 }
                             }
                         } else {
                             @array_push($tagstack, $ot);
                             # <li> can be nested in <ul> or <ol>, skip those cases:
                             if (!isset($htmllist[$ot]) || !isset($listtags[$t])) {
                                 $badtag = true;
                             }
                         }
                     } else {
                         if ($t == 'table') {
                             $tagstack = array_pop($tablestack);
                         }
                     }
                     $newparams = '';
//.........这里部分代码省略.........
开发者ID:JeroenDeDauw,项目名称:iRail,代码行数:101,代码来源:Sanitizer.php

示例4: braceSubstitution


//.........这里部分代码省略.........
         $text = $linestart . "[[{$titleText}]]<!-- WARNING: template omitted, pre-expand include size too large -->";
         $noparse = true;
         $noargs = true;
     }
     # Recursive parsing, escaping and link table handling
     # Only for HTML output
     if ($nowiki && $found && ($this->ot['html'] || $this->ot['pre'])) {
         $text = wfEscapeWikiText($text);
     } elseif (!$this->ot['msg'] && $found) {
         if ($noargs) {
             $assocArgs = array();
         } else {
             # Clean up argument array
             $assocArgs = self::createAssocArgs($args);
             # Add a new element to the templace recursion path
             $this->mTemplatePath[$part1] = 1;
         }
         if (!$noparse) {
             # If there are any <onlyinclude> tags, only include them
             if (in_string('<onlyinclude>', $text) && in_string('</onlyinclude>', $text)) {
                 $replacer = new OnlyIncludeReplacer();
                 StringUtils::delimiterReplaceCallback('<onlyinclude>', '</onlyinclude>', array(&$replacer, 'replace'), $text);
                 $text = $replacer->output;
             }
             # Remove <noinclude> sections and <includeonly> tags
             $text = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $text);
             $text = strtr($text, array('<includeonly>' => '', '</includeonly>' => ''));
             if ($this->ot['html'] || $this->ot['pre']) {
                 # Strip <nowiki>, <pre>, etc.
                 $text = $this->strip($text, $this->mStripState);
                 if ($this->ot['html']) {
                     $text = Sanitizer::removeHTMLtags($text, array(&$this, 'replaceVariables'), $assocArgs);
                 } elseif ($this->ot['pre'] && $this->mOptions->getRemoveComments()) {
                     $text = Sanitizer::removeHTMLcomments($text);
                 }
             }
             $text = $this->replaceVariables($text, $assocArgs);
             # If the template begins with a table or block-level
             # element, it should be treated as beginning a new line.
             if (!$piece['lineStart'] && preg_match('/^(?:{\\||:|;|#|\\*)/', $text)) {
                 $text = "\n" . $text;
             }
         } elseif (!$noargs) {
             # $noparse and !$noargs
             # Just replace the arguments, not any double-brace items
             # This is used for rendered interwiki transclusion
             $text = $this->replaceVariables($text, $assocArgs, true);
         }
     }
     # Prune lower levels off the recursion check path
     $this->mTemplatePath = $lastPathLevel;
     if ($found && !$this->incrementIncludeSize('post-expand', strlen($text))) {
         # Error, oversize inclusion
         $text = $linestart . "[[{$titleText}]]<!-- WARNING: template omitted, post-expand include size too large -->";
         $noparse = true;
         $noargs = true;
     }
     if (!$found) {
         wfProfileOut($fname);
         return $piece['text'];
     } else {
         wfProfileIn(__METHOD__ . '-placeholders');
         if ($isHTML) {
             # Replace raw HTML by a placeholder
             # Add a blank line preceding, to prevent it from mucking up
             # immediately preceding headings
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:67,代码来源:Parser_OldPP.php

示例5: removeHTMLtags

 /**
  * Cleans up HTML, removes dangerous tags and attributes, and
  * removes HTML comments
  * @access private
  * @param string $text
  * @param callback $processCallback to do any variable or parameter replacements in HTML attribute values
  * @param array $args for the processing callback
  * @return string
  */
 function removeHTMLtags($text, $processCallback = null, $args = array())
 {
     global $wgUseTidy, $wgUserHtml;
     $fname = 'Parser::removeHTMLtags';
     wfProfileIn($fname);
     if ($wgUserHtml) {
         $htmlpairs = array('b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rt', 'rb', 'rp', 'p', 'span');
         $htmlsingle = array('br', 'hr', 'li', 'dt', 'dd');
         $htmlsingleonly = array('br', 'hr');
         $htmlnest = array('table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'dl', 'font', 'big', 'small', 'sub', 'sup', 'span');
         $tabletags = array('td', 'th', 'tr', 'tbody');
     } else {
         $htmlpairs = array();
         $htmlsingle = array();
         $htmlnest = array();
         $tabletags = array();
     }
     $htmlsingle = array_merge($tabletags, $htmlsingle);
     $htmlelements = array_merge($htmlsingle, $htmlpairs);
     # Remove HTML comments
     $text = Sanitizer::removeHTMLcomments($text);
     $bits = explode('<', $text);
     $text = array_shift($bits);
     if (!$wgUseTidy) {
         $tagstack = array();
         $tablestack = array();
         foreach ($bits as $x) {
             $prev = error_reporting(E_ALL & ~(E_NOTICE | E_WARNING));
             preg_match('/^(\\/?)(\\w+)([^>]*?)(\\/{0,1}>)([^<]*)$/', $x, $regs);
             list($qbar, $slash, $t, $params, $brace, $rest) = $regs;
             error_reporting($prev);
             $badtag = 0;
             if (in_array($t = strtolower($t), $htmlelements)) {
                 # Check our stack
                 if ($slash) {
                     # Closing a tag...
                     if (in_array($t, $htmlsingleonly)) {
                         $badtag = 1;
                     } elseif (!in_array($t, $htmlsingle) && ($ot = @array_pop($tagstack)) != $t) {
                         @array_push($tagstack, $ot);
                         $badtag = 1;
                     } else {
                         if ($t == 'table') {
                             $tagstack = array_pop($tablestack);
                         }
                         $newparams = '';
                     }
                 } else {
                     # Keep track for later
                     if (in_array($t, $tabletags) && !in_array('table', $tagstack)) {
                         $badtag = 1;
                     } else {
                         if (in_array($t, $tagstack) && !in_array($t, $htmlnest)) {
                             $badtag = 1;
                         } elseif (in_array($t, $htmlsingleonly)) {
                             # Hack to force empty tag for uncloseable elements
                             $brace = '/>';
                         } else {
                             if (!in_array($t, $htmlsingle)) {
                                 if ($t == 'table') {
                                     array_push($tablestack, $tagstack);
                                     $tagstack = array();
                                 }
                                 array_push($tagstack, $t);
                             }
                         }
                     }
                     # Replace any variables or template parameters with
                     # plaintext results.
                     if (is_callable($processCallback)) {
                         call_user_func_array($processCallback, array(&$params, $args));
                     }
                     # Strip non-approved attributes from the tag
                     $newparams = Sanitizer::fixTagAttributes($params, $t);
                 }
                 if (!$badtag) {
                     $rest = str_replace('>', '&gt;', $rest);
                     $close = $brace == '/>' ? ' /' : '';
                     $text .= "<{$slash}{$t}{$newparams}{$close}>{$rest}";
                     continue;
                 }
             }
             $text .= '&lt;' . str_replace('>', '&gt;', $x);
         }
         # Close off any remaining tags
         while (is_array($tagstack) && ($t = array_pop($tagstack))) {
             $text .= "</{$t}>\n";
             if ($t == 'table') {
                 $tagstack = array_pop($tablestack);
             }
         }
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:enotifwiki,代码行数:101,代码来源:Sanitizer.php

示例6: formatFeedEntry

	/**
	 * Generates and returns a single feed entry.
	 * @param $row The wikilog comment database entry.
	 * @return A new WlSyndicationEntry object.
	 */
	function formatFeedEntry( $row ) {
		global $wgMimeType;

		# Create comment object.
		$item = $this->mSingleItem ? $this->mSingleItem : WikilogItem::newFromRow( $row );
		$comment = WikilogComment::newFromRow( $item, $row );

		# Prepare some strings.
		if ( $comment->mUserID ) {
			$usertext = $comment->mUserText;
		} else {
			$usertext = wfMsgForContent( 'wikilog-comment-anonsig',
				$comment->mUserText, ''/*talk*/, $comment->mAnonName
			);
		}
		if ( $this->mSingleItem ) {
			$title = wfMsgForContent( 'wikilog-comment-feed-title1',
				$comment->mID, $usertext
			);
		} else {
			$title = wfMsgForContent( 'wikilog-comment-feed-title2',
				$comment->mID, $usertext, $comment->mItem->mName
			);
		}

		# Create new syndication entry.
		$entry = new WlSyndicationEntry(
			self::makeEntryId( $comment ),
			$title,
			$comment->mUpdated,
			$comment->getCommentArticleTitle()->getFullUrl()
		);

		# Comment text.
		if ( $comment->mCommentRev ) {
			list( $article, $parserOutput ) = WikilogUtils::parsedArticle( $comment->mCommentTitle, true );
			$content = Sanitizer::removeHTMLcomments( $parserOutput->getText() );
			if ( $content ) {
				$entry->setContent( new WlTextConstruct( 'html', $content ) );
			}
		}

		# Author.
		$usertitle = Title::makeTitle( NS_USER, $comment->mUserText );
		$useruri = $usertitle->exists() ? $usertitle->getFullUrl() : null;
		$entry->addAuthor( $usertext, $useruri );

		# Timestamp
		$entry->setPublished( $comment->mTimestamp );

		return $entry;
	}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:57,代码来源:WikilogFeed.php

示例7: removeHTMLtags

 /**
  * Cleans up HTML, removes dangerous tags and attributes, and
  * removes HTML comments
  * @private
  * @param string $text
  * @param callback $processCallback to do any variable or parameter replacements in HTML attribute values
  * @param array $args for the processing callback
  * @return string
  */
 static function removeHTMLtags($text, $processCallback = null, $args = array())
 {
     global $wgUseTidy, $wgUserHtml;
     static $htmlpairs, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags, $htmllist, $listtags, $htmlsingleallowed, $htmlelements, $staticInitialised;
     wfProfileIn(__METHOD__);
     if (!$staticInitialised) {
         if ($wgUserHtml) {
             $htmlpairs = array('b', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rt', 'rb', 'rp', 'p', 'span', 'u');
             $htmlsingle = array('br', 'hr', 'li', 'dt', 'dd');
             $htmlsingleonly = array('br', 'hr');
             $htmlnest = array('table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'dl', 'font', 'big', 'small', 'sub', 'sup', 'span');
             $tabletags = array('td', 'th', 'tr');
             $htmllist = array('ul', 'ol');
             $listtags = array('li');
         } else {
             $htmlpairs = array();
             $htmlsingle = array();
             $htmlnest = array();
             $tabletags = array();
         }
         $htmlsingleallowed = array_merge($htmlsingle, $tabletags);
         $htmlelements = array_merge($htmlsingle, $htmlpairs, $htmlnest);
         # Convert them all to hashtables for faster lookup
         $vars = array('htmlpairs', 'htmlsingle', 'htmlsingleonly', 'htmlnest', 'tabletags', 'htmllist', 'listtags', 'htmlsingleallowed', 'htmlelements');
         foreach ($vars as $var) {
             ${$var} = array_flip(${$var});
         }
         $staticInitialised = true;
     }
     # Remove HTML comments
     $text = Sanitizer::removeHTMLcomments($text);
     $bits = explode('<', $text);
     $text = array_shift($bits);
     if (!$wgUseTidy) {
         $tagstack = $tablestack = array();
         foreach ($bits as $x) {
             $prev = error_reporting(E_ALL & ~(E_NOTICE | E_WARNING));
             preg_match('!^(/?)(\\w+)([^>]*?)(/{0,1}>)([^<]*)$!', $x, $regs);
             list($qbar, $slash, $t, $params, $brace, $rest) = $regs;
             error_reporting($prev);
             $badtag = 0;
             if (isset($htmlelements[$t = strtolower($t)])) {
                 # Check our stack
                 if ($slash) {
                     # Closing a tag...
                     if (isset($htmlsingleonly[$t])) {
                         $badtag = 1;
                     } elseif (($ot = @array_pop($tagstack)) != $t) {
                         if (isset($htmlsingleallowed[$ot])) {
                             # Pop all elements with an optional close tag
                             # and see if we find a match below them
                             $optstack = array();
                             array_push($optstack, $ot);
                             while (($ot = @array_pop($tagstack)) != $t && isset($htmlsingleallowed[$ot])) {
                                 array_push($optstack, $ot);
                             }
                             if ($t != $ot) {
                                 # No match. Push the optinal elements back again
                                 $badtag = 1;
                                 while ($ot = @array_pop($optstack)) {
                                     array_push($tagstack, $ot);
                                 }
                             }
                         } else {
                             @array_push($tagstack, $ot);
                             # <li> can be nested in <ul> or <ol>, skip those cases:
                             if (!(isset($htmllist[$ot]) && isset($listtags[$t]))) {
                                 $badtag = 1;
                             }
                         }
                     } else {
                         if ($t == 'table') {
                             $tagstack = array_pop($tablestack);
                         }
                     }
                     $newparams = '';
                 } else {
                     # Keep track for later
                     if (isset($tabletags[$t]) && !in_array('table', $tagstack)) {
                         $badtag = 1;
                     } else {
                         if (in_array($t, $tagstack) && !isset($htmlnest[$t])) {
                             $badtag = 1;
                             # Is it a self closed htmlpair ? (bug 5487)
                         } else {
                             if ($brace == '/>' && isset($htmlpairs[$t])) {
                                 $badtag = 1;
                             } elseif (isset($htmlsingleonly[$t])) {
                                 # Hack to force empty tag for uncloseable elements
                                 $brace = '/>';
                             } else {
//.........这里部分代码省略.........
开发者ID:puring0815,项目名称:OpenKore,代码行数:101,代码来源:Sanitizer.php

示例8: removeHTMLtags

 /**
  * Cleans up HTML, removes dangerous tags and attributes, and
  * removes HTML comments
  * @param string $text
  * @param callable $processCallback Callback to do any variable or parameter
  *   replacements in HTML attribute values
  * @param array|bool $args Arguments for the processing callback
  * @param array $extratags For any extra tags to include
  * @param array $removetags For any tags (default or extra) to exclude
  * @return string
  */
 public static function removeHTMLtags($text, $processCallback = null, $args = array(), $extratags = array(), $removetags = array())
 {
     global $wgUseTidy, $wgAllowMicrodataAttributes, $wgAllowImageTag;
     static $htmlpairsStatic, $htmlsingle, $htmlsingleonly, $htmlnest, $tabletags, $htmllist, $listtags, $htmlsingleallowed, $htmlelementsStatic, $staticInitialised;
     // Base our staticInitialised variable off of the global config state so that if the globals
     // are changed (like in the screwed up test system) we will re-initialise the settings.
     $globalContext = implode('-', compact('wgAllowMicrodataAttributes', 'wgAllowImageTag'));
     if (!$staticInitialised || $staticInitialised != $globalContext) {
         $htmlpairsStatic = array('b', 'bdi', 'del', 'i', 'ins', 'u', 'font', 'big', 'small', 'sub', 'sup', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'cite', 'code', 'em', 's', 'strike', 'strong', 'tt', 'var', 'div', 'center', 'blockquote', 'ol', 'ul', 'dl', 'table', 'caption', 'pre', 'ruby', 'rb', 'rp', 'rt', 'rtc', 'p', 'span', 'abbr', 'dfn', 'kbd', 'samp', 'data', 'time', 'mark');
         $htmlsingle = array('br', 'wbr', 'hr', 'li', 'dt', 'dd');
         $htmlsingleonly = array('br', 'wbr', 'hr');
         if ($wgAllowMicrodataAttributes) {
             $htmlsingle[] = $htmlsingleonly[] = 'meta';
             $htmlsingle[] = $htmlsingleonly[] = 'link';
         }
         $htmlnest = array('table', 'tr', 'td', 'th', 'div', 'blockquote', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'font', 'big', 'small', 'sub', 'sup', 'span', 'var', 'kbd', 'samp', 'em', 'strong', 'q', 'ruby', 'bdo');
         $tabletags = array('td', 'th', 'tr');
         $htmllist = array('ul', 'ol');
         $listtags = array('li');
         if ($wgAllowImageTag) {
             $htmlsingle[] = 'img';
             $htmlsingleonly[] = 'img';
         }
         $htmlsingleallowed = array_unique(array_merge($htmlsingle, $tabletags));
         $htmlelementsStatic = array_unique(array_merge($htmlsingle, $htmlpairsStatic, $htmlnest));
         # Convert them all to hashtables for faster lookup
         $vars = array('htmlpairsStatic', 'htmlsingle', 'htmlsingleonly', 'htmlnest', 'tabletags', 'htmllist', 'listtags', 'htmlsingleallowed', 'htmlelementsStatic');
         foreach ($vars as $var) {
             ${$var} = array_flip(${$var});
         }
         $staticInitialised = $globalContext;
     }
     # Populate $htmlpairs and $htmlelements with the $extratags and $removetags arrays
     $extratags = array_flip($extratags);
     $removetags = array_flip($removetags);
     $htmlpairs = array_merge($extratags, $htmlpairsStatic);
     $htmlelements = array_diff_key(array_merge($extratags, $htmlelementsStatic), $removetags);
     # Remove HTML comments
     $text = Sanitizer::removeHTMLcomments($text);
     $bits = explode('<', $text);
     $text = str_replace('>', '&gt;', array_shift($bits));
     if (!$wgUseTidy) {
         $tagstack = $tablestack = array();
         foreach ($bits as $x) {
             $regs = array();
             # $slash: Does the current element start with a '/'?
             # $t: Current element name
             # $params: String between element name and >
             # $brace: Ending '>' or '/>'
             # $rest: Everything until the next element of $bits
             if (preg_match(self::ELEMENT_BITS_REGEX, $x, $regs)) {
                 list(, $slash, $t, $params, $brace, $rest) = $regs;
             } else {
                 $slash = $t = $params = $brace = $rest = null;
             }
             $badtag = false;
             if (isset($htmlelements[$t = strtolower($t)])) {
                 # Check our stack
                 if ($slash && isset($htmlsingleonly[$t])) {
                     $badtag = true;
                 } elseif ($slash) {
                     # Closing a tag... is it the one we just opened?
                     wfSuppressWarnings();
                     $ot = array_pop($tagstack);
                     wfRestoreWarnings();
                     if ($ot != $t) {
                         if (isset($htmlsingleallowed[$ot])) {
                             # Pop all elements with an optional close tag
                             # and see if we find a match below them
                             $optstack = array();
                             array_push($optstack, $ot);
                             wfSuppressWarnings();
                             $ot = array_pop($tagstack);
                             wfRestoreWarnings();
                             while ($ot != $t && isset($htmlsingleallowed[$ot])) {
                                 array_push($optstack, $ot);
                                 wfSuppressWarnings();
                                 $ot = array_pop($tagstack);
                                 wfRestoreWarnings();
                             }
                             if ($t != $ot) {
                                 # No match. Push the optional elements back again
                                 $badtag = true;
                                 wfSuppressWarnings();
                                 $ot = array_pop($optstack);
                                 wfRestoreWarnings();
                                 while ($ot) {
                                     array_push($tagstack, $ot);
                                     wfSuppressWarnings();
//.........这里部分代码省略.........
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:101,代码来源:Sanitizer.php


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