Gossamer Forum
Home : Products : Links 2.0 : Customization :

Top Ten Sites Mod

Quote Reply
Top Ten Sites Mod
We installed this some time ago. Checked that it was working and left it at that.

However, one thing we were remiss in - we have sites that have no url's and they are showing in the top ten. (Not sure how). Anyways the link that it points to is links-pages/Ratings..

The easiest way to handle this would be to have the mod ignore entries with no url.



New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
Hey Ian,

Not sure why those listings would show up, that's kind of strange. Anyway, are you using the isLinked mod, or did you just create an additional field to define sites without url's. It doesn't really matter either way. I'm assuming you want only the listings with url's to appear? Are you using the top 10 via ssi or is it the built in one? I think there both pretty much the same anyway...let me know the name of the field and I'll throw something up that you can use....if you still need to fix it that is...


Quote Reply
Top Ten Sites Mod In reply to
Greetings Domenic

1. Yes we are using the Islinked mod.
2. Built in one AnthroRules mod I think.

Here is the code in the site_template.pl and from memory there is also some code in the nph_build file as well.

sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites
open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {if ($count <= 10) {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>
\n";
}$count++;
}
return $output;
}

The mod is called on the page by <%topsites%>

Any assistance appreciated.

New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
Unfortunately...the Mod that I wrote AS IS will not properly print records with NO URL...so, you will need to add conditional statements into the Mod I wrote and also call the appropriate column in the %db_def to call the isLinked field.

Good luck!

Regards,

Eliot Lee
Quote Reply
Re: Top Ten Sites Mod In reply to
This should work for you...

Define your field:
$isLinked{$data[0]} = $data[14];

change 14 above to match your field number.

Then replace yours with this:

my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 100) {
if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}
$count++;

....I'm not sure about what you added to the build file, but you shouldn't need to add anything.

Quote Reply
Top Ten Sites Mod In reply to
Greeting Again Domenic!

Not sure as to where to place this;

Define your field:
$isLinked{$data[0]} = $data[14];

If in the site_template.html.pl, you mean replace this under the globals - topsites => &top_ten,

If it is in the links.def you mean then it would replace this:

isLinked => [21, 'alpha', 0, 5, 0, 'No', 'No|Yes']

The other code I understand where to place that.

Many thanks

New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
See the file you posted above....look for this area:

$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
$isLinked{$data[0]} = $data[14];

...place it just like above...14 stands for the number in your link.def file...yours maybe different, so check it out!

Quote Reply
Re: Top Ten Sites Mod In reply to
Hi Domenic!

Apologises - should of seen what you meant.

Anyways here is the whole code now:

sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites
open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[8];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
$isLinked{$data[0]} = $data[21];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {
if ($count <= 10) {
if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}$count++;
}
return $output;
}

And it comes up with this error when I run build
Error including libraries: Missing right bracket at /home/nzcid/cgi-bin/links2/admin/site_html_templates.pl line 736, at end of line
syntax error at /home/nzcid/cgi-bin/links2/admin/site_html_templates.pl line 736, at EOF

It is missing a right bracket somewhere..




New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
Must have missed one it should look like this:

if ($count <= 10) {
if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}
$count++;
}
}
return $output;

...that should do it for ya!

Quote Reply
Re: Top Ten Sites Mod In reply to
Thanks Domenic that fixed the build issue..

Check this out though

http://www.nzcid.org.nz/links2-pages/Ratings/

Now we have no sites listed in the Top Ten :) :)


New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
In trouble shooting this I went back through the codes and found there was one mistake I had not picked up.. It was the data field no for the hits which was still setup at 8 when mine is 15. Rectified this and rebuilt but still no top ten sites. Though I cannot figure out how the mod was working at all for the data field no for hits has always been 15 not 8 LOL.. Never mind though.

Here is the total code I have now.

sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites
open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[15];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
$isLinked{$data[0]} = $data[21];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {if ($count <= 10) {if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}$count++;
}
}
return $output;
}

New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
Okay...I thought that you guys/gals would figure it out...when I stated "conditional statements", I meant that you have to check BOTH the YES/NO values of the isLinked field.

Change the following codes:

Code:

if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}


To the following:

Code:

if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}
if ($isLinked{$field} eq "No") {
$output .= "$count. $name{$field}\n";
}


Hope this helps.




Regards,

Eliot Lee
Quote Reply
Top Ten Sites Mod In reply to
Ian says Greetings Elliot as he takes off his hat and gives a salute

Guess what - I added that part as well and still no top ten :-)

Here is all the code again with your bit added..

######################
# Top Ten Sites Mod
#####################
sub top_ten {
#-------------------------------------------
# Insert Top Ten Sites
open (NAME,"<$db_file_name") or &cgierr("error in numlinks. unable to open database:$db_links_name.\nReason: $!");
LINE: while(<NAME> ){
next LINE if (/^#/);
next LINE if (/^\s*$/);
@data=split (/\|/);
$tophits{$data[0]} = $data[15];
$name{$data[0]} = $data[1];
$url{$data[0]} = $data[2];
$isLinked{$data[0]} = $data[21];
}
close (NAME);
my $count=1;
foreach $field (sort { $tophits{$b} <=> $tophits{$a} } keys %tophits) {if ($count <= 10) {if ($isLinked{$field} eq "Yes") {
$output .= "$count. <a href=\"$url{$field}\" target=\"_blank\">$name{$field}</a>\n";
}
if ($isLinked{$field} eq "No") {$output .= "$count. $name{$field}\n";
}
$count++;
}
}
return $output;
}

1;

New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
LOL LOL In trouble shooting this more - I thought what I would do is change in the orginal mod the data field for the hits to the correct field 8 to 15. I changed nothing else in the orginal mod and did a rebuild and hey presto up came the top ten sites. All of these are ones with urls there is no entries showing that have no urls.

When I think about your mod Elliot people would only be clicking on entries with urls therefore registering hits. They would not be clicking on entries that have no hyperlink. The mod is designed to pick up those that have hits registered against them and the entries without hyperlinks would not have any hits against them so the mod should not pick them up.

I guess because the data field was wrong it was picking up the wrong info and mucking up the mod somehow.

HEY thanks to both of you Domenic and Elliot for helping me.

Blessings to you both and I will leave it like that for the time being and not waste any more of your time with it.

New Zealand Christian Internet Directory
Quote Reply
Re: Top Ten Sites Mod In reply to
Welp...glad you figured it out...and BTW: You could use info.cgi Mod to register HITS for links that do not have URLs.

Good luck!

Regards,

Eliot Lee
Quote Reply
Info.cgi In reply to
I guess thats in the resource centre - I will pop on over and see what it does - thanks again bro..

New Zealand Christian Internet Directory
Quote Reply
Re: Info.cgi In reply to
Well...you have to hack it a bit...and yes, it is located in the Resource Center.

Regards,

Eliot Lee
Quote Reply
Re: Info.cgi In reply to
LOL....it sounded kind of strange that sites were showing up with no hits...well glad you figured it out.

BTW - Eliot, you DO NOT have to check BOTH the YES/NO values...it works well either way.
Quote Reply
Re: Info.cgi In reply to
Uh...YEA YOU DO! Mad

Regards,

Eliot Lee
Quote Reply
Re: Info.cgi In reply to
UH>>>>>>>NO YOU DON'T!! Mad