From 652bda05a4591dd01207b6b87455be04163010f5 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 25 Jan 2002 22:22:30 +0000 Subject: [PATCH] This adds the support to do section hosts --- Slash/Apache/Apache.pm | 64 ++++++++++++++++++++++-- Slash/Apache/Makefile.PL | 15 ++++++ Slash/Apache/User/User.pm | 5 +- Slash/Utility/Environment/Environment.pm | 7 ++- 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/Slash/Apache/Apache.pm b/Slash/Apache/Apache.pm index f852f97cb..930b4a6ab 100644 --- a/Slash/Apache/Apache.pm +++ b/Slash/Apache/Apache.pm @@ -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; @@ -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; @@ -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; } diff --git a/Slash/Apache/Makefile.PL b/Slash/Apache/Makefile.PL index d5303e936..4e991fec8 100644 --- a/Slash/Apache/Makefile.PL +++ b/Slash/Apache/Makefile.PL @@ -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' } ); diff --git a/Slash/Apache/User/User.pm b/Slash/Apache/User/User.pm index 1348ed70d..9e06440ed 100644 --- a/Slash/Apache/User/User.pm +++ b/Slash/Apache/User/User.pm @@ -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); @@ -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; diff --git a/Slash/Utility/Environment/Environment.pm b/Slash/Utility/Environment/Environment.pm index 7d6d5f9b3..57903c83e 100755 --- a/Slash/Utility/Environment/Environment.pm +++ b/Slash/Utility/Environment/Environment.pm @@ -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; }