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

create new variable of domain from URL

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
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
The plugins I have installed are :

Adcycle 2.15
Bad_Links 2.2.1a
Category_Adverts 3.2
SimpleGlobal 1

Do you mean the hook 'display_link' (not 'link_display')? If so, I see it inside the 'hooks.cfg' file inside Plugins. It has the lines:

Code:
'display_link' => [
{
'subroutine' => 'Links::Link::HTML::display',
'hook_name' => 'display_link',
'filename' => '(eval 4)',
'input_params' => [
'HASH'
],
'output_params' => [
'SCALAR'
],
'description' => '',
'line' => '42',
'path' => './Plugins'
},
{
'subroutine' => 'Links::Link::HTML::display',
'filename' => '(eval 14)',
'hook_name' => 'display_link',
'input_params' => [
'HASH'
],
'description' => '',
'output_params' => [
'SCALAR'
],
'line' => '20',
'path' => './Plugins'
},
{
'subroutine' => 'Links::Link::HTML::display',
'hook_name' => 'display_link',
'filename' => '(eval 4)',
'input_params' => [
'HASH'
],
'output_params' => [
'SCALAR'
],
'description' => '',
'line' => '91',
'path' => './Plugins'
},
{
'subroutine' => 'Links::Link::HTML::display',
'hook_name' => 'display_link',
'filename' => '(eval 13)',
'input_params' => [
'HASH'
],
'output_params' => [
'SCALAR'
],
'description' => '',
'line' => '27',
'path' => './Plugins'
}
],
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Yes, I meant the hooks but you can look at the Plugins/plugins.cfg file. I don't know much about the hooks.cfg

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
Nope, the Plungins/plugin.cfg file only has the hooks 'display_link' PRE and POST for SimpleGlobal
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Is there a Links plugin that tests if the hooks 'PRE' and 'POST' are working and returning the correct variables?
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
You can set a test site to test that.

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
I switched all the 'display_link' and 'display_link_pre' to 'form_link' and 'form_link_pre' in plugin.cfg and SimpleGlobal.pm and it was the same result when viewing the modify link page inside the admin area - the plugin works, no errors, but it shows a blank $domain value. Is there an alternative to this part of the code that would grab the current link's URL value some other way and place it between the brackets?

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


Do any of these have anything to do with it not working?
Perl version: 5.8.8
Gossamer Links version: 3.3.0
GT::Template version: 2.172
Running under mod_perl: No
Running under SpeedyCGI: No

Apache/2.2.14 (Unix)
mod_ssl/2.2.14
OpenSSL/0.9.8e-fips-rhel5
mod_bwlimited/1.4
PHP/5.3.1

Last edited by:

yo Huge: Mar 23, 2013, 11:49 PM
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
It should not rely on those. What are the page the domain does not have value?

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
In Links admin I select 'Database' and then on the left I select 'Links' and 'List All' and press 'GO' and this page loads in the frame showing each link record followed by the word 'Domain:' and no value after it


Code:
/links/admin/admin.cgi?keyword=*&Username=&ID=&ReviewID=&do=search_results&ID-opt=%3D&Username-opt=%3D&ReviewID-opt=%3D&db=Links&todo=search_results&keyid=
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
You're right. It is empty on glinks 3.3.x. My testing is on glinks 3.2.x Let me see what happened there. Or some other plugins cause that. The current version is not correct. Please use this one. So, the glinks' versions does not matter.

Cheers,

Dat

Programming and creating plugins and templates
Blog

Last edited by:

tandat: Mar 24, 2013, 3:05 AM
Quote Reply
Re: [tandat] create new variable of domain from URL In reply to
COOL! It works - yes, that version works now so i guess it was my links ver 3.3 that has some coding changes from ver 3.2 that affected SimpleGlobal. THANKS!
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
In case you were wondering why on earth would I need the domain displayed from each link it's because I need to solve a link verifying problem. When I run 'verify links', if a site is no longer there and it's domain has gone back to its registrar, the registrar's default domain park page is displayed and so there wouldn't be an error 'page not found' and it wouldn't show up in the 'Bad Links' section in verify links results. I would just assume the site was still active there (unless I visited every site manually). So what I did is run an open source program called Thumbpage, a web page thumbnail generator using a text file of all my links and set it to grab a 640x480 screenshot of each site and save it to my PC in the format 'domain.com.png'. Then I uploaded them all to an image directory inside the admin section on my site. So with your plugin, I was able to change this line of code in SimpleGlobal.pm:

Code:
return qq|$out<br><br>Domain:&nbsp;&nbsp;$domain|;

To this:

Code:
return qq|$out<br><img src="/thumbs/$domain.png" width="640" height="480" />|;

Now when I view 'database' 'links' 'list all', every link in the database automatically matches up to its screenshot PNG file which is now shown under each link listing. So at a glance I can now see if a link is a real website or a domain park page and delete it. I just run the thumbpage program once a month. This way, I only have large screenshots of every site in the admin section, not thumbnails in the public section, which is what I wanted to do for now. Thanks again!
Quote Reply
Re: [yo Huge] create new variable of domain from URL In reply to
Also, if I did want to see the live site for each link listed, I would just change it to this:

Code:
return qq|<br><iframe src="$link->{URL}" scrolling="yes" width="1024" height="768" frameborder="0"></iframe><br>$out|;