ip_geoloc-2.0.0-alpha0/ip_geoloc_blocks.inc

ip_geoloc_blocks.inc
<?php

/**
 * @file
 * Blocks available in IP Geolocation Views & Maps.
 */

use Drupal\Component\Serialization\Json;

/**
 * Save map options to a Drupal variable.
 *
 * @param string $var_name
 *   The variable name to save.
 * @param string $map_options
 *   The map options to save.
 */
function ip_geoloc_save_map_options($var_name, $map_options) {

  // @TODO map option sends error
  $map_options_decoded = Json::decode($map_options);
  if ($map_options_decoded == NULL) {
    \Drupal::messenger()->addMessage("Sytax error in map options. These map options may not work: '%map_options'", 'warning');

    // @TODO fix translation
    // drupal_set_message(t("Sytax error in map options. These map options may not work: '%map_options'", array('%map_options' => $map_options)), 'warning');
  }
  $config = \Drupal::service('config.factory')->getEditable('ip_geoloc.settings');
  $config->set($var_name, $map_options);
}

/**
 * Get recent visitor locations.
 *
 * @param int $how_many
 *   How many locations to retrieve.
 *
 * @return object
 *   Object of locations found.
 */
function ip_geoloc_get_recent_visitor_locations($how_many) {
  // @TODO Review how to migrate this code
  /*$locations = array();

  $injected_database->schema()->tableExists('accesslog');
  if (db_table_exists('accesslog')) {
  A LEFT JOIN would also pick up new IP addresses that are about to be
  // inserted into the {accesslog}.
  // However a LEFT JOIN in this query can easily make it 100 times slower
  // than the INNER JOIN used below and would only be relevant for the very
  // first click from a new IP address or in the case where the IP address was
  // removed from the {accesslog}.
  $result = db_query_range('SELECT DISTINCT ip_address, latitude, longitude, formatted_address, COUNT(a.timestamp) AS visit_count, MAX(a.timestamp) AS last_visit FROM {ip_geoloc} i INNER JOIN {accesslog} a ON i.ip_address = a.hostname GROUP BY i.ip_address ORDER BY last_visit DESC', 0, $how_many);
  foreach ($result as $location) {
  // Prevent older IP address locations overwriting the latest location.
  if (!isset($locations[$location->ip_address])) {
  $loc_rendered = new stdClass();
  $loc_rendered->latitude = $location->latitude;
  $loc_rendered->longitude = $location->longitude;
  $loc_rendered->balloon_text = t('IP address') . ' ' . $location->ip_address . '<br/>'
  . $location->formatted_address . '<br/>'
  . t('#visits') . ' ' . (empty($location->visit_count) ? '?' : $location->visit_count)
  . ', ' . t('last visit') . ' ' . (empty($location->last_visit) ? '?' : format_date($location->last_visit, 'short'));
  $locations[$location->ip_address] = $loc_rendered;
  }
  }
  }*/

  $build = [
    '#type' => 'inline_template',
    '#template' => '<p>Removed until better statistics D8 port</p>',
    '#context' => [],
  ];

  $build = [];
  return $build;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc