Ejemplo n.º 1
0
        /// <summary>
        /// 呈现标签页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="t"></param>
        public static void RenderTag(CmsContext context, string t)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            context.Render(cmsPage.GetTagArchive(t ?? String.Empty));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            SiteDto site    = context.CurrentSite;
            int     siteId  = site.SiteId;
            string  cacheId = String.Concat("cms_s", siteId.ToString(), "_index_page");

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }


            string html;

            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object    obj   = cache.Get(cacheId);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheId, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                //DateTime dt = DateTime.Now;
                html = cmsPage.GetIndex(null);
                //context.Render("<br />"+(DateTime.Now - dt).TotalMilliseconds.ToString() + "<br />");
            }

            //response.AddHeader("Cache-Control", "max-age=" + maxAge.ToString());
            context.Render(html);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 呈现搜索页
        /// </summary>
        /// <param name="context"></param>
        /// <param name="c"></param>
        /// <param name="w"></param>
        public static void RenderSearch(CmsContext context, string c, string w)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            context.Render(
                cmsPage.GetSearch(
                    c ?? String.Empty
                    , w ?? String.Empty
                    )
                );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 呈现分类页
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="tag"></param>
        /// <param name="page"></param>
        public static void RenderCategory(CmsContext ctx, string catPath, int page)
        {
            int         siteId   = ctx.CurrentSite.SiteId;
            string      html     = String.Empty;
            CategoryDto category = ServiceCall.Instance.SiteService.GetCategory(siteId, catPath);

            if (!(category.ID > 0))
            {
                RenderNotFound(ctx); return;
            }

            if (!catPath.StartsWith(category.Path))
            {
                RenderNotFound(ctx);
                return;
            }

            ICmsPageGenerator cmsPage = new PageGeneratorObject(ctx);

            /*********************************
            *  @ 单页,跳到第一个特殊文档,
            *  @ 如果未设置则最新创建的文档,
            *  @ 如未添加文档则返回404
            *********************************/
            if (String.IsNullOrEmpty(category.Location))
            {
                html = cmsPage.GetCategory(category, page);
                ctx.Render(html);
            }
            else
            {
                string url = category.Location;
                if (category.Location.IndexOf("://") != -1)
                {
                    url = category.Location;
                }
                else
                {
                    if (!category.Location.StartsWith("/"))
                    {
                        url = String.Concat(ctx.SiteAppPath, ctx.SiteAppPath == "/"?"":"/", category.Location);
                    }
                }
                ctx.Response.Redirect(url, true);  //302
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }
            //检查缓存
            if (!context.CheckAndSetClientCache())
            {
                return;
            }

            SiteDto           site    = context.CurrentSite;
            int               siteId  = site.SiteId;
            string            cacheId = String.Format("cms_s{0}_{1}_index_page", siteId, (int)Cms.Context.DeviceType);
            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (context.Request["cache"] == "0")
            {
                Cms.Cache.Rebuilt();
            }
            string html;

            if (Settings.Opti_IndexCacheSeconds > 0)
            {
                ICmsCache cache = Cms.Cache;
                object    obj   = cache.Get(cacheId);
                if (obj == null)
                {
                    html = cmsPage.GetIndex(null);
                    cache.Insert(cacheId, html, DateTime.Now.AddSeconds(Settings.Opti_IndexCacheSeconds));
                }
                else
                {
                    html = obj as string;
                }
            }
            else
            {
                html = cmsPage.GetIndex(null);
            }
            context.Render(html);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 访问文档
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allhtml"></param>
        public static void RenderArchive(CmsContext context, string allhtml)
        {
            string     html;
            ArchiveDto archive = default(ArchiveDto);

            var    siteId      = context.CurrentSite.SiteId;
            String archivePath = allhtml.Substring(0, allhtml.Length - ".html".Length);

            archive = ServiceCall.Instance.ArchiveService.GetArchiveByIdOrAlias(siteId, archivePath);
            if (archive.Id <= 0)
            {
                RenderNotFound(context);
                return;
            }

            // 如果设置了302跳转
            if (!String.IsNullOrEmpty(archive.Location))
            {
                string url;
                if (Regex.IsMatch(archive.Location, "^http://", RegexOptions.IgnoreCase))
                {
                    url = archive.Location;
                }
                else
                {
                    if (archive.Location.StartsWith("/"))
                    {
                        throw new Exception("URL不能以\"/\"开头!");
                    }
                    url = String.Concat(context.SiteDomain, "/", archive.Location);
                }
                context.Response.Redirect(url, true); //302
                return;
            }

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);

            if (!FlagAnd(archive.Flag, BuiltInArchiveFlags.Visible))
            {
                RenderNotFound(context);
                return;
            }

            CategoryDto category = archive.Category;

            if (!(category.ID > 0))
            {
                RenderNotFound(context);
                return;
            }
            if (FlagAnd(archive.Flag, BuiltInArchiveFlags.AsPage))
            {
                string pagePattern = "^[\\.0-9A-Za-z_-]+\\.html$";

                if (!Regex.IsMatch(context.Request.Path, pagePattern))
                {
                    context.Response.StatusCode       = 301;
                    context.Response.RedirectLocation = String.Format("{0}.html",
                                                                      String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias
                                                                      );
                    context.Response.End();
                    return;
                }
            }
            else
            {
                //校验栏目是否正确
                string categoryPath = category.Path;
                if (!archivePath.StartsWith(categoryPath + "/"))
                {
                    RenderNotFound(context);
                    return;
                }
            }

            //增加浏览次数
            ++archive.ViewCount;
            ServiceCall.Instance.ArchiveService.AddCountForArchive(siteId, archive.Id, 1);
            //显示页面
            html = cmsPage.GetArchive(archive);

            // return html;
            context.Render(html);
        }