Gossamer Forum
Home : Products : Links 2.0 : Customization :

RE: Glennu - randlinks.cgi

Quote Reply
RE: Glennu - randlinks.cgi
Hi Glennu....Have a problem..well not a problem..wish to change your randlinks around a bit...have been trying..with some amazing results *grins*..This is what I wish to do..

Like to use randlinks for featured links for each category..ok...but umm below is a example of the structure of my links..

top category Blues
subcategories A through to Z
top catergory POP
subcategories A through to Z
So forth and so Forth.

OK...The top categories have no Links (this is where I wish to put the featured links)....
Now what I wish to do is for the randlinks to pull 5 links out of the subcategorys under each topcategory...so I can then use them as featured links in each top category...but yep is always a but....I would like the scipt to print them out so I would have say blues.txt or html whatever pop.txt soforth with the 5 rand links for that topcategory which have been pulled out of the subcategories underneath...so then i can place them in the topcategory with the include statement....
Think its a new mod all together ha!
As I said have been trying to do myself but alais not much success. So if you could wrap your brains around it and come up with a answer I will shout you a virtual drink or two *grins*.

Admittedlamb.

PS I can't use SSI #exe cgi CMD on my server as been disabled.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Yeah wouldn't be too hard to do. You could achieve it by adding a sub in nph-build.cgi. Just by using the code from the cgi script and adding some code to open a file for each cateogry and write the results onto it.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Here's a suggestion on how to go about doing it: Should work as is but might need a few alterations ie. I haven't tested it. It's set up to write 5 random links to random_links.txt could be altered to do different ones for each category. Should be able to do this by using what ever method you used before to pull them out foreach category.


Make a directory called Random and make it just off of the main links directory.


In links.cfg add:

# PATH and URL of random files.
$build_random_path = "$build_root_path/Random";
$build_random_url = "$build_root_url/Random";
$num_random_links = "5";
$random_page = "random_links.txt";


In nph-build...


In sub build staggered find:


print "Updating ratings .. \n";
$t1 = time();
&build_update_ratings;
print "Done (", time - $t1, " s)\n\n";

Beneath it add:

print "Updating random links .. \n";
$t1 = time();
&build_update_random_links;
print "Done (", time - $t1, " s)\n\n";


in sub build_all find:

# Create Top Rated Page
$use_html ?
print "Building <A HREF=\"$build_rate_url/$build_index\">Top Rated</A> Page . . .\n" :
print "Building Top Rated . . .\n";
&build_rate_page;
print "Done\n\n";

Beneath it add:


# Create Random links pages
$use_html ?
print "Building <A HREF=\"$build_random_url/$build_index\">Random Links</A> . . .\n" :
print "Building Top Rated . . .\n";
&build_random_links;
print "Done\n\n";

Add the following sub:


sub build_random_links {
# --------------------------------------------------------

# 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;


for ($i = 0; $i < $num_random_links; $i++) {
# Get the random line from the url lookup database.

$find = 0; $rand = int (rand ($count + 0.5));
($rand == $count) and ($rand--);
open (URL, "<$db_links_name") or &error ("unable to open links database: $db_url_name. Reason: $!");
while (<URL>) {

(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
$find++ == $rand or next;
%rec = &array_to_hash (0, @data);
last;
}
close URL;

$link_output .= &site_html_link (%rec) . "\n";

}
open (RANDOM, ">$build_random_path/$random_page") or &cgierr ("unable to open random page: $build_random_path/$random_page. Reason: $!");
print RANDOM "$link_output";
close RANDOM;

}











Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Hi Glennu...thanks for the above...as is works well..except showing the same link twice sometimes...which I see you have fixed in another post. But my prblem is..well be damed if I can change it to do what I wish to do...I have become so frustrated I have given up...can you help before I lose all my hair?. What I wish to do as I stated in my first post...is to have it pull 5 random links below each top category and to print it out onto a seperate page... so is you have 15 top category's..you would have 15 pages with 5 random links from all the subcategory's underneath. That way I can include them into the top category page's, which have no links...and use the 5 random links as featured links for each top category.
Does that explain what I wish...I no it's to hard for me to do...just not expert enough yet..but getting there....

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
If I have a few minutes next week I'll take another look.

I think it could be done by editing the sub build category pages and pulling out links at random from one of the store arrays.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Okay working version... builds a file called randomlinks.txt for each category if the category has a good enough amount of links to take random ones from.


go into nph-build.cgi, sub build_category_pages


Right near the bottom above:

print "\n";


Add:

if ($category_name =~ m,^([^/]*)$,) {
$num_random_links = 5;
}
else {
$num_random_links = 15;
}

if ($numlinks > ($num_random_links + 10)){

$link_output = "";
for ($r = 0; $r < $num_random_links; $r++) {
# Get the random line from the url lookup database.
$find = 0; $rand = int (rand ($numlinks + 0.5));
($rand == $numlinks) and ($rand--);
LINK: for ($i = 0; $i < $numlinks; $i++) {
#last LINK if ($tmp{$db_key} eq "");
$find++ == $rand or next;
$c = 0;

foreach $set (@visited) {
if ($rand == $set){
$c++;
}
}
if ($c == 0){
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$links{$cat}});
$link_output .= &site_html_link (%tmp) . "\n";

}
else {
$r = $r - 1;

}
last;
}
}
# Create the random links page.
open (CAT, ">$dir/randomlinks.txt") or &cgierr ("unable to open category page: $dir/$build_index. Reason: $!");
print CAT "$link_output";
close CAT;




Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Well I just tested it..and nope didn't work..well not sure whether it will...because it just timed out..the build reached the first subcategory..and it then just sat there until it timed out?

