本文整理匯總了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) : '';
}