Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Using a CSS script

(Page 1 of 2)
> >
Quote Reply
Using a CSS script
I would like to add the following to GF:

Code:
sub serve_css {
my ($usage) = @_;
$site = "site URL";
$path = "css";
$browser = "$ENV{'HTTP_USER_AGENT'}";
$browser =~ tr/A-Z/a-z/;
if ($browser =~ /win/ && $browser =~ /msie/) { $css_file = "ie.css"; }
elsif ($browser =~ /win/ && $browser =~ /mozilla/) { $css_file = "nav.css"; }
elsif ($browser =~ /mac/) { $css_file = "mac.css"; }
else { $css_file = "unix.css"; }
$css_serve_code_line .= "<!-- Browser detected: $browser -->\n";
$css_serve_code_line .= "<link rel=\"stylesheet\" href=\"$site/$path/$css_file\" type=\"text/css\">\n";
$css_serve_code_line .= "<style type=\"text/css\">\n";
$css_serve_code_line .= "<!--\n";
$css_serve_code_line .= "a:link { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:visited { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:hover { color: #AC9431; text-decoration: underline; }\n";
$css_serve_code_line .= "-->\n";
$css_serve_code_line .= "</style>\n";
if ($usage eq "") {
print "Content-type: text/html\n\n";
print "$css_serve_code_line";
exit;
}
else { return $css_serve_code_line; }
}

How can be added to the globals, so the sub will execute?

Thanks in advance...

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
Add a global called:

serve_css

that has:

sub {
.. your script
}

in it, and then just put <%serve_css%> in the template. Replace:

if ($usage eq "") {
print "Content-type: text/html\n\n";
print "$css_serve_code_line";
exit;
}
else { return $css_serve_code_line; }


with:

return $css_serve_code_line;

though, as you don't want to call exit. =)

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Using a CSS script In reply to
Yeah, I tried that before posting... all it does is print out the perl code, but it does not executes. I know I can use javascript, but that does not works is js is disabled... while the perl script will.

This is what I got under globals, I named it site_css:

Code:
sub { ($usage) = @_;
$site = "http://argus.bus.ucf.edu";
$path = "css";
$browser = "$ENV{'HTTP_USER_AGENT'}";
$browser =~ tr/A-Z/a-z/;
if ($browser =~ /win/ && $browser =~ /msie/) { $css_file = "ie.css"; }
elsif ($browser =~ /win/ && $browser =~ /mozilla/) { $css_file = "nav.css"; }
elsif ($browser =~ /mac/) { $css_file = "mac.css"; }
else { $css_file = "unix.css"; }
$css_serve_code_line .= "<!-- Browser detected: $browser -->\n";
$css_serve_code_line .= "<link rel=\"stylesheet\" href=\"$site/$path/$css_file\" type=\"text/css\">\n";
$css_serve_code_line .= "<style type=\"text/css\">\n";
$css_serve_code_line .= "<!--\n";
$css_serve_code_line .= "a:link { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:visited { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:hover { color: #AC9431; text-decoration: underline; }\n";
$css_serve_code_line .= "-->\n";
$css_serve_code_line .= "</style>\n";
return $css_serve_code_line;
}

