Beispiel #1
0
        /// <summary>
        /// 文档页
        /// </summary>
        /// <returns></returns>
        public Task Archive(ICompatibleHttpContext context)
        {
            context.Response.ContentType("text/html;charset=utf-8");
            CmsContext ctx = Cms.Context;

            //检测网站状态及其缓存
            if (ctx.CheckSiteState() && ctx.CheckAndSetClientCache())
            {
                context.Response.ContentType("text/html;charset=utf-8");
                var    path        = context.Request.GetPath();
                String archivePath = this.SubPath(path, ctx.SiteAppPath);
                archivePath = archivePath.Substring(0, archivePath.LastIndexOf(".", StringComparison.Ordinal));
                DefaultWebOuput.RenderArchive(ctx, archivePath);
            }
            return(SafetyTask.CompletedTask);

            /*
             * bool eventResult = false;
             * if (OnArchiveRequest != null)
             * {
             *  OnArchiveRequest(ctx, archivePath, ref eventResult);
             * }
             *
             * //如果返回false,则执行默认输出
             * if (!eventResult)
             * {
             *  DefaultWebOuput.RenderArchive(ctx, archivePath);
             * }
             */
        }
Beispiel #2
0
        /// <summary>
        /// 文档页
        /// </summary>
        /// <returns></returns>
        public void Archive(string allHtml)
        {
            CmsContext ctx = base.OutputContext;

            //检测网站状态
            if (!ctx.CheckSiteState())
            {
                return;
            }
            //检查缓存
            if (!ctx.CheckAndSetClientCache())
            {
                return;
            }
            String archivePath = this.SubPath(allHtml, ctx.SiteAppPath);


            bool eventResult = false;

            if (OnArchiveRequest != null)
            {
                OnArchiveRequest(ctx, archivePath, ref eventResult);
            }

            //如果返回false,则执行默认输出
            if (!eventResult)
            {
                DefaultWebOuput.RenderArchive(ctx, archivePath);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 栏目页
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public Task Category(ICompatibleHttpContext context)
        {
            context.Response.ContentType("text/html;charset=utf-8");
            CmsContext ctx = Cms.Context;

            //检测网站状态及其缓存
            if (ctx.CheckSiteState() && ctx.CheckAndSetClientCache())
            {
                var path     = context.Request.GetPath();
                var sitePath = ctx.SiteAppPath;
                // 如果为"/news/",跳转到"/news"
                var pLen = path.Length;
                if (path[pLen - 1] == '/')
                {
                    context.Response.StatusCode(301);
                    context.Response.AddHeader("Location", path.Substring(0, pLen - 1));
                    return(SafetyTask.CompletedTask);
                }

                // 验证是否为当前站点的首页
                if (path == sitePath)
                {
                    return(this.Index(context));
                }

                String catPath = this.SubPath(path, sitePath);
                int    page    = 1;
                //获取页码和tag
                if (catPath.EndsWith(".html"))
                {
                    var ls    = catPath.LastIndexOf("/", StringComparison.Ordinal);
                    var len   = catPath.Length;
                    var begin = ls + 1 + "list_".Length;
                    var ps    = catPath.Substring(begin, len - begin - 5);
                    int.TryParse(ps, out page);
                    catPath = catPath.Substring(0, ls);
                }


                DefaultWebOutput.RenderCategory(ctx, catPath, page);
                // //执行
                // bool eventResult = false;
                // if (OnCategoryRequest != null)
                // {
                //     OnCategoryRequest(ctx, catPath, page, ref eventResult);
                // }
                //
                // //如果返回false,则执行默认输出
                // if (!eventResult)
                // {
                //     DefaultWebOutput.RenderCategory(ctx, catPath, page);
                // }
            }

            return(SafetyTask.CompletedTask);
        }
Beispiel #4
0
        /// <summary>
        /// 栏目页面
        /// </summary>
        /// <param name="allCate"></param>
        /// <returns></returns>
        public void Category(string allCate)
        {
            CmsContext ctx = base.OutputContext;

            //检测网站状态
            if (!ctx.CheckSiteState())
            {
                return;
            }
            //检查缓存
            if (!ctx.CheckAndSetClientCache())
            {
                return;
            }
            String catPath = this.SubPath(allCate, ctx.SiteAppPath);

            //验证是否为当前站点的首页
            if (catPath.Length == 0)
            {
                this.Index();
                return;
            }
            int page = 1;

            if (catPath.IndexOf(".") != -1)
            {
                //获取页码和tag
                Regex paramRegex = new Regex("/*((.+)/(p(\\d+)\\.html)?|(.+))$", RegexOptions.IgnoreCase);
                Match mc         = paramRegex.Match(catPath);
                if (mc.Groups[4].Value != "")
                {
                    page = int.Parse(mc.Groups[4].Value);
                }
                catPath = mc.Groups[mc.Groups[2].Value != "" ? 2 : 5].Value;
            }
            // 去掉末尾的"/"
            if (catPath.EndsWith("/"))
            {
                catPath = catPath.Substring(0, catPath.Length - 1);
            }

            //执行
            bool eventResult = false;

            if (OnCategoryRequest != null)
            {
                OnCategoryRequest(ctx, catPath, page, ref eventResult);
            }

            //如果返回false,则执行默认输出
            if (!eventResult)
            {
                DefaultWebOuput.RenderCategory(ctx, catPath, page);
            }
        }
Beispiel #5
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));
        }
