Gossamer Forum
Home : Products : Links 2.0 : Customization :

Random pic on homepage

Quote Reply
Random pic on homepage
Hi!

I've been digging around on old posts regarding this but still haven't found a reasonable solution:

I got a URL field in the DB pointing to images on the Web.

I'd like to showcase x random, different images, every time someone enters the site. The URL linking to the image would be the detailed URL.

Any way to achieve that easily? I do have access to SSI, but would like to skip using them if possible.

Thanks!



Quote Reply
Re: Random pic on homepage In reply to
Its reasonably easy. Just get a copy of the mod at http://cgi-resource.co.uk/pages/randlinks.shtml and edit the line saying;

Code:
$num = $in{'number'};
to

Code:
$num = 1; # edited otherwise the QUERY_STRING won't be passed in SSI
Then, edit;

Code:
$links .= &site_html_link (%rec) . "\n";
to

Code:
$links .= &site_html_link2 (%rec) . "\n";
Then open up site_html_templates.pl and create a new sub with the following code;

Code:
sub site_html_link {
# --------------------------------------------------------
# This routine is used to display what a link should look
# like.

my %rec = @_;

# Set new and pop to either 1 or 0 for templates.
($rec{'isNew'} eq 'Yes') ? ($rec{'isNew'} = 1) : (delete $rec{'isNew'});
($rec{'isPopular'} eq 'Yes') ? ($rec{'isPopular'} = 1) : (delete $rec{'isPopular'});

return &load_template ('link2.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
%rec,
%globals
});
}
Then you need to make a new template called link2.html. Put in the code to make an image get shown. Something like;

Code:
<img border="0" src="<%FieldName%>">
Then upload that into the templates folder, the site_html_templates.pl file into the admin folder, and the randlinks.cgi file into the /cgi-bin/ (along with add.cgi etc).

Then you can just call the script in SSI enabled pages with an exec cgi command.

Well, hope that helps, and thats to Glen for the great mod in the first place Smile

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
Hey!

Thanks, I'll try this out inmediately!

What if i want to display extra info, like site's name or category?

Shall I just add it to link2.html or do I need to pass anything else?

Thanks!


Quote Reply
Re: Random pic on homepage In reply to
I also asume u made a typo when saying:

"Then open up site_html_templates.pl and create a new sub with the following code;

