rewrote the template api and added lots of caching options
This commit is contained in:
parent
6613992f3d
commit
20482def49
24 changed files with 252 additions and 100 deletions
|
|
@ -10,7 +10,15 @@
|
|||
- Fixed a bug in articles where articles with no content would fail to
|
||||
display their images.
|
||||
- bugfix [966466] WebGUI::Session. System crash when user language setting missing.
|
||||
- Eliminated the need for Data::Serializer.
|
||||
- Eliminated the need for Data::Serializer which results in a small amount of
|
||||
less memory usage.
|
||||
- Rewrote the template API which resulted in a 30% performance increase. See
|
||||
docs/migration.txt for details.
|
||||
- Added five new caching mechanisms for templates. Each has their own
|
||||
benefits and detriments. This allows you to increase scalability and
|
||||
performance at a cost of either memory or disk space or both. The gains
|
||||
here are primarily enjoyed by large heavy traffic sites that use lots of
|
||||
templates.
|
||||
|
||||
|
||||
6.0.3
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ save you many hours of grief.
|
|||
|
||||
* You no longer need Data::Serializer.
|
||||
|
||||
* See docs/migration.txt for changes in the template system.
|
||||
|
||||
|
||||
6.0.2
|
||||
--------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -113,11 +113,16 @@ to load the plug-in at use time.
|
|||
|
||||
5.5 Privilege API Change
|
||||
|
||||
In 6.1 we move isInGroup from WebGUI::Privilege to WebGUI::Grouping, where it
|
||||
In 6.1 we moved isInGroup from WebGUI::Privilege to WebGUI::Grouping, where it
|
||||
belongs. We also moved canViewPage and canEditPage to WebGUI::Page and renamed them
|
||||
to canView and canEdit. And finally, we moved canEditWobject and
|
||||
canViewWobject to WebGUI::Wobject and renamed them canView and canEdit and
|
||||
converted them from regular functions into methods.
|
||||
|
||||
5.6 Template API Change
|
||||
|
||||
In 6.1 we completely rewrote the underlying template framework to add template
|
||||
caching. Any plug-ins that use WebGUI::Template, must be updated to reflect
|
||||
the new API.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ uploadsPath = /data/WebGUI/www/uploads
|
|||
|
||||
useSharedInternationalCache = 1
|
||||
|
||||
templateCacheType=file
|
||||
|
||||
emailRecoveryLoggingEnabled = 1
|
||||
passwordChangeLoggingEnabled = 1
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ Package to manipulate WebGUI Attachments.
|
|||
|
||||
$filename = $attachment->save("formImage");
|
||||
$filename = $attachment->saveFromFilesystem($pathToFile);
|
||||
$filename = $attachment->saveFromScalar($content);
|
||||
|
||||
$filename = $attachment->saveFromHashref($hashRef);
|
||||
$hashRef = $attachment->getHashref;
|
||||
|
|
@ -681,6 +682,32 @@ sub saveFromHashref {
|
|||
return $self->getFilename;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 saveFromScalar ( scalar )
|
||||
|
||||
Stores a scalar as a text attachment.
|
||||
|
||||
=over
|
||||
|
||||
=item scalar
|
||||
|
||||
A scalar variable containing the content to write to the filesystem.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub saveFromScalar {
|
||||
my ($self, $content) = @_;
|
||||
$self->getNode->create();
|
||||
open(FILE,">".$self->getPath);
|
||||
print FILE $content;
|
||||
close(FILE);
|
||||
return $self->getFilename;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -218,7 +218,7 @@ sub createAccount {
|
|||
$vars->{'login.url'} = WebGUI::URL::page('op=auth&method=init');
|
||||
$vars->{'login.label'} = WebGUI::International::get(58);
|
||||
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars);
|
||||
return WebGUI::Template::process(1,$template, $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -306,7 +306,7 @@ sub deactivateAccount {
|
|||
$var{'yes.label'} = WebGUI::International::get(44);
|
||||
$var{'no.url'} = WebGUI::URL::page();
|
||||
$var{'no.label'} = WebGUI::International::get(45);
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,"prompt"), \%var);
|
||||
return WebGUI::Template::process(1,"prompt", \%var);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -379,7 +379,7 @@ sub displayAccount {
|
|||
$vars->{'account.form.footer'} = "</form>";
|
||||
|
||||
$vars->{'account.options'} = WebGUI::Operation::Shared::accountOptions();
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars);
|
||||
return WebGUI::Template::process(1,$template, $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -430,7 +430,7 @@ sub displayLogin {
|
|||
$vars->{'anonymousRegistration.isAllowed'} = ($session{setting}{anonymousRegistration});
|
||||
$vars->{'createAccount.url'} = WebGUI::URL::page('op=createAccount');
|
||||
$vars->{'createAccount.label'} = WebGUI::International::get(67);
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars);
|
||||
return WebGUI::Template::process(1,$template, $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ sub displayAccount {
|
|||
$vars->{'account.form.karma.label'} = WebGUI::International::get(537);
|
||||
}
|
||||
$vars->{'account.options'} = WebGUI::Operation::Shared::accountOptions();
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Auth/LDAP/Account'), $vars);
|
||||
return WebGUI::Template::process(1,'Auth/LDAP/Account', $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ sub displayAccount {
|
|||
$vars->{'account.form.karma.label'} = WebGUI::International::get(537);
|
||||
}
|
||||
$vars->{'account.options'} = WebGUI::Operation::Shared::accountOptions();
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Auth/SMB/Account'), $vars);
|
||||
return WebGUI::Template::process(1,'Auth/SMB/Account', $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ sub recoverPassword {
|
|||
$vars->{'recover.message'} = $_[0] if ($_[0]);
|
||||
$vars->{'recover.form.email'} = WebGUI::Form::text({"name"=>"email"});
|
||||
$vars->{'recover.form.email.label'} = WebGUI::International::get(56);
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,$template), $vars);
|
||||
return WebGUI::Template::process(1,$template, $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -459,7 +459,7 @@ sub resetExpiredPassword {
|
|||
$vars->{'expired.form.submit'} = WebGUI::Form::submit({});
|
||||
$vars->{'expired.form.footer'} = "</form>";
|
||||
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Auth/WebGUI/Expired'), $vars);
|
||||
return WebGUI::Template::process(1,'Auth/WebGUI/Expired', $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -991,7 +991,7 @@ sub HTMLArea {
|
|||
if ($session{user}{richEditor} eq 'none') {
|
||||
return $var{textarea};
|
||||
} else {
|
||||
return WebGUI::Template::process(WebGUI::Template::get($session{user}{richEditor},'richEditor'),\%var);
|
||||
return WebGUI::Template::process($session{user}{richEditor},'richEditor',\%var);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1249,7 +1249,7 @@ sub getPostTemplateVars {
|
|||
$var->{'post.deny.url'} = formatDenyPostURL($callback,$post->get("forumPostId"));
|
||||
$var->{'forum.title'} = $callback->{title};
|
||||
$var->{'forum.description'} = $callback->{description};
|
||||
$var->{'post.full'} = WebGUI::Template::process(WebGUI::Template::get($forum->get("postTemplateId"),"Forum/Post"), $var);
|
||||
$var->{'post.full'} = WebGUI::Template::process($forum->get("postTemplateId"),"Forum/Post", $var);
|
||||
return $var;
|
||||
}
|
||||
|
||||
|
|
@ -1382,7 +1382,7 @@ sub notifySubscribers {
|
|||
$lang{$u->profileField("language")}{var} = getPostTemplateVars($post, $thread, $forum, $caller, $lang{$u->profileField("language")}{var});
|
||||
$lang{$u->profileField("language")}{subject} = WebGUI::International::get(523,"WebGUI",$u->profileField("language"));
|
||||
$lang{$u->profileField("language")}{message} = WebGUI::Template::process(
|
||||
WebGUI::Template::get($forum->get("notificationTemplateId"),"Forum/Notification"),
|
||||
$forum->get("notificationTemplateId"),"Forum/Notification",
|
||||
$lang{$u->profileField("language")}{var}
|
||||
);
|
||||
}
|
||||
|
|
@ -1886,7 +1886,7 @@ sub www_post {
|
|||
value=>$subject
|
||||
});
|
||||
$var->{'form.end'} = '</form>';
|
||||
return WebGUI::Template::process(WebGUI::Template::get($forum->get("postformTemplateId"),"Forum/PostForm"), $var);
|
||||
return WebGUI::Template::process($forum->get("postformTemplateId"),"Forum/PostForm", $var);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -2119,7 +2119,7 @@ sub www_search {
|
|||
$var{numberOfPages} = $p->getNumberOfPages;
|
||||
$var{pageNumber} = $p->getPageNumber;
|
||||
}
|
||||
return WebGUI::Template::process(WebGUI::Template::get($forum->get("searchTemplateId"),"Forum/Search"), \%var);
|
||||
return WebGUI::Template::process($forum->get("searchTemplateId"),"Forum/Search", \%var);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -2293,7 +2293,7 @@ sub www_viewForum {
|
|||
my $forum = WebGUI::Forum->new($forumId);
|
||||
return WebGUI::Privilege::insufficient() unless ($forum->canView);
|
||||
my $var = getForumTemplateVars($caller, $forum);
|
||||
return WebGUI::Template::process(WebGUI::Template::get($forum->get("forumTemplateId"),"Forum"), $var);
|
||||
return WebGUI::Template::process($forum->get("forumTemplateId"),"Forum", $var);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -2332,7 +2332,7 @@ sub www_viewThread {
|
|||
if ($post->get("forumPostId") == $post->getThread->get("rootPostId") && !$post->canView) {
|
||||
return www_viewForum($caller, $post->getThread->getForum->get("forumId"));
|
||||
} else {
|
||||
return WebGUI::Template::process(WebGUI::Template::get($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread"), $var);
|
||||
return WebGUI::Template::process($post->getThread->getForum->get("threadTemplateId"),"Forum/Thread", $var);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ sub process {
|
|||
$i++;
|
||||
}
|
||||
$var{'admin_loop'} = \@admin;
|
||||
return WebGUI::Template::process(WebGUI::Template::get($templateId,"Macro/AdminBar"),\%var);
|
||||
return WebGUI::Template::process($templateId,"Macro/AdminBar",\%var);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ sub process {
|
|||
$var{'account.create.url'} = WebGUI::URL::page('op=createAccount');
|
||||
$var{'account.create.label'} = WebGUI::International::get(407);
|
||||
$var{'form.footer'} = '</form>';
|
||||
return WebGUI::Template::process(WebGUI::Template::get($templateId,"Macro/L_loginBox"),\%var);
|
||||
return WebGUI::Template::process($templateId,"Macro/L_loginBox",\%var);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -337,8 +337,11 @@ sub build {
|
|||
|
||||
# Configure button
|
||||
$var->{'config.button'} = $self->_getEditButton();
|
||||
|
||||
return WebGUI::Template::process($self->{_template} || WebGUI::Template::get($self->{_templateId}, "Navigation"), $var);
|
||||
if ($self->{_template}) {
|
||||
return WebGUI::Template::processRaw($self->{_template}, $var);
|
||||
} else {
|
||||
return WebGUI::Template::process($self->{_templateId}, "Navigation", $var);
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ sub www_viewMessageLog {
|
|||
$vars->{'message.multiplePages'} = ($p->getNumberOfPages > 1);
|
||||
$vars->{'message.accountOptions'} = WebGUI::Operation::Shared::accountOptions();
|
||||
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/MessageLog/View'), $vars);
|
||||
return WebGUI::Template::process(1,'Operation/MessageLog/View', $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -95,7 +95,7 @@ sub www_viewMessageLogMessage {
|
|||
|
||||
$vars->{'message.text'} = $data->{message};
|
||||
$vars->{'message.accountOptions'} = WebGUI::Operation::Shared::accountOptions();
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/MessageLog/Message'), $vars);
|
||||
return WebGUI::Template::process(1,'Operation/MessageLog/Message', $vars);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ sub www_editProfile {
|
|||
$vars->{'profile.form.elements'} = \@array;
|
||||
$vars->{'profile.form.submit'} = WebGUI::Form::submit({});
|
||||
$vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions();
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/Profile/Edit'), $vars);
|
||||
return WebGUI::Template::process(1,'Operation/Profile/Edit', $vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -257,7 +257,7 @@ sub www_viewProfile {
|
|||
if ($session{user}{userId} == $session{form}{uid}) {
|
||||
$vars->{'profile.accountOptions'} = WebGUI::Operation::Shared::accountOptions();
|
||||
}
|
||||
return WebGUI::Template::process(WebGUI::Template::get(1,'Operation/Profile/View'), $vars);
|
||||
return WebGUI::Template::process(1,'Operation/Profile/View', $vars);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -53,13 +53,11 @@ sub _submenu {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_copyTemplate {
|
||||
my (%template);
|
||||
if (WebGUI::Grouping::isInGroup(8)) {
|
||||
%template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid} and namespace=".quote($session{form}{namespace}));
|
||||
WebGUI::SQL->write("insert into template (templateId,name,template,namespace)
|
||||
values ("._getNextTemplateId($session{form}{namespace}).",
|
||||
".quote('Copy of '.$template{name}).", ".quote($template{template}).",
|
||||
".quote($template{namespace}).")");
|
||||
my $template = WebGUI::Template::get($session{form}{tid},$session{form}{namespace});
|
||||
$template->{name} .= " (copy)";
|
||||
$template->{templateId} = "new";
|
||||
WebGUI::Template::set($template);
|
||||
return www_listTemplates();
|
||||
} else {
|
||||
return WebGUI::Privilege::adminOnly();
|
||||
|
|
@ -157,17 +155,15 @@ sub www_editTemplate {
|
|||
#-------------------------------------------------------------------
|
||||
sub www_editTemplateSave {
|
||||
if (WebGUI::Grouping::isInGroup(8)) {
|
||||
if ($session{form}{tid} eq "new") {
|
||||
$session{form}{tid} = _getNextTemplateId($session{form}{namespace});
|
||||
WebGUI::SQL->write("insert into template (templateId,namespace) values
|
||||
($session{form}{tid}, ".quote($session{form}{namespace}).")");
|
||||
}
|
||||
if ($session{form}{template} eq "" && $session{form}{namespace} eq "Page") {
|
||||
$session{form}{template} = "<table>\n<tr>\n<td>\n\n<tmpl_var page.position1>\n\n</td>\n </tr>\n</table>\n";
|
||||
}
|
||||
WebGUI::SQL->write("update template set name=".quote($session{form}{name}).",
|
||||
template=".quote($session{form}{template})."
|
||||
where templateId=".$session{form}{tid}." and namespace=".quote($session{form}{namespace}));
|
||||
$session{form}{tid} = WebGUI::Template::set({
|
||||
templateId=>$session{form}{tid},
|
||||
namespace=>$session{form}{namespace},
|
||||
name=>$session{form}{name},
|
||||
template=>$session{form}{template}
|
||||
});
|
||||
if ($session{form}{action2} eq "") {
|
||||
return www_listTemplates();
|
||||
} else {
|
||||
|
|
@ -209,20 +205,5 @@ sub www_listTemplates {
|
|||
}
|
||||
}
|
||||
|
||||
sub _getNextTemplateId {
|
||||
my $namespace = shift;
|
||||
my $templateId;
|
||||
my $query = "select max(templateId) from template";
|
||||
if ($namespace) {
|
||||
$query .= " where namespace = ".quote($namespace);
|
||||
}
|
||||
($templateId) = WebGUI::SQL->quickArray($query);
|
||||
if ($templateId > 999) {
|
||||
$templateId++;
|
||||
} else {
|
||||
$templateId = 1000;
|
||||
}
|
||||
return $templateId;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -451,7 +451,7 @@ sub generate {
|
|||
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace}. Root cause: ".$@) if($@);
|
||||
}
|
||||
$sth->finish;
|
||||
return WebGUI::Template::process(getTemplate(),\%var);
|
||||
return WebGUI::Template::process($session{page}{templateId},"Page",\%var);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ The unique identifier for the template to retrieve. Defaults to the style templa
|
|||
sub process {
|
||||
my %var;
|
||||
$var{'body.content'} = shift;
|
||||
my $templateId = shift;
|
||||
my $templateId = shift || $session{page}{styleId};
|
||||
if ($session{page}{makePrintable}) {
|
||||
$templateId = $session{page}{printableStyleId};
|
||||
} elsif ($session{page}{useAdminStyle} ne "" && $session{setting}{useAdminStyle}) {
|
||||
|
|
@ -158,7 +158,7 @@ sub process {
|
|||
';
|
||||
}
|
||||
}
|
||||
return WebGUI::Template::process(getTemplate($templateId),\%var);
|
||||
return WebGUI::Template::process($templateId,"style",\%var);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package WebGUI::Template;
|
|||
|
||||
use HTML::Template;
|
||||
use strict;
|
||||
use WebGUI::Attachment;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
|
@ -35,9 +36,10 @@ This package contains utility methods for WebGUI's template system.
|
|||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Template;
|
||||
$template = WebGUI::Template::get($templateId, $namespace);
|
||||
$hashRef = WebGUI::Template::get($templateId, $namespace);
|
||||
$hashRef = WebGUI::Template::getList($namespace);
|
||||
$html = WebGUI::Template::process($template);
|
||||
$html = WebGUI::Template::process($templateId, $namespace, $vars);
|
||||
$templateId = WebGUI::Template::set(\%data);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
|
@ -47,10 +49,47 @@ These subroutines are available from this package:
|
|||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _getTemplateFile {
|
||||
my $templateId = shift;
|
||||
my $namespace = shift;
|
||||
my $filename = $namespace."-".$templateId.".tmpl";
|
||||
$filename =~ s/\//-/g;
|
||||
$filename =~ s/ /-/g;
|
||||
return WebGUI::Attachment->new($filename,"temp","templates");
|
||||
}
|
||||
|
||||
=head2 get ( [ templateId, namespace ] )
|
||||
|
||||
Returns a template.
|
||||
#-------------------------------------------------------------------
|
||||
sub _execute {
|
||||
my $params = shift;
|
||||
my $vars = shift;
|
||||
my $t;
|
||||
eval {
|
||||
$t = HTML::Template->new(%{$params});
|
||||
};
|
||||
unless ($@) {
|
||||
while (my ($section, $hash) = each %session) {
|
||||
next unless (ref $hash eq 'HASH');
|
||||
while (my ($key, $value) = each %$hash) {
|
||||
unless (lc($key) eq "password" || lc($key) eq "identifier") {
|
||||
$t->param("session.".$section.".".$key=>$value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$t->param(%{$vars});
|
||||
$t->param("webgui.version"=>$WebGUI::VERSION);
|
||||
return $t->output;
|
||||
} else {
|
||||
WebGUI::ErrorHandler::warn("Error in template. ".$@);
|
||||
return WebGUI::International::get(848).$@;
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( templateId, namespace )
|
||||
|
||||
Returns a hash reference containing all of the template parameters.
|
||||
|
||||
=over
|
||||
|
||||
|
|
@ -67,11 +106,9 @@ Defaults to "Page". Specify the namespace of the template to retrieve.
|
|||
=cut
|
||||
|
||||
sub get {
|
||||
my $templateId = $_[0] || 1;
|
||||
my $namespace = $_[1] || "Page";
|
||||
my ($template) = WebGUI::SQL->quickArray("select template from template
|
||||
where templateId=".$templateId." and namespace=".quote($namespace));
|
||||
return $template;
|
||||
my $templateId = shift || 1;
|
||||
my $namespace = shift || "Page";
|
||||
return WebGUI::SQL->quickHashRef("select * from template where templateId=".$templateId." and namespace=".quote($namespace));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -99,15 +136,19 @@ sub getList {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( template [ , vars ] )
|
||||
=head2 process ( templateId, namespace, vars )
|
||||
|
||||
Evaluate a template replacing template commands for HTML.
|
||||
|
||||
=over
|
||||
|
||||
=item template
|
||||
=item templateId
|
||||
|
||||
The template to process.
|
||||
Defaults to "1". Specify the templateId of the template to retrieve.
|
||||
|
||||
=item namespace
|
||||
|
||||
Defaults to "Page". Specify the namespace of the template to retrieve.
|
||||
|
||||
=item vars
|
||||
|
||||
|
|
@ -118,35 +159,117 @@ A hash reference containing template variables and loops. Automatically includes
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
my ($t, $test, $html);
|
||||
$html = $_[0];
|
||||
eval {
|
||||
$t = HTML::Template->new(
|
||||
scalarref=>\$html,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
strict=>0
|
||||
);
|
||||
};
|
||||
unless ($@) {
|
||||
while (my ($section, $hash) = each %session) {
|
||||
next unless (ref $hash eq 'HASH');
|
||||
while (my ($key, $value) = each %$hash) {
|
||||
unless (lc($key) eq "password" || lc($key) eq "identifier") {
|
||||
$t->param("session.".$section.".".$key=>$value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$t->param(%{$_[1]});
|
||||
$t->param("webgui.version"=>$WebGUI::VERSION);
|
||||
return $t->output;
|
||||
} else {
|
||||
WebGUI::ErrorHandler::warn("Error in template. ".$@);
|
||||
return WebGUI::International::get(848).$html;
|
||||
my $templateId = shift || 1;
|
||||
my $namespace = shift || "Page";
|
||||
my $vars = shift;
|
||||
my $file = _getTemplateFile($templateId,$namespace);
|
||||
my %params = (
|
||||
filename=>$file->getPath,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
no_includes=>1,
|
||||
file_cache_dir=>$session{config}{uploadsPath}.$session{os}{slash}."temp".$session{os}{slash}."templatecache",
|
||||
strict=>0
|
||||
);
|
||||
if ($session{config}{templateCacheType} eq "file") {
|
||||
$params{file_cache} = 1;
|
||||
} elsif ($session{config}{templateCacheType} eq "memory") {
|
||||
$params{cache} = 1;
|
||||
} elsif ($session{config}{templateCacheType} eq "ipc") {
|
||||
$params{shared_cache} = 1;
|
||||
} elsif ($session{config}{templateCacheType} eq "memory-ipc") {
|
||||
$params{double_cache} = 1;
|
||||
} elsif ($session{config}{templateCacheType} eq "memory-file") {
|
||||
$params{double_file_cache} = 1;
|
||||
}
|
||||
unless (-f $file->getPath) {
|
||||
my ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$templateId." and namespace=".quote($namespace));
|
||||
$file->saveFromScalar($template);
|
||||
}
|
||||
return _execute(\%params,$vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 processRaw ( template, vars )
|
||||
|
||||
Evaluate a template replacing template commands for HTML.
|
||||
|
||||
=over
|
||||
|
||||
=item template
|
||||
|
||||
A scalar variable containing the template.
|
||||
|
||||
=item vars
|
||||
|
||||
A hash reference containing template variables and loops. Automatically includes the entire WebGUI session.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub processRaw {
|
||||
my $template = shift;
|
||||
my $vars = shift;
|
||||
return _execute({
|
||||
scalarref=>\$template,
|
||||
global_vars=>1,
|
||||
loop_context_vars=>1,
|
||||
die_on_bad_params=>0,
|
||||
no_includes=>1,
|
||||
strict=>0
|
||||
},$vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 set ( data )
|
||||
|
||||
Store a template and it's metadata.
|
||||
|
||||
=over
|
||||
|
||||
=item data
|
||||
|
||||
A hash reference containing the data to be stored. At minimum the hash reference must include "templateId" and "namespace". The following are the elements allowed to be stored.
|
||||
|
||||
templateId - The unique id for the template. If set to "new" then a new one will be generated.
|
||||
|
||||
namespace - The namespace division for this template.
|
||||
|
||||
template - The content of the template.
|
||||
|
||||
name - A human friendly name for the template.
|
||||
|
||||
showInForms - A boolean indicating whether this template should appear when using the "template" subroutine in WebGUI::Form.
|
||||
|
||||
isEditable - A boolean indicating whether this template should be editable through the template manager.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub set {
|
||||
my $data = shift;
|
||||
if ($data->{templateId} eq "new") {
|
||||
($data->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace=".quote($data->{namespace}));
|
||||
$data->{templateId}++;
|
||||
if ($data->{templateId} < 1000) {
|
||||
$data->{templateId} = 1000;
|
||||
}
|
||||
WebGUI::SQL->write("insert into template (templateId,namespace) values (".$data->{templateId}.",".quote($data->{namespace}).")");
|
||||
}
|
||||
my @pairs;
|
||||
foreach my $key (keys %{$data}) {
|
||||
push(@pairs, $key."=".quote($data->{$key})) unless ($key eq "namespace" || $key eq "templateId");
|
||||
}
|
||||
WebGUI::SQL->write("update template set ".join(",",@pairs)." where templateId=".$data->{templateId}." and namespace=".quote($data->{namespace}));
|
||||
my $file = _getTemplateFile($data->{templateId},$data->{namespace});
|
||||
$file->delete;
|
||||
return $data->{templateId};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -797,7 +797,7 @@ sub processTemplate {
|
|||
$vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$_[0]->get("wobjectId"));
|
||||
}
|
||||
my $namespace = $_[3] || $_[0]->get("namespace");
|
||||
return WebGUI::Template::process(WebGUI::Template::get($_[1],$namespace), \%vars);
|
||||
return WebGUI::Template::process($_[1],$namespace, \%vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -566,7 +566,7 @@ sub www_viewEvent {
|
|||
$var{"next.label"} = WebGUI::International::get(93,$_[0]->get("namespace")).'»';
|
||||
$var{"next.url"} = WebGUI::URL::page("func=viewEvent&wid=".$_[0]->get("wobjectId")."&eid=".$id) if ($id);
|
||||
$var{description} = $event{description};
|
||||
return WebGUI::Template::process( WebGUI::Template::get( $_[0]->get("eventTemplateId"), "EventsCalendar/Event"), \%var);
|
||||
return $_[0]->processTemplate($_[0]->get("eventTemplateId"),\%var, "EventsCalendar/Event");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use Tie::CPHash;
|
|||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Page;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
|
@ -42,7 +43,7 @@ sub _traversePageTree {
|
|||
}
|
||||
$sth = WebGUI::SQL->read("select urlizedTitle, menuTitle, title, pageId, synopsis from page where parentId='$parent' and hideFromNavigation = 0 order by $orderBy");
|
||||
while ($data = $sth->hashRef) {
|
||||
if (($data->{pageId}<0 || $data->{pageId}>999 || $data->{pageId}==1) && WebGUI::Privilege::canViewPage($data->{pageId})) {
|
||||
if (($data->{pageId}<0 || $data->{pageId}>999 || $data->{pageId}==1) && WebGUI::Page::canView($data->{pageId})) {
|
||||
push(@pages,{
|
||||
"page.indent" => $indentString,
|
||||
"page.url" => WebGUI::URL::gateway($data->{urlizedTitle}),
|
||||
|
|
|
|||
|
|
@ -563,7 +563,7 @@ sub www_editSubmission {
|
|||
});
|
||||
$var{'form.submit'} = WebGUI::Form::submit();
|
||||
$var{'form.footer'} = '</form>';
|
||||
return WebGUI::Template::process(WebGUI::Template::get($_[0]->get("submissionFormTemplateId"),"USS/SubmissionForm"), \%var);
|
||||
return $_[0]->processTemplate($_[0]->get("submissionFormTemplateId"),\%var,"USS/SubmissionForm");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -891,7 +891,7 @@ sub www_viewSubmission {
|
|||
{callback=>$callback,title=>$submission->{title},forumId=>$submission->{forumId}},
|
||||
$submission->{forumId});
|
||||
}
|
||||
return WebGUI::Template::process(WebGUI::Template::get($_[0]->get("submissionTemplateId"),"USS/Submission"), \%var);
|
||||
return $_[0]->processTemplate($_[0]->get("submissionTemplateId"),\%var,"USS/Submission");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue