diff options
author | rvelices <rv-github@modusoptimus.com> | 2008-08-22 00:45:03 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2008-08-22 00:45:03 +0000 |
commit | 0b32dd4c0bd53092fed21a0262dce0ebbd2afb9f (patch) | |
tree | 9a5cf9016316c94505d80475d39a25fe3d6e25ad /include | |
parent | 685f4e2998ba782b03bd0488131a6e1665de0955 (diff) |
- further reduce css rules and remove unused ones
- added a smarty prefilter so that html output is nicely indented now ...
git-svn-id: http://piwigo.org/svn/trunk@2481 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r-- | include/template.class.php | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/include/template.class.php b/include/template.class.php index b51624929..9fd5bd4f5 100644 --- a/include/template.class.php +++ b/include/template.class.php @@ -79,9 +79,10 @@ class Template { $this->smarty->register_modifier( 'translate', array('Template', 'mod_translate') ); $this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') ); $this->smarty->register_block('html_head', array(&$this, 'block_html_head') ); + $this->smarty->register_prefilter( array('Template', 'prefilter_white_space') ); if ( $conf['compiled_template_cache_language'] ) { - $this->smarty->register_prefilter( array(&$this, 'prefilter_language') ); + $this->smarty->register_prefilter( array('Template', 'prefilter_language') ); } if ( !empty($theme) ) @@ -355,15 +356,38 @@ class Template { } } + /*static */ function prefilter_white_space($source, &$smarty) + { + $ld = $smarty->left_delimiter; + $rd = $smarty->right_delimiter; + $ldq = preg_quote($ld, '#'); + $rdq = preg_quote($rd, '#'); + + $regex = array(); + $tags = array('if', 'foreach', 'section'); + foreach($tags as $tag) + { + array_push($regex, "#^\s+($ldq$tag"."[^$ld$rd]*$rdq)\s*$#m"); + array_push($regex, "#^\s+($ldq/$tag$rdq)\s*$#m"); + } + $tags = array('include', 'else', 'html_head'); + foreach($tags as $tag) + { + array_push($regex, "#^\s+($ldq$tag"."[^$ld$rd]*$rdq)\s*$#m"); + } + $source = preg_replace( $regex, "$1", $source); + return $source; + } + /** * Smarty prefilter to allow caching (whenever possible) language strings * from templates. */ - function prefilter_language($source, &$smarty) + /*static */ function prefilter_language($source, &$smarty) { global $lang; - $ldq = preg_quote($this->smarty->left_delimiter, '~'); - $rdq = preg_quote($this->smarty->right_delimiter, '~'); + $ldq = preg_quote($smarty->left_delimiter, '~'); + $rdq = preg_quote($smarty->right_delimiter, '~'); $regex = "~$ldq *\'([^'$]+)\'\|@translate *$rdq~"; $source = preg_replace( $regex.'e', 'isset($lang[\'$1\']) ? $lang[\'$1\'] : \'$0\'', $source); |