Block functions changes.

This commit is contained in:
andrey
2002-03-26 21:01:52 +00:00
parent 20ace8a768
commit 9aaa64f388
7 changed files with 63 additions and 23 deletions

View File

@@ -3,8 +3,8 @@ Monte Ohrt <monte@ispi.net>:
concept" implementation, and maintains documentation & code base. concept" implementation, and maintains documentation & code base.
Andrei Zmievski <andrei@php.net>: Andrei Zmievski <andrei@php.net>:
Rewrote parser from scratch, developed plugin architecture, and maintains Rewrote parser from scratch, developed plugin architecture, reorganized
code base. documentation, and maintains code base.
Anne Holz <anne@ispi.net>: Anne Holz <anne@ispi.net>:
Provided creative input with respect to web design. Provided creative input with respect to web design.

1
NEWS
View File

@@ -1,3 +1,4 @@
- implemented support for block functions. (Andrei)
- made it possible to assign variables in pre/postfilter - made it possible to assign variables in pre/postfilter
plugins. (Andrei) plugins. (Andrei)

View File

@@ -150,6 +150,7 @@ class Smarty
var $_smarty_vars = null; // stores run-time $smarty.* vars var $_smarty_vars = null; // stores run-time $smarty.* vars
var $_sections = array(); // keeps track of sections var $_sections = array(); // keeps track of sections
var $_foreach = array(); // keeps track of foreach blocks var $_foreach = array(); // keeps track of foreach blocks
var $_tag_stack = array(); // keeps track of tag hierarchy
var $_conf_obj = null; // configuration object var $_conf_obj = null; // configuration object
var $_config = array(); // loaded configuration settings var $_config = array(); // loaded configuration settings
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
@@ -275,6 +276,25 @@ class Smarty
unset($this->_plugins['function'][$function]); unset($this->_plugins['function'][$function]);
} }
/*======================================================================*\
Function: register_block
Purpose: Registers block function to be used in templates
\*======================================================================*/
function register_block($block, $block_impl)
{
$this->_plugins['block'][$block] =
array($block_impl, null, null, false);
}
/*======================================================================*\
Function: unregister_block
Purpose: Unregisters block function
\*======================================================================*/
function unregister_block($block)
{
unset($this->_plugins['block'][$block]);
}
/*======================================================================*\ /*======================================================================*\
Function: register_compiler_function Function: register_compiler_function
Purpose: Registers compiler function Purpose: Registers compiler function

View File

@@ -470,6 +470,7 @@ class Smarty_Compiler extends Smarty {
*/ */
$this->_add_plugin('block', $tag_command); $this->_add_plugin('block', $tag_command);
if ($start_tag) {
$arg_list = array(); $arg_list = array();
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
@@ -478,10 +479,9 @@ class Smarty_Compiler extends Smarty {
$arg_list[] = "'$arg_name' => $arg_value"; $arg_list[] = "'$arg_name' => $arg_value";
} }
if ($start_tag) { $output = "<?php \$this->_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).")); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
$output = "<?php \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
} else { } else {
$output = "<?php \$this->_block = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this->_block, \$this); ?>"; $output = "<?php \$this->_block_content = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$this->_block_content, \$this); array_pop(\$this->_tag_stack); ?>";
} }
return true; return true;

1
TODO
View File

@@ -4,7 +4,6 @@
* support implementations of prefiltes, mods, and others as class methods. * support implementations of prefiltes, mods, and others as class methods.
* possibly implement default modifiers that apply to variables upon display * possibly implement default modifiers that apply to variables upon display
* think about possibility of supporting something like {$data[foo].$key[bar]} * think about possibility of supporting something like {$data[foo].$key[bar]}
* allow {custom} .. {/custom} style of custom functions
* ability to concatenate values/strings together * ability to concatenate values/strings together
* fix all E_NOTICE warnings * fix all E_NOTICE warnings
* make simple math easier * make simple math easier

View File

@@ -150,6 +150,7 @@ class Smarty
var $_smarty_vars = null; // stores run-time $smarty.* vars var $_smarty_vars = null; // stores run-time $smarty.* vars
var $_sections = array(); // keeps track of sections var $_sections = array(); // keeps track of sections
var $_foreach = array(); // keeps track of foreach blocks var $_foreach = array(); // keeps track of foreach blocks
var $_tag_stack = array(); // keeps track of tag hierarchy
var $_conf_obj = null; // configuration object var $_conf_obj = null; // configuration object
var $_config = array(); // loaded configuration settings var $_config = array(); // loaded configuration settings
var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty' var $_smarty_md5 = 'f8d698aea36fcbead2b9d5359ffca76f'; // md5 checksum of the string 'Smarty'
@@ -275,6 +276,25 @@ class Smarty
unset($this->_plugins['function'][$function]); unset($this->_plugins['function'][$function]);
} }
/*======================================================================*\
Function: register_block
Purpose: Registers block function to be used in templates
\*======================================================================*/
function register_block($block, $block_impl)
{
$this->_plugins['block'][$block] =
array($block_impl, null, null, false);
}
/*======================================================================*\
Function: unregister_block
Purpose: Unregisters block function
\*======================================================================*/
function unregister_block($block)
{
unset($this->_plugins['block'][$block]);
}
/*======================================================================*\ /*======================================================================*\
Function: register_compiler_function Function: register_compiler_function
Purpose: Registers compiler function Purpose: Registers compiler function

View File

@@ -470,6 +470,7 @@ class Smarty_Compiler extends Smarty {
*/ */
$this->_add_plugin('block', $tag_command); $this->_add_plugin('block', $tag_command);
if ($start_tag) {
$arg_list = array(); $arg_list = array();
$attrs = $this->_parse_attrs($tag_args); $attrs = $this->_parse_attrs($tag_args);
foreach ($attrs as $arg_name => $arg_value) { foreach ($attrs as $arg_name => $arg_value) {
@@ -478,10 +479,9 @@ class Smarty_Compiler extends Smarty {
$arg_list[] = "'$arg_name' => $arg_value"; $arg_list[] = "'$arg_name' => $arg_value";
} }
if ($start_tag) { $output = "<?php \$this->_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).")); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
$output = "<?php \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), null, \$this); ob_start(); ?>";
} else { } else {
$output = "<?php \$this->_block = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](array(".implode(',', (array)$arg_list)."), \$this->_block, \$this); ?>"; $output = "<?php \$this->_block_content = ob_get_contents(); ob_end_clean(); \$this->_plugins['block']['$tag_command'][0](\$this->_tag_stack[count(\$this->_tag_stack)-1][1], \$this->_block_content, \$this); array_pop(\$this->_tag_stack); ?>";
} }
return true; return true;