refactored WebGUI::HTML api to use new ssesion system
This commit is contained in:
parent
16de66517c
commit
45c7e7876d
3 changed files with 52 additions and 30 deletions
|
|
@ -748,6 +748,15 @@ perl -pi.bak -e 's!WebGUI\:\:Grouping\:\:userGroupAdmin!\$group->userIsAdmin!g'
|
||||||
perl -pi.bak -e 's!WebGUI\:\:Grouping\:\:userGroupExpireDate!\$group->userGroupExpireDate!g' fileNameGoesHere
|
perl -pi.bak -e 's!WebGUI\:\:Grouping\:\:userGroupExpireDate!\$group->userGroupExpireDate!g' fileNameGoesHere
|
||||||
|
|
||||||
|
|
||||||
|
5.23.14 WebGUI::HTML API Refactored
|
||||||
|
|
||||||
|
You now need to pass in a reference to $session to the makeAbsolute and
|
||||||
|
processReplacements functions.
|
||||||
|
|
||||||
|
perl -pi.bak -e 's!WebGUI\:\:HTML\:\:makeAbsolute\(!WebGUI::HTML::makeAbsolute(\$self->session,!g' fileNameGoesHere
|
||||||
|
perl -pi.bak -e 's!WebGUI\:\:HTML\:\:processReplacements\(!WebGUI::HTML::processReplacements(\$self->session,!g' fileNameGoesHere
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
6. Automatic list of Assets in Help System.
|
6. Automatic list of Assets in Help System.
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ sub formatContent {
|
||||||
my $msg = WebGUI::HTML::filter($content,$self->getThread->getParent->get("filterCode"));
|
my $msg = WebGUI::HTML::filter($content,$self->getThread->getParent->get("filterCode"));
|
||||||
$msg = WebGUI::HTML::format($msg, $contentType);
|
$msg = WebGUI::HTML::format($msg, $contentType);
|
||||||
if ($self->getThread->getParent->get("useContentFilter")) {
|
if ($self->getThread->getParent->get("useContentFilter")) {
|
||||||
$msg = WebGUI::HTML::processReplacements($msg);
|
$msg = WebGUI::HTML::processReplacements($self->session,$msg);
|
||||||
}
|
}
|
||||||
return $msg;
|
return $msg;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,7 @@ package WebGUI::HTML;
|
||||||
use HTML::TagFilter;
|
use HTML::TagFilter;
|
||||||
use strict;
|
use strict;
|
||||||
use WebGUI::Macro;
|
use WebGUI::Macro;
|
||||||
use WebGUI::Session;
|
|
||||||
use WebGUI::SQL;
|
|
||||||
use HTML::Parser;
|
use HTML::Parser;
|
||||||
use WebGUI::URL;
|
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
|
|
@ -37,8 +34,8 @@ A package for manipulating and massaging HTML.
|
||||||
$html = WebGUI::HTML::filter($html);
|
$html = WebGUI::HTML::filter($html);
|
||||||
$html = WebGUI::HTML::format($content, $contentType);
|
$html = WebGUI::HTML::format($content, $contentType);
|
||||||
$html = WebGUI::HTML::html2text($html);
|
$html = WebGUI::HTML::html2text($html);
|
||||||
$html = WebGUI::HTML::makeAbsolute($html);
|
$html = WebGUI::HTML::makeAbsolute($session, $html);
|
||||||
$html = WebGUI::HTML::processReplacements($html);
|
$html = WebGUI::HTML::processReplacements($session, $html);
|
||||||
|
|
||||||
=head1 METHODS
|
=head1 METHODS
|
||||||
|
|
||||||
|
|
@ -189,22 +186,25 @@ The html segment you want to convert to text.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
# for recursive function
|
||||||
|
my $text = "";
|
||||||
|
my $inside = {};
|
||||||
|
|
||||||
sub html2text {
|
sub html2text {
|
||||||
my $html = shift;
|
my $html = shift;
|
||||||
$session{temp}{html2text}{text} = "";
|
$text = "";
|
||||||
delete($session{temp}{html2text}{inside});
|
$inside = {};
|
||||||
|
|
||||||
my $tagHandler = sub {
|
my $tagHandler = sub {
|
||||||
my($tag, $num) = @_;
|
my($tag, $num) = @_;
|
||||||
$session{temp}{html2text}{inside}{$tag} += $num;
|
$inside->{$tag} += $num;
|
||||||
if($tag eq "br" || $tag eq "p") {
|
if($tag eq "br" || $tag eq "p") {
|
||||||
$session{temp}{html2text}{text} .= "\n";
|
$text .= "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
my $textHandler = sub {
|
my $textHandler = sub {
|
||||||
return if $session{temp}{html2text}{inside}{script} || $session{temp}{html2text}{inside}{style};
|
return if $inside->{script} || $inside->{style};
|
||||||
if ($_[0] =~ /\S+/) {
|
if ($_[0] =~ /\S+/) {
|
||||||
$session{temp}{html2text}{text} .= $_[0];
|
$text .= $_[0];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -216,14 +216,18 @@ sub html2text {
|
||||||
marked_sections => 1,
|
marked_sections => 1,
|
||||||
)->parse($html);
|
)->parse($html);
|
||||||
|
|
||||||
return $session{temp}{html2text}{text};
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 makeAbsolute ( html , [ baseURL ] )
|
=head2 makeAbsolute ( session, html , [ baseURL ] )
|
||||||
|
|
||||||
Returns html with all relative links converted to absolute.
|
Returns html with all relative links converted to absolute.
|
||||||
|
|
||||||
|
=head3 session
|
||||||
|
|
||||||
|
A reference to the current session.
|
||||||
|
|
||||||
=head3 html
|
=head3 html
|
||||||
|
|
||||||
|
|
@ -234,12 +238,15 @@ The html to be made absolute.
|
||||||
The base URL to use. Defaults to current page's url.
|
The base URL to use. Defaults to current page's url.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
|
my $absolute = "";
|
||||||
|
|
||||||
sub makeAbsolute {
|
sub makeAbsolute {
|
||||||
|
my $session = shift;
|
||||||
my $html = shift;
|
my $html = shift;
|
||||||
my $baseURL = shift;
|
my $baseURL = shift;
|
||||||
|
|
||||||
$session{temp}{makeAbsolute}{html} = "";
|
$absolute = "";
|
||||||
|
|
||||||
my $linkParser = sub {
|
my $linkParser = sub {
|
||||||
my ($tagname, $attr, $text) = @_;
|
my ($tagname, $attr, $text) = @_;
|
||||||
|
|
@ -261,7 +268,7 @@ sub makeAbsolute {
|
||||||
);
|
);
|
||||||
|
|
||||||
if(not exists $linkElements{$tagname}) { # no need to touch this tag
|
if(not exists $linkElements{$tagname}) { # no need to touch this tag
|
||||||
$session{temp}{makeAbsolute}{html} .= $text;
|
$absolute .= $text;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,35 +281,39 @@ sub makeAbsolute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$session{temp}{makeAbsolute}{html} .= "<".$tagname;
|
$absolute .= "<".$tagname;
|
||||||
|
|
||||||
foreach (keys %$attr) {
|
foreach (keys %$attr) {
|
||||||
if($_ eq '/') {
|
if($_ eq '/') {
|
||||||
$session{temp}{makeAbsolute}{html} .= '/';
|
$absolute .= '/';
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ($tag_attr{"$tagname $_"}) { # make this absolute
|
if ($tag_attr{"$tagname $_"}) { # make this absolute
|
||||||
$attr->{$_} = $self->session->url->makeAbsolute($attr->{$_}, $baseURL);
|
$attr->{$_} = $session->url->makeAbsolute($attr->{$_}, $baseURL);
|
||||||
}
|
}
|
||||||
$session{temp}{makeAbsolute}{html} .= qq' $_="$attr->{$_}"';
|
$absolute .= qq' $_="$attr->{$_}"';
|
||||||
}
|
}
|
||||||
|
|
||||||
$session{temp}{makeAbsolute}{html} .= '>';
|
$absolute .= '>';
|
||||||
};
|
};
|
||||||
HTML::Parser->new(
|
HTML::Parser->new(
|
||||||
default_h => [ sub { $session{temp}{makeAbsolute}{html} .= shift }, 'text' ],
|
default_h => [ sub { $absolute .= shift }, 'text' ],
|
||||||
start_h => [ $linkParser , 'tagname, attr, text' ],
|
start_h => [ $linkParser , 'tagname, attr, text' ],
|
||||||
)->parse($html);
|
)->parse($html);
|
||||||
|
|
||||||
return $session{temp}{makeAbsolute}{html};
|
return $absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 processReplacements ( content )
|
=head2 processReplacements ( session, content )
|
||||||
|
|
||||||
Processes text using the WebGUI replacements system.
|
Processes text using the WebGUI replacements system.
|
||||||
|
|
||||||
|
=head3 session
|
||||||
|
|
||||||
|
A reference to the current session.
|
||||||
|
|
||||||
=head3 content
|
=head3 content
|
||||||
|
|
||||||
The content to be processed through the replacements filter.
|
The content to be processed through the replacements filter.
|
||||||
|
|
@ -310,20 +321,22 @@ The content to be processed through the replacements filter.
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub processReplacements {
|
sub processReplacements {
|
||||||
|
my $session = shift;
|
||||||
my ($content) = @_;
|
my ($content) = @_;
|
||||||
if (exists $session{replacements}) {
|
my $replacements = $session->stow->get("replacements");
|
||||||
my $replacements = $session{replacements};
|
if (defined $replacements) {
|
||||||
foreach my $searchFor (keys %{$replacements}) {
|
foreach my $searchFor (keys %{$replacements}) {
|
||||||
my $replaceWith = $replacements->{$searchFor};
|
my $replaceWith = $replacements->{$searchFor};
|
||||||
$content =~ s/\Q$searchFor/$replaceWith/gs;
|
$content =~ s/\Q$searchFor/$replaceWith/gs;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
my $sth = $self->session->db->read("select searchFor,replaceWith from replacements",$self->session->db->getSlave);
|
my $sth = $session->db->read("select searchFor,replaceWith from replacements",$session->db->getSlave);
|
||||||
while (my ($searchFor,$replaceWith) = $sth->array) {
|
while (my ($searchFor,$replaceWith) = $sth->array) {
|
||||||
$session{replacements}{$searchFor} = $replaceWith;
|
$replacements->{$searchFor} = $replaceWith;
|
||||||
$content =~ s/\Q$searchFor/$replaceWith/gs;
|
$content =~ s/\Q$searchFor/$replaceWith/gs;
|
||||||
}
|
}
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
|
$session->stow->set("replacements",$replacements);
|
||||||
}
|
}
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue