Index: trunk/core/kernel/application.php =================================================================== diff -u -r7375 -r7391 --- trunk/core/kernel/application.php (.../application.php) (revision 7375) +++ trunk/core/kernel/application.php (.../application.php) (revision 7391) @@ -604,7 +604,7 @@ if (file_exists(KERNEL_PATH.'/constants.php')) { k4_include_once(KERNEL_PATH.'/constants.php'); } - + if (!$this->ModuleInfo) return false; foreach($this->ModuleInfo as $module_name => $module_info) { @@ -651,8 +651,8 @@ if ($this->GetVar('m_opener') == 'p') { $this->LinkVar('main_prefix'); // window prefix, that opened selector $this->LinkVar('dst_field'); // field to set value choosed in selector - $this->LinkVar('return_template'); // template to go, when something was coosen from popup (from finalizePopup) - $this->LinkVar('return_m'); // main env part to restore after popup will be closed (from finalizePopup) +// $this->LinkVar('return_template'); // template to go, when something was coosen from popup (from finalizePopup) +// $this->LinkVar('return_m'); // main env part to restore after popup will be closed (from finalizePopup) } if ($this->GetVar('ajax') == 'yes') { @@ -676,6 +676,17 @@ }*/ } + if ($this->isModuleEnabled('Proj-CMS')) { + $cms_handler =& $this->recallObject('st_EventHandler'); + if (!$this->TemplatesCache->TemplateExists($t) && !$this->IsAdmin()) { + $t = $cms_handler->GetDesignTemplate(); + } + /*else { + $cms_handler->SetCatByTemplate(); + }*/ + } + + if($this->isDebugMode() && constOn('DBG_PROFILE_MEMORY')) { $this->Debugger->appendMemoryUsage('Application before Parsing:'); } @@ -847,7 +858,7 @@ { return $this->Session->RemovePersistentVar($var); } - + /** * Restores Session variable to it's db version * @@ -878,7 +889,7 @@ { return $this->Session->RecallPersistentVar($var, $default); } - + /** * Stores variable $val in session under name $var * @@ -898,7 +909,7 @@ { $this->Session->StorePersistentVar($var, $val); } - + function StoreVarDefault($var, $val) { $session =& $this->recallObject('Session'); @@ -1037,15 +1048,19 @@ { if(!$t) $t = $this->GetVar('t'); // moved from kMainTagProcessor->T() - if ($this->GetVar('skip_last_template')) { + if ($this->isModuleEnabled('Proj-CMS')) { + $t = preg_replace('/^Content\//', '', $t); + } + + /*if ($this->GetVar('skip_last_template')) { $params['opener'] = 'p'; $this->SetVar('m_opener', 'p'); } if ($t == 'incs/close_popup') { // because this template closes the popup and we don't need popup mark here anymore $params['m_opener'] = 's'; - } + }*/ if( substr($t, -4) == '.tpl' ) $t = substr($t, 0, strlen($t) - 4 ); @@ -1075,19 +1090,32 @@ } if (getArrayValue($params, 'opener') == 'u') { - $opener_stack=$this->RecallVar('opener_stack'); - if($opener_stack) { - $opener_stack=unserialize($opener_stack); - if (count($opener_stack) > 0) { - list($index_file, $env) = explode('|', $opener_stack[count($opener_stack)-1]); - $ret = $this->BaseURL($prefix, $ssl).$index_file.'?'.ENV_VAR_NAME.'='.$env; - if( getArrayValue($params,'escape') ) $ret = addslashes($ret); - return $ret; + $wid = $this->Application->GetVar('m_wid'); + $stack_name = rtrim('opener_stack_'.$wid, '_'); + $opener_stack = $this->RecallVar($stack_name); + + if ($opener_stack && $opener_stack != serialize(Array())) { + $opener_stack = unserialize($opener_stack); + list($index_file, $env) = explode('|', $opener_stack[count($opener_stack) - 1]); + $ret = $this->BaseURL($prefix, $ssl).$index_file.'?'.ENV_VAR_NAME.'='.$env; + if ( getArrayValue($params,'escape') ) $ret = addslashes($ret); + + if (isset($params['m_opener']) && $params['m_opener'] == 'u') { + array_pop($opener_stack); + if (!$opener_stack) { + $this->RemoveVar($stack_name); + // remove popups last templates, because popup is closing now + $this->RemoveVar('last_template_'.$wid); + $this->RemoveVar('last_template_popup_'.$wid); + + // don't save popups last templates again :) + $this->SetVar('skip_last_template', 1); + } + else { + $this->StoreVar($stack_name, serialize($opener_stack)); + } } - else { - //define('DBG_REDIRECT', 1); - $t = $this->GetVar('t'); - } + return $ret; } else { //define('DBG_REDIRECT', 1); @@ -1214,7 +1242,7 @@ return $pass_info; } - function BuildEnv_NEW($t, $params, $pass = 'all', $pass_events = false) + function BuildEnv_NEW($t, $params, $pass='all', $pass_events = false) { // $session =& $this->recallObject('Session'); $force_admin = getArrayValue($params,'admin') || $this->GetVar('admin'); @@ -1551,8 +1579,8 @@ /** * Checks if user is logged in, and creates * user object if so. User object can be recalled - * later using "u" prefix. Also you may - * get user id by getting "u_id" variable. + * later using "u.current" prefix_special. Also you may + * get user id by getting "u.current_id" variable. * * @access private */ @@ -1561,19 +1589,26 @@ $session =& $this->recallObject('Session'); $user_id = $session->GetField('PortalUserId'); if (!$user_id && $user_id != -1) $user_id = -2; + $this->SetVar('u.current_id', $user_id); + + if (!$this->IsAdmin()) { + // needed for "profile edit", "registration" forms ON FRONT ONLY $this->SetVar('u_id', $user_id); + } + $this->StoreVar('user_id', $user_id); if ($this->GetVar('expired') == 1) { - $user =& $this->recallObject('u'); + // this parameter is set only from admin + $user =& $this->recallObject('u.current'); $user->SetError('ValidateLogin', 'session_expired', 'la_text_sess_expired'); } if (($user_id != -2) && constOn('DBG_REQUREST_LOG') ) { $http_query =& $this->recallObject('HTTPQuery'); $http_query->writeRequestLog(DBG_REQUREST_LOG); } - + if ($user_id != -2) { // normal users + root $this->LoadPersistentVars(); @@ -1588,6 +1623,7 @@ { $this->Session->LoadPersistentVars(); } + function LoadCache() { $cache_key = $this->GetVar('t').$this->GetVar('m_theme').$this->GetVar('m_lang').$this->IsAdmin(); @@ -2074,42 +2110,85 @@ } /** - * Returns main prefix for subtable prefix passes + * Returns genealogical main prefix for subtable prefix passes + * OR prefix, that has been found in REQUEST and some how is parent of passed subtable prefix * * @param string $current_prefix + * @param string $real_top if set to true will return real topmost prefix, regardless of its id is passed or not * @return string * @access public - * @author Kostja + * @author Kostja / Alex */ - function GetTopmostPrefix($current_prefix) + function GetTopmostPrefix($current_prefix, $real_top=false) { - while ( $parent_prefix = $this->getUnitOption($current_prefix, 'ParentPrefix') ) - { + // 1. get genealogical tree of $current_prefix + $prefixes = Array ($current_prefix); + while ( $parent_prefix = $this->getUnitOption($current_prefix, 'ParentPrefix') ) { $current_prefix = $parent_prefix; + array_unshift($prefixes, $current_prefix); } + + if ($real_top) return $current_prefix; + + // 2. find what if parent is passed + $passed = explode(',', $this->GetVar('passed')); + foreach ($prefixes as $current_prefix) { + if (in_array($current_prefix, $passed)) { + break; + } + } + return $current_prefix; } + /** + * Triggers email event of type Admin + * + * @param string $email_event_name + * @param int $to_user_id + * @param array $send_params associative array of direct send params, possible keys: to_email, to_name, from_email, from_name, message, message_text + * @return unknown + */ function &EmailEventAdmin($email_event_name, $to_user_id = -1, $send_params = false) { return $this->EmailEvent($email_event_name, 1, $to_user_id, $send_params); } + /** + * Triggers email event of type User + * + * @param string $email_event_name + * @param int $to_user_id + * @param array $send_params associative array of direct send params, possible keys: to_email, to_name, from_email, from_name, message, message_text + * @return unknown + */ function &EmailEventUser($email_event_name, $to_user_id = -1, $send_params = false) { return $this->EmailEvent($email_event_name, 0, $to_user_id, $send_params); } + /** + * Triggers general email event + * + * @param string $email_event_name + * @param int $email_event_type ( 0 for User, 1 for Admin) + * @param int $to_user_id + * @param array $send_params associative array of direct send params, + * possible keys: to_email, to_name, from_email, from_name, message, message_text + * @return unknown + */ function &EmailEvent($email_event_name, $email_event_type, $to_user_id = -1, $send_params = false) { - $event = new kEvent('emailevents:OnEmailEvent'); - $event->setEventParam('EmailEventName', $email_event_name); - $event->setEventParam('EmailEventToUserId', $to_user_id); - $event->setEventParam('EmailEventType', $email_event_type); - if ($send_params){ - $event->setEventParam('DirectSendParams', $send_params); + $params = array( + 'EmailEventName' => $email_event_name, + 'EmailEventToUserId' => $to_user_id, + 'EmailEventType' => $email_event_type, + ); + if ($send_params) { + $params['DirectSendParams'] = $send_params; } - $this->HandleEvent($event); + $event_str = isset($send_params['use_special']) ? 'emailevents.'.$send_params['use_special'].':OnEmailEvent' : 'emailevents:OnEmailEvent'; + $this->HandleEvent($event, $event_str, $params); return $event; } @@ -2118,8 +2197,6 @@ function LoggedIn() { $user_id = $this->Application->RecallVar('user_id'); -// $user =& $this->recallObject('u'); -// $user_id = $user->GetID(); $ret = $user_id > 0; if ($this->IsAdmin() && ($user_id == -1)) { @@ -2183,26 +2260,47 @@ trigger_error('depricated method '.$class.'->'.$method.'(...)', E_USER_ERROR); } + /** + * Returns Window ID of passed prefix main prefix (in edit mode) + * + * @param string $prefix + * @return mixed + */ + function GetTopmostWid($prefix) + { + $top_prefix = $this->GetTopmostPrefix($prefix); + $mode = $this->GetVar($top_prefix.'_mode'); + return $mode != '' ? substr($mode, 1) : ''; + } /** * Get temp table name * * @param string $table + * @param mixed $wid * @return string */ - function GetTempName($table) + function GetTempName($table, $wid = '') { - return TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_'.$table; + if (preg_match('/prefix:(.*)/', $wid, $regs)) { + $wid = $this->GetTopmostWid($regs[1]); + } + + return TABLE_PREFIX.'ses_'.$this->GetSID().($wid ? '_'.$wid : '').'_edit_'.$table; } - function GetTempTablePrefix() + function GetTempTablePrefix($wid = '') { - return TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_'; + if (preg_match('/prefix:(.*)/', $wid, $regs)) { + $wid = $this->GetTopmostWid($regs[1]); + } + + return TABLE_PREFIX.'ses_'.$this->GetSID().($wid ? '_'.$wid : '').'_edit_'; } function IsTempTable($table) { - return strpos($table, TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_') !== false; + return preg_match('/'.TABLE_PREFIX.'ses_'.$this->GetSID().'(_[\d]+){0,1}_edit_(.*)/',$table); } /** @@ -2213,9 +2311,10 @@ */ function GetLiveName($temp_table) { - if( preg_match('/'.TABLE_PREFIX.'ses_'.$this->GetSID().'_edit_(.*)/',$temp_table,$rets) ) + if( preg_match('/'.TABLE_PREFIX.'ses_'.$this->GetSID().'(_[\d]+){0,1}_edit_(.*)/',$temp_table, $rets) ) { - return $rets[1]; + // cut wid from table end if any + return $rets[2]; } else {