PHP and accessibility

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Take a look at this package. It may make template creation with PHP easier and faster for you.

http://www.php-tools.de/site.php?file=/ ... /intro.xml
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

Personally I think this will not help.
All I need to know is how can I make it so users select different styles
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Then would this be of more help to you? http://www.alistapart.com/articles/bodyswitchers/
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

I am actually using my own version of one of these scripts to change the stylesheet.
What I want is to generate PHP pages that use values.
so the page would have the content and say the colour of a piece of text would be given the value $test1colour
The colour would be looked up and then the text would display in that colour. I want to have several "stylesheets" (they may not be stylesheets) that the user can pick from . The chosen one would be remembered and future pages would generate usin gthis stylesheet.
The links on the page would have to end in ?[name of stylesheet] automatically
I hope this is clearer
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Gotcha.

What I did on another project was use one stylesheet and place keywords in the CSS. The keywords would be some unique pattern that isn't likely to appear in CSS like $FONTCOLOR$. That is not meant to be a variable but instead a pattern that can be located by a search. Then I would read the CSS and do a search and replace on those keywords based on the users preferences. I would then send that CSS with the web page.

The user preferences were stored in a database and when they logged in I would get their preferences and store them in the session.

You could also provide a dropdown that had some standard styles. If the user picks a style, you load those preferences into session variables and use them. That way a unregistered user can change styles.

This system let me change font size, color, logos, etc. purely based on their choices and there was only one stylesheet to edit.

edit - You could also do as you say and have a URL that includes http://www.domain.com/index.php?style=style1.css. Then use code like this to get the name.

Code: Select all

$stylesheet = (isset($_GETї'style'])) ? $_GETї'style'] : 'default.css';
Then do something like this to load that stylesheet.

Code: Select all

<link href="<?php echo $style; ?>" rel="stylesheet" type="text/css" ></link>
Last edited by smpdawg on Wed Mar 02, 2005 10:43 am, edited 2 times in total.
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

I don't quite understand how to do this.
Please could you explain
Also I don't have access to a database which is a major problem.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Please read the previous post. I added an example that may be more like what you need.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

<style>
<!--
a:link {
font-color: %LINKCOLOR%;
font-size: %LINKSIZE%;
}
etc..
-->
</style>
Then in PHP you would do a

Code: Select all

$CSSContents = file_get_contents($pathToCSS);
$CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
$CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);

... more ...

echo $CSSContents;
And replacing the path, color, etc. as appropriate.
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

I don't full understand how you could do this. could you explain in a bit more detail.
thanks
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

Which part do you have questions about?
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

<style>
<!--
a:link {
font-color: %LINKCOLOR%;
font-size: %LINKSIZE%;
}
etc..
-->
</style>
Where would this go?
$CSSContents = file_get_contents($pathToCSS);
$CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
$CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);

... more ...

echo $CSSContents;
How does this work?
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

The script would go in whatever page is generating the HTML inside of the HEAD tags.

So if you had something that did this.

Code: Select all

<HTML>
  <HEAD>
    <TITLE>My page</TITLE>
  </HEAD>
  <BODY>
    Your content here.
  </BODY>
</HTML>
You would do this.

Code: Select all

<HTML>
  <HEAD>
    <TITLE>My page</TITLE>
<?php
  $CSSContents = file_get_contents($pathToCSS);
  $CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
  $CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);
  echo $CSSContents;
?>
  </HEAD>
  <BODY>
    Your content here.
  </BODY>
</HTML>
That would spit out a page that has the CSS inside of it and the tags would have been replaced to whatever value or variable that you would like.

And the CSS would be in some file that the script could see.
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

<?php
$CSSContents = file_get_contents($pathToCSS);
$CSSContents = str_replace('%LINKCOLOR%", '#0000ff', $CSSContents);
$CSSContents = str_replace('%LINKSIZE%", '12px', $CSSContents);
echo $CSSContents;
?>
What does this mean?
How does it work?
thanks
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

You would use sessions. At the top of each page that generates HTML, you would call to a function that would call session_start(). Then you see if the session variable for font color is set, if not you could give a default. If the user selected a different 'style' you could replace the defaults.

e.g.

Code: Select all

function sessionHandling() &#123;
  session_start();
  $_SESSION&#1111;'linkcolor'] = (isset($_SESSION&#1111;'linkcolor'])) ? $_SESSION&#1111;'linkcolor'] : '#0000ff';  // The #0000ff is the default
  $_SESSION&#1111;'linkcolor'] = (isset($_SESSION&#1111;'linksize'])) ? $_SESSION&#1111;'linksize'] : '#0000ff';  // The 12ox is the default
 etc.
&#125;
The above code would use the session value if it exists or would assign it if it is missing. This way you know that you will always have some value in there.

Having used code similar to what is above, whenever you needed a value you would then access the $_SESSION array to get it like this.

Code: Select all

$_SESSION&#1111;'linkcolor']
Like this example.

Code: Select all

$CSSContents = str_replace('%LINKCOLOR%", $_SESSION&#1111;'linkcolor'], $CSSContents);
horsleyaa
Forum Newbie
Posts: 20
Joined: Tue Mar 01, 2005 8:52 am
Location: Aylesbury, UK

Post by horsleyaa »

I think I understand.
Could you give an example of a page that uses this (the code for the page)

how do the session work?
Post Reply