PHP Generated Stylesheet not modifying layout as .. (solved)
Posted: Sat Jul 07, 2007 9:18 pm
Code: Select all
<?php
include("template.class.php");
$template=new template();
$template->set_title("Testing");
$template->set_body("Test");
$template->set_css("Invalid CSS");
$template->output();
?>Code: Select all
public function set_css($css)
{
$css_code=$css;
if(is_file($css))
{
$handle=fopen($css,"r");
$css_code=stream_get_contents($handle);
fclose($handle);
$file=true;
}
if (stripos($css_code,"<script type='text/css'>")
||
stripos($css_code,"<script type=\"text/css\">"))
{
if (stripos($css_code,"</script>"))
{
if($file)
{
$this->css_external[]=$css;
}
else
{
$this->css[]=$css_code;
}
}
else
{
$this->error[]="CSS must have a valid closing tag, \"</script>\"";
}
}
else
{
$this->error[]="CSS must have a valid starting tag, \"<script type='text/css'>\"
or \"<script type=\"text/css\"> \"";
}
}Code: Select all
public function output()
{
$this->check_empty();
if(sizeof($this->error)>0)
{
$this->get_error();
$this->construct_page();
}
else
{
$this->construct_page();
}
}
Code: Select all
private function get_error()
{
unset($this->body,$this->doctype,$this->title,$this->javascript,$this->javascript_external);
unset($this->css,$this->css_external);
$this->set_doctype("XHTML 1.0 Strict");
$this->set_title("Templating Error");
$this->set_css("
<script type=\"text/css\">
body
{
background-color:#66AADD;
text-align:center;
font-weight:bold;
}
</script>");
foreach($this->error as $error_message)
{
$this->set_body("
<div class='error_message'>
$error_message
</div>
");
}
}Code: Select all
private function construct_page()
{
ob_start();
?>
<?php echo $this->valid_doctypes[$this->doctype];?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>
<?php echo $this->title;?>
</title>
<?php
echo $this->display_javascript();
echo $this->display_css();
?>
</head>
<body>
<?php echo $this->body;?>
<?php echo $this->footer;?>
</body>
</html>
<?php
ob_flush();
}Nothing too complex I'd think but the css style's aren't applying and I'm thinking it has something to do with the way I'm using output buffering. If someone could provide some insight? To see the page in action simply go to http://ourlifeproject.com/monopoly/. Let me know if there's anything else I can add to help clear this up.
And to save you the trouble of right clicking and hit view source...
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>
Templating Error </title>
<script type="text/css">
body
{
background-color:#66AADD;
text-align:center;
font-weight:bold;
}
</script> </head>
<body>
<div class='error_message'>
CSS must have a valid starting tag, "<script type='text/css'>"
or "<script type="text/css"> "
</div>
</body>
</html>