first round of changes for the new session system
This commit is contained in:
parent
da95226072
commit
d4b7f2ce59
128 changed files with 2442 additions and 1478 deletions
|
|
@ -1,4 +1,6 @@
|
|||
6.9.0
|
||||
- Converted WebGUI to use a new object oriented session system. More details
|
||||
in migation.txt.
|
||||
- fix [ 1379384 ] image uploads to non-public pages
|
||||
- fixed a problem with SynchFileToLDAP hourly script.
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,19 @@ upgrading from one version to the next, or even between multiple
|
|||
versions. Be sure to heed the warnings contained herein as they will
|
||||
save you many hours of grief.
|
||||
|
||||
6.9.0
|
||||
--------------------------------------------------------------------
|
||||
* The If macro has been removed because it's far too dangerous and
|
||||
error prone. If you use the If macro you may continue to use
|
||||
it at your own risk, maintenance, and support cost, but it
|
||||
is no longer supported by Plain Black.
|
||||
|
||||
* The session system has been replaced by a new object-oriented one,
|
||||
which has caused massive API changes. Please consult
|
||||
migration.txt to bring your custom code up to date with the
|
||||
new API.
|
||||
|
||||
|
||||
6.8.1
|
||||
--------------------------------------------------------------------
|
||||
* Before upgrading you must install the following new Perl modules:
|
||||
|
|
|
|||
|
|
@ -549,6 +549,113 @@ we are using a native mod perl handler. If you used $session{cgi} object
|
|||
you'll now need to convert your applications to use the methods provided by
|
||||
Apache2::Request which is referenced through $session{modperl} and $session{req}.
|
||||
|
||||
|
||||
5.23 Session System Replaced
|
||||
|
||||
As of 6.9.0 we've removed the old global session system and replaced it with a
|
||||
newer, safer, more modern, object oriented session system. Because session is
|
||||
the glue that holds WebGUI together, it has basically affected every API in
|
||||
the system. Here's a (hopefully complete) list of what's been changed and how
|
||||
it affects you.
|
||||
|
||||
%session no longer exists, so you can no longer do things like
|
||||
$session{user}{userId}. Instead, you'll know have a $session object that will
|
||||
be accessible in whatever plug-in environment you're working on. So to
|
||||
retrieve the current user's userId you'd call $session->user->userId because
|
||||
session loads the current user's user object, and then you can call the userId
|
||||
method on that object. If you're working in an asset environment, you may
|
||||
instead be calling something like $self->session->user->userId.
|
||||
|
||||
Please see the WebGUI::Session API for details on what objects are available
|
||||
through WebGUI::Session. The following unix command line tricks should fix 70%
|
||||
of the things you need to change in your custom assets. You will need to
|
||||
modify them slightly for other types of plugins (run these in order):
|
||||
|
||||
Fix $session{config}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{config}{webguiRoot}!\$self->session->config->getWebguiRoot!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{config}{configFile}!\$self->session->config->getFilename!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{config}{(\w+)}!\$self->session->config->get("$1")!g' {} \;
|
||||
|
||||
Fix $session{setting}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{setting}{(\w+)}!\$self->session->setting->get("$1")!g' {} \;
|
||||
|
||||
Fix $session{user}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{user}{([username|userId])}!\$self->session->user->$1!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{user}{(\w+)}!\$self->session->user->profileField("$1")!g' {} \;
|
||||
|
||||
Fix $session{env}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{env}{(\w+)}!\$self->session->env->get("$1")!g' {} \;
|
||||
|
||||
Fix $session{os}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{os}{(\w+)}!\$self->session->os->get("$1")!g' {} \;
|
||||
|
||||
Fix $session{var}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{var}{(\w+)}!\$self->session->var->get("$1")!g' {} \;
|
||||
|
||||
Fix $session{req}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{req}!\$self->session->request!g' {} \;
|
||||
|
||||
Fix $session{asset}
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{asset}!\$self->session->asset!g' {} \;
|
||||
|
||||
|
||||
5.23.1 WebGUI::SQL API Refactored
|
||||
|
||||
The SQL API has been made more object oriented in 6.9, so it now handles database
|
||||
connections for you. You can get the default database connection via
|
||||
$session->db or a random slave via $session->dbSlave or you can create your
|
||||
own by my $db = WebGUI::SQL->connect($session, $dsn, $user, $pass);
|
||||
|
||||
The following command line tricks should fix most of your database queries
|
||||
(provided your querying the WebGUI database):
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!WebGUI\:\:SQL\-\>!\$self->session->db->!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!quoteAndJoin\(!\$self->session->db->quoteAndJoin(!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!quote\(!\$self->session->db->quote(!g' {} \;
|
||||
|
||||
|
||||
5.23.2 WebGUI::FormProcessor API Refactored
|
||||
|
||||
Instead of accessing $session{form} or WebGUI::FormProcessor getting form data
|
||||
is done through the new session system via $session->form->process("param","Text");
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{form}{(\w+)}!\$self->session->form->process("$1")!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!WebGUI\:\:FormProcessor\:\:!\$self->session->form->!g' {} \;
|
||||
|
||||
|
||||
5.23.3 WebGUI::ErrorHandler API Refactored
|
||||
|
||||
As of 6.9 WebGUI::ErrorHandler is now accessed through session.
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!WebGUI\:\:ErrorHandler\:\:!\$self->session->errorHandler->!g' {} \;
|
||||
|
||||
|
||||
5.23.4 WebGUI::Style API Refactored
|
||||
|
||||
As of 6.9 the WebGUI::Style API has been convereted to OO and is accessed
|
||||
through session. The following command line tricks will help you convert your
|
||||
assets.
|
||||
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{page}{useEmptyStyle} = (\d+);!\$self->session->style->useEmptyStyle("$1")!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!\$session{page}{makePrintable} = (\d+);!\$self->session->style->makePrintable("$1")!g' {} \;
|
||||
find . -name '*.pm' -exec perl -pi.bak -e 's!WebGUI\:\:Style\:\:!\$self->session->style->!g' {} \;
|
||||
|
||||
|
||||
5.23.5 Lots of APIs Refactored
|
||||
|
||||
Lots of other API's have been refactored in 6.9 to conform to the new OO based
|
||||
session system. You should look at the API docs for individual details.
|
||||
|
||||
|
||||
|
||||
6. Automatic list of Assets in Help System.
|
||||
-------------------------------------
|
||||
6.1 Starting in WebGUI 6.7, there is now an automatic list of all Assets
|
||||
|
|
|
|||
|
|
@ -41,22 +41,16 @@ use Apache2::ServerUtil ();
|
|||
#-------------------------------------------------------------------
|
||||
sub handler {
|
||||
my $r = shift;
|
||||
$session{site} = shift || $r->dir_config('WebguiConfig');
|
||||
my $s = Apache2::ServerUtil->server;
|
||||
$s->add_version_component("WebGUI/".$WebGUI::VERSION); # had to remove b/c it was appending on every request for that instance of httpd. :(
|
||||
$session{wguri} = $r->uri;
|
||||
$session{config} = WebGUI::Config::getConfig($s->dir_config('WebguiRoot'),$session{site});
|
||||
### Add Apache Request stuff to global session. Yes, I know the global hash will eventually be deprecated.
|
||||
foreach my $url ($session{config}{extrasURL}, @{$session{config}{passthruUrls}}) {
|
||||
return Apache2::Const::DECLINED if ($session{wguri} =~ m/^$url/);
|
||||
$s->add_version_component("WebGUI/".$WebGUI::VERSION);
|
||||
$config = WebGUI::Config->new($s->dir_config('WebguiRoot'),$r->dir_config('WebguiConfig'));
|
||||
foreach my $url ($config->get("extrasURL"), @{$config->get("passthruUrls")}) {
|
||||
return Apache2::Const::DECLINED if ($r->uri =~ m/^$url/);
|
||||
}
|
||||
my $uploads = $session{config}{uploadsURL};
|
||||
if ($session{wguri} =~ m/^$uploads/) {
|
||||
my $uploads = $config->get("uploadsURL");
|
||||
if ($r->uri =~ m/^$uploads/) {
|
||||
$r->set_handlers(PerlAccessHandler => \&uploadsHandler);
|
||||
} else {
|
||||
$session{requestedUrl} = $session{wguri};
|
||||
my $gateway = $session{config}{gateway};
|
||||
$session{requestedUrl} =~ s/^$gateway(.*)$/$1/;
|
||||
$r->set_handlers(PerlResponseHandler => \&contentHandler);
|
||||
$r->set_handlers(PerlTransHandler => sub { return Apache2::Const::OK });
|
||||
}
|
||||
|
|
@ -66,80 +60,57 @@ sub handler {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub contentHandler {
|
||||
|
||||
### The following items must be in precisely the following order
|
||||
# because each line depends on something from the previous line.
|
||||
|
||||
### inherit Apache request.
|
||||
my $r = shift;
|
||||
### Instantiate the API for this httpd instance.
|
||||
my $s = Apache2::ServerUtil->server;
|
||||
### Open new or existing user session based on user-agent's cookie.
|
||||
WebGUI::Session::open($s->dir_config('WebguiRoot'),'modperl',"false");
|
||||
### Apache2::Request object
|
||||
$session{req} = Apache2::Request->new($r, POST_MAX => 1024 * $session{setting}{maxAttachmentSize});
|
||||
### Sets $session{cookie} as a hashref of the cookies.
|
||||
$session{cookie} = WebGUI::HTTP::getCookies();
|
||||
### Change current user to user specified in wgSession cookie.
|
||||
if ($session{cookie}{wgSession} eq "") {
|
||||
# setting up a visitor session
|
||||
$session{var}{sessionId} = WebGUI::Session::start(1);
|
||||
} else { # load previous session
|
||||
### populate $session{env} and $session{setting}
|
||||
WebGUI::Session::setupSessionVars($session{cookie}{wgSession});
|
||||
}
|
||||
### current user's account and profile information (from users and userProfileData tables)
|
||||
WebGUI::Session::setupUserInfo($session{var}{userId});
|
||||
### Add wgSession cookie to header iff it's not already on the client.
|
||||
WebGUI::HTTP::setCookie("wgSession",$session{var}{sessionId}) unless ($session{var}{sessionId} eq $session{cookie}{wgSession});
|
||||
### check to see if client is proxied and adjust remote_addr as necessary
|
||||
if ($ENV{HTTP_X_FORWARDED_FOR} ne "") {
|
||||
$session{env}{REMOTE_ADDR} = $ENV{HTTP_X_FORWARDED_FOR};
|
||||
}
|
||||
my $session = WebGUI::Session->open($s->dir_config('WebguiRoot'),$r->dir_config('WebguiConfig'),$r, $s);
|
||||
### form variables
|
||||
foreach ($session{req}->param) {
|
||||
$session{form}{$_} = $session{req}->body($_) || $session{req}->param($_);
|
||||
}
|
||||
if ($session{env}{HTTP_X_MOZ} eq "prefetch") { # browser prefetch is a bad thing
|
||||
WebGUI::HTTP::setStatus("403","We don't allow prefetch, because it increases bandwidth, hurts stats, and can break web sites.");
|
||||
$r->print(WebGUI::HTTP::getHeader());
|
||||
} elsif ($session{setting}{specialState} eq "upgrading") {
|
||||
if ($session->env->get("HTTP_X_MOZ") eq "prefetch") { # browser prefetch is a bad thing
|
||||
$session->http->setStatus("403","We don't allow prefetch, because it increases bandwidth, hurts stats, and can break web sites.");
|
||||
$r->print($session->http->getHeader);
|
||||
} elsif ($session->setting->get("specialState") eq "upgrading") {
|
||||
upgrading($r);
|
||||
} elsif ($session{setting}{specialState} eq "init") {
|
||||
} elsif ($session->setting->get("specialState") eq "init") {
|
||||
$r->print(setup());
|
||||
} else {
|
||||
my $output = "";
|
||||
if (WebGUI::ErrorHandler::canShowPerformanceIndicators()) {
|
||||
if ($session->errorHandler->canShowPerformanceIndicators) {
|
||||
my $t = [Time::HiRes::gettimeofday()];
|
||||
$output = page();
|
||||
$output = page($session);
|
||||
$t = Time::HiRes::tv_interval($t) ;
|
||||
$output =~ s/<\/title>/ : ${t} seconds<\/title>/i;
|
||||
} else {
|
||||
$output = page();
|
||||
$output = page($session);
|
||||
}
|
||||
$r->print(WebGUI::HTTP::getHeader());
|
||||
$r->print($output) unless (WebGUI::HTTP::isRedirect());
|
||||
WebGUI::Affiliate::grabReferral(); # process affilliate tracking request
|
||||
$r->print($session->http->getHeader());
|
||||
$r->print($output) unless ($session->http->isRedirect());
|
||||
#WebGUI::Affiliate::grabReferral(); # process affilliate tracking request
|
||||
}
|
||||
WebGUI::Session::close();
|
||||
$session->close;
|
||||
return Apache2::Const::OK;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub page {
|
||||
my $session = shift;
|
||||
my $assetUrl = shift;
|
||||
my $output = processOperations();
|
||||
if ($output eq "") {
|
||||
my $asset = eval{WebGUI::Asset->newByUrl($assetUrl,$session{form}{revision})};
|
||||
my $asset = eval{WebGUI::Asset->newByUrl($session,$assetUrl,$session{form}{revision})};
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::warn("Couldn't instantiate asset for url: ".$session{requestedUrl}." Root cause: ".$@);
|
||||
$session->errorHandler->warn("Couldn't instantiate asset for url: ".$session->url->getRequestedUrl." Root cause: ".$@);
|
||||
}
|
||||
if (defined $asset) {
|
||||
my $method = "view";
|
||||
if (exists $session{form}{func}) {
|
||||
$method = $session{form}{func};
|
||||
unless ($method =~ /^[A-Za-z]+$/) {
|
||||
WebGUI::ErrorHandler::security("tried to call a non-existent method $method on $assetUrl");
|
||||
$session->security("tried to call a non-existent method $method on $assetUrl");
|
||||
$method = "view";
|
||||
}
|
||||
}
|
||||
|
|
@ -148,12 +119,12 @@ sub page {
|
|||
}
|
||||
}
|
||||
if ($output eq "") {
|
||||
WebGUI::HTTP::setStatus("404","Page Not Found");
|
||||
my $notFound = WebGUI::Asset->getNotFound;
|
||||
$session->http->setStatus("404","Page Not Found");
|
||||
my $notFound = WebGUI::Asset->getNotFound($session);
|
||||
if (defined $notFound) {
|
||||
$output = tryAssetMethod($notFound,'view');
|
||||
} else {
|
||||
WebGUI::ErrorHandler::warn("The notFound page failed to be created!");
|
||||
$session->errorHandler->error("The notFound page failed to be created!");
|
||||
$output = "An error was encountered while processing your request.";
|
||||
}
|
||||
$output = "An error was encountered while processing your request." unless $output ne '';
|
||||
|
|
|
|||
|
|
@ -27,19 +27,13 @@ use Tie::IxHash;
|
|||
use WebGUI::AdminConsole;
|
||||
use WebGUI::Cache;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::FormProcessor;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::HTTP;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::Id;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::TabForm;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -411,7 +405,7 @@ sub getAssetAdderLinks {
|
|||
}
|
||||
my $sth = WebGUI::SQL->read("select asset.className,asset.assetId,assetData.revisionDate from asset left join assetData on asset.assetId=assetData.assetId where assetData.isPrototype=1 and asset.state='published' and asset.className in ($constraint) and assetData.revisionDate=(SELECT max(revisionDate) from assetData where assetData.assetId=asset.assetId) group by assetData.assetId");
|
||||
while (my ($class,$id,$date) = $sth->array) {
|
||||
my $asset = WebGUI::Asset->new($id,$class,$date);
|
||||
my $asset = WebGUI::Asset->new($self->session,$id,$class,$date);
|
||||
next unless ($asset->canView && $asset->canAdd && $asset->getUiLevel <= $session{user}{uiLevel});
|
||||
my $url = $self->getUrl("func=add;class=".$class.";prototype=".$id);
|
||||
$url = WebGUI::URL::append($url,$addToUrl) if ($addToUrl);
|
||||
|
|
@ -458,15 +452,20 @@ sub getContainer {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getDefault ( )
|
||||
=head2 getDefault ( session )
|
||||
|
||||
Returns the default object, which is also known by some as the "Home Page". The default object is set in the settings.
|
||||
Constructor. Returns the default object, which is also known by some as the "Home Page". The default object is set in the settings.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub getDefault {
|
||||
my $class = shift;
|
||||
return $class->newByDynamicClass($session{setting}{defaultPage});
|
||||
my $session = shift;
|
||||
return $class->newByDynamicClass($session, $session->setting->get("defaultPage"));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -719,14 +718,20 @@ sub getId {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getImportNode ()
|
||||
=head2 getImportNode ( session )
|
||||
|
||||
Returns the import node asset object. This is where developers will templates, files, etc to the asset tree that have no other obvious attachment point.
|
||||
Constructor. Returns the import node asset object. This is where developers will templates, files, etc to the asset tree that have no other obvious attachment point.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub getImportNode {
|
||||
return WebGUI::Asset->newByDynamicClass("PBasset000000000000002");
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
return WebGUI::Asset->newByDynamicClass($session, "PBasset000000000000002");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -777,45 +782,57 @@ sub getName {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getNotFound ( )
|
||||
=head2 getNotFound ( session )
|
||||
|
||||
Returns the not found object. The not found object is set in the settings.
|
||||
Constructor. Returns the not found object. The not found object is set in the settings.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub getNotFound {
|
||||
if ($session{requestedUrl} eq "*give-credit-where-credit-is-due*") {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
if ($session->url->getRequestedUrl eq "*give-credit-where-credit-is-due*") {
|
||||
my $content = "";
|
||||
open(FILE,"<".$session{config}{webguiRoot}."/docs/credits.txt");
|
||||
open(FILE,"<".$session->config->getWebguiRoot."/docs/credits.txt");
|
||||
while (<FILE>) {
|
||||
$content .= $_;
|
||||
}
|
||||
close(FILE);
|
||||
return WebGUI::Asset->newByPropertyHashRef({
|
||||
return WebGUI::Asset->newByPropertyHashRef($session,{
|
||||
className=>"WebGUI::Asset::Snippet",
|
||||
snippet=> '<pre>'.$content.'</pre>'
|
||||
});
|
||||
} elsif ($session{requestedUrl} eq "abcdefghijklmnopqrstuvwxyz") {
|
||||
return WebGUI::Asset->newByPropertyHashRef({
|
||||
} elsif ($session->url->getRequestedUrl eq "abcdefghijklmnopqrstuvwxyz") {
|
||||
return WebGUI::Asset->newByPropertyHashRef($session,{
|
||||
className=>"WebGUI::Asset::Snippet",
|
||||
snippet=>q|<div style="width: 600px; padding: 200px;">Why would you type in this URL? Really. What were you expecting to see here? You really need to get a life. Are you still here? Seriously, you need to go do something else. I think your boss is calling.</div>|
|
||||
});
|
||||
} else {
|
||||
return WebGUI::Asset->newByDynamicClass($session{setting}{notFoundPage});
|
||||
return WebGUI::Asset->newByDynamicClass($session, $session->setting->get("notFoundPage"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getRoot ()
|
||||
=head2 getRoot ( session )
|
||||
|
||||
Returns the root asset object.
|
||||
Constructor. Returns the root asset object.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub getRoot {
|
||||
return WebGUI::Asset->new("PBasset000000000000001");
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
return WebGUI::Asset->new($session, "PBasset000000000000001");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -965,10 +982,14 @@ sub getValue {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( assetId [, className, revisionDate ] )
|
||||
=head2 new ( session, assetId [, className, revisionDate ] )
|
||||
|
||||
Constructor. This does not create an asset. Returns a new object if it can, otherwise returns undef.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 assetId
|
||||
|
||||
The assetId of the asset you're creating an object reference for. Must not be blank.
|
||||
|
|
@ -985,27 +1006,31 @@ An epoch date that represents a specific version of an asset. By default the mos
|
|||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $assetId = shift;
|
||||
return undef unless ($assetId);
|
||||
my $className = shift;
|
||||
my $revisionDate = shift || $session{assetRevision}{$assetId}{$session{scratch}{versionTag}||'_'};
|
||||
my $assetRevision = $session->stow->get("assetRevision");
|
||||
my $revisionDate = shift || $assetRevision->{$assetId}{$session->scratch->get("versionTag")||'_'};
|
||||
unless ($revisionDate) {
|
||||
($revisionDate) = WebGUI::SQL->quickArray("select max(revisionDate) from assetData where assetId="
|
||||
.quote($assetId)." and (status='approved' or status='archived' or tagId=".quote($session{scratch}{versionTag}).")
|
||||
($revisionDate) = $session->db->quickArray("select max(revisionDate) from assetData where assetId="
|
||||
.$session->db->quote($assetId)." and (status='approved' or status='archived' or tagId="
|
||||
.$session->db->quote($session->scratch->get("versionTag")).")
|
||||
group by assetData.assetId order by assetData.revisionDate");
|
||||
$session{assetRevision}{$assetId}{$session{scratch}{versionTag}||'_'} = $revisionDate unless ($session{config}{disableCache});
|
||||
$assetRevision->{$assetId}{$session->scratch->get("versionTag")||'_'} = $revisionDate;
|
||||
$session->stow("assetRevision",$assetRevision);
|
||||
}
|
||||
return undef unless ($revisionDate);
|
||||
if ($className) {
|
||||
my $cmd = "use ".$className;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::error("Couldn't compile asset package: ".$className.". Root cause: ".$@);
|
||||
$session->errorHandler->error("Couldn't compile asset package: ".$className.". Root cause: ".$@);
|
||||
return undef;
|
||||
}
|
||||
$class = $className;
|
||||
}
|
||||
my $cache = WebGUI::Cache->new(["asset",$assetId,$revisionDate]);
|
||||
my $cache = WebGUI::Cache->new($session, ["asset",$assetId,$revisionDate]);
|
||||
my $properties = $cache->get;
|
||||
if (exists $properties->{assetId}) {
|
||||
# got properties from cache
|
||||
|
|
@ -1015,13 +1040,13 @@ sub new {
|
|||
$sql .= " left join ".$definition->{tableName}." on asset.assetId="
|
||||
.$definition->{tableName}.".assetId and ".$definition->{tableName}.".revisionDate=".$revisionDate;
|
||||
}
|
||||
$sql .= " where asset.assetId=".quote($assetId);
|
||||
$properties = WebGUI::SQL->quickHashRef($sql);
|
||||
$sql .= " where asset.assetId=".$session->db->quote($assetId);
|
||||
$properties = $session->db->quickHashRef($sql);
|
||||
return undef unless (exists $properties->{assetId});
|
||||
$cache->set($properties,60*60*24);
|
||||
}
|
||||
if (defined $properties) {
|
||||
my $object = { _properties => $properties };
|
||||
my $object = { _session=>$session, _properties => $properties };
|
||||
bless $object, $class;
|
||||
return $object;
|
||||
}
|
||||
|
|
@ -1030,10 +1055,14 @@ sub new {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newByDynamicClass ( assetId [ , revisionDate ] )
|
||||
=head2 newByDynamicClass ( session, assetId [ , revisionDate ] )
|
||||
|
||||
Similar to new() except that it will look up the classname of an asset rather than making you specify it. Returns undef if it can't find the classname.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 assetId
|
||||
|
||||
Must be a valid assetId
|
||||
|
|
@ -1046,25 +1075,32 @@ A specific revision date for the asset to retrieve. If not specified, the most r
|
|||
|
||||
sub newByDynamicClass {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $assetId = shift;
|
||||
my $revisionDate = shift;
|
||||
return undef unless defined $assetId;
|
||||
my $className = $session{assetClass}{$assetId};
|
||||
my $assetClass = $session->stow->get("assetClass");
|
||||
my $className = $assetClass->{$assetId};
|
||||
unless ($className) {
|
||||
($className) = WebGUI::SQL->quickArray("select className from asset where assetId=".quote($assetId));
|
||||
$session{assetClass}{$assetId} = $className unless ($session{config}{disableCache});
|
||||
($className) = $session->db->quickArray("select className from asset where assetId=".$session->db->quote($assetId));
|
||||
$assetClass->{$assetId} = $className;
|
||||
$session->stow->set("assetClass",$assetClass);
|
||||
}
|
||||
return undef unless ($className);
|
||||
return WebGUI::Asset->new($assetId,$className,$revisionDate);
|
||||
return WebGUI::Asset->new($session,$assetId,$className,$revisionDate);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newByPropertyHashRef ( properties )
|
||||
=head2 newByPropertyHashRef ( session, properties )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A properties hash reference. The className of the properties hash must be valid.
|
||||
|
|
@ -1073,22 +1109,27 @@ A properties hash reference. The className of the properties hash must be valid.
|
|||
|
||||
sub newByPropertyHashRef {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $properties = shift;
|
||||
return undef unless defined $properties;
|
||||
return undef unless exists $properties->{className};
|
||||
my $className = $properties->{className};
|
||||
my $cmd = "use ".$className;
|
||||
eval ($cmd);
|
||||
WebGUI::ErrorHandler::fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@);
|
||||
bless {_properties => $properties}, $className;
|
||||
$session->errorHandler->fatal("Couldn't compile asset package: ".$className.". Root cause: ".$@) if ($@);
|
||||
bless {_session=>$session, _properties => $properties}, $className;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newByUrl ( [url, revisionDate] )
|
||||
=head2 newByUrl ( session, [url, revisionDate] )
|
||||
|
||||
Returns a new Asset object based upon current url, given url or defaultPage.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 url
|
||||
|
||||
Optional string representing a URL.
|
||||
|
|
@ -1101,7 +1142,8 @@ A specific revision to instanciate. By default we instanciate the newest publish
|
|||
|
||||
sub newByUrl {
|
||||
my $class = shift;
|
||||
my $url = shift || $session{requestedUrl};
|
||||
my $session = shift;
|
||||
my $url = shift || $session->url->getRequestedUrl;
|
||||
my $revisionDate = shift;
|
||||
$url = lc($url);
|
||||
$url =~ s/\/$//;
|
||||
|
|
@ -1110,7 +1152,7 @@ sub newByUrl {
|
|||
$url =~ s/\"//;
|
||||
my $asset;
|
||||
if ($url ne "") {
|
||||
my ($id, $class) = WebGUI::SQL->quickArray("
|
||||
my ($id, $class) = $session->db->quickArray("
|
||||
select
|
||||
asset.assetId,
|
||||
asset.className
|
||||
|
|
@ -1119,18 +1161,18 @@ sub newByUrl {
|
|||
left join
|
||||
assetData on asset.assetId=assetData.assetId
|
||||
where
|
||||
assetData.url=".quote($url)."
|
||||
assetData.url=".$session->db->quote($url)."
|
||||
group by
|
||||
assetData.assetId
|
||||
");
|
||||
if ($id ne "" || $class ne "") {
|
||||
return WebGUI::Asset->new($id, $class, $revisionDate);
|
||||
return WebGUI::Asset->new($session,$id, $class, $revisionDate);
|
||||
} else {
|
||||
WebGUI::ErrorHandler::warn("The URL $url was requested, but does not exist in your asset tree.");
|
||||
$session->errorHandler->warn("The URL $url was requested, but does not exist in your asset tree.");
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
return WebGUI::Asset->getDefault;
|
||||
return WebGUI::Asset->getDefault($session);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -1204,7 +1246,7 @@ sub processTemplate {
|
|||
%{$self->{_properties}},
|
||||
%{$var}
|
||||
);
|
||||
my $template = WebGUI::Asset->new($templateId,"WebGUI::Asset::Template");
|
||||
my $template = WebGUI::Asset->new($self->session, $templateId,"WebGUI::Asset::Template");
|
||||
if (defined $template) {
|
||||
return $template->process(\%vars);
|
||||
} else {
|
||||
|
|
@ -1253,6 +1295,18 @@ sub purgeCache {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setSize ( [extra] )
|
||||
|
|
@ -1363,7 +1417,7 @@ sub www_add {
|
|||
return "";
|
||||
}
|
||||
if ($session{form}{'prototype'}) {
|
||||
my $prototype = WebGUI::Asset->new($session{form}{'prototype'},$class);
|
||||
my $prototype = WebGUI::Asset->new($self->session->form->process("prototype"),$class);
|
||||
foreach my $definition (@{$prototype->definition}) { # cycle through rather than copying properties to avoid grabbing stuff we shouldn't grab
|
||||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
next if (isIn($property,qw(title menuTitle url isPrototype isPackage)));
|
||||
|
|
@ -1387,7 +1441,7 @@ sub www_add {
|
|||
assetId=>"new"
|
||||
);
|
||||
$properties{isHidden} = 1 unless (WebGUI::Utility::isIn($class, @{$session{config}{assetContainers}}));
|
||||
my $newAsset = WebGUI::Asset->newByPropertyHashRef(\%properties);
|
||||
my $newAsset = WebGUI::Asset->newByPropertyHashRef($self->session,\%properties);
|
||||
$newAsset->{_parent} = $self;
|
||||
return WebGUI::Privilege::insufficient() unless ($newAsset->canAdd);
|
||||
return $newAsset->www_edit();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use File::Path;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -107,7 +106,7 @@ sub exportAsHtml {
|
|||
my %oldSession = %session;
|
||||
|
||||
# Change the stuff we need to change to do the export
|
||||
WebGUI::Session::refreshUserInfo($userId) unless ($userId == $session{user}{userId});
|
||||
$session->user({userId=>$userId}) unless ($userId == $session{user}{userId});
|
||||
delete $session{form};
|
||||
$session{var}{adminOn} = $self->get('adminOn');
|
||||
$self->WebGUI::Session::refreshPageInfo;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -494,9 +493,13 @@ sub hasChildren {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 newByLineage ( lineage )
|
||||
=head2 newByLineage ( session, lineage )
|
||||
|
||||
Returns an Asset object based upon given lineage.
|
||||
Constructor. Returns an Asset object based upon given lineage.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 lineage
|
||||
|
||||
|
|
@ -505,16 +508,19 @@ Lineage string.
|
|||
=cut
|
||||
|
||||
sub newByLineage {
|
||||
my $self = shift;
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $lineage = shift;
|
||||
my $id = $session{assetLineage}{$lineage}{id};
|
||||
my $class = $session{assetLineage}{$lineage}{class};
|
||||
my $assetLineage = $session->stow->get("assetLineage");
|
||||
my $id = $assetLineage->{$lineage}{id};
|
||||
$class = $assetLineage->{$lineage}{class};
|
||||
unless ($id && $class) {
|
||||
($id,$class) = WebGUI::SQL->quickArray("select assetId, className from asset where lineage=".quote($lineage));
|
||||
$session{assetLineage}{$lineage}{id} = $id unless ($session{config}{disableCache});
|
||||
$session{assetLineage}{$lineage}{class} = $class unless ($session{config}{disableCache});
|
||||
($id,$class) = $session->db->quickArray("select assetId, className from asset where lineage=".quote($lineage));
|
||||
$assetLineage->{$lineage}{id} = $id;
|
||||
$assetLineage->{$lineage}{class} = $class;
|
||||
$session->stow->set("assetLineage",$assetLineage);
|
||||
}
|
||||
return WebGUI::Asset->new($id, $class);
|
||||
return WebGUI::Asset->new($session, $id, $class);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package WebGUI::Asset;
|
|||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Paginator;
|
||||
|
||||
=head1 NAME
|
||||
|
|
|
|||
|
|
@ -258,8 +258,7 @@ sub createAccountSave {
|
|||
$authInfo .= "\n\n";
|
||||
WebGUI::MessageLog::addEntry($self->userId,"",WebGUI::International::get(870),$self->getSetting("welcomeMessage").$authInfo);
|
||||
}
|
||||
|
||||
WebGUI::Session::convertVisitorToUser($session{var}{sessionId},$userId);
|
||||
$session->user({user=>$u});
|
||||
_logLogin($userId,"success");
|
||||
my $command = $session{setting}{runOnRegistration};
|
||||
WebGUI::Macro::process(\$command);
|
||||
|
|
@ -559,7 +558,7 @@ sub login {
|
|||
#Create a new user
|
||||
$uid = $self->userId;
|
||||
$u = WebGUI::User->new($uid);
|
||||
WebGUI::Session::convertVisitorToUser($session{var}{sessionId},$uid);
|
||||
$session->user({user=>$u});
|
||||
$u->karma($session{setting}{karmaPerLogin},"Login","Just for logging in.") if ($session{setting}{useKarma});
|
||||
_logLogin($uid,"success");
|
||||
|
||||
|
|
|
|||
|
|
@ -683,7 +683,7 @@ sub updateAccount {
|
|||
}
|
||||
}
|
||||
$self->saveParams($u->userId,$self->authMethod,$properties);
|
||||
WebGUI::Session::refreshUserInfo($u->userId);
|
||||
$session->user({user=>$u});
|
||||
|
||||
return $self->displayAccount($display);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,32 +43,59 @@ These subroutines are available from this package:
|
|||
=cut
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getConfig ( webguiRoot , configFile )
|
||||
=head2 get ( param )
|
||||
|
||||
Returns a hash reference containing the configuration data. It tries to get the data out of the memory cache first, but reads the config file directly if necessary.
|
||||
Returns the value of a particular parameter from the config file.
|
||||
|
||||
=head3 webguiRoot
|
||||
=head3 param
|
||||
|
||||
The path to the WebGUI installation.
|
||||
|
||||
=head3 configFile
|
||||
|
||||
The filename of the config file to read.
|
||||
The name of the parameter to return.
|
||||
|
||||
=cut
|
||||
|
||||
sub getConfig {
|
||||
my $webguiPath = shift;
|
||||
my $filename = shift;
|
||||
if (exists $config{$filename}) {
|
||||
return $config{$filename};
|
||||
} else {
|
||||
$config{$filename} = readConfig($webguiPath,$filename);
|
||||
return $config{$filename};
|
||||
sub get {
|
||||
my $self = shift;
|
||||
my $param = shift;
|
||||
my $value = $self->{_config}->get($param);
|
||||
if (isIn($param, qw(assets utilityAssets assetContainers authMethods shippingPlugins paymentPlugins))) {
|
||||
if (ref $value ne "ARRAY") {
|
||||
$value = [$value];
|
||||
}
|
||||
} elsif (isIn($param, qw(assetAddPrivilege macros))) {
|
||||
if (ref $value ne "HASH") {
|
||||
$value = {};
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getFilename ( )
|
||||
|
||||
Returns the filename for this config.
|
||||
|
||||
=cut
|
||||
|
||||
sub getFilename {
|
||||
my $self = shift;
|
||||
return $self->{_configFile};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getWebguiRoot ( )
|
||||
|
||||
Returns the path to the WebGUI installation.
|
||||
|
||||
=cut
|
||||
|
||||
sub getWebguiRoot {
|
||||
my $self = shift;
|
||||
return $self->{_webguiRoot};
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -76,7 +103,7 @@ sub getConfig {
|
|||
|
||||
=head2 loadAllConfigs ( webguiRoot )
|
||||
|
||||
Reads all the config file data for all defined sites into an in-memory cache.
|
||||
Reads all the config file data for all defined sites into an in-memory cache. This is a class method.
|
||||
|
||||
=head3 webguiRoot
|
||||
|
||||
|
|
@ -85,6 +112,7 @@ The path to the WebGUI installation.
|
|||
=cut
|
||||
|
||||
sub loadAllConfigs {
|
||||
my $class = shift;
|
||||
my $webguiPath = shift;
|
||||
my $configs = readAllConfigs($webguiPath);
|
||||
foreach my $filename (keys %{$configs}) {
|
||||
|
|
@ -98,38 +126,9 @@ sub loadAllConfigs {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 readAllConfigs ( webguiRoot )
|
||||
=head2 new ( webguiRoot , configFile )
|
||||
|
||||
Reads all the config file data for all defined sites and returns a hash reference containing the resulting data by config file name.
|
||||
|
||||
Example: $configs->{$filename};
|
||||
|
||||
=head3 webguiRoot
|
||||
|
||||
The path to the WebGUI installation.
|
||||
|
||||
=cut
|
||||
|
||||
sub readAllConfigs {
|
||||
my $webguiPath = shift;
|
||||
opendir(DIR,$webguiPath."/etc");
|
||||
my @files = readdir(DIR);
|
||||
closedir(DIR);
|
||||
my %configs;
|
||||
foreach my $file (@files) {
|
||||
if ($file =~ /\.conf$/ && !($file =~ /^log\.conf$/) && !($file =~ /^spectre\.conf$/)) {
|
||||
$configs{$file} = readConfig($webguiPath,$file);
|
||||
}
|
||||
}
|
||||
return \%configs;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 readConfig ( webguiRoot , configFile )
|
||||
|
||||
Returns a hash reference containing the configuration data. It reads the config data directly from the file.
|
||||
Returns a hash reference containing the configuration data. It tries to get the data out of the memory cache first, but reads the config file directly if necessary.
|
||||
|
||||
=head3 webguiRoot
|
||||
|
||||
|
|
@ -141,37 +140,49 @@ The filename of the config file to read.
|
|||
|
||||
=cut
|
||||
|
||||
sub readConfig {
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $webguiPath = shift;
|
||||
my $filename = shift;
|
||||
my $config = Parse::PlainConfig->new('DELIM' => '=',
|
||||
'FILE' => $webguiPath.'/etc/'.$filename,
|
||||
'PURGE' => 1);
|
||||
my %data;
|
||||
foreach my $key ($config->directives) {
|
||||
$data{$key} = $config->get($key);
|
||||
}
|
||||
foreach my $directive (qw(assets utilityAssets assetContainers authMethods paymentPlugins)) {
|
||||
if (ref $data{$directive} ne "ARRAY") {
|
||||
$data{$directive} = [$data{$directive}];
|
||||
}
|
||||
if (exists $config{$filename}) {
|
||||
return $config{$filename};
|
||||
} else {
|
||||
my $config = Parse::PlainConfig->new('DELIM' => '=', 'FILE' => $webguiPath.'/etc/'.$filename, 'PURGE' => 1);
|
||||
my $self = {_webguiRoot=>$webguiPath, _configFile=>$filename, _config=>$config};
|
||||
bless $self, $class;
|
||||
$config{$filename} = $self;
|
||||
return $self;
|
||||
}
|
||||
foreach my $directive (qw(assetAddPrivilege macros)) {
|
||||
if (ref $data{$directive} ne "HASH") {
|
||||
$data{$directive} = {};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 readAllConfigs ( webguiRoot )
|
||||
|
||||
Reads all the config file data for all defined sites and returns a hash reference containing WebGUI::Config objects keyed by filename. This is a class method.
|
||||
|
||||
Example: $configs->{$filename};
|
||||
|
||||
=head3 webguiRoot
|
||||
|
||||
The path to the WebGUI installation.
|
||||
|
||||
=cut
|
||||
|
||||
sub readAllConfigs {
|
||||
my $class = shift;
|
||||
my $webguiPath = shift;
|
||||
opendir(DIR,$webguiPath."/etc");
|
||||
my @files = readdir(DIR);
|
||||
closedir(DIR);
|
||||
my %configs;
|
||||
foreach my $file (@files) {
|
||||
if ($file =~ /\.conf$/ && !($file =~ /^log\.conf$/) && !($file =~ /^spectre\.conf$/)) {
|
||||
$configs{$file} = WebGUI::Config->new($webguiPath,$file);
|
||||
}
|
||||
}
|
||||
if (ref $data{shippingPlugins} ne "ARRAY") {
|
||||
$data{shippingPlugins} = [$data{shippingPlugins}] if ($data{shippingPlugins});
|
||||
}
|
||||
if (ref $data{sitename} eq "ARRAY") {
|
||||
$data{defaultSitename} = $data{sitename}[0];
|
||||
} else {
|
||||
$data{defaultSitename} = $data{sitename};
|
||||
}
|
||||
$data{webguiRoot} = $webguiPath;
|
||||
$data{configFile} = $filename;
|
||||
return \%data;
|
||||
return \%configs;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@ package WebGUI::ErrorHandler;
|
|||
|
||||
|
||||
use strict;
|
||||
use FileHandle;
|
||||
use Log::Log4perl;
|
||||
use WebGUI::Session;
|
||||
use Apache2::RequestUtil;
|
||||
|
||||
$Log::Log4perl::caller_depth++;
|
||||
|
|
@ -35,25 +33,25 @@ This package provides simple but effective error handling, debugging, and loggi
|
|||
|
||||
use WebGUI::ErrorHandler;
|
||||
|
||||
WebGUI::ErrorHandler::audit(message);
|
||||
WebGUI::ErrorHandler::fatalError();
|
||||
WebGUI::ErrorHandler::security(message);
|
||||
WebGUI::ErrorHandler::warn(message);
|
||||
my $errorHandler = WebGUI::ErrorHandler->new($session);
|
||||
|
||||
WebGUI::ErrorHandler::getSecurity();
|
||||
WebGUI::ErrorHandler::getSessionVars();
|
||||
WebGUI::ErrorHandler::getStackTrace();
|
||||
$errorHandler->audit($message);
|
||||
$errorHandler->debug($message);
|
||||
$errorHandler->error($message);
|
||||
$errorHandler->fatal($message);
|
||||
$errorHandler->info($message);
|
||||
$errorHandler->security($message);
|
||||
$errorHandler->warn($message);
|
||||
|
||||
WebGUI::ErrorHandler::showDebug();
|
||||
WebGUI::ErrorHandler::showStackTrace();
|
||||
WebGUI::ErrorHandler::showWarnings();
|
||||
$logger = $errorHandler->getLogger;
|
||||
|
||||
WebGUI::ErrorHandler::stamp($type);
|
||||
WebGUI::ErrorHandler::writeLog($message);
|
||||
$text = $errorHandler->getSessionVars;
|
||||
$text = $errorHandler->getStackTrace;
|
||||
$html = $errorHandler->showDebug;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These functions are available from this package:
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -72,9 +70,10 @@ Whatever message you wish to insert into the log.
|
|||
=cut
|
||||
|
||||
sub audit {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
$Log::Log4perl::caller_depth++;
|
||||
info($WebGUI::Session::session{user}{username}." (".$WebGUI::Session::session{user}{userId}.") ".$message);
|
||||
$self->info($self->{_session}->user->username." (".$self->{_session}->user->userId.") ".$message);
|
||||
$Log::Log4perl::caller_depth--;
|
||||
}
|
||||
|
||||
|
|
@ -88,17 +87,18 @@ Returns true if the user meets the condition to see debugging information and de
|
|||
=cut
|
||||
|
||||
sub canShowDebug {
|
||||
return 0 unless ($WebGUI::Session::session{setting}{showDebug});
|
||||
return 1 if ($WebGUI::Session::session{setting}{debugIp} eq "");
|
||||
my @ips = split(" ",$WebGUI::Session::session{setting}{debugIp});
|
||||
my $ok = 0;
|
||||
foreach my $ip (@ips) {
|
||||
if ($WebGUI::Session::session{env}{REMOTE_ADDR} =~ /^$ip/) {
|
||||
$ok = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
my $self = shift;
|
||||
return 0 unless ($self->{_session}->setting->get("showDebug"));
|
||||
return 1 if ($self->{_session}->setting->get("debugIp") eq "");
|
||||
my @ips = split(" ",$self->{_session}->setting->get("debugIp"));
|
||||
my $ok = 0;
|
||||
foreach my $ip (@ips) {
|
||||
if ($self->{_session}->env("REMOTE_ADDR") =~ /^$ip/) {
|
||||
$ok = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -110,16 +110,17 @@ Returns true if the user meets the conditions to see performance indicators and
|
|||
=cut
|
||||
|
||||
sub canShowPerformanceIndicators {
|
||||
my $mask = $WebGUI::Session::session{setting}{debugIp};
|
||||
my $ip = $WebGUI::Session::session{env}{REMOTE_ADDR};
|
||||
return (
|
||||
(
|
||||
$WebGUI::Session::session{setting}{showPerformanceIndicators}
|
||||
) && (
|
||||
$ip =~ /^$mask/ ||
|
||||
$WebGUI::Session::session{setting}{debugIp} eq ""
|
||||
)
|
||||
);
|
||||
my $self = shift;
|
||||
my $mask = $self->{_session}->setting->get("debugIp");
|
||||
my $ip = $self->{_session}->env("REMOTE_ADDR");
|
||||
return (
|
||||
(
|
||||
$self->{_session}->setting->get("showPerformanceIndicators")
|
||||
) && (
|
||||
$ip =~ /^$mask/ ||
|
||||
$self->{_session}->setting->get("debugIp") eq ""
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -136,10 +137,10 @@ The message you wish to add to the log.
|
|||
=cut
|
||||
|
||||
sub debug {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
my $logger = getLogger();
|
||||
$logger->debug($message);
|
||||
$WebGUI::Session::session{debug}{'debug'} .= $message."\n";
|
||||
$self->getLogger->debug($message);
|
||||
$self->{_session}->stow->set("debug_debug") = $self->{_session}->stow->get("debug_debug").$message."\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -156,11 +157,11 @@ The message you wish to add to the log.
|
|||
=cut
|
||||
|
||||
sub error {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
my $logger = getLogger();
|
||||
$logger->error($message);
|
||||
$logger->debug("Stack trace for ERROR ".$message."\n".getStackTrace());
|
||||
$WebGUI::Session::session{debug}{'error'} .= $message."\n";
|
||||
$self->getLogger->error($message);
|
||||
$self->getLogger->debug("Stack trace for ERROR ".$message."\n".$self->getStackTrace());
|
||||
$self->{_session}->stow->set("debug_error") = $self->{_session}->stow->get("debug_error").$message."\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -173,28 +174,28 @@ Adds a FATAL type message to the log, outputs an error message to the user, and
|
|||
=cut
|
||||
|
||||
sub fatal {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
WebGUI::HTTP::setStatus("500","Server Error");
|
||||
my $logger = getLogger();
|
||||
Apache2::RequestUtil->request->content_type('text/html') if ($WebGUI::Session::session{req});
|
||||
$logger->fatal($message);
|
||||
$logger->debug("Stack trace for FATAL ".$message."\n".getStackTrace());
|
||||
print WebGUI::HTTP::getHeader if ($WebGUI::Session::session{req});
|
||||
unless (canShowDebug()) {
|
||||
my $self->{_session}->http->setStatus("500","Server Error");
|
||||
Apache2::RequestUtil->request->content_type('text/html') if ($self->{_session}->request);
|
||||
$self->getLogger->fatal($message);
|
||||
$self->getLogger->debug("Stack trace for FATAL ".$message."\n".$self->getStackTrace());
|
||||
print $self->{_session}->http->getHeader if ($self->{_session}->request);
|
||||
unless ($self->canShowDebug()) {
|
||||
#NOTE: You can't internationalize this because with some types of errors that would cause an infinite loop.
|
||||
print "<h1>Problem With Request</h1>
|
||||
We have encountered a problem with your request. Please use your back button and try again.
|
||||
If this problem persists, please contact us with what you were trying to do and the time and date of the problem.";
|
||||
print '<br />'.$WebGUI::Session::session{setting}{companyName};
|
||||
print '<br />'.$WebGUI::Session::session{setting}{companyEmail};
|
||||
print '<br />'.$WebGUI::Session::session{setting}{companyURL};
|
||||
print '<br />'.$self->{_session}->setting("companyName");
|
||||
print '<br />'.$self->{_session}->setting("companyEmail");
|
||||
print '<br />'.$self->{_session}->setting("companyURL");
|
||||
} else {
|
||||
print "<h1>WebGUI Fatal Error</h1><p>Something unexpected happened that caused this system to fault.</p>\n";
|
||||
print "<p>".$message."</p>\n";
|
||||
print showDebug();
|
||||
print $self->showDebug();
|
||||
}
|
||||
WebGUI::Session::close();
|
||||
exit; #this is bad under mod_perl. restarts that httpd instance.
|
||||
$self->{_session}->close();
|
||||
die $message;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -207,10 +208,8 @@ Returns a reference to the logger.
|
|||
=cut
|
||||
|
||||
sub getLogger {
|
||||
unless (Log::Log4perl->initialized()) {
|
||||
Log::Log4perl->init( $WebGUI::Session::session{config}{webguiRoot}."/etc/log.conf" );
|
||||
}
|
||||
return Log::Log4perl->get_logger($WebGUI::Session::session{config}{configFile});
|
||||
my $self = shift;
|
||||
return $self->{_logger};
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -223,11 +222,10 @@ Returns a text message containing all of the session variables.
|
|||
=cut
|
||||
|
||||
sub getSessionVars {
|
||||
my $self = shift;
|
||||
my $data;
|
||||
while (my ($section, $hash) = each %WebGUI::Session::session) {
|
||||
if ($section eq "debug" || $section eq 'replacements') {
|
||||
next;
|
||||
} elsif (ref $hash eq 'HASH') {
|
||||
while (my ($section, $hash) = each %{$self->{_session}}) {
|
||||
if (ref $hash eq 'HASH') {
|
||||
while (my ($key, $value) = each %$hash) {
|
||||
if (ref $value eq 'ARRAY') {
|
||||
$value = '['.join(', ',@$value).']';
|
||||
|
|
@ -259,6 +257,7 @@ Returns a text formatted message containing the current stack trace.
|
|||
=cut
|
||||
|
||||
sub getStackTrace {
|
||||
my $self = shift;
|
||||
my $i = 2;
|
||||
my $output;
|
||||
while (my @data = caller($i)) {
|
||||
|
|
@ -283,10 +282,32 @@ The message you wish to add to the log.
|
|||
=cut
|
||||
|
||||
sub info {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
my $logger = getLogger();
|
||||
$logger->info($message);
|
||||
$WebGUI::Session::session{debug}{'info'} .= $message."\n";
|
||||
$self->getLogger->info($message);
|
||||
$self->{_session}->stow->set("debug_info") = $self->{_session}->stow->get("debug_info").$message."\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session )
|
||||
|
||||
Constructor. Instanciates a new error handler instance.
|
||||
|
||||
=head3 session
|
||||
|
||||
An active WebGUI::Session object.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
unless (Log::Log4perl->initialized()) {
|
||||
Log::Log4perl->init( $session->config->getWebguiRoot."/etc/log.conf" );
|
||||
}
|
||||
my $logger = Log::Log4perl->get_logger($session->config->getFilename);
|
||||
bless {_logger=>$logger, _session=>$session}, $class;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -303,10 +324,11 @@ The message you wish to add to the log.
|
|||
=cut
|
||||
|
||||
sub security {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
$Log::Log4perl::caller_depth++;
|
||||
WebGUI::ErrorHandler::warn($WebGUI::Session::session{user}{username}." (".$WebGUI::Session::session{user}{userId}.") connecting from "
|
||||
.$WebGUI::Session::session{env}{REMOTE_ADDR}." attempted to ".$message);
|
||||
$self->warn($self->{_session}->user->username." (".$self->{_session}->user->userId.") connecting from "
|
||||
.$self->{_session}->env("REMOTE_ADDR")." attempted to ".$message);
|
||||
$log::Log4perl::caller_depth--;
|
||||
}
|
||||
|
||||
|
|
@ -320,19 +342,20 @@ Creates an HTML formatted string
|
|||
=cut
|
||||
|
||||
sub showDebug {
|
||||
my $text = $WebGUI::Session::session{debug}{'error'};
|
||||
my $self = shift;
|
||||
my $text = $self->{_session}->stow->get('debug_error');
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
my $output = 'beginDebug<br /><div style="background-color: #800000;color: #ffffff;">'.$text."</div>\n";
|
||||
$text = $WebGUI::Session::session{debug}{'warn'};
|
||||
$text = $self->{_session}->stow->get('debug_warn');
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="background-color: #ffdddd;color: #000000;">'.$text."</div>\n";
|
||||
$text = $WebGUI::Session::session{debug}{'info'};
|
||||
$text = $self->{_session}->stow->get('debug_info');
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="background-color: #ffffdd;color: #000000;">'.$text."</div>\n";
|
||||
$text = $WebGUI::Session::session{debug}{'debug'};
|
||||
$text = $self->{_session}->stow->get('debug_debug');
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="background-color: #dddddd;color: #000000;">'.$text."</div>\n";
|
||||
$text = getSessionVars();
|
||||
$text = $self->getSessionVars();
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="background-color: #ffffff;color: #000000;">'.$text."</div>\n";
|
||||
return $output;
|
||||
|
|
@ -353,10 +376,10 @@ The message you wish to add to the log.
|
|||
=cut
|
||||
|
||||
sub warn {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
my $logger = getLogger();
|
||||
$logger->warn($message);
|
||||
$WebGUI::Session::session{debug}{'warn'} .= $message."\n";
|
||||
$self->getLogger->warn($message);
|
||||
$self->{_session}->stow->set("debug_warn") = $self->{_session}->stow->get("debug_warn").$message."\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -95,22 +95,22 @@ Renders an asset selector.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($self->{value}) || WebGUI::Asset->getRoot;
|
||||
my $asset = WebGUI::Asset->newByDynamicClass($self->get("value")) || WebGUI::Asset->getRoot;
|
||||
return WebGUI::Form::Hidden->new(
|
||||
name=>$self->{name},
|
||||
extras=>$self->{extras},
|
||||
name=>$self->get("name"),
|
||||
extras=>$self->get("extras"),
|
||||
value=>$asset->getId,
|
||||
id=>$self->{id}
|
||||
)->toHtml
|
||||
.WebGUI::Form::Text->new(
|
||||
name=>$self->{name}."_display",
|
||||
name=>$self->get("name")."_display",
|
||||
extras=>' readonly="1" ',
|
||||
value=>$asset->get("title"),
|
||||
id=>$self->{id}."_display"
|
||||
)->toHtml
|
||||
.WebGUI::Form::Button->new(
|
||||
value=>"...",
|
||||
extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree;classLimiter=".$self->{class}.";formId=".$self->{id}).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"'
|
||||
extras=>'onclick="window.open(\''.$asset->getUrl("op=formAssetTree;classLimiter=".$self->get("class").";formId=".$self->{id}).'\',\'assetPicker\',\'toolbar=no, location=no, status=no, directories=no, width=400, height=400\');"'
|
||||
)->toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -77,11 +77,11 @@ Renders a button.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixQuotes($self->{value});
|
||||
my $value = $self->fixQuotes($self->get("value"));
|
||||
my $html = '<input type="button" ';
|
||||
$html .= 'name="'.$self->{name}.'" ' if ($self->{name});
|
||||
$html .= 'name="'.$self->get("name").'" ' if ($self->get("name"));
|
||||
$html .= 'id="'.$self->{id}.'" ' unless ($self->{id} eq "_formId");
|
||||
$html .= 'value="'.$value.'" '.$self->{extras}.' />';
|
||||
$html .= 'value="'.$value.'" '.$self->get("extras").' />';
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,18 +92,18 @@ sub toHtml {
|
|||
%options = $self->orderedHash();
|
||||
foreach my $key (keys %options) {
|
||||
my $checked = 0;
|
||||
foreach my $item (@{$self->{value}}) {
|
||||
foreach my $item (@{$self->get("value}")) {
|
||||
if ($item eq $key) {
|
||||
$checked = 1;
|
||||
}
|
||||
}
|
||||
$output .= WebGUI::Form::Checkbox->new({
|
||||
name=>$self->{name},
|
||||
name=>$self->get("name"),
|
||||
value=>$key,
|
||||
extras=>$self->{extras},
|
||||
extras=>$self->get("extras"),
|
||||
checked=>$checked
|
||||
})->toHtml;
|
||||
$output .= ${$self->{options}}{$key} . $alignment;
|
||||
$output .= ${$self->get("options}"){$key} . $alignment;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ Retrieves a value from a form GET or POST and returns it. If the value comes bac
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $formValue = $session{req}->param($self->{name});
|
||||
my $formValue = $self->session->request->param($self->get("name"));
|
||||
if (defined $formValue) {
|
||||
return $formValue;
|
||||
} else {
|
||||
|
|
@ -122,10 +122,10 @@ Renders and input tag of type checkbox.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
|
||||
my $checkedText = ' checked="checked"' if ($self->{checked});
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value"))));
|
||||
my $checkedText = ' checked="checked"' if ($self->get("checked"));
|
||||
my $idText = ' id="'.$self->{id}.'" ' if ($self->{id});
|
||||
return '<input type="checkbox" name="'.$self->{name}.'" value="'.$value.'"'.$idText.$checkedText.' '.$self->{extras}.' />';
|
||||
return '<input type="checkbox" name="'.$self->get("name").'" value="'.$value.'"'.$idText.$checkedText.' '.$self->get("extras").' />';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ Renders a code area field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/TabFix.js',{type=>"text/javascript"});
|
||||
$self->{extras} .= ' style="width: 99%; min-width: 440px; height: 400px" onkeypress="return TabFix_keyPress(event)" onkeydown="return TabFix_keyDown(event)"';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/TabFix.js',{type=>"text/javascript"});
|
||||
$self->get("extras") .= ' style="width: 99%; min-width: 440px; height: 400px" onkeypress="return TabFix_keyPress(event)" onkeydown="return TabFix_keyDown(event)"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ Returns a hex color like "#000000". Returns undef if the return value is not a v
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $color = $session{req}->param($self->{name});
|
||||
my $color = $self->session->request->param($self->get("name"));
|
||||
return undef unless $color =~ /\#\w{6}/;
|
||||
return $color;
|
||||
}
|
||||
|
|
@ -82,8 +82,8 @@ Renders a color picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/colorPicker.js',{ type=>'text/javascript' });
|
||||
return '<script type="text/javascript">initColorPicker("'.$self->{name}.'","'.($self->{value}).'");</script>';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/colorPicker.js',{ type=>'text/javascript' });
|
||||
return '<script type="text/javascript">initColorPicker("'.$self->get("name").'","'.($self->get("value")).'");</script>';
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -79,8 +79,8 @@ Returns an array or a carriage return ("\n") separated scalar depending upon whe
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
if ($session{req}->param($self->{name}."_new")) {
|
||||
return $session{req}->param($self->{name}."_new");
|
||||
if ($self->session->request->param($self->get("name")."_new")) {
|
||||
return $self->session->request->param($self->get("name")."_new");
|
||||
}
|
||||
return $self->SUPER::getValueFromPost;
|
||||
}
|
||||
|
|
@ -95,12 +95,12 @@ Renders a combo box form control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
$self->{options}->{''} = '['.WebGUI::International::get(582).']';
|
||||
$self->{options}->{_new_} = WebGUI::International::get(581).'->';
|
||||
$self->get("options")->{''} = '['.WebGUI::International::get(582).']';
|
||||
$self->get("options")->{_new_} = WebGUI::International::get(581).'->';
|
||||
return $self->SUPER::toHtml
|
||||
.WebGUI::Form::Text->new(
|
||||
size=>$session{setting}{textBoxSize}-5,
|
||||
name=>$self->{name}."_new",
|
||||
size=>$self->session->setting->get("textBoxSize")-5,
|
||||
name=>$self->get("name")."_new",
|
||||
id=>$self->{id}."_new"
|
||||
)->toHtml;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ Renders a select list form control.
|
|||
sub toHtml {
|
||||
my $self = shift;
|
||||
my %types;
|
||||
foreach my $type (@{$self->{types}}) {
|
||||
foreach my $type (@{$self->get("types}")) {
|
||||
if ($type eq "text") {
|
||||
$types{text} = WebGUI::International::get(1010);
|
||||
} elsif ($type eq "mixed") {
|
||||
|
|
@ -103,7 +103,7 @@ sub toHtml {
|
|||
$types{html} = WebGUI::International::get(1009);
|
||||
}
|
||||
}
|
||||
$self->{options} = \%types,
|
||||
$self->get("options") = \%types,
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ sub displayFormWithWrapper {
|
|||
if ($self->passUiLevelCheck) {
|
||||
my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper;
|
||||
return '<tr'.$rowClass.'>
|
||||
<td'.$labelClass.$hoverHelp.' valign="top" style="width: 25%;">'.$self->{label}.'</td>
|
||||
<td'.$labelClass.$hoverHelp.' valign="top" style="width: 25%;">'.$self->get("label").'</td>
|
||||
<td valign="top"'.$fieldClass.' style="width: 75%;">'.$self->displayForm().$subtext."</td>
|
||||
</tr>\n";
|
||||
} else {
|
||||
|
|
@ -250,7 +250,7 @@ form elements will just return their value.
|
|||
|
||||
sub displayValue {
|
||||
my ($self) = @_;
|
||||
return $self->{value};
|
||||
return $self->get("value");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -271,6 +271,25 @@ sub generateIdParameter {
|
|||
return $name."_formId";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( var )
|
||||
|
||||
Returns a property of this form object.
|
||||
|
||||
=head3 var
|
||||
|
||||
The variable name of the value to return.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my $self = shift;
|
||||
my $var = shift;
|
||||
return $self->{_params}{$var};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getName ( )
|
||||
|
|
@ -373,20 +392,24 @@ Retrieves a value from a form GET or POST and returns it. If the value comes bac
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $formValue = $session{req}->param($self->{name});
|
||||
my $formValue = $self->session->request->param($self->get("name"));
|
||||
if (defined $formValue) {
|
||||
return $formValue;
|
||||
} else {
|
||||
return $self->{defaultValue};
|
||||
return $self->get("defaultValue");
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( parameters )
|
||||
=head2 new ( session, parameters )
|
||||
|
||||
Constructor. Creates a new form field object.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 parameters
|
||||
|
||||
Accepts any parameters specified by the definition() method. This parameter set can be specified by either a hash or hash reference, and can be tagged or not. Here are examples:
|
||||
|
|
@ -402,6 +425,7 @@ Please note that an id attribute is automatically added to every form element wi
|
|||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my %raw;
|
||||
# deal with a hash reference full of properties
|
||||
if (ref $_[0] eq "HASH") {
|
||||
|
|
@ -440,8 +464,10 @@ sub new {
|
|||
}
|
||||
# preventing ID collisions
|
||||
$params{id} = $params{idPrefix}.$params{id};
|
||||
bless \%params, $class;
|
||||
bless {_session=>$session, _params=>\%params}, $class;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 prepareWrapper ( )
|
||||
|
|
@ -452,13 +478,13 @@ Common code for preparing wrappers for *WithWrapper
|
|||
|
||||
sub prepareWrapper {
|
||||
my $self = shift;
|
||||
my $rowClass = $self->{rowClass};
|
||||
$rowClass = qq| class="$rowClass" | if($self->{rowClass});
|
||||
my $labelClass = $self->{labelClass};
|
||||
$labelClass = qq| class="$labelClass" | if($self->{labelClass});
|
||||
my $fieldClass = $self->{fieldClass};
|
||||
$fieldClass = qq| class="$fieldClass" | if($self->{fieldClass});
|
||||
my $hoverHelp = $self->{hoverHelp};
|
||||
my $rowClass = $self->get("rowClass");
|
||||
$rowClass = qq| class="$rowClass" | if($self->get("rowClass"));
|
||||
my $labelClass = $self->get("labelClass");
|
||||
$labelClass = qq| class="$labelClass" | if($self->get("labelClass"));
|
||||
my $fieldClass = $self->get("fieldClass");
|
||||
$fieldClass = qq| class="$fieldClass" | if($self->get("fieldClass"));
|
||||
my $hoverHelp = $self->get("hoverHelp");
|
||||
$hoverHelp =~ s/\r/ /g;
|
||||
$hoverHelp =~ s/\n/ /g;
|
||||
$hoverHelp =~ s/&/& amp;/g;
|
||||
|
|
@ -471,11 +497,26 @@ sub prepareWrapper {
|
|||
$hoverHelp =~ s/'/\\'/g;
|
||||
$hoverHelp =~ s/^\s+//;
|
||||
$hoverHelp = qq| onmouseover="return escape('$hoverHelp')"| if ($hoverHelp);
|
||||
my $subtext = $self->{subtext};
|
||||
my $subtext = $self->get("subtext");
|
||||
$subtext = qq| <span class="formSubtext">$subtext</span>| if ($subtext);
|
||||
return ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 toHtml ( )
|
||||
|
|
@ -486,7 +527,7 @@ Renders the form field to HTML. This method should be overridden by all subclass
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
return $self->{value};
|
||||
return $self->get("value");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -499,7 +540,7 @@ Renders the form field to HTML as a hidden field rather than whatever field type
|
|||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
return '<input type="hidden" name="'.$self->{name}.'" value="'.$self->fixQuotes($self->fixMacros($self->fixSpecialCharacters($self->{value}))).'" />'."\n";
|
||||
return '<input type="hidden" name="'.$self->get("name").'" value="'.$self->fixQuotes($self->fixMacros($self->fixSpecialCharacters($self->get("value")))).'" />'."\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -515,7 +556,7 @@ sub toHtmlWithWrapper {
|
|||
if ($self->passUiLevelCheck) {
|
||||
my ($fieldClass, $rowClass, $labelClass, $hoverHelp, $subtext) = $self->prepareWrapper;
|
||||
return '<tr'.$rowClass.'>
|
||||
<td'.$labelClass.$hoverHelp.' valign="top" style="width: 25%;">'.$self->{label}.'</td>
|
||||
<td'.$labelClass.$hoverHelp.' valign="top" style="width: 25%;">'.$self->get("label").'</td>
|
||||
<td valign="top"'.$fieldClass.' style="width: 75%;">'.$self->toHtml().$subtext."</td>
|
||||
</tr>\n";
|
||||
} else {
|
||||
|
|
@ -534,10 +575,11 @@ Renders the form field to HTML as a table row complete with labels, subtext, hov
|
|||
sub passUiLevelCheck {
|
||||
my $self = shift;
|
||||
my $passUiLevelCheck = 0;
|
||||
if ($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}}) { # use override if it exists
|
||||
$passUiLevelCheck = ($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}} <= $session{user}{uiLevel});
|
||||
my $override = $self->session->config->get($self->get("uiLevelOverride")."_uiLevel")
|
||||
if (defined $override && $override->{$self->get("name")}) { # use override if it exists
|
||||
$passUiLevelCheck = ($override->{$self->get("name")} <= $self->session->user->profileField("uiLevel"));
|
||||
} else { # use programmed default
|
||||
$passUiLevelCheck = ($self->{uiLevel} <= $session{user}{uiLevel});
|
||||
$passUiLevelCheck = ($self->get("uiLevel") <= $self->session->user->profileField("uiLevel"));
|
||||
}
|
||||
$passUiLevelCheck = WebGUI::Grouping::isInGroup(3) unless ($passUiLevelCheck); # override if in admins group
|
||||
return $passUiLevelCheck;
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ Renders a database connection picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
$self->{options} = WebGUI::DatabaseLink::getList();
|
||||
$self->get("options") = WebGUI::DatabaseLink::getList();
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
|
|
@ -125,11 +125,11 @@ sub toHtmlWithWrapper {
|
|||
my $self = shift;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
my $subtext;
|
||||
if ($self->{afterEdit}) {
|
||||
$subtext = editIcon("op=editDatabaseLink;lid=".$self->{value}.";afterEdit=".WebGUI::URL::escape($self->{afterEdit}));
|
||||
if ($self->get("afterEdit")) {
|
||||
$subtext = editIcon("op=editDatabaseLink;lid=".$self->get("value").";afterEdit=".WebGUI::URL::escape($self->get("afterEdit")));
|
||||
}
|
||||
$subtext .= manageIcon("op=listDatabaseLinks");
|
||||
$self->{subtext} = $subtext . $self->{subtext};
|
||||
$self->get("subtext") = $subtext . $self->get("subtext");
|
||||
}
|
||||
return $self->SUPER::toHtmlWithWrapper;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ Return the date in a human readable format for the Profile system.
|
|||
|
||||
sub displayValue {
|
||||
my ($self) = @_;
|
||||
return WebGUI::DateTime::epochToHuman($self->{value},"%z");
|
||||
return WebGUI::DateTime::epochToHuman($self->get("value"),"%z");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -122,7 +122,7 @@ Returns a validated form post result. If the result does not pass validation, it
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::setToEpoch($session{req}->param($self->{name}));
|
||||
return WebGUI::DateTime::setToEpoch($self->session->request->param($self->get("name")));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -135,20 +135,20 @@ Renders a date picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
if ($self->{_defaulted} && $self->{noDate} ) {
|
||||
$self->{value} = '';
|
||||
if ($self->get("_defaulted") && $self->get("noDate") ) {
|
||||
$self->get("value") = '';
|
||||
}
|
||||
else {
|
||||
$self->{value} = WebGUI::DateTime::epochToSet($self->{value});
|
||||
$self->get("value") = WebGUI::DateTime::epochToSet($self->get("value"));
|
||||
}
|
||||
my $language = WebGUI::International::getLanguage($session{user}{language},"languageAbbreviation");
|
||||
my $language = WebGUI::International::getLanguage($self->session->user->profileField("language"),"languageAbbreviation");
|
||||
unless ($language) {
|
||||
$language = WebGUI::International::getLanguage("English","languageAbbreviation");
|
||||
}
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-'.$language.'.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setLink($session{config}{extrasURL}.'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" });
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/calendar/calendar.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/calendar/lang/calendar-'.$language.'.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/calendar/calendar-setup.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setLink($self->session->config->get("extrasURL").'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" });
|
||||
return $self->SUPER::toHtml. '<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "'.$self->{id}.'",
|
||||
|
|
@ -156,7 +156,7 @@ sub toHtml {
|
|||
showsTime : false,
|
||||
step : 1,
|
||||
timeFormat : "12",
|
||||
firstDay : '.$session{user}{firstDayOfWeek}.'
|
||||
firstDay : '.$self->session->user->profileField("firstDayOfWeek").'
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
|
@ -172,8 +172,8 @@ Renders the form field to HTML as a hidden field rather than whatever field type
|
|||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
return WebGUI::Form::Hidden->new(
|
||||
name=>$self->{name},
|
||||
value=>WebGUI::DateTime::epochToSet($self->{value})
|
||||
name=>$self->get("name"),
|
||||
value=>WebGUI::DateTime::epochToSet($self->get("value"))
|
||||
)->toHtmlAsHidden;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ Returns a validated form post result. If the result does not pass validation, it
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::setToEpoch($session{req}->param($self->{name}));
|
||||
return WebGUI::DateTime::setToEpoch($self->session->request->param($self->get("name")));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -114,23 +114,23 @@ Renders a date picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = WebGUI::DateTime::epochToSet($self->{value},1);
|
||||
my $language = WebGUI::International::getLanguage($session{user}{language},"languageAbbreviation");
|
||||
my $value = WebGUI::DateTime::epochToSet($self->get("value"),1);
|
||||
my $language = WebGUI::International::getLanguage($self->session->user->profileField("language"),"languageAbbreviation");
|
||||
unless ($language) {
|
||||
$language = WebGUI::International::getLanguage("English","languageAbbreviation");
|
||||
}
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/lang/calendar-'.$language.'.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/calendar/calendar-setup.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setLink($session{config}{extrasURL}.'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" });
|
||||
my $mondayFirst = $session{user}{firstDayOfWeek} ? "true" : "false";
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/calendar/calendar.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/calendar/lang/calendar-'.$language.'.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/calendar/calendar-setup.js',{ type=>'text/javascript' });
|
||||
WebGUI::Style::setLink($self->session->config->get("extrasURL").'/calendar/calendar-win2k-1.css', { rel=>"stylesheet", type=>"text/css", media=>"all" });
|
||||
my $mondayFirst = $self->session->user->profileField("firstDayOfWeek") ? "true" : "false";
|
||||
return WebGUI::Form::Text->new(
|
||||
name=>$self->{name},
|
||||
name=>$self->get("name"),
|
||||
value=>$value,
|
||||
size=>$self->{size},
|
||||
extras=>$self->{extras},
|
||||
size=>$self->get("size"),
|
||||
extras=>$self->get("extras"),
|
||||
id=>$self->{id},
|
||||
maxlength=>$self->{maxlength}
|
||||
maxlength=>$self->get("maxlength")
|
||||
)->toHtml . '<script type="text/javascript">
|
||||
Calendar.setup({
|
||||
inputField : "'.$self->{id}.'",
|
||||
|
|
@ -138,7 +138,7 @@ sub toHtml {
|
|||
showsTime : true,
|
||||
step : 1,
|
||||
timeFormat : "12",
|
||||
firstDay : '.$session{user}{firstDayOfWeek}.'
|
||||
firstDay : '.$self->session->user->profileField("firstDayOfWeek").'
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
|
|
@ -154,8 +154,8 @@ Renders the form field to HTML as a hidden field rather than whatever field type
|
|||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
return WebGUI::Form::Hidden->new(
|
||||
name=>$self->{name},
|
||||
value=>WebGUI::DateTime::epochToSet($self->{value},1)
|
||||
name=>$self->get("name"),
|
||||
value=>WebGUI::DateTime::epochToSet($self->get("value"),1)
|
||||
)->toHtmlAsHidden;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ Returns a validated email address. If the result does not pass validation, it re
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
|
||||
if ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) {
|
||||
return $value;
|
||||
|
|
@ -96,8 +96,8 @@ Renders an email address field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/emailCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onchange="emailCheck(this.value)" ';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/emailCheck.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onchange="emailCheck(this.value)" ';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ and DynamicField, the form class dispatcher.
|
|||
|
||||
sub getTypes {
|
||||
my $class = shift;
|
||||
opendir(DIR,$session{config}{webguiRoot}."/lib/WebGUI/Form/");
|
||||
opendir(DIR,$self->session->config->getWebguiRoot."/lib/WebGUI/Form/");
|
||||
my @rawTypes = readdir(DIR);
|
||||
closedir(DIR);
|
||||
my @types;
|
||||
|
|
@ -112,7 +112,7 @@ Returns either what's posted or if nothing comes back it returns "text".
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return $session{req}->param($self->{name}) || "text";
|
||||
return $self->session->request->param($self->get("name")) || "text";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -127,7 +127,7 @@ sub toHtml {
|
|||
my $self = shift;
|
||||
my %options;
|
||||
tie %options, "Tie::IxHash";
|
||||
foreach my $type (@{$self->{types}}) {
|
||||
foreach my $type (@{$self->get("types}")) {
|
||||
my $class = "WebGUI::Form::".ucfirst($type);
|
||||
my $cmd = "use ".$class;
|
||||
eval ($cmd);
|
||||
|
|
@ -137,7 +137,7 @@ sub toHtml {
|
|||
}
|
||||
$options{$type} = $class->getName;
|
||||
}
|
||||
$self->{options} = \%options;
|
||||
$self->get("options") = \%options;
|
||||
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,15 +94,15 @@ delete it. Otherwise, display a form element to upload a file.
|
|||
|
||||
sub displayForm {
|
||||
my ($self) = @_;
|
||||
return $self->toHtml unless $self->{value};
|
||||
return $self->toHtml unless $self->get("value");
|
||||
##There are files inside here, for each one, display the image
|
||||
##and another form control for deleting it.
|
||||
my $location = WebGUI::Storage->get($self->{value});
|
||||
my $location = WebGUI::Storage->get($self->get("value"));
|
||||
my $id = $location->getId;
|
||||
my $fileForm = '';
|
||||
foreach my $file ( @{ $location->getFiles } ) {
|
||||
$fileForm .= sprintf qq!<img src="%s" /><br />!, $location->getUrl($file);
|
||||
my $action = join '_', '_', $self->{name}, 'delete';
|
||||
my $action = join '_', '_', $self->get("name"), 'delete';
|
||||
$fileForm .= WebGUI::International::get(392)
|
||||
. " "x4
|
||||
. WebGUI::Form::YesNo->new({-name=>$action, -value=>0})->toHtml;
|
||||
|
|
@ -123,8 +123,8 @@ form elements will just return their value.
|
|||
|
||||
sub displayValue {
|
||||
my ($self) = @_;
|
||||
return '' unless $self->{value};
|
||||
my $location = WebGUI::Storage->get($self->{value});
|
||||
return '' unless $self->get("value");
|
||||
my $location = WebGUI::Storage->get($self->get("value"));
|
||||
local $_;
|
||||
my @files = map { sprintf qq!<img src="%s" /> %s!, $location->getFileIconUrl($_), $_; } @{ $location->getFiles };
|
||||
my $fileValue = join "<br />\n", @files;
|
||||
|
|
@ -143,8 +143,8 @@ deleting the file if it was specified.
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
if ($session{req}->param(join '_', '_', $self->{name}, 'delete')) {
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
if ($self->session->request->param(join '_', '_', $self->get("name"), 'delete')) {
|
||||
my $storage = WebGUI::Storage->get($value);
|
||||
$storage->delete;
|
||||
return '';
|
||||
|
|
@ -157,7 +157,7 @@ sub getValueFromPost {
|
|||
else {
|
||||
$storage = WebGUI::Storage::Image->create;
|
||||
}
|
||||
$storage->addFileFromFormPost($self->{name});
|
||||
$storage->addFileFromFormPost($self->get("name"));
|
||||
my @files = @{ $storage->getFiles };
|
||||
if (scalar(@files) < 1) {
|
||||
$storage->delete;
|
||||
|
|
@ -179,21 +179,21 @@ Renders a file upload control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/FileUploadControl.js',{type=>"text/javascript"});
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/FileUploadControl.js',{type=>"text/javascript"});
|
||||
my $uploadControl = '<script type="text/javascript">
|
||||
var fileIcons = new Array();
|
||||
';
|
||||
opendir(DIR,$session{config}{extrasPath}.'/fileIcons');
|
||||
opendir(DIR,$self->session->config->get("extrasPath").'/fileIcons');
|
||||
my @files = readdir(DIR);
|
||||
closedir(DIR);
|
||||
foreach my $file (@files) {
|
||||
unless ($file eq "." || $file eq "..") {
|
||||
my $ext = $file;
|
||||
$ext =~ s/(.*?)\.gif/$1/;
|
||||
$uploadControl .= 'fileIcons["'.$ext.'"] = "'.$session{config}{extrasURL}.'/fileIcons/'.$file.'";'."\n";
|
||||
$uploadControl .= 'fileIcons["'.$ext.'"] = "'.$self->session->config->get("extrasURL").'/fileIcons/'.$file.'";'."\n";
|
||||
}
|
||||
}
|
||||
$uploadControl .= 'var uploader = new FileUploadControl("'.$self->{name}.'", fileIcons, "'.WebGUI::International::get('removeLabel','WebGUI').'","'.$self->{maxAttachments}.'");
|
||||
$uploadControl .= 'var uploader = new FileUploadControl("'.$self->get("name").'", fileIcons, "'.WebGUI::International::get('removeLabel','WebGUI').'","'.$self->get("maxAttachments").'");
|
||||
uploader.addRow();
|
||||
</script>';
|
||||
return $uploadControl;
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ Returns either what's posted or if nothing comes back it returns "most".
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return $session{req}->param($self->{name}) || "most";
|
||||
return $self->session->request->param($self->get("name")) || "most";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -114,7 +114,7 @@ sub toHtml {
|
|||
'most'=>WebGUI::International::get(421),
|
||||
'all'=>WebGUI::International::get(419)
|
||||
);
|
||||
$self->{options} = \%filter;
|
||||
$self->get("options") = \%filter;
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ Returns the integer from the form post, or returns 0.0 if the post result is inv
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
if ($value =~ /^[\d\-\.]+$/) {
|
||||
return $value;
|
||||
}
|
||||
|
|
@ -116,8 +116,8 @@ Renders a floating point field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789-.\')"';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onkeyup="doInputCheck(this.form.'.$self->get("name").',\'0123456789-.\')"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,10 +109,10 @@ Returns a group pull-down field. A group pull down provides a select list that p
|
|||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $where;
|
||||
if ($self->{excludeGroups}[0] ne "") {
|
||||
$where = "and groupId not in (".quoteAndJoin($self->{excludeGroups}).")";
|
||||
if ($self->get("excludeGroups")[0] ne "") {
|
||||
$where = "and groupId not in (".$self->session->db->quoteAndJoin($self->get("excludeGroups")).")";
|
||||
}
|
||||
$self->{options} = WebGUI::SQL->buildHashRef("select groupId,groupName from groups where showInForms=1 $where order by groupName");
|
||||
$self->get("options") = $self->session->db->buildHashRef("select groupId,groupName from groups where showInForms=1 $where order by groupName");
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ Creates a series of hidden fields representing the data in the list.
|
|||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
$self->{options} = WebGUI::SQL->buildHashRef("select groupId,groupName from groups");
|
||||
$self->get("options") = $self->session->db->buildHashRef("select groupId,groupName from groups");
|
||||
return $self->SUPER::toHtmlAsHidden();
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +142,7 @@ sub toHtmlWithWrapper {
|
|||
my $self = shift;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
my $subtext = manageIcon("op=listGroups");
|
||||
$self->{subtext} = $subtext . $self->{subtext};
|
||||
$self->get("subtext") = $subtext . $self->get("subtext");
|
||||
}
|
||||
return $self->SUPER::toHtmlWithWrapper;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,13 +77,13 @@ sub definition {
|
|||
defaultValue=>WebGUI::International::get("477","WebGUI")
|
||||
},
|
||||
rows=>{
|
||||
defaultValue=> $session{setting}{textAreaRows}+20
|
||||
defaultValue=> $self->session->setting->get("textAreaRows")+20
|
||||
},
|
||||
columns=>{
|
||||
defaultValue=> $session{setting}{textAreaCols}+10
|
||||
defaultValue=> $self->session->setting->get("textAreaCols")+10
|
||||
},
|
||||
richEditId=>{
|
||||
defaultValue=>$session{setting}{richEditor} || "PBrichedit000000000001"
|
||||
defaultValue=>$self->session->setting->get("richEditor") || "PBrichedit000000000001"
|
||||
},
|
||||
profileEnabled=>{
|
||||
defaultValue=>1
|
||||
|
|
@ -116,10 +116,10 @@ Renders an HTML area field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/textFix.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onblur="fixChars(this.form.'.$self->{name}.')" mce_editable="true" ';
|
||||
return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->{richEditId})->getRichEditor($self->{id});
|
||||
my $richEdit = WebGUI::Asset::RichEdit->new($self->{richEditId});
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/textFix.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onblur="fixChars(this.form.'.$self->get("name").')" mce_editable="true" ';
|
||||
return $self->SUPER::toHtml.WebGUI::Asset::RichEdit->new($self->get("richEditId"))->getRichEditor($self->{id});
|
||||
my $richEdit = WebGUI::Asset::RichEdit->new($self->get("richEditId"));
|
||||
if (defined $richEdit) {
|
||||
return $self->SUPER::toHtml.$richEdit->getRichEditor($self->{id});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -102,9 +102,9 @@ Renders an input tag of type hidden.
|
|||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value"))));
|
||||
my $idText = ' id="'.$self->{id}.'" ' if ($self->{id});
|
||||
return '<input type="hidden" name="'.$self->{name}.'" value="'.$value.'" '.$self->{extras}.$idText.' />'."\n";
|
||||
return '<input type="hidden" name="'.$self->get("name").'" value="'.$value.'" '.$self->get("extras").$idText.' />'."\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -98,8 +98,8 @@ profile field.
|
|||
|
||||
sub displayValue {
|
||||
my ($self) = @_;
|
||||
return '' unless $self->{value};
|
||||
my $location = WebGUI::Storage->get($self->{value});
|
||||
return '' unless $self->get("value");
|
||||
my $location = WebGUI::Storage->get($self->get("value"));
|
||||
local $_;
|
||||
my @files = map { sprintf qq!<img src="%s" />!, $location->getUrl($_) } @{ $location->getFiles };
|
||||
my $fileValue = join "<br />\n", @files;
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ Returns the integer from the form post, or returns 0 if the post result is inval
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
if ($value =~ /^[\d\-]+$/) {
|
||||
return $value;
|
||||
}
|
||||
|
|
@ -116,8 +116,8 @@ Renders an integer field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789-\')"';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onkeyup="doInputCheck(this.form.'.$self->get("name").',\'0123456789-\')"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ Returns either the interval that was posted (in seconds) or if nothing comes bac
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::intervalToSeconds($session{req}->param($self->{name}."_interval"),$session{req}->param($self->{name}."_units")) || 0;
|
||||
return WebGUI::DateTime::intervalToSeconds($self->session->request->param($self->get("name")."_interval"),$self->session->request->param($self->get("name")."_units")) || 0;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -112,20 +112,20 @@ sub toHtml {
|
|||
'weeks'=>WebGUI::International::get(701),
|
||||
'months'=>WebGUI::International::get(702),
|
||||
'years'=>WebGUI::International::get(703));
|
||||
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($self->{value});
|
||||
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($self->get("value"));
|
||||
# not sure why, but these things need to be defined like this or
|
||||
# they fail under some circumstnaces
|
||||
my $cmd = "WebGUI::Form::Integer";
|
||||
my $out = $cmd->new(
|
||||
name=>$self->{name}."_interval",
|
||||
name=>$self->get("name")."_interval",
|
||||
value=>$interval,
|
||||
extras=>$self->{extras},
|
||||
extras=>$self->get("extras"),
|
||||
id=>$self->{id}."_interval",
|
||||
)->toHtml;
|
||||
$cmd = "WebGUI::Form::SelectBox";
|
||||
$out .= $cmd->new(
|
||||
options=>\%units,
|
||||
name=>$self->{name}."_units",
|
||||
name=>$self->get("name")."_units",
|
||||
id=>$self->{id}."_units",
|
||||
value=>[$units]
|
||||
)->toHtml;
|
||||
|
|
@ -143,13 +143,13 @@ Returns the field as hidden controls rather than displayable controls.
|
|||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($self->{value});
|
||||
my ($interval, $units) = WebGUI::DateTime::secondsToInterval($self->get("value"));
|
||||
return WebGUI::Form::Hidden->new(
|
||||
name=>$self->{name}.'_interval',
|
||||
name=>$self->get("name").'_interval',
|
||||
value=>$interval
|
||||
)->toHtmlAsHidden
|
||||
.WebGUI::Form::Hidden->new(
|
||||
name=>$self->{name}.'_units',
|
||||
name=>$self->get("name").'_units',
|
||||
value=>$units
|
||||
)->toHtmlAsHidden;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ Renders a database connection picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
$self->{options} = WebGUI::LDAPLink::getList();
|
||||
$self->get("options") = WebGUI::LDAPLink::getList();
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ Creates a series of hidden fields representing the data in the list.
|
|||
|
||||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
$self->{options} = WebGUI::LDAPLink::getList();
|
||||
$self->get("options") = WebGUI::LDAPLink::getList();
|
||||
return $self->SUPER::toHtmlAsHidden();
|
||||
}
|
||||
|
||||
|
|
@ -146,11 +146,11 @@ sub toHtmlWithWrapper {
|
|||
my $self = shift;
|
||||
if (WebGUI::Grouping::isInGroup(3)) {
|
||||
my $subtext;
|
||||
if ($self->{afterEdit}) {
|
||||
$subtext = editIcon("op=editLDAPLink;llid=".$self->{value}.";afterEdit=".WebGUI::URL::escape($self->{afterEdit}));
|
||||
if ($self->get("afterEdit")) {
|
||||
$subtext = editIcon("op=editLDAPLink;llid=".$self->get("value").";afterEdit=".WebGUI::URL::escape($self->get("afterEdit")));
|
||||
}
|
||||
$subtext .= manageIcon("op=listLDAPLinks");
|
||||
$self->{subtext} = $subtext . $self->{subtext};
|
||||
$self->get("subtext") = $subtext . $self->get("subtext");
|
||||
}
|
||||
return $self->SUPER::toHtmlWithWrapper;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ of radio/check boxes.
|
|||
|
||||
sub alignmentSeparator {
|
||||
my ($self) = @_;
|
||||
if ($self->{vertical}) {
|
||||
if ($self->get("vertical")) {
|
||||
return "<br />\n";
|
||||
}
|
||||
else {
|
||||
|
|
@ -72,10 +72,10 @@ sub correctOptions {
|
|||
s/\s+$//; # remove trailing spaces
|
||||
$options{$_} = $_;
|
||||
}
|
||||
if (exists $self->{options} && ref($self->{options}) eq "HASH") {
|
||||
%options = (%{$self->{options}} , %options);
|
||||
if (exists $self->get("options") && ref($self->get("options")) eq "HASH") {
|
||||
%options = (%{$self->get("options}") , %options);
|
||||
}
|
||||
$self->{options} = \%options;
|
||||
$self->get("options") = \%options;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ sub correctValues {
|
|||
s/\s+$//; # remove trailing spaces
|
||||
push(@defaultValues, $_);
|
||||
}
|
||||
$self->{value} = \@defaultValues;
|
||||
$self->get("value") = \@defaultValues;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ Returns an array or a carriage return ("\n") separated scalar depending upon whe
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my @data = $session{req}->param($self->{name});
|
||||
my @data = $self->session->request->param($self->get("name"));
|
||||
return wantarray ? @data : join("\n",@data);
|
||||
}
|
||||
|
||||
|
|
@ -207,11 +207,11 @@ ref.
|
|||
sub getValues {
|
||||
my $self = shift;
|
||||
my @values = ();
|
||||
if (ref $self->{value} eq 'ARRAY') {
|
||||
@values = @{ $self->{value} };
|
||||
if (ref $self->get("value") eq 'ARRAY') {
|
||||
@values = @{ $self->get("value") };
|
||||
}
|
||||
else {
|
||||
push @values, $self->{value};
|
||||
push @values, $self->get("value");
|
||||
}
|
||||
return @values;
|
||||
}
|
||||
|
|
@ -230,12 +230,12 @@ sub orderedHash {
|
|||
my ($self) = @_;
|
||||
my %options;
|
||||
tie %options, 'Tie::IxHash';
|
||||
if ($self->{sortByValue}) {
|
||||
foreach my $optionKey (sort {"\L${$self->{options}}{$a}" cmp "\L${$self->{options}}{$b}" } keys %{$self->{options}}) {
|
||||
$options{$optionKey} = $self->{options}{$optionKey};
|
||||
if ($self->get("sortByValue")) {
|
||||
foreach my $optionKey (sort {"\L${$self->get("options}"){$a}" cmp "\L${$self->get("options}"){$b}" } keys %{$self->get("options}")) {
|
||||
$options{$optionKey} = $self->get("options"){$optionKey};
|
||||
}
|
||||
} else {
|
||||
%options = %{$self->{options}};
|
||||
%options = %{$self->get("options}");
|
||||
}
|
||||
return %options;
|
||||
}
|
||||
|
|
@ -259,7 +259,7 @@ sub toHtmlAsHidden {
|
|||
foreach my $item (@values) {
|
||||
if ($item eq $key) {
|
||||
$output .= WebGUI::Form::Hidden->(
|
||||
name=>$self->{name},
|
||||
name=>$self->get("name"),
|
||||
value=>$key
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,9 +91,9 @@ Renders an input tag of type password.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $html = '<input type="password" name="'.$self->{name}.'" value="'.$self->fixQuotes($self->{value}).'" size="'.$self->{size}.'" id="'.$self->{id}.'" ';
|
||||
$html .= 'maxlength="'.$self->{maxLength}.'" ' if ($self->{maxLength});
|
||||
$html .= $self->{extras}.' />';
|
||||
my $html = '<input type="password" name="'.$self->get("name").'" value="'.$self->fixQuotes($self->get("value")).'" size="'.$self->get("size").'" id="'.$self->{id}.'" ';
|
||||
$html .= 'maxlength="'.$self->get("maxLength").'" ' if ($self->get("maxLength"));
|
||||
$html .= $self->get("extras").' />';
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ Returns a string filtered to allow only digits, spaces, and these special charac
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
if ($value =~ /^[\d\s\-\+\(\)]+$/) {
|
||||
return $value;
|
||||
}
|
||||
|
|
@ -95,8 +95,8 @@ Renders a phone number field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789-()+ \')" ';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onkeyup="doInputCheck(this.form.'.$self->get("name").',\'0123456789-()+ \')" ';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,10 +97,10 @@ Renders and input tag of type radio.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
|
||||
my $checkedText = ' checked="checked"' if ($self->{checked});
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value"))));
|
||||
my $checkedText = ' checked="checked"' if ($self->get("checked"));
|
||||
my $idText = ' id="'.$self->{id}.'" ' if ($self->{id});
|
||||
return '<input type="radio" name="'.$self->{name}.'" value="'.$value.'"'.$idText.$checkedText.' '.$self->{extras}.' />';
|
||||
return '<input type="radio" name="'.$self->get("name").'" value="'.$value.'"'.$idText.$checkedText.' '.$self->get("extras").' />';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -104,16 +104,16 @@ sub toHtml {
|
|||
%options = $self->orderedHash;
|
||||
foreach my $key (keys %options) {
|
||||
my $checked = 0;
|
||||
if ($self->{value} eq $key) {
|
||||
if ($self->get("value") eq $key) {
|
||||
$checked = 1;
|
||||
}
|
||||
$output .= WebGUI::Form::Radio->new({
|
||||
name=>$self->{name},
|
||||
name=>$self->get("name"),
|
||||
value=>$key,
|
||||
extras=>$self->{extras},
|
||||
extras=>$self->get("extras"),
|
||||
checked=>$checked
|
||||
})->toHtml;
|
||||
$output .= ${$self->{options}}{$key} . $alignment;
|
||||
$output .= ${$self->get("options}"){$key} . $alignment;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ Renders the value.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
return $self->{value};
|
||||
return $self->get("value");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -94,11 +94,11 @@ Retrieves a value from a form GET or POST and returns it. If the value comes bac
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $formValue = $session{req}->param($self->{name});
|
||||
my $formValue = $self->session->request->param($self->get("name"));
|
||||
if (defined $formValue) {
|
||||
return $formValue;
|
||||
} else {
|
||||
return $self->{defaultValue};
|
||||
return $self->get("defaultValue");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ Renders a select list form control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $output = '<select name="'.$self->{name}.'" size="'.$self->{size}.'" id="'.$self->{id}.'" '.$self->{extras}.'>';
|
||||
my $output = '<select name="'.$self->get("name").'" size="'.$self->get("size").'" id="'.$self->{id}.'" '.$self->get("extras").'>';
|
||||
my %options;
|
||||
tie %options, 'Tie::IxHash';
|
||||
%options = $self->orderedHash;
|
||||
|
|
@ -122,7 +122,7 @@ sub toHtml {
|
|||
if ($value eq $key) {
|
||||
$output .= ' selected="selected"';
|
||||
}
|
||||
$output .= '>'.${$self->{options}}{$key}.'</option>';
|
||||
$output .= '>'.${$self->get("options}"){$key}.'</option>';
|
||||
}
|
||||
$output .= '</select>'."\n";
|
||||
return $output;
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ Renders a select list form control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $multiple = ' multiple="1"' if ($self->{multiple});
|
||||
my $output = '<select name="'.$self->{name}.'" size="'.$self->{size}.'" id="'.$self->{id}.'" '.$self->{extras}.$multiple.'>';
|
||||
my $multiple = ' multiple="1"' if ($self->get("multiple"));
|
||||
my $output = '<select name="'.$self->get("name").'" size="'.$self->get("size").'" id="'.$self->{id}.'" '.$self->get("extras").$multiple.'>';
|
||||
my %options;
|
||||
tie %options, 'Tie::IxHash';
|
||||
%options = $self->orderedHash;
|
||||
|
|
@ -104,7 +104,7 @@ sub toHtml {
|
|||
$output .= ' selected="selected"';
|
||||
}
|
||||
}
|
||||
$output .= '>'.${$self->{options}}{$key}.'</option>';
|
||||
$output .= '>'.${$self->get("options}"){$key}.'</option>';
|
||||
}
|
||||
$output .= '</select>'."\n";
|
||||
return $output;
|
||||
|
|
|
|||
|
|
@ -66,12 +66,12 @@ Renders a button.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixQuotes($self->{value});
|
||||
$self->{extras} ||= 'onclick="this.value=\''.WebGUI::International::get(452).'\'"';
|
||||
my $value = $self->fixQuotes($self->get("value"));
|
||||
$self->get("extras") ||= 'onclick="this.value=\''.WebGUI::International::get(452).'\'"';
|
||||
my $html = '<input type="submit" ';
|
||||
$html .= 'name="'.$self->{name}.'" ' if ($self->{name});
|
||||
$html .= 'name="'.$self->get("name").'" ' if ($self->get("name"));
|
||||
$html .= 'id="'.$self->{id}.'" ' unless ($self->{id} eq "_formId");
|
||||
$html .= 'value="'.$value.'" '.$self->{extras}.' />';
|
||||
$html .= 'value="'.$value.'" '.$self->get("extras").' />';
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,15 +94,15 @@ Renders a template picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $templateList = WebGUI::Asset::Template->getList($self->{namespace});
|
||||
my $templateList = WebGUI::Asset::Template->getList($self->get("namespace"));
|
||||
#Remove entries from template list that the user does not have permission to view.
|
||||
for my $assetId ( keys %{$templateList} ) {
|
||||
my $asset = WebGUI::Asset::Template->new($assetId);
|
||||
if (!$asset->canView($session{user}{userId})) {
|
||||
if (!$asset->canView($self->session->user->profileField("userId"))) {
|
||||
delete $templateList->{$assetId};
|
||||
}
|
||||
}
|
||||
$self->{options} = $templateList;
|
||||
$self->get("options") = $templateList;
|
||||
$self->setManageIcons();
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
|
@ -132,15 +132,15 @@ editing the template show up if the user is allowed to do that.
|
|||
|
||||
sub setManageIcons {
|
||||
my $self = shift;
|
||||
my $template = WebGUI::Asset::Template->new($self->{value});
|
||||
my $template = WebGUI::Asset::Template->new($self->get("value"));
|
||||
if (defined $template && $template->canEdit) {
|
||||
my $returnUrl;
|
||||
if (exists $session{asset}) {
|
||||
$returnUrl = ";proceed=goBackToPage;returnUrl=".WebGUI::URL::escape($session{asset}->getUrl);
|
||||
if (exists $self->session->asset) {
|
||||
$returnUrl = ";proceed=goBackToPage;returnUrl=".WebGUI::URL::escape($self->session->asset->getUrl);
|
||||
}
|
||||
my $buttons = editIcon("func=edit".$returnUrl,$template->get("url"));
|
||||
$buttons .= manageIcon("func=manageAssets",$template->getParent->get("url"));
|
||||
$self->{subtext} = $buttons . $self->{subtext};
|
||||
$self->get("subtext") = $buttons . $self->get("subtext");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ sub definition {
|
|||
defaultValue=> 255
|
||||
},
|
||||
size=>{
|
||||
defaultValue=>$session{setting}{textBoxSize} || 30
|
||||
defaultValue=>$self->session->setting->get("textBoxSize") || 30
|
||||
},
|
||||
profileEnabled=>{
|
||||
defaultValue=>1
|
||||
|
|
@ -91,8 +91,8 @@ Renders an input tag of type text.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->{value})));
|
||||
return '<input id="'.$self->{id}.'" type="text" name="'.$self->{name}.'" value="'.$value.'" size="'.$self->{size}.'" maxlength="'.$self->{maxlength}.'" '.$self->{extras}.' />';
|
||||
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->get("value"))));
|
||||
return '<input id="'.$self->{id}.'" type="text" name="'.$self->get("name").'" value="'.$value.'" size="'.$self->get("size").'" maxlength="'.$self->get("maxlength").'" '.$self->get("extras").' />';
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ sub definition {
|
|||
defaultValue=>WebGUI::International::get("476","WebGUI")
|
||||
},
|
||||
rows=>{
|
||||
defaultValue=> $session{setting}{textAreaRows} || 5
|
||||
defaultValue=> $self->session->setting->get("textAreaRows") || 5
|
||||
},
|
||||
columns=>{
|
||||
defaultValue=> $session{setting}{textAreaCols} || 50
|
||||
defaultValue=> $self->session->setting->get("textAreaCols") || 50
|
||||
},
|
||||
wrap=>{
|
||||
defaultValue=>"virtual"
|
||||
|
|
@ -98,9 +98,9 @@ Renders an input tag of type text.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = $self->fixMacros($self->fixTags($self->fixSpecialCharacters($self->{value})));
|
||||
return '<textarea id="'.$self->{id}.'" name="'.$self->{name}.'" cols="'.$self->{columns}.'" rows="'.$self->{rows}.'" wrap="'.
|
||||
$self->{wrap}.'" '.$self->{extras}.'>'.$value.'</textarea>';
|
||||
my $value = $self->fixMacros($self->fixTags($self->fixSpecialCharacters($self->get("value"))));
|
||||
return '<textarea id="'.$self->{id}.'" name="'.$self->get("name").'" cols="'.$self->get("columns").'" rows="'.$self->get("rows").'" wrap="'.
|
||||
$self->get("wrap").'" '.$self->get("extras").'>'.$value.'</textarea>';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ Returns the number of seconds since 00:00:00 on a 24 hour clock. Note, this will
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
return WebGUI::DateTime::timeToSeconds($session{req}->param($self->{name}))-($session{user}{timeOffset}*3600);
|
||||
return WebGUI::DateTime::timeToSeconds($self->session->request->param($self->get("name")))-($self->session->user->profileField("timeOffset")*3600);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -108,13 +108,13 @@ Renders a time field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
my $value = WebGUI::DateTime::secondsToTime($self->{value});
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789:\')"';
|
||||
my $value = WebGUI::DateTime::secondsToTime($self->get("value"));
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onkeyup="doInputCheck(this.form.'.$self->get("name").',\'0123456789:\')"';
|
||||
return $self->SUPER::toHtml
|
||||
.WebGUI::Form::Button->new(
|
||||
id=>$self->{id},
|
||||
extras=>'style="font-size: 8pt;" onclick="window.timeField = this.form.'.$self->{name}.';clockSet = window.open(\''.$session{config}{extrasURL}. '/timeChooser.html\',\'timeChooser\',\'WIDTH=230,HEIGHT=100\');return false"',
|
||||
extras=>'style="font-size: 8pt;" onclick="window.timeField = this.form.'.$self->get("name").';clockSet = window.open(\''.$self->session->config->get("extrasURL"). '/timeChooser.html\',\'timeChooser\',\'WIDTH=230,HEIGHT=100\');return false"',
|
||||
value=>WebGUI::International::get(970)
|
||||
)->toHtml;
|
||||
}
|
||||
|
|
@ -130,8 +130,8 @@ Renders the field as a hidden field.
|
|||
sub toHtmlAsHidden {
|
||||
my $self = shift;
|
||||
return WebGUI::Form::Hidden->new(
|
||||
name=>$self->{name},
|
||||
value=>secondsToTime($self->{value})
|
||||
name=>$self->get("name"),
|
||||
value=>secondsToTime($self->get("value"))
|
||||
)->toHtmlAsHidden;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ Renders a database connection picker control.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
$self->{options} = WebGUI::DateTime::getTimeZones();
|
||||
$self->get("options") = WebGUI::DateTime::getTimeZones();
|
||||
return $self->SUPER::toHtml();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ Parses the posted value and tries to make corrections if necessary.
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
if ($value =~ /mailto:/) {
|
||||
return $value;
|
||||
} elsif ($value =~ /^([A-Z0-9]+[._+-]?){1,}([A-Z0-9]+[_+-]?)+\@(([A-Z0-9]+[._-]?){1,}[A-Z0-9]+\.){1,}[A-Z]{2,4}$/i) {
|
||||
|
|
@ -106,8 +106,8 @@ Renders a URL field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/addHTTP.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onBlur="addHTTP(this.form.'.$self->{name}.')"';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/addHTTP.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onBlur="addHTTP(this.form.'.$self->get("name").')"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ Returns either a 1 or 0 representing yes, no.
|
|||
|
||||
sub yesNo {
|
||||
my $self = shift;
|
||||
if ($session{req}->param($self->{name}) > 0) {
|
||||
if ($self->session->request->param($self->get("name")) > 0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -102,24 +102,24 @@ Renders a yes/no question field.
|
|||
sub toHtml {
|
||||
my $self = shift;
|
||||
my ($checkYes, $checkNo);
|
||||
if ($self->{value}) {
|
||||
if ($self->get("value")) {
|
||||
$checkYes = 1;
|
||||
} else {
|
||||
$checkNo = 1;
|
||||
}
|
||||
my $output = WebGUI::Form::Radio->new(
|
||||
checked=>$checkYes,
|
||||
name=>$self->{name},
|
||||
name=>$self->get("name"),
|
||||
value=>1,
|
||||
extras=>$self->{extras}
|
||||
extras=>$self->get("extras")
|
||||
)->toHtml;
|
||||
$output .= WebGUI::International::get(138);
|
||||
$output .= ' ';
|
||||
$output .= WebGUI::Form::Radio->new(
|
||||
checked=>$checkNo,
|
||||
name=>$self->{name},
|
||||
name=>$self->get("name"),
|
||||
value=>0,
|
||||
extras=>$self->{extras}
|
||||
extras=>$self->get("extras")
|
||||
)->toHtml;
|
||||
$output .= WebGUI::International::get(139);
|
||||
return $output;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ Returns a validated form post result. If the result does not pass validation, it
|
|||
|
||||
sub getValueFromPost {
|
||||
my $self = shift;
|
||||
my $value = $session{req}->param($self->{name});
|
||||
my $value = $self->session->request->param($self->get("name"));
|
||||
if ($value =~ /^[A-Z\d\s\-]+$/) {
|
||||
return $value;
|
||||
}
|
||||
|
|
@ -102,8 +102,8 @@ Renders a zip code field.
|
|||
|
||||
sub toHtml {
|
||||
my $self = shift;
|
||||
WebGUI::Style::setScript($session{config}{extrasURL}.'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->{extras} .= ' onkeyup="doInputCheck(this.form.'.$self->{name}.',\'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- \')"';
|
||||
WebGUI::Style::setScript($self->session->config->get("extrasURL").'/inputCheck.js',{ type=>'text/javascript' });
|
||||
$self->get("extras") .= ' onkeyup="doInputCheck(this.form.'.$self->get("name").',\'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- \')"';
|
||||
return $self->SUPER::toHtml;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,13 +30,16 @@ This is a convenience package to the individual form controls. It allows you to
|
|||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::FormProcessor;
|
||||
$value = WebGUI::FormProcessor::process("favoriteColor","selectList","black");
|
||||
|
||||
$value = WebGUI::FormProcessor::someFormControlType("fieldName");
|
||||
my $fp = WebGUI::FormProcessor->new($session);
|
||||
|
||||
$value = $fp->process("favoriteColor", "selectList", "black");
|
||||
|
||||
$value = $fp->someFormControlType("fieldName");
|
||||
|
||||
Example:
|
||||
|
||||
$value WebGUI::FormProcessor::text("title");
|
||||
$value = $fp->text("title");
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
|
|
@ -55,20 +58,40 @@ Dynamically creates functions on the fly for all the different form control type
|
|||
|
||||
sub AUTOLOAD {
|
||||
our $AUTOLOAD;
|
||||
my $self = shift;
|
||||
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
|
||||
my $fieldName = shift;
|
||||
my $cmd = "use WebGUI::Form::".$name;
|
||||
eval ($cmd);
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
$self->session->errorHandler->error("Couldn't compile form control: ".$name.". Root cause: ".$@);
|
||||
return undef;
|
||||
}
|
||||
my $class = "WebGUI::Form::".$name;
|
||||
return $class->new({name=>$fieldName})->getValueFromPost;
|
||||
return $class->new($self->session, {name=>$fieldName})->getValueFromPost;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
bless {_session=>$session}, $class;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( name, type [ , default ] )
|
||||
|
|
@ -90,12 +113,11 @@ The default value for this variable. If the variable is undefined then the defau
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
|
||||
my ($name, $type, $default) = @_;
|
||||
my ($self, $name, $type, $default) = @_;
|
||||
my $value;
|
||||
$type = ucfirst($type);
|
||||
$type = "Text" if ($type eq "");
|
||||
$value = &$type($name);
|
||||
$value = $self->$type($self->session,$name);
|
||||
unless (defined $value) {
|
||||
return $default;
|
||||
}
|
||||
|
|
@ -105,6 +127,16 @@ sub process {
|
|||
return $value;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session
|
||||
|
||||
=cut
|
||||
|
||||
sub session
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -33,21 +33,23 @@ This package allows the manipulation of HTTP protocol information.
|
|||
|
||||
use WebGUI::HTTP;
|
||||
|
||||
$cookies = WebGUI::HTTP::getCookies();
|
||||
$header = WebGUI::HTTP::getHeader();
|
||||
$mimetype = WebGUI::HTTP::getMimeType();
|
||||
$code = WebGUI::HTTP::getStatus();
|
||||
$boolean = WebGUI::HTTP::isRedirect();
|
||||
my $http = WebGUI::HTTP->new($session);
|
||||
|
||||
$cookies = $http->getCookies();
|
||||
$header = $http->getHeader();
|
||||
$mimetype = $http->getMimeType();
|
||||
$code = $http->getStatus();
|
||||
$boolean = $http->isRedirect();
|
||||
|
||||
WebGUI::HTTP::setCookie($name,$value);
|
||||
WebGUI::HTTP::setFilename($filename,$mimetype);
|
||||
WebGUI::HTTP::setMimeType($mimetype);
|
||||
WebGUI::HTTP::setNoHeader($bool);
|
||||
WebGUI::HTTP::setRedirect($url);
|
||||
$http->setCookie($name,$value);
|
||||
$http->setFilename($filename,$mimetype);
|
||||
$http->setMimeType($mimetype);
|
||||
$http->setNoHeader($bool);
|
||||
$http->setRedirect($url);
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These subroutines are available from this package:
|
||||
These methods are available from this package:
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -62,7 +64,8 @@ Retrieves the cookies from the HTTP header and returns a hash reference containi
|
|||
=cut
|
||||
|
||||
sub getCookies {
|
||||
return APR::Request::Apache2->handle($session{req})->jar();
|
||||
my $self = shift;
|
||||
return APR::Request::Apache2->handle($self->session->request)->jar();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -75,22 +78,23 @@ Generates an HTTP header.
|
|||
=cut
|
||||
|
||||
sub getHeader {
|
||||
return undef if ($session{http}{noHeader});
|
||||
my $self = shift;
|
||||
return undef if ($self->{_http}{noHeader});
|
||||
my %params;
|
||||
if (isRedirect()) {
|
||||
$session{req}->headers_out->set(Location => $session{http}{location});
|
||||
$session{req}->status(301);
|
||||
if ($self->isRedirect()) {
|
||||
$self->session->request->headers_out->set(Location => $self->{_http}{location});
|
||||
$self->session->request->status(301);
|
||||
} else {
|
||||
$session{req}->content_type($session{http}{mimetype} || "text/html");
|
||||
if ($session{setting}{preventProxyCache}) {
|
||||
$self->session->request->content_type($self->{_http}{mimetype} || "text/html");
|
||||
if ($self->session->setting->get("preventProxyCache")) {
|
||||
$params{"-expires"} = "-1d";
|
||||
}
|
||||
if ($session{http}{filename}) {
|
||||
$params{"-attachment"} = $session{http}{filename};
|
||||
$params{"-attachment"} = $self->{_http}{filename};
|
||||
}
|
||||
}
|
||||
$params{"-cookie"} = $session{http}{cookie};
|
||||
$session{req}->status_line(getStatus().' '.$session{http}{statusDescription}) if $session{req};
|
||||
$params{"-cookie"} = $self->{_http}{cookie};
|
||||
$self->session->request->status_line($self->getStatus().' '.$self->{_http}{statusDescription}) if $self->session->request;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +108,8 @@ Returns the current mime type of the document to be returned.
|
|||
=cut
|
||||
|
||||
sub getMimeType {
|
||||
return $session{http}{mimetype} || "text/html";
|
||||
my $self = shift;
|
||||
return $self->{_http}{mimetype} || "text/html";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -117,8 +122,9 @@ Returns the current HTTP status code, if one has been set.
|
|||
=cut
|
||||
|
||||
sub getStatus {
|
||||
$session{http}{statusDescription} = $session{http}{statusDescription} || "OK";
|
||||
return $session{http}{status} || "200";
|
||||
my $self = shift;
|
||||
$self->{_http}{statusDescription} = $self->{_http}{statusDescription} || "OK";
|
||||
return $self->{_http}{status} || "200";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -131,7 +137,41 @@ Returns a boolean value indicating whether the current page will redirect to som
|
|||
=cut
|
||||
|
||||
sub isRedirect {
|
||||
return (getStatus() eq "302");
|
||||
my $self = shift;
|
||||
return ($self->getStatus() eq "302");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
bless {_session=>$session}, $class;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns the reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -155,19 +195,20 @@ The time that the cookie should remain in the browser. Defaults to "+10y" (10 ye
|
|||
=cut
|
||||
|
||||
sub setCookie {
|
||||
my $self = shift;
|
||||
my $name = shift;
|
||||
my $value = shift;
|
||||
my $ttl = shift;
|
||||
$ttl = (defined $ttl ? $ttl : '+10y');
|
||||
if (exists $session{req}) {
|
||||
my $cookie = Apache2::Cookie->new($session{req},
|
||||
if (exists $self->session->request) {
|
||||
my $cookie = Apache2::Cookie->new($self->session->request,
|
||||
-name=>$name,
|
||||
-value=>$value,
|
||||
# -domain=>'.'.$session{env}{HTTP_HOST},
|
||||
-expires=>$ttl,
|
||||
-path=>'/'
|
||||
);
|
||||
$cookie->bake($session{req});
|
||||
$cookie->bake($self->session->request);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,9 +230,10 @@ The mimetype for this file. Defaults to "application/octet-stream".
|
|||
=cut
|
||||
|
||||
sub setFilename {
|
||||
$session{http}{filename} = shift;
|
||||
my $self = shift;
|
||||
$self->{_http}{filename} = shift;
|
||||
my $mimetype = shift || "application/octet-stream";
|
||||
setMimeType($mimetype);
|
||||
$self->setMimeType($mimetype);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -211,7 +253,8 @@ The mime type for the document.
|
|||
=cut
|
||||
|
||||
sub setMimeType {
|
||||
$session{http}{mimetype} = shift;
|
||||
my $self = shift;
|
||||
$self->{_http}{mimetype} = shift;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -228,7 +271,8 @@ Any value other than 0 will disable header printing.
|
|||
=cut
|
||||
|
||||
sub setNoHeader {
|
||||
$session{http}{noHeader} = shift;
|
||||
my $self = shift;
|
||||
$self->{_http}{noHeader} = shift;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -244,9 +288,10 @@ The URL to redirect to.
|
|||
=cut
|
||||
|
||||
sub setRedirect {
|
||||
$session{http}{location} = shift;
|
||||
setStatus("302", "Redirect");
|
||||
WebGUI::Style::setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$session{http}{location}});
|
||||
my $self = shift;
|
||||
$self->{_http}{location} = shift;
|
||||
$self->setStatus("302", "Redirect");
|
||||
$self->session->style->setMeta({"http-equiv"=>"refresh",content=>"0; URL=".$self->{_http}{location}});
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -267,8 +312,10 @@ An HTTP status code description. It is a little one line of text that describes
|
|||
=cut
|
||||
|
||||
sub setStatus {
|
||||
$session{http}{status} = shift;
|
||||
$session{http}{statusDescription} = shift;
|
||||
my $self = shift;
|
||||
$self->{_http}{status} = shift;
|
||||
$self->{_http}{statusDescription} = shift;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ package WebGUI::Macro;
|
|||
|
||||
|
||||
use strict qw(vars subs);
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Session;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -105,10 +103,14 @@ sub negate {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( html )
|
||||
=head2 process ( session, html )
|
||||
|
||||
Runs all the WebGUI macros to and replaces them in the HTML with their output.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 html
|
||||
|
||||
A scalar reference of HTML to be processed.
|
||||
|
|
@ -116,6 +118,7 @@ A scalar reference of HTML to be processed.
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $content = shift;
|
||||
while ($$content =~ /$nestedMacro/gs) {
|
||||
my ($macro, $searchString, $params) = ($1, $2, $3);
|
||||
|
|
@ -125,11 +128,12 @@ sub process {
|
|||
$params =~ s/(^\(|\)$)//g; # remove parenthesis
|
||||
&process(\$params); # recursive process params
|
||||
}
|
||||
if ($WebGUI::Session::session{config}{macros}{$searchString} ne "") {
|
||||
my $cmd = "WebGUI::Macro::".$WebGUI::Session::session{config}{macros}{$searchString};
|
||||
my $macros = $session->config->get("macros");
|
||||
if ($macros->{$searchString} ne "") {
|
||||
my $cmd = "WebGUI::Macro::".$macros->{$searchString};
|
||||
my $load = "use ".$cmd;
|
||||
eval($load);
|
||||
WebGUI::ErrorHandler::error("Macro failed to compile: $cmd.".$@) if($@);
|
||||
$session->errorHandler->error("Macro failed to compile: $cmd.".$@) if($@);
|
||||
my @param;
|
||||
push(@param, $+) while $params =~ m {
|
||||
"([^\"\\]*(?:\\.[^\"\\]*)*)",?
|
||||
|
|
@ -138,13 +142,13 @@ sub process {
|
|||
}gx;
|
||||
push(@param, undef) if substr($params,-1,1) eq ',';
|
||||
$cmd = $cmd."::process";
|
||||
my $result = eval{&$cmd(@param)};
|
||||
my $result = eval{&$cmd($session,@param)};
|
||||
if ($@) {
|
||||
WebGUI::ErrorHandler::error("Processing failed on macro: $macro: ".$@);
|
||||
$session->errorHandler->error("Processing failed on macro: $macro: ".$@);
|
||||
} else {
|
||||
if ($result =~ /\Q$macro/) {
|
||||
$result = "Endless macro loop detected. Stopping recursion.";
|
||||
WebGUI::ErrorHandler::warn($macro." : ".$result)
|
||||
$session->errorHandler->warn($macro." : ".$result)
|
||||
}
|
||||
$$content =~ s/\Q$macro/$result/ges;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::AOIHits;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -37,16 +35,15 @@ The value for the key that will be looked up.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my (@param, $temp);
|
||||
@param = @_;
|
||||
my $key = $param[0];
|
||||
my $value = $param[1];
|
||||
my $session = shift;
|
||||
my $key = shift;
|
||||
my $value = shift;
|
||||
my $sql = "select count from passiveProfileAOI a, metaData_properties f
|
||||
where a.fieldId=f.fieldId
|
||||
and userId=".quote($session{user}{userId})."
|
||||
and fieldName=".quote($key)."
|
||||
and value=".quote($value);
|
||||
my ($count) = WebGUI::SQL->buildArray($sql);
|
||||
and userId=".$session->db->$session->db->quote($session->user->userId)."
|
||||
and fieldName=".$session->db->$session->db->quote($key)."
|
||||
and value=".$session->db->$session->db->quote($value);
|
||||
my ($count) = $session->db->buildArray($sql);
|
||||
return $count;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::AOIRank;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -37,16 +35,15 @@ Define which value, by it's ranking, will be displayed. The highest ranking is
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my (@param, $temp);
|
||||
@param = @_;
|
||||
my $key = $param[0];
|
||||
my $rank = $param[1] || 1; # 1 is highest rank
|
||||
my $session = shift;
|
||||
my $key = shift;
|
||||
my $rank = shift || 1; # 1 is highest rank
|
||||
$rank--; # Rank is zero based
|
||||
my $sql = "select value from passiveProfileAOI a, metaData_properties f
|
||||
where a.fieldId=f.fieldId
|
||||
and userId=".quote($session{user}{userId})."
|
||||
and fieldName=".quote($key)." order by a.count desc";
|
||||
my @values = WebGUI::SQL->buildArray($sql);
|
||||
and userId=".$session->db->$session->db->quote($session->user->userId)."
|
||||
and fieldName=".$session->db->$session->db->quote($key)." order by a.count desc";
|
||||
my @values = $session->db->buildArray($sql);
|
||||
return $values[$rank];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,9 +18,6 @@ use WebGUI::Asset;
|
|||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -45,7 +42,8 @@ Admin bar to the left of the screen.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return "" unless ($session{var}{adminOn});
|
||||
my $session = shift;
|
||||
return "" unless ($session->var->isAdminOn);
|
||||
my @param = @_;
|
||||
my $templateId = $param[0] || "PBtmpl0000000000000090";
|
||||
my %var;
|
||||
|
|
@ -53,29 +51,29 @@ sub process {
|
|||
tie %hash, "Tie::IxHash";
|
||||
tie %hash2, "Tie::IxHash";
|
||||
tie %cphash, "Tie::CPHash";
|
||||
$var{'packages.canAdd'} = ($session{user}{uiLevel} >= 7);
|
||||
$var{'packages.canAdd'} = ($session->user->profileField("uiLevel") >= 7);
|
||||
$var{'packages.label'} = WebGUI::International::get(376,'Macro_AdminBar');
|
||||
$var{'contentTypes.label'} = WebGUI::International::get(1083,'Macro_AdminBar');
|
||||
$var{'clipboard.label'} = WebGUI::International::get(1082,'Macro_AdminBar');
|
||||
if (exists $session{asset}) {
|
||||
foreach my $package (@{$session{asset}->getPackageList}) {
|
||||
if ($session->asset) {
|
||||
foreach my $package (@{$session->asset->getPackageList}) {
|
||||
my $title = $package->getTitle;
|
||||
$title =~ s/'//g; # stops it from breaking the javascript menus
|
||||
push(@{$var{'package_loop'}},{
|
||||
'url'=>$session{asset}->getUrl("func=deployPackage;assetId=".$package->getId),
|
||||
'url'=>$session->asset->getUrl("func=deployPackage;assetId=".$package->getId),
|
||||
'label'=>$title,
|
||||
'icon.small'=>$package->getIcon(1),
|
||||
'icon'=>$package->getIcon()
|
||||
});
|
||||
}
|
||||
$var{contentTypes_loop} = $session{asset}->getAssetAdderLinks;
|
||||
$var{container_loop} = $session{asset}->getAssetAdderLinks(undef,"assetContainers");
|
||||
foreach my $asset (@{$session{asset}->getAssetsInClipboard(1)}) {
|
||||
$var{contentTypes_loop} = $session->asset->getAssetAdderLinks;
|
||||
$var{container_loop} = $session->asset->getAssetAdderLinks(undef,"assetContainers");
|
||||
foreach my $asset (@{$session->asset->getAssetsInClipboard(1)}) {
|
||||
my $title = $asset->getTitle;
|
||||
$title =~ s/'//g; # stops it from breaking the javascript menus
|
||||
push(@{$var{clipboard_loop}}, {
|
||||
'label'=>$title,
|
||||
'url'=>$session{asset}->getUrl("func=paste;assetId=".$asset->getId),
|
||||
'url'=>$session->asset->getUrl("func=paste;assetId=".$asset->getId),
|
||||
'icon.small'=>$asset->getIcon(1),
|
||||
'icon'=>$asset->getIcon()
|
||||
});
|
||||
|
|
@ -83,7 +81,7 @@ sub process {
|
|||
}
|
||||
#--admin functions
|
||||
$var{adminConsole_loop} = WebGUI::AdminConsole->getAdminFunction;
|
||||
return WebGUI::Asset::Template->new($templateId)->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,$templateId)->process(\%var);
|
||||
# 'http://validator.w3.org/check?uri=referer'=>WebGUI::International::get(399,'Macro_AdminBar'),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::AdminText;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -31,9 +30,10 @@ string is returned.
|
|||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my @param = @_;
|
||||
return "" unless ($session{var}{adminOn});
|
||||
return "" unless ($session->var->get("adminOn"));
|
||||
return $param[0];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ package WebGUI::Macro::AdminToggle;
|
|||
use strict;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -48,6 +46,7 @@ A template from the Macro/AdminToggle namespace to use for formatting the link.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
if (WebGUI::Grouping::isInGroup(12)) {
|
||||
my %var;
|
||||
my ($turnOn,$turnOff,$templateName) = @_;
|
||||
|
|
@ -61,9 +60,9 @@ sub process {
|
|||
$var{'toggle.text'} = $turnOn;
|
||||
}
|
||||
if ($templateName) {
|
||||
return WebGUI::Asset::Template->newByUrl($templateName)->process(\%var);
|
||||
return WebGUI::Asset::Template->newByUrl($session,$templateName)->process(\%var);
|
||||
} else {
|
||||
return WebGUI::Asset::Template->new("PBtmpl0000000000000036")->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,"PBtmpl0000000000000036")->process(\%var);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ package WebGUI::Macro::AssetProxy;
|
|||
use strict;
|
||||
use Time::HiRes;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::International;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -39,14 +37,15 @@ Admin is turned on.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $t = [Time::HiRes::gettimeofday()] if (WebGUI::ErrorHandler::canShowPerformanceIndicators());
|
||||
my $asset = WebGUI::Asset->newByUrl($url);
|
||||
my $t = [Time::HiRes::gettimeofday()] if ($session->errorHandler->canShowPerformanceIndicators());
|
||||
my $asset = WebGUI::Asset->newByUrl($session,$url);
|
||||
#Sorry, you cannot proxy the notfound page.
|
||||
if (defined $asset && $asset->getId ne $session{setting}{notFoundPage}) {
|
||||
if (defined $asset && $asset->getId ne $session->setting->get("notFoundPage")) {
|
||||
$asset->toggleToolbar;
|
||||
my $output = $asset->canView ? $asset->view : undef;
|
||||
$output .= "AssetProxy:".Time::HiRes::tv_interval($t) if (WebGUI::ErrorHandler::canShowPerformanceIndicators());
|
||||
$output .= "AssetProxy:".Time::HiRes::tv_interval($t) if ($session->errorHandler->canShowPerformanceIndicators());
|
||||
return $output;
|
||||
} else {
|
||||
return WebGUI::International::get('invalid url', 'Macro_AssetProxy');
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::At_username;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -27,7 +26,8 @@ Macro for displaying the current User's username.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return $session{user}{username};
|
||||
my $session = shift;
|
||||
return $session->user->profileField("username");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::CanEditText;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -34,8 +33,9 @@ this asset, an empty string will be returned.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my @param = @_;
|
||||
if (exists $session{asset} && $session{asset}->canEdit) {
|
||||
if ($session->asset && $session->asset->canEdit) {
|
||||
return $param[0];
|
||||
} else {
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ time is used instead.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my (@param, $temp, $time);
|
||||
@param = @_;
|
||||
$time = $param[1] || time();
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ package WebGUI::Macro::EditableToggle;
|
|||
use strict;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -51,12 +49,13 @@ A template from the Macro/EditableToggle namespace to use for formatting the lin
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
if (exists $session{asset} && $session{asset}->canEdit && WebGUI::Grouping::isInGroup(12)) {
|
||||
my $session = shift;
|
||||
if (exists $session->asset && $session->asset->canEdit && WebGUI::Grouping::isInGroup(12)) {
|
||||
my %var;
|
||||
my @param = @_;
|
||||
my $turnOn = $param[0] || WebGUI::International::get(516,'Macro_EditableToggle');
|
||||
my $turnOff = $param[1] || WebGUI::International::get(517,'Macro_EditableToggle');
|
||||
if ($session{var}{adminOn}) {
|
||||
if ($session->var->get("adminOn")) {
|
||||
$var{'toggle.url'} = WebGUI::URL::page('op=switchOffAdmin');
|
||||
$var{'toggle.text'} = $turnOff;
|
||||
} else {
|
||||
|
|
@ -64,9 +63,9 @@ sub process {
|
|||
$var{'toggle.text'} = $turnOn;
|
||||
}
|
||||
if ($param[2]) {
|
||||
return WebGUI::Asset::Template->newByUrl($param[2])->process(\%var);
|
||||
return WebGUI::Asset::Template->newByUrl($session,$param[2])->process(\%var);
|
||||
} else {
|
||||
return WebGUI::Asset::Template->new("PBtmpl0000000000000038")->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,"PBtmpl0000000000000038")->process(\%var);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::Env;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -32,7 +31,8 @@ then undef will be returned.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return $session{env}{shift};
|
||||
my $session = shift;
|
||||
return $session->env->get(shift);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ be blocked and an error message returned instead.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my @param = @_;
|
||||
if ($param[0] =~ /passwd/ || $param[0] =~ /shadow/ || $param[0] =~ /\.conf/) {
|
||||
return WebGUI::International::get('execute error', 'Macro_Execute');
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::Extras;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -30,7 +29,8 @@ Returns the extrasURL. A trailing slash '/' is appended to the URL.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return $session{config}{extrasURL}."/";
|
||||
my $session = shift;
|
||||
return $session->config->get("extrasURL")."/";
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::FetchMimeType; # edit this line to match your own macro n
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use LWP::MediaTypes qw(guess_media_type);
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -36,6 +35,7 @@ A path to a file
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $path = shift;
|
||||
return guess_media_type($path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ package WebGUI::Macro::FileUrl;
|
|||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::International;
|
||||
|
||||
|
|
@ -41,8 +40,9 @@ The URL to the Asset.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $asset = WebGUI::Asset->newByUrl($url);
|
||||
my $asset = WebGUI::Asset->newByUrl($session,$url);
|
||||
if (defined $asset) {
|
||||
my $storage = WebGUI::Storage->get($asset->get("storageId"));
|
||||
return $storage->getUrl($asset->get("filename"));
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::FormParam;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -33,7 +32,8 @@ The name of the field to pull from the session variable.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return $session{req}->param(shift) if ($session{req});
|
||||
my $session = shift;
|
||||
return $session->form->process(shift);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ package WebGUI::Macro::GroupAdd;
|
|||
use strict;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -47,9 +45,10 @@ An optional template for formatting the text and link.
|
|||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my @param = @_;
|
||||
my $session = shift;
|
||||
return "" if ($param[0] eq "");
|
||||
return "" if ($param[1] eq "");
|
||||
return "" if ($session{user}{userId} eq '1');
|
||||
return "" if ($session->user->userId eq '1');
|
||||
my $g = WebGUI::Group->find($param[0]);
|
||||
return "" if ($g->groupId eq "");
|
||||
return "" unless ($g->autoAdd);
|
||||
|
|
@ -58,9 +57,9 @@ sub process {
|
|||
$var{'group.url'} = WebGUI::URL::page("op=autoAddToGroup;groupId=".$g->groupId);
|
||||
$var{'group.text'} = $param[1];
|
||||
if ($param[2]) {
|
||||
return WebGUI::Asset::Template->newByUrl($param[2])->process(\%var);
|
||||
return WebGUI::Asset::Template->newByUrl($session,$param[2])->process(\%var);
|
||||
} else {
|
||||
return WebGUI::Asset::Template->new("PBtmpl0000000000000040")->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,"PBtmpl0000000000000040")->process(\%var);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ package WebGUI::Macro::GroupDelete;
|
|||
use strict;
|
||||
use WebGUI::Group;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -46,10 +44,11 @@ An optional template for formatting the text and link.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my @param = @_;
|
||||
return "" if ($param[0] eq "");
|
||||
return "" if ($param[1] eq "");
|
||||
return "" if ($session{user}{userId} eq '1');
|
||||
return "" if ($session->user->userId eq '1');
|
||||
my $g = WebGUI::Group->find($param[0]);
|
||||
return "" if ($g->groupId eq "");
|
||||
return "" unless ($g->autoDelete);
|
||||
|
|
@ -58,9 +57,9 @@ sub process {
|
|||
$var{'group.url'} = WebGUI::URL::page("op=autoDeleteFromGroup;groupId=".$g->groupId);
|
||||
$var{'group.text'} = $param[1];
|
||||
if ($param[2]) {
|
||||
return WebGUI::Asset::Template->newByUrl($param[2])->process(\%var);
|
||||
return WebGUI::Asset::Template->newByUrl($session,$param[2])->process(\%var);
|
||||
} else {
|
||||
return WebGUI::Asset::Template->new("PBtmpl0000000000000041")->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,"PBtmpl0000000000000041")->process(\%var);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ package WebGUI::Macro::GroupText;
|
|||
|
||||
use strict;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -44,8 +42,9 @@ Text to be shown to someone not in the group.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my @param = @_;
|
||||
my ($groupId) = WebGUI::SQL->quickArray("select groupId from groups where groupName=".quote($param[0]),WebGUI::SQL->getSlave);
|
||||
my ($groupId) = $session->dbSlave->quickArray("select groupId from groups where groupName=".$session->db->quote($param[0]));
|
||||
$groupId = 3 if ($groupId eq "");
|
||||
if (WebGUI::Grouping::isInGroup($groupId)) {
|
||||
return $param[1];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ use strict;
|
|||
use WebGUI::Asset;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -43,8 +42,9 @@ be used.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my ($label, $templateUrl) = @_;
|
||||
my $home = WebGUI::Asset->getDefault;
|
||||
my $home = WebGUI::Asset->getDefault($session);
|
||||
if ($label ne "linkonly") {
|
||||
my %var;
|
||||
$var{'homelink.url'} = $home->getUrl;
|
||||
|
|
@ -54,9 +54,9 @@ sub process {
|
|||
$var{'homeLink.text'} = WebGUI::International::get(47,'Macro_H_homeLink');
|
||||
}
|
||||
if ($templateUrl) {
|
||||
return WebGUI::Asset::Template->newByUrl($templateUrl)->process(\%var);
|
||||
return WebGUI::Asset::Template->newByUrl($session,$templateUrl)->process(\%var);
|
||||
} else {
|
||||
return WebGUI::Asset::Template->new("PBtmpl0000000000000042")->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,"PBtmpl0000000000000042")->process(\%var);
|
||||
}
|
||||
}
|
||||
return $home->getUrl;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::Hash_userId;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -30,7 +29,8 @@ Returns the userId from the session variable for the current user.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return $session{user}{userId};
|
||||
my $session = shift;
|
||||
return $session->user->userId;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,63 +0,0 @@
|
|||
package WebGUI::Macro::If;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2005 Plain Black Software.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
||||
use strict;
|
||||
use WebGUI::International;
|
||||
use Safe;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Macro::If
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
A macro for implementing a simple conditional.
|
||||
|
||||
=head2 process ( expression, trueResult, falseResult )
|
||||
|
||||
Returns trueResult if expression is true, falseResult if the expression
|
||||
is false and an error message if there was a problem evaluating the
|
||||
expression.
|
||||
|
||||
=head3 expression
|
||||
|
||||
A perl expression that will be evaulated in a Safe compartment.
|
||||
|
||||
=head3 trueResult
|
||||
|
||||
Text that will be returned if the expression is true.
|
||||
|
||||
=head3 falseResult
|
||||
|
||||
Text that will be returned if the expression is false.
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($expression, $true, $false) = @_;
|
||||
my $output = $false;
|
||||
|
||||
# Workaround to "Safely" eval $expression
|
||||
my $compartment = new Safe;
|
||||
my $return = $compartment->reval($expression);
|
||||
|
||||
return sprintf(WebGUI::International::get('eval error', 'Macro_If'),
|
||||
$@,$expression,$true,$false) if ($@);
|
||||
|
||||
$output = $true if ($return);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
@ -36,6 +36,7 @@ The complete path to a file in the local filesystem.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $self = shift;
|
||||
my (@param, $temp, $file);
|
||||
@param = @_;
|
||||
if ($param[0] =~ /passwd/ || $param[0] =~ /shadow/ || $param[0] =~ /WebGUI.conf/) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ package WebGUI::Macro::International;
|
|||
|
||||
use strict;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -41,6 +40,7 @@ The namespace to pull the label from.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $self = shift;
|
||||
return WebGUI::International::get(shift,shift);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::JavaScript;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -20,7 +18,7 @@ Package WebGUI::Macro::JavaScript
|
|||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This Macro is a wrapper for WebGUI::Style::setScript, which puts a script
|
||||
This Macro is a wrapper for $session->style->setScript, which puts a script
|
||||
tag into the head of the current page with the contents of the javascript
|
||||
found at the url that is passed in.
|
||||
|
||||
|
|
@ -35,7 +33,8 @@ URL to the javascript to include in the page's header tags.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
WebGUI::Style::setScript(shift,{type=>'text/javascript'});
|
||||
my $session = shift;
|
||||
$session->style->setScript(shift,{type=>'text/javascript'});
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ package WebGUI::Macro::L_loginBox;
|
|||
use strict;
|
||||
use WebGUI::Form;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -38,7 +36,9 @@ text to wrap in a link for logging out.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub _createURL {
|
||||
return '<a href="'.WebGUI::URL::page("op=auth;method=logout").'">'.$_[0].'</a>';
|
||||
my $session = shift;
|
||||
my $text = shift;
|
||||
return '<a href="'.WebGUI::URL::page("op=auth;method=logout").'">'.$text.'</a>';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -61,23 +61,24 @@ The ID of a template for custom layout of the login box and text.
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
my $self = shift;
|
||||
my @param = @_;
|
||||
my $templateId = $param[2] || "PBtmpl0000000000000044";
|
||||
my %var;
|
||||
$var{'user.isVisitor'} = ($session{user}{userId} eq "1");
|
||||
$var{'user.isVisitor'} = ($session->user->profileField("userId") eq "1");
|
||||
$var{'customText'} = $param[1];
|
||||
$var{'customText'} =~ s/%(.*?)%/_createURL($1)/ge;
|
||||
$var{'customText'} =~ s/%(.*?)%/_createURL($session,$1)/ge;
|
||||
$var{'hello.label'} = WebGUI::International::get(48,'Macro_L_loginBox');
|
||||
$var{'logout.url'} = WebGUI::URL::page("op=auth;method=logout");
|
||||
$var{'account.display.url'} = WebGUI::URL::page('op=auth;method=displayAccount');
|
||||
$var{'logout.label'} = WebGUI::International::get(49,'Macro_L_loginBox');
|
||||
my $boxSize = $param[0];
|
||||
$boxSize = 12 unless ($boxSize);
|
||||
if (index(lc($ENV{HTTP_USER_AGENT}),"msie") < 0) {
|
||||
if (index(lc($session->env->get("HTTP_USER_AGENT")),"msie") < 0) {
|
||||
$boxSize = int($boxSize=$boxSize*2/3);
|
||||
}
|
||||
my $action;
|
||||
if ($session{setting}{encryptLogin}) {
|
||||
if ($session->setting->get("encryptLogin")) {
|
||||
$action = WebGUI::URL::page(undef,1);
|
||||
$action =~ s/http:/https:/;
|
||||
}
|
||||
|
|
@ -109,7 +110,7 @@ sub process {
|
|||
$var{'account.create.url'} = WebGUI::URL::page('op=auth;method=createAccount');
|
||||
$var{'account.create.label'} = WebGUI::International::get(407);
|
||||
$var{'form.footer'} = WebGUI::Form::formFooter();
|
||||
return WebGUI::Asset::Template->new($templateId)->process(\%var);
|
||||
return WebGUI::Asset::Template->new($session,$templateId)->process(\%var);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@ package WebGUI::Macro::LastModified;
|
|||
use strict;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::International;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -42,11 +40,12 @@ sprintf. See L<WebGUI::DateTime/"epochToHuman"> for a list of codes. Uses
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return '' unless $session{asset};
|
||||
my $session = shift;
|
||||
return '' unless $session->asset;
|
||||
my ($label, $format, $time);
|
||||
($label, $format) = @_;
|
||||
$format = '%z' if ($format eq "");
|
||||
($time) = WebGUI::SQL->quickArray("SELECT max(revisionDate) FROM assetData where assetId=".quote($session{asset}->getId),WebGUI::SQL->getSlave);
|
||||
($time) = $session->dbSlave->quickArray("SELECT max(revisionDate) FROM assetData where assetId=".$session->db->quote($session->asset->getId));
|
||||
return WebGUI::International::get('never','Macro_LastModified') if $time eq 0;
|
||||
return $label.epochToHuman($time,$format) if ($time);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ sub process {
|
|||
my $login = $param[0] || WebGUI::International::get(716,'Macro_LoginToggle');
|
||||
my $logout = $param[1] || WebGUI::International::get(717,'Macro_LoginToggle');
|
||||
my %var;
|
||||
if ($session{user}{userId} eq '1') {
|
||||
if ($session->user->profileField("userId") eq '1') {
|
||||
return WebGUI::URL::page("op=auth;method=init") if ($param[0] eq "linkonly");
|
||||
$var{'toggle.url'} = WebGUI::URL::page('op=auth;method=init');
|
||||
$var{'toggle.text'} = $login;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::Page;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -28,14 +27,15 @@ session variable, returns a single space.
|
|||
|
||||
=head3 property
|
||||
|
||||
The name of the property to retrieve from the assset via $session{asset}->get()
|
||||
The name of the property to retrieve from the assset via $session->asset->get()
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
if (exists $session{asset}) {
|
||||
return $session{asset}->get(shift);
|
||||
my $session = shift;
|
||||
if ($session->asset) {
|
||||
return $session->asset->get(shift);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::PageTitle;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -31,11 +30,12 @@ no asset cached in the session variable, nothing is returned.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
if (exists $session{asset}) {
|
||||
if ($session{form}{op} || $session{form}{func}) {
|
||||
return '<a href="'.$session{asset}->getUrl.'">'.$session{asset}->get("title").'</a>';
|
||||
my $self = shift;
|
||||
if ($session->asset) {
|
||||
if ($session->form->process("op") || $session->form->process("func")) {
|
||||
return '<a href="'.$session->asset->getUrl.'">'.$session->asset->get("title").'</a>';
|
||||
} else {
|
||||
return $session{asset}->get("title");
|
||||
return $session->asset->get("title");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::PageUrl;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -30,6 +28,7 @@ process is really a wrapper around WebGUI::URL::page();
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
return WebGUI::URL::page();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
package WebGUI::Macro::Product;
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Product;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::International;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -29,15 +27,16 @@ is left blank, a default template from the Macro/Product namespace will be used.
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my (@param, $productId, $variantId, $product, $variant, $output, $templateId, @variantLoop, %var);
|
||||
|
||||
@param = @_;
|
||||
|
||||
return WebGUI::International::get('no sku or id','Macro_Product') unless ($_[0]);
|
||||
|
||||
($productId, $variantId) = WebGUI::SQL->quickArray("select productId, variantId from productVariants where sku=".quote($_[0]));
|
||||
($productId) = WebGUI::SQL->quickArray("select productId from products where sku=".quote($_[0])) unless ($productId);
|
||||
($productId) = WebGUI::SQL->quickArray("select productId from products where productId=".quote($_[0])) unless ($productId);
|
||||
($productId, $variantId) = $session->db->quickArray("select productId, variantId from productVariants where sku=".$session->db->quote($_[0]));
|
||||
($productId) = $session->db->quickArray("select productId from products where sku=".$session->db->quote($_[0])) unless ($productId);
|
||||
($productId) = $session->db->quickArray("select productId from products where productId=".$session->db->quote($_[0])) unless ($productId);
|
||||
|
||||
return WebGUI::International::get('cannot find product','Macro_Product') unless ($productId);
|
||||
|
||||
|
|
@ -75,7 +74,7 @@ sub process {
|
|||
$var{'variants.message'} = WebGUI::International::get('available product configurations', 'Macro_Product');
|
||||
$templateId = $_[1] || $product->get('templateId');
|
||||
|
||||
return WebGUI::Asset::Template->new($templateId)->process(\%var);
|
||||
return WebGUI::Asset::Template->new($ssession,$templateId)->process(\%var);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ package WebGUI::Macro::Quote;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ Macro for quoting data to make it safe for use in SQL queries.
|
|||
|
||||
=head2 process ( text )
|
||||
|
||||
process is really a wrapper around WebGUI::SQL::quote();
|
||||
process is really a wrapper around WebGUI::SQL::$session->db->quote();
|
||||
|
||||
=head3 text
|
||||
|
||||
|
|
@ -33,7 +32,8 @@ The text to quote.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
return quote(shift);
|
||||
my $session = shift;
|
||||
return $session->db->quote(shift);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ package WebGUI::Macro::RandomAssetProxy;
|
|||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::International;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -35,14 +34,15 @@ if no asset exists at that url, or if the asset has no children.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my $url = shift;
|
||||
my $asset = WebGUI::Asset->newByUrl($url);
|
||||
my $asset = WebGUI::Asset->newByUrl($session, $url);
|
||||
if (defined $asset) {
|
||||
my $children = $asset->getLineage(["children"]);
|
||||
#randomize;
|
||||
srand;
|
||||
my $randomAssetId = $children->[rand(scalar(@{$children}))];
|
||||
my $randomAsset = WebGUI::Asset->newByDynamicClass($randomAssetId);
|
||||
my $randomAsset = WebGUI::Asset->newByDynamicClass($session,$randomAssetId);
|
||||
if (defined $randomAsset) {
|
||||
$randomAsset->toggleToolbar;
|
||||
return $randomAsset->canView ? $randomAsset->view() : undef;
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@ package WebGUI::Macro::RandomThread;
|
|||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::ErrorHandler;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -60,6 +57,7 @@ URL of the template to use to display the random thread. Must be a valid URL wit
|
|||
=cut
|
||||
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my ($startURL, $relatives, $templateURL) = @_;
|
||||
# Seed the randomizer:
|
||||
srand;
|
||||
|
|
@ -70,33 +68,33 @@ sub process {
|
|||
my $numberOfTries = 2; # try this many times in case we select a thread the user cannot view
|
||||
|
||||
# Sanity check of parameters:
|
||||
my $startAsset = WebGUI::Asset->newByUrl($startURL);
|
||||
my $startAsset = WebGUI::Asset->newByUrl($session, $startURL);
|
||||
unless ($startAsset) {
|
||||
WebGUI::ErrorHandler::warn('Error: invalid startURL. Check parameters of macro on page '.$session{asset}->get('url'));
|
||||
$session->errorHandler->warn('Error: invalid startURL. Check parameters of macro on page '.$session->asset->get('url'));
|
||||
return '';
|
||||
}
|
||||
|
||||
$relatives = lc($relatives);
|
||||
unless ( isIn($relatives, ('siblings','children','ancestors','self','descendants','pedigree')) ) {
|
||||
WebGUI::ErrorHandler::warn('Error: invalid relatives specified. Must be one of siblings, children, ancestors, self, descendants, pedigree. Check parameters of macro on page '.$session{asset}->get('url'));
|
||||
$session->errorHandler->warn('Error: invalid relatives specified. Must be one of siblings, children, ancestors, self, descendants, pedigree. Check parameters of macro on page '.$session->asset->get('url'));
|
||||
return '';
|
||||
}
|
||||
|
||||
my $template = $templateURL ? WebGUI::Asset::Template->newByUrl($templateURL) : WebGUI::Asset::Template->new('WVtmpl0000000000000001');
|
||||
my $template = $templateURL ? WebGUI::Asset::Template->newByUrl($session,$templateURL) : WebGUI::Asset::Template->new($session,'WVtmpl0000000000000001');
|
||||
unless ($template) {
|
||||
WebGUI::ErrorHandler::warn('Error: invalid template URL. Check parameters of macro on page '.$session{asset}->get('url'));
|
||||
$session->errorHandler->warn('Error: invalid template URL. Check parameters of macro on page '.$session->asset->get('url'));
|
||||
return '';
|
||||
}
|
||||
|
||||
# Get all CS's that we'll use to pick a thread from:
|
||||
my $lineage = $startAsset->getLineage([$relatives],{includeOnlyClasses => ['WebGUI::Asset::Wobject::Collaboration']});
|
||||
unless ( scalar(@{$lineage}) ) {
|
||||
WebGUI::ErrorHandler::warn('Error: no Collaboration Systems found with current parameters. Check parameters of macro on page '.$session{asset}->get('url'));
|
||||
$session->errorHandler->warn('Error: no Collaboration Systems found with current parameters. Check parameters of macro on page '.$session->asset->get('url'));
|
||||
return '';
|
||||
}
|
||||
|
||||
# Try to get a random thread that the user can see:
|
||||
my $randomThread = _getRandomThread($lineage);
|
||||
my $randomThread = _getRandomThread($session, $lineage);
|
||||
my $i = 0;
|
||||
while ($i < $numberOfTries) {
|
||||
if($randomThread->canView()) {
|
||||
|
|
@ -105,21 +103,25 @@ sub process {
|
|||
return $template->process($var);
|
||||
} else {
|
||||
# Keep trying until we find a thread we can actually view:
|
||||
$randomThread = _getRandomThread($lineage);
|
||||
$randomThread = _getRandomThread($session, $lineage);
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
# If we reach this point, we had no success in finding an asset the user can view:
|
||||
WebGUI::ErrorHandler::warn("Could not find a random thread that was viewable by the user $session{user}{username} after $numberOfTries tries. Check parameters of macro on page ".$session{asset}->get('url'));
|
||||
$session->errorHandler->warn("Could not find a random thread that was viewable by the user $session->user->profileField("username") after $numberOfTries tries. Check parameters of macro on page ".$session->asset->get('url'));
|
||||
return '';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 _getRandomThread ( lineage )
|
||||
=head2 _getRandomThread ( session, lineage )
|
||||
|
||||
Helper function that returns a random thread.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 lineage
|
||||
|
||||
Reference to an array with lineage of Collaboration Systems to select a random thread from.
|
||||
|
|
@ -127,18 +129,19 @@ Reference to an array with lineage of Collaboration Systems to select a random t
|
|||
=cut
|
||||
|
||||
sub _getRandomThread {
|
||||
my $session = shift;
|
||||
my $lineage = shift;
|
||||
|
||||
# Get random CS:
|
||||
my $randomIndex = int(rand(scalar(@{$lineage})));
|
||||
my $randomCSId = $lineage->[$randomIndex];
|
||||
my $randomCS = WebGUI::Asset->new($randomCSId,'WebGUI::Asset::Wobject::Collaboration');
|
||||
my $randomCS = WebGUI::Asset->new($session,$randomCSId,'WebGUI::Asset::Wobject::Collaboration');
|
||||
|
||||
# Get random thread in that CS:
|
||||
$lineage = $randomCS->getLineage(['children'],{includeOnlyClasses => ['WebGUI::Asset::Post::Thread']});
|
||||
$randomIndex = int(rand(scalar(@{$lineage})));
|
||||
my $randomThreadId = $lineage->[$randomIndex];
|
||||
return WebGUI::Asset->new($randomThreadId,'WebGUI::Asset::Post::Thread');
|
||||
return WebGUI::Asset->new($session,$randomThreadId,'WebGUI::Asset::Post::Thread');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::RawHeadTags;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Style;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -24,7 +22,7 @@ Macro for adding
|
|||
|
||||
=head2 process ( tags )
|
||||
|
||||
process is a wrapper for WebGUI::Style::setRawHeadTags();
|
||||
process is a wrapper for $session->style->setRawHeadTags();
|
||||
|
||||
=head3 text
|
||||
|
||||
|
|
@ -34,7 +32,8 @@ Text that will be added to the HEAD tags for this page.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
WebGUI::Style::setRawHeadTags(shift);
|
||||
my $session = shift;
|
||||
$session->style->setRawHeadTags(shift);
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ package WebGUI::Macro::RootTitle;
|
|||
|
||||
use strict;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Session;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -32,10 +31,11 @@ is returned. Otherwise a space is returned.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
if (exists $session{asset}) {
|
||||
my $lineage = $session{asset}->get("lineage");
|
||||
my $session = shift;
|
||||
if ($session->asset) {
|
||||
my $lineage = $session->asset->get("lineage");
|
||||
$lineage = substr($lineage,0,6);
|
||||
my $root = WebGUI::Asset->newByLineage($lineage);
|
||||
my $root = WebGUI::Asset->newByLineage($session,$lineage);
|
||||
if (defined $root) {
|
||||
return $root->get("title");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::SQL;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -40,11 +38,12 @@ be used to position its output in the format.
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
my ($output, @data, $rownum, $temp);
|
||||
my ($statement, $format) = @_;
|
||||
$format = '^0;' if ($format eq "");
|
||||
if ($statement =~ /^\s*select/i || $statement =~ /^\s*show/i || $statement =~ /^\s*describe/i) {
|
||||
my $sth = WebGUI::SQL->unconditionalRead($statement,WebGUI::SQL->getSlave);
|
||||
my $sth = $session->dbSlave->unconditionalRead($statement);
|
||||
unless ($sth->errorCode < 1) {
|
||||
return sprintf WebGUI::International::get('sql error','Macro_SQL'), $sth->errorMessage;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ package WebGUI::Macro::Slash_gatewayUrl;
|
|||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::URL;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -30,6 +28,7 @@ process is really a wrapper around WebGUI::URL::gateway();
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub process {
|
||||
my $session = shift;
|
||||
return WebGUI::URL::gateway();
|
||||
}
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue