dev/core#4127 move ipAddress to userSystem
authorHerb v/d Dool <herb@3speedhub.com>
Tue, 14 Feb 2023 19:43:13 +0000 (14:43 -0500)
committerHerb v/d Dool <herb@3speedhub.com>
Thu, 16 Feb 2023 04:39:05 +0000 (23:39 -0500)
CRM/Utils/System.php
CRM/Utils/System/Backdrop.php
CRM/Utils/System/Base.php
CRM/Utils/System/Drupal.php
CRM/Utils/System/Drupal8.php

index 10c0672734db23b13d19b315fa3342c773478a40..83652a6fb77d0bdc7cace30f6138f15b34e6e4a1 100644 (file)
@@ -1285,14 +1285,8 @@ class CRM_Utils_System {
    *   IP address of logged in user.
    */
   public static function ipAddress($strictIPV4 = TRUE) {
-    $address = $_SERVER['REMOTE_ADDR'] ?? NULL;
-
     $config = CRM_Core_Config::singleton();
-    if ($config->userSystem->is_drupal && function_exists('ip_address')) {
-      // drupal function handles the server being behind a proxy securely. We still have legacy ipn methods
-      // that reach this point without bootstrapping hence the check that the fn exists
-      $address = ip_address();
-    }
+    $address = $config->userSystem->ipAddress();
 
     // hack for safari
     if ($address == '::1') {
index 1742a479c99699c203486877fe11bea1c84bbe05..2b60e638e7270cdb9d099fcc2d36599143091ab7 100644 (file)
@@ -1186,4 +1186,14 @@ AND    u.status = 1
     }
   }
 
+  /**
+   * @inheritdoc
+   */
+  public function ipAddress():?string {
+    // Backdrop function handles the server being behind a proxy securely. We
+    // still have legacy ipn methods that reach this point without bootstrapping
+    // hence the check that the fn exists.
+    return function_exists('ip_address') ? ip_address() : ($_SERVER['REMOTE_ADDR'] ?? NULL);
+  }
+
 }
index 0b88f721b2a5f2819724ec2315ca8bc9d94d4542..3a69bc69e69a29452f21faea25e25cfb9cc06346 100644 (file)
@@ -1142,4 +1142,14 @@ abstract class CRM_Utils_System_Base {
     return FALSE;
   }
 
+  /**
+   * Get the client's IP address.
+   *
+   * @return string
+   *   IP address
+   */
+  public function ipAddress():?string {
+    return $_SERVER['REMOTE_ADDR'] ?? NULL;
+  }
+
 }
index 937187557762de6f6890cb9bcbfdd3e054909138..a645c8b722642f48e6faf7c8bd7dbbcb896b21fd 100644 (file)
@@ -921,4 +921,14 @@ AND    u.status = 1
     }
   }
 
+  /**
+   * @inheritdoc
+   */
+  public function ipAddress():?string {
+    // Drupal function handles the server being behind a proxy securely. We
+    // still have legacy ipn methods that reach this point without bootstrapping
+    // hence the check that the fn exists.
+    return function_exists('ip_address') ? ip_address() : ($_SERVER['REMOTE_ADDR'] ?? NULL);
+  }
+
 }
index d5a6034015975ab8cd3c8ad0970aa1c980e7d0ce..c4d06a5a2c1c259365af621ff2f26a2683c095f6 100644 (file)
@@ -925,4 +925,11 @@ class CRM_Utils_System_Drupal8 extends CRM_Utils_System_DrupalBase {
     return NULL;
   }
 
+  /**
+   * @inheritdoc
+   */
+  public function ipAddress():?string {
+    return class_exists('Drupal') ? \Drupal::request()->getClientIp() : ($_SERVER['REMOTE_ADDR'] ?? NULL);
+  }
+
 }