Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

create new variable of domain from URL

(Page 1 of 2)
> >
Quote Reply
create new variable of domain from URL
in the file "browser_link_list.html" there is this line with the URL variable:

"<a href="<%URL%>" target="_blank"><%URL%></a>"

I want to strip the "http://www." or the first 11 characters from the "URL" variable and create a new variable called "domain" and show this as plain text like this:

<font size="3"><%domain%></font>

Is there a way to do this in that html template page? the only thing I found online is an example of a vbscript function something like this:

<%
domain = URL
domain = Replace(URL, "http://www.", "")
Response.Write domain
%>

or this:

<%
domain = URL
domain = Mid(domain,11)
Response.write domain
%>

What's the code that would work with Links 2.0 and where would I place it for it to work? Thanks.
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Hi,

What is browser_link_list.html? I don't recognize that as a standard template

Code:
<%
domain = URL
domain = Replace(URL, "http://www.", "")
Response.Write domain
%>

or this:

<%
domain = URL
domain = Mid(domain,11)
Response.write domain
%>

That won't work - as the Links2 template system isn't vbscript :) If you can find the right place, you could easily add some perl code in to remove the http://www. part, and then pass it in as a new variable (i.e <%domain2%>)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] create new variable of domain from URL In reply to
Hi,

In Gossamer Links Admin - ver 3.3.0 at the top menu there's a 'Browse' link which loads the category browse menu on the left and loads the 'browser_link_list.html template in the main window. This shows all the links as title, URL, edit, delete, move, copy, owner.

The file location is cgi-bin/links/admin/templates/browser/

I'm looking for the asp code that would do it and also where to place it.
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Hi,

Gossamer Links and Links 2 are totally separate scripts :) I've moved this question into the correct forum for you.

If you can actually see this part in the template:

Code:
<font size="3"><%domain%></font>

Then I'd suggest making a new global to do what you want. Example:

remove_leading_http
Code:
sub {
my $tmp = $_[0];
$tmp =~ s|https?\://(www.)?||;
return $tmp;
}

Then in the template, change it to:

Code:
<font size="3"><%remove_leading_http($domain)%></font>

Untested, but should work.

Hope that helps

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] create new variable of domain from URL In reply to
Thanks for your help!

I added the global and then added the html into the template but when i refreshed the page I got this error:

Error: Variable 'remove_leading_http' is not a code reference

Do you know what that means?

Edit:
I've tried other globals and what it looks like is globals won't work on the template 'browser_link_list.html' in the admin/templates/browser/ directory. How do I set it so they do?

Last edited by:

yo Huge: Mar 20, 2013, 6:11 PM
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Hi,

It seems that global is not existed. It should be working at that template. You can test it by put its calling in a simple test page in luna template or the current one

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Ok I tested it on the new.html template page and it works. So the global works, just not on the browser_link_list.html page. Could it be that Links isn't seeing that '/templates/browser/' directory when it goes through its globals? The top of the browser_link_list.html page show this:


Code:
<tr>
<td>
<font face="Tahoma,Arial,Helvetica" size="2">
<li><%if ExpiryDate < $TIME%><font color="red"><%endif%><%escape_html Title%><%if ExpiryDate < $TIME%></font><%endif%></li>
</font>
</td>
<td>
<font face="Tahoma,Arial,Helvetica" size="2"><a href="<%escape_html URL%>" target="_blank"><%escape_html URL%></a></font>


<br> <font size="3"><%remove_leading_http($URL)%></font>
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
You're right! The global is not loaded into browser template. I don't use the global creating page in admin much so that I did not realize that.

So, this can be put into a simple plugin and call it then? Somewhat like the ULTRAGlobals plugin from Andy

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
How would I create a plugin and call it?
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Hi,

Near the bottom of /admin/Plugins/ULTRAGlobals.pm, find:

Code:
1;

Add this just before it:

Code:
sub remove_leading_http {
my $tmp = $_[0];
$tmp =~ s|https?\://(www.)?||;
return $tmp;
}

Then call with:

Code:
<br> <font size="3"><%Plugins::ULTRAGlobals::remove_leading_http($URL)%></font>

That should work.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Here we go. The call should be

<%Plugins::SimpleGlobal::remove_leading_http($URL)%>

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Cool! it works in ULTRAGlobals. How would I modify the plugin code to also remove everything after the TDL for each domain? Example: to remove the "/home.html" or "/page1.htm"?
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
It can be changed like below:
Code:
sub remove_leading_http { my $tmp = $_[0]; $tmp =~ s|https?\://(www.)?||; $tmp =~ s|/.*$||g; return $tmp; }

Cheers,

Dat

Programming and creating plugins and templates
Blog

Last edited by:

tandat: Mar 21, 2013, 7:21 PM
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
YES! it works. Thanks.

I also wanted to call it from the page 'admin/Links/HTML/Links.pm under the section called 'sub _plg_display' but that's not a regular html template page either. There is some html where it says 'Categories'. How would I get the call to work within that html there? Would I have to set up an external include file there that would call the global?

Code:
sub _plg_display {
# -------------------------------------------------------------------
# Displays a record.
#
my ($self, $opts) = @_;
$opts->{code}->{LinkOwner} ||= \&disp_username;
$opts->{code}->{ExpiryDate} ||= \&disp_expiry;

my $hidden = sub { '' };
$opts->{code}->{ExpiryCounted} ||= $hidden;
$opts->{code}->{ExpiryNotify} ||= $hidden;
$opts->{code}->{LinkExpired} ||= $hidden;

my $out = $self->SUPER::display($opts);
if ($opts->{mode} =~ /$SHOW_CAT_LIST/o) {
my $id = $opts->{values}->{ID};
if ($id) {
my $font = $self->{font};
my $output = $self->disp_categories($id);
$out .= qq~
<p><table border=1 cellpadding=0 bgcolor="#FFFFFF" cellspacing=0 width="500"><tr><td>
<table border=0 bgcolor="#FFFFFF" width="500"><tr>
<td width="20%" valign="top"><font $font>Categories</td>
<td width="80%"><font $font>$output</td>
</tr></table>
</td></tr></table>
~;
}
}
return $out;
}
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
There is no template for that page. The best to do is to use the hook 'display_link' and attache the html code into that page.

Cheers,

Dat

Programming and creating plugins and templates
Blog

Last edited by:

tandat: Mar 22, 2013, 12:41 AM
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Could you explain a little more on how to do that? Thanks for all your help
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
I have amended the plugin to have that hook and its function.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Ok I installed the plugin - no errors on running except that no domain is displayed after the text 'Domain: '.

Just this one line needs correcting:

Code:
my $domain = remove_leading_http($link->{URL});

When I tested an absolute value it worked fine and displayed the domain. ie:

Code:
my $domain = remove_leading_http("http://www.domain.com");

So it seems it's just not grabbing the URL variable for the current link or something.
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
My code should be correct. The $link->{URL} is the URL of current link. The $link has been captured in the sub above the 'pre' hook.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Ok I've tried several options and it seems it's something to do with this:

Code:
sub display_link_pre{
$link = $_[1]->{values};
}
Could my version of Links be using different variable names?
How can I see the variable's contents?
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Try this version please!

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
That version is installed and the script is working ok, no errors, it just seems that $link is not being passed into SimpleGlobal.pm so it stays empty.

Code:
use vars qw/$link/;


Edit: I think I might have found something. The 'display_link_pre' doesn't exist anywhere on my site except in SimpleGlobal.pm

Last edited by:

yo Huge: Mar 22, 2013, 6:15 PM
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
I tested on my glinks. It's working fine. Make sure that the hooks 'link_display' PRE and POST are checked.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Yes, the two hooks are checked. I guess it's a problem with my Links settings somewhere then. I'm using Gossamer Links 3.3.0. Which version did you get it working on?
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
The version should not be problem. Do you use any other plugins which also have the hook link_display (pre)?

Cheers,

Dat

Programming and creating plugins and templates
Blog
> >