| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Freemius |
| 4 |
* @copyright Copyright (c) 2015, Freemius, Inc. |
| 5 |
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 |
| 6 |
* @since 2.5.10 |
| 7 |
*/ |
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
if ( ! function_exists( 'fs_html_get_allowed_kses_list' ) ) { |
| 13 |
/** |
| 14 |
* Get the allowed KSES list for sanitizing HTML output on the template files. |
| 15 |
* |
| 16 |
* @return array |
| 17 |
*/ |
| 18 |
function fs_html_get_allowed_kses_list() { |
| 19 |
$common_attributes = array( |
| 20 |
'id' => true, |
| 21 |
'class' => true, |
| 22 |
'style' => true, |
| 23 |
'data-*' => true, |
| 24 |
); |
| 25 |
|
| 26 |
return array( |
| 27 |
'a' => array_merge( |
| 28 |
$common_attributes, |
| 29 |
array( |
| 30 |
'href' => true, |
| 31 |
'title' => true, |
| 32 |
'target' => true, |
| 33 |
'rel' => true, |
| 34 |
) |
| 35 |
), |
| 36 |
'img' => array_merge( |
| 37 |
$common_attributes, |
| 38 |
array( |
| 39 |
'src' => true, |
| 40 |
'alt' => true, |
| 41 |
'title' => true, |
| 42 |
'width' => true, |
| 43 |
'height' => true, |
| 44 |
) |
| 45 |
), |
| 46 |
'br' => $common_attributes, |
| 47 |
'em' => $common_attributes, |
| 48 |
'small' => $common_attributes, |
| 49 |
'strong' => $common_attributes, |
| 50 |
'u' => $common_attributes, |
| 51 |
'b' => $common_attributes, |
| 52 |
'i' => $common_attributes, |
| 53 |
'hr' => $common_attributes, |
| 54 |
'span' => $common_attributes, |
| 55 |
'p' => $common_attributes, |
| 56 |
'div' => $common_attributes, |
| 57 |
'ul' => $common_attributes, |
| 58 |
'li' => $common_attributes, |
| 59 |
'ol' => $common_attributes, |
| 60 |
'h1' => $common_attributes, |
| 61 |
'h2' => $common_attributes, |
| 62 |
'h3' => $common_attributes, |
| 63 |
'h4' => $common_attributes, |
| 64 |
'h5' => $common_attributes, |
| 65 |
'h6' => $common_attributes, |
| 66 |
'button' => $common_attributes, |
| 67 |
'sup' => $common_attributes, |
| 68 |
'sub' => $common_attributes, |
| 69 |
'nobr' => $common_attributes, |
| 70 |
); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
if ( ! function_exists( 'fs_html_get_classname' ) ) { |
| 75 |
/** |
| 76 |
* Gets an HTML class attribute value. |
| 77 |
* |
| 78 |
* @param string|string[] $classes |
| 79 |
* |
| 80 |
* @return string |
| 81 |
*/ |
| 82 |
function fs_html_get_classname( $classes ) { |
| 83 |
if ( is_array( $classes ) ) { |
| 84 |
$classes = implode( ' ', $classes ); |
| 85 |
} |
| 86 |
|
| 87 |
return esc_attr( $classes ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
if ( ! function_exists( 'fs_html_get_attributes' ) ) { |
| 92 |
/** |
| 93 |
* Gets a properly escaped HTML attributes string from an associative array. |
| 94 |
* |
| 95 |
* @param array<string, string> $attributes A key/value pair array of attributes. |
| 96 |
* |
| 97 |
* @return string |
| 98 |
*/ |
| 99 |
function fs_html_get_attributes( $attributes ) { |
| 100 |
$attribute_string = ''; |
| 101 |
|
| 102 |
foreach ( $attributes as $key => $value ) { |
| 103 |
$attribute_string .= sprintf( |
| 104 |
' %1$s="%2$s"', |
| 105 |
esc_attr( $key ), |
| 106 |
esc_attr( $value ) |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
return $attribute_string; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
if ( ! function_exists( 'fs_html_get_sanitized_html' ) ) { |
| 115 |
/** |
| 116 |
* Get sanitized HTML for template files. |
| 117 |
* |
| 118 |
* @param string $raw_html |
| 119 |
* |
| 120 |
* @return string |
| 121 |
* @since 2.5.10 |
| 122 |
*/ |
| 123 |
function fs_html_get_sanitized_html( $raw_html ) { |
| 124 |
return wp_kses( $raw_html, fs_html_get_allowed_kses_list() ); |
| 125 |
} |
| 126 |
} |
| 127 |
|