| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: |
|
| 11: |
|
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | class Smarty_Internal_ParseTree_Template extends Smarty_Internal_ParseTree
|
| 20: | {
|
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: |
|
| 26: | public $subtrees = array();
|
| 27: |
|
| 28: | |
| 29: | |
| 30: |
|
| 31: | public function __construct()
|
| 32: | {
|
| 33: | }
|
| 34: |
|
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: |
|
| 41: | public function append_subtree(Smarty_Internal_Templateparser $parser, Smarty_Internal_ParseTree $subtree)
|
| 42: | {
|
| 43: | if (!empty($subtree->subtrees)) {
|
| 44: | $this->subtrees = array_merge($this->subtrees, $subtree->subtrees);
|
| 45: | } else {
|
| 46: | if ($subtree->data !== '') {
|
| 47: | $this->subtrees[] = $subtree;
|
| 48: | }
|
| 49: | }
|
| 50: | }
|
| 51: |
|
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: |
|
| 58: | public function append_array(Smarty_Internal_Templateparser $parser, $array = array())
|
| 59: | {
|
| 60: | if (!empty($array)) {
|
| 61: | $this->subtrees = array_merge($this->subtrees, (array)$array);
|
| 62: | }
|
| 63: | }
|
| 64: |
|
| 65: | |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: |
|
| 71: | public function prepend_array(Smarty_Internal_Templateparser $parser, $array = array())
|
| 72: | {
|
| 73: | if (!empty($array)) {
|
| 74: | $this->subtrees = array_merge((array)$array, $this->subtrees);
|
| 75: | }
|
| 76: | }
|
| 77: |
|
| 78: | |
| 79: | |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: |
|
| 85: | public function to_smarty_php(Smarty_Internal_Templateparser $parser)
|
| 86: | {
|
| 87: | $code = '';
|
| 88: |
|
| 89: | foreach ($this->getChunkedSubtrees() as $chunk) {
|
| 90: | $text = '';
|
| 91: | switch ($chunk['mode']) {
|
| 92: | case 'textstripped':
|
| 93: | foreach ($chunk['subtrees'] as $subtree) {
|
| 94: | $text .= $subtree->to_smarty_php($parser);
|
| 95: | }
|
| 96: | $code .= preg_replace(
|
| 97: | '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
|
| 98: | "<?php echo '\$1'; ?>\n",
|
| 99: | $parser->compiler->processText($text)
|
| 100: | );
|
| 101: | break;
|
| 102: | case 'text':
|
| 103: | foreach ($chunk['subtrees'] as $subtree) {
|
| 104: | $text .= $subtree->to_smarty_php($parser);
|
| 105: | }
|
| 106: | $code .= preg_replace(
|
| 107: | '/((<%)|(%>)|(<\?php)|(<\?)|(\?>)|(<\/?script))/',
|
| 108: | "<?php echo '\$1'; ?>\n",
|
| 109: | $text
|
| 110: | );
|
| 111: | break;
|
| 112: | case 'tag':
|
| 113: | foreach ($chunk['subtrees'] as $subtree) {
|
| 114: | $text = $parser->compiler->appendCode($text, $subtree->to_smarty_php($parser));
|
| 115: | }
|
| 116: | $code .= $text;
|
| 117: | break;
|
| 118: | default:
|
| 119: | foreach ($chunk['subtrees'] as $subtree) {
|
| 120: | $text = $subtree->to_smarty_php($parser);
|
| 121: | }
|
| 122: | $code .= $text;
|
| 123: |
|
| 124: | }
|
| 125: | }
|
| 126: | return $code;
|
| 127: | }
|
| 128: |
|
| 129: | private function getChunkedSubtrees() {
|
| 130: | $chunks = array();
|
| 131: | $currentMode = null;
|
| 132: | $currentChunk = array();
|
| 133: | for ($key = 0, $cnt = count($this->subtrees); $key < $cnt; $key++) {
|
| 134: |
|
| 135: | if ($this->subtrees[ $key ]->data === '' && in_array($currentMode, array('textstripped', 'text', 'tag'))) {
|
| 136: | continue;
|
| 137: | }
|
| 138: |
|
| 139: | if ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text
|
| 140: | && $this->subtrees[ $key ]->isToBeStripped()) {
|
| 141: | $newMode = 'textstripped';
|
| 142: | } elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Text) {
|
| 143: | $newMode = 'text';
|
| 144: | } elseif ($this->subtrees[ $key ] instanceof Smarty_Internal_ParseTree_Tag) {
|
| 145: | $newMode = 'tag';
|
| 146: | } else {
|
| 147: | $newMode = 'other';
|
| 148: | }
|
| 149: |
|
| 150: | if ($newMode == $currentMode) {
|
| 151: | $currentChunk[] = $this->subtrees[ $key ];
|
| 152: | } else {
|
| 153: | $chunks[] = array(
|
| 154: | 'mode' => $currentMode,
|
| 155: | 'subtrees' => $currentChunk
|
| 156: | );
|
| 157: | $currentMode = $newMode;
|
| 158: | $currentChunk = array($this->subtrees[ $key ]);
|
| 159: | }
|
| 160: | }
|
| 161: | if ($currentMode && $currentChunk) {
|
| 162: | $chunks[] = array(
|
| 163: | 'mode' => $currentMode,
|
| 164: | 'subtrees' => $currentChunk
|
| 165: | );
|
| 166: | }
|
| 167: | return $chunks;
|
| 168: | }
|
| 169: | }
|
| 170: | |