S
Saya
Hi,
This is the code:
sub Escape{
$item = shift;
use HTML::LinkExtor;
$p = HTML::LinkExtor->new(\&replaceURL, "");
$p->parse($item);
return $item;
}
sub replaceURL {
my(@links) = @_;
my $makeSubstitution = false;
my $newLink;
foreach my $link (@links) {
#$link =~ s/\/$//i;
$makeSubstitution = compareValues($link);
if ($makeSubstitution eq true) {
if($link =~ /http|www/) {
if ($link !~ /http/) {
$newLink = "http://" . $link;
}
else {
$newLink = $link;
}
$item =~ s/href=\"$link/href=\"\/redirect.asp?forwardURL=$newLink/i;
}
}
else {
if($link =~ /http|www/) {
if ($link !~ /http/) {
$item=~ s/href=\"$link/href=\"http:\/\/$link/i;
}
}
}
}
}
sub compareValues {
my $link = shift;
my @safeLinkArr;
@safeLinkArr = getSafeSites();
my $sizeOfArray = @safeLinkArr;
my $result = true;
if($sizeOfArray eq 0) {
return $result;
}
foreach my $safeLink (@safeLinkArr) {
if ( (0 <= (index($link, $safeLink))) or (0 <= (index($safeLink,
$link))) ) {
$result = false;
last;
}
else {
$result = true;
}
}
return $result;
}
sub getSafeSites {
use XML:
OM;
my $count;
my $WAPath;
my @linkArr;
foreach $arg (@ARGV)
{
if ($ARGV[$count] eq '-iw_include-location')
{
$WAPath = $ARGV[$count + 1];
}
$count++;
}
my $nonRedirectList = $WAPath . "/include/nonRedirectList.xml";
# --- Parsing the XML file ---
my $parser = XML:
OM:
arser->new();
my $doc = $parser->parsefile($nonRedirectList);
# --- get all tags ---
my $links = $doc->getElementsByTagName('Link');
my $link;
for my $i (0..$links->getLength()-1) {
$link = $links->item($i);
if ($link->getFirstChild->getNodeValue) {
@linkArr[$i] = $link->getFirstChild->getNodeValue;
}
$i++;
}
$doc->dispose;
return @linkArr;
}
Escape($item);
$item = is real scenario is text + <a> + text <a> etc.
For some reason that I do not understand some links are not parsed
correctly. Does anyone have a reason for why this might be happening ?
I have looked at this problem for 2 days now, and can not find the
problem, so any help will be greatly appreciated
/Saya
This is the code:
sub Escape{
$item = shift;
use HTML::LinkExtor;
$p = HTML::LinkExtor->new(\&replaceURL, "");
$p->parse($item);
return $item;
}
sub replaceURL {
my(@links) = @_;
my $makeSubstitution = false;
my $newLink;
foreach my $link (@links) {
#$link =~ s/\/$//i;
$makeSubstitution = compareValues($link);
if ($makeSubstitution eq true) {
if($link =~ /http|www/) {
if ($link !~ /http/) {
$newLink = "http://" . $link;
}
else {
$newLink = $link;
}
$item =~ s/href=\"$link/href=\"\/redirect.asp?forwardURL=$newLink/i;
}
}
else {
if($link =~ /http|www/) {
if ($link !~ /http/) {
$item=~ s/href=\"$link/href=\"http:\/\/$link/i;
}
}
}
}
}
sub compareValues {
my $link = shift;
my @safeLinkArr;
@safeLinkArr = getSafeSites();
my $sizeOfArray = @safeLinkArr;
my $result = true;
if($sizeOfArray eq 0) {
return $result;
}
foreach my $safeLink (@safeLinkArr) {
if ( (0 <= (index($link, $safeLink))) or (0 <= (index($safeLink,
$link))) ) {
$result = false;
last;
}
else {
$result = true;
}
}
return $result;
}
sub getSafeSites {
use XML:
my $count;
my $WAPath;
my @linkArr;
foreach $arg (@ARGV)
{
if ($ARGV[$count] eq '-iw_include-location')
{
$WAPath = $ARGV[$count + 1];
}
$count++;
}
my $nonRedirectList = $WAPath . "/include/nonRedirectList.xml";
# --- Parsing the XML file ---
my $parser = XML:
my $doc = $parser->parsefile($nonRedirectList);
# --- get all tags ---
my $links = $doc->getElementsByTagName('Link');
my $link;
for my $i (0..$links->getLength()-1) {
$link = $links->item($i);
if ($link->getFirstChild->getNodeValue) {
@linkArr[$i] = $link->getFirstChild->getNodeValue;
}
$i++;
}
$doc->dispose;
return @linkArr;
}
Escape($item);
$item = is real scenario is text + <a> + text <a> etc.
For some reason that I do not understand some links are not parsed
correctly. Does anyone have a reason for why this might be happening ?
I have looked at this problem for 2 days now, and can not find the
problem, so any help will be greatly appreciated
/Saya