Beispiel #6
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);
        }
Beispiel #7
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
                    )
                );
        }
Beispiel #8
0
 /// <summary>
 /// 呈现标签页
 /// </summary>
 /// <param name="context"></param>
 /// <param name="t"></param>
 public static void RenderTag(CmsContext context, string t)
 {
     //检测网站状态
     if (!context.CheckSiteState())
     {
         return;
     }
     try
     {
         ICmsPageGenerator cmsPage = new PageGeneratorObject(context);
         var html = cmsPage.GetTagArchive(t ?? string.Empty);
         context.HttpContext.Response.WriteAsync(html);
     }
     catch (TemplateException ex)
     {
         RenderError(context, ex, false);
     }
 }
Beispiel #9
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);
        }
Beispiel #10
0
        /// <summary>
        /// 呈现首页
        /// </summary>
        /// <param name="context"></param>
        public static void RenderIndex(CmsContext context)
        {
            //检测网站状态
            if (!context.CheckSiteState()) return;

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

        	int siteID=context.CurrentSite.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 = String.Empty;
            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);
        }
Beispiel #11
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);

            try
            {
                context.HttpContext.Response.WriteAsync(
                    cmsPage.GetSearch(
                        c ?? string.Empty
                        , w ?? string.Empty
                        )
                    );
            }
            catch (TemplateException ex)
            {
                RenderError(context, ex, false);
            }
        }
Beispiel #12
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);

            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

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


            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;
            }
            else
            {
                string appPath = Cms.Context.SiteAppPath;
                if (appPath != "/")
                {
                    appPath += "/";
                }

                if (FlagAnd(archive.Flag, BuiltInArchiveFlags.AsPage))
                {
                    string pattern     = "^" + appPath + "[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$";
                    string pagePattern = "^" + appPath + "[\\.0-9A-Za-z_-]+\\.html$";

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

                    if (!path.StartsWith(categoryPath + "/"))
                    {
                        RenderNotFound(context);
                        return;
                    }

                    /*
                     * //设置了别名,则跳转
                     * if (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias,
                     *  StringComparison.OrdinalIgnoreCase) != 0)
                     * {
                     *  context.Response.StatusCode = 301;
                     *  context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html",
                     *      appPath,
                     *      categoryPath,
                     *      String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias
                     *      );
                     *  context.Response.End();
                     *  return;
                     * }
                     */
                }

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

                //再次处理模板
                //html = PageUtility.Render(html, new { }, false);
            }

            // return html;
            context.Render(html);
        }
