Ejemplo n.º 1
0
 /// <summary>
 /// 向浏览器完整XML内容
 /// </summary>
 public string OutWrite(int id, string local)
 {
     SettingItem setting = this._setting;
     //获取页面数据
     PostItem pg = new PostItem();
     if (id > 0)
     {
         if (SiteDat.GetDat(string.Format(SiteCache.PostFormat, id)) == null)
         {
             SiteDat.SetDat(string.Format(SiteCache.PostFormat, id), new PostData(conn).GetPost(id));
         }
         pg = (PostItem)SiteDat.GetDat(string.Format(SiteCache.PostFormat, id));
     }
     else
     {
         if (SiteDat.GetDat(string.Format(SiteCache.PostFormat, local)) == null)
         {
             SiteDat.SetDat(string.Format(SiteCache.PostFormat, local), new PostData(conn).GetPost(local));
         }
         pg = (PostItem)SiteDat.GetDat(string.Format(SiteCache.PostFormat, local));
     }
     //本页XML处理
     StringBuilder xml = new StringBuilder();
     xml.Append("\t\t<page>\n");
     xml.AppendFormat("\t\t\t<link>{0}</link>\n", SiteFun.CDATA(string.Format(SitePath.PageLinkFormat, SiteCfg.Path, SiteFun.UrlEncode(pg.Local))));
     xml.AppendFormat("\t\t\t<id>{0}</id>\n", pg.ID);
     xml.AppendFormat("\t\t\t<local>{0}</local>\n", SiteFun.CDATA(pg.Local));
     xml.AppendFormat("\t\t\t<title>{0}</title>\n", SiteFun.CDATA(pg.Title));
     xml.AppendFormat("\t\t\t<content>{0}</content>\n", SiteFun.CDATA(pg.Content));
     xml.AppendFormat("\t\t\t<publish>{0}</publish>\n", pg.Publish);
     xml.Append("\t\t</page>\n");
     //绑定XML并写出
     string title = string.Empty;
     if (pg.ID > 0) { title = string.Format("{0} - {1}", pg.Title, setting.Basic.Name); }
     return new _WebBaseXml(conn).OutBaseXml(title, xml.ToString());
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取文章内容页完整XML内容
        /// </summary>
        /// <param name="id">文章编号</param>
        /// <param name="local">文章标签</param>
        /// <param name="pwd">文章密码</param>
        /// <param name="page">当前页(评论用)</param>
        /// <param name="pageSize">分页大小(评论用)</param>
        /// <returns>完整XML内容</returns>
        public string OutWriteView(int id, string local, string pwd, int page, int pageSize)
        {
            SettingItem setting = this.OutSetting;
            PostData artData = new PostData(conn);
            SiteDat SiteDat = new SiteDat();
            //取得文章列表数据
            PostItem art = new PostItem();
            if (id > 0)
            {
                if (SiteDat.GetDat(string.Format(SiteCache.PostFormat, id)) == null)
                {
                    SiteDat.SetDat(string.Format(SiteCache.PostFormat, id), artData.GetPost(id));
                }
                art = (PostItem)SiteDat.GetDat(string.Format(SiteCache.PostFormat, id));
            }
            else
            {
                if (SiteDat.GetDat(string.Format(SiteCache.PostFormat, local)) == null)
                {
                    SiteDat.SetDat(string.Format(SiteCache.PostFormat, local), artData.GetPost(local));
                }
                art = (PostItem)SiteDat.GetDat(string.Format(SiteCache.PostFormat, local));
            }
            //取得栏目数据
            ColumnItem columnItem = new ColumnItem();
            if (SiteDat.GetDat(string.Format(SiteCache.ColumnFormat, art.ColumnID)) == null)
            {
                SiteDat.SetDat(string.Format(SiteCache.ColumnFormat, art.ColumnID), new ColumnData(conn).GetColumn(art.ColumnID));
            }
            columnItem = (ColumnItem)SiteDat.GetDat(string.Format(SiteCache.ColumnFormat, art.ColumnID));

            artData.AddPostReader(art.ID);
            //设置模板引擎
            //设置密码文章显示状态
            bool viewPwdArt = pwd == art.Password;
            //本页XML处理
            StringBuilder xml = new StringBuilder();
            xml.Append("\t\t<article>\n");
            xml.AppendFormat("\t\t\t\t<link>{0}</link>\n", SiteFun.CDATA(string.Format(SitePath.ArticleLinkFormat, SiteCfg.Path, SiteFun.UrlEncode(art.Local))));
            xml.AppendFormat("\t\t\t\t<id>{0}</id>\n", art.ID);
            xml.AppendFormat("\t\t\t\t<title>{0}</title>\n", SiteFun.CDATA(art.Title));
            xml.AppendFormat("\t\t\t\t<local>{0}</local>\n", SiteFun.CDATA(art.Local));
            xml.AppendFormat("\t\t\t\t<tags>{0}</tags>\n", SiteFun.CDATA(art.Tags));
            xml.Append("\t\t\t\t<category>\n");
            xml.AppendFormat("\t\t\t\t\t<link>{0}</link>\n", SiteFun.CDATA(string.Format(SitePath.CategoryLinkFormat, SiteCfg.Path, SiteFun.UrlEncode(columnItem.Local))));
            xml.AppendFormat("\t\t\t\t\t<id>{0}</id>\n", columnItem.ID);
            xml.AppendFormat("\t\t\t\t\t<local>{0}</local>\n", SiteFun.CDATA(columnItem.Local));
            xml.AppendFormat("\t\t\t\t\t<name>{0}</name>\n", SiteFun.CDATA(columnItem.Name));
            xml.AppendFormat("\t\t\t\t\t<intro>{0}</intro>\n", SiteFun.CDATA(columnItem.Intro));
            xml.AppendFormat("\t\t\t\t\t<postCount>{0}</postCount>\n", columnItem.PostCount);
            xml.Append("\t\t\t\t</category>\n");
            xml.AppendFormat("\t\t\t\t<explain>{0}</explain>\n", SiteFun.CDATA(CheckPasswordContent(art.Password, art.Explain, art.Local, viewPwdArt)));
            xml.AppendFormat("\t\t\t\t<content>{0}</content>\n", SiteFun.CDATA(CheckPasswordContent(art.Password, art.Content, art.Local, viewPwdArt)));
            xml.AppendFormat("\t\t\t\t<publish>{0}</publish>\n", art.Publish);
            xml.AppendFormat("\t\t\t\t<author>{0}</author>\n", SiteFun.CDATA(art.Author));
            xml.AppendFormat("\t\t\t\t<postCount>{0}</postCount>\n", art.PostCount);
            xml.AppendFormat("\t\t\t\t<reader>{0}</reader>\n", art.Reader);
            xml.AppendFormat("\t\t\t\t<vote>{0}</vote>\n", art.Vote);
            xml.Append("\t\t</article>\n");
            xml.Append("\t\t<comments>\n");
            xml.AppendFormat("\t\t\t<html>{0}</html>\n", SiteFun.CDATA(new CommentUI(conn).GetCommentList(art.ID, page, pageSize)));
            xml.Append("\t\t</comments>\n");
            //绑定XML并写出
            string title = string.Empty;
            if (art.ID > 0) { title = string.Format("{0} - {1} - {2}", art.Title, columnItem.Name, setting.Basic.Name); }
            return new _WebBaseXml(conn).OutBaseXml(title, xml.ToString());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 更新一篇文章
 /// </summary>
 /// <param name="value">文章数据</param>
 /// <returns>返回被修改文章的编号</returns>
 public int UpdatePost(PostItem value)
 {
     int id = 0;
     _DbParameter[] pars ={
                              new _DbParameter().Set("@CID", DbType.Int32, value.ColumnID),
                              new _DbParameter().Set("@Tags", DbType.String, value.Tags),
                              new _DbParameter().Set("@Local", DbType.String, value.Local),
                              new _DbParameter().Set("@Title", DbType.String, value.Title),
                              new _DbParameter().Set("@Explain", DbType.String, value.Explain),
                              new _DbParameter().Set("@Content", DbType.String, value.Content),
                              new _DbParameter().Set("@Author", DbType.String, value.Author),
                              new _DbParameter().Set("@Publish", DbType.String, value.Publish.ToString("yyyy-MM-dd HH:mm:ss")),
                              new _DbParameter().Set("@Password", DbType.String, value.Password),
                              new _DbParameter().Set("@Fine", DbType.Int32, value.Fine ? 1 : 0),
                              new _DbParameter().Set("@Vote", DbType.Int32, value.Vote),
                              new _DbParameter().Set("@Reader", DbType.Int32, value.Reader),
                              new _DbParameter().Set("@PostCount", DbType.Int32, value.PostCount),
                              new _DbParameter().Set("@Show", DbType.Int32, value.Show ? 1 : 0),
                              new _DbParameter().Set("@SwitchCMT", DbType.Int32, value.SwitchComment ? 1 : 0),
                              new _DbParameter().Set("@SwitchTB", DbType.Int32, value.SwitchTrackback ? 1 : 0),
                              new _DbParameter().Set("@AVCMT", DbType.Int32, value.AutoVerifyComment ? 1 : 0),
                              new _DbParameter().Set("@AVTB", DbType.Int32, value.AutoVerifyTrackback ? 1 : 0),
                              new _DbParameter().Set("@Atts", DbType.String, value.Attachments),
                              new _DbParameter().Set("@ID", DbType.Int32, value.ID)
                          };
     conn.ExecuteNonQuery("UPDATE [Post] SET [ColumnID] = @CID, [Tags] = @Tags, [Local] = @Local, [Title] = @Title, [Explain] = @Explain, [Content] = @Content, [Author] = @Author, [Publish] = @Publish, [Password] = @Password, [Fine] = @Fine, [Vote] = @Vote, [Reader] = @Reader, [PostCount] = @PostCount, [Show] = @Show, [SwitchCMT] = @SwitchCMT, [SwitchTB] = @SwitchTB, [AutoVerifyCMT] = @AVCMT, [AutoVerifyTB] = @AVTB, [Attachments] = @Atts WHERE [ID] = @ID", pars);
     id = value.ID;
     if (string.IsNullOrEmpty(value.Local))
     {
         conn.ExecuteNonQuery(string.Format("UPDATE [Post] SET [Local] = [ID] WHERE [ID] = {0}", id));
     }
     return id;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 选择相关文章
 /// </summary>
 /// <param name="outId">例外文章编号</param>
 /// <param name="limit">取得行数</param>
 /// <param name="tags">标签列表</param>
 /// <param name="mode">模式:A-文章,P-单页</param>
 /// <param name="selAll">是否在所有数据里筛选</param>
 /// <returns>返回文章数据列表</returns>
 public DataList<PostItem> SelectRelatedPost(int outId, int limit, string tags, string mode, bool selAll)
 {
     if (!string.IsNullOrEmpty(tags)) { tags = DataBase.SqlEncode(tags); }
     DataList<PostItem> list = new DataList<PostItem>();
     string sqlWhere = string.Format("[Mode] = '{0}'", mode);
     sqlWhere += selAll ? string.Empty : " AND ([Show] <> 0)";
     if (!string.IsNullOrEmpty(tags))
     {
         sqlWhere += " AND (";
         string[] arrTag = tags.Split(',');
         bool noOne = false;
         foreach (string tag in arrTag)
         {
             if (!string.IsNullOrEmpty(tag))
             {
                 sqlWhere += noOne ? " OR" : string.Empty;
                 sqlWhere += string.Format(" ([Tags] = '{0}' OR [Tags] LIKE '{0},%' OR [Tags] LIKE '%,{0},%' OR [Tags] LIKE '%,{0}')", tag.Trim());
                 noOne = true;
             }
         }
         sqlWhere += ")";
     }
     int rows = 0;
     using (IDataReader reader = conn.ExecutePager("[Post]", "[ID], [ColumnID], [Tags], [Local], [Title], [Explain], [Content], [Author], [Publish], [Password], [Fine], [Vote], [Reader], [PostCount], [Show], [SwitchCMT], [SwitchTB], [AutoVerifyCMT], [AutoVerifyTB], [Attachments]", sqlWhere, "[ID]", "DESC", 1, limit, ref rows))
     {
         while (reader.Read())
         {
             PostItem item = new PostItem();
             item.ID = reader.GetInt32(0);
             item.ColumnID = reader.GetInt32(1);
             item.Tags = reader.GetString(2);
             item.Local = reader.GetString(3);
             item.Title = reader.GetString(4);
             item.Explain = reader.GetString(5);
             item.Content = reader.GetString(6);
             item.Author = reader.GetString(7);
             item.Publish = reader.GetDateTime(8);
             item.Password = reader.GetString(9);
             item.Fine = reader.GetInt32(10) == 0 ? false : true;
             item.Vote = reader.GetInt32(11);
             item.Reader = reader.GetInt32(12);
             item.PostCount = reader.GetInt32(13);
             item.Show = reader.GetInt32(14) == 0 ? false : true;
             item.SwitchComment = reader.GetInt32(15) == 0 ? false : true;
             item.SwitchTrackback = reader.GetInt32(16) == 0 ? false : true;
             item.AutoVerifyComment = reader.GetInt32(17) == 0 ? false : true;
             item.AutoVerifyTrackback = reader.GetInt32(18) == 0 ? false : true;
             item.Attachments = reader.GetString(19);
             list.Add(item);
         }
     }
     list.Number = rows;
     return list;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 选择文章
 /// </summary>
 /// <param name="cid">分类ID,为0则选择全部数据</param>
 /// <param name="tag">标签字段</param>
 /// <param name="key">搜索关键字</param>
 /// <param name="intCurPage">当前页码</param>
 /// <param name="btePerPage">分页大小</param>
 /// <param name="orderMode">排序模式:0-按时间倒序,1-编号倒序,2-按阅读数倒序,3-按投票数,4-随机</param>
 /// <param name="mode">模式:A-文章,P-单页</param>
 /// <param name="selAll">是否在所有数据里筛选</param>
 /// <returns>返回文章数据列表</returns>
 public DataList<PostItem> SelectPost(int cid, string tag, string key, int intCurPage, int btePerPage, int orderMode, string mode, bool selAll)
 {
     string putOrder = orderMode == 4 ? string.Empty : "[Fine] DESC, ";
     if (!string.IsNullOrEmpty(tag)) { tag = DataBase.SqlEncode(tag); }
     if (!string.IsNullOrEmpty(key)) { key = DataBase.SqlEncode(key); }
     DataList<PostItem> list = new DataList<PostItem>();
     string[] orderPar = { "[Publish]", "DESC" };
     switch (orderMode)
     {
         case 1: { orderPar[0] = "[ID]"; orderPar[1] = "DESC"; break; }
         case 2: { orderPar[0] = "[Reader]"; orderPar[1] = "DESC"; break; }
         case 3: { orderPar[0] = "[Vote]"; orderPar[1] = "DESC"; break; }
         case 4: { orderPar[0] = (conn.DBMode == DbMode.MSSQL ? "NEWID()" : "RND([ID])"); orderPar[1] = string.Empty; break; }
     }
     string sqlWhere = string.IsNullOrEmpty(mode) ? "[ID] > 0" : string.Format("[Mode] = '{0}'", mode);
     sqlWhere += cid == 0 ? string.Empty : string.Format(" AND ([ColumnID] = {0})", cid);
     sqlWhere += selAll ? string.Empty : " AND ([Show] <> 0)";
     sqlWhere += string.IsNullOrEmpty(tag) ? string.Empty : string.Format(" AND ([Tags] = '{0}' OR [Tags] LIKE '{0},%' OR [Tags] LIKE '%,{0},%' OR [Tags] LIKE '%,{0}')", tag);
     sqlWhere += string.IsNullOrEmpty(key) ? string.Empty : string.Format(" AND ([Title] LIKE '%{0}%' OR [Content] LIKE '%{0}%')", key);
     int rows = 0;
     using (IDataReader reader = conn.ExecutePager("[Post]", "[ID], [ColumnID], [Tags], [Local], [Title], [Explain], [Content], [Author], [Publish], [Password], [Fine], [Vote], [Reader], [PostCount], [Show], [SwitchCMT], [SwitchTB], [AutoVerifyCMT], [AutoVerifyTB], [Attachments]", sqlWhere, putOrder + orderPar[0], orderPar[1], intCurPage, btePerPage, ref rows))
     {
         while (reader.Read())
         {
             PostItem item = new PostItem();
             item.ID = reader.GetInt32(0);
             item.ColumnID = reader.GetInt32(1);
             item.Tags = reader.GetString(2);
             item.Local = reader.GetString(3);
             item.Title = reader.GetString(4);
             item.Explain = reader.GetString(5);
             item.Content = reader.GetString(6);
             item.Author = reader.GetString(7);
             item.Publish = reader.GetDateTime(8);
             item.Password = reader.GetString(9);
             item.Fine = reader.GetInt32(10) == 0 ? false : true;
             item.Vote = reader.GetInt32(11);
             item.Reader = reader.GetInt32(12);
             item.PostCount = reader.GetInt32(13);
             item.Show = reader.GetInt32(14) == 0 ? false : true;
             item.SwitchComment = reader.GetInt32(15) == 0 ? false : true;
             item.SwitchTrackback = reader.GetInt32(16) == 0 ? false : true;
             item.AutoVerifyComment = reader.GetInt32(17) == 0 ? false : true;
             item.AutoVerifyTrackback = reader.GetInt32(18) == 0 ? false : true;
             item.Attachments = reader.GetString(19);
             list.Add(item);
         }
     }
     list.Number = rows;
     return list;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 增加一篇文章
 /// </summary>
 /// <param name="value">文章数据</param>
 /// <param name="mode">模式:A-文章,P-单页</param>
 /// <returns>返回新增文章的编号</returns>
 public int InsertPost(PostItem value, string mode)
 {
     int id = 0;
     _DbParameter[] pars ={
                              new _DbParameter().Set("@CID", DbType.Int32, value.ColumnID),
                              new _DbParameter().Set("@Tags", DbType.String, value.Tags),
                              new _DbParameter().Set("@Local", DbType.String, value.Local),
                              new _DbParameter().Set("@Title", DbType.String, value.Title),
                              new _DbParameter().Set("@Explain", DbType.String, value.Explain),
                              new _DbParameter().Set("@Content", DbType.String, value.Content),
                              new _DbParameter().Set("@Author", DbType.String, value.Author),
                              new _DbParameter().Set("@Publish", DbType.String, value.Publish.ToString("yyyy-MM-dd HH:mm:ss")),
                              new _DbParameter().Set("@Password", DbType.String, value.Password),
                              new _DbParameter().Set("@Fine", DbType.Int32, value.Fine ? 1 : 0),
                              new _DbParameter().Set("@Vote", DbType.Int32, value.Vote),
                              new _DbParameter().Set("@Reader", DbType.Int32, value.Reader),
                              new _DbParameter().Set("@PostCount", DbType.Int32, value.PostCount),
                              new _DbParameter().Set("@Show", DbType.Int32, value.Show ? 1 : 0),
                              new _DbParameter().Set("@SwitchCMT", DbType.Int32, value.SwitchComment ? 1 : 0),
                              new _DbParameter().Set("@SwitchTB", DbType.Int32, value.SwitchTrackback ? 1 : 0),
                              new _DbParameter().Set("@AVCMT", DbType.Int32, value.AutoVerifyComment ? 1 : 0),
                              new _DbParameter().Set("@AVTB", DbType.Int32, value.AutoVerifyTrackback ? 1 : 0),
                              new _DbParameter().Set("@Mode", DbType.String, mode),
                              new _DbParameter().Set("@Atts", DbType.String, value.Attachments)
                          };
     conn.ExecuteNonQuery("INSERT INTO [Post] ([ColumnID], [Tags], [Local], [Title], [Explain], [Content], [Author], [Publish], [Password], [Fine], [Vote], [Reader], [PostCount], [Show], [SwitchCMT], [SwitchTB], [AutoVerifyCMT], [AutoVerifyTB], [Mode], [Attachments]) VALUES (@CID, @Tags, @Local, @Title, @Explain, @Content, @Author, @Publish, @Password, @Fine, @Vote, @Reader, @PostCount, @Show, @SwitchCMT, @SwitchTB, @AVCMT, @AVTB, @Mode, @Atts)", pars);
     conn.ExecuteNonQuery(string.Format("UPDATE [Column] SET [PostCount] = [PostCount] + 1 WHERE [ID] = {0}", value.ColumnID));
     id = Convert.ToInt32(conn.ExecuteNewField("[Post]", null, null));
     if (string.IsNullOrEmpty(value.Local))
     {
         conn.ExecuteNonQuery(string.Format("UPDATE [Post] SET [Local] = [ID] WHERE [ID] = {0}", id));
     }
     return id;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 选择文章
 /// </summary>
 /// <param name="local">文章永久链接</param>
 /// <returns>返回文章数据</returns>
 public PostItem GetPost(string local)
 {
     _DbParameter[] pars ={
                              new _DbParameter().Set("@Local", DbType.String, local)
                          };
     PostItem item = new PostItem();
     int rows = 0;
     using (IDataReader reader = conn.ExecutePager("[Post]", "[ID], [ColumnID], [Tags], [Local], [Title], [Explain], [Content], [Author], [Publish], [Password], [Fine], [Vote], [Reader], [PostCount], [Show], [SwitchCMT], [SwitchTB], [AutoVerifyCMT], [AutoVerifyTB], [Attachments]", "[Local] = @Local", "[ID]", "DESC", 1, 1, pars, ref rows))
     {
         if (reader.Read())
         {
             item.ID = reader.GetInt32(0);
             item.ColumnID = reader.GetInt32(1);
             item.Tags = reader.GetString(2);
             item.Local = reader.GetString(3);
             item.Title = reader.GetString(4);
             item.Explain = reader.GetString(5);
             item.Content = reader.GetString(6);
             item.Author = reader.GetString(7);
             item.Publish = reader.GetDateTime(8);
             item.Password = reader.GetString(9);
             item.Fine = reader.GetInt32(10) == 0 ? false : true;
             item.Vote = reader.GetInt32(11);
             item.Reader = reader.GetInt32(12);
             item.PostCount = reader.GetInt32(13);
             item.Show = reader.GetInt32(14) == 0 ? false : true;
             item.SwitchComment = reader.GetInt32(15) == 0 ? false : true;
             item.SwitchTrackback = reader.GetInt32(16) == 0 ? false : true;
             item.AutoVerifyComment = reader.GetInt32(17) == 0 ? false : true;
             item.AutoVerifyTrackback = reader.GetInt32(18) == 0 ? false : true;
             item.Attachments = reader.GetString(19);
         }
     }
     return item;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 获取附近文章
 /// </summary>
 /// <param name="thisId">当前文章编号</param>
 /// <param name="desc">是否正常排序,否则倒序</param>
 /// <param name="mode">模式:A-文章,P-单页</param>
 /// <returns>返回附近文章数据</returns>
 public PostItem GetClosePost(int thisId, bool desc, string mode)
 {
     string[] pa = { ">", "ASC" };
     if (!desc) { pa[0] = "<"; pa[1] = "DESC"; }
     PostItem item = new PostItem();
     int rows = 0;
     using (IDataReader reader = conn.ExecutePager("[Post]", "[ID], [ColumnID], [Tags], [Local], [Title], [Explain], [Content], [Author], [Publish], [Password], [Fine], [Vote], [Reader], [PostCount], [Show], [SwitchCMT], [SwitchTB], [AutoVerifyCMT], [AutoVerifyTB], [Attachments]", string.Format("[Mode] = '{2}' AND [ID] {0} {1}", pa[0], thisId, mode), "[Publish]", pa[1], 1, 1, ref rows))
     {
         while (reader.Read())
         {
             item.ID = reader.GetInt32(0);
             item.ColumnID = reader.GetInt32(1);
             item.Tags = reader.GetString(2);
             item.Local = reader.GetString(3);
             item.Title = reader.GetString(4);
             item.Explain = reader.GetString(5);
             item.Content = reader.GetString(6);
             item.Author = reader.GetString(7);
             item.Publish = reader.GetDateTime(8);
             item.Password = reader.GetString(9);
             item.Fine = reader.GetInt32(10) == 0 ? false : true;
             item.Vote = reader.GetInt32(11);
             item.Reader = reader.GetInt32(12);
             item.PostCount = reader.GetInt32(13);
             item.Show = reader.GetInt32(14) == 0 ? false : true;
             item.SwitchComment = reader.GetInt32(15) == 0 ? false : true;
             item.SwitchTrackback = reader.GetInt32(16) == 0 ? false : true;
             item.AutoVerifyComment = reader.GetInt32(17) == 0 ? false : true;
             item.AutoVerifyTrackback = reader.GetInt32(18) == 0 ? false : true;
             item.Attachments = reader.GetString(19);
         }
     }
     return item;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 提交文章窗体
        /// </summary>
        /// <param name="mode">模式:A-文章,P-单页</param>
        /// <returns>返回发布文章控件代码</returns>
        public string Post(string mode)
        {
            StringBuilder sr = new StringBuilder();
            if (mode == "A" || mode == "P")
            {
                bool isArticle = mode == "A";
                SettingItem setting = new SettingData(conn).GetSetting();
                string theme = new SettingData(conn).GetTheme;
                string tmpFilePath = Path.Combine(SiteCfg.Router, "Common/Temp/post_cache.tmp");
                int id = SiteFun.ToInt(SiteFun.Query("id"));
                PostData artData = new PostData(conn);
                ColumnData cData = new ColumnData(conn);
                TagData tagData = new TagData(conn);
                //取得默认值
                string[] myUserInfo = _ac.Get();
                UserItem myUser = new UserData(conn).CheckUser(myUserInfo[0], SiteFun.Encryption(myUserInfo[1]), true);
                PostItem old = artData.GetPost(id);
                ColumnItem oldColumn = new ColumnData(conn).GetColumn(old.ColumnID);
                if (old.ID == 0)
                {
                    //默认显示、可评论并自动审核,可发通告
                    old.Show = true;
                    old.SwitchComment = true;
                    old.AutoVerifyComment = true;
                    old.SwitchTrackback = true;
                }
                if (string.IsNullOrEmpty(old.Author)) { old.Author = myUser.Name; }
                if (SiteFun.IsPost)
                {
                    //处理文章数据
                    PostItem postVal = new PostItem();
                    string content = SiteFun.HtmlMatch(SiteFun.Post("content"));
                    string explain = content;
                    if (!string.IsNullOrEmpty(explain))
                    {
                        explain = Regex.Replace(explain, SiteCfg.PageBreakRegular, SiteCfg.PageBreakSymbol, RegexOptions.Multiline | RegexOptions.IgnoreCase);
                        if (explain.IndexOf(SiteCfg.PageBreakSymbol) > 0)
                        {
                            explain = explain.Substring(0, explain.IndexOf(SiteCfg.PageBreakSymbol));
                            explain = SiteFun.HtmlMatch(explain);
                        }
                        explain = explain.Replace(SiteCfg.PageBreakSymbol, string.Empty);
                    }
                    postVal.ID = id;
                    postVal.ColumnID = SiteFun.ToInt(SiteFun.Post("cid"));
                    postVal.Title = SiteFun.Post("title");
                    postVal.Tags = SiteFun.Post("tags");
                    postVal.Local = SiteFun.Post("local");
                    postVal.Explain = explain;
                    postVal.Content = content;
                    postVal.Author = SiteFun.Post("author");
                    postVal.Publish = SiteFun.ToDate(SiteFun.Post("publish"));
                    postVal.Password = SiteFun.Post("pwd");
                    postVal.Vote = SiteFun.ToInt(SiteFun.Post("vote"));
                    postVal.Reader = SiteFun.ToInt(SiteFun.Post("reader"));
                    postVal.Fine = SiteFun.ToInt(SiteFun.Post("fine")) == 0 ? false : true;
                    postVal.Show = SiteFun.ToInt(SiteFun.Post("show")) == 0 ? false : true;
                    postVal.PostCount = old.PostCount;
                    postVal.SwitchComment = SiteFun.ToInt(SiteFun.Post("switchCmt")) == 0 ? false : true;
                    postVal.SwitchTrackback = SiteFun.ToInt(SiteFun.Post("switchTb")) == 0 ? false : true;
                    postVal.AutoVerifyComment = SiteFun.ToInt(SiteFun.Post("avcmt")) == 0 ? false : true;
                    postVal.AutoVerifyTrackback = SiteFun.ToInt(SiteFun.Post("avtb")) == 0 ? false : true;
                    postVal.Attachments = old.Attachments;
                    //分类
                    ColumnItem postColumn = new ColumnData(conn).GetColumn(postVal.ColumnID);
                    if (string.IsNullOrEmpty(postVal.Title)) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgNoTitle"))); }
                    else
                    {
                        if (!string.IsNullOrEmpty(postVal.Local)) { postVal.Local = postVal.Local.Replace(" ", "-"); }
                        if (!string.IsNullOrEmpty(postVal.Local) && (!SiteFun.IsLocal(postVal.Local) || artData.ExistsLocal(postVal.Local, postVal.ID))) { sr.Append(AdminUI.ErrorBox(SiteDat.GetLan("MsgNoLocalOrExists"))); }
                        else
                        {
                            //处理上传图片的内容循环替换
                            if (!string.IsNullOrEmpty(postVal.Content))
                            {
                                string[] tmpFilesHandle = { postVal.Content, postVal.Explain };
                                string atts = new _AdminUpload(conn).SaveAs(HttpContext.Current.Request.Files, ref tmpFilesHandle[0], ref tmpFilesHandle[1], SiteFun.ToInt(SiteFun.Post("ws")), Path.Combine(SiteCfg.Router, setting.Parameter.WatermarkPath));
                                postVal.Content = tmpFilesHandle[0];
                                postVal.Explain = tmpFilesHandle[1];
                                if (!string.IsNullOrEmpty(atts))
                                {
                                    if (string.IsNullOrEmpty(postVal.Attachments)) { postVal.Attachments = atts; }
                                    else { postVal.Attachments += "," + atts; }
                                }
                            }
                            //保存或新增文章数据处理
                            if (postVal.ID == 0)
                            {
                                artData.InsertPost(postVal, mode);
                                //标签处理
                                tagData.InsertTagList(postVal.Tags);
                                //分类统计
                                //cData.CountCategoryPost(postVal.Category.ID);
                                sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgArtInsertSucc"), "?act=post&mode=list&M=" + mode));
                            }
                            else
                            {
                                artData.UpdatePost(postVal);
                                //标签处理
                                tagData.InsertTagList(postVal.Tags);
                                //类统计
                                cData.CountColumnPost(oldColumn.ID);
                                cData.CountColumnPost(postColumn.ID);
                                //更新修改后的显示
                                sr.Append(AdminUI.SuccessBox(SiteDat.GetLan("MsgArtUpdateSucc"), "?act=post&mode=list&M=" + mode));
                            }
                            try { File.Delete(tmpFilePath); }
                            catch { }
                        }
                    }
                    //处理引用通告
                    TrackbackLogData tbld = new TrackbackLogData(conn);
                    SettingBasicItem sbi = setting.Basic;
                    string tbUrls = SiteFun.Post("tbUrls");
                    if (!string.IsNullOrEmpty(tbUrls))
                    {
                        foreach (string vItem in tbUrls.Split('\n'))
                        {
                            if (!string.IsNullOrEmpty(vItem))
                            {
                                string[] tbState = new SiteTrackback().SendTrackback(vItem, string.Format(SitePath.ArticleLinkFormat, sbi.URL + SiteCfg.Path, postVal.Local), sbi.Name, postVal.Title, SiteFun.ClearHtml(postVal.Explain)).Split('|');
                                TrackbackLogItem tbVal = new TrackbackLogItem();
                                tbVal.Error = SiteFun.ToInt(tbState[0]) == 0 ? false : true;
                                tbVal.Message = tbState[1];
                                tbVal.URL = vItem;
                                tbld.InsertTrackbackLog(tbVal);
                            }
                        }
                    }
                    ClearCache();
                    old = postVal;
                }
                //设置分类数据
                DataList<ColumnItem> cateList = cData.SelectColumn(-1, 0, true);
                ArrayList values = new ArrayList();
                ArrayList captions = new ArrayList();
                for (int i = 0; i < cateList.Count; i++)
                {
                    values.Add(cateList[i].ID);
                    captions.Add(cateList[i].Name);
                }
                sr.Append(AdminUI.AdminBoxStart(true));
                sr.Append(HtmlUI.FormStart(null, true));

                sr.Append(HtmlUI.TableStart("onCenter advancedBox"));
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Title")) + HtmlUI.CreateTd(HtmlUI.Input("title", 50, null, SiteFun.HtmlEncode(old.Title)) + (isArticle ? HtmlUI.CreateSelect("cid", values, captions, oldColumn.ID) : string.Empty)));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                if (Regex.IsMatch(old.Local, @"^\d+$")) { old.Local = string.Empty; }
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Local")) + HtmlUI.CreateTd(string.Format((isArticle ? SitePath.ArticleLinkFormat : SitePath.PageLinkFormat), null, HtmlUI.Input("local", 30, null, SiteFun.HtmlEncode(old.Local)))));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Content")) + HtmlUI.CreateTd(AdminUI.Editor("content", SiteFun.HtmlEncode(old.Content))));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd((File.Exists(tmpFilePath) ? "<a id=\"reInsertContent\">" + SiteDat.GetLan("MsgClickArtReload") + "</a>" : string.Empty) + string.Format(SiteDat.GetLan("MsgArtAutoSaveState"), "<span id=\"autoSaveCountdown\">--</span>", "<a id=\"autoSaveButton\">--</a>", "<span id=\"autoSaveIs\"></span>")));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Attach") + ", <a id=\"addFilesA\">" + SiteDat.GetLan("Add") + "</a>") + HtmlUI.CreateTd(string.Format("<span id=\"filesMainBox\">{0}</span><a id=\"filesMainInsertA\">{1}</a><div id=\"filesAttBox\"></div>", HtmlUI.FileInput(null, "files"), SiteDat.GetLan("Insert"))));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TableFinal());

                sr.Append(HtmlUI.TableStart("onCenter hidden advancedBox"));
                string attsHtml = string.Empty;
                DataList<AttachmentItem> attachments = new AttachmentData(conn).SelectAttachment(old.Attachments);
                foreach (AttachmentItem att in attachments)
                {
                    attsHtml += HtmlUI.Link(att.Name, att.Path, att.Type, true) + string.Format(", {0}, {1}, {2}<br/>", att.Publish, att.Size, att.Type);
                }
                if (attachments.Count > 0)
                {
                    sr.Append(HtmlUI.TrStart());
                    sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Attach")) + HtmlUI.CreateTd(attsHtml));
                    sr.Append(HtmlUI.TrFinal());
                }
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Tag")) + HtmlUI.CreateTd(HtmlUI.Input("tags", "tags", 50, null, SiteFun.HtmlEncode(old.Tags))));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(HtmlUI.Button("getInputTags", SiteDat.GetLan("BtnTagsNow")) + "<div id=\"getInputTagsDsp\"></div>"));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Author")) + HtmlUI.CreateTd(HtmlUI.Input("author", 10, null, SiteFun.HtmlEncode(old.Author))));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Time")) + HtmlUI.CreateTd(HtmlUI.Input("timeInput", "publish", 20, null, old.Publish) + HtmlUI.Button("updateTime", SiteDat.GetLan("BtnUpdateTime"))));
                sr.Append(HtmlUI.TrFinal());
                if (isArticle)
                {
                    sr.Append(HtmlUI.TrStart());
                    sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Pwd")) + HtmlUI.CreateTd(HtmlUI.Input("pwd", 30, null, old.Password)));
                    sr.Append(HtmlUI.TrFinal());
                }
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("VoteNum")) + HtmlUI.CreateTd(HtmlUI.Input("vote", 5, null, old.Vote)));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Reader")) + HtmlUI.CreateTd(HtmlUI.Input("reader", 5, null, old.Reader)));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Virtue")) + HtmlUI.CreateTd((isArticle ? HtmlUI.CheckBoxInput(SiteDat.GetLan("Top"), "fine", 1, old.Fine) : string.Empty) + HtmlUI.CheckBoxInput(SiteDat.GetLan("Show"), "show", 1, old.Show)));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                ArrayList wmValues = new ArrayList();
                ArrayList caps = new ArrayList();
                for (int wmI = 0; wmI <= 9; wmI++) { wmValues.Add(wmI); }
                caps.Add("--" + SiteDat.GetLan("WmPosition") + "--");
                caps.Add(SiteDat.GetLan("PTopLeft"));
                caps.Add(SiteDat.GetLan("PTopCen"));
                caps.Add(SiteDat.GetLan("PTopRight"));
                caps.Add(SiteDat.GetLan("PMdlLeft"));
                caps.Add(SiteDat.GetLan("PMdlCen"));
                caps.Add(SiteDat.GetLan("PMdlRight"));
                caps.Add(SiteDat.GetLan("PBtmLeft"));
                caps.Add(SiteDat.GetLan("PBtmCen"));
                caps.Add(SiteDat.GetLan("PBtmRight"));
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Switch")) + HtmlUI.CreateTd(HtmlUI.CheckBoxInput(SiteDat.GetLan("InsertCmt"), "switchCmt", 1, old.SwitchComment) + HtmlUI.CheckBoxInput(SiteDat.GetLan("InsertTb"), "switchTb", 1, old.SwitchTrackback) + HtmlUI.CreateSelect("ws", wmValues, caps, setting.Parameter.WatermarkSeat)));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("AutoVerify")) + HtmlUI.CreateTd(HtmlUI.CheckBoxInput(SiteDat.GetLan("VerifyCmt"), "avcmt", 1, old.AutoVerifyComment) + HtmlUI.CheckBoxInput(SiteDat.GetLan("VerifyTb"), "avtb", 1, old.AutoVerifyTrackback)));
                sr.Append(HtmlUI.TrFinal());
                if (isArticle)
                {
                    sr.Append(HtmlUI.TrStart());
                    sr.Append(HtmlUI.CreateTh(SiteDat.GetLan("Trackback")) + HtmlUI.CreateTd(HtmlUI.Textarea("tbUrls", 5, 80, null)));
                    sr.Append(HtmlUI.TrFinal());
                }
                sr.Append(HtmlUI.TableFinal());

                sr.Append(HtmlUI.TableStart("onCenter"));
                sr.Append(HtmlUI.TrStart());
                sr.Append(HtmlUI.CreateTh() + HtmlUI.CreateTd(HtmlUI.SubmitButton() + HtmlUI.ResetButton() + HtmlUI.Button("advancedLink", SiteDat.GetLan("BtnAdvanced"))));
                sr.Append(HtmlUI.TrFinal());
                sr.Append(HtmlUI.TableFinal());

                sr.Append(HtmlUI.FormFinal());
                sr.Append(AdminUI.AdminBoxFinal());
            }
            return sr.ToString();
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 获取缩略图
 /// </summary>
 /// <param name="postId">资料编号</param>
 /// <param name="width">宽度</param>
 /// <param name="height">高度</param>
 /// <param name="limit">多少个图片</param>
 /// <param name="pf">后缀名,例如:“.png”</param>
 /// <returns>标准图片代码</returns>
 public string GetPostImage(int postId, int width, int height, int limit, string pf)
 {
     string defaPic = SiteCfg.Path + "Common/Images/Nopic.png";
     if (limit < 1) { limit = 1; }
     string imgFormat = "<img src=\"{0}\" width=\"{1}\" height=\"{2}\" border=\"0\"/>";
     string result = string.Empty;
     PostItem item = new PostItem();
     if (SiteDat.GetDat(string.Format(SiteCache.PostFormat, postId)) == null)
     {
         SiteDat.SetDat(string.Format(SiteCache.PostFormat, postId), new PostData(conn).GetPost(postId));
     }
     item = (PostItem)SiteDat.GetDat(string.Format(SiteCache.PostFormat, postId));
     DataList<AttachmentItem> atts = new AttachmentData(conn).SelectAttachment(item.Attachments);
     if (atts.Count > 0)
     {
         int count = 0;
         foreach (AttachmentItem att in atts)
         {
             FileInfo fInfo = new FileInfo(Path.Combine(SiteCfg.Router, att.Path));
             if (fInfo.Exists && !string.IsNullOrEmpty(fInfo.Extension))
             {
                 if (string.IsNullOrEmpty(pf))
                 {
                     if (fInfo.Extension.ToUpper() == ".BMP" || fInfo.Extension.ToUpper() == ".GIF" || fInfo.Extension.ToUpper() == ".JPG" || fInfo.Extension.ToUpper() == ".PNG")
                     {
                         count++;
                         result += string.Format(imgFormat, SiteCfg.Path + att.Path, width, height);
                     }
                 }
                 else
                 {
                     if (fInfo.Extension.ToUpper() == pf.ToUpper())
                     {
                         count++;
                         result += string.Format(imgFormat, SiteCfg.Path + att.Path, width, height);
                     }
                 }
             }
             if (count >= limit) { break; }
         }
     }
     if (string.IsNullOrEmpty(result)) { result = string.Format(imgFormat, defaPic, width, height); }
     return result;
 }