Apply automated PHP8 safety transforms

Agent-Logs-Url: https://github.com/GameServerPanel/GSP/sessions/89922108-1604-44ae-949d-358d32b9d70a

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-23 14:01:37 +00:00 committed by GitHub
parent aca850b6cd
commit e44519c030
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
465 changed files with 1716 additions and 1716 deletions

View file

@ -13,7 +13,7 @@ class HTMLPurifier_Arborize
$definition = $config->getHTMLDefinition();
$parent = new HTMLPurifier_Token_Start($definition->info_parent);
$stack = array($parent->toNode());
foreach ($tokens as $token) {
foreach ((array)$tokens as $token) {
$token->skip = null; // [MUT]
$token->carryover = null; // [MUT]
if ($token instanceof HTMLPurifier_Token_End) {
@ -27,12 +27,12 @@ class HTMLPurifier_Arborize
continue;
}
$node = $token->toNode();
$stack[count($stack)-1]->children[] = $node;
$stack[count((array)$stack)-1]->children[] = $node;
if ($token instanceof HTMLPurifier_Token_Start) {
$stack[] = $node;
}
}
//assert(count($stack) == 1);
//assert(count((array)$stack) == 1);
return $stack[0];
}

View file

@ -28,12 +28,12 @@ class HTMLPurifier_AttrCollections
public function doConstruct($attr_types, $modules)
{
// load extensions from the modules
foreach ($modules as $module) {
foreach ((array)$modules as $module) {
foreach ($module->attr_collections as $coll_i => $coll) {
if (!isset($this->info[$coll_i])) {
$this->info[$coll_i] = array();
}
foreach ($coll as $attr_i => $attr) {
foreach ((array)$coll as $attr_i => $attr) {
if ($attr_i === 0 && isset($this->info[$coll_i][$attr_i])) {
// merge in includes
$this->info[$coll_i][$attr_i] = array_merge(
@ -103,7 +103,7 @@ class HTMLPurifier_AttrCollections
// skip duplicates
$processed = array();
foreach ($attr as $def_i => $def) {
foreach ((array)$attr as $def_i => $def) {
// skip inclusions
if ($def_i === 0) {
continue;

View file

@ -68,7 +68,7 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
$property = false;
$context->register('CurrentCSSProperty', $property);
foreach ($declarations as $declaration) {
foreach ((array)$declarations as $declaration) {
if (!$declaration) {
continue;
}
@ -123,7 +123,7 @@ class HTMLPurifier_AttrDef_CSS extends HTMLPurifier_AttrDef
// slightly inefficient, but it's the only way of getting rid of
// duplicates. Perhaps config to optimize it, but not now.
foreach ($propvalues as $prop => $value) {
foreach ((array)$propvalues as $prop => $value) {
$new_declarations .= "$prop:$value;";
}

View file

@ -56,11 +56,11 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
$i = 0; // number of catches
foreach ($bits as $bit) {
foreach ((array)$bits as $bit) {
if ($bit === '') {
continue;
}
foreach ($caught as $key => $status) {
foreach ((array)$caught as $key => $status) {
if ($key != 'position') {
if ($status !== false) {
continue;
@ -94,7 +94,7 @@ class HTMLPurifier_AttrDef_CSS_Background extends HTMLPurifier_AttrDef
}
$ret = array();
foreach ($caught as $value) {
foreach ((array)$caught as $value) {
if ($value === false) {
continue;
}

View file

@ -88,7 +88,7 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
'center' => 'c'
);
foreach ($bits as $bit) {
foreach ((array)$bits as $bit) {
if ($bit === '') {
continue;
}
@ -135,7 +135,7 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
} elseif ($keywords['ch']) {
$ret[] = $keywords['ch'];
$keywords['cv'] = false; // prevent re-use: center = center center
} elseif (count($measures)) {
} elseif (count((array)$measures)) {
$ret[] = array_shift($measures);
}
@ -143,7 +143,7 @@ class HTMLPurifier_AttrDef_CSS_BackgroundPosition extends HTMLPurifier_AttrDef
$ret[] = $keywords['v'];
} elseif ($keywords['cv']) {
$ret[] = $keywords['cv'];
} elseif (count($measures)) {
} elseif (count((array)$measures)) {
$ret[] = array_shift($measures);
}

View file

@ -36,7 +36,7 @@ class HTMLPurifier_AttrDef_CSS_Border extends HTMLPurifier_AttrDef
$bits = explode(' ', $string);
$done = array(); // segments we've finished
$ret = ''; // return value
foreach ($bits as $bit) {
foreach ((array)$bits as $bit) {
foreach ($this->info as $propname => $validator) {
if (isset($done[$propname])) {
continue;

View file

@ -78,7 +78,7 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
$values = trim(str_replace($function, '', $color), ' ()');
$parts = explode(',', $values);
if (count($parts) !== $parameters_size) {
if (count((array)$parts) !== $parameters_size) {
return false;
}
@ -86,7 +86,7 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
$new_parts = array();
$i = 0;
foreach ($parts as $part) {
foreach ((array)$parts as $part) {
$i++;
$part = trim($part);
@ -95,7 +95,7 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
}
// different check for alpha channel
if ($alpha_channel === true && $i === count($parts)) {
if ($alpha_channel === true && $i === count((array)$parts)) {
$result = $this->alpha->validate($part, $config, $context);
if ($result === false) {
@ -112,7 +112,7 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef
$current_type = 'integer';
}
if (!array_key_exists($current_type, $allowed_types[$i])) {
if (!array_key_exists($current_type, (array)$allowed_types[$i])) {
return false;
}

View file

@ -44,7 +44,7 @@ class HTMLPurifier_AttrDef_CSS_Filter extends HTMLPurifier_AttrDef
$params = explode(',', $parameters);
$ret_params = array();
$lookup = array();
foreach ($params as $param) {
foreach ((array)$params as $param) {
list($key, $value) = explode('=', $param);
$key = trim($key);
$value = trim($value);

View file

@ -65,13 +65,13 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
$stage_1 = array('font-style', 'font-variant', 'font-weight');
$final = ''; // output
for ($i = 0, $size = count($bits); $i < $size; $i++) {
for ($i = 0, $size = count((array)$bits); $i < $size; $i++) {
if ($bits[$i] === '') {
continue;
}
switch ($stage) {
case 0: // attempting to catch font-style, font-variant or font-weight
foreach ($stage_1 as $validator_name) {
foreach ((array)$stage_1 as $validator_name) {
if (isset($caught[$validator_name])) {
continue;
}
@ -87,7 +87,7 @@ class HTMLPurifier_AttrDef_CSS_Font extends HTMLPurifier_AttrDef
}
}
// all three caught, continue on
if (count($caught) >= 3) {
if (count((array)$caught) >= 3) {
$stage = 1;
}
if ($r !== false) {

View file

@ -66,7 +66,7 @@ class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
// assume that no font names contain commas in them
$fonts = explode(',', $string);
$final = '';
foreach ($fonts as $font) {
foreach ((array)$fonts as $font) {
$font = trim($font);
if ($font === '') {
continue;

View file

@ -50,14 +50,14 @@ class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
$i = 0; // number of catches
$none = false;
foreach ($bits as $bit) {
foreach ((array)$bits as $bit) {
if ($i >= 3) {
return;
} // optimization bit
if ($bit === '') {
continue;
}
foreach ($caught as $key => $status) {
foreach ((array)$caught as $key => $status) {
if ($status !== false) {
continue;
}

View file

@ -49,7 +49,7 @@ class HTMLPurifier_AttrDef_CSS_Multiple extends HTMLPurifier_AttrDef
return false;
}
$parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n
$length = count($parts);
$length = count((array)$parts);
$final = '';
for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
if (ctype_space($parts[$i])) {

View file

@ -30,7 +30,7 @@ class HTMLPurifier_AttrDef_CSS_TextDecoration extends HTMLPurifier_AttrDef
$parts = explode(' ', $string);
$final = '';
foreach ($parts as $part) {
foreach ((array)$parts as $part) {
if (isset($allowed_values[$part])) {
$final .= $part . ' ';
}

View file

@ -33,7 +33,7 @@ class HTMLPurifier_AttrDef_HTML_Class extends HTMLPurifier_AttrDef_HTML_Nmtokens
$allowed = $config->get('Attr.AllowedClasses');
$forbidden = $config->get('Attr.ForbiddenClasses');
$ret = array();
foreach ($tokens as $token) {
foreach ((array)$tokens as $token) {
if (($allowed === null || isset($allowed[$token])) &&
!isset($forbidden[$token]) &&
// We need this O(n) check because of PHP's array

View file

@ -53,7 +53,7 @@ class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef
// lookup to prevent duplicates
$ret_lookup = array();
foreach ($parts as $part) {
foreach ((array)$parts as $part) {
$part = strtolower(trim($part));
if (!isset($allowed[$part])) {
continue;

View file

@ -21,7 +21,7 @@ class HTMLPurifier_AttrDef_Lang extends HTMLPurifier_AttrDef
}
$subtags = explode('-', $string);
$num_subtags = count($subtags);
$num_subtags = count((array)$subtags);
if ($num_subtags == 0) { // sanity check
return false;

View file

@ -63,7 +63,7 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef
do {
// generic validation
$result = $uri->validate($config, $context);
$result = $uri->validate($config, is_numeric($context) ? (int)$context : strtotime($context));
if (!$result) {
break;
}

View file

@ -108,7 +108,7 @@ class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
$parts = explode('.', $string);
try {
$new_parts = array();
foreach ($parts as $part) {
foreach ((array)$parts as $part) {
$encodable = false;
for ($i = 0, $c = strlen($part); $i < $c; $i++) {
if (ord($part[$i]) > 0x7a) {

View file

@ -48,7 +48,7 @@ class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
// compression check
$aIP = explode('::', $aIP);
$c = count($aIP);
$c = count((array)$aIP);
if ($c > 2) {
return false;
} elseif ($c == 2) {
@ -56,28 +56,28 @@ class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
$first = explode(':', $first);
$second = explode(':', $second);
if (count($first) + count($second) > 8) {
if (count((array)$first) + count((array)$second) > 8) {
return false;
}
while (count($first) < 8) {
while (count((array)$first) < 8) {
array_push($first, '0');
}
array_splice($first, 8 - count($second), 8, $second);
array_splice($first, 8 - count((array)$second), 8, $second);
$aIP = $first;
unset($first, $second);
} else {
$aIP = explode(':', $aIP[0]);
}
$c = count($aIP);
$c = count((array)$aIP);
if ($c != 8) {
return false;
}
// All the pieces should be 16-bit hex strings. Are they?
foreach ($aIP as $piece) {
foreach ((array)$aIP as $piece) {
if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece))) {
return false;
}

View file

@ -78,7 +78,7 @@ class HTMLPurifier_AttrValidator
// iterate through all the attribute keypairs
// Watch out for name collisions: $key has previously been used
foreach ($attr as $attr_key => $value) {
foreach ((array)$attr as $attr_key => $value) {
// call the definition
if (isset($defs[$attr_key])) {

View file

@ -89,7 +89,7 @@ class HTMLPurifier_Bootstrap
$buggy = version_compare(PHP_VERSION, '5.2.11', '<');
$compat = version_compare(PHP_VERSION, '5.1.2', '<=') &&
version_compare(PHP_VERSION, '5.1.0', '>=');
foreach ($funcs as $func) {
foreach ((array)$funcs as $func) {
if ($buggy && is_array($func)) {
// :TRICKY: There are some compatibility issues and some
// places where we need to error out
@ -113,7 +113,7 @@ class HTMLPurifier_Bootstrap
spl_autoload_unregister($func);
}
spl_autoload_register($autoload);
foreach ($funcs as $func) {
foreach ((array)$funcs as $func) {
spl_autoload_register($func);
}
}

View file

@ -470,7 +470,7 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition
unset($allowed_properties[$name]);
}
// emit errors
foreach ($allowed_properties as $name => $d) {
foreach ((array)$allowed_properties as $name => $d) {
// :TODO: Is this htmlspecialchars() call really necessary?
$name = htmlspecialchars($name);
trigger_error("Style attribute '$name' is not supported $support", E_USER_WARNING);

View file

@ -56,7 +56,7 @@ class HTMLPurifier_ChildDef_Custom extends HTMLPurifier_ChildDef
// collect all elements into the $elements array
preg_match_all("/$el/", $reg, $matches);
foreach ($matches[0] as $match) {
foreach ((array)$matches[0] as $match) {
$this->elements[$match] = true;
}
@ -82,7 +82,7 @@ class HTMLPurifier_ChildDef_Custom extends HTMLPurifier_ChildDef
{
$list_of_children = '';
$nesting = 0; // depth into the nest
foreach ($children as $node) {
foreach ((array)$children as $node) {
if (!empty($node->is_whitespace)) {
continue;
}

View file

@ -52,7 +52,7 @@ class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef
$current_li = false;
foreach ($children as $node) {
foreach ((array)$children as $node) {
if (!empty($node->is_whitespace)) {
$result[] = $node;
continue;

View file

@ -29,7 +29,7 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef
$keys = array_keys($elements);
if ($keys == array_keys($keys)) {
$elements = array_flip($elements);
foreach ($elements as $i => $x) {
foreach ((array)$elements as $i => $x) {
$elements[$i] = true;
if (empty($i)) {
unset($elements[$i]);

View file

@ -69,7 +69,7 @@ class HTMLPurifier_ChildDef_StrictBlockquote extends HTMLPurifier_ChildDef_Requi
$block_wrap = false;
$ret = array();
foreach ($result as $node) {
foreach ((array)$result as $node) {
if ($block_wrap === false) {
if (($node instanceof HTMLPurifier_Node_Text && !$node->is_whitespace) ||
($node instanceof HTMLPurifier_Node_Element && !isset($this->elements[$node->name]))) {

View file

@ -90,7 +90,7 @@ class HTMLPurifier_ChildDef_Table extends HTMLPurifier_ChildDef
$ws_accum =& $initial_ws;
foreach ($children as $node) {
foreach ((array)$children as $node) {
if ($node instanceof HTMLPurifier_Node_Comment) {
$ws_accum[] = $node;
continue;
@ -189,7 +189,7 @@ class HTMLPurifier_ChildDef_Table extends HTMLPurifier_ChildDef
// we have to shuffle tr into tbody
$current_tr_tbody = null;
foreach($content as $node) {
foreach ((array)$content as $node) {
switch ($node->name) {
case 'tbody':
$current_tr_tbody = null;

View file

@ -390,7 +390,7 @@ class HTMLPurifier_Config
private function _listify($lookup)
{
$list = array();
foreach ($lookup as $name => $b) {
foreach ((array)$lookup as $name => $b) {
$list[] = $name;
}
return implode(', ', $list);
@ -681,14 +681,14 @@ class HTMLPurifier_Config
if ($this->isFinalized('Cannot load directives after finalization')) {
return;
}
foreach ($config_array as $key => $value) {
foreach ((array)$config_array as $key => $value) {
$key = str_replace('_', '.', $key);
if (strpos($key, '.') !== false) {
$this->set($key, $value);
} else {
$namespace = $key;
$namespace_values = $value;
foreach ($namespace_values as $directive => $value2) {
foreach ((array)$namespace_values as $directive => $value2) {
$this->set($namespace .'.'. $directive, $value2);
}
}
@ -717,7 +717,7 @@ class HTMLPurifier_Config
$allowed_ns = array();
$allowed_directives = array();
$blacklisted_directives = array();
foreach ($allowed as $ns_or_directive) {
foreach ((array)$allowed as $ns_or_directive) {
if (strpos($ns_or_directive, '.') !== false) {
// directive
if ($ns_or_directive[0] == '-') {
@ -807,7 +807,7 @@ class HTMLPurifier_Config
$allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $schema);
$ret = array();
foreach ($allowed as $key) {
foreach ((array)$allowed as $key) {
list($ns, $directive) = $key;
$skey = "$ns.$directive";
if (!empty($array["Null_$skey"])) {
@ -888,7 +888,7 @@ class HTMLPurifier_Config
if ($this->chatty) {
$trace = debug_backtrace();
// zip(tail(trace), trace) -- but PHP is not Haskell har har
for ($i = 0, $c = count($trace); $i < $c - 1; $i++) {
for ($i = 0, $c = count((array)$trace); $i < $c - 1; $i++) {
// XXX this is not correct on some versions of HTML Purifier
if ($trace[$i + 1]['class'] === 'HTMLPurifier_Config') {
continue;

View file

@ -128,7 +128,7 @@ class HTMLPurifier_ConfigSchema
if (!isset($this->info[$key]->aliases)) {
$this->info[$key]->aliases = array();
}
foreach ($aliases as $alias => $real) {
foreach ((array)$aliases as $alias => $real) {
$this->info[$key]->aliases[$alias] = $real;
}
}

View file

@ -54,7 +54,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
closedir($dh);
sort($files);
foreach ($files as $file) {
foreach ((array)$files as $file) {
$this->buildFile($interchange, $dir . '/' . $file);
}
return $interchange;
@ -88,7 +88,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
}
if (strpos($hash['ID'], '.') === false) {
if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
if (count((array)$hash) == 2 && isset($hash['DESCRIPTION'])) {
$hash->offsetGet('DESCRIPTION'); // prevent complaining
} else {
throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
@ -149,7 +149,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
if (isset($hash['ALIASES'])) {
$raw_aliases = trim($hash->offsetGet('ALIASES'));
$aliases = preg_split('/\s*,\s*/', $raw_aliases);
foreach ($aliases as $alias) {
foreach ((array)$aliases as $alias) {
$directive->aliases[] = $this->id($alias);
}
}
@ -190,7 +190,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
protected function lookup($array)
{
$ret = array();
foreach ($array as $val) {
foreach ((array)$array as $val) {
$ret[$val] = true;
}
return $ret;
@ -215,7 +215,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder
protected function _findUnused($hash)
{
$accessed = $hash->getAccessed();
foreach ($hash as $k => $v) {
foreach ((array)$hash as $k => $v) {
if (!isset($accessed[$k])) {
trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
}

View file

@ -42,7 +42,7 @@ class HTMLPurifier_ContentSets
}
// populate content_sets based on module hints
// sorry, no way of overloading
foreach ($modules as $module) {
foreach ((array)$modules as $module) {
foreach ($module->content_sets as $key => $value) {
$temp = $this->convertToLookup($value);
if (isset($this->lookup[$key])) {
@ -58,7 +58,7 @@ class HTMLPurifier_ContentSets
$old_lookup = $this->lookup;
foreach ($this->lookup as $i => $set) {
$add = array();
foreach ($set as $element => $x) {
foreach ((array)$set as $element => $x) {
if (isset($this->lookup[$element])) {
$add += $this->lookup[$element];
unset($this->lookup[$i][$element]);
@ -160,7 +160,7 @@ class HTMLPurifier_ContentSets
{
$array = explode('|', str_replace(' ', '', $string));
$ret = array();
foreach ($array as $k) {
foreach ((array)$array as $k) {
$ret[$k] = true;
}
return $ret;

View file

@ -86,7 +86,7 @@ class HTMLPurifier_Context
*/
public function loadArray($context_array)
{
foreach ($context_array as $key => $discard) {
foreach ((array)$context_array as $key => $discard) {
$this->register($key, $context_array[$key]);
}
}

View file

@ -157,7 +157,7 @@ class HTMLPurifier_ElementDef
if ($k === 0) {
// merge in the includes
// sorry, no way to override an include
foreach ($v as $v2) {
foreach ((array)$v as $v2) {
$this->attr[0][] = $v2;
}
continue;
@ -201,7 +201,7 @@ class HTMLPurifier_ElementDef
*/
private function _mergeAssocArray(&$a1, $a2)
{
foreach ($a2 as $k => $v) {
foreach ((array)$a2 as $k => $v) {
if ($v === false) {
if (isset($a1[$k])) {
unset($a1[$k]);

View file

@ -441,7 +441,7 @@ class HTMLPurifier_Encoder
$ascii_fix = self::testEncodingSupportsASCII($encoding);
if (!$escape && !empty($ascii_fix)) {
$clear_fix = array();
foreach ($ascii_fix as $utf8 => $native) {
foreach ((array)$ascii_fix as $utf8 => $native) {
$clear_fix[$utf8] = '';
}
$str = strtr($str, $clear_fix);

View file

@ -187,7 +187,7 @@ class HTMLPurifier_ErrorCollector
if ($line == -1) {
continue;
}
foreach ($col_array as $col => $struct) {
foreach ((array)$col_array as $col => $struct) {
$this->_renderStruct($ret, $struct, $line, $col);
}
}
@ -233,7 +233,7 @@ class HTMLPurifier_ErrorCollector
foreach ($current->children as $array) {
$context[] = $current;
$stack = array_merge($stack, array_reverse($array, true));
for ($i = count($array); $i > 0; $i--) {
for ($i = count((array)$array); $i > 0; $i--) {
$context_stack[] = $context;
}
}

View file

@ -103,7 +103,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
$this->_styleMatches = array(); // reset
$context->register('StyleBlocks', $style_blocks); // $context must not be reused
if ($this->_tidy) {
foreach ($style_blocks as &$style) {
foreach ((array)$style_blocks as &$style) {
$style = $this->cleanCSS($style, $config, $context);
}
}
@ -146,7 +146,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
foreach ($this->_tidy->css as $k => $decls) {
// $decls are all CSS declarations inside an @ selector
$new_decls = array();
foreach ($decls as $selector => $style) {
foreach ((array)$decls as $selector => $style) {
$selector = trim($selector);
if ($selector === '') {
continue;
@ -215,7 +215,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
// handle ruleset
$selectors = array_map('trim', explode(',', $selector));
$new_selectors = array();
foreach ($selectors as $sel) {
foreach ((array)$selectors as $sel) {
// split on +, > and spaces
$basic_selectors = preg_split('/\s*([+> ])\s*/', $sel, -1, PREG_SPLIT_DELIM_CAPTURE);
// even indices are chunks, odd indices are
@ -223,7 +223,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
$nsel = null;
$delim = null; // guaranteed to be non-null after
// two loop iterations
for ($i = 0, $c = count($basic_selectors); $i < $c; $i++) {
for ($i = 0, $c = count((array)$basic_selectors); $i < $c; $i++) {
$x = $basic_selectors[$i];
if ($i % 2) {
// delimiter
@ -237,7 +237,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
$components = preg_split('/([#.:])/', $x, -1, PREG_SPLIT_DELIM_CAPTURE);
$sdelim = null;
$nx = null;
for ($j = 0, $cc = count($components); $j < $cc; $j++) {
for ($j = 0, $cc = count((array)$components); $j < $cc; $j++) {
$y = $components[$j];
if ($j === 0) {
if ($y === '*' || isset($html_definition->info[$y = strtolower($y)])) {
@ -289,7 +289,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
}
if ($nsel !== null) {
if (!empty($scopes)) {
foreach ($scopes as $s) {
foreach ((array)$scopes as $s) {
$new_selectors[] = "$s $nsel";
}
} else {
@ -301,7 +301,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter
continue;
}
$selector = implode(', ', $new_selectors);
foreach ($style as $name => $value) {
foreach ((array)$style as $name => $value) {
if (!isset($css_definition->info[$name])) {
unset($style[$name]);
continue;

View file

@ -88,7 +88,7 @@ class HTMLPurifier_Generator
// Basic algorithm
$html = '';
for ($i = 0, $size = count($tokens); $i < $size; $i++) {
for ($i = 0, $size = count((array)$tokens); $i < $size; $i++) {
if ($this->_scriptFix && $tokens[$i]->name === 'script'
&& $i + 2 < $size && $tokens[$i+2] instanceof HTMLPurifier_Token_End) {
// script special case
@ -214,7 +214,7 @@ class HTMLPurifier_Generator
if ($this->_sortAttr) {
ksort($assoc_array_of_attributes);
}
foreach ($assoc_array_of_attributes as $key => $value) {
foreach ((array)$assoc_array_of_attributes as $key => $value) {
if (!$this->_xhtml) {
// Remove namespaced attributes
if (strpos($key, ':') !== false) {

View file

@ -306,7 +306,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
unset($allowed_elements[$name]);
}
// emit errors
foreach ($allowed_elements as $element => $d) {
foreach ((array)$allowed_elements as $element => $d) {
$element = htmlspecialchars($element); // PHP doesn't escape errors, be careful!
trigger_error("Element '$element' is not supported $support", E_USER_WARNING);
}
@ -322,7 +322,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
foreach ($this->info_global_attr as $attr => $x) {
$keys = array($attr, "*@$attr", "*.$attr");
$delete = true;
foreach ($keys as $key) {
foreach ((array)$keys as $key) {
if ($delete && isset($allowed_attributes[$key])) {
$delete = false;
}
@ -339,7 +339,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
foreach ($info->attr as $attr => $x) {
$keys = array("$tag@$attr", $attr, "*@$attr", "$tag.$attr", "*.$attr");
$delete = true;
foreach ($keys as $key) {
foreach ((array)$keys as $key) {
if ($delete && isset($allowed_attributes[$key])) {
$delete = false;
}
@ -360,9 +360,9 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
}
}
// emit errors
foreach ($allowed_attributes_mutable as $elattr => $d) {
foreach ((array)$allowed_attributes_mutable as $elattr => $d) {
$bits = preg_split('/[.@]/', $elattr, 2);
$c = count($bits);
$c = count((array)$bits);
switch ($c) {
case 2:
if ($bits[0] !== '*') {
@ -421,7 +421,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
}
}
}
foreach ($forbidden_attributes as $key => $v) {
foreach ((array)$forbidden_attributes as $key => $v) {
if (strlen($key) < 2) {
continue;
}
@ -463,7 +463,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
$attributes = array();
$chunks = preg_split('/(,|[\n\r]+)/', $list);
foreach ($chunks as $chunk) {
foreach ((array)$chunks as $chunk) {
if (empty($chunk)) {
continue;
}
@ -482,7 +482,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
}
$attr = substr($attr, 0, strlen($attr) - 1); // remove trailing ]
$attr = explode('|', $attr);
foreach ($attr as $key) {
foreach ((array)$attr as $key) {
$attributes["$element.$key"] = true;
}
}

View file

@ -261,7 +261,7 @@ class HTMLPurifier_HTMLModule
$list = func_get_args();
}
$ret = array();
foreach ($list as $value) {
foreach ((array)$list as $value) {
if (is_null($value)) {
continue;
}

View file

@ -13,7 +13,7 @@ class HTMLPurifier_HTMLModule_Name extends HTMLPurifier_HTMLModule
public function setup($config)
{
$elements = array('a', 'applet', 'form', 'frame', 'iframe', 'img', 'map');
foreach ($elements as $name) {
foreach ((array)$elements as $name) {
$element = $this->addBlankElement($name);
$element->attr['name'] = 'CDATA';
if (!$config->get('HTML.Attr.Name.UseCDATA')) {

View file

@ -16,7 +16,7 @@ class HTMLPurifier_HTMLModule_Target extends HTMLPurifier_HTMLModule
public function setup($config)
{
$elements = array('a');
foreach ($elements as $name) {
foreach ((array)$elements as $name) {
$e = $this->addBlankElement($name);
$e->attr = array(
'target' => new HTMLPurifier_AttrDef_HTML_FrameTarget()

View file

@ -54,7 +54,7 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule
$add_fixes = $config->get('HTML.TidyAdd');
$remove_fixes = $config->get('HTML.TidyRemove');
foreach ($fixes as $name => $fix) {
foreach ((array)$fixes as $name => $fix) {
// needs to be refactored a little to implement globbing
if (isset($remove_fixes[$name]) ||
(!isset($add_fixes[$name]) && !isset($fixes_lookup[$name]))) {
@ -92,7 +92,7 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule
return array();
}
$ret = array();
foreach ($activated_levels as $level) {
foreach ((array)$activated_levels as $level) {
foreach ($this->fixesForLevel[$level] as $fix) {
$ret[$fix] = true;
}
@ -128,7 +128,7 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule
*/
public function populate($fixes)
{
foreach ($fixes as $name => $fix) {
foreach ((array)$fixes as $name => $fix) {
// determine what the fix is for
list($type, $params) = $this->getFixType($name);
switch ($type) {

View file

@ -80,7 +80,7 @@ class HTMLPurifier_HTMLModule_Tidy_XHTMLAndHTML4 extends HTMLPurifier_HTMLModule
// {{{
$align_lookup = array();
$align_values = array('left', 'right', 'center', 'justify');
foreach ($align_values as $v) {
foreach ((array)$align_values as $v) {
$align_lookup[$v] = "text-align:$v;";
}
// }}}

View file

@ -242,7 +242,7 @@ class HTMLPurifier_HTMLModuleManager
$special_cases = $config->get('HTML.CoreModules');
if (is_array($lookup)) {
foreach ($modules as $k => $m) {
foreach ((array)$modules as $k => $m) {
if (isset($special_cases[$m])) {
continue;
}
@ -283,7 +283,7 @@ class HTMLPurifier_HTMLModuleManager
// merge in custom modules
$modules = array_merge($modules, $this->userModules);
foreach ($modules as $module) {
foreach ((array)$modules as $module) {
$this->processModule($module);
$this->modules[$module]->setup($config);
}
@ -364,7 +364,7 @@ class HTMLPurifier_HTMLModuleManager
// remove dud elements, this happens when an element that
// appeared to be safe actually wasn't
foreach ($elements as $n => $v) {
foreach ((array)$elements as $n => $v) {
if ($v === false) {
unset($elements[$n]);
}

View file

@ -48,7 +48,7 @@ class HTMLPurifier_IDAccumulator
*/
public function load($array_of_ids)
{
foreach ($array_of_ids as $id) {
foreach ((array)$array_of_ids as $id) {
$this->ids[$id] = true;
}
}

View file

@ -130,7 +130,7 @@ abstract class HTMLPurifier_Injector
if (!is_array($attributes)) {
continue;
}
foreach ($attributes as $name) {
foreach ((array)$attributes as $name) {
if (!isset($def->info[$element]->attr[$name])) {
return "$element.$name";
}

View file

@ -216,7 +216,7 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector
$needs_start = false;
$needs_end = false;
$c = count($raw_paragraphs);
$c = count((array)$raw_paragraphs);
if ($c == 1) {
// There were no double-newlines, abort quickly. In theory this
// should never happen.
@ -269,7 +269,7 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector
}
// Append the paragraphs onto the result
foreach ($paragraphs as $par) {
foreach ((array)$paragraphs as $par) {
$result[] = new HTMLPurifier_Token_Text($par);
$result[] = new HTMLPurifier_Token_End('p');
$result[] = new HTMLPurifier_Token_Text("\n\n");

View file

@ -46,7 +46,7 @@ class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
// $i = index
// $c = count
// $l = is link
for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
for ($i = 0, $c = count((array)$bits), $l = false; $i < $c; $i++, $l = !$l) {
if (!$l) {
if ($bits[$i] === '') {
continue;

View file

@ -50,7 +50,7 @@ class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector
// $i = index
// $c = count
// $l = is link
for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
for ($i = 0, $c = count((array)$bits), $l = false; $i < $c; $i++, $l = !$l) {
if (!$l) {
if ($bits[$i] === '') {
continue;

View file

@ -125,7 +125,7 @@ class HTMLPurifier_Language
$sep = $this->getMessage('Item separator');
$sep_last = $this->getMessage('Item separator last');
$ret = '';
for ($i = 0, $c = count($array); $i < $c; $i++) {
for ($i = 0, $c = count((array)$array); $i < $c; $i++) {
if ($i == 0) {
} elseif ($i + 1 < $c) {
$ret .= $sep;
@ -156,7 +156,7 @@ class HTMLPurifier_Language
$raw = $this->messages[$key];
$subst = array();
$generator = false;
foreach ($args as $i => $value) {
foreach ((array)$args as $i => $value) {
if (is_object($value)) {
if ($value instanceof HTMLPurifier_Token) {
// factor this out some time

View file

@ -216,7 +216,7 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
return array();
}
$array = array();
foreach ($node_map as $attr) {
foreach ((array)$node_map as $attr) {
$array[$attr->name] = $attr->value;
}
return $array;

View file

@ -1850,7 +1850,7 @@ class HTML5TreeConstructer
is already present on the top element of the stack of open elements.
If it is not, add the attribute and its corresponding value to that
element. */
foreach ($token['attr'] as $attr) {
foreach ((array)$token['attr'] as $attr) {
if (!$this->stack[0]->hasAttribute($attr['name'])) {
$this->stack[0]->setAttribute($attr['name'], $attr['value']);
}
@ -2231,7 +2231,7 @@ class HTML5TreeConstructer
add the attribute and its corresponding value to that
element. */
} else {
foreach ($token['attr'] as $attr) {
foreach ((array)$token['attr'] as $attr) {
if (!$this->stack[1]->hasAttribute($attr['name'])) {
$this->stack[1]->setAttribute($attr['name'], $attr['value']);
}
@ -4408,7 +4408,7 @@ class HTML5TreeConstructer
$el = $this->dom->createElement($token['name']);
foreach ($token['attr'] as $attr) {
foreach ((array)$token['attr'] as $attr) {
if (!$el->hasAttribute($attr['name'])) {
$el->setAttribute($attr['name'], $attr['value']);
}
@ -4466,7 +4466,7 @@ class HTML5TreeConstructer
private function elementInScope($el, $table = false)
{
if (is_array($el)) {
foreach ($el as $element) {
foreach ((array)$el as $element) {
if ($this->elementInScope($element, $table)) {
return true;
}

View file

@ -84,7 +84,7 @@ class HTMLPurifier_PercentEncoder
}
$parts = explode('%', $string);
$ret = array_shift($parts);
foreach ($parts as $part) {
foreach ((array)$parts as $part) {
$length = strlen($part);
if ($length < 2) {
$ret .= '%25' . $part;

View file

@ -147,8 +147,8 @@ class HTMLPurifier_Printer
return 'None';
}
$ret = '';
$i = count($array);
foreach ($array as $value) {
$i = count((array)$array);
foreach ((array)$array as $value) {
$i--;
$ret .= $value;
if ($i > 0 && !($polite && $i == 1)) {

View file

@ -105,7 +105,7 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer
$allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def);
$all = array();
foreach ($allowed as $key) {
foreach ((array)$allowed as $key) {
list($ns, $directive) = $key;
$all[$ns][$directive] = $config->get($ns . '.' . $directive);
}
@ -118,7 +118,7 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer
$ret .= $this->element('th', 'Value', array('class' => 'hp-value'));
$ret .= $this->end('tr');
$ret .= $this->end('thead');
foreach ($all as $ns => $directives) {
foreach ((array)$all as $ns => $directives) {
$ret .= $this->renderNamespace($ns, $directives);
}
if ($render_controls) {
@ -150,7 +150,7 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer
$ret .= $this->end('tr');
$ret .= $this->end('tbody');
$ret .= $this->start('tbody');
foreach ($directives as $directive => $value) {
foreach ((array)$directives as $directive => $value) {
$ret .= $this->start('tr');
$ret .= $this->start('th');
if ($this->docURL) {
@ -317,7 +317,7 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer
case HTMLPurifier_VarParser::LOOKUP:
$array = $value;
$value = array();
foreach ($array as $val => $b) {
foreach ((array)$array as $val => $b) {
$value[] = $val;
}
//TODO does this need a break?
@ -326,7 +326,7 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer
break;
case HTMLPurifier_VarParser::HASH:
$nvalue = '';
foreach ($value as $i => $v) {
foreach ((array)$value as $i => $v) {
if (is_array($v)) {
// HACK
$v = implode(";", $v);

View file

@ -262,7 +262,7 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
{
ksort($array);
$list = array();
foreach ($array as $name => $discard) {
foreach ((array)$array as $name => $discard) {
if ($name !== '#PCDATA' && !isset($this->def->info[$name])) {
continue;
}
@ -281,7 +281,7 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
{
ksort($array);
$list = array();
foreach ($array as $obj) {
foreach ((array)$array as $obj) {
$list[] = $this->getClass($obj, 'AttrTransform_');
}
return $this->listify($list);
@ -296,7 +296,7 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
{
ksort($array);
$list = array();
foreach ($array as $name => $obj) {
foreach ((array)$array as $name => $obj) {
if ($obj === false) {
continue;
}

View file

@ -102,7 +102,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
$def_injectors = $definition->info_injector;
$custom_injectors = $injectors['Custom'];
unset($injectors['Custom']); // special case
foreach ($injectors as $injector => $b) {
foreach ((array)$injectors as $injector => $b) {
// XXX: Fix with a legitimate lookup table of enabled filters
if (strpos($injector, '.') !== false) {
continue;
@ -113,11 +113,11 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
}
$this->injectors[] = new $injector;
}
foreach ($def_injectors as $injector) {
foreach ((array)$def_injectors as $injector) {
// assumed to be objects
$this->injectors[] = $injector;
}
foreach ($custom_injectors as $injector) {
foreach ((array)$custom_injectors as $injector) {
if (!$injector) {
continue;
}
@ -475,7 +475,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
}
// do errors, in REVERSE $j order: a,b,c with </a></b></c>
$c = count($skipped_tags);
$c = count((array)$skipped_tags);
if ($e) {
for ($j = $c - 1; $j > 0; $j--) {
// notice we exclude $j == 0, i.e. the current ending tag, from
@ -576,7 +576,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
// Also, mark the newly inserted tokens as having come from
// $injector.
$oldskip = isset($old[0]) ? $old[0]->skip : array();
foreach ($token as $object) {
foreach ((array)$token as $object) {
$object->skip = $oldskip;
$object->skip[$injector] = true;
}

View file

@ -58,7 +58,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
$e =& $context->get('ErrorCollector');
}
foreach ($tokens as $token) {
foreach ((array)$tokens as $token) {
if ($remove_until) {
if (empty($token->is_tag) || $token->name !== $remove_until) {
continue;

View file

@ -21,7 +21,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
$token = false;
$context->register('CurrentToken', $token);
foreach ($tokens as $key => $token) {
foreach ((array)$tokens as $key => $token) {
// only process tokens that have attributes,
// namely start and empty tags

View file

@ -42,7 +42,7 @@ abstract class HTMLPurifier_Token_Tag extends HTMLPurifier_Token
public function __construct($name, $attr = array(), $line = null, $col = null, $armor = array())
{
$this->name = ctype_lower($name) ? $name : strtolower($name);
foreach ($attr as $key => $value) {
foreach ((array)$attr as $key => $value) {
// normalization only necessary when key is not lowercase
if (!ctype_lower($key)) {
$new_key = strtolower($key);

View file

@ -105,7 +105,7 @@ class HTMLPurifier_URI
* @param HTMLPurifier_Context $context
* @return bool True if validation/filtering succeeds, false if failure
*/
public function validate($config, $context)
public function validate($config, is_numeric($context) ? (int)$context : strtotime($context))
{
// ABNF definitions from RFC 3986
$chars_sub_delims = '!$&\'()*+,;=';

View file

@ -39,7 +39,7 @@ class HTMLPurifier_URIScheme_data extends HTMLPurifier_URIScheme
$is_base64 = false;
$charset = null;
$content_type = null;
if (count($result) == 2) {
if (count((array)$result) == 2) {
list($metadata, $data) = $result;
// do some legwork on the metadata
$metas = explode(';', $metadata);

View file

@ -107,7 +107,7 @@ class HTMLPurifier_VarParser
break;
}
if ($type === self::LOOKUP) {
foreach ($var as $k) {
foreach ((array)$var as $k) {
if ($k !== true) {
$this->error('Lookup table contains value other than true');
}

View file

@ -70,13 +70,13 @@ class HTMLPurifier_VarParser_Flexible extends HTMLPurifier_VarParser
$var = preg_split('/(,|[\n\r]+)/', $var);
}
// remove spaces
foreach ($var as $i => $j) {
foreach ((array)$var as $i => $j) {
$var[$i] = trim($j);
}
if ($type === self::HASH) {
// key:value,key2:value2
$nvar = array();
foreach ($var as $keypair) {
foreach ((array)$var as $keypair) {
$c = explode(':', $keypair, 2);
if (!isset($c[1])) {
continue;
@ -95,7 +95,7 @@ class HTMLPurifier_VarParser_Flexible extends HTMLPurifier_VarParser
return $var;
} elseif ($type == self::LOOKUP) {
$new = array();
foreach ($var as $key) {
foreach ((array)$var as $key) {
$new[$key] = true;
}
return $new;
@ -108,7 +108,7 @@ class HTMLPurifier_VarParser_Flexible extends HTMLPurifier_VarParser
return array_values($var);
}
if ($type === self::LOOKUP) {
foreach ($var as $key => $value) {
foreach ((array)$var as $key => $value) {
if ($value !== true) {
trigger_error(
"Lookup array has non-true value at key '$key'; " .

View file

@ -148,7 +148,7 @@ class HTMLPurifier_Zipper
$r = $this->delete();
}
// insert
for ($i = count($replacement)-1; $i >= 0; $i--) {
for ($i = count((array)$replacement)-1; $i >= 0; $i--) {
$this->insertAfter($r);
$r = $replacement[$i];
}