From 0b32dd4c0bd53092fed21a0262dce0ebbd2afb9f Mon Sep 17 00:00:00 2001 From: rvelices Date: Fri, 22 Aug 2008 00:45:03 +0000 Subject: - 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 --- include/template.class.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'include/template.class.php') 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); -- cgit v1.2.3