| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 3 |
if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 4 |
|
| 5 |
if (!trait_exists('WPRProtectFWRuleArrayFunc_V636')) : |
| 6 |
trait WPRProtectFWRuleArrayFunc_V636 { |
| 7 |
private function _rf_inArray() { |
| 8 |
$args = $this->processRuleFunctionParams( |
| 9 |
'inArray', |
| 10 |
func_num_args(), |
| 11 |
func_get_args(), |
| 12 |
2 |
| 13 |
); |
| 14 |
$element = $args[0]; |
| 15 |
$array = $args[1]; |
| 16 |
$strict = isset($args[2]) ? $args[2] : false; |
| 17 |
|
| 18 |
if (!is_array($array)) { |
| 19 |
throw new WPRProtectRuleError_V636( |
| 20 |
$this->addExState("inArray: 2nd param is not an array") |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
if (!is_bool($strict)) { |
| 25 |
throw new WPRProtectRuleError_V636( |
| 26 |
$this->addExState("inArray: 3rd param is not a boolean") |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
return in_array($element, $array, $strict); |
| 31 |
} |
| 32 |
|
| 33 |
private function _rf_recInArray() { |
| 34 |
$args = $this->processRuleFunctionParams( |
| 35 |
'recInArray', |
| 36 |
func_num_args(), |
| 37 |
func_get_args(), |
| 38 |
2 |
| 39 |
); |
| 40 |
$element = $args[0]; |
| 41 |
$array = $args[1]; |
| 42 |
|
| 43 |
if (is_array($array)) { |
| 44 |
foreach ($array as $key => $value) { |
| 45 |
if (is_array($value)) { |
| 46 |
if ($this->_rf_recInArray($element, $value)) { |
| 47 |
return true; |
| 48 |
} |
| 49 |
} else { |
| 50 |
if ($value === $element) { |
| 51 |
return true; |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
} else { |
| 56 |
throw new WPRProtectRuleError_V636( |
| 57 |
$this->addExState("recInArray: Expects an array") |
| 58 |
); |
| 59 |
} |
| 60 |
|
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
private function _rf_arrayKeyExists() { |
| 65 |
$args = $this->processRuleFunctionParams( |
| 66 |
'arrayKeyExists', |
| 67 |
func_num_args(), |
| 68 |
func_get_args(), |
| 69 |
2 |
| 70 |
); |
| 71 |
$key = $args[0]; |
| 72 |
$array = $args[1]; |
| 73 |
|
| 74 |
if (!is_array($array)) { |
| 75 |
throw new WPRProtectRuleError_V636( |
| 76 |
$this->addExState("arrayKeyExists: Array must be of type array") |
| 77 |
); |
| 78 |
} elseif (!is_string($key) && !is_int($key)) { |
| 79 |
throw new WPRProtectRuleError_V636( |
| 80 |
$this->addExState("arrayKeyExists: Key must be of type string or int") |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
return array_key_exists($key, $array); |
| 85 |
} |
| 86 |
|
| 87 |
private function _rf_isArrayEmpty() { |
| 88 |
$args = $this->processRuleFunctionParams( |
| 89 |
'isArrayEmpty', |
| 90 |
func_num_args(), |
| 91 |
func_get_args(), |
| 92 |
1, |
| 93 |
['array'] |
| 94 |
); |
| 95 |
$array = $args[0]; |
| 96 |
|
| 97 |
return $this->_rf_isEmpty($array); |
| 98 |
} |
| 99 |
|
| 100 |
private function _rf_getArrayKeys() { |
| 101 |
$args = $this->processRuleFunctionParams( |
| 102 |
'getArrayKeys', |
| 103 |
func_num_args(), |
| 104 |
func_get_args(), |
| 105 |
1, |
| 106 |
['array'] |
| 107 |
); |
| 108 |
$array = $args[0]; |
| 109 |
|
| 110 |
return array_keys($array); |
| 111 |
} |
| 112 |
|
| 113 |
private function _rf_hasAnyArrayKey() { |
| 114 |
$args = $this->processRuleFunctionParams( |
| 115 |
'hasAnyArrayKey', |
| 116 |
func_num_args(), |
| 117 |
func_get_args(), |
| 118 |
2, |
| 119 |
['array', 'array'] |
| 120 |
); |
| 121 |
$array = $args[0]; |
| 122 |
$keys = $args[1]; |
| 123 |
|
| 124 |
foreach ($keys as $key) { |
| 125 |
if (!is_int($key) && !is_string($key)) { |
| 126 |
throw new WPRProtectRuleError_V636( |
| 127 |
$this->addExState("hasAnyArrayKey: Key must be of type string or int") |
| 128 |
); |
| 129 |
} |
| 130 |
|
| 131 |
if (array_key_exists($key, $array)) { |
| 132 |
return true; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
return false; |
| 137 |
} |
| 138 |
|
| 139 |
private function _rf_digArray() { |
| 140 |
$args = $this->processRuleFunctionParams( |
| 141 |
'digArray', |
| 142 |
func_num_args(), |
| 143 |
func_get_args(), |
| 144 |
2, |
| 145 |
['array', 'array'] |
| 146 |
); |
| 147 |
$array = $args[0]; |
| 148 |
$keys = $args[1]; |
| 149 |
|
| 150 |
foreach ($keys as $key) { |
| 151 |
if (!is_int($key) && !is_string($key)) { |
| 152 |
throw new WPRProtectRuleError_V636( |
| 153 |
$this->addExState("digArray: Keys must be a valid array of string, or integer type") |
| 154 |
); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
return WPRHelper::digArray($array, $keys); |
| 159 |
} |
| 160 |
|
| 161 |
private function _rf_filterArray() { |
| 162 |
$args = $this->processRuleFunctionParams( |
| 163 |
'filterArray', |
| 164 |
func_num_args(), |
| 165 |
func_get_args(), |
| 166 |
2, |
| 167 |
['array', 'array'] |
| 168 |
); |
| 169 |
$array = $args[0]; |
| 170 |
$keys = $args[1]; |
| 171 |
|
| 172 |
foreach ($keys as $key) { |
| 173 |
if (!is_int($key) && !is_string($key)) { |
| 174 |
throw new WPRProtectRuleError_V636( |
| 175 |
$this->addExState("filterArray: Keys must be a valid array of string, or integer type") |
| 176 |
); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
return WPRHelper::filterArray($array, $keys); |
| 181 |
} |
| 182 |
|
| 183 |
private function _rf_getArrayVal() { |
| 184 |
$args = $this->processRuleFunctionParams( |
| 185 |
'getArrayVal', |
| 186 |
func_num_args(), |
| 187 |
func_get_args(), |
| 188 |
2, |
| 189 |
['array'] |
| 190 |
); |
| 191 |
$array = $args[0]; |
| 192 |
$key = $args[1]; |
| 193 |
|
| 194 |
if (!is_string($key) && !is_int($key)) { |
| 195 |
throw new WPRProtectRuleError_V636( |
| 196 |
$this->addExState("getArrayVal: Key must be a valid string or integer") |
| 197 |
); |
| 198 |
} |
| 199 |
|
| 200 |
if (array_key_exists($key, $array)) { |
| 201 |
return $array[$key]; |
| 202 |
} |
| 203 |
|
| 204 |
return null; |
| 205 |
} |
| 206 |
|
| 207 |
private function _rf_arrayIntersection() { |
| 208 |
$args = $this->processRuleFunctionParams( |
| 209 |
'arrayIntersection', |
| 210 |
func_num_args(), |
| 211 |
func_get_args(), |
| 212 |
2, |
| 213 |
['array', 'array'] |
| 214 |
); |
| 215 |
$array1 = $args[0]; |
| 216 |
$array2 = $args[1]; |
| 217 |
|
| 218 |
return array_intersect($array1, $array2); |
| 219 |
} |
| 220 |
|
| 221 |
private function _rf_arrayIntersectionAssoc() { |
| 222 |
$args = $this->processRuleFunctionParams( |
| 223 |
'arrayIntersectionAssoc', |
| 224 |
func_num_args(), |
| 225 |
func_get_args(), |
| 226 |
2, |
| 227 |
['array', 'array'] |
| 228 |
); |
| 229 |
$array1 = $args[0]; |
| 230 |
$array2 = $args[1]; |
| 231 |
|
| 232 |
return array_intersect_assoc($array1, $array2); |
| 233 |
} |
| 234 |
|
| 235 |
private function _rf_arrayUnion() { |
| 236 |
$args = $this->processRuleFunctionParams( |
| 237 |
'arrayUnion', |
| 238 |
func_num_args(), |
| 239 |
func_get_args(), |
| 240 |
2, |
| 241 |
['array', 'array'] |
| 242 |
); |
| 243 |
$array1 = $args[0]; |
| 244 |
$array2 = $args[1]; |
| 245 |
|
| 246 |
return ($array1 + $array2); |
| 247 |
} |
| 248 |
|
| 249 |
private function _rf_arrayMerge() { |
| 250 |
$args = $this->processRuleFunctionParams( |
| 251 |
'arrayMerge', |
| 252 |
func_num_args(), |
| 253 |
func_get_args(), |
| 254 |
2, |
| 255 |
['array', 'array'] |
| 256 |
); |
| 257 |
$array1 = $args[0]; |
| 258 |
$array2 = $args[1]; |
| 259 |
|
| 260 |
return array_merge($array1, $array2); |
| 261 |
} |
| 262 |
|
| 263 |
private function _rf_arrayJoin() { |
| 264 |
$args = $this->processRuleFunctionParams( |
| 265 |
'arrayJoin', |
| 266 |
func_num_args(), |
| 267 |
func_get_args(), |
| 268 |
2, |
| 269 |
['string', 'array'] |
| 270 |
); |
| 271 |
$separator = $args[0]; |
| 272 |
$array = $args[1]; |
| 273 |
|
| 274 |
foreach ($array as $element) { |
| 275 |
if (!is_scalar($element)) { |
| 276 |
throw new WPRProtectRuleError_V636( |
| 277 |
$this->addExState("arrayJoin: Array element must be of scalar type") |
| 278 |
); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
return implode($separator, $array); |
| 283 |
} |
| 284 |
} |
| 285 |
endif; |