cvs: smarty / NEWS /libs Smarty.class.php Smarty_Compiler.class.php
| From: | Messju Mohr | Date: | Sun, 08 Jun 2003 01:07:39 +0000 |
| Subject: | cvs: smarty / NEWS /libs Smarty.class.php Smarty_Compiler.class.php | ||
| Groups: | php.smarty.cvs | ||
| Request: | Send a blank email to php-smarty-cvs+get-633@lists.php.net to get a copy of this message | ||
messju Sat Jun 7 21:07:39 2003 EDT
Modified files:
/smarty NEWS
/smarty/libs Smarty.class.php Smarty_Compiler.class.php
Log:
added block-methods for registered objects
Index: smarty/NEWS
diff -u smarty/NEWS:1.371 smarty/NEWS:1.372
--- smarty/NEWS:1.371 Fri Jun 6 11:54:28 2003
+++ smarty/NEWS Sat Jun 7 21:07:39 2003
@@ -1,3 +1,4 @@
+ - added block-methods for registered objects (Bharat Mediratta, messju)
- ignore one char resource names like c:foo.tpl (Monte)
- added default_resource_type feature (Monte)
- fix bug where config file starts with hidden section (boots, Monte)
Index: smarty/libs/Smarty.class.php
diff -u smarty/libs/Smarty.class.php:1.399 smarty/libs/Smarty.class.php:1.400
--- smarty/libs/Smarty.class.php:1.399 Fri Jun 6 11:49:29 2003
+++ smarty/libs/Smarty.class.php Sat Jun 7 21:07:39 2003
@@ -42,7 +42,7 @@
* @version 2.5.0
*/
-/* $Id: Smarty.class.php,v 1.399 2003/06/06 15:49:29 mohrt Exp $ */
+/* $Id: Smarty.class.php,v 1.400 2003/06/08 01:07:39 messju Exp $ */
/**
* DIR_SEP isn't used anymore, but third party apps might
@@ -721,13 +721,14 @@
* @param object &$object_impl the referenced PHP object to register
* @param null|array $allowed list of allowed methods (empty = all)
* @param boolean $smarty_args smarty argument format, else traditional
+ * @param null|array $block_functs list of methods that are block format
*/
- function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true)
+ function register_object($object, &$object_impl, $allowed = array(), $smarty_args = true,
$block_methods = array())
{
settype($allowed, 'array');
settype($smarty_args, 'boolean');
$this->_reg_objects[$object] =
- array(&$object_impl, $allowed, $smarty_args);
+ array(&$object_impl, $allowed, $smarty_args, $block_methods);
}
/**
Index: smarty/libs/Smarty_Compiler.class.php
diff -u smarty/libs/Smarty_Compiler.class.php:1.231 smarty/libs/Smarty_Compiler.class.php:1.232
--- smarty/libs/Smarty_Compiler.class.php:1.231 Fri May 23 15:26:57 2003
+++ smarty/libs/Smarty_Compiler.class.php Sat Jun 7 21:07:39 2003
@@ -39,7 +39,7 @@
* @package Smarty
*/
-/* $Id: Smarty_Compiler.class.php,v 1.231 2003/05/23 19:26:57 mohrt Exp $ */
+/* $Id: Smarty_Compiler.class.php,v 1.232 2003/06/08 01:07:39 messju Exp $ */
/**
* Template compiling class
* @package Smarty
@@ -379,7 +379,7 @@
/* Split tag into two three parts: command, command modifiers and the arguments. */
if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' .
$this->_var_regexp
- . '|' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp .
')(' . $this->_mod_regexp . '*))
+ . '|\/?' . $this->_reg_obj_regexp . '|\/?' . $this->_func_regexp .
')(' . $this->_mod_regexp . '*))
(?:\s+(.*))?$
/xs', $template_tag, $match)) {
$this->_syntax_error("unrecognized tag: $template_tag", E_USER_ERROR, __FILE__,
__LINE__);
@@ -401,7 +401,7 @@
}
/* If the tag name is a registered object, we process it. */
- if (preg_match('!^' . $this->_reg_obj_regexp . '$!', $tag_command))
{
+ if (preg_match('!^\/?' . $this->_reg_obj_regexp . '$!',
$tag_command)) {
return $this->_compile_registered_object_tag($tag_command, $this->_parse_attrs($tag_args),
$tag_modifier);
}
@@ -691,6 +691,13 @@
*/
function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier)
{
+ if ($tag_command{0} == '/') {
+ $start_tag = false;
+ $tag_command = substr($tag_command, 1);
+ } else {
+ $start_tag = true;
+ }
+
list($object, $obj_comp) = explode('->', $tag_command);
$arg_list = array();
@@ -708,36 +715,63 @@
}
}
+ if($this->_reg_objects[$object][2]) {
+ // smarty object argument format
+ $args = "array(".implode(',', (array)$arg_list)."),
\$this";
+ } else {
+ // traditional argument format
+ $args = implode(',', array_values($attrs));
+ if (empty($args)) {
+ $args = 'null';
+ }
+ }
+
+ $prefix = '';
+ $postfix = '';
if(!is_object($this->_reg_objects[$object][0])) {
$this->_trigger_fatal_error("registered '$object' is not an object");
} elseif(!empty($this->_reg_objects[$object][1]) && !in_array($obj_comp,
$this->_reg_objects[$object][1])) {
$this->_trigger_fatal_error("'$obj_comp' is not a registered component of
object '$object'");
} elseif(method_exists($this->_reg_objects[$object][0], $obj_comp)) {
// method
- if($this->_reg_objects[$object][2]) {
- // smarty object argument format
- $return =
"\$this->_reg_objects['$object'][0]->$obj_comp(array(".implode(',',
(array)$arg_list)."), \$this)";
+ if(in_array($obj_comp, $this->_reg_objects[$object][3])) {
+ // block method
+ if ($start_tag) {
+ $prefix = "\$this->_tag_stack[] = array('$obj_comp', $args);
";
+ $prefix .=
"\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1],
null, \$this, \$_block_repeat=true); ";
+ $prefix .= "while (\$_block_repeat) { ob_start();";
+ $return = null;
+ $postfix = '';
} else {
- // traditional argument format
- $return =
"\$this->_reg_objects['$object'][0]->$obj_comp(".implode(',',
array_values($attrs)).")";
+ $prefix = "\$this->_obj_block_content = ob_get_contents();
ob_end_clean(); ";
+ $return =
"\$this->_reg_objects['$object'][0]->$obj_comp(\$this->_tag_stack[count(\$this->_tag_stack)-1][1],
\$this->_obj_block_content, \$this, \$_block_repeat=false)";
+ $postfix = "} array_pop(\$this->_tag_stack);";
+ }
+ } else {
+ // non-block method
+ $return =
"\$this->_reg_objects['$object'][0]->$obj_comp($args)";
}
} else {
// property
$return = "\$this->_reg_objects['$object'][0]->$obj_comp";
}
-
- if($tag_modifier != '') {
- $this->_parse_modifiers($return, $tag_modifier);
- }
-
- if($_assign_var) {
- return "<?php \$this->assign('" . $this->_dequote($_assign_var)
."', $return); ?>\n";
- } else {
- return '<?php echo ' . $return . "; ?>\n";
- }
+
+ if($return != null) {
+ if($tag_modifier != '') {
+ $this->_parse_modifiers($return, $tag_modifier);
+ }
+
+ if(!empty($_assign_var)) {
+ $output = "\$this->assign('" . $this->_dequote($_assign_var)
."', $return);";
+ } else {
+ $output = 'echo ' . $return . ';';
+ }
+ } else {
+ $output = '';
+ }
+
+ return '<?php ' . $prefix . $output . $postfix . "?>\n";
}
-
-
/**
* Compile {insert ...} tag