Beispiel #13
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;

            //跳转
            if (!String.IsNullOrEmpty(site.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, site.Location);
                //}

                context.Response.Redirect(site.Location, true);  //302

                return;
            }


            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 = String.Empty;

            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);
        }
Beispiel #14
0
        /// <summary>
        /// 访问文档
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allhtml"></param>
        public static void RenderArchive(CmsContext context, string allhtml)
        {
            string     id = null;
            string     html;
            ArchiveDto archive = default(ArchiveDto);

            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }

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


            var siteId = context.CurrentSite.SiteId;

            ICmsPageGenerator cmsPage = new PageGeneratorObject(context);


            Regex paramRegex = new Regex("/*([^/]+).html$", RegexOptions.IgnoreCase);

            if (paramRegex.IsMatch(allhtml))
            {
                id      = paramRegex.Match(allhtml).Groups[1].Value;
                archive = ServiceCall.Instance.ArchiveService.GetArchiveByIdOrAlias(siteId, id);
            }

            if (archive.Id <= 0)
            {
                RenderNotFound(context);
                return;
            }
            else
            {
                //跳转
                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

                    //context.Response.StatusCode = 301;
                    //context.Render(@"<html><head><meta name=""robots"" content=""noindex""><script>location.href='" +
                    //                   url + "';</script></head><body></body></html>");

                    return;
                }

                BuiltInArchiveFlags flag = ArchiveFlag.GetBuiltInFlags(archive.Flags);

                if ((flag & BuiltInArchiveFlags.Visible) != BuiltInArchiveFlags.Visible)
                //|| (flag & BuiltInArchiveFlags.IsSystem)== BuiltInArchiveFlags.IsSystem)   //系统文档可以单独显示
                {
                    RenderNotFound(context);
                    return;
                }

                CategoryDto category = archive.Category;

                if (!(category.Id > 0))
                {
                    RenderNotFound(context);
                    return;
                }
                else
                {
                    string appPath = AtNet.Cms.Cms.Context.SiteAppPath;
                    if (appPath != "/")
                    {
                        appPath += "/";
                    }

                    if ((flag & BuiltInArchiveFlags.AsPage) == BuiltInArchiveFlags.AsPage)
                    {
                        string pattern     = "^" + appPath + "[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$";
                        string pagePattern = "^" + appPath + "[\\.0-9A-Za-z_-]+\\.html$";

                        if (!Regex.IsMatch(context.Request.Path, pagePattern))
                        {
                            context.Response.StatusCode       = 301;
                            context.Response.RedirectLocation = String.Format("{0}{1}.html",
                                                                              appPath,
                                                                              String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias
                                                                              );
                            context.Response.End();
                            return;
                        }
                    }
                    else
                    {
                        //校验栏目是否正确
                        string categoryPath = category.UriPath;
                        string _path        = appPath != "/" ? allhtml.Substring(appPath.Length - 1) : allhtml;

                        if (!_path.StartsWith(categoryPath + "/"))
                        {
                            RenderNotFound(context);
                            return;
                        }

                        //设置了别名,则跳转
                        if (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, true) != 0)
                        {
                            context.Response.StatusCode       = 301;
                            context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html",
                                                                              appPath,
                                                                              categoryPath,
                                                                              String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias
                                                                              );
                            context.Response.End();
                            return;
                        }
                    }


                    //增加浏览次数
                    ++archive.ViewCount;
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            ServiceCall.Instance.ArchiveService.AddCountForArchive(siteId, archive.Id, 1);
                        }
                        catch
                        {
                        }
                    }).Start();

                    //显示页面
                    html = cmsPage.GetArchive(archive);

                    //再次处理模板
                    //html = PageUtility.Render(html, new { }, false);
                }
            }

            // return html;
            context.Render(html);
        }
Beispiel #15
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
                )
                );
        }
Beispiel #16
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));
        }