Question..why for the else statement and why is it set at 15.....anyway decreased it to 2 and 3 and still timed out..then went in to server admin and increased the cgi timeout my 5 minutes..and it still timed out...so there is no errors coming up..just timing out???

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
why for the else statement and why is it set at 15.....


cause if it's not a top level category then get 15 random links instead.


Are you building via telnet or online via admin? If your building online via admin... build via telnet instead!

Also put before the if/else statement:

$link_output ="";


Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Um actually I am sitting right next to my server! which is a dual p3 933 1024mb memory and the only thing runing at the time was the build...O and it's windows 2000 advance server. And there is no links at all on the top level categorys.. I have 15 top level categorys with 26 subcategorys underneath each one....thats what I wish to do pull 5 random links out of the 26 subcats under each topcat and insert in the topcat to use as featured links.. Ok did as you suggested..insert that code on top..no difference still stops...also run at command prompt (that would be the same as using telnet)..it justs stops when reaching the above code. And I mean just that it stops as if it as come to the end of the script???

Admittedlamb.

Programming ..just like women ..can't live with them and can't live without them!

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Oh just noticed something. Change:

for ($i = 0; $i < $num_random_links; $i++) {

To:

for ($r = 0; $r < $num_random_links; $r++) {

and change:

$i = $i - 1;

To:

$r = $r - 1;


That was prob causing it to loop to infinity which would explain the time out!







Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Ok Glennu..did as suggested above...and nope still the same...it stops still or loops still...O and by the way this..<$dir/category_name.txt.. that wouldn't work..for the topcat it would..but for the subcats..it would try and build in blues/A/blues/A/A.txt....and of course no such directory..thats my nickles worth..anyway it stops before then...did fiddle no success though..tis a bummer..its the one thing I really need..Ok you perl guru's..see if you can help Glennu and me work it out..I just no it can be done!

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
When I get back home I'll have access to test it and will take a quick look. Cause as you say it shouldn't be too hard to do. Also it's easier when I can see it in action and see what's going on (plus I'd also find a solution to this useful!).


One more thing to change (this'll get rid of the error you said about):

Change:

$category_name.txt

To:

randomlinks.txt



Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Okay tested it online (made a number of alterations) and it now works! Instead of posting all the code again I'll alter my post above so it'll have the final code in it...

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Works like a charm...except *grins*...its not exactly what I wanted..but I will use it. What I actually wished to do..was not do random links for each and every category. But to pull 5 links out of the "whole 26 subcats" not individually..under each topcat..um...example I have a topcat called blues..underneath that topcat I have 26 subcats named from A through to Z. So in effect I 15 topcats..and 26 subcats underneath each one name A to Z.. so it looks like this....

Homepage/
blues/
blues/a/
blues/b/

pop/
pop/a
pop/b

Soforth..
So what i wish to do is pull 5 random links out of the 26 subcats "just 5 links out of the whole 26" and to insert in the topcat with a include...does that explain it??...the one ya done works great for what it does...and i could use that to put say 1 featured link for each subcat.

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Ah I see, sorry I should had read your post a bit more. What you want can be done. Way I'd do it is to instead put the code in a new sub. Then add some code to sub build stats:


if ($subcategory =~ m,^$values[$db_category]/([^/]+)/*,) {
push (@{$random_links2{$category}}, @values)
}

else {
$category = $values[$db_category];
push (@{$random_links{$category}}, @values)
}

Then alter the random code to include a loop to go thru each top level cat and then go thru each subcategory. (you'd also need to alter it slightly so instead of $links{$cat} it'd now be $random_links{$category})




Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Ok Glennu...will give that a shot..see what happens...see if I got it right...put the if else statment into the the build stats sub....change $links{cat}...then create a loop right?
First question in this push (@{$random_links2{$category}}, @values)....where is the "$random_links2" defined??.

Admittedlamb.


Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Sorry ignore what I was saying above, just re-read your post:

Instead use the code as you were before in sub build category pages but...

Replace:

if ($category_name =~ m,^([^/]*)$,) {
$num_random_links = 5;
}
else {
$num_random_links = 15;
}

With:

$num_random_links = 5;


Replace:

if ($numlinks > ($num_random_links + 10)){


With:

if (($numlinks > ($num_random_links + 10)) and ($category_name =~ m,.*/([^/]+)$,)){


And replace:

last;
}
}
# Create the random links page.
open (CAT, ">$dir/randomlinks.txt") or &cgierr ("unable to open category page: $dir/$build_index. Reason: $!");
print CAT "$link_output";
close CAT;

With:

last;
}
# Create the random links page.
open (CAT, ">$dir/randomlinks.txt") or &cgierr ("unable to open category page: $dir/$build_index. Reason: $!");
print CAT "$link_output";
close CAT;
}

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Hi Glennu, yep did as you suggested..but didn't seem to change anything...built exactly the same why as before..for every subcat???..I have tried various things...but mainly get errors...but unlike you I don't no link2 that well..and takes me ages to find where all the definitions and variables come from.

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Yeah sorry I'm getting confused as to what you want, is this correct:

