Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Filtered Random Links

Quote Reply
Filtered Random Links
I have a number of links that are "placeholder" links that do not have valid URL's. They have a URL preface of http://site

The problem is the Random Link is choosing from these links.

How can I modify Jump.pm or other means to not choose those?

If needed, I can always add a column that is a "isRandomEnabled" boolean and propogate the column.

Any ideas are welcome!

Lance
Quote Reply
Re: [lancerasmussen] Filtered Random Links In reply to
Hi Lance,

As far as I know, you need to modify the Jump.pm or create a plugin to hook into that jump to do so.

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [lancerasmussen] Filtered Random Links In reply to
Hi,

It should be as easy as opening /admin/Links/User/Jump.pm, and finding:

Code:
if (lc $id eq "random") {
my $offset = int rand $links->count(VIEWABLE);
$links->select_options("LIMIT 1 OFFSET $offset");
my $sth = $links->select(qw/ID URL/ => VIEWABLE);
($id, $goto) = $sth->fetchrow_array;
}

..change it to add in the bit of code in red:


Code:
if (lc $id eq "random") {
my $offset = int rand $links->count(VIEWABLE);
$links->select_options("LIMIT 1 OFFSET $offset");
my $sth = $links->select(qw/ID URL/ => VIEWABLE, GT::SQL::Condition->new('URL','!=','http://site') );
($id, $goto) = $sth->fetchrow_array;
}

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] Filtered Random Links In reply to
Andy,

thanks.. I'll give that a try...

GT::SQL::Condition->new('URL','!=','http://site') );

Two questions tho:
1) If I have a -########## suffix added to the URL, which was the phone number, how I can check for just the first part.

or

2) The other choice could be to add a boolean column called Randomable in the table and then default it to YES. Then for the non-links, I can SQL set the existing links to NO. I'm assuming I can change URL to Random
Quote Reply
Re: [lancerasmussen] Filtered Random Links In reply to
Hi,

Quote:
Two questions tho:
1) If I have a -########## suffix added to the URL, which was the phone number, how I can check for just the first part.

Not sure what you mean?

Quote:
2) The other choice could be to add a boolean column called Randomable in the table and then default it to YES. Then for the non-links, I can SQL set the existing links to NO. I'm assuming I can change URL to Random

Sure, if you have a field called "Random" in the "Links" table, then you could change the conditioon to:

Code:
if (lc $id eq "random") {
my $offset = int rand $links->count(VIEWABLE);
$links->select_options("LIMIT 1 OFFSET $offset");
my $sth = $links->select(qw/ID URL/ => VIEWABLE, { Random =>1 } );
($id, $goto) = $sth->fetchrow_array;
}

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] Filtered Random Links In reply to
Thanks Andy,

I'll give the below a try, as it gives me a little more power to add certain links that are not actual URL's or are dead, but I want still listed.

Lance

Code:
if (lc $id eq "random") {
my $offset = int rand $links->count(VIEWABLE);
$links->select_options("LIMIT 1 OFFSET $offset");
my $sth = $links->select(qw/ID URL/ => VIEWABLE, { Random =>1 } );
($id, $goto) = $sth->fetchrow_array;
}
Quote Reply
Re: [Andy] Filtered Random Links In reply to
Andy,

maybe you or someone would have an idea on this. Once I have the link, I need to loop until I have a valid link. I keep getting server errors and don't quite see where I'm off.

Lance


Code:

# If we are chosing a random link, then get the total and go to one at random.
if (lc $id eq "random") {
# loop through, grabbing a new random ID until we found a link that is randomable
while (length($goto)= 0) {
my $offset = int rand $links->count(VIEWABLE);
$links->select_options("LIMIT 1 OFFSET $offset");
my $sth = $links->select(qw/ID URL/ => VIEWABLE, GT::SQL::Condition->new('isRandomable','=','Yes') );
($id, $goto) = $sth->fetchrow_array;
}
}
Quote Reply
Re: [lancerasmussen] Filtered Random Links In reply to
Hi,

Quote:
maybe you or someone would have an idea on this. Once I have the link, I need to loop until I have a valid link. I keep getting server errors and don't quite see where I'm off.

Not sure why you are taking this approach though?

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] Filtered Random Links In reply to
Well...

By just changing the code with the suggestion you added, appears to:
1) If isRandomable flag .... Jump to the URL
2) If not isRandomable flag.... Fall down and display a page saying No links were available.

This made sense in that it appears the original code is pulling the number of links available and randomizing the number from that.
Then it pulls the information from the link, if its available. With your suggestion, it looks like it will pull the information if it is available AND the isRandomable is set.

What I need to do is either:
1) keep looping until I hit a link that is available and isRandomable is set....

or

2) Query with the effect of
Select ID from Links
where Links.isRandomable = 'Yes'

Then then pick a random row from 0 to the query row count.
THEN pull the link info.