rfe: choice of type of redirect on redirect assets

This commit is contained in:
JT Smith 2008-09-16 17:51:15 +00:00
parent fc7fbfbd0c
commit 6e04c4b705
5 changed files with 85 additions and 30 deletions

View file

@ -3,6 +3,7 @@
- rfe: Town Hall: Menu title in search results
- rfe: Process Macros in HTTP Proxy's URL
- rfe: TimeZone for the User Profiles displays incorrectly after installation
- rfe: choice of type of redirect on redirect assets
- rewrite macro parser, improving speed and making parameter parsing more sane
- Made the charset metatag the highest thing in the head block.
- fixed: AssetProxy allows proxying content in the trash or clipboard

View file

@ -33,6 +33,7 @@ removeDoNothingOnDelete( $session );
fixIsPublicOnTemplates ( $session );
addSortOrderToFolder( $session );
addEMSBadgeTemplate ( $session );
redirectChoice ($session);
finish($session); # this line required
@ -89,13 +90,12 @@ sub removeDoNothingOnDelete {
}
#----------------------------------------------------------------------------
# Describe what our function does
#sub exampleFunction {
# my $session = shift;
# print "\tWe're doing some stuff here that you should know about... " unless $quiet;
# # and here's our code
# print "DONE!\n" unless $quiet;
#}
sub redirectChoice {
my $session = shift;
print "\tGiving a user choice about which type of redirect they'd like to perform... " unless $quiet;
$session->db->write("alter table redirect add column redirectType int not null default 302");
print "DONE!\n" unless $quiet;
}
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------

View file

@ -67,27 +67,29 @@ sub definition {
tableName=>'redirect',
className=>'WebGUI::Asset::Redirect',
properties=>{
redirectUrl=>{
tab=>"properties",
label=>$i18n->get('redirect url'),
hoverHelp=>$i18n->get('redirect url description'),
fieldType=>'url',
defaultValue=>undef
}
}
});
redirectUrl=>{
tab => "properties",
label => $i18n->get('redirect url'),
hoverHelp => $i18n->get('redirect url description'),
fieldType => 'url',
defaultValue => undef
},
redirectType=>{
tab => "properties",
label => $i18n->get('Redirect Type'),
hoverHelp => $i18n->get('redirect type description'),
fieldType => 'selectBox',
defaultValue => 302,
options => {
302 => $i18n->get('302 Moved Temporarily'),
301 => $i18n->get('301 Moved Permanently'),
}
},
},
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked;
return $self->getAdminConsole->render($self->getEditForm->print, $self->addEditLabel);
}
#-------------------------------------------------------------------
=head2 exportHtml_view
@ -108,6 +110,32 @@ sub exportHtml_view {
#-------------------------------------------------------------------
=head2 view ( )
Display the redirect url when in admin mode.
=cut
sub view {
my $self = shift;
if ($self->session->var->get("adminOn")) {
return $self->getToolbar.' '.$self->getTitle.' '.$self->get('redirectUrl');
}
else {
return "";
}
}
#-------------------------------------------------------------------
sub www_edit {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
return $self->session->privilege->locked() unless $self->canEditIfLocked;
return $self->getAdminConsole->render($self->getEditForm->print, $self->addEditLabel);
}
#-------------------------------------------------------------------
=head2 www_view
A web executable method that redirects the user to the specified page, or displays the edit interface when admin mode is enabled.
@ -129,7 +157,7 @@ sub www_view {
</ul>',$i18n->get("assetName"));
}
unless ($url eq $self->get("url")) {
$self->session->http->setRedirect($url);
$self->session->http->setRedirect($url,$self->get('redirectType'));
return undef;
}
return $i18n->get('self_referential');

View file

@ -16,6 +16,7 @@ package WebGUI::Session::Http;
use strict;
use WebGUI::Utility;
=head1 NAME
@ -231,7 +232,7 @@ Returns a boolean value indicating whether the current page will redirect to som
sub isRedirect {
my $self = shift;
return ($self->getStatus() eq "302");
return isIn($self->getStatus(), qw(302 301));
}
@ -279,7 +280,7 @@ sub sendHeader {
my %params;
if ($self->isRedirect()) {
$request->headers_out->set(Location => $self->getRedirectLocation);
$request->status(301);
$request->status($self->getStatus);
} else {
$request->content_type($self->getMimeType);
my $cacheControl = $self->getCacheControl;
@ -494,7 +495,7 @@ sub setNoHeader {
#-------------------------------------------------------------------
=head2 setRedirect ( url )
=head2 setRedirect ( url, [ type ] )
Sets the necessary information in the HTTP header to redirect to another URL.
@ -502,16 +503,21 @@ Sets the necessary information in the HTTP header to redirect to another URL.
The URL to redirect to.
=head3 type
Defaults to 302 (temporary redirect), but you can optionally set 301 (permanent redirect).
=cut
sub setRedirect {
my $self = shift;
my $url = shift;
my $type = shift || 302;
my @params = $self->session->form->param;
return undef if ($url eq $self->session->url->page() && scalar(@params) < 1); # prevent redirecting to self
$self->session->errorHandler->info("Redirecting to $url");
$self->setRedirectLocation($url);
$self->setStatus("302", "Redirect");
$self->setStatus($type, "Redirect");
$self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$url});
}

View file

@ -8,6 +8,26 @@ our $I18N = {
lastUpdated => 0,
},
'302 Moved Temporarily' => {
message => q|302 Moved Temporarily|,
lastUpdated => 0,
},
'301 Moved Permanently' => {
message => q|301 Moved Permanently|,
lastUpdated => 0,
},
'Redirect Type' => {
message => q|Redirect Type|,
lastUpdated => 0,
},
'redirect type description' => {
message => q|The type of HTTP header that the Redirect asset will send.|,
lastUpdated => 0,
},
'go to the redirect url' => {
message => q|Go to the redirect URL.|,
lastUpdated => 0,