diff options
-rw-r--r-- | include/config_default.inc.php | 9 | ||||
-rw-r--r-- | include/template.class.php | 86 | ||||
-rw-r--r-- | template/yoga/admin/plugins_list.tpl | 15 | ||||
-rw-r--r-- | template/yoga/month_calendar.tpl | 14 |
4 files changed, 112 insertions, 12 deletions
diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 7a2fcdea8..5d2e77aa3 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -690,4 +690,11 @@ $conf['light_slideshow'] = true; // the local data directory is used to store data such as compiled templates // or other plugin variables etc $conf['local_data_dir'] = dirname(dirname(__FILE__)).'/_data'; -?> + +// if true, some language strings are replaced during template compilation +// (insted of template output). this results in better performance. however +// any change in the language file will not be propagated until you purge +// the compiled templates from the admin / maintenance menu +$conf['compiled_template_cache_language'] = false; + +?>
\ No newline at end of file diff --git a/include/template.class.php b/include/template.class.php index 9982b76f7..1fd3c94ac 100644 --- a/include/template.class.php +++ b/include/template.class.php @@ -43,13 +43,15 @@ class Template { // Hash of filenames for each template handle. var $files = array(); + // used by html_head smarty block to add content before </head> + var $html_head_elements = array(); + function Template($root = ".", $theme= "") { global $conf; $this->smarty = new Smarty; $this->smarty->debugging = $conf['debug_template']; - //$this->smarty->force_compile = true; if ( isset($conf['compiled_template_dir'] ) ) { @@ -76,6 +78,11 @@ class Template { $this->smarty->assign_by_ref( 'pwg', new PwgTemplateAdapter() ); $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') ); + if ( $conf['compiled_template_cache_language'] ) + { + $this->smarty->register_prefilter( array(&$this, 'prefilter_language') ); + } if ( !empty($theme) ) { @@ -95,7 +102,7 @@ class Template { $real_dir = realpath($dir); $compile_id = crc32( $real_dir===false ? $dir : $real_dir); - $this->smarty->compile_id = sprintf('%08X', $compile_id ); + $this->smarty->compile_id = base_convert($compile_id, 10, 36 ); } /** @@ -223,7 +230,21 @@ class Template { $this->smarty->assign( 'ROOT_URL', get_root_url() ); $this->smarty->assign( 'TAG_INPUT_ENABLED', ((is_adviser()) ? 'disabled="disabled" onclick="return false;"' : '')); + + global $conf, $lang_info; + if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) ) + { + $save_compile_id = $this->smarty->compile_id; + $this->smarty->compile_id .= '.'.$lang_info['code']; + } + $v = $this->smarty->fetch($this->files[$handle], null, null, false); + + if (isset ($save_compile_id) ) + { + $this->smarty->compile_id = $save_compile_id; + } + if ($return) { return $v; @@ -238,19 +259,31 @@ class Template { function pparse($handle) { $this->parse($handle, false); + $this->flush(); + } + + function flush() + { + if ( count($this->html_head_elements) ) + { + $search = "\n</head>"; + $pos = strpos( $this->output, $search ); + if ($pos !== false) + { + $this->output = substr_replace( $this->output, "\n".implode( "\n", $this->html_head_elements ), $pos, 0 ); + } //else maybe error or warning ? + $this->html_head_elements = array(); + } echo $this->output; $this->output=''; - } - /** flushes the output */ function p() { $start = get_moment(); - echo $this->output; - $this->output=''; + $this->flush(); if ($this->smarty->debugging) { @@ -283,6 +316,47 @@ class Template { { return explode($delimiter, $text); } + + /** + * This smarty "html_head" block allows to add content just before + * </head> element in the output after the head has been parsed. This is + * handy in order to respect strict standards when <style> and <link> + * html elements must appear in the <head> element + */ + function block_html_head($params, $content, &$smarty, &$repeat) + { + $content = trim($content); + if ( !empty($content) ) + { // second call + if ( empty($this->output) ) + {//page header not parsed yet + $this->append('head_elements', $content); + } + else + { + $this->html_head_elements[] = $content; + } + } + } + + /** + * Smarty prefilter to allow caching (whenever possible) language strings + * from templates. + */ + function prefilter_language($source, &$smarty) + { + global $lang; + $ldq = preg_quote($this->smarty->left_delimiter, '~'); + $rdq = preg_quote($this->smarty->right_delimiter, '~'); + + $regex = "~$ldq *\'([^'$]+)\'\|@translate *$rdq~"; + $source = preg_replace( $regex.'e', 'isset($lang[\'$1\']) ? $lang[\'$1\'] : \'$0\'', $source); + + $regex = "~$ldq *\'([^'$]+)\'\|@translate\|~"; + $source = preg_replace( $regex.'e', 'isset($lang[\'$1\']) ? \'{\'.var_export($lang[\'$1\'],true).\'|\' : \'$0\'', $source); + + return $source; + } } /** diff --git a/template/yoga/admin/plugins_list.tpl b/template/yoga/admin/plugins_list.tpl index 8276cd359..abba01861 100644 --- a/template/yoga/admin/plugins_list.tpl +++ b/template/yoga/admin/plugins_list.tpl @@ -18,9 +18,22 @@ <td>{'Actions'|@translate}</td> </tr> </thead> +{html_head} {*add the style to html head for strict standard compliance*} +<style type="text/css"> +TABLE.table2 TR TD.pluginState {ldelim} + padding-left:16px; +} +TABLE.table2 TR TD.active {ldelim} + background: url({$ROOT_URL}{$themeconf.admin_icon_dir}/plugin_active.gif) no-repeat center left +} +TABLE.table2 TR TD.inactive {ldelim} + background: url({$ROOT_URL}{$themeconf.admin_icon_dir}/plugin_inactive.gif) no-repeat center left +} +</style> +{/html_head} {foreach from=$plugins item=plugin name=plugins_loop} <tr class="{if $smarty.foreach.plugins_loop.index is odd}row1{else}row2{/if}"> - <td style="padding-left:16px; {if not empty($plugin.STATE)}background: url({$ROOT_URL}{$themeconf.admin_icon_dir}/plugin_{$plugin.STATE}.gif) no-repeat center left{/if}"> + <td class="pluginState{if not empty($plugin.STATE)} {$plugin.STATE}{/if}"> {$plugin.NAME} </td> <td>{$plugin.VERSION}</td> diff --git a/template/yoga/month_calendar.tpl b/template/yoga/month_calendar.tpl index 34f035915..410824b23 100644 --- a/template/yoga/month_calendar.tpl +++ b/template/yoga/month_calendar.tpl @@ -36,7 +36,13 @@ {/foreach} </tr> </thead> - +{html_head} {*add the style to html head for strict standard compliance*} +<style type="text/css"> +TABLE.calMonth TBODY TD, TABLE.calMonth TBODY TD DIV.calImg {ldelim} + width:{$chronology_calendar.month_view.CELL_WIDTH}px;height:{$chronology_calendar.month_view.CELL_HEIGHT}px; +} +</style> +{/html_head} {foreach from=$chronology_calendar.month_view.weeks item=week} <tr> {foreach from=$week item=day} @@ -44,16 +50,16 @@ {if isset($day.IMAGE)} <td class="calDayCellFull"> <div class="calBackDate">{$day.DAY}</div><div class="calForeDate">{$day.DAY}</div> - <div class="calImg" style="width:{$chronology_calendar.month_view.CELL_WIDTH}px;height:{$chronology_calendar.month_view.CELL_HEIGHT}px;"> + <div class="calImg"> <a href="{$day.U_IMG_LINK}"> <img style="{$day.IMAGE_STYLE}" src="{$day.IMAGE}" alt="{$day.IMAGE_ALT}" title="{$pwg->l10n_dec('%d element','%d elements', $day.NB_ELEMENTS)}" /> </a> </div> {else} - <td class="calDayCellEmpty" style="width:{$chronology_calendar.month_view.CELL_WIDTH}px;height:{$chronology_calendar.month_view.CELL_HEIGHT}px;">{$day.DAY} + <td class="calDayCellEmpty">{$day.DAY} {/if} {else} - <td class="calDayCellBlank" style="width:{$chronology_calendar.month_view.CELL_WIDTH}px;height:{$chronology_calendar.month_view.CELL_HEIGHT}px;"> + <td class="calDayCellBlank"> {/if} </td> {/foreach} {*day in week*} |