Main file

This is the implementation of Septum.

Summary
This is the implementation of Septum.
The type of beginning token quotes to use.
The type of ending token quotes to use.
The tokens ending keyword.
The token ending keyword.
The token parameter keyword.
Specifies what to return when the page has no KEYWORDS_END token.
Specifies the extension that each page will have.
Specifies the variable to use when GETting the page, for example www.myserver.com/index.php?page=index.
Specifies whether or not to use document caching.
Specifies the number of seconds to cache the page.
Specifies the name of the template file.
The page to be returned when the requested page could not be found.
This will be prepended to the page filename.
The main function.
Returns a file through the method specified (file, MySQL page, etc).
Returns the tokens section of a file.
Returns the page section of a file.
Parses the tokens section of a file.
Replaces tokens in $strFile with the text specified in $arrTokens.
Replaces a token with its value taking into account that it may contain other tokens within it.
Replaces a complex token with its value.

Constants

CONST_BEGINNING_QUOTES

The type of beginning token quotes to use.

CONST_ENDING_QUOTES

The type of ending token quotes to use.

CONST_KEYWORDS_END

The tokens ending keyword.

CONST_TOKEN_END

The token ending keyword.

CONST_PARAM_KEYWORD

The token parameter keyword.

Options

OPTION_RETURN_FULL_PAGE

Specifies what to return when the page has no KEYWORDS_END token.  If set to TRUE the page is returned.  Setting to false doesn’t make much sense, since a bare template is not of much use, but I have included it here anyway.

OPTION_PAGE_EXTENSION

Specifies the extension that each page will have.  This will be appended to each request.  Warning: DO NOT LEAVE EMPTY!  If you leave this empty then users will be able to read any page in the current directory (and perhaps other directories) and see your PHP files.

OPTION_PAGE_NAME

Specifies the variable to use when GETting the page, for example www.myserver.com/index.php?page=index.  This changes the “page” variable in the previous example.

OPTION_CACHE_DOCUMENT

Specifies whether or not to use document caching.  Since most pages are static, this could greatly improve performance on your server.  Make sure there is a subdirectory called /cache in that path, or it will not work.  This uses the PEAR’s Cache_Lite object, but the file is included in Septum in case you do not have it installed on the server.

OPTION_CACHE_TIME

Specifies the number of seconds to cache the page.  If this many seconds pass, a new page is generated.  Only applicable if caching is enabled.

OPTION_TEMPLATE_NAME

Specifies the name of the template file.

OPTION_ERROR_PAGE

The page to be returned when the requested page could not be found.  Can be a tokens page or a normal HTML page (if the RETURN_FULL_PAGE option is set to TRUE).

OPTION_BASE_PATH

This will be prepended to the page filename.  Use it if all your pages are in a sub directory, or for added security(?).

Functions

fnMain

function fnMain()

The main function.  Opens the files and replaces the tokens of the template into the tokens of the page and then those into the template.

Parameters

None.

Returns

Nothing.

fnGetFile

function fnGetFile($strPage,
$intMethod)

Returns a file through the method specified (file, MySQL page, etc).

Parameters

$strPageA string containing the page name.
$intMethodAn integer specifying the method to return it through (currently 0 for file).

Returns

A string containing the file.

fnGetTokens

function fnGetTokens($strFile)

Returns the tokens section of a file.

Parameters

$strFileA string containing the file to parse.

Returns

A string containing the tokens section, or NULL if there is no such section.

fnGetPage

function fnGetPage($strFile)

Returns the page section of a file.

Parameters

$strFileA string containing the file to parse.

Returns

A string containing the page.

fnParseTokens

function fnParseTokens($strFile)

Parses the tokens section of a file.

Parameters

$strFileA string containing the tokens section of the file to parse.

Returns

An array containing the tokens to be passed to fnReplaceTokens (in the form ($array[TOKEN] = TEXT]) or NULL if $strFile is empty.

fnReplaceTokens

function fnReplaceTokens($strFile,
$arrTokens)

Replaces tokens in $strFile with the text specified in $arrTokens.

Parameters

$strFileA string containing the page in which to replace tokens.
$arrTokensThe array that holds the tokens to replace, created by fnParseTokens.

Returns

A string containing the replaced page.

fnReplaceParameters

function fnReplaceParameters($strToken,
$strValue,
$strText)

Replaces a token with its value taking into account that it may contain other tokens within it.

Parameters

$strTokenA string containing the token to be expanded.
$strValueA string containing the token value.
$strTextA string containing the text to search.

Returns

An array of a string containing the replaced text and a number containing the number of replacements made.

fnExpandComplexToken

function fnExpandComplexToken($strToken,
$strValue)

Replaces a complex token with its value.

Parameters

$strTokenA string containing the token to be expanded (without the quotes).
$strValueA string containing the token value.

Returns

A string containing the replaced token value.

function fnMain()
The main function.
function fnGetFile($strPage,
$intMethod)
Returns a file through the method specified (file, MySQL page, etc).
function fnGetTokens($strFile)
Returns the tokens section of a file.
function fnGetPage($strFile)
Returns the page section of a file.
function fnParseTokens($strFile)
Parses the tokens section of a file.
function fnReplaceTokens($strFile,
$arrTokens)
Replaces tokens in $strFile with the text specified in $arrTokens.
function fnReplaceParameters($strToken,
$strValue,
$strText)
Replaces a token with its value taking into account that it may contain other tokens within it.
function fnExpandComplexToken($strToken,
$strValue)
Replaces a complex token with its value.