You are here

function forward_tracker in Forward 7.3

Same name and namespace in other branches
  1. 5 forward.module \forward_tracker()
  2. 6 forward.module \forward_tracker()
  3. 7 forward.module \forward_tracker()
  4. 7.2 forward.module \forward_tracker()

Callback for clickthrough tracker

1 string reference to 'forward_tracker'
forward_menu in ./forward.module
Implements hook_menu().

File

./forward.module, line 92
Allows forwarding of entities by email, and provides a record of how often each has been forwarded.

Code

function forward_tracker() {
  global $user;
  global $language;

  // Prepare path
  $path = $_GET['path'];
  if (drupal_get_normal_path($path, $language->language) == variable_get('site_frontpage', 'node')) {
    $path = '<front>';
  }

  // Flood control - only allow a certain number of tracking events per minute per IP address
  if (flood_is_allowed('forward_tracker', variable_get('forward_flood_control_clicks', 3), 60)) {
    $id = _forward_entity_from_path($path, $entity_type, $entity, $bundle);
    if ($id) {
      db_update('forward_statistics')
        ->expression('clickthrough_count', 'clickthrough_count + 1')
        ->condition('type', $entity_type)
        ->condition('bundle', $bundle)
        ->condition('id', $id)
        ->execute();
    }

    // REF = clickthrough
    db_insert('forward_log')
      ->fields(array(
      'path' => $path,
      'type' => 'REF',
      'timestamp' => REQUEST_TIME,
      'uid' => $user->uid,
      'hostname' => ip_address(),
    ))
      ->execute();
  }

  // Regiser the click so flood control knows when the limit is reached
  flood_register_event('forward_tracker', 60);

  // Redirect to the link the user clicked on, or the site home page if the user clicked on an invalid path
  $path = $_GET['path'];
  if (!url_is_external($path)) {
    drupal_goto(drupal_get_path_alias($path, $language->language));
  }
  else {
    drupal_goto();
  }
}