Gossamer Forum
Home : Products : Links 2.0 : Customization :

RE: Glennu - randlinks.cgi

(Page 2 of 2)
> >
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.



> >