Пример #1
0
        /// <summary>
        /// 生成插件页面
        /// </summary>
        /// <param name="pgconf"></param>
        /// <param name="site"></param>
        /// <param name="type"></param>
        /// <param name="parentpath"></param>
        public static void CreatePluginPage(PluginConfig pgconf, string type, string parentpath)
        {
            string WebPath   = Site.Instance.WebPath;
            string path      = System.Web.HttpRuntime.AppDomainAppPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + type + "/page/" + parentpath;
            string filepath  = WebPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + type + "/page/" + parentpath;
            string mediapath = "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + type;

            if (type == "admin")
            {
                if (!string.IsNullOrEmpty(RequestTool.GetConfigKey("SystemAdmin").Trim()))
                {
                    path      = System.Web.HttpRuntime.AppDomainAppPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + RequestTool.GetConfigKey("SystemAdmin").Trim() + "/page/" + parentpath;
                    filepath  = WebPath + "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + RequestTool.GetConfigKey("SystemAdmin").Trim() + "/page/" + parentpath;
                    mediapath = "/plugin/" + pgconf.Assembly.ToLower() + "/systempage/" + RequestTool.GetConfigKey("SystemAdmin").Trim();
                }
            }
            if (!Directory.Exists(path))
            {
                return;
            }
            DirectoryInfo mydir = new DirectoryInfo(path);

            DirectoryInfo[] dirs = mydir.GetDirectories();
            foreach (DirectoryInfo dir in dirs)
            {
                CreatePluginPage(pgconf, type, parentpath + "/" + dir.Name);//递归全部文件夹
            }
            FileInfo[] files    = mydir.GetFiles();
            string     content  = "";
            string     pagename = "";

            parentpath = parentpath.ToLower().Trim('/');

            string createpath = type;

            if (type == "admin")
            {
                createpath = Site.Instance.AdminPath;
            }
            else if (type == "supplier")
            {
                createpath = Site.Instance.SupplierPath;
            }
            //parentpath = parentpath.Substring(type.Length, parentpath.Length - type.Length);
            if (!Directory.Exists(System.Web.HttpRuntime.AppDomainAppPath + "/" + createpath))
            {
                Directory.CreateDirectory(System.Web.HttpRuntime.AppDomainAppPath + "/" + createpath);
            }
            foreach (FileInfo f in files)
            {
                pagename = f.Name.Replace(".html", ".aspx");
                pagename = ThemeUrl.GetFullPath(WebPath + "/" + createpath + "/" + parentpath + "/" + pagename);
                content  = HtmlEngine.ReadTxt(filepath + "/" + f.Name);
                CreatAdminAspx(pagename, content, type, mediapath);
            }
        }
