From 7a40f4354b32809af3d0cfd6e3af0eda02ab0e0a Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 12 May 2012 17:57:41 -0700 Subject: some important stuff we'll need --- .../sysplugins/smarty_internal_compilebase.php | 176 +++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 lib/smarty/libs/sysplugins/smarty_internal_compilebase.php (limited to 'lib/smarty/libs/sysplugins/smarty_internal_compilebase.php') diff --git a/lib/smarty/libs/sysplugins/smarty_internal_compilebase.php b/lib/smarty/libs/sysplugins/smarty_internal_compilebase.php new file mode 100644 index 000000000..5fb56f371 --- /dev/null +++ b/lib/smarty/libs/sysplugins/smarty_internal_compilebase.php @@ -0,0 +1,176 @@ + $mixed) { + // shorthand ? + if (!is_array($mixed)) { + // option flag ? + if (in_array(trim($mixed, '\'"'), $this->option_flags)) { + $_indexed_attr[trim($mixed, '\'"')] = true; + // shorthand attribute ? + } else if (isset($this->shorttag_order[$key])) { + $_indexed_attr[$this->shorttag_order[$key]] = $mixed; + } else { + // too many shorthands + $compiler->trigger_template_error('too many shorthand attributes', $compiler->lex->taglineno); + } + // named attribute + } else { + $kv = each($mixed); + // option flag? + if (in_array($kv['key'], $this->option_flags)) { + if (is_bool($kv['value'])) { + $_indexed_attr[$kv['key']] = $kv['value']; + } else if (is_string($kv['value']) && in_array(trim($kv['value'], '\'"'), array('true', 'false'))) { + if (trim($kv['value']) == 'true') { + $_indexed_attr[$kv['key']] = true; + } else { + $_indexed_attr[$kv['key']] = false; + } + } else if (is_numeric($kv['value']) && in_array($kv['value'], array(0, 1))) { + if ($kv['value'] == 1) { + $_indexed_attr[$kv['key']] = true; + } else { + $_indexed_attr[$kv['key']] = false; + } + } else { + $compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", $compiler->lex->taglineno); + } + // must be named attribute + } else { + reset($mixed); + $_indexed_attr[key($mixed)] = $mixed[key($mixed)]; + } + } + } + // check if all required attributes present + foreach ($this->required_attributes as $attr) { + if (!array_key_exists($attr, $_indexed_attr)) { + $compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $compiler->lex->taglineno); + } + } + // check for unallowed attributes + if ($this->optional_attributes != array('_any')) { + $tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags); + foreach ($_indexed_attr as $key => $dummy) { + if (!in_array($key, $tmp_array) && $key !== 0) { + $compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", $compiler->lex->taglineno); + } + } + } + // default 'false' for all option flags not set + foreach ($this->option_flags as $flag) { + if (!isset($_indexed_attr[$flag])) { + $_indexed_attr[$flag] = false; + } + } + + return $_indexed_attr; + } + + /** + * Push opening tag name on stack + * + * Optionally additional data can be saved on stack + * + * @param object $compiler compiler object + * @param string $openTag the opening tag's name + * @param mixed $data optional data saved + */ + public function openTag($compiler, $openTag, $data = null) + { + array_push($compiler->_tag_stack, array($openTag, $data)); + } + + /** + * Pop closing tag + * + * Raise an error if this stack-top doesn't match with expected opening tags + * + * @param object $compiler compiler object + * @param array|string $expectedTag the expected opening tag names + * @return mixed any type the opening tag's name or saved data + */ + public function closeTag($compiler, $expectedTag) + { + if (count($compiler->_tag_stack) > 0) { + // get stacked info + list($_openTag, $_data) = array_pop($compiler->_tag_stack); + // open tag must match with the expected ones + if (in_array($_openTag, (array) $expectedTag)) { + if (is_null($_data)) { + // return opening tag + return $_openTag; + } else { + // return restored data + return $_data; + } + } + // wrong nesting of tags + $compiler->trigger_template_error("unclosed {" . $_openTag . "} tag"); + return; + } + // wrong nesting of tags + $compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno); + return; + } + +} + +?> \ No newline at end of file -- cgit v1.2.3