| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: |
|
| 10: | class Smarty_Internal_Runtime_UpdateScope
|
| 11: | {
|
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | public function _updateScope(Smarty_Internal_Template $tpl, $varName, $tagScope = 0)
|
| 20: | {
|
| 21: | if ($tagScope) {
|
| 22: | $this->_updateVarStack($tpl, $varName);
|
| 23: | $tagScope = $tagScope & ~Smarty::SCOPE_LOCAL;
|
| 24: | if (!$tpl->scope && !$tagScope) {
|
| 25: | return;
|
| 26: | }
|
| 27: | }
|
| 28: | $mergedScope = $tagScope | $tpl->scope;
|
| 29: | if ($mergedScope) {
|
| 30: | if ($mergedScope & Smarty::SCOPE_GLOBAL && $varName) {
|
| 31: | Smarty::$global_tpl_vars[ $varName ] = $tpl->tpl_vars[ $varName ];
|
| 32: | }
|
| 33: |
|
| 34: | foreach ($this->_getAffectedScopes($tpl, $mergedScope) as $ptr) {
|
| 35: | $this->_updateVariableInOtherScope($ptr->tpl_vars, $tpl, $varName);
|
| 36: | if ($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) {
|
| 37: | $this->_updateVarStack($ptr, $varName);
|
| 38: | }
|
| 39: | }
|
| 40: | }
|
| 41: | }
|
| 42: |
|
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: |
|
| 51: | public function _getAffectedScopes(Smarty_Internal_Template $tpl, $mergedScope)
|
| 52: | {
|
| 53: | $_stack = array();
|
| 54: | $ptr = $tpl->parent;
|
| 55: | if ($mergedScope && isset($ptr) && $ptr->_isTplObj()) {
|
| 56: | $_stack[] = $ptr;
|
| 57: | $mergedScope = $mergedScope & ~Smarty::SCOPE_PARENT;
|
| 58: | if (!$mergedScope) {
|
| 59: |
|
| 60: | return $_stack;
|
| 61: | }
|
| 62: | $ptr = $ptr->parent;
|
| 63: | }
|
| 64: | while (isset($ptr) && $ptr->_isTplObj()) {
|
| 65: | $_stack[] = $ptr;
|
| 66: | $ptr = $ptr->parent;
|
| 67: | }
|
| 68: | if ($mergedScope & Smarty::SCOPE_SMARTY) {
|
| 69: | if (isset($tpl->smarty)) {
|
| 70: | $_stack[] = $tpl->smarty;
|
| 71: | }
|
| 72: | } elseif ($mergedScope & Smarty::SCOPE_ROOT) {
|
| 73: | while (isset($ptr)) {
|
| 74: | if (!$ptr->_isTplObj()) {
|
| 75: | $_stack[] = $ptr;
|
| 76: | break;
|
| 77: | }
|
| 78: | $ptr = $ptr->parent;
|
| 79: | }
|
| 80: | }
|
| 81: | return $_stack;
|
| 82: | }
|
| 83: |
|
| 84: | |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | |
| 90: |
|
| 91: | public function _updateVariableInOtherScope(&$tpl_vars, Smarty_Internal_Template $from, $varName)
|
| 92: | {
|
| 93: | if (!isset($tpl_vars[ $varName ])) {
|
| 94: | $tpl_vars[ $varName ] = clone $from->tpl_vars[ $varName ];
|
| 95: | } else {
|
| 96: | $tpl_vars[ $varName ] = clone $tpl_vars[ $varName ];
|
| 97: | $tpl_vars[ $varName ]->value = $from->tpl_vars[ $varName ]->value;
|
| 98: | }
|
| 99: | }
|
| 100: |
|
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: |
|
| 107: | public function _updateVarStack(Smarty_Internal_Template $tpl, $varName)
|
| 108: | {
|
| 109: | $i = 0;
|
| 110: | while (isset($tpl->_cache[ 'varStack' ][ $i ])) {
|
| 111: | $this->_updateVariableInOtherScope($tpl->_cache[ 'varStack' ][ $i ][ 'tpl' ], $tpl, $varName);
|
| 112: | $i++;
|
| 113: | }
|
| 114: | }
|
| 115: | }
|
| 116: | |