Gossamer Forum
Home : Products : Links 2.0 : Customization :

Can't find solution...

Quote Reply
Can't find solution...
Just wanted first off to thank everyone for all their help in this forum. Without this forum I would have been lost plenty of times. Been using Links since 1998 and I couldn't live without the mods and the hacks :)

Anyways, I have looked through these forums for 4 days now... tried EVERYTHING I could find, read all the FAQ's, looked at all the problems the mods have had and found nothing on this problem that worked... so I am posting, this jump.cgi is driving me crazy.

The problem is this. I have my jump.cgi modified to jump to the detailed pages from the category pages instead of an outside URL. My database is setup so there is no outside URL's for any of the links, the URL part of the database is blank. The jump.cgi works perfectly for going from the category listing to the detailed pages but when I try to do a random link it gets a file not found.

This is my jump.cgi:


# =======================================================
#
# Form Input:
# '$db_key' = key number # Send as form input the key name and key value
# # of the link you want to go to.
#
# Setup:
# Make sure the require statement below points to the config file.

# Required Librariers
# --------------------------------------------------------
eval {
($0 =~ m,(.*)/[^/]+,) && unshift (@INC, "$1"); # Get the script location: UNIX /
($0 =~ m,(.*)\\[^\\]+,) && unshift (@INC, "$1"); # Get the script location: Windows \

require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";
};
if ($@) {
print "Content-type: text/plain\n\n";
print "Error including libraries: $@\n";
print "Make sure they exist, permissions are set properly, and paths are set correctly.";
}

# ========================================================

eval { &main; }; # Trap any fatal errors so the program hopefully
if ($@) { &cgierr("fatal error: $@"); } # never produces that nasty 500 server error page.
exit; # There are only two exit calls in the script, here and in in &cgierr.

sub main {
# --------------------------------------------------------
my %in = &parse_form();
my ($goto, $id, $delim, $time);



$id = $in{$db_key};
$delim = quotemeta($db_delim);
$time = time();

if ($id eq "random") {
my ($count, $rand, $find);

# Pull out the total number of links.
open (COUNT, "<$db_hits_path/index.count") or &error ("unable to open index count file: $db_hits_path/index.count. Reason: $!");
$count = int <COUNT>;
close COUNT;

# Get the random line from the url lookup database.
srand;
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
open (URL, "<$db_url_name") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL>) {
$find++ == $rand or next;
/\d+$delim(.+)/o or next;
$goto = $1;
last;
}
close URL;
$goto or &error ("Can't find random line: $rand.");
}
elsif (exists $in{$db_key}) {
# Make sure this is a valid looking id.
($id =~ /^\d+$/) or &error ("Invalid id: $id");



# Let's get the URL.
open (URL, "<$db_url_name") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL>) {
(/^$id$delim(.+)/o) or next;
chomp ($goto = $1);
last;
}
close URL;
$goto or &error ("Can't find link id: $id");


# Bump the counter one.
if (open (HIT, "<$db_hits_path/$id")) {
my ($count, $old_time, @IP, $ip, $visited);
chomp ($count = <HIT>);
chomp ($old_time = <HIT>);
chomp (@IP = <HIT>);
(($time - $old_time) > 21600) and (@IP = ());
foreach $ip (@IP) {
$ip eq $ENV{'REMOTE_ADDR'} and ($visited++ and last);
}
if (!$visited) {
push (@IP, $ENV{'REMOTE_ADDR'});
$count = $count + 1;
open (HIT, ">$db_hits_path/$id") or &error ("Can't open for output counter file. Reason: $!");
if ($db_use_flock) { flock (HIT, 2) or &error ("Can't get file lock. Reason: $!"); }
local $" = "\n";
print HIT "$count\n$time\n@IP";
close HIT;
}
}
else {
open (HIT, ">$db_hits_path/$id") or &error ("Can't increment counter file. Reason: $!");
print HIT "1\n$time\n$ENV{'REMOTE_ADDR'}";
close HIT;
}
}
else {
&error ("No link specified!");
}


# Now let's send the user to the url..
$goto ?

print "Location: $build_detail_url/$id.html\n\n" :

## print "Location: $goto\n\n" :
&error ("Record not found ($in{$db_key})");
}

sub error {
# ------------------------------------------
#
print "Content-type: text/plain\n\n";
print "Error: $_[0]\n";
exit;
}