Beispiel #17
0
        /// <summary>
        /// 文档页提交
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allhtml"></param>
        public static void PostArchive(CmsContext context, string allhtml)
        {
            var form = context.Request.Form;
            var rsp = context.Response;

            //检测网站状态
            if (!context.CheckSiteState()) return;


            string id = form["id"];           //文档编号
            Member member;              //会员

            //提交留言
            if (form["action"] == "comment")
            {
                id = form["ce_id"];

                string view_name = form["ce_nickname"];
                string content = form["ce_content"];
                int memberID;
                member = UserState.Member.Current;

                //校验验证码
                if (!CheckVerifyCode(form["ce_verifycode"]))
                {
                    rsp.Write(ScriptUtility.ParentClientScriptCall("cetip(false,'验证码不正确!');cms.$('ce_verifycode').nextSibling.onclick();"));
                    return;
                }
                else if (String.Compare(content, "请在这里输入评论内容", true) == 0 || content.Length == 0)
                {
                    rsp.Write(ScriptUtility.ParentClientScriptCall("cetip(false,'请输入内容!'); "));
                    return;
                }
                else if (content.Length > 200)
                {
                    rsp.Write(ScriptUtility.ParentClientScriptCall("cetip(false,'评论内容长度不能大于200字!'); "));
                    return;
                }

                if (member == null)
                {
                    if (String.IsNullOrEmpty(view_name))
                    {
                        //会员未登录时,需指定名称
                        rsp.Write(ScriptUtility.ParentClientScriptCall("cetip(false,'不允许匿名评论!'); "));
                        return;
                    }
                    else
                    {
                        //补充用户
                        content = String.Format("(u:'{0}'){1}", view_name, content);
                        memberID = 0;
                    }
                }
                else
                {
                    memberID = UserState.Member.Current.ID;
                }
                CmsLogic.Comment.InsertComment(id, memberID, context.Request.UserHostAddress, content);
                rsp.Write(ScriptUtility.ParentClientScriptCall("cetip(false,'提交成功!'); setTimeout(function(){location.reload();},500);"));
                return;
            }
        }
Beispiel #18
0
        /// <summary>
        /// 文档页提交
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allhtml"></param>
        public static void PostArchive(CmsContext context, string allhtml)
        {
            var req = context.HttpContext.Request;
            var rsp = context.HttpContext.Response;

            //检测网站状态
            if (!context.CheckSiteState())
            {
                return;
            }


            string id = req.Form("id"); //文档编号
            Member member;              //会员

            //提交留言
            if (req.Form("action") == "comment")
            {
                id = req.Form("ce_id");

                string view_name = req.Form("ce_nickname");
                string content   = req.Form("ce_content");
                int    memberID;
                member = UserState.Member.Current;

                //校验验证码
                if (!CheckVerifyCode(req.Form("ce_verify_code")))
                {
                    rsp.WriteAsync(
                        ScriptUtility.ParentClientScriptCall(
                            "ce_tip(false,'验证码不正确!');jr.$('ce_verify_code').nextSibling.onclick();"));
                    return;
                }
                else if (string.Compare(content, "请在这里输入评论内容", StringComparison.OrdinalIgnoreCase) == 0 ||
                         content.Length == 0)
                {
                    rsp.WriteAsync(ScriptUtility.ParentClientScriptCall("ce_tip(false,'请输入内容!'); "));
                    return;
                }
                else if (content.Length > 200)
                {
                    rsp.WriteAsync(ScriptUtility.ParentClientScriptCall("ce_tip(false,'评论内容长度不能大于200字!'); "));
                    return;
                }

                if (member == null)
                {
                    if (string.IsNullOrEmpty(view_name))
                    {
                        //会员未登录时,需指定名称
                        rsp.WriteAsync(ScriptUtility.ParentClientScriptCall("ce_tip(false,'不允许匿名评论!'); "));
                        return;
                    }
                    else
                    {
                        //补充用户
                        content  = string.Format("(u:'{0}'){1}", view_name, content);
                        memberID = 0;
                    }
                }
                else
                {
                    memberID = UserState.Member.Current.ID;
                }

                CmsLogic.Comment.InsertComment(id, memberID, WebCtx.Current.UserIpAddress, content);
                rsp.WriteAsync(
                    ScriptUtility.ParentClientScriptCall(
                        "ce_tip(false,'提交成功!'); setTimeout(function(){location.reload();},500);"));
                return;
            }
        }
