DTcms.Common/PageTemplate.cs

(开头部分) 18KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;

namespace DTcms.Common
{
    /// <summary>
    /// Template为页面模板类.
    /// </summary>
    public abstract class PageTemplate
    {
        public static Regex[] r = new Regex[19];

        static PageTemplate()
        {
            RegexOptions options = RegexOptions.None;
            r[0] = new Regex(@"<%template src=/([^\[\]\{\}\s]+)/%>", options);
            //命名空间
            r[1] = new Regex(@"<%namespace (?:""?)([\s\S]+?)(?:""?)%>", options);
            //C#代码
            r[2] = new Regex(@"<%csharp%>([\s\S]+?)<%/csharp%>", options);
            //loop循环
            //r[3] = new Regex(@"<%loop ((\(([a-zA-Z]+)\) )?)([^\[\]\{\}\s]+) ([^\[\]\{\}\s]+)%>", options);
            r[3] = new Regex(@"<%loop ((\(([^\[\]\{\}\s]+)\) )?)([^\[\]\{\}\s]+) ([^\[\]\{\}\s]+)%>", options);
            r[4] = new Regex(@"<%\/loop%>", options);
            //IF语句
            r[5] = new Regex(@"<%if (?:\s*)(([^\s]+)((?:\s*)(\|\||\&\&)(?:\s*)([^\s]+))?)(?:\s*)%>", options);
            r[6] = new Regex(@"<%else(( (?:\s*)if (?:\s*)(([^\s]+)((?:\s*)(\|\||\&\&)(?:\s*)([^\s]+))?))?)(?:\s*)%>", options);
            r[7] = new Regex(@"<%\/if%>", options);
            r[8] = new Regex(@"<%continue%>");
            r[9] = new Regex(@"<%break%>");
            //解析普通变量{}
            r[10] = new Regex(@"(\{request\[([^\[\]\{\}\s]+)\]\})", options);
            //截取字符串
            r[11] = new Regex(@"(<%cutstring\(([^\s]+?),(.\d*?)\)%>)", options);
            //url链接
            r[12] = new Regex(@"(<%linkurl\(([^\s]*?)\)%>)", options);
            //set标签
            //r[13] = new Regex(@"<%set ((\(([a-zA-Z]+)\))?)(?:\s*)\{([^\s]+)\}(?:\s*)=(?:\s*)(.*?)(?:\s*)%>", options);
            r[13] = new Regex(@"<%set ((\(([\w\.<>]+)\))?)(?:\s*)\{([^\s]+)\}(?:\s*)=(?:\s*)(.*?)(?:\s*)%>", options);
            ////解析==表达式
            r[14] = new Regex(@"(\{([^\[\]\{\}\s]+)\[([^\[\]\{\}\s]+)\]\})", options);
            //解析普通变量{}
            r[15] = new Regex(@"({([^\[\]/\{\}=:'\s]+)})", options);
            //时间格式转换
            r[16] = new Regex(@"(<%datetostr\(([^\s]+?),(.*?)\)%>)", options);
            //整型转换
            r[17] = new Regex(@"(\{strtoint\(([^\s]+?)\)\})", options);
            //write标签
            r[18] = new Regex(@"<%write (?:\s*)(.*?)(?:\s*)%>", options);
        }

        /// <summary>
        /// 获得模板字符串,从设置中的模板路径来读取模板文件.
        /// </summary>
        /// <param name="sitePath">站点目录</param>
        /// <param name="tempPath">模板目录</param>
后面还有 305 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。