sub site_html_link {"

u meant:

"Then open up site_html_templates.pl and create a new sub with the following code;


sub site_html_link2 {"


right??

Tu!



Quote Reply
Re: Random pic on homepage In reply to
Damnit!

I'm getting the same error with randlinks.cgi than with recent password.cgi script I complained about some posts ago!

I compared the first lines of randlinks and password .cgis with other CGIs that do work, like add.cgi or modify.cgi, and they're IDENTICAL!!!

I don't get why randlinks.cgi refuses to work!!

This is what i get when called from command line (from Web i get a 500 Server error). File was upped in ascii, chmoded 755, etc.

"webcamworld% perl randlinks.cgi
Content-type: text/plain

Error including libraries: Can't locate /usr/local/etc/httpd/webcamworld.com/cgi
/directory/admin/db_utils.pl in @INC (@INC contains: /usr/libdata/perl/5.00503/m
ach /usr/libdata/perl/5.00503 /usr/local/lib/perl5/site_perl/5.005/i386-freebsd
/usr/local/lib/perl5/site_perl/5.005 .) at randlinks.cgi line 25.

Undefined subroutine &main::cgierr called at randlinks.cgi line 40.
Make sure they exist, permissions are set properly, and paths are set correctly."

IDeas???

Thanks!!


Quote Reply
Re: Random pic on homepage In reply to
Yup, sorry about that Blush. You are right, it should be

sub site_html_link2

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
Sorry, I don't have a copy of randlinks.cgi with me. Could you post the script here so I can have a look? It may just be that you need to use the full path in thje reuire statement (*instead of /admin/db.pl, or whatever it is).

I'm at work at the mo, but I'll be back in about 30 mins. I'll try to help you out a bit better then Wink

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
Ok, in randlinks.cgi try changing the following;

Code:
require "admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
to

Code:
require "/full/path/for/admin/folder/admin/links.cfg"; # Change this to full path to links.cfg if you have problems.
That will hopefully sort out the problem Smile

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
hi!

Tu for checking into this but that does not help.

Check this:

http://www.gossamer-threads.com/perl/forum/showflat.pl?Cat=&Board=L2Cust&Number=155149&page=0&view=collapsed&sb=5


What do u thinK?

Quote Reply
Re: Random pic on homepage In reply to
Can any1 help with this plz? Still stuck!

Tu!


Quote Reply
Re: Random pic on homepage In reply to
So, all the other CGI Scripts are working ok?

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
Try it for yourself:

http://webcamworld.com/directory/


You'll notice add.cgi, modify.cgi, rate.cgi... work fine but things like password.cgi (retrieve password rqred when modifying) or randlinks.cgi do not work.

The fun part is that all of them reside on the same place and contain the same set of instructions:

#!/usr/bin/perl

and

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


Ideas???


Quote Reply
Re: Random pic on homepage In reply to
When I run password.cgi, it gave me the following info;

Code:
There was an error adding a Cam to our database:

Error: No email address specified




Please press Back on your browser and try again!
Do you normally get that? As for randlinks.cgi, well, try the full path to require "admin/links.cfg";

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
Oh well!

This is AMAZING!

I've been out of town for holidays a few days, so I've not touched ANYTHING on the server nor scripts.

And now password.cgi is working fine again?!?!?!?!?!?!?!

I don't get it!!!


I'll make some tests with randlinks.cgi now and let you know.


Thanks for checking in!


Quote Reply
Re: Random pic on homepage In reply to
It could be something to do with your ISP / Servers caching. I have that problem loads of times...it gets really annoying, especially when you are trying to write and debug a script Frown

Andy

webmaster@ace-installer.com
http://www.ace-installer.com
Quote Reply
Re: Random pic on homepage In reply to
Ok, now it's happening what I thought...

password.cgi runs fine /still dunno how nor why/

but randlinks.cgi does not.


Content-type: text/plain

Error including libraries: Can't locate /usr/local/etc/httpd/webcamworld.com/cgi
/directory/admin/db_utils.pl in @INC (@INC contains: /usr/libdata/perl/5.00503/m
ach /usr/libdata/perl/5.00503 /usr/local/lib/perl5/site_perl/5.005/i386-freebsd
/usr/local/lib/perl5/site_perl/5.005 .) at randlinks.cgi line 25.

Undefined subroutine &main::cgierr called at randlinks.cgi line 40.
Make sure they exist, permissions are set properly, and paths are set correctly.
webcamworld%

File was upped in ASCII mode, permissions are ok, tested with full and non-full path, contents are identical to the rest of scripts (password.cgi, add.cgi, etc...):

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

Etc...


IDEAS????

Thanks!


Quote Reply
Re: Random pic on homepage In reply to
Double check this path

/usr/local/etc/httpd/webcamworld.com/cgi/directory/admin/db_utils.pl

It doesn't look right.

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Random pic on homepage In reply to
Hi!

Why do u think that?

Which is the problem u think there is with that path?

Why do the rest of scripts work fine with THE SAME path, permissions and settings?

Thnks!


Quote Reply
Re: Random pic on homepage In reply to
Paul, youradds,

I've made further investigation on the issue and I've determined Telnet sessions don't help too much...

I tried to ran on telnet a %perl password.cgi and the problem related to paths appeared. HOWEVER the script runs fine via web browser!

In fact, it happens with ALL OF THE CGIs!! ie. telnet does not like the perl scripts to be run remotelly, but the scripts do work fine!!

So, if you test http://cgi.webcamworld.com/directory/randlinks.cgi, the results are 0, Empty, Nothing! So...

I wonder if the mod you suggested to randlinks.cgi before has been tested or are we getting all mad! ;)

I also would like to know if the mod shown above will alow me to publish title and url in addition to the pic.


Thanks!!


Quote Reply
Re: Random pic on homepage In reply to
In fact, i've just installed the randlinks.cgi (the original one) and a nasty 500 Server error appears. As usual, files were uped in AScii, permissions are ok, etc...

I'm getting mad on this!!


Quote Reply
Re: Random pic on homepage In reply to
Check your _error log_

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: Random pic on homepage In reply to
Nothing is recorded in there.

Anything else?

Quote Reply
Re: Random pic on homepage In reply to
 
I still need assistance with this, plz!

Thanks!


Quote Reply
Re: [webcamworld] Random pic on homepage In reply to
Well after some further testing and still don't know how, it began working fine!

Now I wonder: will the fact of calling randlinks.cgi, which actually retrieves 5 random links from the database EACH TIME a user enters the home page, overload a server? How fast will it?

Ideas? Does it proceed?

Thanks!

Quote Reply
Re: [webcamworld] Random pic on homepage In reply to
If your site is running on a reasonable server you should have no real problems. I'm not really sure on the CPU etc consumption of it, but I reallyt wouldn't think it would be that much!

Andy

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!