コード例 #1
0
ファイル: ThemeUrl.cs プロジェクト: zwkjgs/LebiShop
        /// <summary>
        /// 生成地址重写规则
        /// </summary>
        public static void CreateURLRewrite()
        {
            StringBuilder sb  = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();

            sb.AppendLine("[ISAPI_Rewrite]");
            sb1.AppendLine("RewriteEngine On");
            sb1.AppendLine("RewriteCompatibility2 On");
            sb1.AppendLine("RepeatLimit 200");
            sb1.AppendLine("RewriteBase");

            List <Lebi_Language>   langs  = B_Lebi_Language.GetList("", "Sort desc,id asc");
            List <Lebi_Theme_Page> models = B_Lebi_Theme_Page.GetList("Type_id_PublishType=123", "");
            string str1     = "";
            string str2     = "";
            string language = "";

            foreach (Lebi_Theme_Page model in models)
            {
                if (model.PageParameter == "")
                {
                    str1 = model.PageName;
                    str2 = model.StaticPath + "/" + model.StaticPageName;
                    str2 = ThemeUrl.CheckURL(str2);
                    str1 = str1.Trim('/');
                    str2 = str2.Trim('/');
                    str1 = str1.Replace(".", @"\.");
                    str2 = str2.Replace(".", @"\.");
                    foreach (Lebi_Language lang in langs)
                    {
                        Lebi_Site site = B_Lebi_Site.GetModel(lang.Site_id);
                        if (site == null)
                        {
                            site = new Lebi_Site();
                        }
                        language = site.Path + lang.Path.TrimEnd('/');
                        language = language.Replace("//", "/");
                        if (language == "")
                        {
                            continue;
                        }
                        sb.AppendLine(@"RewriteRule /(.*)" + language + "/" + str2 + "(.*) /$1" + language + "/" + str1 + " [N,I]");
                        sb1.AppendLine(@"RewriteRule " + language + "/" + str2 + "(.*)$ " + language + "/" + str1 + " [NC,N]");
                    }
                    sb.AppendLine(@"RewriteRule /(.*)" + str2 + "(.*) /$1" + str1 + " [N,I]");
                    sb1.AppendLine(@"RewriteRule /" + str2 + "(.*)$ /" + str1 + " [NC,N]");
                    //RewriteRule /CN/(.*)$ /CN/Basket\.aspx\?Basket\.html$1 [NC,N]
                    //RewriteRule /(.*)$ /Basket\.aspx\?Basket\.html$1 [NC,N]
                }
                else
                {
                    str1 = model.PageName + @"\?" + model.PageParameter;
                    str2 = model.StaticPath + "/" + model.StaticPageName;
                    str2 = ThemeUrl.CheckURL(str2);
                    str1 = str1.Trim('/');
                    str2 = str2.Trim('/');
                    str1 = str1.Replace(".", @"\.");
                    str2 = str2.Replace(".", @"\.");
                    str1 = RegexTool.ReplaceRegValue(str1, @"{\d+}", ",");
                    str2 = RegexTool.ReplaceRegValue(str2, @"{\d+}", "(.*)");
                    string[] arr     = str1.Split(',');
                    int      j       = 1;
                    string   str_ini = "";
                    string   str_hta = "";
                    foreach (string ar in arr)
                    {
                        if (ar != "")
                        {
                            str_hta += ar + "$" + j;
                        }
                        j++;
                        if (ar != "")
                        {
                            str_ini += ar + "$" + j;
                        }
                    }
                    foreach (Lebi_Language lang in langs)
                    {
                        Lebi_Site site = B_Lebi_Site.GetModel(lang.Site_id);
                        if (site == null)
                        {
                            site = new Lebi_Site();
                        }
                        language = site.Path + lang.Path.TrimEnd('/');
                        language = language.Replace("//", "/");
                        if (language == "")
                        {
                            continue;
                        }
                        sb.AppendLine(@"RewriteRule /(.*)" + language + "/" + str2 + "(.*) /$1" + language + "/" + str_ini + " [N,I]");
                        sb1.AppendLine(@"RewriteRule " + language + "/" + str2 + "(.*)$ " + language + "/" + str_hta + " [NC,N]");
                    }
                    sb.AppendLine(@"RewriteRule /(.*)" + str2 + "(.*) /$1" + str_ini + " [N,I]");
                    sb1.AppendLine(@"RewriteRule /" + str2 + "(.*)$ /" + str_hta + " [NC,N]");
                }
            }
            //生成商品分类重写规则
            List <Lebi_Pro_Type> tps   = B_Lebi_Pro_Type.GetList("", "");
            Lebi_Theme_Page      tpage = B_Lebi_Theme_Page.GetModel("Code='P_ProductCategory'");

            str1 = tpage.PageName + @"\?" + tpage.PageParameter;
            str1 = str1.Trim('/');
            str1 = str1.Replace(".", @"\.");
            str1 = RegexTool.ReplaceRegValue(str1, @"{\d+}", ",");
            string[] arr1     = str1.Split(',');
            string   str_ini1 = "";
            string   str_hta1 = "";

            //foreach (string ar in arr1)
            //{
            //    if (ar != "")
            //        str_hta1 += ar + "$" + j1;
            //    j1++;
            //    if (ar != "")
            //        str_ini1 += ar + "$" + j1;

            //}

            foreach (Lebi_Pro_Type tp in tps)
            {
                str_hta1 = arr1[0] + tp.id;
                str_ini1 = arr1[0] + tp.id;
                foreach (Lebi_Language lang in langs)
                {
                    if (Language.Content(tp.IsUrlrewrite, lang.Code) != "1")
                    {
                        continue;
                    }
                    str2 = Language.Content(tp.Url, lang.Code);
                    if (str2 == "")
                    {
                        continue;
                    }



                    str2 = ThemeUrl.CheckURL(str2);
                    str2 = str2.Trim('/');
                    str2 = str2.Replace(".", @"\.");
                    str2 = RegexTool.ReplaceRegValue(str2, @"{\d+}", "(.*)");


                    Lebi_Site site = B_Lebi_Site.GetModel(lang.Site_id);
                    if (site == null)
                    {
                        site = new Lebi_Site();
                    }
                    language = site.Path + lang.Path.TrimEnd('/');
                    language = language.Replace("//", "/");
                    language = language.TrimEnd('/');
                    sb.AppendLine(@"RewriteRule /(.*)" + language + "/" + str2 + "(.*) /$1" + language + "/" + str_ini1 + " [N,I]");
                    sb1.AppendLine(@"RewriteRule /(.*)" + language + "/" + str2 + "(.*)$ /$1" + language + "/" + str_hta1 + " [NC,N]");
                }
            }
            HtmlEngine save = new HtmlEngine();

            save.CreateFile("httpd.ini", sb.ToString(), "ascii");
            save.CreateFile(".htaccess", sb1.ToString(), "ascii");
            CreateURLRewrite_shop();
        }
