| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: |
|
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | abstract class Smarty_Internal_CompileBase
|
| 17: | {
|
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: |
|
| 23: | public $required_attributes = array();
|
| 24: |
|
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: |
|
| 31: | public $optional_attributes = array();
|
| 32: |
|
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: |
|
| 38: | public $shorttag_order = array();
|
| 39: |
|
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: |
|
| 45: | public $option_flags = array('nocache');
|
| 46: |
|
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: |
|
| 52: | public $optionMap = array(1 => true, 0 => false, 'true' => true, 'false' => false);
|
| 53: |
|
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: |
|
| 59: | public $mapCache = array();
|
| 60: |
|
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: |
|
| 73: | public function getAttributes($compiler, $attributes)
|
| 74: | {
|
| 75: | $_indexed_attr = array();
|
| 76: | if (!isset($this->mapCache[ 'option' ])) {
|
| 77: | $this->mapCache[ 'option' ] = array_fill_keys($this->option_flags, true);
|
| 78: | }
|
| 79: | foreach ($attributes as $key => $mixed) {
|
| 80: |
|
| 81: | if (!is_array($mixed)) {
|
| 82: |
|
| 83: | if (isset($this->mapCache[ 'option' ][ trim($mixed, '\'"') ])) {
|
| 84: | $_indexed_attr[ trim($mixed, '\'"') ] = true;
|
| 85: |
|
| 86: | } elseif (isset($this->shorttag_order[ $key ])) {
|
| 87: | $_indexed_attr[ $this->shorttag_order[ $key ] ] = $mixed;
|
| 88: | } else {
|
| 89: |
|
| 90: | $compiler->trigger_template_error('too many shorthand attributes', null, true);
|
| 91: | }
|
| 92: |
|
| 93: | } else {
|
| 94: | foreach ($mixed as $k => $v) {
|
| 95: |
|
| 96: | if (isset($this->mapCache[ 'option' ][ $k ])) {
|
| 97: | if (is_bool($v)) {
|
| 98: | $_indexed_attr[ $k ] = $v;
|
| 99: | } else {
|
| 100: | if (is_string($v)) {
|
| 101: | $v = trim($v, '\'" ');
|
| 102: | }
|
| 103: | if (isset($this->optionMap[ $v ])) {
|
| 104: | $_indexed_attr[ $k ] = $this->optionMap[ $v ];
|
| 105: | } else {
|
| 106: | $compiler->trigger_template_error(
|
| 107: | "illegal value '" . var_export($v, true) .
|
| 108: | "' for option flag '{$k}'",
|
| 109: | null,
|
| 110: | true
|
| 111: | );
|
| 112: | }
|
| 113: | }
|
| 114: |
|
| 115: | } else {
|
| 116: | $_indexed_attr[ $k ] = $v;
|
| 117: | }
|
| 118: | }
|
| 119: | }
|
| 120: | }
|
| 121: |
|
| 122: | foreach ($this->required_attributes as $attr) {
|
| 123: | if (!isset($_indexed_attr[ $attr ])) {
|
| 124: | $compiler->trigger_template_error("missing '{$attr}' attribute", null, true);
|
| 125: | }
|
| 126: | }
|
| 127: |
|
| 128: | if ($this->optional_attributes !== array('_any')) {
|
| 129: | if (!isset($this->mapCache[ 'all' ])) {
|
| 130: | $this->mapCache[ 'all' ] =
|
| 131: | array_fill_keys(
|
| 132: | array_merge(
|
| 133: | $this->required_attributes,
|
| 134: | $this->optional_attributes,
|
| 135: | $this->option_flags
|
| 136: | ),
|
| 137: | true
|
| 138: | );
|
| 139: | }
|
| 140: | foreach ($_indexed_attr as $key => $dummy) {
|
| 141: | if (!isset($this->mapCache[ 'all' ][ $key ]) && $key !== 0) {
|
| 142: | $compiler->trigger_template_error("unexpected '{$key}' attribute", null, true);
|
| 143: | }
|
| 144: | }
|
| 145: | }
|
| 146: |
|
| 147: | foreach ($this->option_flags as $flag) {
|
| 148: | if (!isset($_indexed_attr[ $flag ])) {
|
| 149: | $_indexed_attr[ $flag ] = false;
|
| 150: | }
|
| 151: | }
|
| 152: | if (isset($_indexed_attr[ 'nocache' ]) && $_indexed_attr[ 'nocache' ]) {
|
| 153: | $compiler->tag_nocache = true;
|
| 154: | }
|
| 155: | return $_indexed_attr;
|
| 156: | }
|
| 157: |
|
| 158: | |
| 159: | |
| 160: | |
| 161: | |
| 162: | |
| 163: | |
| 164: | |
| 165: |
|
| 166: | public function openTag($compiler, $openTag, $data = null)
|
| 167: | {
|
| 168: | array_push($compiler->_tag_stack, array($openTag, $data));
|
| 169: | }
|
| 170: |
|
| 171: | |
| 172: | |
| 173: | |
| 174: | |
| 175: | |
| 176: | |
| 177: | |
| 178: | |
| 179: |
|
| 180: | public function closeTag($compiler, $expectedTag)
|
| 181: | {
|
| 182: | if (count($compiler->_tag_stack) > 0) {
|
| 183: |
|
| 184: | list($_openTag, $_data) = array_pop($compiler->_tag_stack);
|
| 185: |
|
| 186: | if (in_array($_openTag, (array)$expectedTag)) {
|
| 187: | if (is_null($_data)) {
|
| 188: |
|
| 189: | return $_openTag;
|
| 190: | } else {
|
| 191: |
|
| 192: | return $_data;
|
| 193: | }
|
| 194: | }
|
| 195: |
|
| 196: | $compiler->trigger_template_error("unclosed '{$compiler->smarty->left_delimiter}{$_openTag}{$compiler->smarty->right_delimiter}' tag");
|
| 197: | return;
|
| 198: | }
|
| 199: |
|
| 200: | $compiler->trigger_template_error('unexpected closing tag', null, true);
|
| 201: | return;
|
| 202: | }
|
| 203: | }
|
| 204: | |