Index: branches/5.2.x/core/kernel/utility/http_query.php
===================================================================
diff -u -r14699 -r14714
--- branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 14699)
+++ branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 14714)
@@ -1,6 +1,6 @@
AddAllVars();
$this->specialsToRemove = $this->Get('remove_specials');
- if ($this->specialsToRemove) {
+ if ( $this->specialsToRemove ) {
foreach ($this->specialsToRemove as $prefix_special => $flag) {
- if ($flag && strpos($prefix_special, '.') === false) {
+ if ( $flag && strpos($prefix_special, '.') === false ) {
unset($this->specialsToRemove[$prefix_special]);
- trigger_error('Incorrect usage of "remove_specials['.$prefix_special.']" field (no special found)', E_USER_NOTICE);
+ trigger_error('Incorrect usage of "remove_specials[' . $prefix_special . ']" field (no special found)', E_USER_NOTICE);
}
}
@@ -133,9 +145,9 @@
* @param string $prefix_special
*
* @return Array|bool
- * @access protected
+ * @access public
*/
- protected function discoverUnit($prefix_special)
+ public function discoverUnit($prefix_special)
{
list($prefix) = explode('.', $prefix_special);
@@ -200,20 +212,30 @@
return substr($prefix, 0, 1) == '#' ? $this->_getQueryString( substr($prefix, 1) ) : Array ();
}
- function removeSpecials($array)
+ /**
+ * Removes specials from request
+ *
+ * @param Array $array
+ * @return Array
+ * @access protected
+ */
+ protected function removeSpecials($array)
{
- $ret = Array();
+ $ret = Array ();
$removed = false;
+
foreach ($this->specialsToRemove as $prefix_special => $flag) {
- if ($flag) {
+ if ( $flag ) {
$removed = true;
- list ($prefix,$special) = explode('.', $prefix_special, 2);
+ list ($prefix, $special) = explode('.', $prefix_special, 2);
+
foreach ($array as $key => $val) {
- $new_key = preg_match("/^".$prefix."[._]{1}".$special."(.*)/", $key, $regs) ? $prefix.$regs[1] : $key;
+ $new_key = preg_match("/^" . $prefix . "[._]{1}" . $special . "(.*)/", $key, $regs) ? $prefix . $regs[1] : $key;
$ret[$new_key] = is_array($val) ? $this->removeSpecials($val) : $val;
}
}
}
+
return $removed ? $ret : $array;
}
@@ -225,17 +247,15 @@
*/
function AddAllVars()
{
- for ($i=0; $i < strlen($this->Order); $i++)
- {
- $current = $this->Order[$i];
- switch ($current) {
+ for ($i = 0; $i < strlen($this->Order); $i++) {
+ switch ( $this->Order[$i] ) {
case 'G':
$this->Get = $this->AddVars($_GET);
if (array_key_exists('sid', $_GET)) {
$this->_sidInQueryString = true;
}
- $vars = $this->processQueryString( $this->Get(ENV_VAR_NAME) );
+ $vars = $this->Application->processQueryString( $this->Get(ENV_VAR_NAME) );
if (array_key_exists('sid', $vars)) {
// used by Session::GetPassedSIDValue
@@ -255,22 +275,20 @@
$this->Cookie = $this->AddVars($_COOKIE);
break;
- case 'E';
- $this->Env = $this->AddVars($_ENV);
+ /*case 'E';
+ $this->Env = $this->AddVars($_ENV, false); //do not strip slashes!
break;
case 'S';
- $this->Server = $this->AddVars($_SERVER);
- break;
+ $this->Server = $this->AddVars($_SERVER, false); //do not strip slashes!
+ break;*/
case 'F';
$this->convertFiles();
$this->Files = $this->MergeVars($_FILES, false); //do not strip slashes!
break;
}
}
-
-// $this->AfterInit();
}
/**
@@ -281,22 +299,22 @@
function _processPostEnvVariables()
{
$passed = $this->Get('passed');
- if (!$passed) {
- return ;
+ if ( !$passed ) {
+ return;
}
$passed = explode(',', $passed);
foreach ($passed as $prefix_special) {
- if (strpos($prefix_special, '.') === false) {
+ if ( strpos($prefix_special, '.') === false ) {
continue;
}
list ($prefix, $special) = explode('.', $prefix_special);
$query_map = $this->getQueryString($prefix);
$post_prefix_special = $prefix . '_' . $special;
- foreach ($query_map as $index => $var_name) {
- if (array_key_exists($post_prefix_special . '_' . $var_name, $this->Post)) {
+ foreach ($query_map as $var_name) {
+ if ( array_key_exists($post_prefix_special . '_' . $var_name, $this->Post) ) {
$this->Set($prefix_special . '_' . $var_name, $this->Post[$post_prefix_special . '_' . $var_name]);
}
}
@@ -310,14 +328,16 @@
if ($this->Application->RewriteURLs() || $rewrite_url) {
// maybe call onafterconfigread here
+ $this->Application->UrlManager->initRewrite();
+
if (defined('DEBUG_MODE') && $this->Application->isDebugMode()) {
$this->Application->Debugger->profileStart('url_parsing', 'Parsing MOD_REWRITE url');
- $this->processRewriteURL();
+ $this->Application->UrlManager->rewrite->parseRewriteURL();
$description = 'Parsing MOD_REWRITE url (template: ' . $this->Get('t') . ')';
$this->Application->Debugger->profileFinish('url_parsing', $description);
}
else {
- $this->processRewriteURL();
+ $this->Application->UrlManager->rewrite->parseRewriteURL();
}
if ( !$rewrite_url && $this->rewriteRedirectRequired() ) {
@@ -345,7 +365,7 @@
function rewriteRedirectRequired()
{
$redirect_conditions = Array (
- !$this->Application->Session->IsHTTPSRedirect(), // not https <-> http redirect
+ !$this->IsHTTPSRedirect(), // not https <-> http redirect
!$this->refererIsOurSite(), // referer doesn't match ssl path or non-ssl domain (same for site domains)
!defined('GW_NOTIFY'), // not in payment gateway notification script
preg_match('/[\/]{0,1}index.php[\/]{0,1}/', $_SERVER['PHP_SELF']), // "index.php" was visited
@@ -366,6 +386,22 @@
}
/**
+ * This is redirect from https to http or via versa
+ *
+ * @return bool
+ */
+ function IsHTTPSRedirect()
+ {
+ $http_referer = array_key_exists('HTTP_REFERER', $_SERVER) ? $_SERVER['HTTP_REFERER'] : false;
+
+ return (
+ ( PROTOCOL == 'https://' && preg_match('#http:\/\/#', $http_referer) )
+ ||
+ ( PROTOCOL == 'http://' && preg_match('#https:\/\/#', $http_referer) )
+ );
+ }
+
+ /**
* Checks, that referer is out site
*
* @return bool
@@ -505,208 +541,48 @@
}
}
- function finalizeParsing($passed = Array(), $module_params = Array() )
+ function finalizeParsing($passed = Array())
{
- if ($passed) {
- foreach ($passed as $passed_prefix) {
- $this->discoverUnit($passed_prefix); // from mod-rewrite url parsing
- }
-
- $this->Set('passed', implode(',', $this->getDiscoveredUnits()));
+ if (!$passed) {
+ return;
}
- // get joined version (env var + mod rewrite parsed)
- $passed = $this->Application->GetVar('passed');
-
- if (!array_key_exists('editing_mode', $module_params)) {
- $module_params['editing_mode'] = '';
+ foreach ($passed as $passed_prefix) {
+ $this->discoverUnit($passed_prefix); // from mod-rewrite url parsing
}
- $module_params['__URLENCODE__'] = 1;
-
- $env = $this->Application->BuildEnv( $this->Get('t'), $module_params, $passed, false, false);
- $this->Set(ENV_VAR_NAME, $env);
- $_REQUEST['env'] = $_GET['env'] = $env; // for capability with old in-portal code
+ $this->Set('passed', implode(',', $this->getDiscoveredUnits()));
}
- function processRewriteURL()
- {
- $mod_rw_helper =& $this->Application->recallObject('ModRewriteHelper');
- /* @var $mod_rw_helper kModRewriteHelper */
-
- $mod_rw_helper->processRewriteURL();
- }
-
- function getDefaultTemplate($t)
- {
- $t = $this->getTemplateName(trim($t, '/'));
-
- if ( !$t ) {
- $t = 'index';
- }
-
- return trim($t, '/');
- }
-
- function extractSIDAndTemplate(&$parts)
- {
- $template = '';
- $vars = Array ();
-
- if ( preg_match('/^([\d]+|)-(.*)$/', $parts[0], $regs) ) {
- // first "env" component matches "sid-template" format
- // (will be false, when mod-rewrite url to home page is built)
- $sid = $regs[1];
- $template = $regs[2];
- array_shift($parts);
-
- if ( $sid ) {
- // Save Session ID
- $this->Set('sid', $sid);
- $vars['sid'] = $sid;
- }
- }
-
- // Save Template Name
- $vars['t'] = $this->getDefaultTemplate($template);
-
- return $vars;
- }
-
/**
- * Process QueryString only, create
- * events, ids, based on config
- * set template name and sid in
- * desired application variables.
- *
- * @param string $env_var environment string value
- * @param string $pass_name
- * @return Array
- * @access public
- */
- function processQueryString($env_var, $pass_name = 'passed')
- {
- // env=SID-TEMPLATE:m-1-1-1-1:l0-0-0:n-0-0-0:bb-0-0-1-1-1-0
- $vars = Array ();
- if ($env_var) {
- $more_vars = strpos($env_var, '&');
- if ($more_vars !== false) {
- parse_str(substr($env_var, $more_vars + 1), $vars);
- $env_var = substr($env_var, 0, $more_vars);
- }
-
- // replace escaped ":" symbol not to explode by it
- $env_var = str_replace('\:','_&+$$+&_', $env_var); // replace escaped "=" with spec-chars :)
- $parts = explode(':', $env_var);
-
- if (!$this->Application->RewriteURLs() || ($this->Application->RewriteURLs() && $this->Get('rewrite') != 'on')) {
- $vars = array_merge($vars, $this->extractSIDAndTemplate($parts));
- }
-
- if ($parts) {
- $passed = Array ();
- foreach ($parts as $mixed_part) {
- list ($passed[], $processed_vars) = $this->_parseEnvPart($mixed_part);
- $vars = array_merge($vars, $processed_vars);
- }
-
- $vars[$pass_name] = implode(',', array_unique($passed));
- }
- }
- else {
- $t = $this->getTemplateName('index');
- $vars['t'] = $t;
- }
-
- return $vars;
- }
-
- /**
- * Converts environment part into variable array (based on query map for given prefix)
- *
- * @param string $mixed_part
- * @return Array
- */
- function _parseEnvPart($mixed_part)
- {
- // In-portal old style env conversion - adds '-' between prefix and first var
- $mixed_part = str_replace('_&+$$+&_', ':', $mixed_part);
- $mixed_part = preg_replace("/^([a-zA-Z]+)([0-9]+)-(.*)/", "$1-$2-$3", $mixed_part);
-
- // replace escaped "-" symbol not to explode by it
- $escaped_part = str_replace('\-', '_&+$$+&_', $mixed_part);
- $escaped_part = explode('-', $escaped_part);
-
- $mixed_part = Array();
- foreach ($escaped_part as $escaped_val) {
- $mixed_part[] = str_replace('_&+$$+&_', '-', $escaped_val);
- }
-
- $prefix_special = array_shift($mixed_part); // l.pick, l
- $query_map = $this->discoverUnit($prefix_special); // from $_GET['env']
-
- $vars = Array ();
-
- // if config is not defined for prefix in QueryString, then don't process it
- if ($query_map) {
- foreach ($query_map as $index => $var_name) {
- // l_id, l_page, l_bla-bla-bla
- $val = $mixed_part[$index - 1];
- if ($val == '') $val = false;
- $vars[$prefix_special.'_'.$var_name] = $val;
- }
- }
-
- return Array ($prefix_special, $vars);
- }
-
- /**
- * Removes tpl part from template name + resolved template ID to name
- *
- * @param string $t
- * @return string
- * @access private
- */
- function getTemplateName($t)
- {
- if ( array_key_exists('t', $this->Get) && $this->Get['t'] ) {
- // template name is passed directly in url (GET method)
- $t = $this->Get['t'];
- }
-
- // if t was set through env, even in mod_rewrite mode!
- if ( $this->Get('env') && $this->Application->RewriteURLs() && $this->Get('t') ) {
- $t = $this->Get('t');
- }
-
- return preg_replace('/\.tpl$/', '', $t);
- }
-
- /**
* Saves variables from array specified
* into common variable storage place
*
* @param Array $array
+ * @param bool $strip_slashes
* @return Array
* @access private
*/
- function AddVars($array)
+ function AddVars($array, $strip_slashes = true)
{
- $array = $this->StripSlashes($array);
- foreach($array as $key => $value)
- {
- $this->Set($key,$value);
+ if ( $strip_slashes ) {
+ $array = $this->StripSlashes($array);
}
+
+ foreach ($array as $key => $value) {
+ $this->Set($key, $value);
+ }
+
return $array;
}
function MergeVars($array, $strip_slashes = true)
{
- if ($strip_slashes) {
+ if ( $strip_slashes ) {
$array = $this->StripSlashes($array);
}
- foreach($array as $key => $value_array) {
+ foreach ($array as $key => $value_array) {
// $value_array is an array too
$this->_Params = kUtil::array_merge_recursive($this->_Params, Array ($key => $value_array));
}
@@ -853,4 +729,19 @@
}
}
+ /**
+ * Checks, that url is empty
+ *
+ * @return bool
+ * @access public
+ */
+ public function isEmptyUrl()
+ {
+ if ( $this->Application->RewriteURLs() ) {
+ return !$this->Get('_mod_rw_url_');
+ }
+
+ return !count($this->Get);
+ }
+
}
\ No newline at end of file