Previous Thread
Next Thread
Print Thread
Hop To
Joined: Feb 2007
Posts: 57
journeyman
journeyman
Joined: Feb 2007
Posts: 57
After importing my UBB Classic forums into my new UBB Threads installation, and uploading and editing the redirector scripts to the old UBB Classic directory, it seems that old links to particular topics don't work any more. As many of our users have saved links to various topics, it would be really useful if the replacement ultimatebb.cgi script could route them to the new address. Is this possible?

Thanks in advance!

Shane


RnJpZW5kc2hpcCB3aXRoIHRoZSB3b3JsZCBpcyBob3N0aWxpdH
kgdG93YXJkcyBHb2QuICBKYW1lcyA0OjQ=
Joined: Jun 2006
Posts: 9,242
Likes: 1
R
Former Developer
Former Developer
R Offline
Joined: Jun 2006
Posts: 9,242
Likes: 1
Do they redirect at all? If it's redirecting you to showflat then your halfway there in that it's at least redirecting you to the right script.

Joined: Feb 2007
Posts: 57
journeyman
journeyman
Joined: Feb 2007
Posts: 57
Sorry I never responded. I had to make a bunch of changes to the ultimatebb.cgi script to get it to work. It seemed that it was written with CGI/perl functions that are not present in PHP (which is what I've always had installed), or something like that. (I don't know much CGI or PHP). Just recently, I found that only links with ampersands were working and not those with semicolons (or maybe vice versa). So I had to fix the script again. The script I'm now using is below. Maybe you can use the script so other people don't have the problems I was having.

Code
#!/usr/bin/perl
#
#	Copyright (C) 2005 Groupee, Inc.
#
#
# Most of this code stolen straight from the original ultimatebb.cgi
#	Thanks to Ian Spence

# Replacement ultimatebb.cgi script.  
# $URL needs to be set to your ubb.threads installation.  
$URL = "http://www.raisinggodlytomatoes.com/ubbthreads";

# site_id only needs to be changed if you've imported multiple forums.  The importer
# will tell you what your site id needs to be changed to
$site_id = 1;

# What type of redirect shall we send?
# 0 - Don't send a 301/302 header, my webserver does this. (Enable this if 301/302 results in an ISE or blank page)
# 301 - Permanent
# 302 - Temporary
$redirect = 301;

# Search engine friendly redirects? Change to 0 to disable
$search_friendly = 0;


# You shouldn't need to edit anything below this line
$var_start = "?";
$var_sep = "&";
$var_eq = "=";

if ($search_friendly == 1) {
	$var_start = "/";
	$var_sep = "/";
	$var_eq = "/";
}


# added by shane:
#  print("200 blah\n\n");
#  print("test \$ENV\{'QUERY_STRING'\}: $ENV{'QUERY_STRING'}\n");
#  print("ubb\=$in{'ubb'}\n");
#  print("f\=$in{'f'}\n");
# ------

# Get our arguments
%in = map{
	my @z = param($_);
	( scalar(@z) > 1 ?
		( $_ => join(",", @z) ) :
		( $_ => $z[0] )
		)
	} param();

# added by shane:
$ENV{'QUERY_STRING'} =~ s/&/\;/g;
# ------

# added by shane:
if (length ($ENV{'QUERY_STRING'}) > 0){
      $buffer = $ENV{'QUERY_STRING'};
      @pairs = split(';', $buffer);
      foreach $pair (@pairs){
           ($name, $value) = split(/=/, $pair);
           $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
           $in{$name} = $value; 
      }
 }
# --------



