RE: [SMARTY] Making smarty tags xhtml compliant: prefilter

From: Date: Mon, 14 Oct 2002 11:40:06 +0000
Subject: RE: [SMARTY] Making smarty tags xhtml compliant: prefilter
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6130@lists.php.net to get a copy of this message
Hello, My attachment did not come through. I have included the source below: <?php /** * Smarty plugin * ----------------------------------------- * File: prefilter.tags2smarty.php * Type: prefilter function * Name: tags2smarty * Version: 1.0 * Purpose: Convert (almost) xhtml tags to smarty tags. * Date: October 14, 2002 * * Example: * * <!@tagPrefix="smarty"> * <!@tagPrefixAdd="table"> * <!@tagPrefixAdd="form"> * <!@tagPrefixAdd="html"> * <html> * <head> * <title>{$title}</title> * <smarty:literal> <!-- will be converted to {literal} --> * <style> * .col1 {background: blue;} * .col2 {background: green;} * .col3 {background: yellow; } * </style> * </smarty:literal> <!-- will be converted to {/literal} --> * * </head> * <body> * <form action="none"> * <html:select_date display_days="yes" /> <!-- will be converted to {html_select_date } --> * <select name="gender" multiple="multiple" size="2"> * <form:options options=$gender_options selected=$testgender /> * </select> * <form:radio name="radio" options=$gender_options selected=$testgender /> * </form> * * </form> * * <table:table border=1> * <table:row class="test" valign="top" height="50" max_rows=$data.max_rows total_rows=$data.total_rows array=$personList > * <table:column type="numbering" class="col1" placecontent="before" >No. </table:column> * <table:column name="firstname" class="col2" header="First Name" sort="true"> </table:column> * <table:column name="lastname" class="col3" header="Last Name" sort="true"> </table:column> * </table:row> * </table:table> * * </body> * </html> * * Install: Just drop into the plugin directory. Call something like: * $smarty->autoload_filters = array("pre" => array("tags2smarty")); * * ----------------------------------------- */ function smarty_prefilter_tags2smarty($source, &$smarty) { // ---------------------------------------- // process all the tagPrefixAdd definitions // ---------------------------------------- $lines = split("\n", $source); $addprefixes = ""; $pattern = "/<\!\@tagPrefixAdd\s*=\s*\"([^\"]*)\"\s*>/"; // find the tagPrefixAdd definitions foreach ($lines as $line) { if (preg_match($pattern, $line, $matches)) $addprefixes[] = $matches[1]; } // replace all the different types of tags if (is_array($addprefixes)) { foreach ($addprefixes as $prefix) { $source = preg_replace("/<" . $prefix . ":([^>]*)\/>/", "{" . $prefix . "_\$1}", $source); $source = preg_replace("/<" . $prefix . ":([^>]*)>/", "{" . $prefix . "_\$1}", $source); $source = preg_replace("/<\/" . $prefix . ":([^>]*)\/?>/", "{/" . $prefix . "_$1}", $source); } } // remove prefix definitions $source = preg_replace($pattern, "" , $source); // ------------------------------------- // process all the tagPrefix definitions // ------------------------------------- $prefixes = ""; $pattern = "/<\!\@tagPrefix\s*=\s*\"([^\"]*)\"\s*>/"; reset($lines); // find the tagPrefix definitions foreach ($lines as $line) { if (preg_match($pattern, $line, $matches)) $prefixes[] = $matches[1]; } // replace all the different types of tags if (is_array($prefixes)) { foreach ($prefixes as $prefix) { $source = preg_replace("/<" . $prefix . ":([^>]*)\/>/", "{\$1}", $source); $source = preg_replace("/<" . $prefix . ":([^>]*)>/", "{\$1}", $source); $source = preg_replace("/<\/" . $prefix . ":([^>]*)\/?>/", "{/$1}", $source); } } // remove prefix definitions $source = preg_replace($pattern, "" , $source); return $source; } ?> -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ .

« previous php.smarty.general (#6130) next »