Exemple #1
0
function checkCat($uri)
{
    require_once 'backend/model/Frontend.php';
    $model = new Fontend();
    $uri = str_replace("+", "", $uri);
    $p_detail = '#chi-tiet/[a-z0-9\\-\\+]+\\-\\d+.html#';
    $p_detail_news = '#tin-tuc/[a-z0-9\\-\\+]+\\-\\d+.html#';
    $p_cate_page = '#/[a-z0-9\\-\\+]+.html#';
    $p_product_detail = '#[a-z0-9\\-\\+]/[a-z0-9\\-\\+]/[a-z0-9\\-\\+]+.html#';
    $p_cate_news = '#danh-muc/[a-z0-9\\-\\+]+\\-\\d+.html#';
    $p_detail_event = '#su-kien/[a-z0-9\\-\\+]+\\-\\d+.html#';
    $p_tag = '#/tag/[a-z\\-]+.html#';
    $p_contact = '#/lien-he+.html#';
    $p_order = '#/quan-ly-don-hang+.html#';
    $p_orderdetail = '#/chi-tiet-don-hang+.html#';
    $p_info = '#/cap-nhat-thong-tin+.html#';
    $p_changepass = '******';
    $p_logout = '#/thoat+.html#';
    $p_hot = '#/[a-z0-9\\-]+\\-+c+\\d+h+\\d+.html#';
    $p_sale = '#/[a-z0-9\\-]+\\-+c+\\d+s+\\d+.html#';
    $p_cart = '#/gio-hang+.html#';
    $p_register = '#/dang-ky+.html#';
    $p_about = '#/gioi-thieu+.html#';
    $p_thanhtoan = '#/thanh-toan+.html#';
    $p_tintuc = '#/tin-tuc+.html#';
    $p_cate = '#/[a-z0-9\\-]+\\-+p+\\d+.html#';
    $p_content = '#/[a-z0-9\\-]+\\-+c+\\d+.html#';
    $p_search = '#/tim-kiem+.html#';
    $mod = $seo = "";
    $object_id = 0;
    $arrTmp = explode('/', $uri);
    if (count($arrTmp) == 4) {
        $mod = "detail";
    } elseif (strpos($uri, 'tin-tuc/')) {
        $mod = "detail-news";
    } elseif (strpos($uri, 'tim-kiem.')) {
        $mod = "search";
    } elseif (strpos($uri, 'dat-hang-thanh-cong.')) {
        $mod = "thanks";
    } elseif (strpos($uri, 'danh-muc/')) {
        $mod = "cate-news";
    } elseif (strpos($uri, 'dang-ky')) {
        $mod = "register";
        if (!empty($_SESSION['user'])) {
            $rel = isset($_GET['rel']) ? $_GET['rel'] : 'gio-hang';
            header('location:' . $rel . '.html');
        }
    } elseif (strpos($uri, 'cap-nhat-thong-tin')) {
        $mod = "info";
        if (empty($_SESSION['user'])) {
            header('location:dang-ky.html');
        }
    } elseif (strpos($uri, 'quan-ly-don-hang')) {
        $mod = "order";
        if (empty($_SESSION['user'])) {
            header('location:dang-ky.html');
        }
    } elseif (strpos($uri, 'chi-tiet-don-hang')) {
        $mod = "orderdetail";
        if (empty($_SESSION['user'])) {
            header('location:dang-ky.html');
        }
    } elseif (strpos($uri, 'doi-mat-khau')) {
        $mod = "changepass";
        $seo = $model->getDetailSeo(9);
        if (empty($_SESSION['user'])) {
            header('location:dang-ky.html');
        }
    } else {
        if (preg_match($p_product_detail, $uri)) {
            $mod = "product_detail";
        }
        if (preg_match($p_cart, $uri)) {
            $mod = "cart";
            if (empty($_SESSION['user'])) {
                //    header('location:dang-ky.html');
            }
        }
        if (preg_match($p_search, $uri)) {
            $mod = "search";
        }
        if (preg_match($p_cate_page, $uri)) {
            $uri = substr($uri, 1);
            $tmp = explode(".", $uri);
            if ($tmp[0] == "lien-he") {
                $mod = "contact";
            } elseif ($tmp[0] == "thanh-toan") {
                $mod = "thanhtoan";
            } elseif ($tmp[0] == "tin-tuc") {
                $mod = "news";
                $seo = $model->getDetailSeo(4);
            } else {
                $row = $model->getDetailAlias($tmp[0]);
                if ($row['type'] == 1) {
                    $mod = 'cate';
                } elseif ($row['type'] == 2) {
                    $mod = 'content';
                } elseif ($row['type'] == 3) {
                    $mod = 'catetype';
                }
                //$mod = $row['type'] == 1 ? "cate" : "content";
                $object_id = $row['object_id'];
            }
        }
        if (preg_match($p_about, $uri)) {
            $mod = "about";
            $seo = $model->getDetailSeo(2);
        }
        if (preg_match($p_thanhtoan, $uri)) {
            $mod = "thanhtoan";
            if (empty($_SESSION['user'])) {
                //    header('location:dang-ky.html');
            }
        }
        if (preg_match($p_detail_news, $uri)) {
            $mod = "detail-news";
        }
        if (preg_match($p_detail_event, $uri)) {
            $mod = "detail-event";
        }
        if (preg_match($p_tintuc, $uri)) {
            $mod = "news";
            $seo = $model->getDetailSeo(4);
        }
        if (preg_match($p_cate_news, $uri)) {
            $mod = "cate-news";
        }
        if (preg_match($p_cate, $uri)) {
            $mod = "cate";
        }
        if (preg_match($p_content, $uri)) {
            $mod = "content";
        }
        if (preg_match($p_hot, $uri) || preg_match($p_sale, $uri)) {
            $mod = "catetype";
        }
        if (preg_match($p_contact, $uri)) {
            $mod = "contact";
        }
        if (preg_match($p_logout, $uri)) {
            session_destroy();
            $mod = "";
            $seo = $model->getDetailSeo(1);
        }
    }
    return array("seo" => $seo, "mod" => $mod, 'object_id' => $object_id);
}