| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 3 |
if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 4 |
|
| 5 |
if (!trait_exists('WPRProtectFWRuleMiscFunc_V676')) : |
| 6 |
trait WPRProtectFWRuleMiscFunc_V676 { |
| 7 |
private function _rf_isTrue() { |
| 8 |
$args = $this->processRuleFunctionParams( |
| 9 |
'isTrue', |
| 10 |
func_num_args(), |
| 11 |
func_get_args(), |
| 12 |
1 |
| 13 |
); |
| 14 |
$value = $args[0]; |
| 15 |
|
| 16 |
return ($value === true); |
| 17 |
} |
| 18 |
|
| 19 |
private function _rf_isFalse() { |
| 20 |
$args = $this->processRuleFunctionParams( |
| 21 |
'isFalse', |
| 22 |
func_num_args(), |
| 23 |
func_get_args(), |
| 24 |
1 |
| 25 |
); |
| 26 |
$value = $args[0]; |
| 27 |
|
| 28 |
return ($value === false); |
| 29 |
} |
| 30 |
|
| 31 |
private function _rf_isFileUpload() { |
| 32 |
$args = $this->processRuleFunctionParams( |
| 33 |
'isFileUpload', |
| 34 |
func_num_args(), |
| 35 |
func_get_args(), |
| 36 |
1 |
| 37 |
); |
| 38 |
$value = $args[0]; |
| 39 |
|
| 40 |
$file = $this->_rf_getFiles($value); |
| 41 |
if (!is_array($file) || !array_key_exists('tmp_name', $file)) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
$paths = array($file['tmp_name']); |
| 46 |
while (!empty($paths)) { |
| 47 |
$path = array_pop($paths); |
| 48 |
|
| 49 |
if (is_array($path)) { |
| 50 |
foreach ($path as $nested_path) { |
| 51 |
$paths[] = $nested_path; |
| 52 |
} |
| 53 |
continue; |
| 54 |
} |
| 55 |
|
| 56 |
if (is_string($path) && $path !== '' && is_uploaded_file($path)) { |
| 57 |
return true; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
private function _rf_getVarValue() { |
| 65 |
$args = $this->processRuleFunctionParams( |
| 66 |
'getVarValue', |
| 67 |
func_num_args(), |
| 68 |
func_get_args(), |
| 69 |
1, |
| 70 |
['string'] |
| 71 |
); |
| 72 |
$name = $args[0]; |
| 73 |
|
| 74 |
if (!array_key_exists($name, $this->variables)) { |
| 75 |
throw new WPRProtectRuleError_V676( |
| 76 |
$this->addExState("UndefinedVariableError: " . $name . " is not defined.") |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
return $this->variables[$name]; |
| 81 |
} |
| 82 |
|
| 83 |
private function _rf_getVariables() { |
| 84 |
$args = $this->processRuleFunctionParams( |
| 85 |
'getVariables', |
| 86 |
func_num_args(), |
| 87 |
func_get_args() |
| 88 |
); |
| 89 |
|
| 90 |
return $this->variables; |
| 91 |
} |
| 92 |
|
| 93 |
private function _rf_digVariables() { |
| 94 |
$args = $this->processRuleFunctionParams( |
| 95 |
'digVariables', |
| 96 |
func_num_args(), |
| 97 |
func_get_args(), |
| 98 |
1, |
| 99 |
['array'] |
| 100 |
); |
| 101 |
$keys = $args[0]; |
| 102 |
|
| 103 |
return $this->_rf_digArray($this->variables, $keys); |
| 104 |
} |
| 105 |
|
| 106 |
private function _rf_isPostRequest() { |
| 107 |
$args = $this->processRuleFunctionParams( |
| 108 |
'isPostRequest', |
| 109 |
func_num_args(), |
| 110 |
func_get_args() |
| 111 |
); |
| 112 |
|
| 113 |
return $this->_rf_getReqMethod() === "POST"; |
| 114 |
} |
| 115 |
|
| 116 |
private function _rf_match() { |
| 117 |
$args = $this->processRuleFunctionParams( |
| 118 |
'match', |
| 119 |
func_num_args(), |
| 120 |
func_get_args(), |
| 121 |
2 |
| 122 |
); |
| 123 |
$pattern = $args[0]; |
| 124 |
$subject = $args[1]; |
| 125 |
|
| 126 |
if (is_array($subject)) { |
| 127 |
foreach ($subject as $k => $v) { |
| 128 |
if ($this->_rf_match($pattern, $v)) { |
| 129 |
return true; |
| 130 |
} |
| 131 |
} |
| 132 |
return false; |
| 133 |
} |
| 134 |
$resp = WPRHelper::safePregMatch((string) $pattern, (string) $subject); |
| 135 |
if ($resp === false) { |
| 136 |
throw new WPRProtectRuleError_V676( |
| 137 |
$this->addExState('BVHelper::safePregMatch' . serialize($subject)) |
| 138 |
); |
| 139 |
} elseif ($resp > 0) { |
| 140 |
return true; |
| 141 |
} |
| 142 |
return false; |
| 143 |
} |
| 144 |
|
| 145 |
private function _rf_notMatch() { |
| 146 |
$args = $this->processRuleFunctionParams( |
| 147 |
'notMatch', |
| 148 |
func_num_args(), |
| 149 |
func_get_args(), |
| 150 |
2 |
| 151 |
); |
| 152 |
$pattern = $args[0]; |
| 153 |
$subject = $args[1]; |
| 154 |
|
| 155 |
return !$this->_rf_match($pattern, $subject); |
| 156 |
} |
| 157 |
|
| 158 |
private function _rf_matchCount() { |
| 159 |
$args = $this->processRuleFunctionParams( |
| 160 |
'matchCount', |
| 161 |
func_num_args(), |
| 162 |
func_get_args(), |
| 163 |
2 |
| 164 |
); |
| 165 |
$pattern = $args[0]; |
| 166 |
$subject = $args[1]; |
| 167 |
|
| 168 |
$count = 0; |
| 169 |
if (is_array($subject)) { |
| 170 |
foreach ($subject as $val) { |
| 171 |
$count += $this->_rf_matchCount($pattern, $val); |
| 172 |
} |
| 173 |
return $count; |
| 174 |
} |
| 175 |
$count = preg_match_all((string) $pattern, (string) $subject, $matches); |
| 176 |
if ($count === false) { |
| 177 |
throw new WPRProtectRuleError_V676( |
| 178 |
$this->addExState("preg_match_all: " . serialize($subject)) |
| 179 |
); |
| 180 |
} |
| 181 |
return $count; |
| 182 |
} |
| 183 |
|
| 184 |
private function _rf_maxMatchCount() { |
| 185 |
$args = $this->processRuleFunctionParams( |
| 186 |
'maxMatchCount', |
| 187 |
func_num_args(), |
| 188 |
func_get_args(), |
| 189 |
2 |
| 190 |
); |
| 191 |
$pattern = $args[0]; |
| 192 |
$subject = $args[1]; |
| 193 |
|
| 194 |
$count = 0; |
| 195 |
if (is_array($subject)) { |
| 196 |
foreach ($subject as $val) { |
| 197 |
$count = max($count, $this->_rf_matchCount($pattern, $val)); |
| 198 |
} |
| 199 |
return $count; |
| 200 |
} |
| 201 |
$count = preg_match_all((string) $pattern, (string) $subject, $matches); |
| 202 |
if ($count === false) { |
| 203 |
throw new WPRProtectRuleError_V676( |
| 204 |
$this->addExState("preg_match_all: " . serialize($subject)) |
| 205 |
); |
| 206 |
} |
| 207 |
return $count; |
| 208 |
} |
| 209 |
|
| 210 |
private function _rf_equals() { |
| 211 |
$args = $this->processRuleFunctionParams( |
| 212 |
'equals', |
| 213 |
func_num_args(), |
| 214 |
func_get_args(), |
| 215 |
2 |
| 216 |
); |
| 217 |
$val = $args[0]; |
| 218 |
$subject = $args[1]; |
| 219 |
|
| 220 |
return ($val == $subject); |
| 221 |
} |
| 222 |
|
| 223 |
private function _rf_notEquals() { |
| 224 |
$args = $this->processRuleFunctionParams( |
| 225 |
'notEquals', |
| 226 |
func_num_args(), |
| 227 |
func_get_args(), |
| 228 |
2 |
| 229 |
); |
| 230 |
$val = $args[0]; |
| 231 |
$subject = $args[1]; |
| 232 |
|
| 233 |
return !$this->_rf_equals($val, $subject); |
| 234 |
} |
| 235 |
|
| 236 |
private function _rf_isIdentical() { |
| 237 |
$args = $this->processRuleFunctionParams( |
| 238 |
'isIdentical', |
| 239 |
func_num_args(), |
| 240 |
func_get_args(), |
| 241 |
2 |
| 242 |
); |
| 243 |
$val = $args[0]; |
| 244 |
$subject = $args[1]; |
| 245 |
|
| 246 |
return ($val === $subject); |
| 247 |
} |
| 248 |
|
| 249 |
private function _rf_notIdentical() { |
| 250 |
$args = $this->processRuleFunctionParams( |
| 251 |
'notIdentical', |
| 252 |
func_num_args(), |
| 253 |
func_get_args(), |
| 254 |
2 |
| 255 |
); |
| 256 |
$val = $args[0]; |
| 257 |
$subject = $args[1]; |
| 258 |
|
| 259 |
return !$this->_rf_isIdentical($val, $subject); |
| 260 |
} |
| 261 |
|
| 262 |
private function _rf_greaterThan() { |
| 263 |
$args = $this->processRuleFunctionParams( |
| 264 |
'greaterThan', |
| 265 |
func_num_args(), |
| 266 |
func_get_args(), |
| 267 |
2 |
| 268 |
); |
| 269 |
$val = $args[0]; |
| 270 |
$subject = $args[1]; |
| 271 |
|
| 272 |
return ($subject > $val); |
| 273 |
} |
| 274 |
|
| 275 |
private function _rf_greaterThanEqualTo() { |
| 276 |
$args = $this->processRuleFunctionParams( |
| 277 |
'greaterThanEqualTo', |
| 278 |
func_num_args(), |
| 279 |
func_get_args(), |
| 280 |
2 |
| 281 |
); |
| 282 |
$val = $args[0]; |
| 283 |
$subject = $args[1]; |
| 284 |
|
| 285 |
return ($subject >= $val); |
| 286 |
} |
| 287 |
|
| 288 |
private function _rf_lessThan() { |
| 289 |
$args = $this->processRuleFunctionParams( |
| 290 |
'lessThan', |
| 291 |
func_num_args(), |
| 292 |
func_get_args(), |
| 293 |
2 |
| 294 |
); |
| 295 |
$val = $args[0]; |
| 296 |
$subject = $args[1]; |
| 297 |
|
| 298 |
return ($subject < $val); |
| 299 |
} |
| 300 |
|
| 301 |
private function _rf_lessThanEqualTo() { |
| 302 |
$args = $this->processRuleFunctionParams( |
| 303 |
'lessThanEqualTo', |
| 304 |
func_num_args(), |
| 305 |
func_get_args(), |
| 306 |
2 |
| 307 |
); |
| 308 |
$val = $args[0]; |
| 309 |
$subject = $args[1]; |
| 310 |
|
| 311 |
return ($subject <= $val); |
| 312 |
} |
| 313 |
|
| 314 |
private function _rf_lengthGreaterThan() { |
| 315 |
$args = $this->processRuleFunctionParams( |
| 316 |
'lengthGreaterThan', |
| 317 |
func_num_args(), |
| 318 |
func_get_args(), |
| 319 |
2 |
| 320 |
); |
| 321 |
$val = $args[0]; |
| 322 |
$subject = $args[1]; |
| 323 |
|
| 324 |
return (strlen((string) $subject) > $val); |
| 325 |
} |
| 326 |
|
| 327 |
private function _rf_lengthLessThan() { |
| 328 |
$args = $this->processRuleFunctionParams( |
| 329 |
'lengthLessThan', |
| 330 |
func_num_args(), |
| 331 |
func_get_args(), |
| 332 |
2 |
| 333 |
); |
| 334 |
$val = $args[0]; |
| 335 |
$subject = $args[1]; |
| 336 |
|
| 337 |
return (strlen((string) $subject) < $val); |
| 338 |
} |
| 339 |
|
| 340 |
private function _rf_md5Equals() { |
| 341 |
$args = $this->processRuleFunctionParams( |
| 342 |
'md5Equals', |
| 343 |
func_num_args(), |
| 344 |
func_get_args(), |
| 345 |
2 |
| 346 |
); |
| 347 |
$val = $args[0]; |
| 348 |
$subject = $args[1]; |
| 349 |
|
| 350 |
return (md5((string) $subject) === $val); |
| 351 |
} |
| 352 |
|
| 353 |
private function _rf_matchActions() { |
| 354 |
$args = $this->processRuleFunctionParams( |
| 355 |
'matchActions', |
| 356 |
func_num_args(), |
| 357 |
func_get_args(), |
| 358 |
1 |
| 359 |
); |
| 360 |
$actions = $args[0]; |
| 361 |
|
| 362 |
return $this->_rf_inArray($this->_rf_getAction(), $actions); |
| 363 |
} |
| 364 |
|
| 365 |
private function _rf_compareMultipleSubjects() { |
| 366 |
$args = $this->processRuleFunctionParams( |
| 367 |
'compareMultipleSubjects', |
| 368 |
func_num_args(), |
| 369 |
func_get_args(), |
| 370 |
3 |
| 371 |
); |
| 372 |
$func = $args[0]; |
| 373 |
$_args = $args[1]; |
| 374 |
$subjects = $args[2]; |
| 375 |
|
| 376 |
// TODO |
| 377 |
} |
| 378 |
|
| 379 |
private function _rf_isset() { |
| 380 |
$args = $this->processRuleFunctionParams( |
| 381 |
'isset', |
| 382 |
func_num_args(), |
| 383 |
func_get_args(), |
| 384 |
1 |
| 385 |
); |
| 386 |
$var = $args[0]; |
| 387 |
|
| 388 |
return isset($var); |
| 389 |
} |
| 390 |
|
| 391 |
private function _rf_getDebugBacktrace() { |
| 392 |
$this->processRuleFunctionParams( |
| 393 |
'getDebugBacktrace', |
| 394 |
func_num_args(), |
| 395 |
func_get_args() |
| 396 |
); |
| 397 |
|
| 398 |
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace -- Needed for stack trace functionality |
| 399 |
return debug_backtrace(); |
| 400 |
} |
| 401 |
|
| 402 |
private function _rf_getFilesFromBacktrace() { |
| 403 |
$this->processRuleFunctionParams( |
| 404 |
'getFilesFromBacktrace', |
| 405 |
func_num_args(), |
| 406 |
func_get_args() |
| 407 |
); |
| 408 |
|
| 409 |
$files = array(); |
| 410 |
$backtrace = $this->_rf_getDebugBacktrace(); |
| 411 |
|
| 412 |
foreach ($backtrace as $trace) { |
| 413 |
if (isset($trace['file']) && is_string($trace['file'])) { |
| 414 |
$files[] = $trace['file']; |
| 415 |
} |
| 416 |
} |
| 417 |
|
| 418 |
return $files; |
| 419 |
} |
| 420 |
|
| 421 |
private function _rf_isAnyFileInBacktrace() { |
| 422 |
$args = $this->processRuleFunctionParams( |
| 423 |
'isAnyFileInBacktrace', |
| 424 |
func_num_args(), |
| 425 |
func_get_args(), |
| 426 |
1, |
| 427 |
['array'] |
| 428 |
); |
| 429 |
$names = $args[0]; |
| 430 |
|
| 431 |
return $this->_rf_checkStringsForSubstringsPos($this->_rf_getFilesFromBacktrace(), $names, 0); |
| 432 |
} |
| 433 |
|
| 434 |
private function _rf_isEmpty() { |
| 435 |
$args = $this->processRuleFunctionParams( |
| 436 |
'isEmpty', |
| 437 |
func_num_args(), |
| 438 |
func_get_args(), |
| 439 |
1 |
| 440 |
); |
| 441 |
$value = $args[0]; |
| 442 |
|
| 443 |
return (empty($value)); |
| 444 |
} |
| 445 |
|
| 446 |
private function _rf_isConstantDefined() { |
| 447 |
$args = $this->processRuleFunctionParams( |
| 448 |
'isConstantDefined', |
| 449 |
func_num_args(), |
| 450 |
func_get_args(), |
| 451 |
1, |
| 452 |
['string'] |
| 453 |
); |
| 454 |
$constant_name = $args[0]; |
| 455 |
|
| 456 |
return defined($constant_name); |
| 457 |
} |
| 458 |
|
| 459 |
private function _rf_isArray() { |
| 460 |
$args = $this->processRuleFunctionParams( |
| 461 |
'isArray', |
| 462 |
func_num_args(), |
| 463 |
func_get_args(), |
| 464 |
1 |
| 465 |
); |
| 466 |
$value = $args[0]; |
| 467 |
|
| 468 |
return is_array($value); |
| 469 |
} |
| 470 |
|
| 471 |
private function _rf_isString() { |
| 472 |
$args = $this->processRuleFunctionParams( |
| 473 |
'isString', |
| 474 |
func_num_args(), |
| 475 |
func_get_args(), |
| 476 |
1 |
| 477 |
); |
| 478 |
$value = $args[0]; |
| 479 |
|
| 480 |
return is_string($value); |
| 481 |
} |
| 482 |
|
| 483 |
private function _rf_isInt() { |
| 484 |
$args = $this->processRuleFunctionParams( |
| 485 |
'isInt', |
| 486 |
func_num_args(), |
| 487 |
func_get_args(), |
| 488 |
1 |
| 489 |
); |
| 490 |
$value = $args[0]; |
| 491 |
|
| 492 |
return is_int($value); |
| 493 |
} |
| 494 |
|
| 495 |
private function _rf_isBool() { |
| 496 |
$args = $this->processRuleFunctionParams( |
| 497 |
'isBool', |
| 498 |
func_num_args(), |
| 499 |
func_get_args(), |
| 500 |
1 |
| 501 |
); |
| 502 |
$value = $args[0]; |
| 503 |
|
| 504 |
return is_bool($value); |
| 505 |
} |
| 506 |
|
| 507 |
private function _rf_isFloat() { |
| 508 |
$args = $this->processRuleFunctionParams( |
| 509 |
'isFloat', |
| 510 |
func_num_args(), |
| 511 |
func_get_args(), |
| 512 |
1 |
| 513 |
); |
| 514 |
$value = $args[0]; |
| 515 |
|
| 516 |
return is_float($value); |
| 517 |
} |
| 518 |
|
| 519 |
private function _rf_isObject() { |
| 520 |
$args = $this->processRuleFunctionParams( |
| 521 |
'isObject', |
| 522 |
func_num_args(), |
| 523 |
func_get_args(), |
| 524 |
1 |
| 525 |
); |
| 526 |
$value = $args[0]; |
| 527 |
|
| 528 |
return is_object($value); |
| 529 |
} |
| 530 |
|
| 531 |
private function _rf_getType() { |
| 532 |
$args = $this->processRuleFunctionParams( |
| 533 |
'getType', |
| 534 |
func_num_args(), |
| 535 |
func_get_args(), |
| 536 |
1 |
| 537 |
); |
| 538 |
$value = $args[0]; |
| 539 |
|
| 540 |
return gettype($value); |
| 541 |
} |
| 542 |
} |
| 543 |
endif; |
| 544 |
|