libs/sysplugins/smarty_internal_compilebase.php Quellcode

smarty_internal_compilebase.php
gehe zur Dokumentation dieser Datei
1 <?php
17 {
23  public $required_attributes = array();
30  public $optional_attributes = array();
36  public $shorttag_order = array();
42  public $option_flags = array('nocache');
43 
56  public function getAttributes($compiler, $attributes)
57  {
58  $_indexed_attr = array();
59  // loop over attributes
60  foreach ($attributes as $key => $mixed) {
61  // shorthand ?
62  if (!is_array($mixed)) {
63  // option flag ?
64  if (in_array(trim($mixed, '\'"'), $this->option_flags)) {
65  $_indexed_attr[trim($mixed, '\'"')] = true;
66  // shorthand attribute ?
67  } elseif (isset($this->shorttag_order[$key])) {
68  $_indexed_attr[$this->shorttag_order[$key]] = $mixed;
69  } else {
70  // too many shorthands
71  $compiler->trigger_template_error('too many shorthand attributes', $compiler->lex->taglineno);
72  }
73  // named attribute
74  } else {
75  $kv = each($mixed);
76  // option flag?
77  if (in_array($kv['key'], $this->option_flags)) {
78  if (is_bool($kv['value'])) {
79  $_indexed_attr[$kv['key']] = $kv['value'];
80  } elseif (is_string($kv['value']) && in_array(trim($kv['value'], '\'"'), array('true', 'false'))) {
81  if (trim($kv['value']) == 'true') {
82  $_indexed_attr[$kv['key']] = true;
83  } else {
84  $_indexed_attr[$kv['key']] = false;
85  }
86  } elseif (is_numeric($kv['value']) && in_array($kv['value'], array(0, 1))) {
87  if ($kv['value'] == 1) {
88  $_indexed_attr[$kv['key']] = true;
89  } else {
90  $_indexed_attr[$kv['key']] = false;
91  }
92  } else {
93  $compiler->trigger_template_error("illegal value of option flag \"{$kv['key']}\"", $compiler->lex->taglineno);
94  }
95  // must be named attribute
96  } else {
97  reset($mixed);
98  $_indexed_attr[key($mixed)] = $mixed[key($mixed)];
99  }
100  }
101  }
102  // check if all required attributes present
103  foreach ($this->required_attributes as $attr) {
104  if (!array_key_exists($attr, $_indexed_attr)) {
105  $compiler->trigger_template_error("missing \"" . $attr . "\" attribute", $compiler->lex->taglineno);
106  }
107  }
108  // check for not allowed attributes
109  if ($this->optional_attributes != array('_any')) {
110  $tmp_array = array_merge($this->required_attributes, $this->optional_attributes, $this->option_flags);
111  foreach ($_indexed_attr as $key => $dummy) {
112  if (!in_array($key, $tmp_array) && $key !== 0) {
113  $compiler->trigger_template_error("unexpected \"" . $key . "\" attribute", $compiler->lex->taglineno);
114  }
115  }
116  }
117  // default 'false' for all option flags not set
118  foreach ($this->option_flags as $flag) {
119  if (!isset($_indexed_attr[$flag])) {
120  $_indexed_attr[$flag] = false;
121  }
122  }
123 
124  return $_indexed_attr;
125  }
126 
135  public function openTag($compiler, $openTag, $data = null)
136  {
137  array_push($compiler->_tag_stack, array($openTag, $data));
138  }
139 
149  public function closeTag($compiler, $expectedTag)
150  {
151  if (count($compiler->_tag_stack) > 0) {
152  // get stacked info
153  list($_openTag, $_data) = array_pop($compiler->_tag_stack);
154  // open tag must match with the expected ones
155  if (in_array($_openTag, (array) $expectedTag)) {
156  if (is_null($_data)) {
157  // return opening tag
158  return $_openTag;
159  } else {
160  // return restored data
161  return $_data;
162  }
163  }
164  // wrong nesting of tags
165  $compiler->trigger_template_error("unclosed {$compiler->smarty->left_delimiter}" . $_openTag . "{$compiler->smarty->right_delimiter} tag");
166 
167  return;
168  }
169  // wrong nesting of tags
170  $compiler->trigger_template_error("unexpected closing tag", $compiler->lex->taglineno);
171 
172  return;
173  }
174 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.