Example #1
0
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;
}
Example #2
0
function tep_get_infopages_tree($infopage_id)
{
    global $languages_id;
    $pages_array = array();
    $page_query = tep_db_query('SELECT i.parent_id, i.type, it.infopages_title, i.infopages_id FROM infopages i, infopages_text it WHERE i.infopages_id = it.infopages_id AND it.language_id = "' . (int) $languages_id . '" AND i.infopages_id = "' . $infopage_id . '"');
    if (tep_db_num_rows($page_query) > 0) {
        $page = tep_db_fetch_array($page_query);
        $pages_array[] = $page;
        if ($page['parent_id'] != '0') {
            $parent_tree = tep_get_infopages_tree($page['parent_id']);
            foreach ($parent_tree as $key => $value) {
                $pages_array[] = $value;
            }
        }
    }
    return $pages_array;
}