PHP Classes

File: httclass.txt

Recommend this page to a friend!
  Classes of Joseph E. Albritton   HttClass   httclass.txt   Download  
File: httclass.txt
Role: Documentation
Content type: text/plain
Description: The Info File
Class: HttClass
HTML documents templating engine
Author: By
Last change:
Date: 18 years ago
Size: 7,894 bytes
 

Contents

Class file image Download
===================================================================================================== HYPERTEXT TEMPLATE CLASS (httclass.php) - Author: Joseph E. Albritton - License: Public Domain - Warranty: None, use at own risk - Background: Based on the ParseTemplate class of WinSysInfo 1.21 ===================================================================================================== INTRODUCTION - Hypertext as defined here, is client-side browser renderable code, ie. HTML, SCRIPT, CSS - A .htt file consist of one or more named sections of hypertext - A section of hypertext is delimited by the [/SECTION\] and [\SECTION/] tags, where SECTION is the name - A section of hypertext may contain any number of three different types of replacement tags [|FILE|] - replaced automatically by the content of FILE name [[SECTION]] - replaced automatically by the content of SECTION name [REPLACE] - replaced by calling the Replace() method ===================================================================================================== PURPOSE - Provide flexibilty in how hypertext is used by creating separate, reusable, named sections - Reduce script size and complexity by moving static hypertext into a .htt file - Reduce redundant hypertext by using automatic replacement section tags - Change how data is presented by using different .htt files - Provide tags to be replaced automatically with the content of a file - Provide tags to be replaced automatically with the content of a section - Provide tags to be replaced with user defined data ===================================================================================================== EXAMPLE SCRIPT USING HTTCLASS.PHP (test.php) <?php //--------------------------------------------------------- require_once( "c:/YOUR_PATH/httclass.php" ); $oHtt = new HttClass; if( $oHtt->Init("test.htt") ) { $oHtt->Replace( "[TITLE]", "Example *.htt Usage", "HEAD" ); echo $oHtt->Get( "HEAD" ); $oHtt->Replace( "[DATA]" , "Auto TABLE Section" , "BODY" ); $oHtt->Replace( "[TABLE]", $oHtt->Get( "TABLE" ) , "BODY" ); $oHtt->Replace( "[DATA]" , "Another TABLE Section", "BODY" ); echo $oHtt->Get( "BODY" ); echo $oHtt->Get( "FOOT" ); } //--------------------------------------------------------- ?> ===================================================================================================== EXAMPLE HYPERTEXT TEMPLATE FILE (test.htt) ------------------------------------- [/HEAD\] <html> <head> <title>[TITLE]</title> [|test.txt|] </head> [\HEAD/] ------------------------------------- [/BODY\] <body> [[TABLE]] [TABLE] </body> [\BODY/] ------------------------------------- [/TABLE\] <table border="1"> <tr> <td>[DATA]</td> </tr> </table> [\TABLE/] ------------------------------------- [/FOOT\] </body> </html> [\FOOT/] ------------------------------------- ===================================================================================================== EXAMPLE AUTO REPLACE FILE (test.txt) <script language="JavaScript">x = 1;</script> ===================================================================================================== EXAMPLE RESULTANT HYPERTEXT <html> <head> <title>Example *.htt Usage</title> <script language="JavaScript">x = 1;</script> </head> <body> <table border="1"> <tr> <td>Auto TABLE Section</td> </tr> </table> <table border="1"> <tr> <td>Another TABLE Section</td> </tr> </table> </body> </body> </html> ===================================================================================================== RULES - Init() method must be called first to process the .htt file - The .htt file is processed once, from the top to the bottom - The default section "HTT" is a reserved section name ===================================================================================================== INSTANTIATE require_once( "httclass.php" ); $oHtt = new HttClass; ===================================================================================================== METHODS ----------------------------------------------------------------------------------------------------- Init( FILE ) Action: Read the content of FILE into the "HTT" section Replace all [|FILE|] tags within the "HTT" section with the content of FILE name Replace all [[SECTION]] tags within the "HTT" section with the content of SECTION name Parse the "HTT" section into named sections Clear the "HTT" section Where: FILE is the name of the .htt file (Default = "index.htt" ) Returns: True if success, False if failure Usage: if( $oHtt->Init("Htt_File") ) { ----------------------------------------------------------------------------------------------------- Add( STRING, SECTION ) Action: Add STRING to the content of SECTION name Creates a new named section if SECTION does not exist Where: STRING is the string to add SECTION is the section name to add the string to (Default = "HTT") Returns: True if success, False if failure Usage: $oHtt->Add( "Some_String" ) ----------------------------------------------------------------------------------------------------- Replace( SEARCH, REPLACE, SECTION ) Action: Replace all SEARCH strings within SECTION name with REPLACE string Where: SEARCH is the string to replace REPLACE is the string to replace the search string with SECTION is the section name to replace the search string in (Default = "HTT") Returns: True if success, False if failure Usage: $oHtt->Replace( "[Tag]", "Some_String" ) ----------------------------------------------------------------------------------------------------- Get( SECTION ) Action: Get the content of SECTION name Where: SECTION is the section name to get the content of (Default = "HTT") Returns: Content of section if success, "" if failure Usage: echo $oHtt->Get() ----------------------------------------------------------------------------------------------------- Load( FILE, SECTION ) Action: Load SECTION name with the content of FILE name Creates a new named section if SECTION does not exist Where: FILE is the file name to load SECTION is the section name to load the file into (Default = "HTT") Returns: True if success, False if failure Usage: echo $oHtt->Load( "File_Name" ) ----------------------------------------------------------------------------------------------------- Parse( SECTION ) Action: Parse the SECTION into named sections Where: SECTION is the section name to parse into named sections (Default = "HTT") Returns: True if success, False if failure Usage: $oHtt->Parse() ----------------------------------------------------------------------------------------------------- Clear( SECTION ) Action: Clear the content of SECTION name Where: SECTION is the section name to clear the content of (Default = "HTT") Returns: True if success, False if failure Usage: $oHtt->Clear() ----------------------------------------------------------------------------------------------------- GetStr( STR_BEG, STR_END, STRING ) Action: Get a substring of STRING between STR_BEG and STR_END, non-inclusive Where: STR_BEG is the beginning tag within STRING STR_END is the ending tag within STRING STRING is the string to get the substring from Returns: Substring of string if success, "" if failure Usage: $section = $oHtt->Section( "[Tag_Begin]", "[Tag_End]", $String ) =====================================================================================================