本文整理汇总了PHP中safecss_filter_attr函数的典型用法代码示例。如果您正苦于以下问题:PHP safecss_filter_attr函数的具体用法?PHP safecss_filter_attr怎么用?PHP safecss_filter_attr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了safecss_filter_attr函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_style
private function process_style($string)
{
// Filter properties
$string = safecss_filter_attr(esc_html($string));
if (!$string) {
return array();
}
// Normalize order
$styles = array_map('trim', explode(';', $string));
sort($styles);
$processed_styles = array();
// Normalize whitespace and filter rules
foreach ($styles as $index => $rule) {
$arr2 = array_map('trim', explode(':', $rule, 2));
if (2 !== count($arr2)) {
continue;
}
list($property, $value) = $this->filter_style($arr2[0], $arr2[1]);
if (empty($property) || empty($value)) {
continue;
}
$processed_styles[$index] = $property . ':' . $value;
}
return $processed_styles;
}
示例2: wp_kses_attr_check
/**
* Determine whether an attribute is allowed.
*
* @since 4.2.3
*
* @param string $name The attribute name. Returns empty string when not allowed.
* @param string $value The attribute value. Returns a filtered value.
* @param string $whole The name=value input. Returns filtered input.
* @param string $vless 'y' when attribute like "enabled", otherwise 'n'.
* @param string $element The name of the element to which this attribute belongs.
* @param array $allowed_html The full list of allowed elements and attributes.
* @return bool Is the attribute allowed?
*/
function wp_kses_attr_check(&$name, &$value, &$whole, $vless, $element, $allowed_html)
{
$allowed_attr = $allowed_html[strtolower($element)];
$name_low = strtolower($name);
if (!isset($allowed_attr[$name_low]) || '' == $allowed_attr[$name_low]) {
$name = $value = $whole = '';
return false;
}
if ('style' == $name_low) {
$new_value = safecss_filter_attr($value);
if (empty($new_value)) {
$name = $value = $whole = '';
return false;
}
$whole = str_replace($value, $new_value, $whole);
$value = $new_value;
}
if (is_array($allowed_attr[$name_low])) {
// there are some checks
foreach ($allowed_attr[$name_low] as $currkey => $currval) {
if (!wp_kses_check_attr_val($value, $vless, $currkey, $currval)) {
$name = $value = $whole = '';
return false;
}
}
}
return true;
}
示例3: wp_kses_attr
/**
* Removes all attributes, if none are allowed for this element.
*
* If some are allowed it calls wp_kses_hair() to split them further, and then
* it builds up new HTML code from the data that kses_hair() returns. It also
* removes "<" and ">" characters, if there are any left. One more thing it does
* is to check if the tag has a closing XHTML slash, and if it does, it puts one
* in the returned code as well.
*
* @since 1.0.0
*
* @param string $element HTML element/tag
* @param string $attr HTML attributes from HTML element to closing HTML element tag
* @param array $allowed_html Allowed HTML elements
* @param array $allowed_protocols Allowed protocols to keep
* @return string Sanitized HTML element
*/
function wp_kses_attr($element, $attr, $allowed_html, $allowed_protocols)
{
# Is there a closing XHTML slash at the end of the attributes?
$xhtml_slash = '';
if (preg_match('%\\s*/\\s*$%', $attr)) {
$xhtml_slash = ' /';
}
# Are any attributes allowed at all for this element?
if (!isset($allowed_html[strtolower($element)]) || count($allowed_html[strtolower($element)]) == 0) {
return "<{$element}{$xhtml_slash}>";
}
# Split it
$attrarr = wp_kses_hair($attr, $allowed_protocols);
# Go through $attrarr, and save the allowed attributes for this element
# in $attr2
$attr2 = '';
$allowed_attr = $allowed_html[strtolower($element)];
foreach ($attrarr as $arreach) {
if (!isset($allowed_attr[strtolower($arreach['name'])])) {
continue;
}
# the attribute is not allowed
$current = $allowed_attr[strtolower($arreach['name'])];
if ($current == '') {
continue;
}
# the attribute is not allowed
if (!is_array($current)) {
$attr2 .= ' ' . $arreach['whole'];
# there are no checks
} else {
# there are some checks
$ok = true;
foreach ($current as $currkey => $currval) {
if (!wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval)) {
$ok = false;
break;
}
}
if (strtolower($arreach['name']) == 'style') {
$orig_value = $arreach['value'];
$value = safecss_filter_attr($orig_value);
if (empty($value)) {
continue;
}
$arreach['value'] = $value;
$arreach['whole'] = str_replace($orig_value, $value, $arreach['whole']);
}
if ($ok) {
$attr2 .= ' ' . $arreach['whole'];
}
# it passed them
}
# if !is_array($current)
}
# foreach
# Remove any "<" or ">" characters
$attr2 = preg_replace('/[<>]/', '', $attr2);
return "<{$element}{$attr2}{$xhtml_slash}>";
}
示例4: sprite
function sprite($sprite = '', $title = '', $args = [])
{
// Setup default arguments
$args = wp_parse_args($args, ['desc' => '', 'class' => [], 'style' => '', 'prefix' => 'sprite', 'url' => '']);
// Generate a unique ID and initialize ARIA
$id = uniqid();
$desc = $style = $aria = '';
// Check for title and description, wrap them both in the appropriate markup, and set ARIA attributes
if ($title) {
$title = sprintf('<title id="title-%1$s">%2$s</title>', $id, esc_html(strip_tags($title)));
$aria .= 'title-' . $id;
}
if ($args['desc']) {
$desc = sprintf('<desc id="desc-%1$s">%2$s</desc>', $id, esc_html(strip_tags($args['desc'])));
$aria .= ' desc-' . $id;
}
if ($args['style']) {
$style = sprintf(' style="%s"', safecss_filter_attr($args['style']));
}
// Sanitize inline styles: https://wordpress.stackexchange.com/questions/173526/why-is-wp-kses-not-keeping-style-attributes-as-expected
if ($aria) {
$aria = sprintf(' aria-labelledby="%s"', trim($aria));
}
// Put it all together
return apply_filters('ubik_svg_sprite', sprintf('<svg%s%s%srole="img">%s%s<use xlink:href="%s#%s"></use></svg>', sprite_class($sprite, $args['class'], $args['prefix']), $style, $aria, $title, $desc, $args['url'], esc_attr($sprite)));
}
示例5: raindrops_default_colors_clone
function raindrops_default_colors_clone($name = 'dark', $option_name = false, $default = false)
{
$raindrops_images_path = get_stylesheet_directory_uri() . '/images/';
// Sidebar Image
$navigation_title_img = raindrops_warehouse_clone('raindrops_heading_image');
$navigation_title_img_uri = esc_url($raindrops_images_path . $navigation_title_img);
switch ($name) {
case "w3standard":
$custom_dark_bg = apply_filters('raindrops_w3_default_bg_dark', raindrops_colors_clone('3', 'background'));
$custom_light_bg = apply_filters('raindrops_w3_default_bg_light', raindrops_colors_clone('1', 'background'));
$custom_color = apply_filters('raindrops_w3_default_color', raindrops_colors_clone('1', 'color'));
$custom_link_color = apply_filters('raindrops_w3_default_link_color', raindrops_colors_clone('1', 'color'));
$custom_footer_link_color = apply_filters('raindrops_w3_default_footer_link_color', raindrops_colors_clone('1', 'color'));
$raindrops_footer_color_default = apply_filters('raindrops_w3_default_footer_color', '#000');
$raindrops_header_color_default = apply_filters('raindrops_w3_default_header_color', '#000');
break;
case "dark":
/**
* dark
*/
$custom_dark_bg = apply_filters('raindrops_dark_default_bg_dark', raindrops_colors_clone('-1', 'background'));
$custom_light_bg = apply_filters('raindrops_dark_default_bg_light', raindrops_colors_clone('-4', 'background'));
$custom_color = apply_filters('raindrops_dark_default_color', raindrops_colors_clone('-3', 'color'));
$custom_link_color = apply_filters('raindrops_dark_default_link_color', raindrops_colors_clone('-3', 'color'));
$custom_footer_link_color = apply_filters('raindrops_dark_default_footer_link_color', raindrops_colors_clone('-3', 'color'));
$raindrops_footer_color_default = apply_filters('raindrops_dark_default_footer_color', '#fff');
$raindrops_header_color_default = apply_filters('raindrops_dark_default_header_color', '#fff');
break;
case "light":
/**
* light
*/
$custom_dark_bg = apply_filters('raindrops_light_default_bg_dark', raindrops_colors_clone('5', 'background'));
$custom_light_bg = apply_filters('raindrops_light_default_bg_light', raindrops_colors_clone('3', 'background'));
$custom_color = apply_filters('raindrops_light_default_color', raindrops_colors_clone('3', 'color'));
$custom_link_color = apply_filters('raindrops_light_default_link_color', raindrops_colors_clone('3', 'color'));
$custom_footer_link_color = apply_filters('raindrops_light_default_footer_link_color', raindrops_colors_clone('3', 'color'));
$raindrops_footer_color_default = apply_filters('raindrops_light_default_footer_color', '#333');
$raindrops_header_color_default = apply_filters('raindrops_light_default_header_color', '#333');
break;
default:
$custom_dark_bg = apply_filters('raindrops_color_type_default_bg_dark', raindrops_colors_clone('3', 'background'));
$custom_light_bg = apply_filters('raindrops_color_type_default_bg_light', raindrops_colors_clone('1', 'background'));
$custom_color = apply_filters('raindrops_color_type_default_color', raindrops_colors_clone('3', 'color'));
$custom_link_color = apply_filters('raindrops_color_type_default_link_color', raindrops_colors_clone('3', 'color'));
$custom_footer_link_color = apply_filters('raindrops_color_type_default_footer_link_color', raindrops_colors_clone('1', 'color'));
$raindrops_footer_color_default = apply_filters('raindrops_color_type_default_footer_color', '#000');
$raindrops_header_color_default = apply_filters('raindrops_color_type_default_header_color', '#000');
break;
}
if (!empty($option_name)) {
if ('raindrops_background_color' == $option_name || 'custom_dark_bg' == $option_name) {
return $custom_dark_bg;
}
if ('custom_light_bg' == $option_name) {
return $custom_light_bg;
}
if ('raindrops_default_fonts_color' == $option_name || 'custom_color' == $option_name || 'default-text-color') {
return $custom_color;
}
if ('raindrops_header_color' == $option_name) {
$raindrops_header_color = raindrops_warehouse_clone('raindrops_default_fonts_color');
if (false == $default && isset($raindrops_header_color) && !empty($raindrops_header_color)) {
return $raindrops_header_color;
} else {
return $raindrops_header_color_default;
}
}
if ('raindrops_footer_color' == $option_name) {
$raindrops_footer_color = raindrops_warehouse_clone('raindrops_footer_color');
if (false == $default && isset($raindrops_footer_color) && !empty($raindrops_footer_color)) {
return $raindrops_footer_color;
} else {
return $raindrops_footer_color_default;
}
}
if ('raindrops_footer_link_color' == $option_name) {
return $custom_footer_link_color;
}
if ('raindrops_hyperlink_color' == $option_name) {
return $custom_link_color;
}
if ('raindrops_header_image_filter_color' == $option_name) {
return $custom_light_bg;
}
if ('h2_w3standard_background' == $option_name) {
$style = "background:" . raindrops_colors_clone(5, 'background') . ' ';
$style .= "url( {$navigation_title_img_uri} );";
$style .= "color:" . raindrops_colors_clone(4, 'color') . ';';
return safecss_filter_attr($style);
}
if ('h2_dark_background' == $option_name) {
$style = "background:" . raindrops_colors_clone(-3, 'background') . ' ';
$style .= "url( {$navigation_title_img_uri} );";
$style .= "color:" . raindrops_colors_clone(-3, 'color') . ';';
return safecss_filter_attr($style);
}
if ('h2_light_background' == $option_name) {
$style = "background:" . raindrops_colors_clone(4, 'background') . ' ';
$style .= "url( {$navigation_title_img_uri} );";
//.........这里部分代码省略.........