コード例 #2
0
        /// <summary>
        /// 根据主题重新设置系统图片尺寸
        /// </summary>
        public static void UpdteImageSize()
        {
            BaseConfig           mx    = ShopCache.GetBaseConfig();
            List <Lebi_Language> langs = B_Lebi_Language.GetList("", "");
            Lebi_ImageSize       model;

            string ids = "0";

            //检查系统默认的规格
            model = B_Lebi_ImageSize.GetModel("Width=" + mx.ImageBigWidth + " and Height=" + mx.ImageBigHeight + "");
            if (model == null)
            {
                model        = new Lebi_ImageSize();
                model.Width  = mx.ImageBigWidth;
                model.Height = mx.ImageBigHeight;
                B_Lebi_ImageSize.Add(model);
                ids += "," + B_Lebi_ImageSize.GetMaxId();
            }
            else
            {
                ids += "," + model.id;
            }
            model = B_Lebi_ImageSize.GetModel("Width=" + mx.ImageMediumWidth + " and Height=" + mx.ImageMediumHeight + "");
            if (model == null)
            {
                model        = new Lebi_ImageSize();
                model.Width  = mx.ImageMediumWidth;
                model.Height = mx.ImageMediumHeight;
                B_Lebi_ImageSize.Add(model);
                ids += "," + B_Lebi_ImageSize.GetMaxId();
            }
            else
            {
                ids += "," + model.id;
            }
            model = B_Lebi_ImageSize.GetModel("Width=" + mx.ImageSmallWidth + " and Height=" + mx.ImageSmallHeight + "");
            if (model == null)
            {
                model        = new Lebi_ImageSize();
                model.Width  = mx.ImageSmallWidth;
                model.Height = mx.ImageSmallHeight;
                B_Lebi_ImageSize.Add(model);
                ids += "," + B_Lebi_ImageSize.GetMaxId();
            }
            else
            {
                ids += "," + model.id;
            }
            foreach (Lebi_Language lang in langs)
            {
                Lebi_Theme theme = B_Lebi_Theme.GetModel(lang.Theme_id);
                if (theme == null)
                {
                    continue;
                }
                //model = B_Lebi_ImageSize.GetModel("Width=" + theme.ImageBig_Width + " and Height=" + theme.ImageBig_Height + "");
                //if (model == null)
                //{
                //    model = new Lebi_ImageSize();
                //    model.Width = theme.ImageBig_Width;
                //    model.Height = theme.ImageBig_Height;
                //    B_Lebi_ImageSize.Add(model);
                //    ids += "," + B_Lebi_ImageSize.GetMaxId();
                //}
                //else
                //{
                //    ids += "," + model.id;
                //}
                model = B_Lebi_ImageSize.GetModel("Width=" + theme.ImageMedium_Width + " and Height=" + theme.ImageMedium_Height + "");
                if (model == null)
                {
                    model        = new Lebi_ImageSize();
                    model.Width  = theme.ImageMedium_Width;
                    model.Height = theme.ImageMedium_Height;
                    B_Lebi_ImageSize.Add(model);
                    ids += "," + B_Lebi_ImageSize.GetMaxId();
                }
                else
                {
                    ids += "," + model.id;
                }
                //model = B_Lebi_ImageSize.GetModel("Width=" + theme.ImageSmall_Width + " and Height=" + theme.ImageSmall_Height + "");
                //if (model == null)
                //{
                //    model = new Lebi_ImageSize();
                //    model.Width = theme.ImageSmall_Width;
                //    model.Height = theme.ImageSmall_Height;
                //    B_Lebi_ImageSize.Add(model);
                //    ids += "," + B_Lebi_ImageSize.GetMaxId();
                //}
                //else
                //{
                //    ids += "," + model.id;
                //}
            }
            B_Lebi_ImageSize.Delete("id not in (" + ids + ")");
        }
