You are here

function _gotwo_do_redir in Go - url redirects 7

Same name and namespace in other branches
  1. 6 gotwo.module \_gotwo_do_redir()

Redirect the user to the given location.

1 string reference to '_gotwo_do_redir'
gotwo_menu in ./gotwo.module
Implements hook_menu().

File

./gotwo.module, line 105
Module that provides easy to use redirection links. A redirection link would be like: http://examples.org/go/a_label http://examples.org/go/123546 http://examples.org/go/or/like/this

Code

function _gotwo_do_redir() {
  $args = func_get_args();
  $src = implode('/', $args);

  // $src may be an GID or a source URL.
  $result = db_query("SELECT * FROM {gotwo} WHERE src = :src OR gid = :gid", array(
    ':src' => $src,
    ':gid' => intval($src),
  ))
    ->fetchObject();
  if (!$result) {
    drupal_not_found();
  }
  else {

    // Count up the current click counter +1.
    db_update('gotwo')
      ->fields(array(
      'cnt' => NULL,
    ))
      ->expression('cnt', 'cnt + 1')
      ->condition('gid', $result->gid)
      ->execute();
    if (variable_get('gotwo_disclaimer_boolean', FALSE)) {

      // Display the Disclaimer
      $disclaimer_title = variable_get('gotwo_disclaimer_title', 'Disclaimer');
      $disclaimer_text = variable_get('gotwo_disclaimer_text', '');
      $disclaimer_time = variable_get('gotwo_disclaimer_time', 0);
      drupal_set_title($disclaimer_title);
      $tokens = array(
        '%url',
        '%seconds',
      );
      $token_values = array(
        check_url($result->dst),
        $disclaimer_time,
      );
      $page_content = filter_xss_admin(str_replace($tokens, $token_values, $disclaimer_text));

      // Should we refresh?
      if ($disclaimer_time > 0) {
        $disclaimer_meta = array(
          '#tag' => 'meta',
          '#attributes' => array(
            'http-equiv' => 'refresh',
            'content' => $disclaimer_time . ';url=' . check_url($result->dst),
          ),
        );
        drupal_add_html_head($disclaimer_meta, 'gotwo_disclaimer_refresh');
      }
      return $page_content;
    }
    else {

      // Parse the URL.
      $uri = drupal_parse_url($result->dst);
      drupal_goto($uri['path'], array(
        'query' => $uri['query'],
        'fragment' => $uri['fragment'],
      ));
    }
  }
}