Gossamer Forum
Home : Products : Links 2.0 : Customization :

Site of the day MOD Posted here!

(Page 1 of 3)
> >
Quote Reply
Site of the day MOD Posted here!
Here is the site_of_the_day.pl file that you will have to run every night with crontab.

Code:
#!/usr/bin/perl

#################################################################
# Set up Variables
#################################################################

$txtfile = '/opt/guide/HTML/txt/generated/siteoftheday.txt';

#################################################################
# Main Script
#################################################################

# 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";
$build_use_templates ?
require "$db_lib_path/site_html_templates.pl" :
require "$db_lib_path/site_html.pl";
};
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.";
exit;
}

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

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 ($id, $delim, $time);
my ($count, $rand, $find);

$delim = quotemeta($db_delim);
$time = time();


# 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;
/(.+)$delim/o or next;
$id = $1;
last;
}
close URL;
$id or &error ("Can't find random line: $rand.");


if ($id =~ /^\d+$/) {
my (%rec) = &get_record ($id);
($rec{$db_key} eq $id) ?
&build_page :
&error ("Random ID $id is not a valid ID.");
} else {
&error ("Can't find random Links ID: $id.");
}


}

sub build_page {
# --------------------------------------------------------

open (PAGE, ">$txtfile") or &error ("unable to open textfile: $txtfile. Reason: $!");
print PAGE &site_html_site_of_the_day (%rec);
close PAGE;
}

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

And here is the modification for site_html.pl

Code:
sub site_html_site_of_the_day {
# --------------------------------------------------------
# This routine determines how the sotd page will look like.
#

my %rec = @_;

$output = qq~

PUT YOUR HTML HERE!
(you can use $rec{ ***** })

~;

return $output;
}

[This message has been edited by chrishintz (edited June 27, 1999).]
Quote Reply
Re: Site of the day MOD Posted here! In reply to
And here is the modification for site_html.pl

