} public function getParentCategoryIdFromId($category_id){ $cat_query = $this->db->query("SELECT path_id FROM " . DB_PREFIX . "category_path WHERE category_id = '" . $category_id . "' AND level = (select level from " . DB_PREFIX . "category_path where category_id = path_id AND category_id='".$category_id."') -1 "); if($cat_query->num_rows){ return $cat_query->row['path_id']; }else{ return false; } } public function setSeoLink($key = 'alias') { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_alias WHERE status = '1' ORDER BY priority ASC"); $ali = array(); foreach ($query->rows as $res) { if (!in_array($res['url'], $ali) || $key == 'alias') { $ali[$res['alias']] = $res['url']; } } if ($key != 'alias') { $ali = array_flip($ali); } return $ali; } public function rewrite($link) { $url_info = parse_url(str_replace('&', '&', $link)); $url = ''; $data = array(); $route = str_replace(str_replace('/index.php', '', $_SERVER['PHP_SELF']), '', $url_info['path']); if (trim($route, '/')) $url_info['query'] = 'route=' . trim($route, '/') . (isset($url_info['query'])? '&' . $url_info['query']:''); $url_info['path'] = $_SERVER['PHP_SELF']; if (isset($url_info['query'])) parse_str($url_info['query'], $data); $link_rel = $this->setSeoLink('url'); foreach ($data as $key => $value) { if (isset($data['route']) && isset($link_rel[$data['route']])) { $url .= '/' . $link_rel[$data['route']]; unset($data[$key]); }else if($key == 'project_id' || $key == 'news_id'){ $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int) $value) . "'"); if ($query->num_rows) { $url .= '/' . $query->row['keyword']; unset($data[$key]); } }else if (isset($data['route'])) { if (($data['route'] == 'product/product' && $key == 'product_id') || (($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') || ( ($data['route'] == 'information/information' || $data['route'] == 'information/information/info') && $key == 'information_id')) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = '" . $this->db->escape($key . '=' . (int)$value) . "'"); if ($query->num_rows) { if(($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id'){ $url .= '/manufacturer'; } $url .= '/' . $query->row['keyword'] . (isset($data['route']) && $data['route'] == 'information/information/info'? "/info":""); unset($data[$key]); } }elseif ($key == 'path') { $categories = explode('_', $value); $url .= '/category'; foreach ($categories as $category) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int) $category . "'"); if ($query->num_rows) { $url .= '/' . $query->row['keyword']; }else{ $url = ''; break; } } unset($data[$key]); } elseif ($key == 'path') { $categories = explode('_', $value); foreach ($categories as $category) { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE `query` = 'category_id=" . (int)$category . "'"); if ($query->num_rows) { $url .= '/' . $query->row['keyword']; } } unset($data[$key]); } } } if ($url) { unset($data['route']); $query = ''; if ($data) { foreach ($data as $key => $value) { $query .= '&' . $key . '=' . $value; } if ($query) { $query = '?' . trim($query, '&'); } } return $url_info['scheme'] . '://' . $url_info['host'] . (isset($url_info['port']) ? ':' . $url_info['port'] : '') . str_replace('/index.php', '', $url_info['path']) . $url . $query; } else { return $link; } } } ?>