< * > --> > * " --> " * & not followed by some entity --> & */ function escape_html($string) { if(is_string($string)) { $transtbl = Array('<' => '<', '>' => '>', '"' => '"', '\'' => '''); return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/", "&" , strtr($string, $transtbl)); } else { return $string; } } // }}} // {{{ function at_to_globals() /** * helper */ function _to_globals($s) { global $globals; $t = explode('.',$s); if (count($t) == 1) { return var_export($globals->$t[0],true); } else { return var_export($globals->$t[0]->$t[1],true); } } /** * compilation plugin used to import $globals confing through #globals.foo.bar# directives */ function at_to_globals($tpl_source, &$smarty) { return preg_replace('/#globals\.([a-zA-Z0-9_.]+?)#/e', '_to_globals(\'\\1\')', $tpl_source); } // }}} // {{{ function trimwhitespace function trimwhitespace($source, &$smarty) { // Pull out the script blocks preg_match_all("!]+>.*?!is", $source, $match); $_script_blocks = $match[0]; $source = preg_replace("!]+>.*?!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source); // Pull out the pre blocks preg_match_all("!
.*?
!is", $source, $match); $_pre_blocks = $match[0]; $source = preg_replace("!
.*?
!is", '@@@SMARTY:TRIM:PRE@@@', $source); // Pull out the textarea blocks preg_match_all("!]+>.*?!is", $source, $match); $_textarea_blocks = $match[0]; $source = preg_replace("!]+>.*?!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source); // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. $source = preg_replace('/((?)\n)[\s]+/m', '\1', $source); // replace script blocks foreach($_script_blocks as $curr_block) { $source = preg_replace("!@@@SMARTY:TRIM:SCRIPT@@@!", $curr_block, $source, 1); } // replace pre blocks foreach($_pre_blocks as $curr_block) { $source = preg_replace("!@@@SMARTY:TRIM:PRE@@@!",$curr_block,$source,1); } // replace textarea blocks foreach($_textarea_blocks as $curr_block) { $source = preg_replace("!@@@SMARTY:TRIM:TEXTAREA@@@!",$curr_block,$source,1); } return $source; } // }}} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: ?>