[pmwiki-users] Nifty css/php trick, but is it safe?

Tegan Dowling tmdowling at gmail.com
Fri Nov 30 09:43:40 CST 2007


By putting the following line in the .htaccess file at the root-level
of my pmwiki installation (in the same dir as pmwiki.php):

AddType application/x-httpd-php .css

I am able to have php code inside css files.

I've used this on http://www.test.wikitraining.com/Main/HomePage,
where I have installed a fresh download of PmWiki V2.2.0 beta 65, and
at the top of the skin's pmwiki.css, I added the material that appears
between the following rows of ----------- (just pasted it in right
above the existing content):

---------------------------------------------------------------------------
<?php header("Content-Type: text/css;");
$highlight1 = '#ccc';
$bodytxt = '#ff0000';
$headings = '#008400';
?>
/*use the variable names for the colors by replacing the
usual "color:#xxxxxx;" with "color:<?=$varnamehere?>;*/
---------------------------------------------------------------------------

Then further down in the css file, I have

---------------------------------------------------------------------------
body {
  color:<?=$bodytxt?>;
---------------------------------------------------------------------------

and

---------------------------------------------------------------------------
h1, h2, h3, h4, h5, h6 {
  color:<?=$headings?>;
  background-color:<?=$highlight1?>;
---------------------------------------------------------------------------

and

---------------------------------------------------------------------------
.sidehead {
  background-color:<?=$highlight1?>;
---------------------------------------------------------------------------

NOW I can change, say, the highlight1 color once, at the top, and have
it change everywhere I've used it.  SO it's kind of like the idea of
wikistyles, but done so I can use them in the skin, and not just on a
wikipage.

I got the code for the combined PHP and CSS from the first part of the
instructions onhttp://www.barelyfitz.com/projects/csscolor/ -- just up
through the section titled "Abstracting Your Colors" -- but those
instructions say to put them in a php file, and call a style php
instead of style css from the html (in our case the skin's .tmpl)
file.

I was having trouble getting it to work, and posted to the site's
forum.  Another poster suggested this business of adding the line
AddType application/x-httpd-php .css
to the .htaccess file, suggesting that one might not want people to
know that one was using php.  I dunno why that would be, but I do like
being able to just add a line to the .htaccess and there-after being
able to put php code right into my css files.  SO the QUESTION is: is
this safe?

Ancilary questions:
Can anyone offer any improvements, or suggest whether this would or
would not make a good cookbook recipe?  If I put it in, what should I
call it?  Should I treat the .htaccess line that enables php in css as
a separate recipe from the use of re-usable names for colors in the
skin?

Thanks!

Tegan



More information about the pmwiki-users mailing list