Beispiel #1
0
        ///// <summary>
        ///// loop标签的匹配替换
        ///// </summary>
        ///// <param name="template">模板内容</param>
        public string LoopClass(string template)
        {
            string Attributes = "";
            string Text       = "";
            string AllText    = "";
            Regex  r          = new Regex(@"(\[SG:class\s+(?<attributes>[^\]]*?)\](?<text>[\s\S]*?)\[/SG:class\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            foreach (Match m in r.Matches(template))
            {
                Attributes = m.Groups["attributes"].ToString(); //循环属性集
                Text       = m.Groups["text"].ToString();       //循环的内容不包含SG:Loop
                AllText    = m.Groups[0].Value.ToString();      //整个匹配的内容包含SG:Loop

                #region  取得相关属性
                string Count   = null;   //调用数量
                string classID = null;
                string Templet = null;   // 模板ID

                Templet = TagVal(Attributes, "Templet");
                Count   = TagVal(Attributes, "Count");

                classID = TagVal(Attributes, "classID");

                #endregion

                #region 对循环的内容进行替换
                string content = "";
                ROYcms.Sys.BLL.ROYcms_class bll = new ROYcms.Sys.BLL.ROYcms_class();
                DataSet dt = bll.GetClassList(0);
                if (classID != null)
                {
                    dt = bll.GetSubClassList(bll.GetClassId(Convert.ToInt32(classID)));
                }
                if (dt.Tables[0].Rows.Count > 0)
                {
                    int rowsCount = dt.Tables[0].Rows.Count;
                    if (Count != null && rowsCount > Convert.ToInt32(Count))
                    {
                        rowsCount = Convert.ToInt32(Count);
                    }
                    for (int n = 0; n < rowsCount; n++)
                    {
                        string str = Text;
                        str      = Replace(str, @"\[SG:ClassName\]", dt.Tables[0].Rows[n]["ClassName"].ToString());
                        str      = Replace(str, @"\[SG:Link\]", config.web_host + TemplateZone.Zpath(this.pageHost) + "list" + Templet + "-" + dt.Tables[0].Rows[n]["Id"].ToString() + config.web_forge);
                        str      = Replace(str, @"\[SG:_Link\]", "list-" + dt.Tables[0].Rows[n]["Id"].ToString() + config.web_forge);
                        content += str;
                    }
                }
                else
                {
                    content = "";
                }
                #endregion
                template = template.Replace(AllText, content);
            }
            return(template);
        }
Beispiel #2
0
        /// <summary>
        /// show页面标签 替换
        /// </summary>
        /// <param name="template">模板内容</param>
        /// <returns></returns>
        public string ShowTag(string template)
        {
            if (this.bh != null)
            {
                ROYcms.Sys.BLL.ROYcms_news bll = new ROYcms.Sys.BLL.ROYcms_news();

                DataSet dt    = bll.GetList("bh = '" + this.bh + "'");
                DataSet pg_Dn = bll.GetList("bh > '" + this.bh + "'");
                DataSet pg_Up = bll.GetList("bh < '" + this.bh + "' order by bh DESC");

                if (pg_Dn.Tables[0].Rows.Count > 0)
                {
                    template = Replace(template, @"\[SG:pg_Dn\]", pg_Dn.Tables[0].Rows[0]["title"].ToString());
                    template = Replace(template, @"\[SG:pg_Dn_Link\]", pg_Dn.Tables[0].Rows[0]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + this.templet + "-" + pg_Dn.Tables[0].Rows[0]["bh"].ToString() + "-" + Convert.ToDateTime(pg_Dn.Tables[0].Rows[0]["time"]).ToString("yyyyMM") + config.web_forge) : pg_Dn.Tables[0].Rows[0]["jumpurl"].ToString());
                }
                else
                {
                    template = Replace(template, @"\[SG:pg_Dn\]", "无数据");
                    template = Replace(template, @"\[SG:pg_Dn_Link\]", "#");
                }
                if (pg_Up.Tables[0].Rows.Count > 0)
                {
                    template = Replace(template, @"\[SG:pg_Up\]", pg_Up.Tables[0].Rows[0]["title"].ToString());
                    template = Replace(template, @"\[SG:pg_Up_Link\]", pg_Up.Tables[0].Rows[0]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + this.templet + "-" + pg_Up.Tables[0].Rows[0]["bh"].ToString() + "-" + Convert.ToDateTime(pg_Up.Tables[0].Rows[0]["time"]).ToString("yyyyMM") + config.web_forge) : pg_Up.Tables[0].Rows[0]["jumpurl"].ToString());
                }
                else
                {
                    template = Replace(template, @"\[SG:pg_Up\]", "无数据");
                    template = Replace(template, @"\[SG:pg_Up_Link\]", "#");
                }
                template = Replace(template, @"\[SG:UrlPath\]", config.web_host);
                Regex r = new Regex(@"(\[SG:Field\s+name=" + "\"" + @"(?<name>[^" + "\"" + "]*)" + "\"" + @"\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                if (dt.Tables[0].Rows.Count > 0)
                {
                    foreach (Match m in r.Matches(template))
                    {
                        string name = m.Groups["name"].ToString().ToLowerInvariant();
                        if (name == "year")
                        {
                            template = template.Replace(m.Groups[0].Value.ToString(), Convert.ToDateTime(dt.Tables[0].Rows[0]["time"]).Date.Year.ToString());
                        }
                        else if (name == "month")
                        {
                            template = template.Replace(m.Groups[0].Value.ToString(), Convert.ToDateTime(dt.Tables[0].Rows[0]["time"]).Date.Month.ToString());
                        }
                        else if (name == "day")
                        {
                            template = template.Replace(m.Groups[0].Value.ToString(), Convert.ToDateTime(dt.Tables[0].Rows[0]["time"]).Date.Day.ToString());
                        }
                        else
                        {
                            try
                            {
                                template = template.Replace(m.Groups[0].Value.ToString(), dt.Tables[0].Rows[0][name].ToString());
                            }
                            catch { return("标签定义出错"); }
                        }
                    }
                }
            }
            else
            {
                return(template);
            }

            return(template);
        }
