/** * Rebuilds $_GET array * Takes care of redirection if needed */ public function parseURL() { global $request_type; // get out if SSU is off or this is not an index.php page if (!SSUConfig::registry('configs', 'status') || end(explode('/', $_SERVER["SCRIPT_NAME"])) != 'index.php') { return false; } // remove the catalog dir from the link $catalog_dir = SSUConfig::registry('paths', 'catalog'); $regex = array('/' . str_replace('/', '\\/', $catalog_dir) . '/'); $this->original_uri = trim($catalog_dir == '/' ? $_SERVER['REQUEST_URI'] : preg_replace($regex, '', $_SERVER['REQUEST_URI'], 1), '/'); // if the index.php is in the url, lets see if we need to rebuild the path and redirect. if (strpos($this->original_uri, 'index.php') !== false) { if (!isset($_GET['main_page']) || empty($_GET['main_page'])) { $_GET['main_page'] = 'index'; $this->original_uri = $this->original_uri . '&main_page=index'; } if ($this->checkPageExcludedList($_GET['main_page'])) { return false; } $this->redirect_type = 2; return false; } // if we are using multi-lang, then we should have language code at the very beginning if (SSUConfig::registry('configs', 'multilang_status')) { $languages_code = substr($this->original_uri, 0, 2); if (!array_key_exists($languages_code, SSUConfig::registry('languages'))) { $this->redirect_type = 1; } else { $_get['language'] = $languages_code; $this->original_uri = trim(substr($this->original_uri, 2), '/'); } } if (empty($this->original_uri)) { $_get['main_page'] = 'index'; } else { // if we have a link like this http://site.com/en/?blah=blahblah, we assume it is an index page if (substr($this->original_uri, 0, 1) == '?') { parse_str(trim($this->original_uri, '?'), $_get); if (!isset($_get['main_page'])) { $_get['main_page'] = 'index'; } $this->rebuildENV($_get, $catalog_dir); $this->redirect_type = 1; return false; } $this->original_uri = str_replace(array('&', '&', '=', '?'), '/', $this->original_uri); // if we are using link alias, lets attempt to get the parsed content from cache if (SSUConfig::registry('configs', 'alias_status')) { $this->alias_filename = md5($_SERVER['REQUEST_URI']); if (($alias_get_array = SSUCache::read($this->alias_filename, 'aliases')) !== false) { parse_str($alias_get_array, $_get); $this->rebuildENV($_get, $catalog_dir); $this->redirect_type = 1; return true; } else { SSUAlias::aliasToLink($this->original_uri); } } // explode the params link into an array $parts = explode('/', preg_replace('/\\/\\/+/', '/', $this->original_uri)); // identify and assign main page if (!isset($_get['main_page'])) { $parsers = SSUConfig::registry('plugins', 'parsers'); foreach ($parsers as $key => $parser) { if (call_user_func_array(array("{$parser}Parser", "identifyPage"), array(&$parts, &$_get))) { unset($parsers[$key]); $this->redirect_type = 1; break; } } // found nothing? if (!isset($_get['main_page'])) { $_get['main_page'] = $parts[0]; unset($parts[0]); } } /* * This is where we loop thru the query parts and put things into their places * We need to do it this way because we want to keep the generated GET array in the correct order. */ $parts = array_values($parts); $parts_count = count($parts); for ($counter = 0; $counter < $parts_count; $counter++) { $parser_encountered = false; foreach ($parsers as $key => $parser) { if (call_user_func_array(array("{$parser}Parser", "identifyName"), array($parts[$counter]))) { call_user_func_array(array("{$parser}Parser", "updateGet"), array($parts[$counter], &$_get)); $this->redirect_type = 1; $parser_encountered = true; unset($parsers[$key]); break; } } if (!$parser_encountered) { $_get[$parts[$counter]] = isset($parts[$counter + 1]) ? $parts[++$counter] : ''; } } // remove extension, it's in the link just for show $extension = SSUConfig::registry('configs', 'extension'); if (!empty($extension)) { $_get['main_page'] = str_replace(".{$extension}", '', $_get['main_page']); } } $this->rebuildENV($_get, $catalog_dir); return true; }
/** * Rebuilds $_GET array * Takes care of redirection if needed */ public function parseURL() { global $request_type; $ssu_get = array(); // get out if SSU is off or this is not an index.php page if (!SSUConfig::registry('configs', 'status') || end(explode(DIRECTORY_SEPARATOR, $_SERVER["SCRIPT_FILENAME"])) != 'index.php') { return false; } // remove the catalog dir from the link $catalog_dir = SSUConfig::registry('paths', 'catalog'); $regex = array('/' . str_replace('/', '\\/', $catalog_dir) . '/'); $this->request_uri = urldecode($this->requestUri()); $this->original_uri = trim($catalog_dir == '/' ? $this->request_uri : preg_replace($regex, '', $this->request_uri, 1), '/'); // if the index.php is in the url, lets see if we need to rebuild the path and redirect. if (strpos($this->original_uri, 'index.php') !== false) { if (!isset($_GET['main_page']) || empty($_GET['main_page'])) { // we can redirect to the shop url without the index.php if ($request_type == 'SSL' && ENABLE_SSL == 'true') { $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG; } else { $link = HTTP_SERVER . DIR_WS_CATALOG; } $this->redirect($link); exit; } else { if ($this->checkPageExcludedList($_GET['main_page'])) { return false; } } $this->redirect_type = 2; return false; } // if we are using multi-lang, then we should have language code at the very beginning if (SSUConfig::registry('configs', 'multilang_status')) { $languages_code = current(explode('/', $this->original_uri, 2)); $is_languages_code = array_key_exists($languages_code, SSUConfig::registry('languages')); // if this is the default language, we may need redirection here if (SSUConfig::registry('configs', 'multilang_default_identifier')) { if ($languages_code == DEFAULT_LANGUAGE) { $this->redirect_type = 1; } elseif (!$is_languages_code) { $languages_code = DEFAULT_LANGUAGE; } elseif (strpos($current_page_url = $this->curPageURL(), "{$languages_code}/") === false) { $this->redirect($current_page_url . '/'); } } elseif (!$is_languages_code) { $languages_code = DEFAULT_LANGUAGE; $this->redirect_type = 1; } if ($is_languages_code) { $this->original_uri = trim(substr($this->original_uri, 2), '/'); } $ssu_get['language'] = $languages_code; } if (empty($this->original_uri)) { $ssu_get['main_page'] = 'index'; } else { // if we have a link like this http://site.com/en/?blah=blahblah, we assume it is an index page if (substr($this->original_uri, 0, 1) == '?') { parse_str(trim($this->original_uri, '?'), $temp_ssu_get); $ssu_get = array_merge($temp_ssu_get, $ssu_get); $this->rebuildENV($ssu_get, $catalog_dir); $this->redirect_type = 1; return false; } // if we are using link alias, lets attempt to get the parsed content from cache if (SSUConfig::registry('configs', 'alias_status')) { $uri_parts = explode('?', $this->original_uri); if (SSUAlias::linkToAlias($uri_parts[0]) > 0) { if ($request_type == 'SSL' && ENABLE_SSL == 'true') { $this->redirect(HTTPS_SERVER . DIR_WS_HTTPS_CATALOG . implode("&", $uri_parts)); } else { $this->redirect(HTTP_SERVER . DIR_WS_CATALOG . implode("&", $uri_parts)); } } else { SSUAlias::aliasToLink($uri_parts[0]); $this->original_uri = isset($uri_parts[1]) ? $uri_parts[0] . '?' . $uri_parts[1] : $uri_parts[0]; } } $this->original_uri = str_replace(array('&', '&', '=', '?'), '/', $this->original_uri); // explode the params link into an array $parts = explode('/', preg_replace('/\\/\\/+/', '/', $this->original_uri)); // identify and assign main page if (!isset($ssu_get['main_page'])) { $parsers = SSUConfig::registry('plugins', 'parsers'); foreach ($parsers as $key => $parser) { if (call_user_func_array(array("{$parser}Parser", "identifyPage"), array(&$parts, &$ssu_get))) { unset($parsers[$key]); $this->redirect_type = 1; break; } } // found nothing? if (!isset($ssu_get['main_page'])) { $ssu_get['main_page'] = $parts[0]; unset($parts[0]); } } /* * This is where we loop thru the query parts and put things into their places * We need to do it this way because we want to keep the generated GET array in the correct order. */ $parts = array_values($parts); $parts_count = count($parts); for ($counter = 0; $counter < $parts_count; $counter++) { $parser_encountered = false; foreach ($parsers as $key => $parser) { if (call_user_func_array(array("{$parser}Parser", "identifyName"), array($parts[$counter]))) { call_user_func_array(array("{$parser}Parser", "updateGet"), array($parts[$counter], &$ssu_get)); $this->redirect_type = 1; $parser_encountered = true; unset($parsers[$key]); break; } } if (!$parser_encountered) { $ssu_get[$parts[$counter]] = isset($parts[$counter + 1]) ? $parts[++$counter] : ''; } } // remove extension, it's in the link just for show $extension = SSUConfig::registry('configs', 'extension'); if (!empty($extension)) { $ssu_get['main_page'] = str_replace(".{$extension}", '', $ssu_get['main_page']); } } $this->rebuildENV($ssu_get, $catalog_dir); return true; }