It is jumping correctly, just not when it tries to do a random jump.

I am on a RAQ3 if that matters, and I have installed a lot of mods (and hacked a bit), but everything is working lovely except for the jump.cgi random problem.

Any help with this would be greatly appreciated. A girl can only do so much before pulling her hair out, and I am starting to yank on it....

:)
Tyranny

Quote Reply
Re: Can't find solution... In reply to
Yep, same issue.

Might anyone know how to get random jumps to find the Detailed Pages, rather than random outside links?

Thanks very much. Smile

DT

Quote Reply
Re: Can't find solution... In reply to
Hi, just bumpin this one up, too.

Thanks.

DT

Quote Reply
Re: Can't find solution... In reply to
If url.db is empty then that will be your problem. You will need to modify the code in jump.cgi to search the detailed url's rather than url.db for it's random link.

Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: Can't find solution... In reply to
Thanks, Paul. I'll give it a shot. Much appreciated!

DT

Quote Reply
Re: Can't find solution... In reply to
Hi Paul

I've tried a bunch of things, but nothing is working so far. What would we have to change to get the script to look in /Detailed, rather than in url.db?

I think that the following is that part that needs some adjustment:

In Reply To:
# Get the random line from the url lookup database.
srand;
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
open (URL, "<$db_url_name") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL>) {
$find++ == $rand or next;
/\d+$delim(.+)/o or next;
$goto = $1;
last;
}
close URL;
$goto or &error ("Can't find random line: $rand.");
}
elsif (exists $in{$db_key}) {
# Make sure this is a valid looking id.
($id =~ /^\d+$/) or &error ("Invalid id: $id");

# Let's get the URL.
open (URL, "<$db_url_name") or &error ("unable to open url database: $db_url_name. Reason: $!");
while (<URL>) {
(/^$id$delim(.+)/o) or next;
chomp ($goto = $1);
last;
}
close URL;
$goto or &error ("Can't find link id: $id");
I've tried changing URL to DETAIL and $db_url_name to $db_detail_name and to $build_detail_url, but no go.

Another possibility would be to build a detail.db within /data. This would be especially great if it would build detail.db whether you were using the default location for Detailed, where all detailed pages go into one folder (root/Detailed), OR if you were using the Detailed mod by junko, where the detail pages go into a sub-directory of each respective category, (root/Category/Detailed/) - http:// http://www.findinghim.com/links_mods/detail_cat/

I also tried to populate url.db with all the Detailed URLs, but if you have 1000 URLs, it gets to be a bit of a job plugging that stuff in.

Anyway, thanks for your help. Smile

DT

Quote Reply
Re: Can't find solution... In reply to
You would need to add a new sub in nph-build.cgi similar to build_url_index to build the detailed index and then change jump.cgi to search detailed.db instead of url.db

It is not as simple as what you tried....

In Reply To:
$db_url_name to $db_detail_name and to $build_detail_url
Alternatively you could forget all that and just get jump.cgi to search the detailed url field in links.db rather than creating a new database.


Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Random Jump To Detail Page In reply to
That's the best way. Would it be something like this:

In Reply To:
# Get the random line from the url lookup database.
srand;
$find = 0; $rand = int (rand ($count + 0.5)); ($rand == $count) and ($rand--);
open (LINKS, "<$db_links_name") or &error ("unable to open links database: $db_links_name. Reason: $!");
while (<LINKS>) {
$find++ == $rand or next;
/\d+$delim(.+)/o or next;
$goto = $1;
last;
}
close LINKS;
$goto or &error ("Can't find random line: $rand.");
}
elsif (exists $in{$db_key}) {
# Make sure this is a valid looking id.
($id =~ /^\d+$/) or &error ("Invalid id: $id");

# Let's get the LINK.
open (LINKS, "<$db_links_name") or &error ("unable to open links database: $db_links_name. Reason: $!");
while (<LINKS>) {
(/^$id$delim$title$delim(.+)/o) or next;
chomp ($goto = $1);
last;
}
close LINKS;
$goto or &error ("Can't find link id: $id");
I gave this a try, but I got a 404. It said:

In Reply To:
The requested URL /cgi-bin/linkdirectory/Title|http://root/linkdirectory/Detailed/4.html|1-Mar-2001|Category|AltCategory|...............etc was not found on this server. (my etc comment)
So, I think I'm close. Any suggestions on how to get jump.cgi to find the URL field in links.db?

Many thanks for your help. Smile

DT

Quote Reply
Re: Can't find solution... In reply to
Here's a link to something that junko did:

http://www.camelsoup.com/?view=info_jump

Thanks, junko !

DT

Quote Reply
Re: Can't find solution... In reply to
Okay, I've got the random jump.cgi directed toward Detail pages, instead of outside urls. What I did is the following:

1. In links.def, in # Field Number of some important fields, add:

In Reply To:
$db_id = 0;
2. In nph-build.cgi, go to sub build_url_index and find:
In Reply To:
print URL "$values[$db_key_pos]$db_delim$values[$db_url]\n";
Comment that line out. Then right below the line above, if using a single Detailed directory, add the following:

In Reply To:
print URL "$values[$db_key_pos]$db_delim$build_root_url/Detailed/$values[$db_id].html\n";
If using the Detailed Under Category hack, use the following instead:
In Reply To:
print URL "$values[$db_key_pos]$db_delim$build_root_url/$values[$db_category]/Detailed/$values[$db_id].html\n";
So, now random jumps can go to the Detailed pages.

However, I want to set it up so that my visitors can select to go to EITHER a random Detailed page OR a random External Link.

So, what I need to do is explore what Paul was saying above to get nph-build to build a separate detail.db for the local jumps as well as the url.db for external jumps.

I have copied and renamed sub build_url_index as sub build_detail_index and substituted DETAIL for URL within the sub. I also created a blank detail.db and installed it in the data directory. I also deleted the "Build the Count file..." stuff because if you're keeping sub build_url_index, that builds it once and that is all it should be. If the "Build the Count file..." is not commented out or deleted from the new sub, then you DOUBLE the count file and the random jump is looking for higher file numbers than actually exist. But, when I run it, I get an error message stating that

In Reply To:
Error Message : unable to open detail index: . Reason: No such file or directory
Here's what I have for sub build_detail_index:

In Reply To:
################## BEGIN build_detail_index ###############
sub build_detail_index {
# --------------------------------------------------------
# This routine builds a quick URL lookup database so the script
# does not have to search the links.db for every hit.

my $time = time();
my @values = ();
my $count = 0;

open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
open (DETAIL, ">$db_detail_name") or &cgierr("unable to open detail index: $db_detail_name. Reason: $!");
if ($db_use_flock) { flock (DETAIL, 2) or &cgierr ("unable to get exclusive lock. Reason: $!"); }
LINE: while (<DB>) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = &split_decode($_);
# print DETAIL "$values[$db_key_pos]$db_delim$values[$db_sku]\n";
# print URL "$values[$db_key_pos]$db_delim$build_root_url/$values[$db_category]/Detailed/$values[$db_id].html\n";
print DETAIL "$values[$db_key_pos]$db_delim$build_root_url/Detailed/$values[$db_id].html\n";
$count++;
$count++;
}
close DB;
close DETAIL;
}
########## END build_detail_index ###########################
How do I get nph-build to build detail.db using sub build_detail_index?

