: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Nextend\Framework;
use Nextend\Framework\Platform\Platform;
global $allowedentitynames;
* @var string[] $allowedentitynames Array of KSES allowed HTML entitity names.
$allowedentitynames = is_array($allowedentitynames) ? $allowedentitynames : array(
public static $basicTags = array();
// Tags for admin page forms with text fields, on-offs, selects, textareas, etc..
public static $adminFormTags = array();
// Tags for the rest of the admin page layout.
public static $adminTemplateTags = array();
// Tags for CSS and JS codes.
public static $assetTags = array();
public static $videoTags = array();
private static function getCharset() {
return Platform::getCharset();
* Checks for invalid UTF8 in a string.
* @param string $string The text which is to be checked.
* @param bool $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false.
* @return string The checked text.
* @staticvar bool $is_utf8
* @staticvar bool $utf8_pcre
private static function check_invalid_utf8($string, $strip = false) {
$string = (string)$string;
if (0 === strlen($string)) {
// Store the site charset as a static to avoid multiple calls to get_option()
$is_utf8 = in_array(self::getCharset(), array(
// Check for support for utf8 in the installed PCRE library once and store the result in a static
static $utf8_pcre = null;
if (!isset($utf8_pcre)) {
$utf8_pcre = @preg_match('/^./u', 'a');
// We can't demand utf8 in the PCRE installation, so just return the string in those cases
// preg_match fails when it encounters invalid UTF8 in $string
if (1 === @preg_match('/^./us', $string)) {
// Attempt to strip the bad chars if requested (not recommended)
if ($strip && function_exists('iconv')) {
return iconv('utf-8', 'utf-8', $string);
* Converts a number of special characters into their HTML entities.
* Specifically deals with: &, <, >, ", and '.
* $quote_style can be set to ENT_COMPAT to encode " to
* ", or ENT_QUOTES to do both. Default is ENT_NOQUOTES where no quotes are encoded.
* @param string $string The text which is to be encoded.
* @param int|string $quote_style Optional. Converts double quotes if set to ENT_COMPAT,
* both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES.
* Also compatible with old values; converting single quotes if set to 'single',
* double if set to 'double' or both if otherwise set.
* Default is ENT_NOQUOTES.
* @param string|bool $charset Optional. The character encoding of the string. Default is false.
* @param bool $double_encode Optional. Whether to encode existing html entities. Default is false.
* @return string The encoded text with HTML entities.
* @staticvar string $_charset
private static function _specialchars($string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false) {
$string = (string)$string;
if (0 === strlen($string)) return '';
// Don't bother if there are no specialchars - saves some processing
if (!preg_match('/[&<>"\']/', $string)) return $string;
// Account for the previous behaviour of the function when the $quote_style is not an accepted value
if (empty($quote_style)) $quote_style = ENT_NOQUOTES; else if (!in_array($quote_style, array(
), true)) $quote_style = ENT_QUOTES;
// Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
$_charset = self::getCharset();
if (in_array($charset, array(
$_quote_style = $quote_style;
if ($quote_style === 'double') {
$quote_style = ENT_COMPAT;
$_quote_style = ENT_COMPAT;
} else if ($quote_style === 'single') {
$quote_style = ENT_NOQUOTES;
// Guarantee every &entity; is valid, convert &garbage; into &garbage;
// This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable.
$string = self::kses_normalize_entities($string);
$string = @htmlspecialchars($string, $quote_style, $charset, $double_encode);
if ('single' === $_quote_style) $string = str_replace("'", ''', $string);
* Converts and fixes HTML entities.
* This function normalizes HTML entities. It will convert `AT&T` to the correct
* `AT&T`, `:` to `:`, `&#XYZZY;` to `&#XYZZY;` and so on.
* @param string $string Content to normalize entities
* @return string Content with normalized entities
private static function kses_normalize_entities($string) {
// Disarm all entities by converting & to &
$string = str_replace('&', '&', $string);
// Change back the allowed entities in our entity whitelist
$string = preg_replace_callback('/&([A-Za-z]{2,8}[0-9]{0,2});/', array(
$string = preg_replace_callback('/&#(0*[0-9]{1,7});/', array(
'kses_normalize_entities2'
$string = preg_replace_callback('/&#[Xx](0*[0-9A-Fa-f]{1,6});/', array(
'kses_normalize_entities3'
* Callback for kses_normalize_entities() regular expression.
* This function only accepts valid named entity references, which are finite,
* case-sensitive, and highly scrutinized by HTML and XML validators.
* @param array $matches preg_replace_callback() matches array
* @return string Correctly encoded entity
* @global array $allowedentitynames
public static function kses_named_entities($matches) {
global $allowedentitynames;
if (empty($matches[1])) return '';
return (!in_array($i, $allowedentitynames)) ? "&$i;" : "&$i;";
* Callback for kses_normalize_entities() regular expression.
* This function helps kses_normalize_entities() to only accept 16-bit
* values and nothing more for `&#number;` entities.
* @param array $matches preg_replace_callback() matches array
* @return string Correctly encoded entity
public static function kses_normalize_entities2($matches) {
if (empty($matches[1])) return '';