Gossamer Forum
Home : Products : Links 2.0 : Customization :

"links" without links?

Quote Reply
"links" without links?
Here's my problem:
I'd like to use "links" to make a yahoo like index of shops, the problem is they don't all have URLs, but if I try to enter a new item in the database it's refused because it lacks a URL. Is there a way to stop the script checking for a URL, so that if one is present it turns the item name into a link, if there is non, then the item name is just plain text?

Thanks
Quote Reply
Re: "links" without links? In reply to
Make the default (value="") for the URL field in the add form be "http://" so that the field always has something in it. That way, the check on that field will succeed but Links will not build a link for the field because it is incomplete. Actually, I think it will build a link for it, but the link will not go anywhere.

Or, as part of the build process, you could check the field (in sub site_html_link in site_html.pl/site_html_templates.pl) to see if it only has "http://" in the field, and if it does, just build the "link" without the anchor tag.

I hope this helps.
Quote Reply
Re: "links" without links? In reply to
Bobsie,

If I want the link to always be the detailed page <ID> for the entered infomation, I would define the URL field value to be "detailed_url" for the database.

mike

------------------
MIkeY !!!!!!!
Quote Reply
Re: "links" without links? In reply to
Mike,

I don't understand what that has to do with cob's question of how to make Links work when some of the resources have no URLs. He doesn't want a link listed for such resources.
Quote Reply
Re: "links" without links? In reply to
Here is what you do. You edit the Links.DEF file so that the URL is not required. Like this:

URL => [2, 'alpha', 45, 75, 0, '', '^http|news|mailto|ftp'],

Notice the "0" after the 75. That means that the field is NOT REQUIRED. The next '' rather than 'http://' means that the field defaults to nothing rather than the http thing.

Now what you need to do is edit the site_html.pl so that the site_html_link sub looks something like this:

my (%rec) = @_;

if ($rec{'URL'}) {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~$rec{'Title'}~);
}
else {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a>~);
}

That should fix it up for you.

------------------
TheByrdMan Out!

//-Tweet-\\

[This message has been edited by TheByrdMan (edited May 18, 1999).]

[This message has been edited by TheByrdMan (edited May 18, 1999).]
Quote Reply
Re: "links" without links? In reply to
Code:
if ($rec{'URL'}) {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~$rec{'Title'}~);
}
else {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a>~);
}

I think this is reversed from what you meant. If $rec{'URL'} means, if there is a URL, build an anchored link. The way you have it, it would build without the anchor and if there isn't a URL, then it will build the anchor. I think you meant:

Code:
if ($rec{'URL'}) {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a>~);
}
else {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~$rec{'Title'}~);
}
Quote Reply
Re: "links" without links? In reply to
This is EXACTLY what I need as well, with one small exception! I'd like for those that don't have a URL to just appear with the title and no link... primarily because I don't want to irritate people with a lot of links that either go nowhere or go to some notification file. Is this possible??

Thanks! Smile
Quote Reply
Re: "links" without links? In reply to
Joice,

The code listed above does exactly that. The line that looks like this:

Code:
($output = qq~$rec{'Title'}~);

will give you the "Title" without a link to anywhere. You will also need to do the thing to your Links.Def file where the URL is not REQUIRED so that you do not get an error message when leaving that field blank. With the code above you must have a BLANK URL for the link to NOT appear.

You may also want to add some color to the link as it will not be a link and thus be black (or whatever your text color is). Like this:

Code:
($output = qq~<font color="#090909">$rec{'Title'}</font>~);

------------------
TheByrdMan Out!

//-Tweet-\\


[This message has been edited by TheByrdMan (edited May 20, 1999).]
Quote Reply
Re: "links" without links? In reply to
ByrdMan,

Actually, nothing else need to be done in links.def if, as I said in my first reply, the value="http://" is included in the <input> tag on the user add form. The links.def file already contains a default for the field.

Here is how the code would look for Joyce to do what she wants:

Code:
if ($rec{'URL'} eq "http://")) {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~$rec{'Title'}~);
}
else {
$build_detailed ?
($output = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($output = qq~<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a>~);
}

I hope this helps.

[This message has been edited by Bobsie (edited May 20, 1999).]
Quote Reply
Re: "links" without links? In reply to
True enough. Either way works.

------------------
TheByrdMan Out!

//-Tweet-\\
Quote Reply
Re: "links" without links? In reply to
Thanks for the help.
What I need is what Joyce mentions: the title should be plain text and not hyperlinked when no URL has been included. Using all of the above examples, including the latest, it is still hyperlinked with a /jump.cgi?ID=12 (for ex), which means that when someone clicks on the link they get a "Error: Can't find link id: 12" message. I've tried playing with the code to change this but with no luck, my Perl knowledge is pretty basic.

Cheers.
Quote Reply
Re: "links" without links? In reply to
It doesn't work for me either... I'm using templates, does that make a difference?

My current code (before attempting the mod above) in site_html_templates.pl in the sub site_html_link secition is this:

sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

# Mod: adds logos to certain sites

my $logo_gif;

if ($rec{'logo'} eq "Yes") {
$logo_gif = $rec{'ID'} . ".gif";
}
else {
$logo_gif = "none.gif";
}

# Mod: end of mod

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});



