Gossamer Forum
Home : Products : Links 2.0 : Customization :

One problem figured out :)

Quote Reply
One problem figured out :)
I figured out one problem I posed on this board awhile back - how to compile a list of the top hit listings - in my case, top 2. I've added the following to the nph-build.cgi script at the beginning of the 'main' subroutine:

Code:
open(FILE, "/home/serve/links/scripts/addlink/admin/data/url.db");
@rinfo = <FILE>;
close(FILE);
$rdata = @rinfo;
for ($ra = 0; $ra < $rdata; $ra++) {
chomp(@rinfo[$ra]);
($rID[$ra], $rURL[$ra], $rhits[$ra], $rmisc[$ra]) = split(/\|/,@rinfo[$ra]);
}
for ($ra = 0; $ra < $rdata; $ra++) {
for ($rb = ($rdata - 1); $rb > $ra; $rb--) {
if ($rhits[$rb] > $rhits[$rb-1]) {
$rtemp3 = $rhits[$rb-1];
$rhits[$rb-1] = $rhits[$rb];
$rhits[$rb] = $rtemp3;
$rtemp4 = $rURL[$rb-1];
$rURL[$rb-1] = $rURL[$rb];
$rURL[$rb] = $rtemp4;
}
}
}
$referer1=$rURL[0];
$referer2=$rURL[1];

Yeah Smile This gives me the daily (based on previous day results) top 2 which are linked at the top of each index.html page (generated by site_html.cgi). And of course this can very easily be modified to write X number top sites to a file.

Now, my other question - can anyone help me convert (standardize) the hits to daily hits. This is critical in my case as listings are ordered in descending numerical order from highest hits to lowest hits.

Thanks... Dan Smile
Quote Reply
Re: One problem figured out :) In reply to
thanks dan! but two questions...is that all of the code i need?? or do i need also the one in your original post? Also where would I put this at? in nph-build.cgi? Thanks! :~)
Quote Reply
Re: One problem figured out :) In reply to
Hi:

Replace the original code fragment (in the first message here) with this one. And place the code in the nph-build.cgi script at the beginning of the 'main' subroutine.

Dan Smile

BTW, I've not tested the output to topreferers.db file (new bit I added for you) so get back to me after you installed the code and tested it.
Quote Reply
Re: One problem figured out :) In reply to
LOL...I guess I should have tried it out before asking the question!! Great script...it works out perfecttly!! I just have one more question. I am going to use the top ten.db to print it out to a ticker. The ticker needs certain parameters such as this one I already have in the old text file:

Code:
^^pause(1500)
^^setURL (http://www.atomicarchive.com/main.html)
^^setspeed(5)
5. The Atomic Archive

This would be needed to be put before every link...where at in the script would I insert this to be printed in the .db? Also, is it possible to get the number printed before the link (eg: number 7 link gets at 7. before it?) Thanks a lot again!! :~)

Joseph Gruber
Quote Reply
Re: One problem figured out :) In reply to
hey dan Smile) great job on the script...now if i wanted to modify it so it would print the top ten links to a flat text file how would i do that? i understand about putting 8 more: $refer3=... but how would i get it to go into the text file? Let me know! Thanks! :~)
Quote Reply
Re: One problem figured out :) In reply to
Code:
open (FILE, "/home/serve/links/scripts/addlink/admin/data/url.db") or die("Error [nph-build.cgi]: Cannot open url.db file to compile top referers list.");
@rinfo = <FILE>;
close(FILE);
$rdata = @rinfo;
for ($ra = 0; $ra < $rdata; $ra++) {
chomp(@rinfo[$ra]);
($rID[$ra], $rURL[$ra], $rhits[$ra], $rmisc[$ra]) = split(/\|/,@rinfo[$ra]);
}
for ($ra = 0; $ra < $rdata; $ra++) {
for ($rb = ($rdata - 1); $rb > $ra; $rb--) {
if ($rhits[$rb] > $rhits[$rb-1]) {
$rtemp3 = $rhits[$rb-1];
$rhits[$rb-1] = $rhits[$rb];
$rhits[$rb] = $rtemp3;
$rtemp4 = $rURL[$rb-1];
$rURL[$rb-1] = $rURL[$rb];
$rURL[$rb] = $rtemp4;
}
}
}

