Index: branches/5.2.x/core/kernel/managers/request_manager.php =================================================================== diff -u -N -r14663 -r14664 --- branches/5.2.x/core/kernel/managers/request_manager.php (.../request_manager.php) (revision 14663) +++ branches/5.2.x/core/kernel/managers/request_manager.php (.../request_manager.php) (revision 14664) @@ -1,6 +1,6 @@ Application->GetVar('m_wid'); + $opener_stack =& $this->Application->makeClass('kOpenerStack'); + /* @var $opener_stack kOpenerStack */ - $opener_action = $this->Application->GetVar('m_opener'); - $opener_stack = $this->Application->RecallVar(rtrim('opener_stack_'.$wid, '_')); - $opener_stack = $opener_stack ? unserialize($opener_stack) : Array(); - - switch ($opener_action) { + switch ( $this->Application->GetVar('m_opener') ) { case 'r': - // "reset" opener stack - $opener_stack = Array (); + $opener_stack->reset(); break; case 'd': @@ -295,16 +291,16 @@ $front_session =& $this->Application->recallObject('Session.front'); /* @var $front_session Session */ - array_push( $opener_stack, '../' . $front_session->RecallVar('last_template') ); + $opener_stack->pushRaw( '../' . $front_session->RecallVar('last_template') ); } else { - array_push( $opener_stack, $this->Application->RecallVar('last_template') ); + $opener_stack->pushRaw( $this->Application->RecallVar('last_template') ); } break; case 'u': // "up/pop" last template from opener stack, deeplevel-- - array_pop($opener_stack); + $opener_stack->pop(); break; case 'p': @@ -314,40 +310,20 @@ $this->Application->StoreVar('last_wid', $popup_wid); $this->Application->SetVar('m_wid', $popup_wid); - if ( $this->Application->GetVar('front') ) { - $front_session =& $this->Application->recallObject('Session.front'); - /* @var $front_session Session */ + $popup_opener_stack =& $this->Application->makeClass('kOpenerStack', Array ($popup_wid)); + /* @var $popup_opener_stack kOpenerStack */ - $last_template = '../' . $front_session->RecallVar( rtrim('last_template_popup_' . $parent_wid, '_') ); - } - else { - if ( $this->Application->GetVar('merge_opener_stack') ) { - // get last template from parent (that was closed) window opener stack - $parent_opener_stack_name = rtrim('opener_stack_' . $parent_wid, '_'); - $parent_opener_stack = unserialize( $this->Application->RecallVar($parent_opener_stack_name) ); - $last_template = array_pop($parent_opener_stack); + $popup_opener_stack->pushRaw( $this->getLastTemplate($parent_wid) ); + $popup_opener_stack->save(); - if ($parent_opener_stack) { - $this->Application->StoreVar( $parent_opener_stack_name, serialize($parent_opener_stack) ); - } - else { - $this->Application->RemoveVar( $parent_opener_stack_name ); - } - } - else { - $last_template = $this->Application->RecallVar( rtrim('last_template_popup_' . $parent_wid, '_') ); - } - } - - $opener_stack = Array ($last_template); $this->Application->SetVar('m_opener', 's'); - $wid = $popup_wid; /*// store window relations $window_relations = $this->Application->RecallVar('window_relations'); $window_relations = $window_relations ? unserialize($window_relations) : Array (); $window_relations[$popup_wid] = $parent_wid; $this->Application->StoreVar('window_relations', serialize($window_relations));*/ + return; break; default: @@ -356,85 +332,105 @@ } $this->Application->SetVar('m_opener', 's'); - $this->Application->StoreVar(rtrim('opener_stack_' . $wid, '_'), serialize($opener_stack), !$opener_stack); // empty stack is optional + $opener_stack->save(); } /** + * Returns last template from window with given id + * + * @param int $window_id + * @return string + * @access protected + */ + protected function getLastTemplate($window_id) + { + if ( $this->Application->GetVar('front') ) { + $front_session =& $this->Application->recallObject('Session.front'); + /* @var $front_session Session */ + + return '../' . $front_session->RecallVar( rtrim('last_template_popup_' . $window_id, '_') ); + } + + if ( $this->Application->GetVar('merge_opener_stack') ) { + // get last template from parent (that was closed) window opener stack + $parent_opener_stack =& $this->Application->makeClass('kOpenerStack', Array ($window_id)); + /* @var $parent_opener_stack kOpenerStack */ + + $last_template = $parent_opener_stack->pop(true); + $parent_opener_stack->save(true); + } + else { + $last_template = $this->Application->RecallVar( rtrim('last_template_popup_' . $window_id, '_') ); + } + + return $last_template; + } + + /** * Allows to add new element to opener stack * * @param string $template * @param Array $params - * @param string $pass + * @param int $wid * @access public */ - public function openerStackPush($template, $params, $pass = 'all', $wid = null) + public function openerStackPush($template = '', $params = Array (), $wid = null) { - if (!isset($wid)) { - $wid = $this->Application->GetVar('m_wid'); + if ( !isset($params['pass']) ) { + $params['pass'] = 'all'; } /*// get parent window wid, when this was popup $window_relations = $this->Application->RecallVar('window_relations'); $window_relations = $window_relations ? unserialize($window_relations) : Array (); - $wid = array_key_exists($wid, $window_relations) ? $window_relations[$wid] : false;*/ + $wid = isset($window_relations[$wid]) ? $window_relations[$wid] : false;*/ - // get opener stack - $stack_name = rtrim('opener_stack_' . $wid, '_'); - $opener_stack = $this->Application->RecallVar($stack_name); - $opener_stack = $opener_stack ? unserialize($opener_stack) : Array (); + $opener_stack =& $this->Application->makeClass('kOpenerStack', Array ($wid)); + /* @var $opener_stack kOpenerStack */ // change opener stack $default_params = Array ('m_opener' => 'u', '__URLENCODE__' => 1); - if (!$this->Application->ConfigValue('UsePopups') && $wid) { + if ( !$this->Application->ConfigValue('UsePopups') && $opener_stack->getWindowID() ) { // remove wid to show combined header block in editing window $default_params['m_wid'] = ''; + list ($last_template, $last_params, ) = $opener_stack->get(kOpenerStack::LAST_ELEMENT); - // move last popup's opener stack elemenent to main window's opener stack - if ($opener_stack) { - list ($index_file, $env) = explode('|', $opener_stack[ count($opener_stack) - 1 ], 2); - $main_params = $this->Application->HttpQuery->processQueryString($env, 'pass'); - $main_template = $main_params['t']; - unset($main_params['t']); - - $main_params = array_merge($main_params, $default_params); - $this->openerStackPush($main_template, $main_params, $main_params['pass'], ''); + // move last popup's opener stack element to main window's opener stack + if ( $last_params ) { + $last_params = array_merge($last_params, $default_params); + $this->openerStackPush($last_template, $last_params, ''); } } - $redirect_params = array_merge($default_params, $params); - $new_level = $this->Application->BuildEnv($template, $redirect_params, $pass, true); - array_push($opener_stack, 'index.php|' . ltrim($new_level, ENV_VAR_NAME . '=') ); - $this->Application->StoreVar($stack_name, serialize($opener_stack)); + $params = array_merge($default_params, $params); + $opener_stack->push($template, $params, 'index.php'); + $opener_stack->save(); } /** * Allows to change last element in opener stack * - * @param string $template - * @param Array $params - * @param string $pass + * @param string $new_template + * @param Array $new_params * @access public */ - public function openerStackChange($params = Array(), $pass_events = true, $wid = null) + public function openerStackChange($new_template = null, $new_params = null) { - if (!isset($wid)) { - $wid = $this->Application->GetVar('m_wid'); - } + $opener_stack =& $this->Application->makeClass('kOpenerStack'); + /* @var $opener_stack kOpenerStack */ - // get opener stack - $stack_name = rtrim('opener_stack_' . $wid, '_'); - $opener_stack = $this->Application->RecallVar($stack_name); - $opener_stack = $opener_stack ? unserialize($opener_stack) : Array (); + list ($template, $params, $index_file) = $opener_stack->pop(); - // change opener stack - list ($index_file, $env) = explode('|', $opener_stack[ count($opener_stack) - 1 ], 2); - $vars = $this->Application->HttpQuery->processQueryString($env, 'pass'); - $vars = array_merge($vars, $params); + if ( isset($new_template) ) { + $template = $new_template; + } - // save opener stack - $new_level = $this->Application->BuildEnv($vars['t'], $vars, $vars['pass'], $pass_events, false); - $opener_stack[ count($opener_stack) - 1 ] = $index_file . '|' . $new_level; - $this->Application->StoreVar($stack_name, serialize($opener_stack)); + if ( isset($new_params) ) { + $params = array_merge($params, $new_params); + } + + $opener_stack->push($template, $params, $index_file); + $opener_stack->save(); } } \ No newline at end of file