Merge branch 'WebGUI8' into HEAD

This commit is contained in:
Graham Knop 2010-04-16 20:52:46 -05:00
commit 373be0881d
871 changed files with 36107 additions and 28933 deletions

View file

@ -298,8 +298,11 @@ A string representing the output format for the date. Defaults to '%z %Z'. You c
=cut
sub epochToHuman {
my $self = shift;
my $epoch = shift || time();
my $self = shift;
my $epoch = shift;
if (!defined $epoch || $epoch eq '') {
$epoch = time();
}
my $i18n = WebGUI::International->new($self->session);
my $language = $i18n->getLanguage($self->session->user->profileField('language'));
my $locale = $language->{languageAbbreviation} || 'en';
@ -950,7 +953,7 @@ sub setToEpoch {
}
unless ($dt) {
$self->session->errorHandler->warn("Could not format date $set for epoch. Returning current time");
return $self->time();
return time();
}
return $dt->epoch;
}
@ -959,7 +962,8 @@ sub setToEpoch {
=head2 time ( )
Returns an epoch date for now.
DEPRECATED - This method is deprecated, and should not be used in new code. Use
the perl built in function time().
=cut

View file

@ -188,6 +188,9 @@ sub requestNotViewed {
Returns true if a https request was made.
HTTP_SSLPROXY is set by mod_proxy in the WRE so that WebGUI knows that the original request
was made via SSL.
=cut
sub sslRequest {

View file

@ -16,6 +16,7 @@ package WebGUI::Session::ErrorHandler;
use strict;
use WebGUI::Paths;
use JSON;
use HTML::Entities qw(encode_entities);
use Log::Log4perl;
@ -338,7 +339,8 @@ sub new {
# Thanks to Plack, wG has been decoupled from Log4Perl
# However when called outside a web context, we currently still fall back to Log4perl
# (pending a better idea)
Log::Log4perl->init_once( $session->config->getWebguiRoot . "/etc/log.conf" );
require Log::Log4perl;
Log::Log4perl->init_once( WebGUI::Paths->logConfig );
my $log4perl = Log::Log4perl->get_logger( $session->config->getFilename );
$logger = sub {
my $args = shift;

View file

@ -203,19 +203,36 @@ sub getStreamedFile {
#-------------------------------------------------------------------
=head2 ifModifiedSince ( epoch )
=head2 ifModifiedSince ( epoch [, maxCacheTimeout] )
Returns 1 if the epoch is greater than the modified date check.
=head3 epoch
The date that the requested content was last modified in epoch format.
=head3 maxCacheTimeout
A modifier to the epoch, that allows us to set a maximum timeout where content will appear to
have changed and a new page request will be allowed to be processed.
=cut
sub ifModifiedSince {
my $self = shift;
my $epoch = shift;
my $self = shift;
my $epoch = shift;
my $maxCacheTimeout = shift;
require APR::Date;
my $modified = $self->session->request->header('If-Modified-Since');
return 1 if ($modified eq "");
$modified = APR::Date::parse_http($modified);
##Implement a step function that increments the epoch time in integer multiples of
##the maximum cache time. Used to handle the case where layouts containing macros
##(like assetproxied Navigations) can be periodically updated.
if ($maxCacheTimeout) {
my $delta = time() - $epoch;
$epoch += $delta - ($delta % $maxCacheTimeout);
}
return ($epoch > $modified);
}
@ -288,9 +305,14 @@ sub sendHeader {
# $response->no_cache(1); # TODO - re-enable this?
}
# in all other cases, set cache, but tell it to ask us every time so we don't mess with recently logged in users
else {
$response->header( 'Last-Modified' => $date);
$response->header( 'Cache-Control' => "must-revalidate, max-age=" . $cacheControl );
else {
if ( $cacheControl eq "none" ) {
$response->header("Cache-Control" => "private, max-age=1");
}
else {
$response->header('Last-Modified' => $date);
$response->header('Cache-Control' => "must-revalidate, max-age=" . $cacheControl);
}
# do an extra incantation if the HTTP protocol is really old
if ($request->protocol =~ /(\d\.\d)/ && $1 < 1.1) {
my $date = $datetime->epochToHttp(time() + $cacheControl);

View file

@ -167,7 +167,7 @@ sub delete {
my $pageURL = shift || $self->session->url->getRequestedUrl;
my $confirmText = shift;
if($confirmText) {
$confirmText = qq| onclick="return confirm('$confirmText')" |;
$confirmText = qq| onclick="return confirm('$confirmText');" |;
}
my $i18n = WebGUI::International->new($self->session,'Icon');
my $output = '<p class="toolbarIcon" style="display:inline;vertical-align:middle;"><a href="'.$self->session->url->gateway($pageURL,$urlParams).'" '.$confirmText.'>';

View file

@ -15,6 +15,7 @@ package WebGUI::Session::Scratch;
=cut
use strict;
use WebGUI::International;
=head1 NAME
@ -169,6 +170,19 @@ sub get {
return $self->{_data}{$var};
}
#-------------------------------------------------------------------
=head2 getLanguageOverride ()
Retrieves the language of the session scratch
=cut
sub getLanguageOverride {
my $self = shift;
my $languageOverride = $self->session->scratch->get('language');
return $languageOverride;
}
#-------------------------------------------------------------------
@ -191,7 +205,18 @@ sub new {
bless {_session=>$session, _data=>$scratch}, $class;
}
#-------------------------------------------------------------------
=head2 removeLanguageOverride()
Removes the language scratch variable from the session
=cut
sub removeLanguageOverride {
my $self = shift;
$self->session->scratch->delete('language');
}
#-------------------------------------------------------------------
=head2 session ( )
@ -232,5 +257,30 @@ sub set {
$session->db->write("replace into userSessionScratch (sessionId, name, value) values (?,?,?)", [$id, $name, $value]);
}
#----------------------------------------------------------------------
=head2 setLanguageOverride ( language )
Sets a scratch variable language in the session if the language is installed
=head3 language
The language that should be set into the session
=cut
sub setLanguageOverride {
my $self = shift;
my $language = shift;
my $i18n = WebGUI::International->new($self->session);
if($i18n->getLanguages()->{$language}) {
$self->session->scratch->set("language",$language);
return undef;
}
else {
$self->session->log->error("Language $language is not installed in this site");
return undef;
}
}
1;

View file

@ -64,10 +64,7 @@ The initial value of the setting.
sub add {
my $self = shift;
my $name = shift;
my $value = shift;
$self->{_settings}{$name} = $value;
$self->session->db->write("insert into settings (name,value) values (?,?)",[$name, $value]);
$self->set(@_);
}
#-------------------------------------------------------------------
@ -208,7 +205,7 @@ sub set {
my $name = shift;
my $value = shift;
$self->{_settings}{$name} = $value;
$self->session->db->write("update settings set value=? where name=?",[$value, $name]);
$self->session->db->write("REPLACE INTO settings (name, value) VALUES (?, ?)", [$name, $value]);
}

View file

@ -19,8 +19,8 @@ use strict;
use Tie::CPHash;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Asset::Template;
use WebGUI;
require WebGUI::Asset;
BEGIN { eval { require WebGUI; WebGUI->import } }
use HTML::Entities ();
=head1 NAME
@ -260,16 +260,34 @@ if ($self->session->user->isRegistered || $self->session->setting->get("preventP
$var{'head.tags'} .= '<meta http-equiv="Cache-Control" content="must-revalidate" />'
}
# TODO: Figure out if user is still in the admin console
if ( $session->asset ) {
my $assetDef = {
assetId => $session->asset->getId,
title => $session->asset->getTitle,
url => $session->asset->getUrl,
icon => $session->asset->getIcon(1),
};
$var{'head.tags'} .= sprintf <<'ADMINJS', JSON->new->encode( $assetDef );
<script type="text/javascript">
if ( window.parent && window.parent.admin ) {
window.parent.admin.navigate( %s );
}
</script>
ADMINJS
}
# Removing the newlines will probably annoy people.
# Perhaps turn it off under debug mode?
$var{'head.tags'} =~ s/\n//g;
#$var{'head.tags'} =~ s/\n//g;
# head.tags = head_attachments . body_attachments
# keeping head.tags for backwards compatibility
$var{'head_attachments'} = $var{'head.tags'};
$var{'head.tags'} .= ($var{'body_attachments'} = '<!--morebody-->');
my $style = eval { WebGUI::Asset::Template->newById($self->session, $templateId); };
my $style = eval { WebGUI::Asset->newById($self->session, $templateId); };
my $output;
if (! Exception::Class->caught()) {
my $meta = {};

View file

@ -193,7 +193,7 @@ sub gateway {
my $url = $self->make_urlmap_work($self->session->config->get("gateway")).'/'.$pageUrl;
$url =~ s/\/+/\//g;
if ($self->session->setting->get("preventProxyCache") == 1 and !$skipPreventProxyCache) {
$url = $self->append($url,"noCache=".randint(0,1000).':'.$self->session->datetime->time());
$url = $self->append($url,"noCache=".randint(0,1000).':'.time());
}
if ($pairs) {
$url = $self->append($url,$pairs);

View file

@ -186,12 +186,12 @@ sub new {
$self->session->{_sessionId} = $self->{_var}{sessionId};
return $self;
}
if ($self->{_var}{expires} && $self->{_var}{expires} < $session->datetime->time()) { ##Session expired, start a new one with the same Id
if ($self->{_var}{expires} && $self->{_var}{expires} < time()) { ##Session expired, start a new one with the same Id
$self->end;
$self->start(1,$sessionId);
}
elsif ($self->{_var}{sessionId} ne "") { ##Fetched an existing session. Update variables with recent data.
my $time = $session->datetime->time();
my $time = time();
my $timeout = $session->setting->get("sessionTimeout");
$self->{_var}{lastPageView} = $time;
$self->{_var}{lastIP} = $session->env->getIp;
@ -255,7 +255,7 @@ sub start {
my $id = $session->id;
$sessionId = $id->generate if ($sessionId eq "");
my $timeout = $session->setting->get('sessionTimeout');
my $time = $session->datetime->time();
my $time = time();
$self->{_var} = {
expires => $time + $timeout,
lastPageView => $time,