function prepareHtaccessCode($arr_err_code) { global $application; loadCoreFile('URI.class.php'); $uriObj = new URI($application->getAppIni('HTTP_URL')); $url_dir = $uriObj->getPart('dir') . (_ml_substr($uriObj->getPart('dir'), -1) != '/' ? '/' : ''); $hta_content = ERRDOC_BLOCK_IDENT_BEGIN . "\n"; /* ignore list htaccess code - starts */ $hta_content .= str_replace('%files_to_ignore%', FILES_TO_IGNORE, file_get_contents(dirname(__FILE__) . '/includes/errdoc_ignore_list_block_first_strings')); foreach ($arr_err_code as $error_code => $error_page) { $hta_content .= str_replace('%error_code%', $error_code, file_get_contents(dirname(__FILE__) . '/includes/errdoc_block_for_ignore_list')); } $hta_content .= file_get_contents(dirname(__FILE__) . '/includes/errdoc_ignore_list_block_last_strings'); /* ignore list htaccess code - ends */ foreach ($arr_err_code as $error_code => $error_page) { $hta_content .= str_replace(array('%error_code%', '%url_dir%', '%error_code_file%'), array($error_code, $url_dir, $error_page), file_get_contents(dirname(__FILE__) . '/includes/errdoc_block_for_all_files')); } $hta_content .= ERRDOC_BLOCK_IDENT_END; return $hta_content; }
/** * URL URL * mod_rewrite * @param string $url - URL * @return string - URL */ function encodeURL($url) { global $application; if ($application->row_layout_ini_array === null) { return $url; } $row_layout_ini_array = $application->row_layout_ini_array; loadCoreFile('URI.class.php'); $uriObj = new URI($url); if ($uriObj->getPart('scheme') == 'http://') { $r_string = str_replace($row_layout_ini_array['Site']['SiteURL'], '', $url); } elseif ($uriObj->getPart('scheme') == 'https://') { $r_string = str_replace($row_layout_ini_array['Site']['SiteHTTPSURL'], '', $url); } else { return $url; } $rel_script_path = str_replace($uriObj->getPart('query'), '', $r_string); $query_string = str_replace('?', '', $uriObj->getPart('query')); if (strstr($query_string, 'asc_action=SetCurrentProduct') !== false) { # URL . preg_match("/prod_id=(\\d+)/i", $query_string, $matches); $product_id = $matches[1]; # ProductInfo $founded_keys = array(); foreach ($row_layout_ini_array['ProductInfo'] as $layout_key => $layout_script) { if ($layout_script == $rel_script_path) { $founded_keys[] = $layout_key; } } $prodObj =& $application->getInstance('CProductInfo', $product_id); $seo_html_name = $prodObj->getProductTagValue('SEOPrefix'); if ($seo_html_name == '' or $seo_html_name == null) { $seo_html_name = 'info'; //: move to config } $encode_rule = array('type' => 'default', 'prod_id' => $product_id, 'cat_id' => null); # 1. Products {x} foreach ($founded_keys as $lkey) { if (preg_match("/^products/i", $lkey)) { $encode_rule['type'] = 'product'; break; } } # 2. Categories {x} if ($encode_rule['type'] == 'default') { $choosen_cat = $prodObj->chooseCategoryID(); reset($founded_keys); $parent_cat = null; foreach ($founded_keys as $lkey) { if (preg_match("/^categories\\s*\\{([0-9\\,\\+]+)\\}/i", $lkey, $matches)) { $row_cats_ids = array_map("trim", explode(",", $matches[1])); if (in_array($choosen_cat, $row_cats_ids)) { $encode_rule['type'] = 'category'; $encode_rule['cat_id'] = $choosen_cat; break; } else { foreach ($row_cats_ids as $cat_id_str) { if (strstr($cat_id_str, '+') !== false) { $parent_cat = str_replace('+', '', $cat_id_str); if ($parent_cat == $choosen_cat) { $encode_rule['type'] = 'category'; $encode_rule['cate_id'] = $cat_id_str; break; } $parent_cat = $cat_id_str; } } } } } if ($encode_rule['type'] == 'default' and $parent_cat !== null) { $encode_rule['type'] = 'category'; $encode_rule['cat_id'] = $parent_cat; } } # URL $encoded_url = ''; if ($uriObj->getPart('scheme') == 'https://') { $encoded_url .= $row_layout_ini_array['Site']['SiteHTTPSURL']; } else { $encoded_url .= $row_layout_ini_array['Site']['SiteURL']; } switch ($encode_rule['type']) { case 'category': $encoded_url .= str_replace(array('%product_id%', '%parent_cid%', '%query_prod_prefix%', '%seo_prod_prefix%'), array($encode_rule['prod_id'], '-' . $encode_rule['cat_id'], $this->queries_prefixes['product'], $seo_html_name), $this->encode_scheme['product']); # . //$encoded_url .= $this->queries_prefixes['product'].'/'.$encode_rule['prod_id'].'/'.$encode_rule['cat_id'].'/'.$seo_html_name.'.html'; break; case 'product': case 'default': $encoded_url .= str_replace(array('%product_id%', '%parent_cid%', '%query_prod_prefix%', '%seo_prod_prefix%'), array($encode_rule['prod_id'], '', $this->queries_prefixes['product'], $seo_html_name), $this->encode_scheme['product']); # . //$encoded_url .= $this->queries_prefixes['product'].'/'.$encode_rule['prod_id'].'/'.$seo_html_name.'.html'; break; } return $encoded_url; } if (strstr($query_string, 'asc_action=SetCurrCat') !== false or strstr($query_string, 'asc_action=Paginator_SetPage&pgname=Catalog_ProdsList_') !== false) { # URL if (preg_match("/category_id=(\\d+)/i", $query_string, $matches)) { $category_id = $matches[1]; $page_number = 1; } else { preg_match("/pgname=Catalog_ProdsList_(\\d+)&pgnum=(\\d+)/i", $query_string, $matches); $category_id = $matches[1]; $page_number = $matches[2]; } $catObj =& $application->getInstance('CCategoryInfo', $category_id); $seo_html_name = $catObj->getCategoryTagValue('seo_url_prefix'); if ($seo_html_name === null or $seo_html_name == '') { $seo_html_name = 'info'; } # ProductList $founded_keys = array(); foreach ($row_layout_ini_array['ProductList'] as $layout_key => $layout_script) { if ($layout_script == $rel_script_path) { $founded_keys[] = $layout_key; } } $encode_rule = array('type' => 'default', 'cat_id' => $category_id, 'parent_cat_id' => null); $category_parents = modApiFunc('Catalog', 'getCategoryFullPathAsCategoriesIDs', $category_id, false); # Categories {x} foreach ($founded_keys as $lkey) { if (preg_match("/^categories\\s*\\{([0-9\\,\\+]+)\\}/i", $lkey, $matches)) { $row_cats_ids = array_map("trim", explode(",", $matches[1])); if (in_array($category_id, $row_cats_ids) or in_array($category_id . '+', $row_cats_ids)) { $encode_rule['type'] = 'category'; break; } $parent_ids = array(); foreach ($row_cats_ids as $parent_id) { if (strstr($parent_id, '+')) { $parent_ids[] = str_replace('+', '', $parent_id); } } # ID+ ID if (!empty($parent_ids) and !empty($category_parents)) { foreach ($category_parents as $cpid) { if (in_array($cpid, $parent_ids)) { $encode_rule['type'] = 'parent'; $encode_rule['parent_cat_id'] = $cpid . '+'; break; } } } # , if ($encode_rule['parent_cat_id'] !== null) { break; } } } # URL $encoded_url = ''; if ($uriObj->getPart('scheme') == 'https://') { $encoded_url .= $row_layout_ini_array['Site']['SiteHTTPSURL']; } else { $encoded_url .= $row_layout_ini_array['Site']['SiteURL']; } switch ($encode_rule['type']) { case 'parent': $encoded_url .= str_replace(array('%category_id%', '%page_number%', '%parent_cid%', '%query_cat_prefix%', '%seo_cat_prefix%'), array($encode_rule['cat_id'], $page_number, '-' . $encode_rule['parent_cat_id'], $this->queries_prefixes['category'], $seo_html_name), $this->encode_scheme['category']); # . //$encoded_url .= $this->queries_prefixes['category'].'/'.$encode_rule['cat_id'].'/'.$page_number.'/'.$encode_rule['parent_cat_id'].'/'.$seo_html_name.'.html'; break; case 'category': case 'default': $encoded_url .= str_replace(array('%category_id%', '%page_number%', '%parent_cid%', '%query_cat_prefix%', '%seo_cat_prefix%'), array($encode_rule['cat_id'], $page_number, '', $this->queries_prefixes['category'], $seo_html_name), $this->encode_scheme['category']); # . //$encoded_url .= $this->queries_prefixes['category'].'/'.$encode_rule['cat_id'].'/'.$page_number.'/'.$seo_html_name.'.html'; break; } return $encoded_url; } if (strstr($query_string, 'page_id=') !== false) { # URL . preg_match("/page_id=(\\d+)/i", $query_string, $matches); $page_id = $matches[1]; # CMSPage $founded_keys = array(); foreach ($row_layout_ini_array['CMSPage'] as $layout_key => $layout_script) { if ($layout_script == $rel_script_path) { $founded_keys[] = $layout_key; } } $cmsObj =& $application->getInstance('CCMSPageInfo', $page_id); $seo_html_name = $cmsObj->getCMSPageTagValue('prefix', array()); if ($seo_html_name == '' or $seo_html_name == null) { $seo_html_name = 'info'; //: move to config } $encode_rule = array('type' => 'default', 'page_id' => $page_id); # URL $encoded_url = ''; if ($uriObj->getPart('scheme') == 'https://') { $encoded_url .= $row_layout_ini_array['Site']['SiteHTTPSURL']; } else { $encoded_url .= $row_layout_ini_array['Site']['SiteURL']; } switch ($encode_rule['type']) { case 'default': $encoded_url .= str_replace(array('%page_id%', '%query_cms_prefix%', '%seo_cms_prefix%'), array($encode_rule['page_id'], $this->queries_prefixes['cmspage'], $seo_html_name), $this->encode_scheme['cmspage']); # . //$encoded_url .= $this->queries_prefixes['product'].'/'.$encode_rule['prod_id'].'/'.$seo_html_name.'.html'; break; } return $encoded_url; } # , URL . return $url; }
/** * Sets the request URL. * * @param $url URL */ function setURL($url) { loadCoreFile('URI.class.php'); $_uri = new URI($url); $this->proto = _ml_strtoupper(str_replace('://', '', $_uri->getPart('scheme'))); $this->host = $_uri->getPart("host"); $this->port = $_uri->getPart("port"); $this->url = $this->__urlencode($_uri->getPart("path")) . $_uri->getPart("query"); }