コード例 #1
0
ファイル: rewrite.php プロジェクト: CristianCCIT/shop4office
function seo_url_category($category_id = 0)
{
    global $cat_array, $languages_id, $breadcrumb, $request_type, $url_parts, $count_parts, $breadcrumb;
    if ($category_id > 0) {
        $new_cat_array = array();
        $new_cat_array[$category_id] = $cat_array[$category_id];
        $parent_id = $cat_array[$category_id]['parent'];
        while ($parent_id > 0) {
            $new_cat_array[$parent_id] = $cat_array[$parent_id];
            $parent_id = $cat_array[$parent_id]['parent'];
        }
        $cPath = '';
        $cat_array = array_reverse($new_cat_array, true);
        end($cat_array);
        $current_category_id = key($cat_array);
        reset($cat_array);
        foreach ($cat_array as $cat_id => $data) {
            $cPath .= $cat_id . '_';
            $breadcrumb->add($data['name'], tep_href_link('index.php', 'cPath=' . substr($cPath, 0, -1), $request_type, true, false));
        }
        $cPath = substr($cPath, 0, -1);
    } else {
        if (count($cat_array) != count($url_parts)) {
            if (count($cat_array) > count($url_parts)) {
                /********************************************************************/
                /*	There is a category name in the url that has multiple instances	*/
                /*	Remove the extra category by checking the parent ids			*/
                /********************************************************************/
                $rcat_array = array_reverse($cat_array, true);
                $new_cat_array = array();
                $count = 0;
                $parent_id = 0;
                if ($count_parts == 1) {
                    foreach ($rcat_array as $key => $value) {
                        if ($value['parent'] == '0') {
                            $new_cat_array[$key] = $value;
                        }
                    }
                } else {
                    foreach ($rcat_array as $key => $value) {
                        $count++;
                        if ($count == 1) {
                            $new_cat_array[$key] = $value;
                            $parent_id = $value['parent'];
                        } else {
                            if ($key == $parent_id) {
                                $new_cat_array[$key] = $value;
                                $parent_id = $value['parent'];
                            }
                        }
                    }
                }
                $cat_array = array_reverse($new_cat_array, true);
                end($cat_array);
                $current_category_id = key($cat_array);
                $cPath = '';
                reset($cat_array);
                foreach ($cat_array as $cat_id => $data) {
                    $cPath .= $cat_id . '_';
                    $breadcrumb->add($data['name'], tep_href_link('index.php', 'cPath=' . substr($cPath, 0, -1), $request_type, true, false));
                }
                $cPath = substr($cPath, 0, -1);
            } else {
                /************************************************************/
                /*	There is a category name in the url that doesn't exist	*/
                /*	Reverse array, to start with the lowest level			*/
                /************************************************************/
                $rcat_array = array_reverse($cat_array, true);
                $rurl_parts = array_reverse($url_parts, true);
                foreach ($rcat_array as $key => $value) {
                    if (in_array($value['uri_part'], $rurl_parts)) {
                        $lowest_cat_id = $key;
                        break;
                    }
                }
                /****************************************************/
                /*	tree structure of lowest level category found	*/
                /****************************************************/
                $cpath_data = array_reverse(tep_get_category_tree_db($lowest_cat_id, 'parents'));
                //function in includes/functions/seo.php
                $cPath = '';
                foreach ($cpath_data as $value) {
                    $cPath .= $value['categories_id'] . '_';
                }
                /********************************************/
                /*	Redirect to lowest level category found	*/
                /********************************************/
                header("HTTP/1.0 404 Not Found");
                header("Location: " . tep_href_link('index.php', 'cPath=' . substr($cPath, 0, -1), $request_type, true, false));
                exit;
            }
        } else {
            /********************/
            /*	All looks good	*/
            /********************/
            end($cat_array);
            $current_category_id = key($cat_array);
            $cPath = '';
            reset($cat_array);
            foreach ($cat_array as $cat_id => $data) {
                $cPath .= $cat_id . '_';
                $breadcrumb->add($data['name'], tep_href_link('index.php', 'cPath=' . substr($cPath, 0, -1), $request_type, true, false));
            }
            $cPath = substr($cPath, 0, -1);
        }
    }
    $parameters = array();
    $dirname = dirname($_SERVER['PHP_SELF']);
    if (substr($dirname, -1) != '/' && strlen($dirname) > 0) {
        $dirname .= '/';
    }
    $parameters['_SERVER'] = array('PHP_SELF' => $dirname . 'index.php');
    $parameters['_GET'] = array('cPath' => $cPath);
    $parameters['page'] = 'index.php';
    $parameters['variables'] = array('current_category_id' => $current_category_id, 'cPath' => $cPath);
    return $parameters;
}
コード例 #2
0
ファイル: seo.php プロジェクト: CristianCCIT/shop4office
function tep_get_category_tree_db($category_id, $type)
{
    global $languages_id;
    $categories = array();
    if ($type == 'parents') {
        $parent_query = tep_db_query('SELECT cd.categories_name, cd.categories_id, c.parent_id FROM categories c, categories_description cd WHERE c.categories_id = cd.categories_id AND cd.language_id = "' . (int) $languages_id . '" AND c.categories_id = "' . $category_id . '"');
        while ($parent = tep_db_fetch_array($parent_query)) {
            $categories[] = array('categories_name' => $parent['categories_name'], 'parent_id' => $parent['parent_id'], 'categories_id' => $parent['categories_id']);
            if ($parent['parent_id'] != '0') {
                $parent_categorie = tep_get_category_tree_db($parent['parent_id'], $type);
                foreach ($parent_categorie as $key => $value) {
                    $categories[] = array('categories_name' => $value['categories_name'], 'parent_id' => $value['parent_id'], 'categories_id' => $value['categories_id']);
                }
            }
        }
    }
    return $categories;
}