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

Show random paid link

(Page 1 of 2)
> >
Quote Reply
Show random paid link
   
Hi,

I`d like to show a random paid link on all my linkssql pages, with info about title, desc and url.
Does anybody have an idea of how to accomplish this?

Regards,
Wilhelm
http://www.radiodirectory.com/
Quote Reply
Re: [wilhelm] Show random paid link In reply to
Hi

did you ever get this to work?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [wilhelm] Show random paid link In reply to
Hi,

This could be a global called <%random_listing%>. The show something <%r_listing%>. Not tested yet

Cheers,


sub {

my $db->table('Links');
my $time = time;
my $cond = GT::SQL::Condtion->new(
'ExpiryDate','>', $time,
'ExpiryDate', '<', 2147483647);
my $c = $db->count($cond);
my $r = rand($c);
$db->select_options("Limit $r,1");
my $row = $db->select($cond)->fetchrow_hashref;
return unless(defined $row);

my $r_listing = qq|<a href="$row->{URL}">$row->{Title}</a><br>$row->{Description}|;
return $r_listing;

}

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Show random paid link In reply to
Thanks the following works great.

But can I change it to use a certain template we have: link_short.html and not the r_listing?

sub {
my $db = $DB->table('Links');
my $time = time;
my $cond = GT::SQL::Condition->new('ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $c = $db->count($cond);
my $r = rand($c);
$db->select_options("Limit $r,1");
my $row = $db->select($cond)->fetchrow_hashref;
return unless(defined $row);
my $r_listing = qq|<a href="$row->{URL}">$row->{Title}</a><br>$row->{Description}|;
return $r_listing;
}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Show random paid link In reply to
Yes, you can change that to whatever you like.

Cheers,

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] Show random paid link In reply to
Thank you all

here is the final code:

sub {
my $db = $DB->table('Links');
my $time = time;
my $cond = GT::SQL::Condition->new('ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $c = $db->count($cond);
my $r = rand($c);
$db->select_options("Limit $r,1");
my $row = $db->select($cond)->fetchrow_hashref;
return Links::SiteHTML::display('link_featured', $row);
}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Show random paid link In reply to
The following emended code will prevent duplications if you use the same code twice in one page..

sub {
# Displays the random featured links)
my $db = $DB->table('Links');
my $time = time;
my $cond = GT::SQL::Condition->new('ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $c = $db->count($cond);
my $r = int rand $c;
$db->select_options("Limit $r,1");
my $row = $db->select($cond)->fetchrow_hashref;
return Links::SiteHTML::display('link_featured', $row);
}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Show random paid link In reply to
Is there a way to alter the following code to display more than one link at a time with no duplications?

sub {
# Displays the random featured links)
my $db = $DB->table('Links');
my $time = time;
my $cond = GT::SQL::Condition->new('ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $c = $db->count($cond);
my $r = int rand $c;
$db->select_options("Limit $r,1");
my $row = $db->select($cond)->fetchrow_hashref;
return Links::SiteHTML::display('link_featured', $row);
}

We tried changing:
$db->select_options("Limit $r,1");
To
$db->select_options("Limit $r,2");

But that still displayes one link only.
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Show random paid link In reply to
You need to add in a while clause:

my $output;
$db->select_options("Limit $r,2");
while (my $row = $db->select($cond)->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link_featured', $row);
}
return $output;
}
Quote Reply
Re: [afinlr] Show random paid link In reply to
Thank you.

It is very odd..
Adding that code is sending page.cgi into a loop and crashing the server..

Is its the code or just a coincident?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Show random paid link In reply to
Can you paste the whole global that you are using now.
Quote Reply
Re: [katabd] Show random paid link In reply to
It Is

sub {
# Displays the random featured links)
my $db = $DB->table('Links');
my $time = time;
my $cond = GT::SQL::Condition->new('ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $c = $db->count($cond);
my $r = int rand $c;
my $output;
$db->select_options("Limit $r,2");
while (my $row = $db->select($cond)->fetchrow_hashref) {
$output .= Links::SiteHTML::display('link_featured', $row);
}
return $output;
}
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Show random paid link In reply to
Hi there,

I wonder if anybody can help? Perhaps using the global from above?

I'm using Links SQL 2.2.1 in dynamic setup.

How can I display a random paid / sponsored link at the top of its selected category? i.e. the paid links currently show in alphabetical order.
This is very annoying for the companies who are called Zebra Trading who always get listed below Apple Trading even though they have paid.
I wish to retain alphabetical sorting for unpaid links which show below the paid links.

Many thanks for any tips,
Best wishes,

Piers



Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

Maybe something like this would work:

Call with:

Code:
<%random_paid_in_category($category_id)%>
<%if random_link.length%>
<%loop random_link%>
<%include link.html%>
<%endif%>
<%endif%>


Then add this global:

random_paid_in_category

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isNew','=','Yes','isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/" . $DB->table('Links')->detailed_url( $hit->{ID} ); }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

push @links, $hit;
}

return { random_link => \@links }

}

Untested, but 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!

Last edited by:

Andy: Apr 24, 2008, 5:29 AM
Quote Reply
Re: [Andy] Show random paid link In reply to
Hi Andy,

Thanks for your help.

I added another if statement as this was causing an error without it (not sure if this is correct);
Code:
<%if random_paid_in_category($category_id)%>
<%if random_link.length%>
<%loop random_link%>
<%include link.html%>
<%endif%>
<%endif%>
but then got this error when added into category.html template;
"GT::SQL::Table (14571): Invalid category id: HASH(0x8841440) at /home/mysite/public_html/cgi-bin/admin/Links/Table/Category.pm line 406."

Not sure if this is helpful, but I change the formatting for the paid links by using this in links.html
Code:
<%payment_tags%>
<%if paymentsEnabled and not isFree%>
<%include include_paid_link.html%>

The payment_tags global contains this;
Code:
sub {
my $tags = GT::Template->tags;
if ($CFG->{payment}->{enabled}) {
my $expiry_date = $tags->{ExpiryDate};
my $rec;
$rec->{paymentsEnabled} = 1;
$rec->{isUnpaid} = $expiry_date == UNPAID;
$rec->{isFree} = $expiry_date == FREE;
$rec->{isExpired} = ($expiry_date > UNPAID and $expiry_date < time);
return $rec;
}
}

include_paid_link.html then formats the actual sponsored links differently.

Not quite sure where it is all going wrong?

Best wishes,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

You can't do it quite like that :)

You need another global - check_if_paid_exists .. with this code:

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isNew','=','Yes','isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $count = $db_obj->count ( $cond, $cond2 ) || die $GT::SQL::error;

return { num_paid_found => $count }

}

..then use this:

Code:
<%num_paid_found($category_id)%>
<%if num_paid_found > 0%>
. ..
<%endif%>

Untested, but 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!

Last edited by:

Andy: Apr 24, 2008, 5:29 AM
Quote Reply
Re: [Piers1] Show random paid link In reply to
BTW, I've updated both the above globals - so there were 2 spaces between sub and {

i.e should be:

Code:
sub {

but was like:

Code:
sub {

(having the 2 spaces would stop it being treated as a global =))

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] Show random paid link In reply to
Sorry Andy,
I've been playing with this for a while now and feel thick....
a) I'm trying to use just the last global you gave - or do I need to use both?
b) The second global is named 'check_if_paid_exists', but I don't understand how it is called in the category.html template which doesn't refer to it.
c) I'm assuming I should be adding the include to format the links in the code you gave like this?;
Code:
<%num_paid_found($category_id)%>
<%if num_paid_found > 0%>
<%include include_paid_link.html%>
<%endif%>
Apologies but thanks for your help,
Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Hi,

You need both :P

I'll put together a post with all the stuff you'll need - give me half hour though - need some breakfast first Smile

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: [Piers1] Show random paid link In reply to
Hi,

Ok, try this:

Ok, you need 2 globals:

1) random_paid_in_category

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isNew','=','Yes','isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $sth = $db_obj->select (['Links.*'], $cond, $cond2 ) || die $GT::SQL::error;

my @links;
while (my $hit = $sth->fetchrow_hashref) {

if ($CFG->{build_detailed}) { $hit->{detailed_url} = $CFG->{build_root_url} . "/" . $DB->table('Links')->detailed_url( $hit->{ID} ); }

if ($hit->{isNew} eq "Yes") { $hit->{isNew} = 1; } else { $hit->{isNew} = 0; }
if ($hit->{isPopular} eq "Yes") { $hit->{isPopular} = 1; } else { $hit->{isPopular} = 0; }
if ($hit->{isChanged} eq "Yes") { $hit->{isChanged} = 1; } else { $hit->{isChanged} = 0; }

push @links, $hit;
}

return { random_link => \@links }

}


2) check_if_paid_exists

Code:
sub {

my $cat = shift;
my $all_ids = $DB->table('Category')->children($cat);
push @$all_ids, $cat;

my $db_obj = $DB->table('Links','CatLinks','Category');
$db_obj->select_options ('ORDER BY Add_Date DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('isNew','=','Yes','isValidated','=','Yes','ExpiryDate','>', $time, 'ExpiryDate', '<', 2147483647);
my $count = $db_obj->count ( $cond, $cond2 ) || die $GT::SQL::error;

return { num_paid_found => $count }

}

..then use this:

Code:
<%num_paid_found($category_id)%>
<%if num_paid_found > 0%>
. ..
<%endif%>


Then, call with:

Code:
<%check_if_paid_exists($category_id)%>
<%if num_paid_found > 0%>
<%random_paid_in_category($category_id)%>
<%if random_link.length%>
<%loop random_link%>
<%include nclude_paid_link.html%>
<%endif%>
<%endif%>
<%endif%>


Again, untested - but thats how I would use it (from the 2 globals above)

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!

Last edited by:

Andy: Apr 25, 2008, 2:59 AM
Quote Reply
Re: [Andy] Show random paid link In reply to
Yikes - Got it - and called it from the link.html template, but get this;

Error: Variable 'num_paid_found' is not a code reference

That's where I'm confused, I don't see how the second global named "check_if_paid_exists" gets called in my templates?

Cheers,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Whoops, typo in the template code :D

You should be using

Code:
<%check_if_paid_exists($category_id)%>

..and NOT

Code:
<%num_paid_found($category_id)%>

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] Show random paid link In reply to
Ok makes more sense now, but getting a problem with the first global;

Code:
Died at (eval 39) line 13. Stack Trace
======================================
Links (6321): Links::environment called at /home/stagelink/public_html/cgi-bin/admin/Links.pm line 515 with no arguments.
Links (6321): Links::fatal called at (eval 39) line 13 with arguments
(Died at (eval 39) line 13.
).
Links (6321): Links::__ANON__ called at GT::Template::_call_func line 862 with arguments
(3044).
Links (6321): GT::Template::_call_func called at /home/stagelink/public_html/cgi-bin/admin/templates/stagelink/compiled/category.html.compiled line 501 with arguments
(GT::Template=HASH(0x883e62c), check_if_paid_exists, 3044).
Links (6321): GT::Template::parsed_template called at /home/stagelink/public_html/cgi-bin/admin/GT/Template.pm line 648 with arguments
(GT::Template=HASH(0x883e62c)).
Links (6321): GT::Template::_parse called at /home/stagelink/public_html/cgi-bin/admin/GT/Template.pm line 134 with arguments
(GT::Template=HASH(0x883e62c), category.html, HASH(0x8836610)).
more stuff here but not shown because it gets boring.....

Cheers,

Piers
Quote Reply
Re: [Piers1] Show random paid link In reply to
Can you send me a link, where I can see it in full? Can't tell much from that :)

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] Show random paid link In reply to
Andy,

Have sent you a PM with admin access etc and link to offending page.

Cheers,

Piers
> >