Same name and namespace in other branches
  1. 7.x-1.x spambot.module \spambot_account_ip_addresses() 1 comment

Retrieves a list of IP addresses for an account.

Parameters

object $account: Account to retrieve IP addresses for.

Return value

array An array of IP addresses, or an empty array if none found

2 calls to spambot_account_ip_addresses()
SpambotUserspamForm::checkSubmit in src/Form/SpambotUserspamForm.php
Function provide functional for "Check" button.
spambot_account_is_spammer in ./spambot.module
Checks an account to see if it's a spammer.

File

./spambot.module, line 229

Code

function spambot_account_ip_addresses($account) {
    $hostnames = [];
    // Retrieve IPs from any sessions which may still exist in the CMS.
    $items = \Drupal::database()->select('sessions')
        ->distinct()
        ->fields('sessions', [
        'hostname',
    ])
        ->condition('uid', $account->id(), '=')
        ->execute()
        ->fetchCol();
    $hostnames = array_merge($hostnames, $items);
    // Retrieve IPs from comments.
    $module_handler = \Drupal::moduleHandler();
    if ($module_handler->moduleExists('comment')) {
        $comment_cid = \Drupal::database()->select('comment_entity_statistics')
            ->distinct()
            ->fields('comment_entity_statistics', [
            'cid',
        ])
            ->condition('last_comment_uid', $account->id(), '=')
            ->execute()
            ->fetchCol();
        if ($comment_cid) {
            $items = \Drupal::database()->select('comment_field_data')
                ->distinct()
                ->fields('comment_field_data', [
                'hostname',
            ])
                ->condition('cid', $comment_cid, 'IN')
                ->execute()
                ->fetchCol();
        }
        else {
            $items = [];
        }
        $hostnames = array_merge($hostnames, $items);
    }
    $hostnames = array_unique($hostnames);
    return $hostnames;
}