From: i18n <i1...@ya...> - 2002-09-05 18:49:12
|
This is from admin.pl in Bebder (it may be in 2.2 for all I know also)... 1 while ($story_content =~ m|<A(.*?)>(.*?)</A>|sgi) { 2 my($url, $label) = ($1, $2); 3 $label =~ s/(\S{30})/$1 /g; 4 $related_links .= "<LI><A$url>$label</A></LI>\n" unless $label eq "[?]"; This is the part of the code where the text that goes in the "Related Links" box is generated. My question is about line 3 - it looks like the purpose is to break up a chunk of text in the label that is over 30 characters and insert spaces every 30 chars. Why? Is this to make sure that the box width isn't broke by long text? If so there is a bit of a bug.... I was trying to add a link to a book notice to a page that was a pointer to my associate link on amazon, complete with an image to the cover. The link is this: <A HREF="http://www.amazon.com/exec/obidos/ASIN/0735712085/wwwi18ncom-20"><IMG SRC="/images/0735712085.01.TZZZZZZZ.jpg" border="0" alt="cover" hspace="3" vspace="3" WIDTH="73" HEIGHT="90"><br><center>Buy From Amazon</center></A> but after I insert a errorLog call after the loop above to look at $related_links, I get this: [Thu Sep 5 17:56:46 2002] [error] /admin.pl:Apache::ROOTwww_2ei18n_2ecom::admin_2epl:/usr/local/slash/site/slash/htdocs/admin.pl:1284:updateStory: getRelated: <LI><A HREF="http://www.amazon.com/exec/obidos/ASIN/0735712085/wwwi18ncom-20"><IMG SRC="/images/0735712085.01.TZZ ZZZZZ.jpg" border="0" alt="cover" hspace="3" vspace="3" WIDTH="73" HEIGHT="90"><br><center>Buy From Amazon</center></A></LI> Note the extra space in the middle of the run of "Z"s, which is 30 spaces from the begining of the SRC element. Does anybody have an improved Regex for the questionable line 3, or is it even necessary at all? Can I just comment it out? Thanks! Barry |
From: chromatic <chr...@wg...> - 2002-09-05 20:14:29
|
On Thursday 05 September 2002 11:47, i18n wrote: > 1 while ($story_content =~ m|<A(.*?)>(.*?)</A>|sgi) { > 2 my($url, $label) = ($1, $2); > 3 $label =~ s/(\S{30})/$1 /g; > 4 $related_links .= "<LI><A$url>$label</A></LI>\n" unless > $label eq "[?]"; > Does anybody have an improved Regex for the questionable line 3, or is it > even necessary at all? Can I just comment it out? A better approach would be to use a real HTML parser that can distinguish between tags and content. *insert handwaving*, -- c |
From: i18n <i1...@ya...> - 2002-09-05 21:29:27
|
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").... Barry |
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; } |