Location: PHPKode > scripts > Text Resizer > text-resizer/text-resizer.class.php
<?php

/*
*
* author: hide@address.com
* css help from Collin Olan <hide@address.com>
* 
* Release: 2003-08-22
* License: Gnu Public License <http://www.gnu.org/copyleft/gpl.html?cid=6>
* 
* 

Short Description: Resizes text on a page using styles and sessions.

Full Description: Thanks to the cascading nature of CSS, a simple font-size percentage can be included in the head of any page to facilite this text resizer.  It will not desirupt any other attribute of your styles except the body's font size.  Directions: Instantiate this object on any page where you want to use the resizer, call ProcessTextReset(), and reset the text size by passing query string variables: set_text=smaller, set_text=larger, or set_text=normal (the class uses sessions to remember values).  The font size is reset to a percentage of the default size of your user's browser.  It should be compatible with all of PHP 4; let me know if you find problems.

*
*/

class TextResizer
{

var $PercentageIncrement = 10; 
var $TextPercentage;

function TextResizer()
{
	session_start();
} // END function TextResizer()

function GetGetVar($VarName)
{
	if(!empty($GLOBALS['HTTP_GET_VARS'][$VarName])) 
		$_GET[$VarName] = $GLOBALS['HTTP_GET_VARS'][$VarName];
	return $_GET[$VarName];
} // END function GetGetVar($VarName)

function GetSessionVar($VarName)
{
	if(!empty($GLOBALS['HTPP_SESSION_VARS'][$VarName]))
		$_SESSION[$VarName] = $GLOBALS['HTPP_SESSION_VARS'][$VarName];
	return $_SESSION[$VarName];
} // END function GetSessionVar($VarName)

function GetTextPercentage()
{
	if(!empty($this->TextPercentage))
		return $this->TextPercentage;
	$this->TextPercentage = $this->GetSessionVar('TextPercentage');
	if(!empty($this->TextPercentage))
		return $this->TextPercentage;
	$this->TextPercentage = 100;
	return $this->TextPercentage;
} // END function GetTextPercentage()

# function PrintStyle()
#
# this style must be printed after any other styles are defined.
# It should not disrupt any other part of your style except the body's
# font size
function PrintStyle()
{
	$TextPercentage = $this->GetTextPercentage();
	$Style = <<<Style
<style type="text/css"> body { font-size: $TextPercentage%; } </style>

Style;
	echo $Style;
} // END function PrintStyle()

function ProcessTextReset()
{
	$SetText = $this->GetGetVar('set_text');
	$TextPercentage = $this->GetTextPercentage();
	if(empty($TextPercentage)) $TextPercentage = 100;
	switch($SetText) {
		case 'smaller':
			$TextPercentage -= $this->PercentageIncrement;
			break;
		case 'larger':
			$TextPercentage += $this->PercentageIncrement;
			break;
		case 'normal':
			$TextPercentage = 100;
			break;
	} // END switch($SetText) {
	$this->SetTextPercentage($TextPercentage);
} // END function ProcessTextReset()

function SetPercentageIncrement($PercentageIncrement)
{
	$this->PercentageIncrement = $PercentageIncrement;
} // END function SetPercentageIncrement($PercentageIncrement)

function SetSessionVar($VarName,$Value)
{
	if(isset($_SESSION))
		$_SESSION[$VarName] = $Value;
	else
		$GLOBALS['HTTP_SESSION_VARS'][$VarName] = $Value;
} // END function SetSessionVar($VarName,$Value)

# function SetTextPercentage($TextPercentage)
#
# this method sets the percentage for the text, i.e. 100%
# If you want to give your users a static number of text percentage options
# you should create a new processing function like ProcessTextReset() to wrap
# around this function
function SetTextPercentage($TextPercentage)
{
	$this->SetSessionVar('TextPercentage',$TextPercentage);
	$this->TextPercentage = $TextPercentage;
} // END function SetTextPercentage($TextPercentage)

} // END class TextResizer

?>
Return current item: Text Resizer