Skip to content

Commit

Permalink
This adds the support to do section hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianAker committed Jan 25, 2002
1 parent 449451e commit 652bda0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
64 changes: 61 additions & 3 deletions Slash/Apache/Apache.pm
Expand Up @@ -42,11 +42,13 @@ sub SlashVirtualUser ($$$) {
createCurrentStatic ($cfg->{constants} = $cfg->{slashdb}->getSlashConf($user));

# placeholders ... store extra placeholders in DB? :)
for (qw[user form themes template cookie objects cache]) {
for (qw[user form themes template cookie objects cache site_constants ]) {
$cfg->{$_} = '';
}

$cfg->{constants}{form_override} ||= {};
# This has to be a hash
$cfg->{site_constants} = {};

if ($overrides) {
@{$cfg->{constants}}{keys %$overrides} = values %$overrides;
Expand All @@ -72,14 +74,64 @@ sub SlashVirtualUser ($$$) {

sub SlashSetVar ($$$$) {
my($cfg, $params, $key, $value) = @_;
unless ($cfg->{constants}) {
print STDERR "SlashSetVar must be called after call SlashVirtualUser \n";
exit(1);
}
$cfg->{constants}{$key} = $value;
}

sub SlashSetForm ($$$$) {
my($cfg, $params, $key, $value) = @_;
unless ($cfg->{constants}) {
print STDERR "SlashSetForm must be called after call SlashVirtualUser \n";
exit(1);
}
$cfg->{constants}{form_override}{$key} = $value;
}

sub SlashSetVarHost ($$$$$) {
my($cfg, $params, $key, $value, $hostname) = @_;
unless ($cfg->{constants}) {
print STDERR "SlashSetVarHost must be called after call SlashVirtualUser \n";
exit(1);
}
my %$new_cfg = %{$cfg->{constants}};
$new_cfg->{$key} = $value;
$cfg->{site_constants}{$hostname} = $new_cfg;
}

sub SlashSetFormHost ($$$$$) {
my($cfg, $params, $key, $value, $hostname) = @_;
unless ($cfg->{constants}) {
print STDERR "SlashSetFormHost must be called after call SlashVirtualUser \n";
exit(1);
}
my %$new_cfg = %{$cfg->{constants}};
$new_cfg->{form_override}{$key} = $value;
$cfg->{site_constants}{$hostname} = $new_cfg;
}

sub SlashSectionHost ($$$$) {
my($cfg, $params, $section, $url) = @_;
my $hostname = $url;
$hostname =~ s/.*\/\///;
unless ($cfg->{constants}) {
print STDERR "SlashSectionHost must be called after call SlashVirtualUser \n";
exit(1);
}
my %$new_cfg = %{$cfg->{constants}};
# Must not just copy the form_override info
%$new_cfg->{form_override} = {};
%{$new_cfg->{form_override}}= %{$cfg->{constants}{form_override}};
$new_cfg->{absolutedir} = $url;
$new_cfg->{rootdir} = $url;
$new_cfg->{basedomain} = $hostname;
$new_cfg->{static_section} = $section;
$new_cfg->{form_override}{section} = $section;
$cfg->{site_constants}{$hostname} = $new_cfg;
}

sub SlashCompileTemplates ($$$) {
my($cfg, $params, $flag) = @_;
return unless $flag;
Expand Down Expand Up @@ -171,8 +223,14 @@ sub IndexHandler {
$r->filename("$basedir/index.pl");
return OK;
} else {
$r->uri('/index.shtml');
$r->filename("$basedir/index.shtml");
my $constants = getCurrentStatic();
if ($constants->{static_section}) {
$r->filename("$basedir/$constants->{static_section}/index.shtml");
$r->uri("/$constants->{static_section}/index.shtml");
} else {
$r->filename("$basedir/index.shtml");
$r->uri("/index.shtml");
}
writeLog('shtml');
return OK;
}
Expand Down
15 changes: 15 additions & 0 deletions Slash/Apache/Makefile.PL
Expand Up @@ -23,10 +23,25 @@ my @directives = (
args_how => 'TAKE2',
req_overrive => 'ACCESS_CONF'
},
{ name => 'SlashSetVarHost',
errmsg => 'Takes a key, a value, and a hostname that will override the var values in the DB for a specific hostname',
args_how => 'TAKE3',
req_overrive => 'ACCESS_CONF'
},
{ name => 'SlashSetFormHost',
errmsg => 'Takes a key, a value, and a hostname that will be applied to each form object for a specific hostname',
args_how => 'TAKE3',
req_overrive => 'ACCESS_CONF'
},
{ name => 'SlashCompileTemplates',
errmsg => 'Turn precompiling templates on or off',
args_how => 'FLAG',
req_overrive => 'ACCESS_CONF'
},
{ name => 'SlashSectionHost',
errmsg => 'Associate a host with a given section name',
args_how => 'TAKE2',
req_overrive => 'ACCESS_CONF'
}
);

Expand Down
5 changes: 3 additions & 2 deletions Slash/Apache/User/User.pm
Expand Up @@ -54,9 +54,11 @@ sub handler {

my $cfg = Apache::ModuleConfig->get($r);
my $dbcfg = Apache::ModuleConfig->get($r, 'Slash::Apache');
my $constants = $dbcfg->{constants};
my $constants = getCurrentStatic();
my $slashdb = $dbcfg->{slashdb};
my $apr = Apache::Request->new($r);

my $hostname = $r->header_in('host');

$r->err_header_out('X-Powered-By' => "Slash $Slash::VERSION");
random($r);
Expand Down Expand Up @@ -92,7 +94,6 @@ sub handler {
$params{query_apache} = $apr;
my $form = filter_params(%params);
$form->{query_apache} = $apr;

@{$form}{keys %{$constants->{form_override}}} =
values %{$constants->{form_override}};
my $cookies = Apache::Cookie->fetch;
Expand Down
7 changes: 6 additions & 1 deletion Slash/Utility/Environment/Environment.pm
Expand Up @@ -517,7 +517,12 @@ sub getCurrentStatic {

if ($ENV{GATEWAY_INTERFACE} && (my $r = Apache->request)) {
my $const_cfg = Apache::ModuleConfig->get($r, 'Slash::Apache');
$constants = $const_cfg->{'constants'};
my $hostname = $r->header_in('host');
if ($const_cfg->{'site_constants'}{$hostname}) {
$constants = $const_cfg->{site_constants}{$hostname};
} else {
$constants = $const_cfg->{'constants'};
}
} else {
$constants = $static_constants;
}
Expand Down

0 comments on commit 652bda0

Please sign in to comment.