You are here

protected static function GoogleAnalyticsAdminSettingsForm::containsForbiddenToken in Google Analytics 8.2

Same name and namespace in other branches
  1. 8.3 src/Form/GoogleAnalyticsAdminSettingsForm.php \Drupal\google_analytics\Form\GoogleAnalyticsAdminSettingsForm::containsForbiddenToken()
  2. 4.x src/Form/GoogleAnalyticsAdminSettingsForm.php \Drupal\google_analytics\Form\GoogleAnalyticsAdminSettingsForm::containsForbiddenToken()

Validate if string contains forbidden tokens not allowed by privacy rules.

Parameters

string $token_string: A string with one or more tokens to be validated.

Return value

bool TRUE if blacklisted token has been found, otherwise FALSE.

File

src/Form/GoogleAnalyticsAdminSettingsForm.php, line 818

Class

GoogleAnalyticsAdminSettingsForm
Configure Google_Analytics settings for this site.

Namespace

Drupal\google_analytics\Form

Code

protected static function containsForbiddenToken($token_string) {

  // List of strings in tokens with personal identifying information not
  // allowed for privacy reasons. See section 8.1 of the Google Analytics
  // terms of use for more detailed information.
  //
  // This list can never ever be complete. For this reason it tries to use a
  // regex and may kill a few other valid tokens, but it's the only way to
  // protect users as much as possible from admins with illegal ideas.
  //
  // User tokens are not prefixed with colon to catch 'current-user' and
  // 'user'.
  //
  // TODO: If someone have better ideas, share them, please!
  $token_blacklist = [
    ':account-name]',
    ':author]',
    ':author:edit-url]',
    ':author:url]',
    ':author:path]',
    ':current-user]',
    ':current-user:original]',
    ':display-name]',
    ':fid]',
    ':mail]',
    ':name]',
    ':uid]',
    ':one-time-login-url]',
    ':owner]',
    ':owner:cancel-url]',
    ':owner:edit-url]',
    ':owner:url]',
    ':owner:path]',
    'user:cancel-url]',
    'user:edit-url]',
    'user:url]',
    'user:path]',
    'user:picture]',
    // addressfield_tokens.module.
    ':first-name]',
    ':last-name]',
    ':name-line]',
    ':mc-address]',
    ':thoroughfare]',
    ':premise]',
    // realname.module.
    ':name-raw]',
    // token.module.
    ':ip-address]',
  ];
  return preg_match('/' . implode('|', array_map('preg_quote', $token_blacklist)) . '/i', $token_string);
}