say you had:

music
rock, pop, trance


You'd want 5 random links pulled from all those subcats together.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
If you want to do as I mentioned above it's a little bit more work. You'll want to create a new sub to run it all in you'll need to include the sub in the build all and staggered...


In sub build staggered find:

print "Updating ratings .. \n";
$t1 = time();
&build_update_ratings;
print "Done (", time - $t1, " s)\n\n";

Beneath it add:

print "Updating random links .. \n";
$t1 = time();
&build_update_random_links;
print "Done (", time - $t1, " s)\n\n";


in sub build_all find:

# Create Top Rated Page
$use_html ?
print "Building <A HREF=\"$build_rate_url/$build_index\">Top Rated</A> Page . . .\n" :
print "Building Top Rated . . .\n";
&build_rate_page;
print "Done\n\n";

Beneath it add:


# Create Random links pages
$use_html ?
print "Building <A HREF=\"$build_random_url/$build_index\">Random Links</A> . . .\n" :
print "Building Top Rated . . .\n";
&build_random_links;
print "Done\n\n";


Then add this to sub build stats.

if ($subcategory =~ m,^$values[$db_category]/([^/]+)/*,) {
push (@{$random_links{$category}}, @values)
}


Then create the new sub build_random_links.

to this sub add the random code used before except put it in a loop 'foreach $category (@{$random_links{$category}}){ etc...'. Also change the $links{$cat}. You'll also need to add some code to calc $numlinks.


Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Thats nearly right....um ok in my home page i have 15 categorys...won't name them all...blues, pop, rock ect. ok.
click on blues..you bring up the blues page..this as no links on it whats soever...on the blues page there are 26 cats named A through to Z ok.....what I wish to do is pull 5 random links out the cats A through to Z (not 5 links out of each of them) and put them 5 links into the blues page to use as featured links for blues. So I would have 5 radoms links on the blues page..the pop page soforth.

Does that better explaine it..I would never make a teacher!

Admittedlamb.


PS: I must have be typing this out as you was typing the above.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Ok I will give that a go but not now..tis 2:01am in the morning here (Australia) and my brain is just fudge at the moment....but if you get a spare moment *grins* would you be able to print out the sub routine for me...but only if have time..you have spent considerable time on this now..and must have other more urgent things to do...and beleive me I apprecaite the help you have given!

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
The instructions above should get it so you'd have a random links page (taking a total of 5 links chosen at random from all of the sub categories for that main category) This info is stored in a txt file in the same directory as the each main category. So all you'd need to do is include this file.

This would this for all your main categories, but you could of course just alter the if statement, if you wanted it to be done for blues category only.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
nah not just for blues..just used that as a example...for all..and again thanks...if you need any help with asp, jscript..thats my forte.

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
No problem, I will prob come back to this again at some point as I will prob use it for a future site directory I have in mind.

The code/instructions I provided above should do it, it's off the top of my head, I haven't tested it and so it might need a little playing around with...

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
OK Glennu this is what I done with sub..# Build Top Category Featured Links.
# -----------------------------------------------------------
sub build_featured_links{
$num_random_links = 5;
foreach $category (@{$random_links{$category}}){
if (($numlinks > ($num_random_links + 10)) and ($category_name =~ m,.*/([^/]+)$,)){

$link_output = "";
for ($r = 0; $r < $num_random_links; $r++) {
# Get the random line from the url lookup database.
$find = 0; $rand = int (rand ($numlinks + 0.5));
($rand == $numlinks) and ($rand--);
LINK: for ($i = 0; $i < $numlinks; $i++) {
#last LINK if ($tmp{$db_key} eq "");
$find++ == $rand or next;
$c = 0;

foreach $set (@visited) {
if ($rand == $set){
$c++;
}
}
if ($c == 0){
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$random_links{$category}});
$link_output .= &site_html_link (%tmp) . "\n";

}
else {
$r = $r - 1;

}
}
last;
}
}
}
# Create the random links page.
open (CAT, ">$dir/randomlinks.txt") or &cgierr ("unable to open category page: $dir/randomlinks.txt: $!");
print CAT "$link_output";
close CAT;
}