return &load_template ('link.html', {
# Mod: more logo stuff

logo_gif => $logo_gif,
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}


=========================

Thanks for all your help... hope I can get this thing going! Smile

-Joyce
(who's perl is VERY limited)

[This message has been edited by Joyce (edited May 21, 1999).]

[This message has been edited by Joyce (edited May 21, 1999).]
Quote Reply
Re: "links" without links? In reply to
Joyce,

Here is how I would do it.

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

# Mod: adds logos to certain sites

my $logo_gif;

if ($rec{'logo'} eq "Yes") {
$logo_gif = $rec{'ID'} . ".gif";
}
else {
$logo_gif = "none.gif";
}

# Mod: end of mod

# Mod: Builds links only if more than "http://" is in URL

if ($rec{'URL'} eq "http://")) {
$build_detailed ?
($link_url = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($link_url = qq~$rec{'Title'}~);
}
else {
$build_detailed ?
($link_url = qq~<a href="$build_detail_url/$rec{$db_key}$build_extension">$rec{'Title'}</a>~) :
($link_url = qq~<a class="link" href="$build_jump_url?$db_key=$rec{$db_key}">$rec{'Title'}</a>~);
}

# Mod: end of mod

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ?
($rec{'isNew'} = 1) :
(delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ?
($rec{'isPopular'} = 1) :
(delete $rec{'isPopular'});

return &load_template ('link.html', {

# Mod: more logo and link stuff - detailed_url not needed

link_url => $link_url,
logo_gif => $logo_gif,
# detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}

Then, in link.html, I would change:

Quote:
<ul><li><a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"><%Title%></a>

to read:

Quote:
<ul><li><%link_url%>

Let me know how it goes. I hope this helps.
Quote Reply
Re: "links" without links? In reply to
Bobsie, you are AWESOME! That's exactly what I needed, though I can't use the logo-mod with it (I was linking the logo as well as the text... can't do that part). The site I wanted to do this with won't have the logo-mod anyway, so I'm a *very* happy girl! Thanks so much for your help. Smile

For anyone that uses the above code, there's a tiny typo on this line:
if ($rec{'URL'} eq "http://")) {

It should be:
if ($rec{'URL'} eq "http://") {

Thanks again Bobsie!
Quote Reply
Re: "links" without links? In reply to
I solved this somewhat differently. I try to minimize changes to nph-build.cgi, so I set the default for the URL field in links.def to nothing, and made the field not required; then I changed links.html to have the following:

<%if URL%>
<a class="link" href="<%db_cgi_url%>/jump.cgi?ID=<%ID%>"
onMouseOver="window.status='<%URL%>';return true">
<%endif%>

<%Title%>

<%if URL%>
</a>
<%endif%>


So if there is no URL, the Title will appear alone.

You can see it at http://library.ust.hk/info/databases/

-Spode


p.s. - One caveat - I am not as well-organized as Bobsie, and sometimes do not properly comment where I modify the code. Frown So it is possible that I also did something else which I don't recall.
Quote Reply
Re: [Bobsie] "links" without links? In reply to
Hi,

This is what I assumed happened when first fiddling around with Links 2.0 in regards to incomplete URL fields. Builds link but link does not go anywhere.

Unfortunately while I was fiddling around I seemed to have mucked this up. What would cause the URL [that has no url] to still jump and then return Cannot Find Server instead of just going nowhere?

I would like for it to return back to default, build link but link does not go anwhere. If anyone can shed some light on this I would greatly appreciate it.
Quote Reply
Re: [Saph] "links" without links? In reply to
Links actually builds a database of ID/URLs which is accessed by the jump.cgi to send the surfer to the link owner's site. See url.db in the data folder. It is built each time you run the "build" routine.

If the URL field is blank, then the jump goes to a non-existent website.

I am a little confused by what your problem is or what you are want to do ( But then I am ususally in a confused state of mind Crazy ).

If you look thru the posts to this thread, you will see a couple of solutions. You will have to either apply one of them or enter a vaild URL.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [esm] "links" without links? In reply to
Hi Gene,

In the second post of this thread Bobsie mentions " Actually, I think it will build a link for it, but the link will not go anywhere."

That is exactly what I thought, because when I was first testing the links it built a link, [even though the URL field was left blank.] When I clicked this link it didn't go anywhere. It just stayed on the same page.

Now that I've been modifying some things, when I do click a link that is the same as what I've mentioned above it tries to jump to a non-existent website as you said and obviously can't find it and returns a cannot find server.

Does it make any sense yet? [Sorry Blush.] So what Bobsie was saying I think is by default, now that I've messed it up somehow, instead of not going anywhere and staying on the same page it tries to go to a non existant url. I would like it to go back to default.

If I can't do this or I don't make much senseCrazy then I probably have to use one of the solutions in this thread, [but in the mean time I'd like to keep trying!]

Thanks Gene

Last edited by:

Saph: Mar 5, 2003, 3:39 PM
Quote Reply
Re: [Saph] "links" without links? In reply to
try adding a new link without the URL and then click on it and see what happens. If it gives you what you want, then change all the "non" links to be the same. If it doesn't work, they follow one of the suggestions.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."
Quote Reply
Re: [Saph] "links" without links? In reply to
well, I added a link with no URL to a a fairly clean Links. When I click on it it, I get a page cannot be displayed error. Unless you modified yours, I would assume you would have gotten the same thing. So I am not sure how you would have gotten something different before you "fiddled" around with links.

You will need to "require" a URL ( and add a URL to existing links ) or use one of the above suggested solutions.


Gene
"The older I get, the more I admire competence, just simple competence in any field from adultery to zoology."