Index: trunk/core/kernel/startup.php =================================================================== diff -u -r2608 -r2659 --- trunk/core/kernel/startup.php (.../startup.php) (revision 2608) +++ trunk/core/kernel/startup.php (.../startup.php) (revision 2659) @@ -9,16 +9,8 @@ define('INPORTAL_ENV', 1); # New path detection method - -//echo "FULL_PATH: ".FULL_PATH.'
'; - -//$fp = str_replace('\\', '/', dirname(FULL_PATH)); $ps = preg_replace("/\/admin$/", '', str_replace('\\', '/', dirname($_SERVER['PHP_SELF']))); -//echo "fp: $fp
"; -//echo "ps: $ps
"; - -//$_SERVER['DOCUMENT_ROOT'] = $fp; define('BASE_PATH', $ps); # /New method Index: trunk/core/kernel/application.php =================================================================== diff -u -r2604 -r2659 --- trunk/core/kernel/application.php (.../application.php) (revision 2604) +++ trunk/core/kernel/application.php (.../application.php) (revision 2659) @@ -667,13 +667,15 @@ if( isset($params['index_file']) ) $index_file = $params['index_file']; + $ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null; + 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).$index_file.'?'.ENV_VAR_NAME.'='.$env; + $ret = $this->BaseURL($prefix, $ssl).$index_file.'?'.ENV_VAR_NAME.'='.$env; if( getArrayValue($params,'escape') ) $ret = addslashes($ret); return $ret; } @@ -691,21 +693,19 @@ $pass = isset($params['pass']) ? $params['pass'] : ''; $pass_events = isset($params['pass_events']) ? $params['pass_events'] : false; // pass events with url - - if (defined('MOD_REWRITE') && MOD_REWRITE) { $env = $this->BuildEnv('', $params, $pass, $pass_events, false); $env = ltrim($env, ':-'); $session =& $this->recallObject('Session'); $sid = $session->NeedQueryString() ? '?sid='.$this->GetSID() : ''; // $env = str_replace(':', '/', $env); - $ret = rtrim($this->BaseURL($prefix).$t.'.html/'.$env.'/'.$sid, '/'); + $ret = rtrim($this->BaseURL($prefix, $ssl).$t.'.html/'.$env.'/'.$sid, '/'); } else { $env = $this->BuildEnv($t, $params, $pass, $pass_events); - $ret = $this->BaseURL($prefix).$index_file.'?'.$env; + $ret = $this->BaseURL($prefix, $ssl).$index_file.'?'.$env; } return $ret; @@ -788,9 +788,19 @@ return $ret; } - function BaseURL($prefix='') + function BaseURL($prefix='', $ssl=null) { - return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/'; + if ($ssl == null) { + return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/'; + } + else { + if ($ssl) { + return $this->ConfigValue('SSL_URL').$prefix.'/'; + } + else { + return 'http://'.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/'; + } + } } function Redirect($t='', $params=null, $prefix='', $index_file=null) Index: trunk/core/kernel/processors/main_processor.php =================================================================== diff -u -r2346 -r2659 --- trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 2346) +++ trunk/core/kernel/processors/main_processor.php (.../main_processor.php) (revision 2659) @@ -1,18 +1,18 @@ Application->recallObject('kActions'); $actions->Set('t', $this->Application->GetVar('t')); $actions->Set('sid', $this->Application->GetSID()); $actions->Set('m_opener', $this->Application->GetVar('m_opener') ); - + } - + /** * Used to handle calls where tag name * match with existing php function name @@ -25,7 +25,7 @@ if ($tag->Tag=='include') $tag->Tag='MyInclude'; return parent::ProcessTag($tag); } - + /** * Creates HTML tag for all templates * affects future css, js files and href params of links @@ -38,7 +38,7 @@ $url = $this->Application->BaseURL().substr(THEMES_PATH,1).'/'; return ''; } - + /** * Returns base url for web-site * @@ -49,17 +49,17 @@ { return $this->Application->BaseURL(); } - + function TemplatesBase($params) { return $this->Application->BaseURL().THEMES_PATH; } - + function ProjectBase($params) { return $this->Application->BaseURL(); } - + /*function Base($params) { return $this->Application->BaseURL().$params['add']; @@ -86,13 +86,13 @@ unset($params['template']); $prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']); $index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']); - + /*$pass=isset($params['pass']) ? $params['pass'] : $this->Application->GetVar('t_pass'); unset($params['pass']); $this->Application->SetVar('t_pass', $pass); - + $pass_events = isset($params['pass_events']) && $params['pass_events'] ? 1 : 0; unset($params['pass_events']); $this->Application->SetVar('t_pass_events', $pass_events);*/ - + //Use only implicit params passing, do not set into APP // $this->Set($params); // set other params as application vars if( !getArrayValue($params,'no_amp') ) @@ -104,7 +104,7 @@ return $this->Application->HREF($t,$prefix,$params,$index_file); } } - + function Link($params) { if (isset($params['template'])) { @@ -113,46 +113,46 @@ } if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm'; if (isset($params['no_pass'])) unset($params['no_pass']); - + if( $this->Application->GetVar('admin') ) $params['admin'] = 1; - + return $this->T($params); } - + function Env($params) { $t = $params['template']; unset($params['template']); return $this->Application->BuildEnv($t, $params, 'm', null, false); } - + function FormAction($params) { return $this->Application->ProcessParsedTag('m', 't', Array( 'pass'=>'all,m' ) ); } - + /*// NEEDS TEST function Config($params) { return $this->Application->ConfigOption($params['var']); } - + function Object($params) { $name = $params['name']; $method = $params['method']; - + $tmp =& $this->Application->recallObject($name); if ($tmp != null) { - if (method_exists($tmp, $method)) + if (method_exists($tmp, $method)) return $tmp->$method($params); else echo "Method $method does not exist in object ".get_class($tmp)." named $name
"; } else echo "Object $name does not exist in the appliaction
"; }*/ - + /** * Tag, that always returns true. * For parser testing purposes @@ -165,7 +165,7 @@ { return true; } - + /** * Tag, that always returns false. * For parser testing purposes @@ -178,7 +178,7 @@ { return false; } - + /** * Returns block parameter by name * @@ -191,11 +191,11 @@ //$parser =& $this->Application->recallObject('TemplateParser'); $res = $this->Application->Parser->GetParam($params['name']); if ($res === false) $res = ''; - if (isset($params['plus'])) + if (isset($params['plus'])) $res += $params['plus']; return $res; } - + /** * Compares block parameter with value specified * @@ -210,13 +210,13 @@ $value = $params['value']; return ($this->Application->Parser->GetParam($name) == $value); } - + /*function PHP_Self($params) { return $HTTP_SERVER_VARS['PHP_SELF']; } */ - + /** * Returns session variable value by name * @@ -241,7 +241,7 @@ $value = $params['value']; $this->Application->StoreVar($name,$value); } - + /** * Sets application variable value(-s) * @@ -254,7 +254,7 @@ $this->Application->SetVar($param, $value); } } - + /** * Increment application variable * specified by number specified @@ -266,7 +266,7 @@ { $this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']); } - + /** * Retrieves application variable * value by name @@ -278,9 +278,9 @@ function Get($params) { $ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), EMPTY_ON_NULL); - return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret; + return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret; } - + /** * Retrieves application constant * value by name @@ -293,13 +293,13 @@ { return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : ''; } - + function ConfigEquals($params) { $option = $this->SelectParam($params, 'name,option,var'); return $this->Application->ConfigValue($option) == getArrayValue($params, 'value'); } - + /** * Creates all hidden fields * needed for kernel_form @@ -312,7 +312,7 @@ { $actions =& $this->Application->recallObject('kActions'); $actions->Set('t', $this->Application->GetVar('t') ); - + $params = $actions->GetParams(); $o=''; foreach ($params AS $name => $val) @@ -321,7 +321,7 @@ } return $o; } - + function GetFormHiddens($params) { $sid = $this->Application->GetSID(); @@ -340,7 +340,7 @@ } return $o; } - + function Odd_Even($params) { $odd = $params['odd']; @@ -351,7 +351,7 @@ else { $var = $params['var']; } - + if ($this->Application->GetVar($var) == 'even') { $this->Application->SetVar($var, 'odd'); return $even; @@ -361,7 +361,7 @@ return $odd; } } - + /** * Returns phrase translation by name * @@ -390,35 +390,35 @@ $if_true=$params['true']; $if_false=$params['false']; } - + if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/", $this->Application->GetVar('t'))) { return $if_true; } else { return $if_false; } } - + function IsNotActive($params) { return !$this->is_active($params); } - + function IsActive($params) { return $this->is_active($params); } - + function is_t_active($params) { return $this->is_active($params); } - + function CurrentTemplate($params) { return $this->is_active($params); } - + /** * Checks if session variable * specified by name value match @@ -452,7 +452,7 @@ return 1; } } - + /** * Includes template * and returns it's @@ -468,18 +468,18 @@ $BlockParser->SetParams($params); $parser =& $this->Application->Parser; $this->Application->Parser =& $BlockParser; - + $t = $this->SelectParam($params, 't,template,block,name'); $t = eregi_replace("\.tpl$", '', $t); - + $templates_cache =& $this->Application->recallObject('TemplatesCache'); - + $res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t), $t ); - + if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) { if ($block_no_data = getArrayValue($params, 'block_no_data')) { $res = $BlockParser->Parse( - $templates_cache->GetTemplateBody($block_no_data, $silent), + $templates_cache->GetTemplateBody($block_no_data, $silent), $t ); } @@ -491,11 +491,11 @@ $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists; return $res; } - + /*function Kernel_Scripts($params) { return ''; - }*/ + }*/ /*function GetUserPermission($params) @@ -510,8 +510,8 @@ return $aPermissions[$perm_name]; } }*/ - - + + /** * Set's parser block param value * @@ -527,31 +527,31 @@ $parser->AddParam('/\$'.$param.'/', $value); } } - + /*function ParseToVar($params) { $var = $params['var']; $tagdata = $params['tag']; $parser =& $this->Application->Parser; //recallObject('TemplateParser'); $res = $this->Application->ProcessTag($tagdata); - + $parser->SetParam($var, $res); $parser->AddParam('/\$'.$var.'/', $res); return ''; }*/ - + /*function TagNotEmpty($params) { $tagdata = $params['tag']; $res = $this->Application->ProcessTag($tagdata); return $res != ''; }*/ - + /*function TagEmpty($params) { return !$this->TagNotEmpty($params); }*/ - + /** * Parses block and returns result * @@ -564,12 +564,12 @@ $parser =& $this->Application->Parser; // recallObject('TemplateParser'); return $parser->ParseBlock($params); } - + function RenderElement($params) { return $this->ParseBlock($params); } - + /** * Checks if debug mode is on * @@ -580,7 +580,7 @@ { return $this->Application->isDebugMode(); } - + function MassParse($params) { $qty = $params['qty']; @@ -590,7 +590,7 @@ $o = ''; if ($mode == 'func') { $func = create_function('$params', ' - $o = \'\'; + $o = \'\'; $o.= \'a\'.$params[\'param1\'].\'\'; $o.= \'a\'.$params[\'param2\'].\'\'; $o.= \'a\'.$params[\'param3\'].\'\'; @@ -603,26 +603,26 @@ $block_params['param2'] = rand(1, 10000); $block_params['param3'] = rand(1, 10000); $block_params['param4'] = rand(1, 10000); - $o .= $func($block_params); + $o .= $func($block_params); } return $o; } - + $block_params['name'] = $block; - + for ($i=0; $i<$qty; $i++) { $block_params['param1'] = rand(1, 10000); $block_params['param2'] = rand(1, 10000); $block_params['param3'] = rand(1, 10000); $block_params['param4'] = rand(1, 10000); $block_params['passed'] = $params['passed']; $block_params['prefix'] = 'm'; - + $o.= $this->Application->ParseBlock($block_params, 1); } return $o; } - + function AfterScript($params) { $after_script = $this->Application->GetVar('after_script'); @@ -631,12 +631,12 @@ } return ''; } - + function LoggedIn($params) { return $this->Application->LoggedIn(); } - + /** * Checks if user is logged in and if not redirects it to template passed * @@ -657,24 +657,24 @@ $has_permission = $has_permission && $this->Application->CheckPermission($permission); } $group_has_permission = $group_has_permission || $has_permission; - + if($group_has_permission) { return; } } - + if( !$this->Application->LoggedIn() ) { $t = $this->Application->GetVar('t'); $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) ); } - else + else { $this->Application->Redirect( $params['no_permissions_template'] ); } } - + $condition = getArrayValue($params,'condition'); if(!$condition) { @@ -690,32 +690,72 @@ { $condition = $this->Application->ConfigValue($condition); } - + } - + if( !$this->Application->LoggedIn() && $condition ) { $t = $this->Application->GetVar('t'); $this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) ); } } - + + /** + * Checks if SSL is on and redirects to SSL URL if needed + * If SSL_URL is not defined in config - the tag does not do anything + * If for_logged_in_only="1" exits if user is not logged in. + * If called without params forces https right away. If called with by_config="1" checks the + * Require SSL setting from General Config and if it is ON forces https + * + * @param unknown_type $params + */ + function CheckSSL($params) + { + $ssl = $this->Application->ConfigValue('SSL_URL'); + if (!$ssl) return; //SSL URL is not set - no way to require SSL + + $require = false; + + if ($params['mode'] == 'required') { + $require = true; + if (isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn()) { + $require = false; + } + + if (isset($params['condition'])) { + if (!$this->Application->ConfigValue($params['condition'])) { + $require = false; + } + } + } + + if ($require) { + if (PROTOCOL == 'https://') return; + $this->Application->Redirect('', Array('__SSL__' => 1)); + } + else { + if (PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required')) { + $this->Application->Redirect('', Array('__SSL__' => 0)); + } + } + } + function SaveReturnScript($params) { // admin/save_redirect.php?do= $url = str_replace($this->Application->BaseURL(), '', $this->T($params) ); $url = explode('?', $url, 2); $url = 'save_redirect.php?'.$url[1].'&do='.$url[0]; - + $this->Application->StoreVar('ReturnScript', $url); } - + function ConstOn($params) { $name = $this->SelectParam($params,'name,const'); return $this->Application->isDebugMode() && dbg_ConstOn($name); } - + function SetDefaultCategory($params) { $module_name = $params['module']; @@ -729,19 +769,19 @@ $user_prefix = 'users'; $this->parser->registerprefix($user_prefix); $user_class = $this->parser->processors[$user_prefix]->item_class; - + $candidate = new $user_class(NULL, $this->parser->processors[$user_prefix]); //print_pre($this->Session->Property); - + $special = array_shift($params); //echo"$special
"; $candidate_id = $candidate->Login($this->Session->GetProperty('username'), $this->Session->GetProperty('password'), $special); - + if ($candidate_id !== false) { $this->Session->SetField('user_id', $candidate_id); $this->Session->Update(); - $this->Session->AfterLogin(); - + $this->Session->AfterLogin(); + $this->parser->register_prefix('m'); $template = array_shift($params); if ($template == '') $template = 'index';