예제 #1
0
        public string GetDefaultTemplatePath(string templateAlias, bool isDetail)
        {
            HelperFactory     helperFactory = (HelperFactory)HttpContext.Current.Application[HelperFactory.ApplicationID];
            SiteSettingHelper cdHelper      = helperFactory.GetHelper <SiteSettingHelper>();

            GeneralConfigInfo si = GeneralConfigs.GetConfig();

            if (si.DefaultTemplateGroupFileName != null && si.DefaultTemplateGroupFileName.Length > 0)
            {
                TemplateGroup tg = GetTemplateGroupCache(si.DefaultTemplateGroupFileName);
                string        DefaultTemplatePath = "";

                foreach (TemplateGroup.Item it in tg.Items)
                {
                    if (it.Alias == templateAlias && it.IsDetailTemplate == isDetail)
                    {
                        DefaultTemplatePath = it.Template;
                        break;
                    }
                }

                if (DefaultTemplatePath != "")
                {
                    if (EnableSiteSkins)
                    {
                        DefaultTemplatePath = String.Format("{0}/{1}", Path.GetFileNameWithoutExtension(si.DefaultTemplateGroupFileName), DefaultTemplatePath);
                    }
                    return(GetTemplatePath(DefaultTemplatePath));
                }
                else
                {
                    return("");
                }
            }
            else
            {
                return("");
            }
        }
예제 #2
0
        /// <summary>
        /// 保存模板信息
        /// </summary>
        /// <param name="tp">模板信息</param>
        /// <param name="Templatefolder">模板文件夹</param>
        public void SaveTemplate(Template tp, string templatefolder)
        {
            string            templatePath = DefaultTemplateGroupPath;
            SiteSettingHelper cdHelper     = new SiteSettingHelper();
            GeneralConfigInfo si           = GeneralConfigs.GetConfig();

            if (string.IsNullOrEmpty(templatefolder))
            {
                templatefolder = si.DefaultTemplateGroupFileName;
            }
            else if (templatefolder.ToLower().EndsWith(".xml"))
            {
                templatefolder = templatefolder.Substring(0, templatefolder.Length - 4);
            }
            if (si.DefaultTemplateGroupFileName != templatefolder)
            {
                templatePath = String.Format("{0}\\{1}", Path.Combine(Root, Constants.TemplateBasePath), templatefolder);
            }
            else
            {
                templatePath = String.Format("{0}", DefaultTemplateGroupPath);
            }

            string fn = tp.FileName;

            fn += Constants.TemplateFileExtension;

            string target = Path.Combine(templatePath, fn);

            tp.ToFile(target);

            //清除模板列表缓存
            HttpContext Context = HttpContext.Current;
            string      key     = string.Format(TemplatesKeyID, templatefolder);

            Context.Cache.Remove(key);
        }
예제 #3
0
        public string GetThisHtmlPageTemplate(string ColumnMode, string ColumnID, string SearchWord, string SeSearchWord)
        {
            string TemplatePath = "";
            bool   IsDetail     = false;

            if (ColumnMode == "detail" || ColumnMode == "productDetail" || ColumnMode == "contentMode" || ColumnMode == "adviceMode")
            {
                IsDetail = true;
            }
            if (!We7Helper.IsEmptyID(ColumnID))
            {
                HelperFactory helperFactory = (HelperFactory)HttpContext.Current.Application[HelperFactory.ApplicationID];
                ChannelHelper channelHelper = helperFactory.GetHelper <ChannelHelper>();
                Channel       ch            = channelHelper.GetChannel(ColumnID, null);

                SiteSettingHelper cdHelper = helperFactory.GetHelper <SiteSettingHelper>();

                GeneralConfigInfo si = GeneralConfigs.GetConfig();
                if (si.DefaultTemplateGroupFileName != null && si.DefaultTemplateGroupFileName.Length > 0)                                        //判断一下模板文件是否真实存在
                {
                    if (IsDetail && ch != null && ch.DetailTemplate != null && ch.DetailTemplate != "" && GetTemplate(ch.DetailTemplate) != null) //详细模板
                    {
                        TemplatePath = GetTemplatePath(si.DefaultTemplateGroupFileName, ch.DetailTemplate);
                    }
                    else if (ch != null && ch.TemplateName != null && ch.TemplateName != "" && !IsDetail)
                    {
                        TemplatePath = GetTemplatePath(si.DefaultTemplateGroupFileName, ch.TemplateName);
                    }
                }

                if (TemplatePath == "" || TemplatePath == null) //按别名匹配
                {
                    if (ch != null && ch.Alias != null && ch.Alias != "" && !IsDetail)
                    {
                        string tmp = GetDefaultTemplatePath(ch.Alias, IsDetail);
                        if (tmp != null && tmp != "")
                        {
                            TemplatePath = tmp;
                        }
                    }
                }
                if (TemplatePath == "" || TemplatePath == null) //按标签匹配
                {
                    if (!IsDetail)
                    {
                        List <string> tags = channelHelper.GetTags(ColumnID);
                        if (tags.Count != 0)
                        {
                            string tmp = GetDefaultTemplatePath(tags[0], IsDetail);
                            if (tmp != null && tmp != "")
                            {
                                TemplatePath = tmp;
                            }
                        }
                    }
                }
            }

            if (TemplatePath == "" || TemplatePath == null) //赋值默认模板
            {
                //if (ColumnMode == "productDetail")
                //{
                //    TemplatePath = GetDefaultTemplatePath("[productcontentpage]");
                //}
                if (SeSearchWord != null)
                {
                    TemplatePath = GetDefaultTemplatePath("[sesearch]");
                }
                else if (SearchWord != null)
                {
                    TemplatePath = GetDefaultTemplatePath("[search]");
                }
                else if (We7Helper.IsEmptyID(ColumnID) || ColumnID == "/")
                {
                    TemplatePath = GetDefaultTemplatePath("[homepage]");
                }
                else if (ColumnMode == "detail")
                {
                    TemplatePath = GetDefaultTemplatePath("[contentpage]", true);
                }
                else if (ColumnMode == "productDetail")
                {
                    TemplatePath = GetDefaultTemplatePath("[productcontentpage]");
                }
                else if (ColumnMode == "contentMode")
                {
                    TemplatePath = GetDefaultTemplatePath("[ContentMode]");
                }
                else if (ColumnMode == "adviceMode")
                {
                    TemplatePath = GetDefaultTemplatePath("[AdviceMode]");
                }
                else
                {
                    TemplatePath = GetDefaultTemplatePath("[channel]");
                }
            }
            return(TemplatePath);
        }