Conn =& $this->Application->GetADODBConnection(); $this->Order = $order; $this->Admin = $this->Application->IsAdmin(); // better cache this value, not to calculate it each time in foreach } function Init($prefix, $special) { $this->AddAllVars(); $this->specialsToRemove = $this->Get('remove_specials'); if($this->specialsToRemove) { $this->_Params = $this->removeSpecials($this->_Params); } ini_set('magic_quotes_gpc', 0); } function removeSpecials($array) { $ret = Array(); $removed = false; foreach($this->specialsToRemove as $prefix_special => $flag) { if($flag) { $removed = true; 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; $ret[$new_key] = is_array($val) ? $this->removeSpecials($val) : $val; } } } return $removed ? $ret : $array; } /** * All all requested vars to * common storage place * * @access private */ function AddAllVars() { for ($i=0; $i < strlen($this->Order); $i++) { $current = $this->Order[$i]; switch ($current) { case 'G': $this->Get = $this->AddVars($_GET); $vars = $this->processQueryString( $this->Get(ENV_VAR_NAME) ); $this->AddParams($vars); break; case 'P': $this->Post = $this->AddVars($_POST); $this->convertPostEvents(); break; case 'C': $this->Cookie = $this->AddVars($_COOKIE); break; case 'E'; $this->Env = $this->AddVars($_ENV); break; case 'S'; $this->Server = $this->AddVars($_SERVER); break; case 'F'; $this->convertFiles(); $this->Files = $this->MergeVars($_FILES, false); //do not strip slashes! break; } } // $this->AfterInit(); } function AfterInit() { // $vars = $this->processQueryString($this->Get(ENV_VAR_NAME)); // $this->AddParams($vars); // $this->convertPostEvents(); // if ($this->Application->RewriteURLs()) { if ($this->Application->RewriteURLs() || $this->Get('_mod_rw_url_')) { if( $this->Application->isDebugMode() ) { $this->Application->Debugger->profileStart('url_parsing'); $this->processRewriteURL(); $description = 'Parsing MOD_REWRITE url (template: '.$this->Get('t').')'; $this->Application->Debugger->profileFinish('url_parsing', $description); } else { $this->processRewriteURL(); } } else { $this->Application->VerifyLanguageId(); $this->Application->VerifyThemeId(); } } function convertFiles() { if (!$_FILES) { return false; } $file_keys = Array('error','name','size','tmp_name','type'); $tmp = Array(); foreach($_FILES as $file_name => $file_info) { if( is_array($file_info['error']) ) { $tmp[$file_name] = $this->getArrayLevel( $file_info['error'], $file_name ); } else { $normal_files[$file_name] = $file_info; } } if(!$tmp) return false; $files = $_FILES; $_FILES = Array(); foreach($tmp as $prefix => $prefix_files) { $anchor =& $_FILES; foreach($prefix_files['keys'] as $key) { $anchor =& $anchor[$key]; } foreach($prefix_files['value'] as $field_name) { unset($inner_anchor); unset($copy); $work_copy = $prefix_files['keys']; foreach($file_keys as $file_key) { $inner_anchor =& $files[$prefix][$file_key]; if (isset($copy)) { $work_copy = $copy; } else { $copy = $work_copy; } array_shift($work_copy); foreach($work_copy as $prefix_file_key) { $inner_anchor =& $inner_anchor[$prefix_file_key]; } $anchor[$field_name][$file_key] = $inner_anchor[$field_name]; } } } // keys: img_temp, 0, values: LocalPath, ThumbPath } function getArrayLevel(&$level, $prefix='') { $ret['keys'] = $prefix ? Array($prefix) : Array(); $ret['value'] = Array(); foreach($level as $level_key => $level_value) { if( is_array($level_value) ) { $ret['keys'][] = $level_key; $tmp = $this->getArrayLevel($level_value); $ret['keys'] = array_merge($ret['keys'], $tmp['keys']); $ret['value'] = array_merge($ret['value'], $tmp['value']); } else { $ret['value'][] = $level_key; } } return $ret; } /** * Owerwrites GET events with POST events in case if they are set and not empty * */ function convertPostEvents() { $events = $this->Get('events'); if (is_array($events)) { foreach ($events as $prefix_special => $event_name) { if ($event_name) { $this->Set($prefix_special.'_event', $event_name); } } } } 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->Set('passed', implode(',', array_keys($event_manger->queryMaps))); } // get joined version (env var + mod rewrite parsed) $passed = $this->Application->GetVar('passed'); $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 } function processRewriteURL() { $mod_rw_helper = $this->Application->recallObject('ModRewriteHelper'); $mod_rw_helper->processRewriteURL(); } function getDefaultTemplate($t) { $t = $this->getTemplateName( trim($t, '/') ); if (!$t) $t = 'index'; return trim($t, '/'); } function extractSIDAndTemplate(&$parts) { $vars = Array (); if (defined('INPORTAL_ENV') && INPORTAL_ENV) { // SID-TEMPLATE $sub_parts = array_shift($parts); list($sid, $t) = explode('-', $sub_parts, 2); // Save Session ID if ($sid) { $this->Set('sid', $sid); $vars['sid'] = $sid; } } else { // SID:TEMPLATE // Save Session ID $sid = array_shift($parts); if ($sid) $vars['sid'] = $sid; $t = array_shift($parts); } // Save Template Name $vars['t'] = $this->getDefaultTemplate($t); return $vars; } /** * Process QueryString only, create * events, ids, based on config * set template name and sid in * desired application variables. * * @param string $env_var enviroment string value * * @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_recursive2($vars, $this->extractSIDAndTemplate($parts)); } if ($parts) { foreach ($parts as $mixed_part) { $vars = array_merge_recursive2($vars, $this->parseEnvPart($mixed_part, $pass_name)); } } } else { $t = $this->getTemplateName('index'); $vars['t'] = $t; } return $vars; } function parseEnvPart($mixed_part, $pass_name = 'passed') { // 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->Application->EventManager->setQueryMap($prefix_special); $vars = Array (); $vars[$pass_name] = implode(',', array_keys($this->Application->EventManager->queryMaps)); // 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 $vars; } /** * Removes tpl part from template name + resolved template ID to name * * @param string $t * @return string * @access private */ function getTemplateName($t) { if (isset($this->Get['t']) && $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'); } if (is_numeric($t)) { $sql = 'SELECT CONCAT(FilePath, \'/\', FileName) FROM '.TABLE_PREFIX.'ThemeFiles WHERE FileId = '.$t; $t = $this->Conn->GetOne($sql); } return preg_replace('/\.tpl$/', '', $t); } /** * Saves variables from array specified * into common variable storage place * * @param Array $array * @return Array * @access private */ function AddVars($array) { $array = $this->StripSlashes($array); foreach($array as $key => $value) { $this->Set($key,$value); } return $array; } 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)); } return $array; } function StripSlashes($array) { //if( !get_magic_quotes_gpc() ) return $array; foreach($array as $key=>$value) { if( is_array($value) ) { $array[$key] = $this->StripSlashes($value); } else { // $value = iconv('UTF-8', 'windows-1257', $value); if( get_magic_quotes_gpc() ) $value = stripslashes($value); if(!$this->Admin) $value = htmlspecialchars($value); $array[$key] = $value; } //$array[$key]=is_array($value)?$this->StripSlashes($value):stripslashes($value); } return $array; } /** * Returns all $_GET array excluding system parameters, that are not allowed to be passed through generated urls * * @return Array */ function getRedirectParams() { $unset_vars = Array(ENV_VAR_NAME, 'rewrite', '_mod_rw_url_', 'Action'); $ret = $this->Get; foreach ($unset_vars as $var_name) { if( isset($ret[$var_name]) ) unset( $ret[$var_name] ); } return $ret; } function writeRequestLog($filename) { $folder_path = dirname(FULL_PATH.'/'.$filename); if (is_writable($folder_path)) { $fp = fopen(FULL_PATH.'/'.$filename, 'a'); if ($fp) { $session =& $this->Application->recallObject('Session'); $user_id = $session->GetField('PortalUserId'); $admin_mark = $this->Application->IsAdmin() ? 'ADMIN' : 'FRONT'; $data = '['.date('D M d H:i:s Y').'] '.$admin_mark.'; ip: '.$_SERVER['REMOTE_ADDR'].'; user_id: '.$user_id.'; sid: '.$this->Application->GetSID().'; request: '."\n"; if ($this->Get) { $data .= "_GET:\n".print_r($this->Get, true); } if ($this->Post) { $data .= "_POST:\n".print_r($this->Post, true); } if ($this->Cookie) { $data .= "_COOKIE:\n".print_r($this->Cookie, true); } $data .= str_repeat('=', 100)."\n"; fwrite($fp, $data); fclose($fp); } else { trigger_error('Requrest Log directory not writable', E_USER_WARNING); } } else { trigger_error('Requrest Log directory not writable', E_USER_WARNING); } } } ?>