Gossamer Forum
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
Quote Reply
Re: [Piers1] Show random paid link In reply to
OK, took a while to work out why it wasn't working - but found some errors in the globals (also, you're using an old version of LSQL [2.1], so had a few tag issues =))

The final codes are:

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 RAND() DESC LIMIT 1');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('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} . "/Detailed/$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 }

}

check_if_paid_exists

Code:
sub {

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

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

# my $sth = $DB->table('Links','CatLinks','Category')->select ( $cond, $cond2 ) || die $GT::SQL::error;

# return $sth->query;

my $count = $DB->table('Links','CatLinks','Category')->count ( $cond, $cond2 ) || 0;

return { num_paid_found => $count }

}

..and the template code (category.html);

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 include_paid_link.html%>
<%endloop%>
<%endif%>
<%endif%>

Tested, and its all working as its mean't to now :)

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
.....oh Andy...

I agree this does work, but it only shows one paid link. Is it easy to show ALL of the paid links in the category but still retain the random display order?
I thought this was what the loop random_link did, but it only ever returns one random record, even when there is more then one paid link.

Sorry the pain continues,

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

Sorry - thought you only wanted one =)

Try it now (I just removed LIMIT 1) =)

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,

I think your time on this one is truly done.....

Thank you so much - it all works as I wanted,

Best wishes,

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

Glad it works 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: [Andy] Show random paid link In reply to
Andy,

I have upgraded my test site to Linksql 3.2.0 and of course want the random paid link to work once more!

One major difference - I now only have one type of link.html template (as I can do the paid formatting using the "isPaidLink" tag) called by category.html

I have used the same globals as before and inserted the code into category.html, but am a little stuck.

I get correctly showing random paid links (but they ignore the "isPaidLink" tag for the fancy formatting), and then I get the paid links ordered alphabetically with fancy formatting. Not quite sure how to move forward, but it is very close already.
Here is the relevant bit from my category.html template;
Code:
<%if links_loop.length~%>
<h3>Links</h3>
<%if paging.num_hits%><div class="paging"><%Links::Utils::paging()%></div><%endif%>

<%-- Start of Random Paid Links --%>
<%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 link.html%>
<%endloop%>
<%endif%>
<%endif%>
<%-- End of Random Paid Links --%>

<%loop links_loop~%>
<%include link.html%>
<%~endloop%>
This is a sample category from the test site which shows the problem;
Sample Category from test site

Could you take a look? - It would be much appreciated,

Best wishes,

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

So whats not working - the isPaidLink tag is not being passed in, or am I mis-understanding the problem?

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
Hi there,

Two problems;

1) I am seeing two lots of the paid links displayed in my categories. The first lot comes from your random global, and the second lot comes as standard.
How do I only display the paid links from your global, but still show the non paid links below them?

2) Some tags from your global are not being passed in;
isPaidLink
and if you own the link the 'Edit this Link', 'Renewal Payment' are also missing.

Cheers,

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

Please try this (for the second problem);

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 RAND() DESC LIMIT 10');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('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} . "/Detailed/$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; }

$hit->{isPaidLink} = 1;
$hit->{paymentsEnabled} = 1;

if ($hit->{LinkOwner} eq $USER->{Username}) {
$hit->{isLinkOwner} = 1;
}


push @links, $hit;
}

return { random_link => \@links }

}

...the first problem, I'm not sure there is a lot you can really do for 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!

Last edited by:

Andy: Aug 25, 2008, 3:39 AM
Quote Reply
Re: [Andy] Show random paid link In reply to
Almost....
I think I still need these tags to be passed through;

paymentsEnabled
isLinkOwner
isExpired
isUnpaid
wasPaid

However unless I can filter out the second display of paid links, then I have to stop using the whole global (which would be a pity as then random display of paid links has been requested by my users several times).

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

Regarding paymentsEnabled and isLinkOwner - try the modified version below.

Quote:
However unless I can filter out the second display of paid links, then I have to stop using the whole global (which would be a pity as then random display of paid links has been requested by my users several times).

So basically, you are on category.html - and you want to show this globals, BUT stop any of these ones, from showing up? There is a way of doing it - but it may add a lot more work for your server :/ (and, also it will mean that one or more links will be missed out - so instead of say showing 25 on the page, it may only show 20 - if there were 5 paid links on that page)

Code:
<%loop links_loop%>
<%set hasbeenshown = 0%>
<%loop random_link%>
<%if SavedID eq $ID%><%set hasbeenshown = 1%><%endif%>
<%endloop%>

<%if not hasbeenshown%>
<%include link.html%>
<%endif%>

<%endloop%>

..with this global:

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 RAND() DESC LIMIT 10');

my $time = time;
my $cond = GT::SQL::Condition->new('CategoryID', 'IN', $all_ids);
my $cond2 = GT::SQL::Condition->new('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} . "/Detailed/$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; }

$hit->{isPaidLink} = 1;
$hit->{paymentsEnabled} = 1;
$hit->{SavedID} = $hit->{ID}; # need to do this, otherwise cos of doing more than one loop of links - the ID will just get overwritten
if ($hit->{LinkOwner} eq $USER->{Username}) {
$hit->{isLinkOwner} = 1;
}


push @links, $hit;
}

return { random_link => \@links }

}

NB - not tested - so may not work Angelic

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,

1) The new category.html template code, results in just the standard links display without any random sorting of the paid links.

2) When logged in, ALL links in the Random Loop, I get offered the option to 'Sponsor Your Link' even for Links I don't own. The 'Edit Link' button does work correctly, so almost there.

Apologies - this is getting more involved then I expected.

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

For anyone intersted, heres how I did it:

redotheloop
Code:
sub {

my $random_loop = $_[0];
my $link_loop = $_[1];

my $ran_loop_ids;

foreach (@$random_loop) {
$ran_loop_ids->{$_->{ID}} = 1;
}

my @newlinks;
foreach (@$link_loop) {

if ($ran_loop_ids->{$_->{ID}}) {
# looks like this links in the random list - so ignore
} else {
push @newlinks, $_;
}
}

return { links_loop => \@newlinks }

}
..just add this into category.html:

Code:
<%redotheloop($random_link,$links_loop)%>

..just before the:

Code:
<%loop links_loop%>

..bit.

This basically weeds out the links that already exist in the priority listing stuff - thus they don't show 2 times =)

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!