本文整理汇总了PHP中Sanitizer::fixDeprecatedAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Sanitizer::fixDeprecatedAttributes方法的具体用法?PHP Sanitizer::fixDeprecatedAttributes怎么用?PHP Sanitizer::fixDeprecatedAttributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sanitizer
的用法示例。
在下文中一共展示了Sanitizer::fixDeprecatedAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixTagAttributes
/**
* Take a tag soup fragment listing an HTML element's attributes
* and normalize it to well-formed XML, discarding unwanted attributes.
* Output is safe for further wikitext processing, with escaping of
* values that could trigger problems.
*
* - Normalizes attribute names to lowercase
* - Discards attributes not on a whitelist for the given element
* - Turns broken or invalid entities into plaintext
* - Double-quotes all attribute values
* - Attributes without values are given the name as attribute
* - Double attributes are discarded
* - Unsafe style attributes are discarded
* - Prepends space if there are attributes.
*
* @param $text String
* @param $element String
* @return String
*/
static function fixTagAttributes($text, $element)
{
if (trim($text) == '') {
return '';
}
$decoded = Sanitizer::decodeTagAttributes($text);
$decoded = Sanitizer::fixDeprecatedAttributes($decoded, $element);
$stripped = Sanitizer::validateTagAttributes($decoded, $element);
$attribs = array();
foreach ($stripped as $attribute => $value) {
$encAttribute = htmlspecialchars($attribute);
$encValue = Sanitizer::safeEncodeAttribute($value);
$attribs[] = "{$encAttribute}=\"{$encValue}\"";
}
return count($attribs) ? ' ' . implode(' ', $attribs) : '';
}
示例2: fixTagAttributes
/**
* Take a tag soup fragment listing an HTML element's attributes
* and normalize it to well-formed XML, discarding unwanted attributes.
* Output is safe for further wikitext processing, with escaping of
* values that could trigger problems.
*
* - Normalizes attribute names to lowercase
* - Discards attributes not on a whitelist for the given element
* - Turns broken or invalid entities into plaintext
* - Double-quotes all attribute values
* - Attributes without values are given the name as attribute
* - Double attributes are discarded
* - Unsafe style attributes are discarded
* - Prepends space if there are attributes.
*
* @param $text String
* @param $element String
* @return String
*/
static function fixTagAttributes($text, $element)
{
if (trim($text) == '') {
return '';
}
$decoded = Sanitizer::decodeTagAttributes($text);
$decoded = Sanitizer::fixDeprecatedAttributes($decoded, $element);
$stripped = Sanitizer::validateTagAttributes($decoded, $element);
$attribs = array();
foreach ($stripped as $attribute => $value) {
$encAttribute = htmlspecialchars($attribute);
$encValue = Sanitizer::safeEncodeAttribute($value);
# RTE (Rich Text Editor) - begin
# @author: Inez Korczyński, macbre
global $wgRTEParserEnabled;
if (!empty($wgRTEParserEnabled) && $encAttribute == 'style') {
// BugId:2462 - remove apostrophes from style attribute
$encValue = str_replace(''', '', $encValue);
$attribs[] = "data-rte-style=\"{$encValue}\"";
}
# RTE - end
$attribs[] = "{$encAttribute}=\"{$encValue}\"";
}
# RTE (Rich Text Editor) - begin
# @author: Inez Korczyński
global $wgRTEParserEnabled;
if (!empty($wgRTEParserEnabled)) {
if (strpos($text, "") !== false) {
RTE::$edgeCases[] = 'COMPLEX.08';
}
$attribs[] = RTEParser::encodeAttributesStr($text);
}
# RTE - end
return count($attribs) ? ' ' . implode(' ', $attribs) : '';
}