You are here

function _gotwo_do_redir in Go - url redirects 6

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

Redirect the user to the given location

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

File

./gotwo.module, line 119
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 Go ID or a source attribute
  $res = db_fetch_object(db_query("SELECT * FROM {gotwo} WHERE src = '%s' OR gid = %d", $src, intval($src)));
  if (!$res) {
    drupal_not_found();
  }
  else {
    db_query("UPDATE {gotwo} SET cnt = cnt+1 WHERE gid = %d", $res->gid);
    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(check_plain($disclaimer_title));
      $tokens = array(
        '%url',
        '%seconds',
      );
      $token_values = array(
        check_url($res->dst),
        $disclaimer_time,
      );
      $page_content = filter_xss_admin(str_replace($tokens, $token_values, $disclaimer_text));

      // Should we refresh?
      if (variable_get('gotwo_disclaimer_time', 0) > 0) {
        drupal_set_html_head('<meta http-equiv="refresh" content="' . variable_get('gotwo_disclaimer_time', 0) . ';url=' . check_url($res->dst) . '"/>');
      }
      return $page_content;
    }
    else {

      // Parse the URL.
      $uri = parse_url($res->dst);
      $scheme = isset($uri['scheme']) ? $uri['scheme'] . '://' : '';
      $user = isset($uri['user']) ? $uri['user'] . ($uri['pass'] ? ':' . $uri['pass'] : '') . '@' : '';
      $port = isset($uri['port']) ? $uri['port'] : 80;
      $host = $uri['host'] . ($port != 80 ? ':' . $port : '');
      $path = isset($uri['path']) ? $uri['path'] : '/';

      // Glue the URL variables.
      $dst_url = $scheme . $user . $host . $path;
      $dst_query = isset($uri['query']) ? $uri['query'] : NULL;
      $dst_fragment = isset($uri['fragment']) ? $uri['fragment'] : NULL;
      drupal_goto($dst_url, $dst_query, $dst_fragment);
    }
  }
}