You are here

function __gotwo_do_redir in Go - url redirects 5

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 118
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(db_rewrite_sql("UPDATE {gotwo} SET cnt = cnt+1 WHERE gid = %d"), $res->gid);

    //echo 'updated db '.$res->gid;exit;
    if (variable_get('gotwo_disclaimer_boolean', FALSE)) {

      // Display the Disclaimer.
      $disclaimer_text = variable_get('gotwo_disclaimer_text', '');
      $find_array = array(
        '%url',
        '%seconds',
      );
      $replace_array = array(
        check_url($res->dst),
        variable_get('gotwo_disclaimer_time', 0),
      );
      $page_content = filter_xss_admin(str_replace($find_array, $replace_array, $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);
    }
  }
}