# ------------------------------------------------------------------------
# Finnish of Top Category Featured Links.

No erors come up..but it doesn't build anything either as in nothing..problem something I have done or haven't done..but I am at a lose to no what..

Admittedlamb.



Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Try:

# -----------------------------------------------------------
sub build_featured_links{

$num_random_links = 5;
foreach $category (@{$random_links{$category}}){

$numlinks = $#random_links{$category};
if (($numlinks > ($num_random_links + 10)) and ($category =~ m,.*/([^/]+)$,)){
$link_output = "";
for ($r = 0; $r < $num_random_links; $r++) {
# Get the random line from the url lookup database.
$find = 0; $rand = int (rand ($numlinks + 0.5));
($rand == $numlinks) and ($rand--);
LINK: for ($i = 0; $i < $numlinks; $i++) {
#last LINK if ($tmp{$db_key} eq "");
$find++ == $rand or next;
$c = 0;

foreach $set (@visited) {
if ($rand == $set){
$c++;
}
}
if ($c == 0){
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$random_links{$category}});
$link_output .= &site_html_link (%tmp) . "\n";

}
else {
$r = $r - 1;

}
}
last;
}
}
}
# Create the random links page.
open (CAT, ">$build_root_url/$category/randomlinks.txt") or &cgierr ("unable to open category page: $build_root_url/$category/randomlinks.txt: $!");
print CAT "$link_output";
close CAT;
}



Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Ok give it ago but..first..

Shouldn't this $#random_links{$category}; Be this $random_links{$category}; without the hash??...and this

open (CAT, ">$build_root_url/$category/randomlinks.txt")
I am sure wouldn't work..wouldn,t it look for randomlinks.txt in my case...
http://btm/btm/music/blues/pop/country/rock/blah/blah/fithteen times/randomlinks.text.....because that is what $category does build the top cats in home page????.

Admittedlamb.



Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
'Shouldn't this $#random_links{$category}; Be this $random_links{$category}; without the hash??...'

No because you need to get a total count.

'because that is what $category does build the top cats in home page????.'

Depends how you do it. Instead of $category you could use $category2
Then in the build stats you'll need to make it so that $category2 is defined. $use a regular expression so that each $category2 is the names of the main categories and the links within them are the links in their sub categories.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
OK Glenu this his the first error...

syntax error at c:\inetpub\wwwroot\btm\music-cgi-bin\admin\nph-build.cgi line 1179, near "$#random_links{"
syntax error at c:\inetpub\wwwroot\btm\music-cgi-bin\admin\nph-build.cgi line 1215, near "}"
Execution of c:\inetpub\wwwroot\btm\music-cgi-bin\admin\nph-build.cgi aborted due to compilation errors.

1215 is the last } after close cat...

Took Hash out..and then got down to the open print...and this error......

Building Random Links . . .

