You are here

private function Firewall::prioritize in Anti Spam by CleanTalk 8.4

Same name and namespace in other branches
  1. 9.1.x src/lib/Cleantalk/Common/Firewall/Firewall.php \Cleantalk\Common\Firewall\Firewall::prioritize()

Sets priorities for firewall results. It generates one main result from multi-level results array.

Parameters

array $results:

Return value

array Single element array of result

1 call to Firewall::prioritize()
Firewall::run in src/lib/Cleantalk/Common/Firewall/Firewall.php
Do main logic of the module.

File

src/lib/Cleantalk/Common/Firewall/Firewall.php, line 230

Class

Firewall

Namespace

Cleantalk\Common\Firewall

Code

private function prioritize($results) {
  $current_fw_result_priority = 0;
  $result = array(
    'status' => 'PASS',
    'passed_ip' => '',
  );
  if (is_array($results)) {
    foreach ($this->fw_modules as $module) {
      if (array_key_exists($module->module_name, $results)) {
        foreach ($results[$module->module_name] as $fw_result) {
          $priority = array_search($fw_result['status'], $this->statuses_priority) + (isset($fw_result['is_personal']) && $fw_result['is_personal'] ? count($this->statuses_priority) : 0);
          if ($priority >= $current_fw_result_priority) {
            $current_fw_result_priority = $priority;
            $result['status'] = $fw_result['status'];
            $result['passed_ip'] = isset($fw_result['ip']) ? $fw_result['ip'] : $fw_result['passed_ip'];
            $result['blocked_ip'] = isset($fw_result['ip']) ? $fw_result['ip'] : $fw_result['blocked_ip'];
            $result['pattern'] = isset($fw_result['pattern']) ? $fw_result['pattern'] : array();
          }
        }
      }
    }
  }
  $result['ip'] = strpos($result['status'], 'PASS') !== false ? $result['passed_ip'] : $result['blocked_ip'];
  $result['passed'] = strpos($result['status'], 'PASS') !== false;
  return $result;
}