sub site_html_site_of_the_day {
# This routine determines how the sotd page will look like. # my %rec = @_;$output = qq~ PUT YOUR HTML HERE! (you can use $rec{ ***** })~; return $output;}

So but if I using Templates(webcrawler) What I must to do?

And What`s code I must ensert to my html file?

------------------
Quote Reply
Re: Site of the day MOD Posted here! In reply to
You put the sub-routine in the site_html.pl even though you may not use that file. Follow the directions precisely as they are written! I am using templates, yet I put the sub-routine in the site_html.pl and uploaded it to my server. It works just fine!

In your home.html or other template files, you insert the following codes:

Code:
<!--#include virtual="/path/to/siteofday.txt"-->

(If you have SSI enabled.)

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Site of the day MOD Posted here! In reply to
SSI is enabled.
but ist again not working Frown
Dear Eliot,can you correct it plzz.

all files(site_of_the_day.pl;site_html_templates.pl and home.html - where it showed) you can find here:
http://yourfreebies.virtualave.net/cgi-bin/admin/admin.cgi - modify templates.

Plzz help me.Im need it.

------------------
Quote Reply
Re: Site of the day MOD Posted here! In reply to
Can any one modify this script so it updates automatically, so there is no need to go and do it every night manually.

Thanks
Rimvis
Quote Reply
Re: Site of the day MOD Posted here! In reply to
Rimvis,

There is virtually no way to do this other than using Cron or Windows Scheduler Program to pull the site of the day.

roman,

Is the siteofday.txt even created with the script???

Regards,



------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Site of the day MOD Posted here! In reply to
how does the script pick site of the say? is it random?
Quote Reply
Re: Site of the day MOD Posted here! In reply to
Eliot, Thanks for your replay, Wink
Quote Reply
Re: Site of the day MOD Posted here! In reply to
In to my site_html_templates.pl I past:


sub site_html_site_of_the_day {# --------------------------------------------------------# This routine determines how the sotd page will look like.
#
my %rec = @_;$output = qq~
PUT YOUR HTML HERE! (you can use $rec{ ***** })
~;
return $output;

}


And When I run admin.cgi script It said:
Error including libraries: syntax error at http//(path to file)/site_html_templates.pl line 46, near "* })

------------------
Quote Reply
Re: Site of the day MOD Posted here! In reply to
HI!

I assume the SOTD mod picks a random site, but does it control it won't repeat previous STODs?

How ends the templates thing? I dont have SSI capabilities right now!


------------------
Alex Tutusaus
Atyc WebDesigns
http://www.webcamworld.com/
Quote Reply
Re: Site of the day MOD Posted here! In reply to
The Site of the Day is randomly picked. However, I am working on having the script choose the site with the most hits of the day at the time of re-building the Index. This, of course, is dependent on using Cron or Windows Scheduling Program to automatically re-build the index.

In terms of inserting the siteofday.txt file without using SSI, you can try the following:

1) Insert the following codes into your site_html_templates.pl file:

Code:
sub siteofday {
# ---------------------------------------------
# Displays the number of accounts

open (INC, "/path/to/siteofday.txt") or return "Can't find include file:
Site of Day file{$_}";
return join ("", <INC> );
}

2) Then add the following global variable in the site_html_templates.pl file:

Code:
siteofday => &siteofday,

3) Insert the following tag in your home.html or category.html template files:

Code:
<%siteofday%>

Voila...that should work.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




[This message has been edited by Eliot (edited November 12, 1999).]
Quote Reply
Re: Site of the day MOD Posted here! In reply to
What code I must place to my site_html_templates.pl for site_of_the_day?
Quote Reply
Re: Site of the day MOD Posted here! In reply to
roman,

READ THE POST MORE CAREFULLY!!! I PLAINLY WROTE WHAT CODES YOU ADD TO THE SITE_HTML_TEMPLATES.PL!

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Site of the day MOD Posted here! In reply to
are u using templates?

If so, it will never be able to call that sub cause links has no idea to look in site_html.pl when you have it set to read site_html_templates.pl.
I have the same problem, but haven't got around to looking it over yet.

Derek
Quote Reply
Re: Site of the day MOD Posted here! In reply to
I can't seem to figure out what I'm doing wrong... I paste the sub routine in the site_html.pl file.. but when I try and execute the perl program from the webbrowser to test it... it gives me the error of main::&site_html_site_of_day routine is undifined

I pasted this at the very end of the site_html.pl file right before the 1; .. should I be pasting it somewhere else?
Quote Reply
Re: Site of the day MOD Posted here! In reply to
I tested this under templates, too, and get fatal error: Undefined
subroutine &main::site_html_site_of_the_day called at site_of_the_day.pl.
I fiddled around with site_html_templates.pl and got it to work.
Here's what I added to site_html_templates...
Code:
sub site_html_site_of_the_day {
# -------------------------------------------
# This routine determines how the sotd page will look like.
my %rec = @_;
return &load_template ( 'sotd.html', {
%rec,
%globals
});
}
I also created a simple template file which looks like this
Code:
<a class="link" href="/path/to/your/detailed/links/<%ID%>.htm"><%Title%></A>
If you are running site_of_the_day.pl from the command line, you're done.
If you don't have access to cron (like me), then add the following before
the final close bracket in the main subroutine...
Code:
print "Content-type: text/html\n\n";
print "<html><title>Processing Site of the Day</title>\n";
print "<body><UL><B>The site of the day is...</B> $rec{Title}</UL></body></html>\n";
This should stop the server errors.


[This message has been edited by oldmoney (edited December 22, 1999).]
Quote Reply
Re: Site of the day MOD Posted here! In reply to
Thanks for the fix!

I know exactly why you are getting the server error. It has to be run through cron, it can just be typed in to the browser, well, it can, but you will get the error, but the page will be created.

Derek
Quote Reply
Re: Site of the day MOD Posted here! In reply to
You guys didn't even try the codes I posted. All I did was use a sub-routine in site_html_templates.pl that prints the siteofday.txt file. Then I created a global variable, siteofday. It works fine for me.

Another thing you can do is simple use an SSI call:

Code:
<!--#include virtual="/cgi-bin/links/siteofday.txt"-->

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Site of the day MOD Posted here! In reply to
I did try it, siteoftheday.txt was not being built.
But i have it all working now, SSI and home.html template

Thanks,
Derek
Quote Reply
Re: Site of the day MOD Posted here! In reply to
Eh, I just gave up on it.. for a while I was getting that error message (even when running it through Cron) and it was writing siteofday.txt .. but it didn't put anything in that file..

So I just decided I just won't have a site of the day.
Quote Reply
Re: Site of the day MOD Posted here! In reply to
Eliot, I believe I followed your instructions to a T, which still resulted in the Undefined subroutine &main::site_html_site_of_the_day called at site_of_the_day.pl. I don't see how site_html_site_of_the_day ever gets called (which is required to write out the .txt file) when its in site_html if you use templates. I was just playing with this anyway, and don't plan to use the site of the day on my site. Predator, you were dead on about the script expectign to be a cron job. I added a couple Print lines to my earlier code, shown above, which solved the problem. Wink

[This message has been edited by oldmoney (edited December 22, 1999).]
Quote Reply
Re: Site of the day MOD Posted here! In reply to
No you didn't, oldmoney...As you will see in my sub-routine, I am not loading the siteofday file. I am calling it by opening the file and then printing the codes via the defined tag <%siteofday%>.

So, you did not follow my instructions.

Wink

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Site of the day MOD Posted here! In reply to
Okay I got it to make the site of the day.txt file by changing the sub below.

Had to change the sub for
Code:
sub build_page {
# --------------------------------------------------------

open (PAGE, ">$txtfile") or &error ("unable to open textfile: $txtfile. Reason: $!");
print PAGE &site_html_site_of_the_day (%rec);
close PAGE;
}
TO:
Code:
sub build_page {
# --------------------------------------------------------

open (PAGE, ">$txtfile") or &error ("unable to open textfile: $txtfile. Reason: $!");
print PAGE &siteofday (%rec);
close PAGE;
}
All of this is in the site_of_the_day.pl script. Which is line 70 in my script.
This is for you, if using the <%siteofday%> call in your template html files.

But now I am getting the error that it Can't find include file: Site of Day file{} on my final output html pages.

Also the txt file is just a copy of the links.db link. Is this correct? It seems that it will build what is printed in flat file format. I could not see how you are building the layout of the site of the day.

Any solutions?

Jerry
Quote Reply
Re: Site of the day MOD Posted here! In reply to
The original codes using site_html.pl will build the site of the day appropriately. It works for me. I build the siteofday.txt file via the site_html.pl, and I call the siteofday.txt file via the codes I posted a long time ago.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Site of the day MOD Posted here! In reply to
Well using the post that oldmoney made, I have got this mod to work, from executing it from the browser.. I have created two different pl files to create one that prints the Content header and that one works fine from the webbrowser, however the other one that doesn't the one I will use with Cron I still need to work with a bit.. for some reason when I execute it from the command line it says it can't find links.cfg in @INC I belive this is due to the fact I'm running on a Virtual Server system, and /usr/local/...ect ect ect works fine when executed from a webbrowser, however anything on the command line needs to be ~/usr/local/..ect.etc.etc .. but I'm almost there =)

------------------
Extreme Network Hosting
http://www.enhost.com
> >