CGI ERROR
==========================================
Error Message : unable to open category page: http://btm/btm/music/
Blues
Childrens
Classical
Country_&_Folk
Dance_&_Electronic
Gospel_&_Christain
International_&_World
Jazz_&_Swing
Moods_&_Lounge
New Age
R&B_&_Soul
Rap_&_Hip Hop
Reggea_&_Ska
Rock_Indie_&_Pop
Soundtracks_&_Musicals
/randomlinks.txt: No such file or directory
Script Location : c:\inetpub\wwwroot\btm\music-cgi-bin\admin\nph-build.cgi
Perl Version : 5.006


Admittedlamb.







Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Ok Glennu just read your post..you mean change this which is in sub stat now..

if ($subcategory =~ m,^$values[$db_category]/([^/]+)/*,) {
push (@{$random_links{$category}}, @values)
}

to this

if ($subcategory =~ m,^$values[$db_category]/([^/]+)/*,) {
push (@{$random_links{$category2}}, @values)
}

and also change this in the sub ....

foreach $category (@{$random_links{$category}}){

to this

foreach $category (@{$random_links{$category2}}){

and this

%tmp = &array_to_hash ($i, @{$random_links{$category}});

to this

%tmp = &array_to_hash ($i, @{$random_links{$category2}});

and this

open (CAT, ">$build_root_url/$category/randomlinks.txt")

to this

open (CAT, ">$build_root_url/$category2/randomlinks.txt")

is that correct or am i totally wrong, which is not unusual..

Admittedlamb.












Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
In sub build stats instead try:

$category2 = $values[$db_category];
$category2 = scalar reverse($values[$db_category]);
if ($category2 =~ m,.*/([^/]+)$,) {
$category2 = $1;
$category2 = scalar reverse($category2);
push (@{$random_links{$category2}}, @values)
}

This should work but there are better/more efficient ways of doing it (but affraid I can't think of a better way off the top of my head at the moment)

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Works like a charm Smile....I would never have worked it out in a month of sundays...not knowing to use scalar reverse!. Thanks heaps...it made my day..Wink. I have made it pull 6 links..now all I have to do is figure out how to put the output in the txt file into two column's..to match the rest of the site as I have links in two columns...but I will work on it! Again thanks you a bueaty mate!

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Glad it works. Will prob look at a better way of doing it after my exams.

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
'now all I have to do is figure out how to put the output in the txt file into two column's..'

Shouldn't be too hard to do quick suggestion:


Replace:

$link_output = "";


With:

my ($half) = int (($#numlinks+2) / 2);
$link_output = qq|<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top">\n|;


Replace:

if ($c == 0){
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$random_links{$category}});
$link_output .= &site_html_link (%tmp) . "\n";

}

With:


if ($c == 0){
if ($i == $half) {
$link_output .= qq|</td><td class="catlist" valign="top">\n|;
}
$i++;
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$random_links{$category}});
$link_output .= &site_html_link (%tmp) . "\n";

}



Under:

last;
}


Add:

$link_output .= "</td></tr></table>\n";



Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Thanks glennu...I was very close...I had..