Thanks very much for any help. I hope my little hack above helps some folks.

DT


Quote Reply
Re: Can't find solution... In reply to
In Reply To:
Error Message : unable to open detail index: . Reason: No such file or directory
This means that the folder does not exist. You need to create a folder that you defined for $db_detail_name in the links.cfg file. Also, this file needs to be chmod 666.

Also, rather than building a second index file, you could consider adding conditional statements in the jump.cgi like the following:

Code:

if ($in{'detailed'}) {
dosomething;
}
else {
RANDOM LINK CODES;
}


Then in your header/footer files or template files, use the following codes:

Code:

<a href="<%db_cgi_url%>/jump.cgi?ID=random&detailed=1">Random Detailed Page</a>
<a href="<%db_cgi_url%>/jump.cgi?ID=random">Random Link</a>


This will be less intensive on the build script and also reduces having to add new fields (like isDetailed or isLocal) and then updating the database file.

Regards,

Eliot Lee
Quote Reply
Re: Can't find solution... In reply to
Thank you very much, AnthroRules. This was the last piece that I needed to get this to work. For this random jump to detail function, I simply copied and renamed jump.cgi as random.cgi. I use random.cgi solely to jump to randomly selected Detail pages. So, I don't know if it also does the other jump.cgi functions.

I went ahead and created the extra db since I was already way down that road already, but I'm going to try your other suggestion as well so that I can economize.