Beispiel #19
0
        /// <summary>
        /// 访问文档
        /// </summary>
        /// <param name="context"></param>
        /// <param name="allhtml"></param>
        public static void RenderArchive(CmsContext context, string allhtml)
        {
            string id = null;
            int siteId;
            string html = String.Empty;
            ArchiveDto archive = default(ArchiveDto);
            CategoryDto category = default(CategoryDto);

            //检测网站状态
            if (!context.CheckSiteState()) return;

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

            
            siteId=context.CurrentSite.SiteId;

        	ICmsPageGenerator cmsPage=new PageGeneratorObject(context);


            Regex paramRegex = new Regex("/*([^/]+).html$", RegexOptions.IgnoreCase);
            if (paramRegex.IsMatch(allhtml))
            {
                id = paramRegex.Match(allhtml).Groups[1].Value;
                archive = ServiceCall.Instance.ArchiveService.GetArchiveByIdOrAlias(siteId, id);
            }

            if (archive.Id <= 0)
            {
            	RenderNotFound(context);
                return;
            }
            else
            {

                BuiltInArchiveFlags flag = ArchiveFlag.GetBuiltInFlags(archive.Flags);

                if ((flag & BuiltInArchiveFlags.Visible) != BuiltInArchiveFlags.Visible)
                //|| (flag & BuiltInArchiveFlags.IsSystem)== BuiltInArchiveFlags.IsSystem)   //系统文档可以单独显示
                {
            		RenderNotFound(context);
                    return;
                }

                category = archive.Category;

                if (!(category.ID>0))
                {
            		RenderNotFound(context);
                    return;
                }
                else
                {
                	string appPath = Cms.Context.SiteAppPath;
                    if (appPath != "/") appPath += "/";

                    if ((flag & BuiltInArchiveFlags.AsPage) == BuiltInArchiveFlags.AsPage)
                    {
                        string pattern = "^" + appPath + "[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$";
                        string pagePattern = "^" + appPath + "[\\.0-9A-Za-z_-]+\\.html$";

                        if (!Regex.IsMatch(context.Request.Path, pagePattern))
                        {
                            context.Response.StatusCode = 301;
                            context.Response.RedirectLocation = String.Format("{0}{1}.html",
                                appPath,
                                String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias
                                );
                            context.Response.End();
                            return;
                        }
                    }
                    else
                    {
                        //校验栏目是否正确
                        string categoryPath = category.UriPath;
                        string _path = appPath != "/" ? allhtml.Substring(appPath.Length - 1) : allhtml;

                        if (!_path.StartsWith(categoryPath + "/"))
                        {
            				RenderNotFound(context);
                            return;
                        }

                        //设置了别名,则跳转
                        if (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, true) != 0)
                        {
                            context.Response.StatusCode = 301;
                            context.Response.RedirectLocation = String.Format("{0}{1}/{2}.html",
                                 appPath,
                                 categoryPath,
                                 String.IsNullOrEmpty(archive.Alias) ? archive.StrId : archive.Alias
                                 );
                            context.Response.End();
                            return;

                        }
                    }


                    //增加浏览次数
                    ++archive.ViewCount;
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            ServiceCall.Instance.ArchiveService.AddCountForArchive(siteId, archive.Id, 1);
                        }
                        catch
                        {
                        }
                    }).Start();

                    //显示页面
                    html = cmsPage.GetArchive(archive);

                    //再次处理模板
                    //html = PageUtility.Render(html, new { }, false); 
                }
            }

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