コード例 #3
0
        /// <summary>
        /// 返回用户的语种
        /// </summary>
        /// <returns></returns>
        public static List <Lebi_Language> AllLanguages()
        {
            List <Lebi_Language> tmodels = B_Lebi_Language.GetList("", "Sort desc");

            return(tmodels);
        }
コード例 #4
0
        /// <summary>
        /// 返回站点语言
        /// </summary>
        /// <param name="siteid"></param>
        /// <returns></returns>
        public static List <Lebi_Language> SiteLanguages(int siteid)
        {
            List <Lebi_Language> tmodels = B_Lebi_Language.GetList("Site_id=" + siteid + "", "Sort desc");

            return(tmodels);
        }
コード例 #5
0
        /// <summary>
        /// 载入主题
        /// </summary>
        /// <param name="themecode"></param>
        /// <param name="siteid"></param>
        /// <param name="languagecode"></param>
        /// <param name="pcode"></param>
        /// <param name="checklogin">是否检查用户登录</param>
        public void LoadTheme(string themecode, int siteid, string languagecode, string pcode, bool checklogin)
        {
            CurrentSite_ = B_Lebi_Site.GetModel(siteid);
            if (ShopCache.GetMainSite().id == CurrentSite_.id || CurrentSite_.Domain == "")
            {
                IsMainSite = true;
            }
            CurrentLanguage_ = B_Lebi_Language.GetModel("Code='" + languagecode + "' and Site_id=" + siteid + "");
            if (CurrentLanguage_ == null)
            {
                CurrentLanguage_ = new Lebi_Language();
            }

            if (IsMainSite)
            {
                CurrentLanguage_.Path = (CurrentSite_.Path + CurrentLanguage_.Path).Replace("//", "/").TrimEnd('/');
            }
            if (checklogin)
            {
                if (CurrentUser.id == 0 || CurrentUser.IsAnonymous == 1)
                {
                    HttpContext.Current.Response.Redirect(URL("P_Login", "" + HttpUtility.UrlEncode(RequestTool.GetRequestUrlNonDomain()) + "," + GetUrlToken(RequestTool.GetRequestUrlNonDomain()) + ""));
                }
            }
            CurrentTheme_ = B_Lebi_Theme.GetModel("Code='" + themecode + "'");
            CurrentPage   = B_Lebi_Theme_Page.GetModel("Code='" + pcode + "'");
            if (CurrentTheme_ == null)
            {
                CurrentTheme_ = new Lebi_Theme();
            }
            Lebi_Theme_Skin skin = B_Lebi_Theme_Skin.GetModel("Theme_id=" + CurrentTheme_.id + " and Code='" + pcode + "'");

            if (skin != null)
            {
                if (skin.PageSize > 0)
                {
                    PageSize = skin.PageSize;
                }
            }
            if (CurrentSite_ != null)
            {
                SYS.Copyright   = CurrentSite_.Copyright;
                SYS.Domain      = CurrentSite_.Domain;
                SYS.Email       = CurrentSite_.Email;
                SYS.Fax         = CurrentSite_.Fax;
                SYS.Keywords    = CurrentSite_.Keywords;
                SYS.Logoimg     = CurrentSite_.Logoimg;
                SYS.Description = CurrentSite_.Description;
                SYS.Phone       = CurrentSite_.Phone;
                SYS.QQ          = CurrentSite_.QQ;
                SYS.ServiceP    = CurrentSite_.ServiceP;
                SYS.Name        = CurrentSite_.Name;
                SYS.Title       = CurrentSite_.Title;
                SYS.FootHtml    = CurrentSite_.FootHtml;
                SYS.TopAreaid   = CurrentLanguage_.TopAreaid.ToString();
            }
            LBTITLE  = "";
            LBTITLE += " - Powered by LebiShop";
            //底部版权信息
            //if (CurrentPage != null)
            //{
            //    StringBuilder sb = new StringBuilder();
            //    sb.Append("Powered by <a style=\"font-size:12px;color:#00497f\" href=\"http://www.lebi.cn\" target=\"_blank\" title=\"LebiShop多语言网上商店系统\">LebiShop</a> ");
            //    sb.Append("V" + SYS.Version + "." + SYS.Version_Son);
            //    try
            //    {
            //        Label label = (Label)this.Page.FindControl("LeBiLicense");
            //        label.Text = sb.ToString();
            //    }
            //    catch (System.NullReferenceException)
            //    {
            //        Response.Write("<div style=\"height:100px;padding-top:10px;text-align:left;font-size:12;\">内部错误,请到【配置】=》【站点语言】栏目中重新生成网站<br>");
            //        Response.Write(sb.ToString() + "</div>");
            //        Response.End();
            //    }
            //}
            Session["CurrentTheme"]    = CurrentTheme_;//session主要是为那些没有LoadTheme方法的页面服务的,如ajax
            Session["CurrentLanguage"] = CurrentLanguage_;
            Session["CurrentSite"]     = CurrentSite_;
            //写入cookie
            NameValueCollection nvs = new NameValueCollection();

            nvs.Add("theme", CurrentTheme_.Code);
            nvs.Add("language", CurrentLanguage_.Code);
            nvs.Add("site", CurrentSite_.id.ToString());
            CookieTool.WriteCookie("ThemeStatus", nvs, 10);
            //多站点商品显示
            if (Shop.Bussiness.Site.Instance.SiteCount > 1)
            {
                //if (Shop.LebiAPI.Service.Instanse.Check("domain3admin"))
                //{
                if (DataBase.DBType == "sqlserver")
                {
                    ProductWhere         = "(Charindex('," + CurrentSite_.id + ",',','+Site_ids+',')>0 or Site_ids='') and Product_id = 0 and Type_id_ProductStatus = 101";
                    ProductCategoryWhere = "(Charindex('," + CurrentSite_.id + ",',','+Site_ids+',')>0 or Site_ids='')";
                }
                if (DataBase.DBType == "access")
                {
                    ProductWhere         = "(Instr(','+Site_ids+',','," + CurrentSite_.id + ",')>0 or Site_ids='') and Product_id = 0 and Type_id_ProductStatus = 101";
                    ProductCategoryWhere = "(Instr(','+Site_ids+',','," + CurrentSite_.id + ",')>0 or Site_ids='')";
                }
                //}
                //else
                //{
                //    ProductWhere = "Product_id = 0 and Type_id_ProductStatus = 101";
                //}
            }
            else
            {
                ProductWhere         = "Product_id = 0 and Type_id_ProductStatus = 101";
                ProductCategoryWhere = "1=1";
            }
            //ProductWhere += " and (UserLevel_ids_show='' or UserLevel_ids_show is null or ','+UserLevel_ids_show+',' like '%," + CurrentUserLevel.id + ",%'  )";
            ProductWhere += " and (IsDel!=1 or IsDel is null)";
        }