$columns = 2 and this...
my ($half) = int (($#numlinks+2) / 2);
was
my ($half) = int (($#numlinks+2) / $columns);

and $#numlinks was $#randomlinks

So I was Close.

Also had this $link_output .= "</td></tr></table>\n";

In the wrong place it seems....had it before $last..

didn't produce any errors but done nothing either...will try your suggetion out.

Admittedlamb.

PS: This is totally of the subject... but in your tell a freind 1st version..would it me possible to get it to write the two email adresses to a seperate txt file or even to the excisiting email txt file and also I suppose you have to have a why to tell it not to write if the email addy already excists in txt file??...





Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
well afraid no luck with your suggestion...no errors, nothing changed still single column..grrr how come nothing is ever easy?

Admittedlamb.

Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
To write to logfile make a blank text file called tellfriend.txt. Add this to the cgi script:


open (DB, "<tellfriend.txt") or &cgierr("error unable to open db file: $db_file_name. Reason: $!");
$found = 0;
LINE: while (<DB>) {
(/^#/) and next LINE;
(/^\s*$/) and next LINE;
chomp;
@data = &split_decode($_);
if ($data[3] eq $in{'temail'}) {
$found = 1;
last LINE;
}
}
close DB;

if (!$found){

$date = &get_date;
open (TELL, ">>tellfriend.txt") or &cgierr("error . unable to open tellfriend log file: tellfriend.txt. Reason: $!");
flock(TELL, 2) unless (!$db_use_flock);
print TELL "$date|$in{'temail'}|$in{'yname'}|$in{'yemail'}\n";
close TELL; # automatically removes file lock
}

Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Thanks Glennu...that was quick response....I am still trying to get this dam random_links.txt into two cloumns..this is my latest try...

sub build_featured_links{
my($link_output);

$num_random_links = 5;

$column_2 = "0";


foreach $category (@{$random_links{$category2}}){



$numlinks = $random_links{$category};
if (($numlinks > ($num_random_links + 10)) and ($category =~ m,.*/([^/]+)$,)){


$link_output = '';




for ($r = 0; $r < $num_random_links; $r++) {
# Get the random line from the url lookup database.
$find = 0; $rand = int (rand ($numlinks + 0.5));
($rand == $numlinks) and ($rand--);
LINK: for ($i = 0; $i < $numlinks; $i++) {
#last LINK if ($tmp{$db_key} eq "");
$find++ == $rand or next;
$c = 0;

foreach $set (@visited) {
if ($rand == $set){
$c++;
}
}
if ($c == 0){
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$random_links{$category}});
if ($column_2 ne "1") {
$column_2 = "1";
$link_output .= "<TR><TD
width=50% valign=top>\n";

$link_output .= &site_html_link (%tmp);

$link_output .= "</TD>\n";
}
else {
$column_2 = "0";
$link_output .= "<TD width=50%
valign=top>\n";
$link_output .= &site_featured_links(%tmp);

$link_output .="</TD></TR>\n";
}

}


else {
$r = $r - 1;

}
}
last;
}
if (int($numlinks/2) != ($numlinks/2)) {
$link_output .= "<td></td></TR>\n"; }
}
}


# Create the random links page.
open (CAT, ">$build_root_path/$category2/randomlinks.html") or &cgierr ("unable to open category page: $build_root_url/$category/randomlinks.txt: $!");
print CAT &site_featured_links;
close CAT;
}


Don't laugh either...it didn't work in respect it still only printed it out in one column...as you can see i treid to use the 2 column link mod..and i also made a template for it..which worked..but dam it I want to columns!!!!!!

Admittedlamb.


Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
I don't know, I never lookedat or used the 2 column link mod. However it should be quite easy to do as you just need to do it like the print cat routine... I noticed one mistake in my instructions:


$link_output .= "</td></tr></table>\n";

should go above:

# Create the random links page.

Without testing it myself (which I can't do due to lack of spare time) it's hard to say. Could you post a little of the output. ie. what tags are being printed and where?



Glenn

Links 2 Mods Site:
http://cgi-resource.co.uk/pages/links2mods.shtml
Quote Reply
Re: RE: Glennu - randlinks.cgi In reply to
Hi glennu, I have made a number of changes to it....

1. created a template for it.
2. created a seperate directory for it..to put all the files in and had them named blues, pop, children ect.
3. defined the directory in links.cfg.
4. changed the biuld all so it showed the pages it was building.

I will post the sub again here so you can see the changes.

sub build_featured_links{
my($link_output);

$num_featured_links = 5;

foreach $category (@{$random_links{$category2}}){
$numlinks = $random_links{$category};
if (($numlinks > ($num_featured_links + 10)) and ($category =~ m,.*/([^/]+)$,)){
$link_output = '';
for ($r = 0; $r < $num_featured_links; $r++) {
# Get the random line from the url lookup database.
$find = 0; $rand = int (rand ($numlinks + 0.5));
($rand == $numlinks) and ($rand--);
LINK: for ($i = 0; $i < $numlinks; $i++) {
#last LINK if ($tmp{$db_key} eq "");
$find++ == $rand or next;
$c = 0;
foreach $set (@visited) {
if ($rand == $set){
$c++;
}

}

if ($c == 0){
push (@visited, $rand);
%tmp = &array_to_hash ($i, @{$random_links{$category}});
$link_output .= &site_html_link (%tmp);
}

else {
$r = $r - 1;
}

}
last;
}
}
}
# Create the random links page.
open (CAT, ">$build_featured_path/$category2.html") or &cgierr ("unable to open category page: $build_featured_path/category2.html: $!");
print CAT &site_featured_links;
close CAT;
$use_html ?
print qq~<a href="$build_featured_path/$category2.html" target="_blank">$category2</a> ~;

(++$count % 10) or print "\n\t";
}
close DB;
print "\n";

There!

But still can't get it to build dam two columns...took all the code out in the above so you could see it a fresh with the changes I have made.

I will try it again with the above change you made.

O yeah I want it to pull 6 instead of 5 which I thought changing the $num_random_links = to 6 would do..but nah it doesn't???

Admittedlamb.