Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

What about this one Pugdog/Eliot?

Quote Reply
What about this one Pugdog/Eliot?
Hi and thanks for your help so far - even though that problem with the numbered links remains unsolved (at the mo).

Anyway in my search and category results I am displaying each link as:

1. Some Title Here
this is the description of this site
URL: http://www.whatever.com
Rating: 10 (Vote Now!)


The problem is that some of the sites in my database have very long URLs and I want a way to crop(truncate) the displayed url. Therefore if it's more than 25 characters long it will just add "..."


http://www.verlongdomain.com/veryverylong/verylong.html


would become


http://www.verlongdomain.com/veryverylo...


Does anyone think this can be done? If so - how?

JeffB

PS - how do you format "code" on this forum, it's not in the FAQs?!


Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
In Reply To:
PS - how do you format "code" on this forum, it's not in the FAQs?!
Duh...yea..it is...look at the pre anchors in the FAQ.

Wink

And for shortening your text, you will have to use length codes...Search http://www.perl.com for information about length. And also the easiest solution is to use the following codes:

Code:

URL: <a href="<%URL%>">Click here</a>


Regards,

Eliot Lee

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
The thing with counting the links in a category is solved, search the forum or send a mail; i have something similar running, but with some more things around (saving the rank, rank_old and show both)
At the moment im deep in my sql, but hope to write the doku next days for www.adeva.de/links.htm


Robert

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Jeff,

Perl has many functions for modifying strings.

You'd want to create a new hash entry "URL_S" just before you send the link to the Link.html template (you could probably do it in the HTML_Templates.pm file).

You'd want to do something like:

$rec->{URL_S}=substr($rec->{URL}, 0, 32) . "... "; ## corrected 8/1/00

That way you can still use the HTML tags:

Code:
<A HREF=<%URL%>><%URL_S%></A>
To reference the url.



http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Where about in HTML_Templates.pm would that line go? I looked through the file but couldn't find the place for hashes?

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
I can't access my ftp directories at the moment to check the exact name, but the sub would be something like sub site_html_link

(Wherever the link is built).

You'll see the call to &load_template, and you'll see it passing the %rec, %GLOBALS, and other parameters. Before that line, just add a new entry to the %rec hash before it's passed. that automatically becomes a "tag" available in the template being parsed.


http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Pugdog,

I tried adding it in a couple of places that you suggested by either got a URL_S tag unknown in my search results page or Software Error on the build.

Here is the part of HTML_Template.pm:

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like. Due to overhead, you can't use user variables here, only
# on main pages.
#
my ($rec, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $rec eq 'HASH') or croak "HTML_TEMPLATES: Argument '$rec' must be hash reference";

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


# Figure out how many days old it is if it's a new link.
if ($LINKS{build_days_old}) {
if ($rec->{'isNew'}) {
$rec->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $rec->{'Add_Date'});
}
else { $rec->{'Days_Old'} = ''; }
}
my $user = {};
defined $dynamic and &load_user ($dynamic, $user, $rec->{CategoryID});
my $output = &load_template ('link.html', {
detailed_url => "$LINKS{db_detailed_url}/${$rec}{'ID'}$LINKS{build_extension}",
%$rec,
%$user,
%GLOBALS
}, undef, $template);
# Don't clean output on a single link.
return $output
Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Right after the "set new and/or pop"lines:

$rec->{URL_S} = substring($rec->{URL}, 0, 32) . '... ';

should create a new hash entry "URL_S" that is a tag in the link.html template.

If you are trying to do that in the detailed.html template as well, you'd have to add that line to the same routine there.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
I did that but got this error when building:


Software error:
Undefined subroutine &Links::HTML_Templates::substring called at Links/HTML_Templates.pm line 82.


What's wrong? Here is the modified routine:

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like. Due to overhead, you can't use user variables here, only
# on main pages.
#
my ($rec, $dynamic) = @_;
my $template = defined $dynamic ? $dynamic->param('t') : undef;
(ref $rec eq 'HASH') or croak "HTML_TEMPLATES: Argument '$rec' must be hash reference";

# Set new and pop to either 1 or undef for templates.
($rec->{'isNew'} eq 'Yes') ? ($rec->{'isNew'} = 1) : (delete $rec->{'isNew'});
($rec->{'isChanged'} eq 'Yes') ? ($rec->{'isChanged'} = 1) : (delete $rec->{'isChanged'});
($rec->{'isPopular'} eq 'Yes') ? ($rec->{'isPopular'} = 1) : (delete $rec->{'isPopular'});
$rec->{URL_S} = substring($rec->{URL}, 0, 32) . '... ';


# Figure out how many days old it is if it's a new link.
if ($LINKS{build_days_old}) {
if ($rec->{'isNew'}) {
$rec->{'Days_Old'} = &Links::DBSQL::date_diff (&Links::DBSQL::get_date(), $rec->{'Add_Date'});
}
else { $rec->{'Days_Old'} = ''; }
}
my $user = {};
defined $dynamic and &load_user ($dynamic, $user, $rec->{CategoryID});
my $output = &load_template ('link.html', {
detailed_url => "$LINKS{db_detailed_url}/${$rec}{'ID'}$LINKS{build_extension}",
%$rec,
%$user,
%GLOBALS
}, undef, $template);
# Don't clean output on a single link.
return $output;
}
Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
It told you exactly what the error was... I was typing too fast.

change the 'substring' to 'substr'

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Pugdog

I changed the typo and it builds fine and the URLs are showing up. But the URLs are not being truncated - even when I change 32 to 20 the very long URLs are still being shown in their full length. Is there something else that needs to change? I am using <%URL_S%> in my link.html template and everything is set up like you said?!

JeffB

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Did you remember to change the link.html and detail.html template to use the <%URL_S%> tag?

If you did, do me a favor, and put at the top of one of the templates

The short URL is: <%URL_S%> :to here

and tell me what it prints out. The first text at the top of the template should be what is in the string<%URL_S%>

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
OK, I took another look at this and now it seems to work BUT it is adding "..." to the end of all URLs even if they are very short. I changed the code in HTML_Template.pm so that the 32 becomes 45

$rec->{URL_S} = substr ($rec->{URL}, 0, 45) . '... ';

but it is still adding "..." to all URLs.

Pugdog? Help?

JeffB

JeffB

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
What you'd need to do is something like

Wrap the assignment in an if clause.

Code:
if (length($rec->{URL}) > 32) {
$rec->{URL_S} = substr ($rec->{URL}, 0, 32) . '... ';
} else {
$rec->{URL_S} = $rec->{URL};
}
That should catch every eventuality.

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Thank you - that works very well Smile

JeffB

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Would this work in Links 2?

JeffB

Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
If you mean the NG generation of Links SQL, then no and it would not work in Links 2.0 either.

Regards,

Eliot Lee
Quote Reply
Re: What about this one Pugdog/Eliot? In reply to
Until the final version is shown, we won't know what ALex has built in, and what it will take to use old mods.

Changes are inevitable, since the calling conventions have changed. Some things remain the same (basically) but the naming/calling has changed.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