Exemplo n.º 1
0
        public string GetFullTemplate(string skinID)
        {
            m_IncludedSkinFile = false;
            m_IncludedFiles    = new List <TemplateFile>();

            string path = this.FilePath;

            if (m_BaseFile != null)
            {
                if (File.Exists(path) == false)
                {
                    path = m_BaseFile.FilePath;
                }
                else
                {
                    m_IncludedSkinFile = true;
                }
            }

            string content = File.ReadAllText(path, Encoding.Default);

            MatchEvaluator callback = delegate(Match match)
            {
                string includeVirtualPath = match.Groups[1].Value;

                includeVirtualPath = GetIncludeFileVirtualPath(includeVirtualPath);

                TemplateFile includeFile = null;

                if (TemplateManager.GetTemplateFiles().TryGetValue(includeVirtualPath, out includeFile))
                {
                    if (skinID != MaxLabs.bbsMax.Consts.DefaultSkinID)
                    {
                        includeFile = includeFile.GetSkin(skinID);
                    }

                    string includePath = IOUtil.MapPath(includeVirtualPath);

                    //includeFile.ResetWatcher();

                    m_IncludedFiles.Add(includeFile);

                    string result = includeFile.GetFullTemplate(skinID);

                    if (m_IncludedSkinFile == false && includeFile.m_IncludedSkinFile)
                    {
                        m_IncludedSkinFile = true;
                    }

                    //开始处理包含文件的参数
                    string          includeParams = match.Groups["param"].Value;
                    MatchCollection matchs        = Pool <TemplateAttributeListRegex> .Instance.Matches(includeParams);

                    foreach (Match param in matchs)
                    {
                        //应该计算索引位置,否则会存在误判和错误替换
                        result = result.Replace("$" + param.Groups["name"].Value, param.Groups["value"].Value);
                    }

                    return(result);
                }
                else
                {
                    return(string.Empty);
                }
            };

            //content = regex_pager.Replace(content, delegate(Match match) {
            //    return OnMatchPager(match, skinID);
            //});
            content = regex_pager4.Replace(content, delegate(Match match)
            {
                return(OnMatchPager(match, skinID));
            });

            content = s_MatchNotes.Replace(content, string.Empty);

            content = s_MatchInclude.Replace(content, callback);

            content = s_MatchPreInclude.Replace(content, callback);

            content = regex_fast_css.Replace(content, new MatchEvaluator(ReplaceFast));
            content = regex_fast_js.Replace(content, new MatchEvaluator(ReplaceFast));



            content = content.Trim();

            return(content);

            //StringBuilder sb = new StringBuilder();

            //string vpath = path.Substring(Globals.GetPath(SystemDirecotry.Root).Length);

            //sb.AppendLine("<!--begin ").Append(vpath).AppendLine("-->");
            //sb.Append(content.Trim());
            //sb.AppendLine("<!--end ").Append(vpath).AppendLine("-->");

            //return sb.ToString();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 解析指定路径下的模板文件,并返回模板解析结果的路径,如果所给的路径不是模板文件路径,则返回原路径
        /// </summary>
        /// <param name="virtualPath">模板文件的虚拟路径,支持.aspx和.ascx文件</param>
        /// <returns></returns>
        public static string ParseTemplate(string path)
        {
            string virtualPath = null;
            string queryString = null;

            int queryStart = path.IndexOf('?');

            if (queryStart >= 0)
            {
                virtualPath = path.Substring(0, queryStart);
                queryString = path.Substring(queryStart);
            }
            else
            {
                virtualPath = path;
            }

            //if (virtualPath.StartsWith(SkinedPath, StringComparison.OrdinalIgnoreCase))
            //{
            //    string skinID = User.Current.SkinID;

            //    virtualPath = "~/max-templates/default/" + skinID + virtualPath.Substring(1);
            //}

            TemplateFile templateFile = GetTemplateFile(virtualPath);

            if (templateFile == null)
            {
                return(path);//virtualPath + queryString;
            }
            Skin skin = s_IsPreParsing == false ? Context.Current.Skin : s_PreParseSkin;

            bool   useSkin;
            string skinID;

            if (skin == null)
            {
                useSkin = false;
                skinID  = MaxLabs.bbsMax.Consts.DefaultSkinID;
            }
            else
            {
                useSkin = skin.SkinID != MaxLabs.bbsMax.Consts.DefaultSkinID;
                skinID  = skin.SkinID;
            }

            if (useSkin)
            {
                templateFile = templateFile.GetSkin(skin.SkinID);
            }

            if (templateFile.IsParsed == false)
            {
                lock (templateFile)
                {
                    if (templateFile.IsParsed == false)
                    {
                        using (TemplateParser parser = new TemplateParser())
                        {
                            //string forumPath = "~/max-templates/" + skinID + "/forums/";

                            ////UrlFormat urlFormat = s_IsPreParsing ? s_PreParseUrlFormat : AllSettings.Current.FriendlyUrlSettings.UrlFormat;

                            //if (templateFile.VirtualPath.StartsWith(forumPath, StringComparison.OrdinalIgnoreCase))
                            //{
                            //    parser.GenerateV30AspxCode(skinID, templateFile, Config.Current.TemplateImports);
                            //}
                            //else
                            //{
                            parser.GenerateAspxCode(skinID, templateFile, Config.Current.TemplateImports);
                            //}

                            templateFile.IsParsed = true;
                        }
                    }
                }
            }

            return(templateFile.ParsedFileVirtualPath + queryString);
        }