# See if we have any args in the path
my $pi = $ENV{PATH_INFO};
$pi = "" if($ENV{PATH_INFO} eq $ENV{SCRIPT_NAME});
if(!$pi && ($ENV{QUERY_STRING} =~ m/^\//)) {
	$pi = $ENV{QUERY_STRING};
} # end if

# added by shane:
#  print("test pi: $pi\n");
#  print("test in: $in\n");
#  print("test ubb: $in{'ubb'}\n");
#  print("test f: $in{'f'}\n");
#  print("test t: $in{'t'}\n");
#  print("test p: $in{'p'}\n");
#  exit(0);
# ----

if($pi ne "") {
	my @args = split(/\//, $pi);
	shift @args; # first arg is always blank
	$args[-1] =~ s/\.html$// if @args;
	if(($args[0] eq "ubb") && (scalar(@args) % 2 == 0)) {
		# proper pairing
		%in = (@args, %in);
	} elsif(($args[0] eq "ubb") && (scalar(@args) % 2 == 1)) {
		# Sigh, we're missing an argument...
		pop @args; # so yank it
		%in = (@args, %in);
	} elsif($args[0] eq "topic") {
		%in = (
			ubb => "get_topic",
			f => $args[1],
			t => &Do6Digit($args[2]),
			p => $args[3],
			%in,
		);
	} elsif($args[0] eq "forum") {
		%in = (
			ubb => "forum",
			f => $args[1],
			hardset => $args[2],
			start_point => $args[3],
			%in,
		);
	} elsif($args[0] eq "profile") {
		%in = (
			ubb => "get_profile",
			u => &Do8Digit($args[1]),
			%in,
		);

	} # end if
} # end if

# I actually have to look up how to do a foreach in perl.
# I've possibly been away from it too long

$query = "";
foreach my $key (keys %in) {
	$query .= qq~$key=$in{$key}&~;
}

# If ubb = get_topic we'll redirect to showflat
if ($in{'ubb'} eq "get_topic") {
	if ($redirect eq "301") {
		print(qq~Status: HTTP/1.1 301 Moved Permanently\n~ );
	} elsif ($redirect eq "302") {
		print(qq~Status: HTTP/1.1 302 Moved Temporarily\n~ );
	}
	if (!$in{'f'}) {$in{'f'} = 0; }
	if (!$in{'t'}) {$in{'t'} = 0; }
	if (!$in{'p'}) {$in{'p'} = 0; }
	if ($search_friendly) {
		print(qq~Location: $URL/ubbthreads.php/ubb/showflat/Forum/$in{'f'}/topic/$in{'t'}/Number/$in{'p'}/site_id/$site_id#import\n\n~);
	} else {
		print(qq~Location: $URL/ubbthreads.php?ubb=showflat&Forum=$in{'f'}&topic=$in{'t'}&Number=$in{'p'}&site_id=$site_id#import\n\n~);
	}		
	exit(0);
} else {
	if ($redirect eq "301") {
		print(qq~Status: HTTP/1.1 301 Moved Permanently\n~ );
	} elsif ($redirect eq "302") {
		print(qq~Status: HTTP/1.1 302 Moved Temporarily\n~ );
	}
	if ($search_friendly) {
		print(qq~Location: $URL/ubbthreads.php/ubb/cfrm\n\n~ );
	} else {
		print(qq~Location: $URL/ubbthreads.php?ubb=cfrm\n\n~ );
	}
	exit(0);
}


sub param {

    my($name,$value,@other);

    # For compatibility between old calling style and use_named_parameters() style,
    # we have to special case for a single parameter present.
    if (@p > 1) {
	($name,$value,@other) = $self->rearrange([NAME,[DEFAULT,VALUE,VALUES]],@p);
	my(@values);

	if (substr($p[0],0,1) eq '-' || $self->use_named_parameters) {
	    @values = defined($value) ? (ref($value) && ref($value) eq 'ARRAY' ? @{$value} : $value) : ();
	} else {
	    foreach ($value,@other) {
		push(@values,$_) if defined($_);
	    }
	}
	# If values is provided, then we set it.
	if (@values) {
	    $self->add_parameter($name);
	    $self->{$name}=[@values];
	}
    } else {
	$name = $p[0];
    }

    return unless defined($name) && $self->{$name};
    return wantarray ? @{$self->{$name}} : $self->{$name}->[0];
}

sub Do8Digit {
	return (sprintf("%.8d", $_[0]));
}

sub Do6Digit {
return (sprintf("%.6d", $_[0]));
}


RnJpZW5kc2hpcCB3aXRoIHRoZSB3b3JsZCBpcyBob3N0aWxpdH
kgdG93YXJkcyBHb2QuICBKYW1lcyA0OjQ=
Joined: Feb 2007
Posts: 57
journeyman
journeyman
Joined: Feb 2007
Posts: 57
P.S. I think I commented my code additions with "added by shane" so you can see them. There's only like 3 or 4 spots in the top section of the code. I did most of it a long time ago, though, so I don't really remember what the problem was or what my fix does.


RnJpZW5kc2hpcCB3aXRoIHRoZSB3b3JsZCBpcyBob3N0aWxpdH
kgdG93YXJkcyBHb2QuICBKYW1lcyA0OjQ=

Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
spam issues
by ECNet - 03/19/2024 11:45 PM
Who's Online Now
1 members (Nightcrawler), 963 guests, and 210 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20230217)