function seo_url_infopage($infopage_id = 0) { global $page_array, $languages_id, $breadcrumb, $request_type, $url_parts, $count_parts; if ($infopage_id > 0) { $new_page_array = array(); $new_page_array[$infopage_id] = $page_array[$infopage_id]; $parent_id = $page_array[$infopage_id]['parent']; while ($parent_id > 0) { $new_page_array[$parent_id] = $page_array[$parent_id]; $parent_id = $page_array[$parent_id]['parent']; } $page_array = array_reverse($new_page_array, true); end($page_array); reset($page_array); foreach ($page_array as $page_id => $data) { $breadcrumb->add($data['name'], tep_href_link('infopage.php', 'page=' . $page_id, $request_type, true, false)); $page = $page_id; } } else { end($page_array); $nav_path = tep_get_navigation_tree($languages_id, 'i_' . key($page_array), ''); if (count($nav_path) > 0) { $cpath_array = array(); /********************************************************/ /* In navigation => this one has priority */ /* If the pages are in the navigation, */ /* You're sure the site owner wants it to be visible */ /********************************************************/ if (count($nav_path) > 1) { /********************************************************/ /* This page is more then once used in the navigation */ /********************************************************/ /****************************************************/ /* check wich database cPath is equal to url cPath */ /****************************************************/ $check_cPath_array = array(); foreach ($nav_path as $nav_id => $value) { foreach ($value as $key => $data) { foreach ($page_array as $page_id => $page_data) { if ($data['id'] == $page_id) { $check_cPath_array[$nav_id][] = $data; } } } } /************************************************************/ /* work with the tree that fits the most in the url tree */ /************************************************************/ $biggest_tree_count = 0; $biggest_tree = ''; foreach ($check_cPath_array as $nav_id => $tree) { if (count($tree) > $biggest_tree_count) { $biggest_tree_count = count($tree); $biggest_tree = $nav_id; } } $check_cPath_array = $check_cPath_array[$biggest_tree]; $page_tree = array_reverse($nav_path[$biggest_tree]); } else { /********************************************************/ /* This page is only one time used in the navigation */ /********************************************************/ $page_tree = array_reverse($nav_path[key($nav_path)]); } if (count($page_tree) == $count_parts) { foreach ($page_tree as $page_info) { $breadcrumb->add($page_info['name'], tep_href_link('infopage.php', 'page=' . $page_info['id'], $request_type, true, false)); $page = $page_info['id']; } } else { end($page_array); header("HTTP/1.1 301 Moved Permanently"); header("Location: " . tep_href_link('infopage.php', 'page=' . key($page_array), $request_type, true, false)); exit; } } else { /********************************************/ /* This page is not used in the navigation */ /* next we filter out the last page => the */ /* one that isn't a parent */ /********************************************/ $last_page_array = $page_array; $new_page_array = array(); foreach ($last_page_array as $key => $value) { foreach ($page_array as $cat_id => $cat_data) { if ($key == $cat_data['parent']) { $new_page_array[$key] = $value; unset($last_page_array[$key]); break; } } } /********************************************/ /* check if we have the right page array */ /********************************************/ if (count($new_page_array) == count($url_parts)) { $page_array = $new_page_array; } else { /********************/ /* page(s) missing */ /********************/ $missing = count($url_parts) - count($new_page_array); $rurl_parts = array_reverse($url_parts); $missing_items = array(); for ($x = 0; $x < $missing; $x++) { $missing_items[] = trim(decodeUrlPart($rurl_parts[$x])); //function in includes/functions/seo.php } foreach ($missing_items as $title) { foreach ($last_page_array as $key => $value) { if (!in_array($title, $value)) { unset($last_page_array[$key]); } } } /********************************************/ /* add the last page to the new page array */ /********************************************/ foreach ($last_page_array as $key => $value) { $new_page_array[$key] = $value; } $final_page_array = array(); if (count($new_page_array) > count($url_parts)) { $count_array_item = 0; foreach ($new_page_array as $key => $value) { $count_array_item++; if ($count_array_item > count($url_parts)) { unset($new_page_array[$key]); } } } $page_array = $new_page_array; } /****************************/ /* set to last array key */ /****************************/ end($page_array); $page_tree = tep_get_infopages_tree(key($page_array)); //function in includes/functions/seo.php if (count($page_tree) == count($page_array)) { $rpage_tree = array_reverse($page_tree); foreach ($rpage_tree as $page_info) { $breadcrumb->add($page_info['infopages_title'], tep_href_link('infopage.php', 'page=' . $page_info['infopages_id'], $request_type, true, false)); $page = $page_info['infopages_id']; } } else { if (count($page_tree) < count($page_array)) { $rpage_tree = array_reverse($page_tree); foreach ($rpage_tree as $page_info) { $breadcrumb->add($page_info['infopages_title'], tep_href_link('infopage.php', 'page=' . $page_info['infopages_id'], $request_type, true, false)); $page = $page_info['infopages_id']; } } else { reset($page_tree); header("HTTP/1.1 301 Moved Permanently"); header("Location: " . tep_href_link('infopage.php', 'page=' . $page_tree[key($page_tree)]['infopages_id'], $request_type, true, false)); exit; } } } } $parameters = array(); $dirname = dirname($_SERVER['PHP_SELF']); if (substr($dirname, -1) != '/' && strlen($dirname) > 0) { $dirname .= '/'; } $parameters['_SERVER'] = array('PHP_SELF' => $dirname . '/infopage.php'); $parameters['_GET'] = array('page' => $page); $parameters['page'] = 'infopage.php'; return $parameters; }
function tep_get_navigation_tree($languages_id, $link = '', $custom = '') { $nav_array = array(); if ($link != '') { $nav_query = tep_db_query('SELECT id, parent_id FROM navigatie WHERE link = "' . $link . '" AND status = 1'); $item_id = explode('_', $link); while ($nav = tep_db_fetch_array($nav_query)) { if (preg_match('/^([i]{1})+([_]{1})+([0-9]+$)/i', $link)) { //infopage $page_query = tep_db_query('SELECT infopages_id, infopages_title FROM infopages_text WHERE language_id = "' . (int) $languages_id . '" AND infopages_id = "' . $item_id[1] . '"'); $infopage = tep_db_fetch_array($page_query); $nav_array[$nav['id']][] = array('name' => $infopage['infopages_title'], 'type' => 'infopage', 'id' => $infopage['infopages_id'], 'page' => 'infopage.php', 'get_param' => 'page=' . $infopage['infopages_id']); } else { if (preg_match('/^([c]{1})+([_]{1})+([0-9]+$)/i', $nav_item['link'])) { //category $cat_query = tep_db_query('SELECT categories_id, categories_name FROM categories_description WHERE language_id = "' . (int) $languages_id . '" AND categories_id = "' . $item_id[1] . '"'); $category = tep_db_fetch_array($cat_query); $nav_array[$nav['id']][] = array('name' => $category['categories_name'], 'type' => 'category', 'id' => $category['categories_id'], 'page' => 'index.php', 'get_param' => 'cPath=' . $category['categories_id']); } else { if (preg_match('/^([p]{1})+([_]{1})+([0-9]+$)/i', $nav_item['link'])) { //product $prod_query = tep_db_query('SELECT products_name, products_id FROM products_description WHERE language_id = "' . (int) $languages_id . '" AND products_id = "' . $item_id[1] . '"'); $product = tep_db_fetch_array($prod_query); $nav_array[$nav['id']][] = array('name' => $product['products_name'], 'type' => 'infopage', 'id' => $product['products_id'], 'page' => 'product_info.php', 'get_param' => 'products_id=' . $product['products_id']); } } } if ($nav['parent_id'] != 0) { $parent_query = tep_db_query('SELECT link, custom FROM navigatie WHERE id = "' . $nav['parent_id'] . '"'); if (tep_db_num_rows($parent_query) > 0) { $parent = tep_db_fetch_array($parent_query); $parent_array = tep_get_navigation_tree($languages_id, $parent['link'], $parent['custom']); foreach ($parent_array as $nav_id => $nav_data) { foreach ($nav_data as $key => $value) { $nav_array[$nav['id']][] = $value; } } } } } } else { if ($custom != '') { $nav_query = tep_db_query('SELECT id, parent_id, name FROM navigatie WHERE custom = "' . $custom . '" AND status = 1'); while ($nav = tep_db_fetch_array($nav_query)) { $nav_array[$nav['id']][] = array('name' => $nav['name'], 'type' => 'custom', 'id' => '', 'page' => $custom, 'get_params' => ''); if ($nav['parent_id'] != 0) { $parent_query = tep_db_query('SELECT link, custom FROM navigatie WHERE id = "' . $nav['parent_id'] . '"'); if (tep_db_num_rows($parent_query) > 0) { $parent = tep_db_fetch_array($parent_query); $parent_array = tep_get_navigation_tree($languages_id, $parent['link'], $parent['custom']); foreach ($parent_array as $nav_id => $nav_data) { foreach ($nav_data as $key => $value) { $nav_array[$nav['id']][] = $value; } } } } } } } return $nav_array; }