Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Cached Dynamic Modules - The 3rd Incarnation
For those of you who have been interested in the evolution of the Cached Dynamic Modules, here's the 3rd Incarnation. This article is written on the assumption that you are partly familiar with the Cached Dynamic Modules script. These first few pages go over the additions, and updates to the original code; then dives right into the (pretty) source code. The code should look familiar because a lot of the code used in this version has been used verbatim to the way Spencer set it forth in his article, Another Look At "Building Your Website With Cached Dynamic Modules". Thanks are due to both Spencer and JP for their initial work on the project.
Change
Features Added
Debugging mode
Debugging of the parser is now available. Nearly all variables are printed in the parse_it() function as they are set. A common output would read:

$str_func on line 234 = handle_xxx
Almost all of the information printed while in debugging mode gives the line at which it was generated to help you find it in the code. However useful this may be, it is strongly advised that you don't use this on public portion of the website. Exposing all of the variable names to prying eyes could prove a disaster to your site security.
Module file checking
In Spencer's version, no checking was done to ensure that the module file to be included existed. Checking was added, and if the file does not exist, the current information is returned with the following error message added to the line above the custom code:

<!-- xxx cannot be processed - # -->
xxx is replaced with the name of the custom tag, and # is replaced with the line number which it was returned.
Closing tag support
Before, only opening tags (tags without a '/') were processed. This would be fine as long as the custom tags were not being replaced by tags that went around the text or images within the opening and closing tags (ie. a table cell). Support was added, in an identical way to the opening tag, except it calls handle_close_xxx() instead of handle_xxx(). The module file is still the same.
The default cache time is now set via the call to the parse_it() function. This is set so you can change how long the default caches are set for programmatically. This will require editing the parse() function, however.
Modifications
Function variables modified
The parse() and parse_it() functions were changed to the following:

function parse( $doc_root, $file, $_debug = false)
function parse_it( $str, $doc_root, $use_tag, $_debug = false, $def_cache_time = 3600 )
  • $doc_root is the equivalent of PHP's $DOCUMENT_ROOT. There were some problems accessing the global variable, so it was added into the function calls.
  • $_debug has been added to enable/disable debugging mode. By default, debugging mode is turned off.
  • $use_tag in the parse_it() function is the dynamically generated custom tag (example $use_tag = "my" if the file extension is ".my")
  • $def_cache_time in the parse_it() is used to change the default cache time. If it is not set, 3600 seconds (60 minutes) is assumed.
  • $str & $str were respectively carried over from their original purpose with their own functions
Comments revised
The comments within the file parse.php3 have been extensively revised. So much so, that documentation outside the file would be extremely redundant. Also added in the comments section at the bottom of the file are instructions on how to setup parse.php3 to run, as well as example files to test the parser out.