Any other tips?

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
Make sure your global starts with sub { exactly. No leading white space or anything. The first 5 chars must be 'sub {' (minus quotes).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Using a CSS script In reply to
Now is running, but the page does not prints.. it only prints"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"></HEAD>
<BODY></BODY></HTML>

Something is not right...

The sub is:

Code:
sub { $browser = "$ENV{'HTTP_USER_AGENT'}";
$browser =~ tr/A-Z/a-z/;
if ($browser =~ /win/ && $browser =~ /msie/) { $css_file = "ie.css"; }
elsif ($browser =~ /win/ && $browser =~ /mozilla/) { $css_file = "nav.css"; }
elsif ($browser =~ /mac/) { $css_file = "mac.css"; }
else { $css_file = "unix.css"; }
$css_serve_code_line .= "<!-- Browser detected: $browser -->\n";
$css_serve_code_line .= "<link rel=\"stylesheet\" href=\"$site/$path/$css_file\" type=\"text/css\">\n";
$css_serve_code_line .= "<style type=\"text/css\">\n";
$css_serve_code_line .= "<!--\n";
$css_serve_code_line .= "a:link { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:visited { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:hover { color: #AC9431; text-decoration: underline; }\n";
$css_serve_code_line .= "-->\n";
$css_serve_code_line .= "</style>\n";
return $css_serve_code_line;
}

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
You aren't using strict code. All variables need declaring with my()
Quote Reply
Re: [Paul] Using a CSS script In reply to
I tried that before I posted with same results, it prints a blank page.

Code with localizing:

Code:
sub { my $site = "http://argus.bus.ucf.edu";
my $path = "css";
my $browser = "$ENV{'HTTP_USER_AGENT'}";
$browser =~ tr/A-Z/a-z/;
if ($browser =~ /win/ && $browser =~ /msie/) { my $css_file = "ie.css"; }
elsif ($browser =~ /win/ && $browser =~ /mozilla/) { $css_file = "nav.css"; }
elsif ($browser =~ /mac/) { $css_file = "mac.css"; }
else { $css_file = "unix.css"; }
my $css_serve_code_line .= "<!-- Browser detected: $browser -->\n";
$css_serve_code_line .= "<link rel=\"stylesheet\" href=\"$site/$path/$css_file\" type=\"text/css\">\n";
$css_serve_code_line .= "<style type=\"text/css\">\n";
$css_serve_code_line .= "<!--\n";
$css_serve_code_line .= "a:link { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:visited { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:hover { color: #AC9431; text-decoration: underline; }\n";
$css_serve_code_line .= "-->\n";
$css_serve_code_line .= "</style>\n";
return $css_serve_code_line; }

This is what my log spits out:

GT::Config (28315): Unable to compile 'site_css' in file '/usr/local/var/www/cgi-bin/latest/admin/templates/default/globals.txt': Global symbol "$css_file" requires explicit package name at (eval 14) line 10.
at /usr/local/var/www/cgi-bin/latest/admin/GForum/Template.pm line 73.

--
David

Last edited by:

unixman: Apr 22, 2002, 5:54 AM
Quote Reply
Re: [unixman] Using a CSS script In reply to
Make the following adjustments (annotated below).

Code:
sub { my $site = "http://argus.bus.ucf.edu";
my $path = "css";
my $browser = "$ENV{'HTTP_USER_AGENT'}";
$browser =~ tr/A-Z/a-z/;
my $css_file;
if ($browser =~ /win/ && $browser =~ /msie/) { my $css_file = "ie.css"; }
elsif ($browser =~ /win/ && $browser =~ /mozilla/) { $css_file = "nav.css"; }
elsif ($browser =~ /mac/) { $css_file = "mac.css"; }
else { $css_file = "unix.css"; }
my $css_serve_code_line .= "<!-- Browser detected: $browser -->\n";
$css_serve_code_line .= "<link rel=\"stylesheet\" href=\"$site/$path/$css_file\" type=\"text/css\">\n";
$css_serve_code_line .= "<style type=\"text/css\">\n";
$css_serve_code_line .= "<!--\n";
$css_serve_code_line .= "a:link { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:visited { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:hover { color: #AC9431; text-decoration: underline; }\n";
$css_serve_code_line .= "-->\n";
$css_serve_code_line .= "</style>\n";
return $css_serve_code_line; }

Add the extra line which is outlined in bold above and remove the my that is outlined in red from your code. If you put my inside your if loop then the variable won't be available outside of it. You need to define the variable first before entering the loop.

You should end up with this:

Code:
sub { my $site = "http://argus.bus.ucf.edu";
my $path = "css";
my $browser = "$ENV{'HTTP_USER_AGENT'}";
$browser =~ tr/A-Z/a-z/;
my $css_file;
if ($browser =~ /win/ && $browser =~ /msie/) { $css_file = "ie.css"; }
elsif ($browser =~ /win/ && $browser =~ /mozilla/) { $css_file = "nav.css"; }
elsif ($browser =~ /mac/) { $css_file = "mac.css"; }
else { $css_file = "unix.css"; }
my $css_serve_code_line .= "<!-- Browser detected: $browser -->\n";
$css_serve_code_line .= "<link rel=\"stylesheet\" href=\"$site/$path/$css_file\" type=\"text/css\">\n";
$css_serve_code_line .= "<style type=\"text/css\">\n";
$css_serve_code_line .= "<!--\n";
$css_serve_code_line .= "a:link { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:visited { color: #3366CC; text-decoration: none; }\n";
$css_serve_code_line .= "a:hover { color: #AC9431; text-decoration: underline; }\n";
$css_serve_code_line .= "-->\n";
$css_serve_code_line .= "</style>\n";
return $css_serve_code_line; }

I hope this helps.

- wil

Last edited by:

Wil: Apr 22, 2002, 6:06 AM
Quote Reply
Re: [Wil] Using a CSS script In reply to
It helped! NOw it is detecting the browser and all, but it is converting the <> tags for the equivalent on HTML (&stuff)... how to make it to print the raw code?

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
Can't help you with that sorry. I'm assuming a GT module is doing this, and I have no working knoweldge of how they, or the program works.

Hopefully someone else will be along to help you.

Good luck.

- wil
Quote Reply
Re: [Wil] Using a CSS script In reply to
Thanks! I will give it a try by entering the html code on the scripts (doing the reverse) and see...

Someone else to take on help? Thanks Will!

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
Aha. A quick search of the forums (that's a magic button that search, I'm convinced :-)) revealed the following thread which could be of use to you:

http://www.gossamer-threads.com/...orum.cgi?post=172548

Basically. I think it's just as easy as adding a backslash in there:

Code:
...
return \$css_serve_code_line;
}

Hope this helps.

- wil

Last edited by:

Wil: Apr 22, 2002, 7:01 AM
Quote Reply
Re: [Wil] Using a CSS script In reply to
Aha! Yes! Thanks Will. Working like a charm now!!!

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
Glad I could help.

Cheers

- wil
Quote Reply
Re: [Wil] Using a CSS script In reply to
Yep thats right, you need a scalar reference or "backslashing" as you put it :)

Edit: Hmm you two post quick.

Last edited by:

Paul: Apr 22, 2002, 7:05 AM
Quote Reply
Re: [Paul] Using a CSS script In reply to
:-) When I am looking for an answer I really keep my eye on the forum.

Cheers!

--
David
Quote Reply
Re: [Paul] Using a CSS script In reply to
Paul

LOL. Backslashing is a technical term, right? ;-)

- wil
Quote Reply
Re: [Wil] Using a CSS script In reply to
Yeah, backslaching is technical, escaping is just a slang. :-))))

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
David

Yeah, these forums are excellent.

But I am mightily impressed by the powerful search function on this forum. They should rename that button to the Holly Grail or something. It's got to be one of the most accurate and powerful search I've used.

/me is well happy with it :-)

- wil
Quote Reply
Re: [Wil] Using a CSS script In reply to
Hahahaha! I am going to be taking advantage of that in the future.. and on the modified GF I am planning to use. It will not be a forum, but an archive for mailing lists... I have cut down to 10 templates only, which I will modify just for that. The rest will be gone.

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
By the way, anyone is free to use the snippet for CSS. I find it more handy than the include_css.html, since you can server styles based on the browser (platform). I want mine to look the same under Windows (N and IE), Mac (both too) and Linux

--
David
Quote Reply
Re: [Wil] Using a CSS script In reply to
>>
Yeah, these forums are excellent.

But I am mightily impressed by the powerful search function on this forum. They should rename that button to the Holly Grail or something. It's got to be one of the most accurate and powerful search I've used.

/me is well happy with it :-)

<<

I remember once you said I brown-nosed GT Cool j/k

Last edited by:

Paul: Apr 22, 2002, 7:40 AM
Quote Reply
Re: [Paul] Using a CSS script In reply to
Did I? Hmmm, the search did not render any hits on that one :-))

--
David
Quote Reply
Re: [unixman] Using a CSS script In reply to
Look at the subject line....my reply was to Wil Smile
Quote Reply
Re: [Paul] Using a CSS script In reply to
Paul

LOL! No, I am geniunly impressed with the search function. I dunno if it's the way MySQL indexes things or if it's GT search algorithm - but whatever it is, it's good! :-)

- wil
> >