Gossamer Forum
Home : Products : DBMan : Customization :

Removing <b> from $rec to allow links

Quote Reply
Removing <b> from $rec to allow links
Im trying to use $rec{'whatever'} in a url ie www.gaslight.org.uk/$rec{'whatever'}.html to allow people to link through the Db. The problem is if the user found the record via the $rec i want to link to then DBman puts <b> and </b> in the $rec value. I hope that makes sense.

What i want to do is disable the function which inserts the <b> tags when finding records. Can anybody help?

Thanks, Mark.

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
In your .cfg file, set

Code:

# Bold search results (1 = Yes, 0 = No).
$db_bold = 0;
JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Removing <b> from $rec to allow links In reply to
However - what if you still want the bold to be seen on the search results, but not bold on the hyperlink? I note the db.cgi script has:

if ($db_bold and $in{'view_records'}) {
for $i (0 .. (($#hits+1) / ($#db_cols+1)) - 1) {
$offset = $i * ($#db_cols+1);
foreach $field (@search_fields) {
$hits[$field + $offset] =~ s,(<[^>]+>)|($regexp_bold[$field]),defined($1) ? $1 : "<B>$2</B>",ge;
}
}
}

Is there a way of modifying this so that if there is a hyperlink in the record (ie http or mailto) that the script won't bold the <a href="???">, but will bold the hyperlink.

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
The regular expression used by the bold routine actually works perfectly on HTML inside the record. The problem comes about if you try and convert URL's to hyperlinks upon display of a record (for example, via the Auto URL Mod)

In other words, if the HTML for the link is stored in the record, it won't be affected. But if you are converting URLs to hyperlinks, the URL is bolded, and then converted to a hyperlink with the <B> tags stuck inside.

That would be my best guess as to what is happening, although without knowing how your links are generated, I can't be sure...

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Removing <b> from $rec to allow links In reply to
The html isn't stored in the record in this database, and as there are novices updating this database, I would prefer to leave it as a such.

I would prefer to modify db.cgi if this is a possibility

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
I am not a perl whiz, not even a beginner. But in my recent work with JPD's mod I found this line

$rec{'UserID'} =~ s/<\/?B>//g;

I changed that line to strip the <b> tags off my homepage entries. I also used a modified line like this to strip the http:// off of any entries that may have them. I then hard coded the http:// in for the output.
In Reply To:
$rec{'UserID'} =~ s/<\/?B>//g;
$url{'UserEmail'} = $rec{'UserEmail'};
$url{'UserEmail'} =~ s/<\/?B>//g;
$url{'UserHomepage'} = $rec{'UserHomepage'};
$url{'UserHomepage'} =~ s/<\/?B>//g;
$url{'UserHomepage'}=~ s/http:\/\///g;
This is what I used to strip the <b> and to strip the http:// from the entries. I then used
In Reply To:
if ($rec{'UserHomepage'}) {
print qq|
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>Homepage:</FONT></TD>
<TD WIDTH="80%"> <$font><a href="http://$url{'UserHomepage'}">$rec{'UserHomepage'}</a>
|;
}
To test whether or not to print the cell and input the http:// back into the href line of the code.

I really do not know how all those lines work exactly. I just kind of figured they were doing what I wanted and cut and pasted them in.

Dale


Quote Reply
Re: Removing <b> from $rec to allow links In reply to
Hi,

I have played a little with this code in the html.pl file - but it appears to strip everything from the new url contact email record (ie the rec contact email remains intact, but hyperlink to url (mailto in this case) is actually blank.

$url{'Contact_Email'} = $rec{'Contact_Email'};
$url{'Contact_Email'} =~ s/<\?/B>//g;

Any other suggestions?

Ian


Quote Reply
Re: Removing <b> from $rec to allow links In reply to
This code is incorrect
$url{'Contact_Email'} =~ s/<\?/B>//g;

It should be
$url{'Contact_Email'} =~ s/<\/?B>//g;

From what I understand the s is a swithch tag, then the / starts the expression the < is the first part of the <b> you are trying to remove. The \is a comment out tag so perl will ignore the / that follows. The ? is in connection with the / it follows. The code will remove < and </ so far. The rest of the expression removes the B> and replaces it with the stuff between // in this case nothing. The way you changed the code may have effects I can not predict with my little knowledge of perl.

Dale



Quote Reply
Re: Removing <b> from $rec to allow links In reply to
Having fiddled a little more, (the last bit was actually a typo by me and not the real problem), I have discovered that the script is not recognising that rec whatever is actually url whatever.

syntax is

$rec{'Contact_Email'} = $url{'Contact_Email'};

However, ignoring the next part of the script (that of debolding the url) I cannot get the script to place url contact email where it should go in the html output.

Any further thoughts?

(Thanks heaps)

Ian

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
In Reply To:
From what I understand the s is a swithch tag
Correct.

In Reply To:
then the / starts the expression
Pretty much true. The / could be seen as the field delimiter, so to speak, of the regular expression. It doesn't have to be "/", but it has to be the same character throughout.

In Reply To:
the < is the first part of the <b> you are trying to remove.
Correct, except that it's more accurate to look at it as the first item you are trying to *match* not remove -- you only remove it if the whole regex matches.

In Reply To:
The \is a comment out tag so perl will ignore the / that follows.
Sort of. It escapes the following / so that it can be interpreted simply as a / and not a special character such as that which divides the sections of the regex.

In Reply To:
The ? is in connection with the / it follows.
The ? means the / it follows is optional. This is telling the regex to effectively look <B> or </B>, as the only difference is the optional /.

In Reply To:
The rest of the expression removes the B> and replaces it with the stuff between // in this case nothing.
Correct.

Now, back to the question at hand... I've looked through the thread a few times, and I can't quite follow why you're doing it exactly the way you are with $url. Wouldn't

$rec{'Contact_Email'} =~ s/<\/?B>//g;

do what you need? If you do need to set the two equal, try using == instead of =

Dan

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
Thanks for the explanation

The reason for both rec and url is that I want to display the bold (rec), but have the url missing the bold (url).

Just picking up on your last comment,

> If you do need to set the two equal, try using == instead of =

..does this mean that the syntax should be:

$rec{'Contact_Email'} == $url{'Contact_Email'}

Ian

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
No promises, but I believe that's the syntax you want, just flip it around:

$url{'Contact_Email'} == $rec{'Contact_Email'};


However, it seems to me that setting a variable would be preferable:

$no_bold_email == $rec{'Contact_Email'};

Depending on where it's being placed, it might have to go within a loop to be updated as needed for each database record.

Dan

Quote Reply
Re: Removing <b> from $rec to allow links In reply to
I have got it working now - I'm not sure what's different today (as I'm sure I tried this yesterday), but solution is:

$url{'Contact_Email'} = $rec{'Contact_Email'};
$url{'Contact_Email'} =~ s/<\/?B>//g;

Ian