/// <summary> /// 生成内容页 /// </summary> /// <param name="news"></param> /// <param name="cls"></param> public string CreateContentPage(News news, Class cls) { if (news.NavUrl.ToS().Trim().Length > 0)//如果是外部连接新闻 则不需要生成 { return string.Format("<script type='text/javascript'>location.href='';</script>", news.NavUrl); } TemplateContent temp = GetContentTemplate(cls); string Content = temp.Content; Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplaceSystemSetting(Content); Content = Content.Replace("[!--class.id--]", cls.ID.ToString()); Content = Content.Replace("[!--class.name--]", cls.ClassName); Content = Content.Replace("[!--class.url--]", BasePage.GetClassUrl(cls)); Content = ReplaceContent(Content, news, cls); Content = ReplaceTagContent(Content); #region 上一篇 下一篇 链接 News news_pre = BasePage.GetPreNews(news, cls); News news_next = BasePage.GetNextNews(news, cls); //上一篇 string pre_link = "<a href=\"javascript:void(0)\">没有了</a>"; if (news_pre != null) { pre_link = string.Format("<a id=\"btn_pre\" href=\"{0}\">{1}</a>", BasePage.GetNewsUrl(news_pre, cls), news_pre.Title); } Content = Content.Replace("[!--news.prelink--]", pre_link); //下一篇 string next_link = "<a href=\"javascript:void(0)\">没有了</a>"; if (news_next != null) { next_link = string.Format("<a id=\"btn_next\" href=\"{0}\">{1}</a>", BasePage.GetNewsUrl(news_next, cls), news_next.Title); } Content = Content.Replace("[!--news.nextlink--]", next_link); #endregion //替换导航条 Content = Content.Replace("[!--newsnav--]", BuildClassNavString(cls)); return Content; }
public string ReplaceContent(string TempString, News n, Class c) { return ReplaceContent(new TemplateList() { TimeFormat = "yyyy-MM-dd HH:mm:ss", CutTitle = 0 }, TempString, n, c); }
/// <summary> /// 替换新闻 /// </summary> /// <param name="TempString"></param> /// <param name="n"></param> /// <returns></returns> public string ReplaceContent(TemplateList temp, string TempString, News n, Class c) { string _title = "<font color='#" + n.TitleColor + "'>" + n.Title + "</font>"; if (n.TitleB.ToBoolean() == true) { _title = "<strong>" + _title + "</strong>"; } if (n.TitleI.ToBoolean() == true) { _title = "<I>" + _title + "</I>"; } if (n.TitleS.ToBoolean() == true) { _title = "<STRIKE>" + _title + "</STRIKE>"; } string r = TempString; r = r.Replace("[!--news.author--]", n.Author); r = r.Replace("[!--news.authorid--]", n.AutorID.ToS()); r = r.Replace("[!--news.classname--]", c.ClassName); r = r.Replace("[!--news.classid--]", n.ClassID.ToS()); r = r.Replace("[!--news.content--]", n.Content); r = r.Replace("[!--news.contenten--]", n.ContentEn); r = r.Replace("[!--news.description--]", n.Description); r = r.Replace("[!--news.downcount--]", n.DownCount.ToS()); r = r.Replace("[!--news.filefolder--]", n.FileForder); r = r.Replace("[!--news.filename--]", n.FileName); r = r.Replace("[!--news.ftile--]", n.FTitle); r = r.Replace("[!--news.id--]", n.ID.ToS()); r = r.Replace("[!--news.keywords--]", n.KeyWords); r = r.Replace("[!--news.navurl--]", n.NavUrl); r = r.Replace("[!--news.newstime--]", n.NewsTime.ToDateTime().ToString(temp.TimeFormat)); r = r.Replace("[!--news.source--]", n.Source); r = r.Replace("[!--news.title--]", n.Title); r = r.Replace("[!--news.oldtitle--]", n.Title); r = r.Replace("[!--news.ftitle--]", _title); r = r.Replace("[!--news.titlecolor--]", n.TitleColor); r = r.Replace("[!--news.titleimage--]", n.TitleImage); r = r.Replace("[!--news.ztid--]", n.ZtID.ToS()); r = r.Replace("[!--news.url--]", BasePage.GetNewsUrl(n, c)); return r; }
/// <summary> /// 用户投稿 /// </summary> /// <param name="news"></param> /// <param name="user"></param> /// <returns></returns> public static Result UserPost(News news, User user) { using (DataEntities ent = new DataEntities()) { Result r = new Result(); UserGroup g = (from l in ent.UserGroup where l.ID == user.Group select l).FirstOrDefault(); int? maxPost = 0; try { maxPost = g.MaxPost; } catch { } //验证用户是否允许投稿 if (maxPost <= 0) { r.Success = false; r.Text = "对不起,您没有投稿的权限!"; return r; } //验证本日投稿数是否已经过多 //int todayPost = NewsView.Count(string.Format("AutorID={0}", user.ID)); int todayPost = (from l in ent.News where l.AutorID == user.ID && l.NewsTime > DateTime.Now.Date && l.NewsTime < DateTime.Now.AddDays(1).Date select l).Count(); if (todayPost > maxPost && news.ID <= 0) { r.Success = false; r.Text = "对不起,您本日投稿数量已经达到最大限制,请明天继续!"; return r; } //验证标题是否为空 if (news.Title.IsNullOrEmpty()) { r.Success = false; r.Text = "文章标题不能为空"; return r; } //验证栏目 if (news.ClassID <= 0) { r.Success = false; r.Text = "栏目不能为空!"; return r; } news.Audit = g.PostAotuAudit; news.AutorID = user.ID; if (news.Author.IsNullOrEmpty()) { news.Author = user.UserName; } if (news.ID <= 0) { ent.AddToNews(news); } user.Cent += (from l in ent.Class where l.ID == news.ClassID select l).FirstOrDefault().PostAddCent; ent.SaveChanges(); r.Success = true; r.Text = "投递成功!"; return r; } }
protected void btn_Save_Click(object sender, EventArgs e) { DataEntities ent = new DataEntities(); User u=UserAction.opuser; UserGroup g = //UserGroupView.GetModelByID(u.Group.ToS()); (from l in ent.UserGroup where l.ID == u.Group select l).FirstOrDefault(); if (FileUpload1.FileName.IsNullOrEmpty()) { Js.AlertAndGoback("为提高您文章的排名,请选择一张标题图片"); return; } #region 上传图片 SysSetting ss = BasePage.SystemSetting; HttpPostedFile file = Request.Files["FileUpload1"]; string FileName = file.FileName.GetFileNameFromPath();//文件名 string ExtName = file.FileName.GetFileExtNameFromPath();//扩展名 string NewName = @string.GetGuid() + ExtName;//新文件名 if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(','))) { Js.AlertAndGoback("不允许上传此类文件"); return; } if (file.ContentLength > ss.MaxPostFileSize) { Js.AlertAndGoback("文件太大"); return; } string Folder = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";//文件目录 string FolderShotCut = Folder + "ShortCut/";//缩略图目录 string FilePath = Folder + NewName;//文件路径 string FilePath_ShortCut = FolderShotCut + NewName;//缩略图路径 file.SaveAs(Server.MapPath(FilePath), true); ImageHelper.MakeThumbnail(Server.MapPath(FilePath), Server.MapPath(FilePath_ShortCut), 105, 118, "Cut"); FileInfo savedFile = new FileInfo(Server.MapPath(FilePath)); Voodoo.Basement.File f = new Voodoo.Basement.File(); f.FileDirectory = ss.FileDir; f.FileExtName = ExtName; f.FilePath = FilePath; f.FileSize = (savedFile.Length / 1024).ToInt32(); //f.FileType= f.SmallPath = FilePath_ShortCut; f.UpTime = DateTime.Now; ent.AddToFile(f); ent.SaveChanges(); #endregion News n = new News(); n.Author = txt_Author.Text.TrimDbDangerousChar(); n.AutorID = UserAction.opuser.ID; n.ClassID = ddl_Class.SelectedValue.ToInt32(); n.ClickCount = 0; n.Content = txt_Content.Text.TrimDbDangerousChar(); n.Description = txt_Description.Text.TrimDbDangerousChar(); n.DownCount = 0; n.EnableReply = false; n.FTitle = txtFtitle.Text.TrimDbDangerousChar(); n.KeyWords = txt_Keyword.Text.TrimDbDangerousChar(); n.ModelID = 0; n.NavUrl = ""; n.NewsTime = DateTime.Now; n.SetTop = false; n.Source = txt_Source.Text.TrimDbDangerousChar(); n.Title = txt_Title.Text.TrimDbDangerousChar(); n.TitleColor = "000"; n.TitleImage = FilePath;//上传图片 n.ZtID = 0; n.Audit = g.PostAotuAudit; n.FileForder = DateTime.Now.ToString("yyyy-MM-dd"); n.ID = WS.RequestInt("id"); Result r=NewsAction.UserPost(n, UserAction.opuser); if (r.Success) { Js.AlertAndChangUrl(r.Text, "PostList.aspx"); } else { Js.AlertAndGoback(r.Text); } ent.Dispose(); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Save_Click(object sender, EventArgs e) { DataEntities ent = new DataEntities(); cls = WS.RequestInt("class", 0); zt = WS.RequestInt("zt", 0); url = string.Format("NewsList.aspx?class={0}&zt={1}", cls, zt); News n = new News(); if (WS.RequestInt("id") > 0) { n = //NewsView.GetModelByID(WS.RequestString("id")); (from l in ent.News where l.ID == id select l).FirstOrDefault(); cls = n.ClassID.ToInt32(); } else { n.ClassID = cls; n.ZtID = zt; } Class c = NewsAction.NewsClass.Where(p => p.ID.ToString() == ddl_Class.SelectedValue).First(); n.ClassID = ddl_Class.SelectedValue.ToInt32(); n.Title = txt_Title.Text.TrimDbDangerousChar(); n.TitleColor = cp_TitleColor.Value.TrimDbDangerousChar(); n.TitleB = chk_TitleB.Checked; n.TitleI = chk_TitleI.Checked; n.TitleS = chk_TitleS.Checked; n.FTitle = txt_FTitle.Text.TrimDbDangerousChar(); n.Audit = chk_Audit.Checked; n.Tuijian = chk_Tuijian.Checked; n.Toutiao = chk_Toutiao.Checked; n.KeyWords = txt_Key.Text.TrimDbDangerousChar(); //关键词写入系统 txt_Key.Text = Regex.Replace(txt_Key.Text, "\\s", ","); string[] keys = Regex.Replace(txt_Key.Text, "\\s", ",").Split(','); foreach (string k in keys) { InsertKeyWords(1, k); } n.NavUrl = txt_NavUrl.Text.TrimDbDangerousChar(); n.NewsTime=txt_NewsTime.Text.ToDateTime(); n.TitleImage = txt_TitleImage.Text.TrimDbDangerousChar(); n.Description = txt_Description.Text.TrimDbDangerousChar(); n.Author = txt_Author.Text.TrimDbDangerousChar(); n.Source = txt_Source.Text.TrimDbDangerousChar(); n.Content = FCKeditor1.Text.TrimDbDangerousChar(); //n.ContentEn = FCKeditor2.Text.TrimDbDangerousChar(); n.SetTop = chk_SetTop.Checked; n.EnableReply = !chk_CloseReply.Checked; n.ModelID = ddl_contentTemp.SelectedValue.ToInt32(); n.ClickCount = txt_ClickCount.Text.ToInt32(); n.DownCount = txt_DownCount.Text.ToInt32(); n.FileForder = txt_FileForder.Text; n.FileName = txt_FileName.Text; n.ReplyCount = 0; if (id <= 0) { ent.AddToNews(n); } ent.SaveChanges(); ent.Dispose(); if (SystemSetting.EnableStatic) { CreatePage.CreateContentPage(n, c); News news_pre = GetPreNews(n, c); if (news_pre != null) { CreatePage.CreateContentPage(news_pre, c); } switch (c.EditcreateList) { case 0: break; case 1: CreatePage.CreateListPage(c, 1); break; case 2: CreatePage.GreateIndexPage(); break; case 3: case 4: CreatePage.CreateListPage(c, 1); break; case 5: CreatePage.GreateIndexPage(); break; case 6: CreatePage.CreateListPage(c, 1); CreatePage.GreateIndexPage(); break; } } Js.AlertAndChangUrl("保存成功!",url); }