Пример #2
0
        /// <summary>
        /// 执行代码替换
        /// 在${...}$内
        /// </summary>
        /// <param name="strIn"></param>
        /// <returns></returns>
        public static string DoCodeConvert(string strIn, string type, string webpath, string mediapath)
        {
            strIn = DoLayout(strIn, type, webpath, mediapath);
            //======================================================
            string[] PartArry   = RegexTool.GetSimpleRegResultArray(strIn, @"({[Mm][Oo][Dd]:.*?})");
            string   partTag    = "";
            string   partConten = "";
            string   partPara   = "";

            webpath = webpath.TrimEnd('/');
            Lebi_Theme_Skin partskin = new Lebi_Theme_Skin();

            foreach (string partStr in PartArry)
            {
                partTag    = "";
                partConten = "";
                partPara   = "";
                if (partStr.Contains("("))
                {
                    partTag  = RegexTool.GetRegValue(partStr, @"{[Mm][Oo][Dd]:(.*?)\(.*?}");
                    partPara = RegexTool.GetRegValue(partStr, @"{[Mm][Oo][Dd]:.*?\((.*?)\)}");
                }
                else
                {
                    partTag = RegexTool.GetRegValue(partStr, @"{[Mm][Oo][Dd]:(.*?)}");
                }
                if (partTag != "")
                {
                    //模块提取优先级
                    //1插件中的BLOCK文件夹
                    //2模板中的自定义设置
                    //3系统块

                    string[] plugins = ShopCache.GetBaseConfig().PluginUsed.ToLower().Split(',');
                    foreach (string plugin in plugins)
                    {
                        partConten = HtmlEngine.ReadTxt(webpath + "/plugin/" + plugin + "/systempage/" + type + "/block/" + partTag + ".html");
                        if (partConten == "")
                        {
                            partConten = HtmlEngine.ReadTxt(webpath + "/plugin/" + plugin + "/block/" + partTag + ".html");
                        }
                        if (partConten != "")
                        {
                            break;
                        }
                    }

                    if (partConten == "")
                    {
                        partConten = HtmlEngine.ReadTxt(ThemeUrl.GetFullPath(webpath + "/system/" + type + "/block/" + partTag + ".html"));
                    }
                    if (partConten == "")
                    {
                        partConten = HtmlEngine.ReadTxt(ThemeUrl.GetFullPath(webpath + "/system/block/" + partTag + ".html"));
                    }
                    if (partConten != "")
                    {
                        partConten = "<!--MOD_start:" + partTag + "-->\r\n" + DoCodeConvert(partConten, type, webpath, "") + "<!--MOD_end:" + partTag + "-->\r\n";
                        strIn      = RegexTool.ReplaceRegValue(strIn, @"{[Mm][Oo][Dd]:" + partTag + ".*?}", partConten);
                    }
                }
            }
            //=========================================================
            string str  = "";
            Type   t    = typeof(ShopPage);
            string temp = "";

            int[,] d = IndexFlagArry(strIn);//记录开始,结尾标记的数组
            if (d.Length > 0)
            {
                int begin = 0;
                string[,] tempArry = new string[d.GetUpperBound(0) + 1, 2];//用于存放一个外层标记的临时数组
                for (int i = 0; i < d.GetUpperBound(0); i++)
                {
                    temp          += RegexTool.GetSubString(strIn, begin, d[i, 0]) + "$$$" + i + "$$$";//挑选非标记部组合,将标记部分替换为$$$0$$$,$$$1$$$形式
                    begin          = d[i, 1] + 2;
                    tempArry[i, 0] = "$$$" + i + "$$$";
                    tempArry[i, 1] = RegexTool.GetSubString(strIn, d[i, 0] + 2, d[i, 1]);//截取不包含开始,结尾标记的块
                }
                temp += RegexTool.GetSubString(strIn, begin, strIn.Length);
                str   = temp;//str已经替除了全部的标记块

                for (int i = 0; i < tempArry.GetUpperBound(0); i++)
                {
                    temp = DoPart(tempArry[i, 1], type, webpath);
                    str  = str.Replace("$$$" + i + "$$$", temp);
                }
            }
            return(str);
        }
Пример #3
0
        /// <summary>
        /// 载入布局文件
        /// </summary>
        /// <param name="strIn"></param>
        /// <param name="theme"></param>
        /// <returns></returns>
        public static string DoLayout(string strIn, string type, string webpath, string mediapath)
        {
            string layout = RegexTool.GetRegValue(strIn, @"{[Ll][Aa][Yy][Oo][Uu][Tt]:(.*?)}");
            string cs     = RegexTool.GetRegValue(strIn, @"({[Cc][Ll][Aa][Ss][Ss]:.*?})");

            if (layout == "")
            {
                return(cs + strIn);
            }

            string layoutpath    = "";
            string layoutContent = "";

            if (mediapath != "")
            {
                layoutpath    = webpath + mediapath + "/layout/" + layout + ".layout";
                layoutpath    = ThemeUrl.GetFullPath(layoutpath);
                layoutContent = HtmlEngine.ReadTxt(layoutpath);
            }
            if (layoutContent == "")
            {
                layoutpath    = webpath + "/theme/system/systempage/" + type + "/layout/" + layout + ".layout";
                layoutpath    = ThemeUrl.GetFullPath(layoutpath);
                layoutContent = HtmlEngine.ReadTxt(layoutpath);
            }
            if (layoutContent == "")
            {
                layoutpath    = webpath + "/theme/system/layout/" + layout + ".layout";
                layoutpath    = ThemeUrl.GetFullPath(layoutpath);
                layoutContent = HtmlEngine.ReadTxt(layoutpath);
            }
            if (layoutContent == "")
            {
                return("");
            }
            string[] holderArray = RegexTool.GetSimpleRegResultArray(layoutContent, @"({[Hh][Oo][Ll][Dd][Ee][Rr]:.*?})");
            foreach (string holder in holderArray)
            {
                string tag    = RegexTool.GetRegValue(holder, @"{[Hh][Oo][Ll][Dd][Ee][Rr]:(.*?)}");
                string regtag = "";
                foreach (char t in tag)
                {
                    regtag += "[" + t.ToString().ToUpper() + t.ToString().ToLower() + "]";
                }
                string holdercontent = RegexTool.GetRegValue(strIn, @"<" + regtag + ">(.*?)</" + regtag + ">");
                layoutContent = RegexTool.ReplaceRegValue(layoutContent, @"{[Hh][Oo][Ll][Dd][Ee][Rr]:" + tag + ".*?}", holdercontent);
            }
            //载入重写模块
            string[] rewriteArray = RegexTool.GetSimpleRegResultArray(strIn, @"({[Rr][Ee][Ww][Rr][Ii][Tt][Ee]:.*?})");
            foreach (string rewrite in rewriteArray)
            {
                string tag  = RegexTool.GetRegValue(rewrite, @"{[Rr][Ee][Ww][Rr][Ii][Tt][Ee]:(.*?)}");
                string from = "";
                string to   = "";
                from = tag.Substring(0, tag.IndexOf(" "));
                to   = tag.Substring(tag.IndexOf(" ") + 1, tag.Length - from.Length - 1);
                string regfrom = "";
                string regto   = "";
                foreach (char t in from)
                {
                    regfrom += "[" + t.ToString().ToUpper() + t.ToString().ToLower() + "]";
                }
                foreach (char t in to)
                {
                    regto += "[" + t.ToString().ToUpper() + t.ToString().ToLower() + "]";
                }
                string holdercontent = RegexTool.GetRegValue(strIn, @"<" + regto + ">(.*?)</" + regto + ">");
                if (holdercontent == "")
                {
                    holdercontent = "{MOD:" + to + "}";
                }
                layoutContent = RegexTool.ReplaceRegValue(layoutContent, @"{[Mm][Oo][Dd]:" + regfrom + "}", holdercontent);
            }
            layoutContent = cs + layoutContent;
            return(layoutContent);
        }