open (FILE, ">/home/serve/links/scripts/addlink/admin/data/topreferers.db") or die("Error [nph-build.cgi]: Cannot open topreferers.db file to compile top referers list.");
for ($count = 0; $count < 10; $count++) {
print FILE "$rURL[$count]\n";
}
close (FILE);

I haven't tested it but it should work.

Dan Smile


[This message has been edited by dan (edited January 28, 1999).]
Quote Reply
Re: One problem figured out :) In reply to
To include the site name, we have to switch to the links.db file. I'll have to get back to you later today or tomorrow as I'm kinda busy modifying 2 scripts.

Dan Smile
Quote Reply
Re: One problem figured out :) In reply to
Thanks a lot!! :~)
Quote Reply
Re: One problem figured out :) In reply to
Code:
open (FILE, "/home/serve/links/scripts/addlink/admin/data/links.db")
or die("Error [nph-build.cgi]: Cannot open url.db file to compile top referers list.");

flock (FILE, 2);
@rinfo = <FILE>;
close(FILE);
$rdata = @rinfo;

for ($ra = 0; $ra < $rdata; $ra++) {
chomp(@rinfo[$ra]);
($rID[$ra], $rtitle[$ra], $rURL[$ra], $rdate[$ra], $rdir[$ra], $rdesc[$ra], $rmisc1[$ra],
$remail[$ra], $rhits[$ra], $rmisc2[$ra], $rmisc3[$ra]) = split(/\|/,@rinfo[$ra]);
}

for ($ra = 0; $ra < $rdata; $ra++) {
for ($rb = ($rdata - 1); $rb > $ra; $rb--) {
if ($rhits[$rb] > $rhits[$rb-1]) {
$rtemp3 = $rhits[$rb-1];
$rhits[$rb-1] = $rhits[$rb];
$rhits[$rb] = $rtemp3;
$rtemp4 = $rURL[$rb-1];
$rURL[$rb-1] = $rURL[$rb];
$rURL[$rb] = $rtemp4;
}
}
}

open (FILE, ">/home/serve/links/scripts/addlink/admin/data/topreferers.db")
or die("Error [nph-build.cgi]: Cannot open topreferers.db file to compile top referers list.");

for ($count = 0; $count < 10; $count++) {
print FILE "^^pause(1500)\n";
print FILE "^^setURL ($rURL[$count])\n";
print FILE "^^setspeed(5)\n";
print FILE "$count. $rtitle[$count]\n";
}
close (FILE);

Try that. Again, I've not tested the modified code. BTW, you probably could insert the code elsewhere and you could use the pre-defined links arrays ($db-cols[]). I believe they are not defined at this point. But if it works (as clumsy the code is), it works.

Dan Smile


[This message has been edited by dan (edited January 28, 1999).]
Quote Reply
Re: One problem figured out :) In reply to
Hi Dan! It works out really well. I only had to make two slight modifications to it. The first one was that the order I needed the code in was wrong (but that was my fault). Secondly, you started $count at 0...it should have been 1. With the 0 I was getting a 0.) Site Here. I have only one more problem I can't seem to figure out. The number one (most hits) link is shown in the db as the first one but after that no links are input into it. I have included an example on my site of topreferers.db at linksgalore.virtualave.net/topten.txt and also here is the code I am currently using. Can you see what is wrong?

