Index: branches/5.2.x/core/kernel/utility/http_query.php =================================================================== diff -u -N -r14092 -r14095 --- branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 14092) +++ branches/5.2.x/core/kernel/utility/http_query.php (.../http_query.php) (revision 14095) @@ -1,6 +1,6 @@ Conn =& $this->Application->GetADODBConnection(); $this->Order = $order; if (array_key_exists('HTTP_X_REQUESTED_WITH', $_SERVER) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { // when AJAX request is made from jQuery, then create ajax variable, // so any logic based in it (like redirects) will not break down $_GET['ajax'] = 'yes'; } - } - function Init($prefix, $special) - { $this->AddAllVars(); - $this->specialsToRemove = $this->Get('remove_specials'); + if ($this->specialsToRemove) { foreach ($this->specialsToRemove as $prefix_special => $flag) { 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); } } + $this->_Params = $this->removeSpecials($this->_Params); } + ini_set('magic_quotes_gpc', 0); } + /** + * Discovers unit form request and returns it's QueryString option on success + * + * @param string $prefix_special + * + * @return Array|bool + * @access protected + */ + protected function discoverUnit($prefix_special) + { + list($prefix) = explode('.', $prefix_special); + + $query_string = $this->getQueryString($prefix); + + if ($query_string) { + // only units with QueryString option can be discovered + $this->discoveredUnits[$prefix_special] = $query_string; + + return $query_string; + } + + unset( $this->discoveredUnits[$prefix] ); + + return false; + } + + /** + * Returns units, passed in request + * + * @param bool $prefix_special_only + * @return Array + * @access protected + */ + public function getDiscoveredUnits($prefix_special_only = true) + { + return $prefix_special_only ? array_keys( $this->discoveredUnits ) : $this->discoveredUnits; + } + + /** + * Returns QueryMap for requested unit config. + * In case if unit config is a clone, then get parent item's (from prefix) config to create clone + * + * @param string $prefix + * @return Array + * @access protected + */ + protected function getQueryString($prefix) + { + $ret = $this->Application->getUnitOption($prefix, 'QueryString', Array ()); + + if ( !$ret && preg_match('/(.*?)-(.*)/', $prefix, $regs) ) { + // "#prefix" (new format), "prefix" (old format) + return $this->_getQueryString('#' . $regs[2]); + } + + return $ret; + } + + /** + * Returns query string (with safety check against missing prefixes) + * + * @param string $prefix + * @return Array + */ + private function _getQueryString($prefix) + { + if ( $this->Application->prefixRegistred($prefix) ) { + return $this->Application->getUnitOption($prefix, 'QueryString'); + } + + return substr($prefix, 0, 1) == '#' ? $this->_getQueryString( substr($prefix, 1) ) : Array (); + } + function removeSpecials($array) { $ret = Array(); @@ -221,7 +293,7 @@ } list ($prefix, $special) = explode('.', $prefix_special); - $query_map = $this->Application->EventManager->getQueryMap($prefix); + $query_map = $this->getQueryString($prefix); $post_prefix_special = $prefix . '_' . $special; foreach ($query_map as $index => $var_name) { @@ -439,11 +511,11 @@ function finalizeParsing($passed = Array(), $module_params = Array() ) { if ($passed) { - $event_manger =& $this->Application->recallObject('EventManager'); foreach ($passed as $passed_prefix) { - $event_manger->setQueryMap($passed_prefix); + $this->discoverUnit($passed_prefix); // from mod-rewrite url parsing } - $this->Set('passed', implode(',', array_keys($event_manger->queryMaps))); + + $this->Set('passed', implode(',', $this->getDiscoveredUnits())); } // get joined version (env var + mod rewrite parsed) @@ -518,14 +590,14 @@ $parts = explode(':', $env_var); if (!$this->Application->RewriteURLs() || ($this->Application->RewriteURLs() && $this->Get('rewrite') != 'on')) { - $vars = array_merge_recursive2($vars, $this->extractSIDAndTemplate($parts)); + $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_recursive2($vars, $processed_vars); + $vars = array_merge($vars, $processed_vars); } $vars[$pass_name] = implode(',', array_unique($passed)); @@ -561,7 +633,7 @@ } $prefix_special = array_shift($mixed_part); // l.pick, l - $query_map = $this->Application->EventManager->setQueryMap($prefix_special); + $query_map = $this->discoverUnit($prefix_special); // from $_GET['env'] $vars = Array (); @@ -618,13 +690,17 @@ return $array; } - function MergeVars($array, $strip_slashes=true) + function MergeVars($array, $strip_slashes = true) { - if ($strip_slashes) $array = $this->StripSlashes($array); - foreach($array as $key => $value) - { - $this->_Params = array_merge_recursive2($this->_Params, Array($key=>$value)); + if ($strip_slashes) { + $array = $this->StripSlashes($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)); + } + return $array; }