Пример #4
0
        /// <summary>
        /// 生成后台的单个文件
        /// </summary>
        /// <param name="Path">生成文件名已经路径</param>
        /// <param name="Content"></param>
        /// <param name="WebPath"></param>
        /// <returns></returns>
        public static void CreatAdminAspx(string Path, string Content, string type, string mediapath)
        {
            if (Content == "")
            {
                return;
            }
            string     FileName   = "";
            BaseConfig bf         = ShopCache.GetBaseConfig();
            string     WebPath    = Site.Instance.WebPath;
            string     serverpath = "";

            if (System.Web.HttpContext.Current == null)
            {
                serverpath = System.Web.HttpRuntime.AppDomainAppPath;
            }
            else
            {
                serverpath = System.Web.HttpContext.Current.Server.MapPath(@"~/");
            }
            try
            {
                Path     = ThemeUrl.GetFullPath(Path);
                FileName = ThemeUrl.GetFileName(Path);
                Path     = ThemeUrl.GetPath(Path);
                string PhysicsPath = serverpath + Path;
                if (!Directory.Exists(PhysicsPath))
                {
                    Directory.CreateDirectory(PhysicsPath);
                }
                string PhysicsFileName = serverpath + Path + FileName;
                if (System.IO.File.Exists(PhysicsFileName))
                {
                    System.IO.File.Delete(PhysicsFileName);
                }
                Content = DoCodeConvert(Content, type, WebPath, mediapath);
                //=============================================================
                //处理特殊页面引用

                string cs = RegexTool.GetRegValue(Content, @"{[Cc][Ll][Aa][Ss][Ss]:(.*?)}");
                if (cs != "")
                {
                    string pagehead = "<%@ Page Language=\"C#\" AutoEventWireup=\"true\" Inherits=\"" + cs + "\" validateRequest=\"false\"%>";
                    Content = RegexTool.ReplaceRegValue(Content, @"<%@ Page .*? %>", "");
                    Content = pagehead + Content;
                    //if (type == "supplier")
                    //    Content = Content.Replace("Shop.Bussiness.SupplierPageBase", cs);
                    //else
                    //    Content = Content.Replace("Shop.Bussiness.AdminPageBase", cs);
                }
                //处理资源路径
                string Path_JS    = WebPath + "/system/systempage/" + type + "/js";
                string Path_Image = WebPath + "/system/systempage/" + type + "/images";
                string Path_CSS   = WebPath + "/system/systempage/" + type + "/css";
                Path_JS    = RegexTool.ReplaceRegValue(Path_JS, @"//*/", "/");
                Path_Image = RegexTool.ReplaceRegValue(Path_Image, @"//*/", "/");
                Path_CSS   = RegexTool.ReplaceRegValue(Path_CSS, @"//*/", "/");
                Content    = RegexTool.ReplaceRegValue(Content, @"{/[Jj][Ss]}", Path_JS);
                Content    = RegexTool.ReplaceRegValue(Content, @"{/[Cc][Ss][Ss]}", Path_CSS);
                Content    = RegexTool.ReplaceRegValue(Content, @"{/[Ii][Mm][Aa][Gg][eE]}", Path_Image);
                Content    = RegexTool.ReplaceRegValue(Content, @"<!--.*?-->", "");
                Content    = RegexTool.ReplaceRegValue(Content, @"{[Cc][Ll][Aa][Ss][Ss]:.*?}", "");

                HtmlEngine.Instance.WriteFile(PhysicsFileName, Content);
            }
            catch (Exception ex)
            {
            }
        }