PHP Framework

Download Report

Transcript PHP Framework

PHP Framework
Presented by
Phil Barnett
LEAP Meeting
November 21, 2002
Copyleft 2002, Phil Barnett
<? ob_start("ob_gzhandler") ?>
void ob_start ( [string output_callback])
This function will turn output buffering on. While output buffering is active no output is sent from the script
(other than headers), instead the output is stored in an internal buffer.
The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output
what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently
discard the buffer contents.
An optional output_callback function may be specified. This function takes a string as a parameter and
should return a string. The function will be called when ob_end_flush() is called, or when the output
buffer is flushed to the browser at the end of the request. When output_callback is called, it will receive
the contents of the output buffer as its parameter and is expected to return a new output buffer as a
result, which will be sent to the browser.
Note: In PHP 4.0.4, ob_gzhandler() was introduced to facilitate sending gz-encoded data to web
browsers that support compressed web pages. ob_gzhandler() determines what type of content
encoding the browser will accept and will return it's output accordingly.
index.php3
<? ob_start("ob_gzhandler") ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<? include( "title.htm" ) ?>
<? include( "metatags.htm" ) ?>
<? include( "style.htm" ) ?>
</HEAD>
<!-- Contains <BODY> tag --><? include( "body.htm" ) ?>
<TABLE width="100%" cellpadding="0" cellspacing="12">
<TBODY>
<TR>
<TD valign="top" align="left" style="bodytext">
<!-- BODY BEGIN -->
<? include( "header.htm" ) ?>
<P>
<? include( "mainbody.htm" ) ?>
<? include( "footer.php3" ) ?>
<!-- BODY END -->
</TD>
<TD valign="top" align="center" width="160">
<!-- MENU BEGIN -->
<? include "mainmenu.htm" ?>
<!-- MENU END -->
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
<? ob_end_flush() ?>
header.htm
<P class="header"><IMG SRC="logo.gif" ALT="Logo"></P>
<P class="banner">Everything Linux!</P>
<P class="header">---------------------- Header Ends Here ---------------------</P>
mainbody.htm
Everything between the header and the footer comes from <B>mainbody.htm</B>. It's just a file that
contians the body of content for your sites main page. You can put any text or highly formatted html
here.
<hr align="center" size="1" width="90%">
This is just ordinary text.
<P>You can put <i>formatting</i> in it, <B>but it should not contain header or body tags.</B>
<P class="monospace">
(should be monospaced and indented 10%) You can inherit from the style sheets!
</P>
A perl script regex to find CRLF/CR/LF and replace with &lt;P&gt; is appropriate.
<P class="funcky">This text or content could come from a form using the POST method for
dynamic content, it could come from a database, or it could be static
content mixed with both of the above. (think /.)</P>
title.htm
<TITLE>Linux Rulez!(and so does Open Source!)</TITLE>
metatags.htm
<META NAME="description" CONTENT="This site is a test for php frameworks">
<META NAME="keywords" CONTENT="CSS, style sheets, php, framework,phil barnett">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
style.htm
<STYLE TYPE="text/css">
BODY { background-image: url("blustripe .jpg") }
LI, H1, H2, H3, H4, H5, H6, TABLE { font-family: sans-serif }
P.header { margin-left: 10%; margin-right: 10%; }
P.margins { margin-left: 5%; margin-right: 10%; }
TABLE.header {background-image: url(grey-striped.gif)}
TABLE.mainbody { font-size: large }
TABLE.menu { font-size: medium; text-align: center; background-color:
#fff5c5; border-right-width: thick; border-color: #ffe98a}
TABLE.submenu { font-size: medium; text-align: left; background-color:
#ffbbcc; border-right-width: thick; border-color: #bbbbbb}
P.monospace {font-family: monospace; margin-left: 10% }
TD.content { font-size: small }
P.content { font-size: small }
P.banner { font-size: xx-large; color: blue; font-style: bold; text-align: center }
P.header { font-size: medium; text-align: center; font-style: italic }
P.footer { font-size: medium; text-align: center; font-style: italic }
P.copyright { font-size: large; text-align: center; color: green }
P.funcky { font-size: medium; color: purple }
</STYLE>
Reference:
http://www.w3.org/Style/CSS/
footer.php3
<P class="footer">---------------------------- Footer Begins Here ---------------------------</P>
<P class="footer">Last Maintenance: November 21, 2002</P>
<P class="copyright">Copyleft 2002 Phil Barnett. All Rights Reversed.</P>
mainbody.htm
Everything between the header and the footer comes from <B>mainbody.htm</B>.
It's just a file that contians the body of content for your sites main page.
You can put any text or highly formatted html here.
<hr align="center" size="1" width="90%">
This is just ordinary text.
<P>You can put <i>formatting</i> in it, <B>but it should not contain header
or body tags.</B>
<P class="monospace">
(should be monospaced and indented 10%) You can inherit from the style
sheets!
</P>
A perl script regex to find CRLF/CR/LF and replace with &lt;P&gt; is
appropriate.
<P class="funcky">This text or content could come from a form using the POST
method for
dynamic content, it could come from a database, or it could be static
content mixed with both of the above. (think /.)</P>
mainmenu.htm
<TABLE width="160" cellpadding="2" cellspacing="2" border="0" style="menu">
<TBODY>
<TR>
<TD bgcolor="#000000">
<TABLE bgcolor="#91C8FF" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR> <TD align="center"><B>Menu</B></TD></TR>
</TABLE>
</TD>
</TR>
<TR>
<TD align=center><A HREF="master.php3?content=foo.htm">Foo Foo Foo</A></TD>
</TR>
<TR>
<TD align=center><A HREF="master.php3?content=bar.htm">Bar Bar Bar</A></TD>
</TR>
<TR>
<TD align=center><A HREF="master.php3?content=baz.htm">Baz Baz Baz</A></TD>
</TR>
<TR>
<TD align=center><A HREF="master.php3?content=feedback.htm">Feedback</A></TD>
</TR>
<TR>
<TD align=center><A HREF="index.php3">Home Page</A></TD>
</TR>
</TBODY>
</TABLE>
strcasecmp()
int strcasecmp ( string str1, string str2)
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than
str2, and 0 if they are equal.
master.php3
<? ob_start("ob_gzhandler") ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<? include( "title.htm" ) ?>
<? include( "metatags.htm" ) ?>
<? include( "style.htm" ) ?>
</HEAD>
<!-- Contains <BODY> tag --><? include( "body.htm" ) ?>
<TABLE width="100%" cellpadding="0" cellspacing="12">
<TBODY>
<TR>
<TD valign="top" align="left" class="content">
<!-- BODY BEGIN -->
<? include( "header.htm" ) ?>
<P>
<? if( ( strcasecmp( $content , "master.php3" ) != 0 ) && ( file_exists( $content) ) )
{include( $content );}
?>
<? include( "footer.php3" ) ?>
<!-- BODY END -->
</TD>
<TD valign="top" align="center" width="160">
<!-- MENU BEGIN -->
<? include "submenu.htm" ?>
<!-- MENU END -->
</TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</HTML>
<? ob_end_flush() ?>
submenu.php3
<TABLE width="160" cellpadding="2" cellspacing="2" border="0" style="submenu">
<TBODY>
<TR>
<TD bgcolor="#000000">
<TABLE bgcolor="#91C8FF" width="100%" border="0" cellspacing="0" cellpadding="0">
<TR> <TD align="center"><B>Menu</B></TD></TR>
</TABLE>
</TD>
</TR>
<TR>
<TD align=center><A
HREF="master.php3?content=bing.htm">Bing</A></TD>
</TR>
<TR>
<TD align=center><A
HREF="master.php3?content=bang.htm">Bang</A></TD>
</TR>
<TR>
<TD align=center><A
HREF="master.php3?content=bong.htm">Bong</A></TD>
</TR>
<TR>
<TD align=center><A HREF="index.php3">Home Page</A></TD>
</TR>
</TBODY>
</TABLE>