Exemple #1
0
        /// <summary>
        /// GEs the t_ DATE.
        /// </summary>
        /// <param name="Con">The con.</param>
        /// <returns></returns>
        public string ArticlsHtml(HttpContext Con)
        {
            //初始化一些参数
            this.Context  = Con;
            this.type     = Context.Request["type"];
            this.bh       = Context.Request["id"];
            this.templet  = Context.Request["templet"];
            this.pageNum  = Context.Request["page_Num"]; //分页  page 参数
            this.classs   = Context.Request["class"];    //list页的分类编号参数
            this.pageHost = Context.Request["host"];
            //模板URL
            string templet_url = "~/" + config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost) + "/" + type + templet + ".html";
            //读取 模板
            StringBuilder HTM = new StringBuilder();

            if (DataCache.GetCache(templet_url) == null)
            {
                try
                {
                    if (SystemCms.Read_File(Context.Server.MapPath(templet_url), config.templet_language) == null)
                    {
                        //目录不存在创建
                        if (!Directory.Exists(Con.Server.MapPath("~/" + config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost) + "/")))
                        {
                            Directory.CreateDirectory(Con.Server.MapPath("~/" + config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost) + "/"));
                        }

                        if (this.templet != null)
                        {
                            ROYcms.Sys.Model.ROYcms_template model = _BLL.GetModel(Convert.ToInt32(this.templet));
                            HTM.Append(model.htmlcontent);
                            SystemCms.CreateFile(Con.Server.MapPath(templet_url), model.htmlcontent, config.templet_language);
                        }
                        else
                        {
                            HTM.Append("模板不存在!");
                            SystemCms.CreateFile(Con.Server.MapPath(templet_url), "ROYcms!NT  空模板,请编辑", config.templet_language);
                        }
                    }
                    else
                    {
                        HTM.Append(SystemCms.Read_File(Context.Server.MapPath(templet_url), config.templet_language));
                    }
                    DataCache.SetCache(templet_url, (object)SystemCms.Read_File(Context.Server.MapPath(templet_url), config.templet_language));
                }
                catch { HTM.Append("读取模板异常!确定是否有创建文件的权限"); }
            }
            else
            {
                HTM.Append(DataCache.GetCache(templet_url).ToString());
            }
            if (config.HTML_zip == "true")
            {
                return(SystemCms.ZipHtml(LoopClass(loopPage(ShowTag(LoopTag(PublicTag(HTM.ToString())))))));
            }
            else
            {
                return(LoopClass(loopPage(ShowTag(LoopTag(PublicTag(HTM.ToString()))))));
            }
        }
Exemple #2
0
        /// <summary>
        /// 公共标签替换
        /// </summary>
        /// <param name="template">模板内容</param>
        /// <returns></returns>
        /// <summary>
        private string PublicTag(string template)
        {
            //引入外部文件标签
            Regex r = new Regex(@"(\[SG:File\s+Path=" + "\"" + @"(?<Path>[^" + "\"" + "]*)" + "\"" + @"\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            foreach (Match m in r.Matches(template))
            {
                string Path = m.Groups["Path"].ToString();
                template = template.Replace(m.Groups[0].Value.ToString(), SystemCms.Read_File(Context.Server.MapPath(config.templet_root + TemplateZone.TemplateZpath(this.pageHost) + "/" + Path), config.templet_language));
            }
            //WEB.config 文件信息替换
            template = Replace(template, @"\[SG:WebPath\]", config.web_host);
            template = Replace(template, @"\[SG:WebName\]", config.web_name);

            template = Replace(template, @"\[SG:TemplatePath\]", config.templet_root + "/" + TemplateZone.TemplateZpath(this.pageHost));
            //用户自定义标签替换
            #region 对循环的内容进行替换
            ROYcms.Sys.BLL.ROYcms_CustomTag bll = new ROYcms.Sys.BLL.ROYcms_CustomTag();
            DataSet dt = bll.GetAllList();
            if (dt.Tables[0].Rows.Count > 0)
            {
                int rowsCount = dt.Tables[0].Rows.Count;
                for (int n = 0; n < rowsCount; n++)
                {
                    string str = template;
                    str      = str.Replace(@"[SG:" + dt.Tables[0].Rows[n]["TAG"].ToString().Trim() + "]", dt.Tables[0].Rows[n]["TAG_content"].ToString().Trim());
                    template = str;
                }
            }
            #endregion
            return(template);
        }