Beispiel #3
0
        ///// <summary>
        ///// loopPage分页标签的匹配替换
        ///// </summary>
        ///// <param name="template">模板内容</param>
        public string loopPage(string template)
        {
            string Attributes = "";
            string Text       = "";
            string AllText    = "";
            Regex  r          = new Regex(@"(\[SG:loopPage\s+(?<attributes>[^\]]*?)\](?<text>[\s\S]*?)\[/SG:loopPage\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            foreach (Match m in r.Matches(template))
            {
                Attributes = m.Groups["attributes"].ToString(); //循环属性集
                Text       = m.Groups["text"].ToString();       //循环的内容不包含SG:Loop
                AllText    = m.Groups[0].Value.ToString();      //整个匹配的内容包含SG:Loop

                #region  取得相关属性
                string NewsCount = null;     //调用数量
                string TitleNum  = null;     //新闻标题的显示字符数量
                string ding      = null;
                string tuijian   = null;
                string NewsType  = null;     //调用新闻的类型
                string Templet   = null;     // 模板ID
                string Pagesize  = null;     //

                string SQL = null;

                NewsCount = TagVal(Attributes, "NewsCount");
                if (NewsCount == null)
                {
                    NewsCount = "1000";
                }
                TitleNum = TagVal(Attributes, "TitleNum");
                if (TitleNum == null)
                {
                    TitleNum = "100";
                }
                ding = TagVal(Attributes, "ding");
                if (ding == null)
                {
                    ding = "false";
                }
                tuijian = TagVal(Attributes, "tuijian");
                if (tuijian == null)
                {
                    tuijian = "false";
                }

                NewsType = TagVal(Attributes, "NewsType");
                if (NewsType == null)
                {
                    NewsType = "0";
                }
                if (this.classs != null)
                {
                    NewsType = this.classs;
                }

                Templet = TagVal(Attributes, "Templet");

                Pagesize = TagVal(Attributes, "Pagesize");
                if (Pagesize == null)
                {
                    Pagesize = "30";
                }

                SQL = TagVal(Attributes, "SQL");
                #endregion

                #region 构造 查询SQL语句
                //SQL语句拼接
                string        strWher = "";
                StringBuilder strSql  = new StringBuilder();
                if (SQL == null)
                {
                    strWher = "classname='" + NewsType + "'";

                    strSql.Append("select top ");
                    strSql.Append(NewsCount);
                    strSql.Append(" * from [" + config.date_prefix + "news] where ");
                    strSql.Append(strWher);
                    strSql.Append(" AND switchs='0'");
                    if (ding == "true")
                    {
                        strSql.Append(" AND ding='0'");
                    }
                    if (tuijian == "true")
                    {
                        strSql.Append(" AND tuijian='0'");
                    }
                    strSql.Append(" order by switchs,bh DESC");
                }
                else
                {
                    strSql.Append(SQL);
                }


                #endregion
                #region 对循环的内容进行替换
                string    content     = "";
                DataSet   Pa          = Bll.GetDataSet(strSql.ToString());
                int       PageContent = Pa.Tables[0].Rows.Count;//数据总数 分页用
                int       PS          = Convert.ToInt32(Pagesize);
                int       p           = Convert.ToInt32(pageNum == null ? "1" : pageNum) - 1;
                DataTable dt          = new DataTable();
                dt = Pa.Tables[0];
                if (dt.Rows.Count > 0)
                {
                    int rowsCount = p * PS + PS;
                    if ((p * PS + PS) - dt.Rows.Count > 0)
                    {
                        rowsCount = dt.Rows.Count;
                    }

                    for (int n = p * PS; n < rowsCount; n++)
                    {
                        string str = Text;
                        str = Replace(str, @"\[SG:Title\]", ROYcms.Common.input.GetSubString(dt.Rows[n]["title"].ToString(), Convert.ToInt32(TitleNum)));
                        str = Replace(str, @"\[SG:Id\]", dt.Rows[n]["bh"].ToString());
                        str = Replace(str, @"\[SG:Url\]", dt.Rows[n]["url"].ToString());

                        str = Replace(str, @"\[SG:Link\]", dt.Rows[n]["jumpurl"].ToString() == "" ? (config.web_host + TemplateZone.Zpath(this.pageHost) + "show" + Templet + "-" + dt.Rows[n]["bh"].ToString() + "-" + Convert.ToDateTime(dt.Rows[n]["time"]).ToString("yyyyMM") + config.web_forge) : dt.Rows[n]["jumpurl"].ToString());
                        str = Replace(str, @"\[SG:_Link\]", dt.Rows[n]["jumpurl"].ToString() == "" ? ("show-" + dt.Rows[n]["bh"].ToString() + "-" + Convert.ToDateTime(dt.Rows[n]["time"]).ToString("yyyyMM") + config.web_forge) : dt.Rows[n]["jumpurl"].ToString());
                        str = Replace(str, @"\[SG:Pic\]", dt.Rows[n]["pic"].ToString());
                        str = Replace(str, @"\[SG:Zhaiyao\]", dt.Rows[n]["zhaiyao"].ToString());
                        str = Replace(str, @"\[SG:Keyword\]", dt.Rows[n]["keyword"].ToString());
                        str = Replace(str, @"\[SG:classname\]", dt.Rows[n]["classname"].ToString());

                        str = Replace(str, @"\[SG:Content\]", dt.Rows[n]["contents"].ToString());
                        str = Replace(str, @"\[SG:Infor\]", dt.Rows[n]["infor"].ToString());
                        str = Replace(str, @"\[SG:Author\]", dt.Rows[n]["author"].ToString());
                        str = Replace(str, @"\[SG:Tag\]", dt.Rows[n]["tag"].ToString());
                        str = Replace(str, @"\[SG:Dig\]", dt.Rows[n]["dig"].ToString());
                        str = Replace(str, @"\[SG:Hits\]", dt.Rows[n]["hits"].ToString());
                        str = Replace(str, @"\[SG:Time\]", dt.Rows[n]["time"].ToString());
                        str = Replace(str, @"\[SG:Year\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Year.ToString());
                        str = Replace(str, @"\[SG:Month\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Month.ToString());
                        str = Replace(str, @"\[SG:Day\]", Convert.ToDateTime(dt.Rows[n]["time"]).Date.Day.ToString());

                        content += str;
                    }
                }
                else
                {
                    content = "";
                }
                #endregion

                template = template.Replace(AllText, content);
                template = template.Replace(@"[SG:Page]", PageContent.ToString());
                if (this.classs != null)
                {
                    ROYcms.Sys.BLL.ROYcms_class ROYcms_classBLL = new ROYcms.Sys.BLL.ROYcms_class();

                    template = template.Replace(@"[SG:ClassTitle]", ROYcms_classBLL.GetClassTitle(Convert.ToInt32(this.classs)));
                }
            }
            return(template);
        }