<?xml version="1.0"?><phpdoc><class name="IntegratedTemplate" extends="" undoc="false" access="public"><file>c:/www/apache/doc2//form/IT.php</file><doc><author email="uw@netuse.de">Ulf Wendel</author><description>Well there&amp;apos;s not much to say about it. I needed a template class thatsupports a single template file with multiple (nested) blocks inside anda simple block API.The Isotemplate API is somewhat tricky for a beginner although it is the bestone you can build. template::parse() [phplib template = Isotemplate] requestsyou to name a source and a target where the current block gets parsed into.Source and target can be block names or even handler names. This API gives youa maximum of fexibility but you always have to know what you do which isquite unusual for php skripter like me.I noticed that I do not any control on which block gets parsed into which one.If all blocks are within one file, the script knows how they are nested and inwhich way you have to parse them. IT knows that inner1 is a child of block2, there&amp;apos;sno need to tell him about this.&amp;lt;table border&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td colspan=2&amp;gt;__global__&amp;lt;p&amp;gt;(hidden and automatically added)&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;block1&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;lt;table border&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td colspan=2&amp;gt;block2&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;inner1&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;inner2&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;To add content to block1 you simply type:&amp;lt;code&amp;gt;$tpl-&amp;gt;setCurrentBlock(&amp;quot;block1&amp;quot;);&amp;lt;/code&amp;gt;and repeat this as often as needed:&amp;lt;code&amp;gt;$tpl-&amp;gt;setVariable(...);$tpl-&amp;gt;parseCurrentBlock();&amp;lt;/code&amp;gt;To add content to block2 you would type something like:&amp;lt;code&amp;gt;$tpl-&amp;gt;setCurrentBlock(&amp;quot;inner1&amp;quot;);$tpl-&amp;gt;setVariable(...);$tpl-&amp;gt;parseCurrentBlock();$tpl-&amp;gt;setVariable(...);$tpl-&amp;gt;parseCurrentBlock();$tpl-&amp;gt;parse(&amp;quot;block1&amp;quot;);&amp;lt;/code&amp;gt;This will result in one repition of block1 which contains two repitionsof inner1. inner2 will be removed if $removeEmptyBlock is set to true which is the default.Usage:&amp;lt;code&amp;gt;$tpl = new IntegratedTemplate( [string filerootdir] );// load a template or set it with setTemplate()$tpl-&amp;gt;loadTemplatefile( string filename [, boolean removeUnknownVariables, boolean removeEmptyBlocks] )// set &amp;quot;global&amp;quot; Variables meaning variables not beeing within a (inner) block$tpl-&amp;gt;setVariable( string variablename, mixed value );// like with the Isotemplates there&amp;apos;s a second way to use setVariable()$tpl-&amp;gt;setVariable( array ( string varname =&amp;gt; mixed value ) );// Let&amp;apos;s use any block, even a deeply nested one$tpl-&amp;gt;setCurrentBlock( string blockname );// repeat this as often as you need it.$tpl-&amp;gt;setVariable( array ( string varname =&amp;gt; mixed value ) );$tpl-&amp;gt;parseCurrentBlock();// get the parsed template or print it: $tpl-&amp;gt;show()$tpl-&amp;gt;get();&amp;lt;/code&amp;gt;</description><shortdescription>Integrated Template - IT</shortdescription><version>$Id: IT.php,v 1.3 2001/01/19 13:37:03 sbergmann Exp $</version></doc><function name="IntegratedTemplate" undoc="false" access="public"><doc><see type="function">setRoot()</see><parameter name="$root" default="&amp;quot;&amp;quot;" type="string">root directory, prefix for all filenames given to the object.</parameter><return type="void"/><description>Make sure that you call this constructor if you derive your templateclass from this one.</description><shortdescription>Builds some complex regular expressions and optinally sets the file root directory.</shortdescription></doc></function><function name="show" undoc="false" access="private"><doc><see type="function">show()</see><parameter name="$block" default="&amp;quot;__global__&amp;quot;" type="string">of the block</parameter><return type="void"/><description/><shortdescription>Print a certain block with all replacements done.</shortdescription><brother>get</brother></doc></function><function name="get" undoc="false" access="public"><doc><see type="function">show()</see><parameter name="$block" default="&amp;quot;__global__&amp;quot;" type="string">of the block</parameter><return name="" type="string"/><description/><shortdescription>Returns a block with all replacements done.</shortdescription></doc></function><function name="parse" undoc="false" access="public"><doc><see type="function">parseCurrentBlock()</see><parameter name="$block" default="&amp;quot;__global__&amp;quot;" type="string">of the block to be parsed</parameter><parameter name="$flag_recursion" type="boolean" undoc="true"/><return type="void"/><description/><shortdescription>Parses the given block.</shortdescription></doc></function><function name="parseCurrentBlock" undoc="false" access="public"><doc><see type="function">parse()</see><see type="function">setCurrentBlock()</see><see type="var">$currentBlock</see><return type="void"/><description/><shortdescription>Parses the current block</shortdescription></doc></function><function name="setVariable" undoc="false" access="public"><doc><parameter name="$variable" type="mixed">with the variable name or an array %variables[&amp;quot;varname&amp;quot;] = &amp;quot;value&amp;quot;</parameter><return type="void"/><description>The function can be used eighter like setVariable( &amp;quot;varname&amp;quot;, &amp;quot;value&amp;quot;)or with one array $variables[&amp;quot;varname&amp;quot;] = &amp;quot;value&amp;quot; given setVariable($variables)quite like phplib templates set_var().</description><shortdescription>Sets a variable value.</shortdescription></doc></function><function name="setCurrentBlock" undoc="false" access="public"><doc><parameter name="$block" default="&amp;quot;__global__&amp;quot;" type="string">of the block</parameter><return name="" type="boolean">false on failure, otherwise true</return><description/><shortdescription>Sets the name of the current block that is the block where variables are added.</shortdescription></doc></function><function name="touchBlock" undoc="false" access="public"><doc><see type="var">$removeEmptyBlocks</see><parameter name="$block" type="string">of the block</parameter><return name="" type="boolean">false on false, otherwise true</return><description/><shortdescription>Preserves an empty block even if removeEmptyBlocks is true.</shortdescription></doc></function><function name="init" undoc="false" access="public"><doc><see type="function">free()</see><return type="void"/><description>LoadTemplatefile() and setTemplate() automatically call this functionwhen a new template is given. Don&amp;apos;t use this functionunless you know what you&amp;apos;re doing.</description><shortdescription>Clears all datafields of the object and rebuild the internal blocklist</shortdescription></doc></function><function name="free" undoc="false" access="public"><doc><see type="function">init()</see><return type="void"/><description>Don&amp;apos;t use this function unless you know what you&amp;apos;re doing.</description><shortdescription>Clears all datafields of the object.</shortdescription></doc></function><function name="setTemplate" undoc="false" access="public"><doc><see type="function">LoadTemplatefile()</see><see type="var">$template</see><parameter name="$template" type="string">content</parameter><return type="void"/><description>You can eighter load a template file from disk with LoadTemplatefile() or set thetemplate manually using this function.</description><shortdescription>Sets the template.</shortdescription></doc></function><function name="loadTemplatefile" undoc="false" access="public"><doc><see type="var">$template</see><see type="var">$removeUnknownVariables</see><see type="var">$removeEmptyBlocks</see><see type="function">setTemplate()</see><parameter name="$filename" type="string">of the template file</parameter><parameter name="$removeUnknownVariables" default="true" type="boolean">to handle unknown variables.</parameter><parameter name="$removeEmptyBlocks" default="true" type="boolean">to handle empty blocks.</parameter><return name="" type="boolean">false on failure, otherwise true</return><description/><shortdescription>Reads a template file from the disk.</shortdescription></doc></function><function name="setRoot" undoc="false" access="public"><doc><see type="function">IntegratedTemplate()</see><parameter name="$root" type="string"/><return type="void"/><description>Make sure that you override this function when using the classon windows.</description><shortdescription>Sets the file root. The file root gets prefixed to all filenames passed to the object.</shortdescription></doc></function><function name="buildBlockvariablelist" undoc="false" access="private"><doc><return type="void"/><description/><shortdescription>Build a list of all variables within of a block</shortdescription></doc></function><function name="getGlobalvariables" undoc="false" access="private"><doc><return type="void"/><description/><shortdescription>Returns a list of all</shortdescription></doc></function><function name="findBlocks" undoc="false" access="private"><doc><see type="var">$blocklist</see><parameter name="$string" type="string">that gets scanned</parameter><return type="void"/><description/><shortdescription>Recusively builds a list of all blocks within the template.</shortdescription></doc></function><function name="getFile" undoc="false" access="private"><doc><parameter name="$filename" type="string"/><return name="" type="string">Filecontent </return><description/><shortdescription>Reads a file from disk and returns its content.</shortdescription></doc></function><function name="halt" undoc="false" access="private"><doc><see type="var">$err</see><parameter name="$message" type="string">message</parameter><parameter name="$file" default="&amp;quot;&amp;quot;" type="mixed">where the error occured</parameter><parameter name="$line" default="0" type="integer">where the error occured</parameter><return type="void"/><description/><shortdescription>Error Handling function.</shortdescription></doc></function><variable name="$err" access="public" type="array">array()<doc><see type="function">halt()</see><see type="var">$printError</see><see type="var">$haltOnError</see><description/><shortdescription>Contains the error objects</shortdescription></doc></variable><variable name="$printError" access="public" type="boolean">false<doc><see type="function">halt()</see><see type="var">$haltOnError</see><see type="var">$err</see><description/><shortdescription>Print error messages?</shortdescription></doc></variable><variable name="$haltOnError" access="public" type="boolean">false<doc><see type="function">halt()</see><see type="var">$printError</see><see type="var">$err</see><description/><shortdescription>Call die() on error?</shortdescription></doc></variable><variable name="$clearCache" access="private" type="boolean">false<doc><description/><shortdescription>Clear cache on get()?</shortdescription></doc></variable><variable name="$openingDelimiter" access="public" type="string">&amp;quot;{&amp;quot;<doc><see type="var">$closingDelimiter</see><see type="var">$blocknameRegExp</see><see type="var">$variablenameRegExp</see><description/><shortdescription>First character of a variable placeholder ( _{_VARIABLE} ).</shortdescription></doc></variable><variable name="$closingDelimiter" access="public" type="string">&amp;quot;}&amp;quot;<doc><see type="var">$openingDelimiter</see><see type="var">$blocknameRegExp</see><see type="var">$variablenameRegExp</see><description/><shortdescription>Last character of a variable placeholder ( {VARIABLE_}_ ).</shortdescription></doc></variable><variable name="$blocknameRegExp" access="public" type="string">&amp;quot;[0-9A-Za-z_-]+&amp;quot;<doc><see type="var">$variablenameRegExp</see><see type="var">$openingDelimiter</see><see type="var">$closingDelimiter</see><description>Per default &amp;quot;sm&amp;quot; is used as the regexp modifier, &amp;quot;i&amp;quot; is missing.That means a case sensitive search is done.</description><shortdescription>RegExp matching a block in the template.</shortdescription></doc></variable><variable name="$variablenameRegExp" access="public" type="string">&amp;quot;[0-9A-Za-z_-]+&amp;quot;<doc><see type="var">$blocknameRegExp</see><see type="var">$openingDelimiter</see><see type="var">$closingDelimiter</see><description>Per default &amp;quot;sm&amp;quot; is used as the regexp modifier, &amp;quot;i&amp;quot; is missing.That means a case sensitive search is done.</description><shortdescription>RegExp matching a variable placeholder in the template.</shortdescription></doc></variable><variable name="$variablesRegExp" access="public" type="string">&amp;quot;&amp;quot;<doc><see type="function">IntegratedTemplate()</see><description/><shortdescription>RegExp used to find variable placeholder, filled by the constructor.</shortdescription></doc></variable><variable name="$removeVariablesRegExp" access="private" type="string">&amp;quot;&amp;quot;<doc><description/><shortdescription>RegExp used to strip unused variable placeholder.</shortdescription></doc></variable><variable name="$removeUnknownVariables" access="public" type="boolean">true<doc><description/><shortdescription>Controls the handling of unknown variables, default is remove.</shortdescription></doc></variable><variable name="$removeEmptyBlocks" access="public" type="boolean">true<doc><description/><shortdescription>Controls the handling of empty blocks, default is remove.</shortdescription></doc></variable><variable name="$blockRegExp" access="private" type="string">&amp;quot;&amp;quot;<doc><see type="function">IntegratedTemplate()</see><description/><shortdescription>RegExp used to find blocks an their content, filled by the constructor.</shortdescription></doc></variable><variable name="$currentBlock" access="private" type="string">&amp;quot;__global__&amp;quot;<doc><description/><shortdescription>Name of the current block.</shortdescription></doc></variable><variable name="$template" access="private" type="string">&amp;quot;&amp;quot;<doc><description/><shortdescription>Content of the template.</shortdescription></doc></variable><variable name="$blocklist" access="private" type="array">array()<doc><see type="function">findBlocks()</see><description/><shortdescription>Array of all blocks and their content.</shortdescription></doc></variable><variable name="$blockdata" access="private" type="array">array()<doc><description/><shortdescription>Array with the parsed content of a block.</shortdescription></doc></variable><variable name="$blockvariables" access="private" type="array">array()<doc><description/><shortdescription>Array of variables in a block.</shortdescription></doc></variable><variable name="$blockinner" access="private" type="array">array()<doc><description/><shortdescription>Array of inner blocks of a block.</shortdescription></doc></variable><variable name="$touchedBlocks" access="private" type="array">array()<doc><see type="function">touchBlock()</see><see type="var">$removeEmptyBlocks</see><description>This is something special. Sometimes you have blocks thatshould be preserved although they are empty (no placeholder replaced).Think of a shopping basket. If it&amp;apos;s empty you have to drop a message tothe user. If it&amp;apos;s filled you have to show the contents of the shopping baseket.Now where do you place the message that the basket is empty? It&amp;apos;s no goodidea to place it in you applications as customers tend to like unecessary minortext changes. Having another template file for an empty basket means that it&amp;apos;svery likely that one fine day the filled and empty basket templates have differentlayout. I decided to introduce blocks that to not contain any placeholder but onlytext such as the message &amp;quot;Your shopping basked is empty&amp;quot;.Now if there is no replacement done in such a block the block will be recognizedas &amp;quot;empty&amp;quot; and by default ($removeEmptyBlocks = true) be stripped off. To avoid thisyou can now call touchBlock() to avoid this.The array $touchedBlocks stores a list of touched block which must not be removed evenif they are empty.</description><shortdescription>List of blocks to preverse even if they are &amp;quot;empty&amp;quot;.</shortdescription></doc></variable><variable name="$variableCache" access="private" type="array">array()<doc><see type="function">setVariable()</see><see type="var">$clearCacheOnParse</see><description>Variables get cached before any replacement is done.Advantage: empty blocks can be removed automatically.Disadvantage: might take some more memory</description><shortdescription>Variable cache.</shortdescription></doc></variable><variable name="$clearCacheOnParse" access="private" type="boolean">false<doc><description>If you&amp;apos;re not an expert just leave the default false.True reduces memory consumption somewhat if you tend toadd lots of values for unknown placeholder.</description><shortdescription>Clear the variable cache on parse?</shortdescription></doc></variable><variable name="$fileRoot" access="private" type="string">&amp;quot;&amp;quot;<doc><see type="function">IntegratedTemplate()</see><see type="function">setRoot()</see><description>The string gets prefixed to all filenames given.</description><shortdescription>Root directory for all file operations.</shortdescription></doc></variable><variable name="$flagBlocktrouble" access="private" type="boolean">false<doc><description/><shortdescription>Internal flag indicating that a blockname was used multiple times.</shortdescription></doc></variable><variable name="$flagGlobalParsed" access="private" type="boolean">false<doc><description/><shortdescription>Flag indicating that the global block was parsed.</shortdescription></doc></variable><variable name="$flagCacheTemplatefile" access="private" type="boolean">true<doc><description>Flag indication that a template gets cached.Complex templates require some times to be preparsedbefore the replacement can take place. Often I useone template file over and over again but I don&amp;apos;t knowbefore that I will use the same template file again.Now IT could notice this and skip the preparse.</description><shortdescription>EXPERIMENTAL! FIXME!</shortdescription></doc></variable><variable name="$lastTemplatefile" access="private" type="string">&amp;quot;&amp;quot;<doc><description/><shortdescription>EXPERIMENTAL! FIXME!</shortdescription></doc></variable><subclasses><subclass>IntegratedTemplateExtension</subclass></subclasses></class></phpdoc>
