/**
* css_formatter.php
*
* This class is intended to help apply CSS to the output
* of php when forming text to be shown on xhtml pages
* additions needed - ul formatter
*
*
* Written by: Alan Chard
* Last Updated: May 2006
*/
class CSS
{
function ShowSession()
{
echo $this->Tag('h3', 'Contents of the $_SESSION array - - - - - -');
//echo '';
foreach ($_SESSION as $key=>$value )
{
echo $key.' : '.$value.'
';
}
//echo '
';
echo $this->Tag('h3', 'end of Contents of the $_SESSION array - - - - - -');
}
function ShowPost()
{
echo $this->Tag('h3', 'Contents of the $_POST array');
foreach ($_POST as $key=>$value )
{
echo $this->Tag('p', $key.' : '.$value);
}
}
function ShowArray($showit)
{
echo $this->Tag('h3', 'Contents of the array');
if(empty($showit)) {echo 'The array was undefined'.'
'; return;}
foreach ($showit as $key=>$value )
{
echo $this->Tag('p', $key.' : '.$value);
}
}
function ShowEnvVars()
{// Print Environment Variables
echo "Environment Variables from $HTTP_ENV_VARS
";
reset($HTTP_ENV_VARS); // point to first element of array
while (list ($key, $val) = each ($HTTP_ENV_VARS)) {
echo $key . " = " . $val . "
";
}
}
/**
* Tag uses the formatting string to apply CSS to the text string
* use this for h1 ... h6 and similar tags, p,
*/
function Tag($formatting_string, $text){
$open_tag = '<'.$formatting_string.'>';
$close_tag= ''.$formatting_string.'>';
return $open_tag.$text.$close_tag;
}
/**
* a series of tagging utility functions
* use this for h1 ... h6 and similar tags, p,
*/
function p($text){
// wraps text in p tag
return $this->Tag('p', $text);
}
function h1($text){
// wraps text in p tag
return $this->Tag('h1', $text);
}
function h2($text){
// wraps text in p tag
return $this->Tag('h2', $text);
}
function h3($text){
// wraps text in p tag
return $this->Tag('h3', $text);
}
function h4($text){
// wraps text in p tag
return $this->Tag('h4', $text);
}
function h5($text){
// wraps text in p tag
return $this->Tag('h5', $text);
}
function h6($text){
// wraps text in p tag
return $this->Tag('h6', $text);
}
function br(){
// ends text with a br tag
echo '
';
}
/**
* MakeLink
* forms link from url and link text supplied
* you might also want to wrap it with p tags
*/
function MakeLink($url, $link_text){
return ''.$link_text.'';
}
/**
* SetClass
* sets class for any tag, looks for > in the string and does nothing if it's not found
* NOTE WELL - it looks for the first > and replaces it with the class string
* so only use after a style has been applied with Tag
* for setting both tag and class see SetTagAndClass below
*/
function SetClass($class, $text){
if (strpos(">",$text)) return $text; // Do nothing if there is no tag to act on
$class_string = ' class = "'.$class.'">';
return preg_replace("/>/",$class_string, $text,1);
}
/**
* SetTagAndClass
* sets tag and class for the given text
* it's a combination of two existing functions
*/
function SetTagAndClass($tag, $class, $text){
$text=$this->Tag($tag, $text);
$text=$this->SetClass($class, $text);
return $text;
}
/**
* Span encloses the substring in span tags
*
*/
function Span($span_tag, $substring, $text){
if (!strpos($text, $substring)) return '['.$substring.' not found, no span tag applied] '.$text; // Do nothing if the substring is not found
$span_string = '';
$regex='/'.$substring.'/'; // add delimiters for regex
return preg_replace($regex,$span_string.$substring.'', $text,1);
}
/**
* Strong encloses the substring in strong tags
* it does NOT put the text in any other tags, so that it can easily be
* . added to other text and so leave it on the same line
*/
function Strong($text){
return ''.$text.'';
}
/**
* Format a span class to cloak email addresses
* this works in conjunction with a script that does a lot of the work
* to get the full cloaking the javascript must also be 'included'
* this function converts an email address in the form
* xxxxx@domain.[second level domain].tld into
* edmonton(at)taoist.org
*/
function CloakEmail($email){
$email=preg_replace('/@/','(at)', $email);
return ''.$email.'';
}
/**
* If the item passed has a value then format it in a tag (defaults to p)
* using the optional class supplied
* Used to insert database values that are optional
*/
function EchoIfSet($item, $label="", $tag="p", $class=""){
if(strlen($item)>0)
{
$item=$label.$item;
$rev_item=$this->Tag($tag, $item);
return ((strlen($class)>0) ? $this->SetClass($class, $rev_item) : $rev_item);
}
else
{
return; // do nothing
}
}
/**
* forms a tag around the passed link and link text
*
*
*/
function liLink($link, $link_text) {
return ''.$this->MakeLink($link, $link_text).'';
}
/**
* forms a link that passes paramters to the SPECIAL_ACTIONS_HANDLER (see config for path)
* $image_path is the relative path, needs to be so because of server base directive
* $alt_text is just that
* the image is queried using getimagesize to obtain the width and height details
* p_id and the action text are pass-thru parameters
*/
function imageLink($p_id, $image_path, $action='fail', $alt_text='Click to perform this action') {
$image_size_string=getimagesize($image_path);
$final_link='
';
#echo 'imageLink returned : '.$final_link.'
';
return $final_link;
}
/**
* outputs class setting for form messages, this sets them error or no error depending on $field passed
*/
function set_display_class($field, $error_array, $error_class='inputError', $non_error_class='required'){
if(isset($error_array[$field])) {$class=' class="'.$error_class.' "';} else {$class=' class="'.$non_error_class.' "';}
return $class;
}
};
?>