<pre>
sub build_top_ten {
# Builds the top ten directory
open (FILE, "$db_script_path/data/links.db")
or die("Error [nph-build.cgi]: Cannot open url.db file to compile top referers list.");
flock (FILE, 2);
@rinfo = <FILE>;
close(FILE);
$rdata = @rinfo;
for ($ra = 0; $ra < $rdata; $ra++) {
chomp(@rinfo[$ra]);
($rID[$ra], $rtitle[$ra], $rURL[$ra], $rdate[$ra], $rdir[$ra], $rdesc[$ra], $rmisc1[$ra],
$remail[$ra], $rhits[$ra], $rmisc2[$ra], $rmisc3[$ra]) = split(/\|/,@rinfo[$ra]);
}
for ($ra = 0; $ra < $rdata; $ra++) {
for ($rb = ($rdata - 1); $rb > $ra; $rb--) {
if ($rhits[$rb] > $rhits[$rb-1]) {
$rtemp3 = $rhits[$rb-1];
$rhits[$rb-1] = $rhits[$rb];
$rhits[$rb] = $rtemp3;
$rtemp4 = $rURL[$rb-1];
$rURL[$rb-1] = $rURL[$rb];
$rURL[$rb] = $rtemp4;
}
}
}
open (FILE, ">$db_script_path/data/topreferers.db")
or die("Error [nph-build.cgi]: Cannot open topreferers.db file to compile top referers list.");
for ($count = 1; $count < 10; $count++) {
print FILE "^^setspeed(5)\n";
print FILE "^^setURL ($rURL[$count])\n";
print FILE "^^pause(1500)\n";
print FILE "$count. $rtitle[$count]\n";
}
close (FILE);
}
</pre>

If you (or anybody else for that matter) has any suggestion it would be appreciated. Thanks for helping me out with this mod!! :~)



------------------
Joseph Gruber
http://linksgalore.virtualave.net

~To be or not to be...which is better?~


[This message has been edited by USFJoseph1 (edited January 29, 1999).]
Quote Reply
Re: One problem figured out :) In reply to
Like I say, the code is clumsy but the solution is simple:

Code:
for ($ra = 0; $ra < $rdata; $ra++) {
for ($rb = ($rdata - 1); $rb > $ra; $rb--) {
if ($rhits[$rb] > $rhits[$rb-1]) {
$rtemp3 = $rhits[$rb-1];
$rhits[$rb-1] = $rhits[$rb];
$rhits[$rb] = $rtemp3;
$rtemp4 = $rURL[$rb-1];
$rtemp5 = $rtitle[$rb-1];
$rURL[$rb-1] = $rURL[$rb];
$rURL[$rb] = $rtemp4;
$rtitle[$rb-1] = $rtitle[$rb];
$rtitle[$rb] = $rtemp5;
}
}
}

Try that... Dan Smile
Quote Reply
Re: One problem figured out :) In reply to
Like I say, the code is clumsy but the solution is simple:

Code:
for ($ra = 0; $ra < $rdata; $ra++) {
for ($rb = ($rdata - 1); $rb > $ra; $rb--) {
if ($rhits[$rb] > $rhits[$rb-1]) {
$rtemp3 = $rhits[$rb-1];
$rhits[$rb-1] = $rhits[$rb];
$rhits[$rb] = $rtemp3;
$rtemp4 = $rURL[$rb-1];
$rtemp5 = $rtitle[$rb-1];
$rURL[$rb-1] = $rURL[$rb];
$rURL[$rb] = $rtemp4;
$rtitle[$rb-1] = $rtitle[$rb];
$rtitle[$rb] = $rtemp5;
}
}
}

Try that... Dan Smile
Quote Reply
Re: One problem figured out :) In reply to
Hi Dan! I tried it and it still did the same thing. With my db only having 2 links I decided to add a "fake" link and see what would happen. Guess what? Two links are in topreferers.db! I know its one of those number things like the $count=0 was but which one is it?

Joe Smile

[This message has been edited by USFJoseph1 (edited January 30, 1999).]