Here's what I did:

1. added sub and other stuff to nph-build
2. added line to links.cfg
3. copied and renamed jump.cgi as random.cgi
4. change link code to /random.cgi?ID=random

For anyone who wants to try this:
Please make backups of all your stuff before trying this.

nph-build.cgi
In sub build_staggered, right below this:
In Reply To:
$t1 = time();
print "Building URL Index . . .\n";
&build_url_index;
print "Done (", time - $t1, " s)\n\n";
add this:

In Reply To:
$t1 = time();
print "Building DETAIL Index . . .\n";
&build_detail_index;
print "Done (", time - $t1, " s)\n\n";
Then, in sub build_all, just below this:

In Reply To:
# Rebuild URL Index (This file is auto-generated, you will never need to touch it!
print "Building URL Index . . .\n";
&build_url_index;
print "Done.\n\n";
add this:
In Reply To:
## Rebuild DETAIL Index (This file is auto-generated, you will never need to touch it!
print "Building DETAIL Index . . .\n";
&build_detail_index;
print "Done.\n\n";
then, find sub build_url_index. Right after that entire sub, paste the following sub and choose which format your DETAIL address will be (look in this sub for "print DETAIL" (without quotations):

In Reply To:
sub build_detail_index {
# --------------------------------------------------------
# This routine builds a quick URL lookup database so the script
# does not have to search the links.db for every hit.

my $time = time();
my @values = ();
my $count = 0;

open (DB, "<$db_file_name") or &cgierr("unable to open database: $db_file_name.\nReason: $!");
open (DETAIL, ">$db_detail_name") or &cgierr("unable to open detail index: $db_detail_name. Reason: $!");
if ($db_use_flock) { flock (DETAIL, 2) or &cgierr ("unable to get exclusive lock. Reason: $!"); }
LINE: while (<DB>) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = &split_decode($_);
# print DETAIL "$values[$db_key_pos]$db_delim$build_root_url/$values[$db_category]/Detailed/$values[$db_id].html\n"; ## IF USING DETAIL UNDER CATEGORY HACK
print DETAIL "$values[$db_key_pos]$db_delim$build_root_url/Detailed/$values[$db_id].html\n"; ## IF USING STANDARD DETAIL DIRECTORY
$count++;
}
close DB;
close DETAIL;
}
links.cfg
Scroll to the bottom and find

In Reply To:
$db_url_name = "$db_script_path/data/url.db"; # PATH to URL lookup database.
then, below that, paste:

In Reply To:
$db_detail_name = "$db_script_path/data/detail.db"; # PATH to DETAIL lookup database.
Then, create a blank file called detail.db and place it in /data

Next, what I did is copy and rename jump.cgi as random.cgi. If you choose to do that, then rename your any links that you want to jump to a random detail page as /random.cgi?ID=random

I think that's it. It's a very easy mod, but make sure that you don't copy over the wrong stuff. I prefer commenting things out, rather than deleting. You can always throw something out later. Just make sure you get it working first.

Many thanks to AnthroRules for supplying the missing link.

HTH Smile

DT



Quote Reply
Re: [DogTags] Can't find solution... In reply to
I've used the solution proposed in this thread to get my jump.cgi to jump to detailed pages rather than outside URL's. This is working.

Now I'm trying to get the random link to do the same. I've applied DogTag's solution, but it isn't working yet. The random link that's getting built is "mydomain.com/Detailed/random.html" rather than "mydomain.com/Detailed/3.html". It's putting in the word "random" instead of the file name. I tried to carefully implement the changes, but obviously I've goofed somewhere. Can someone point me in the right direction. I have to plead ignorance here - I'm a newbie. Thanks.
Quote Reply
Re: [cco] Can't find solution... In reply to
Hi cco

I think it's this spot that controls that:

[$db_category]/Detailed/$values[$db_id].html\n"; ## IF USING DETAIL UNDER

See the $values[$db_id] - that's the guy, if I remember correctly
Quote Reply
Re: [cco] Can't find solution... In reply to
Hi cco

I think it's this spot that controls that:

[$db_category]/Detailed/$values[$db_id].html\n"; ## IF USING DETAIL UNDER

See the $values[$db_id] - that's the guy, if I remember correctly