|
From: i18n <i1...@ya...> - 2002-09-06 18:01:36
|
At 02:27 PM 9/5/2002 -0700, i18n wrote:
>At 01:11 PM 9/5/2002 -0700, chromatic wrote:
>
>>A better approach would be to use a real HTML parser that can distinguish
>>between tags and content.
>>
>>*insert handwaving*,
>>-- c
>>
>
>Hmm yeah I could do that I guess...am I at least right about the purpose of the mysterious line of code?
>
>If so, until I or someone else inserts HTML::Parser code, I could at least code around it ("if href does not contain amazon then do that line of code")....
below is my code around....
to see the results, go to http://www.i18n.com/article.pl?sid=02/09/05/0811249
from admin.pl:
----------------------------------------------
# And slurp in all the URLs just for good measure
while ($story_content =~ m|<A(.*?)>(.*?)</A>|sgi) {
my($url, $label) = ($1, $2);
$label = massageLabel($label);
$related_links = buildRelatedLinks($related_links,$label,$url);
}
return $related_links;
}
##################################################################
# -- this is added by barry
sub buildRelatedLinks{
my ($related_links,$label,$url) = @_;
SWITCH: {
if ($url =~ /wwwi18ncom-20/) {# my amazon associate number
$related_links .= "<center><A$url>$label</A></center>\n"; # center in teh related links box
last SWITCH;
}
$related_links .= "<LI><A$url>$label</A></LI>\n" unless $label eq "[?]";
}
return $related_links;
}
##################################################################
# -- this is added by barry
sub massageLabel{
my ($label)= @_;
my $newlabel =~ s/<.*?>//g; # strip out any tags
if ($label eq $newlabel){ # there were no tags, this is the original case
$label =~ s/(\S{30})/$1 /g;
}
else {
if ($label =~ /amazon/i){
$label =~ s/<.{0,1}center>//g; # strip out the center tags
# $label =~ s/^(.*)$/<center>$1</center>/; # recenter the whole thing
}
}
#else stick with the original $label
return $label;
}
|