Exemple #1
0
        public bool DeleteArchive(int archiveId)
        {
            IArchive archive = this.GetArchiveById(archiveId);

            if (archive == null)
            {
                return(false);
            }
            if (ArchiveFlag.GetFlag(archive.Get().Flags, BuiltInArchiveFlags.IsSystem))
            {
                throw new NotSupportedException("系统文档,不允许删除,请先取消系统设置后再进行删除!");
            }
            bool result = this._archiveRep.DeleteArchive(this.SiteId, archive.GetAggregaterootId());

            if (result)
            {
                //删除模板绑定
                this._tempRep.RemoveBind(archive.GetAggregaterootId(), TemplateBindType.ArchiveTemplate);


                //
                //TODO:删除评论及点评
                //

                //删除评论
                // new CommentDAL().DeleteArchiveComments(archiveID);

                //删除点评
                //new CommentBLL().DeleteArchiveReviews(archiveID);
            }

            archive = null;

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 创建新的文档
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private int CreateNewArchive(DataPack data)
        {
            bool   visible    = request.Form["visible"] == "on";
            int    categoryID = int.Parse(request.Form["category"]);
            string author     = UserState.Administrator.Current.UserName;

            //string[,] flags;
            string flags = ArchiveFlag.GetFlagString(false, false, visible, false, null);

            ArchiveDto archive = new ArchiveDto
            {
                Agree    = 0,
                Disagree = 0,
                Category = new CategoryDto {
                    ID = categoryID
                },
                Flags      = flags,
                Author     = author,
                Tags       = String.Empty,
                Outline    = String.Empty,
                Source     = String.Empty,
                Title      = data["title"],
                Content    = ReplaceContent(data["content"]),
                CreateDate = DateTime.Now
            };

            return(ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, archive));
        }
Exemple #3
0
        /// <summary>
        /// 创建新文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="post"></param>
        /// <param name="publish"></param>
        /// <returns></returns>
        public string newPost(string blogid, string username, string password, Post post, bool publish)
        {
            UserDto user;

            if ((user = ValidUser(username, password)) != null)
            {
                int    categoryId   = 0;
                string categoryName = post.categories[0];

                //根据提交的栏目设置栏目ID
                if (post.categories.Length != 0)
                {
                    var category = ServiceCall.Instance.SiteService.GetCategoryByName(this.siteId, categoryName);
                    if (category.Id > 0)
                    {
                        categoryId = category.Id;
                    }
                }

                //如果栏目ID仍然为0,则设置第一个栏目
                if (categoryId == 0)
                {
                    throw new Exception("请选择分类!");
                }

                string flag = ArchiveFlag.GetFlagString(false, false, publish, false, null);

                ArchiveDto dto = new ArchiveDto
                {
                    Title       = post.title,
                    PublisherId = user.Id,
                    Outline     = String.Empty,
                    Content     = post.description,
                    CreateDate  = post.dateCreated,
                    Source      = post.source.name,
                    ViewCount   = 1,
                    Flags       = flag,
                    Tags        = String.Empty
                };
                dto.Category = new CategoryDto {
                    Id = categoryId
                };

                return(ServiceCall.Instance.ArchiveService.SaveArchive(this.siteId, dto).ToString());;

                //执行监视服务

                /*
                 * try
                 * {
                 *  WatchService.PublishArchive(abll.GetArchiveByID(id));
                 * }
                 * catch { }
                 */
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// 获取历史文档
        /// </summary>
        /// <param name="blogid"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="numberOfPosts"></param>
        /// <returns></returns>
        public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts)
        {
            Post[] posts;
            User   user;

            if ((user = ValidUser(username, password)) != null)
            {
                User usr = ubll.GetUser(username);

                int totalRecords, pages;

                string[,] flags = new string[, ] {
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem), "" },
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial), "" },
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible), "" },
                    { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage), "" }
                };

                DataTable dt = ServiceCall.Instance.ArchiveService.GetPagedArchives(
                    this.siteId, null,
                    usr.Group == UserGroups.Master ? null : username, flags, null,
                    false, numberOfPosts, 1, out totalRecords, out pages);

                //如果返回的数量没有制定数多
                posts = new Post[dt.Rows.Count < numberOfPosts ? dt.Rows.Count : numberOfPosts];

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    posts[i] = new Post
                    {
                        postid      = dt.Rows[i]["id"].ToString(),                            //编号
                        title       = dt.Rows[i]["title"].ToString(),                         //标题
                        categories  = new string[] { dt.Rows[i]["cid"].ToString() },          //栏目
                        description = dt.Rows[i]["content"].ToString(),                       //内容
                        userid      = dt.Rows[i]["author"].ToString(),                        //作者
                        source      = new Source {
                            name = dt.Rows[i]["source"].ToString()
                        },                                                                          //来源
                        link = String.Format(post_uri,                                              //文档链接地址
                                             String.IsNullOrEmpty(dt.Rows[i]["aias"] as string) ?
                                             dt.Rows[i]["strid"].ToString() : dt.Rows[i]["alias"].ToString()),
                    };
                }

                return(posts);
            }
            return(null);
        }
Exemple #5
0
        /// <summary>
        /// search文档列表
        /// </summary>
        public void Search_GET()
        {
            HttpRequest request = HttpContext.Current.Request;

            const int __pageSize = 10;

            object data;            //返回的数据

            int pageSize,
                pageIndex,
                recordCount,
                pages;


            string _keyword   = request["keyword"],
                   _pageIndex = request["page"] ?? "1",
                   _pageSize  = request["size"];


            if (String.IsNullOrEmpty(_keyword))
            {
                data = new
                {
                    keyword         = _keyword ?? "",
                    headerText      = "",
                    archiveListHtml = "",
                    pagerHtml       = ""
                };
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                string        pagerHtml,            //分页链接
                              tableHeaderText,      //表头字段
                              archiveListHtml;      //文档列表HTML

                //获取表头
                bool isMaster = (UserGroups)UserState.Administrator.Current.GroupID == UserGroups.Master;
                tableHeaderText = isMaster ? "<th>发布人</th>" : String.Empty;


                //处理页码大小并保存

                if (!Regex.IsMatch(_pageIndex, "^(?!0)\\d+$"))
                {
                    pageIndex = 1;                                              //If pageindex start with zero or lower
                }
                else
                {
                    pageIndex = int.Parse(_pageIndex);
                }

                if (String.IsNullOrEmpty(_pageSize))
                {
                    int.TryParse(HttpContext.Current.Session["archivelist_pagesize"] as string, out pageSize);
                }
                else
                {
                    int.TryParse(_pageSize, out pageSize);
                    HttpContext.Current.Session["archivelist_pagesize"] = pageSize;
                }
                if (pageSize == 0)
                {
                    pageSize = __pageSize;
                }



                //文档数据表,并生成Html
                DataTable dt = null;// CmsLogic.Archive.Search(this.CurrentSite.SiteId, _keyword, pageSize, pageIndex, out recordCount, out pages, null);


                IDictionary <string, bool> flagsDict;

                bool isSpecial,
                     isSystem,
                     isVisible,
                     isPage;

                foreach (DataRow dr in dt.Rows)
                {
                    flagsDict = ArchiveFlag.GetFlagsDict(dr["flags"].ToString());
                    isSpecial = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)) &&
                                flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)];

                    isSystem = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)) &&
                               flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)];

                    isVisible = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)) &&
                                flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)];

                    isPage = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)) &&
                             flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)];

                    //编号
                    sb.Append("<tr><td align=\"center\">").Append(dr["id"].ToString()).Append("</td>");
                    //标题
                    sb.Append("<td").Append(isSpecial ? " class=\"special\">" : ">").Append(dr["title"].ToString()).Append("</td>");

                    //管理员可以查看发布人
                    if (isMaster)
                    {
                        sb.Append("<td><a href=\"?module=archive&amp;action=list&amp;moduleID=&amp;author=")
                        .Append(dr["author"].ToString()).Append("\" title=\"查看该用户发布的文档\">").Append(dr["Author"].ToString()).Append("</a></td>");
                    }

                    sb.Append("<td>").Append(String.Format("{0:yyyy/MM/dd HH:mm}", Convert.ToDateTime(dr["CreateDate"]))).Append("</td><td align=\"center\">")
                    .Append(dr["ViewCount"].ToString()).Append("</td><td><button class=\"refresh\" /></td><td><button class=\"file\" /></td><td><button class=\"edit\" /></td><td><button class=\"delete\" /></td></tr>");
                }

                archiveListHtml = sb.ToString();



                string format = String.Format("?module=archive&action=search&keyword={1}&page={0}&size={2}", "{0}", HttpUtility.UrlEncode(_keyword), pageSize);

                //pagerHtml = Helper.BuildPagerInfo(format, pageIndex, recordCount, pages);

                data = new
                {
                    keyword         = _keyword ?? "",
                    headerText      = tableHeaderText,
                    archiveListHtml = archiveListHtml,
                    // pagerHtml = pagerHtml
                };
            }
            base.RenderTemplate(ResourceMap.SearchArchiveList, data);
        }
Exemple #6
0
        /// <summary>
        /// 文档列表Json数据
        /// </summary>
        public void PagerJsonData_POST()
        {
            HttpRequest request = HttpContext.Current.Request;


            int pageSize,
                pageIndex,
                recordCount,
                pages;

            int?categoryID = null,
               moduleID    = null;

            string _categoryID = request["category_id"],
                   _pageIndex  = request["page_index"] ?? "1",
                   _pageSize   = request["page_size"] ?? "10",
                   _author     = request["author"],
                   _visible    = request["lb_visible"] ?? "-1",
                   _special    = request["lb_special"] ?? "-1",
                   _system     = request["lb_system"] ?? "-1",
                   _aspage     = request["lb_page"] ?? "-1";


            if (_categoryID != null)
            {
                int __categoryId;
                int.TryParse(_categoryID, out __categoryId);
                if (__categoryId > 0)
                {
                    categoryID = __categoryId;
                }
            }
            StringBuilder sb = new StringBuilder();

            string pagerHtml;                   //分页链接


            //处理页码大小并保存

            if (!Regex.IsMatch(_pageIndex, "^(?!0)\\d+$"))
            {
                pageIndex = 1;   //If pageindex start with zero or lower
            }
            else
            {
                pageIndex = int.Parse(_pageIndex);
            }

            //分页尺寸
            int.TryParse(_pageSize, out pageSize);


            string[,] flags = new string[, ] {
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem), _system },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial), _special },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible), _visible },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage), _aspage }
            };



            //文档数据表,并生成Html
            DataTable dt = ServiceCall.Instance.ArchiveService.GetPagedArchives(this.SiteId, categoryID, _author, flags, null, false, pageSize, pageIndex, out recordCount, out pages);

            foreach (DataRow dr in dt.Rows)
            {
                dr["content"] = "";
            }

            //  CmsLogic.Archive.GetPagedArchives(this.SiteId, moduleID, categoryID, _author, flags, null, false, pageSize, pageIndex, out recordCount, out pages);
            //moduleID == null ? CmsLogic.Archive.GetPagedArchives(categoryID, _author,flags, null, false, pageSize, pageIndex, out recordCount, out pages)
            //: CmsLogic.Archive.GetPagedArchives((SysModuleType)(moduleID ?? 1), _author, flags,null, false, pageSize, pageIndex, out recordCount, out pages);


            pagerHtml = Helper.BuildJsonPagerInfo("javascript:window.toPage({0});", pageIndex, recordCount, pages);

            base.PagerJson(dt, pagerHtml);
        }
Exemple #7
0
        /// <summary>
        /// 文档列表
        /// </summary>
        public void List_GET()
        {
            HttpRequest request = HttpContext.Current.Request;

            const int __pageSize = 10;

            object data;            //返回的数据

            int pageSize,
                pageIndex,
                recordCount,
                pages;

            bool?visible,
                special,
                system,
                aspage;

            int?categoryID = null,
               moduleID    = null;

            string _categoryId = request["category.id"],    //只有这个参数为必传
                   _moduleId   = request["moduleId"],
                   _pageIndex  = request["page"] ?? "1",
                   _pageSize   = request["size"],
                   _author     = request["author"],
                   _visible    = request["visible"],
                   _special    = request["special"],
                   _system     = request["system"],
                   _aspage     = request["aspage"];

            StringBuilder sb = new StringBuilder();
            string        categoryOpts,         //栏目Options
                          pagerHtml,            //分页链接
                          tableHeaderText,      //表头字段
                          archiveListHtml;      //文档列表HTML


            goto result;


            //处理页码大小并保存

            if (!Regex.IsMatch(_pageIndex, "^(?!0)\\d+$"))
            {
                pageIndex = 1;                                              //If pageindex start with zero or lower
            }
            else
            {
                pageIndex = int.Parse(_pageIndex);
            }

            if (String.IsNullOrEmpty(_pageSize))
            {
                object o = HttpContext.Current.Session["archivelist_pagesize"];
                int.TryParse(HttpContext.Current.Session["archivelist_pagesize"] as string, out pageSize);
            }
            else
            {
                int.TryParse(_pageSize, out pageSize);
                HttpContext.Current.Session["archivelist_pagesize"] = pageSize;
            }
            if (pageSize == 0)
            {
                pageSize = __pageSize;
            }



            //文档显示选项
            #region
            if (String.IsNullOrEmpty(_visible))
            {
                visible = null;
            }
            else
            {
                visible = String.Compare(_visible, String.Intern("true"), true) == 0;
            }

            if (String.IsNullOrEmpty(_special))
            {
                special = null;
            }
            else
            {
                special = String.Compare(_special, String.Intern("true"), true) == 0;
            }

            if (String.IsNullOrEmpty(_system))
            {
                system = null;
            }
            else
            {
                system = String.Compare(_system, String.Intern("true"), true) == 0;
            }


            if (String.IsNullOrEmpty(_aspage))
            {
                aspage = null;
            }
            else
            {
                aspage = String.Compare(_aspage, String.Intern("true"), true) == 0;
            }

            #endregion


            //获取表头
            bool isMaster = (UserGroups)UserState.Administrator.Current.GroupID == UserGroups.Master;
            tableHeaderText = isMaster ? "<th style=\"width:60px\" class=\"center\">发布人</th>" : String.Empty;

            //加载栏目
            ServiceCall.Instance.SiteService.HandleCategoryTree(this.SiteId, 1, (category, level) =>
            {
                sb.Append("<option value=\"").Append(category.ID.ToString()).Append("\">");
                for (var i = 0; i < level; i++)
                {
                    sb.Append("-");
                }
                sb.Append(category.Name).Append("</option>");
            });

            categoryOpts = sb.ToString();
            sb.Remove(0, sb.Length);


            string[,] flags = new string[, ] {
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem), system == null?"":(system.Value?"1":"0") },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial), special == null?"":(special.Value?"1":"0") },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible), visible == null?"":(visible.Value?"1":"0") },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage), aspage == null?"":(aspage.Value?"1":"0") }
            };

            //文档数据表,并生成Html
            DataTable dt = ServiceCall.Instance.ArchiveService.GetPagedArchives(this.SiteId, categoryID, _author, flags, null, false, pageSize, pageIndex, out recordCount, out pages);


            //moduleID == null ? CmsLogic.Archive.GetPagedArchives(categoryID, _author,flags, null, false, pageSize, pageIndex, out recordCount, out pages)
            //: CmsLogic.Archive.GetPagedArchives((SysModuleType)(moduleID ?? 1), _author, flags,null, false, pageSize, pageIndex, out recordCount, out pages);


            IDictionary <string, bool> flagsDict;

            bool isSpecial,
                 isSystem,
                 isVisible,
                 isPage;

            foreach (DataRow dr in dt.Rows)
            {
                flagsDict = ArchiveFlag.GetFlagsDict(dr["flags"].ToString());
                isSpecial = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)) &&
                            flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)];

                isSystem = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)) &&
                           flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)];

                isVisible = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)) &&
                            flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)];

                isPage = flagsDict.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)) &&
                         flagsDict[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)];


                //编号
                sb.Append("<tr indent=\"").Append(dr["id"].ToString()).Append("\"><td align=\"center\">").Append(dr["id"].ToString()).Append("</td>");
                //标题
                sb.Append("<td").Append(isSpecial ? " class=\"special\">" : ">").Append(dr["title"].ToString());

                if (!String.IsNullOrEmpty(dr["alias"] as string))
                {
                    sb.Append("&nbsp;<span style=\"color:#777\">( 别名:").Append(dr["alias"].ToString()).Append(" )</span>");
                }
                sb.Append("</td>");

                //管理员可以查看发布人
                if (isMaster)
                {
                    sb.Append("<td class=\"center\"><a href=\"?module=archive&amp;action=list&amp;moduleID=").Append(_moduleId).Append("&amp;author=")
                    .Append(dr["author"].ToString()).Append("\" title=\"查看该用户发布的文档\">").Append(dr["Author"].ToString()).Append("</a></td>");
                }

                sb.Append("<td>").Append(String.Format("{0:yyyy/MM/dd HH:mm}", Convert.ToDateTime(dr["CreateDate"]))).Append("</td><td align=\"center\">")
                .Append(dr["ViewCount"].ToString()).Append("</td><td><button class=\"refresh\" /></td><td><button class=\"file\" /></td><td><button class=\"edit\" /></td><td><button class=\"delete\" /></td></tr>");
            }

            archiveListHtml = sb.ToString();



            string format = String.Format("?module=archive&action=list&categoryID={0}&moduleID={1}&page={2}&size={3}&author={4}&visible={5}&special={6}&system={7}",
                                          _categoryId, _moduleId, "{0}", pageSize, _author, _visible, _special, _system);

            pagerHtml = Helper.BuildPagerInfo(format, pageIndex, recordCount, pages);


result:

            data = new
            {
                moduleID   = _moduleId ?? String.Empty,
                categoryID = _categoryId ?? String.Empty,
                username   = _author
            };

            base.RenderTemplate(ResourceMap.GetPageContent(ManagementPage.Archive_List), data);
        }
Exemple #8
0
        private ArchiveDto GetFormCopyedArchive(int siteId, NameValueCollection form, ArchiveDto archive, string alias)
        {
            string flag = ArchiveFlag.GetFlagString(
                form["IsSystem"] == "on",     //系统
                form["IsSpecial"] == "on",    //特殊
                form["IsNotVisible"] != "on", //隐藏
                form["AsPage"] == "on",       //作为单页
                null);

            string content = form["Content"];

            //自动替换Tags
            if (form["autotag"] == "on")
            {
                //todo:顺序调换了下
                HttpTags _tags = this.GetTags(siteId);
                content = _tags.Tags.RemoveAutoTags(content);
                content = _tags.Tags.ReplaceSingleTag(content);
            }

            archive.LastModifyDate = DateTime.Now;
            archive.Title          = form["Title"];
            archive.Source         = form["Source"];
            archive.Outline        = form["Outline"];
            archive.Alias          = alias;
            archive.Flags          = flag;
            archive.Tags           = form["Tags"].Replace(",", ",");
            archive.Content        = content;
            archive.Thumbnail      = form["Thumbnail"];

            //分类
            int categoryID = int.Parse(form["categoryid"]);

            archive.Category = new CategoryDto {
                ID = categoryID
            };

            //检测图片是否为默认图片
            if (archive.Thumbnail == CmsVariables.FRAMEWORK_ARCHIVE_NoPhoto)
            {
                archive.Thumbnail = String.Empty;
            }

            archive.ExtendValues = new List <IExtendValue>();

            //=============== 更新扩展字段 ===================

            IExtendField field;
            string       extendValue;

            foreach (string key in form.Keys)
            {
                if (key.StartsWith("extend_"))
                {
                    extendValue = form[key];
                    field       = new ExtendField(int.Parse(key.Substring(7)), null);
                    archive.ExtendValues.Add(new ExtendValue(-1, field, extendValue));
                }
            }

            //更新模板设置
            archive.TemplatePath = form["TemplatePath"];
            if (archive.TemplatePath != String.Empty)
            {
                archive.IsSelfTemplate = true;
            }
            return(archive);
        }
Exemple #9
0
        /// <summary>
        /// 更新文档
        /// </summary>
        public void Update_GET()
        {
            object data;
            int    archiveId = int.Parse(base.Request["archive.id"]);
            string tpls,
                   nodesHtml,                                                 //栏目JSON
                   extendFieldsHtml = "",                                     //属性Html
                   extendItemsHtml  = "";

            Module module;

            int siteId = this.CurrentSite.SiteId;

            ArchiveDto archive = ServiceCall.Instance.ArchiveService.GetArchiveById(siteId, archiveId);

            int categoryId = archive.Category.ID;



            #region 旧的

            //获取上次发布的栏目
            //Category category = CmsLogic.Category.Get(a => a.ID == archive.Category.ID);

            //if (base.CompareSite(category.SiteId)) return;

            //bool categoryIsNull = category == null;

            /*
             * if (!categoryIsNull)
             * {
             *
             *  module = CmsLogic.Module.GetModule(category.ModuleID);
             *
             *  //=============  拼接模块的属性值 ==============//
             *
             *  StringBuilder sb = new StringBuilder(50);
             *  IList<DataExtend> extends = null;// new List<DataExtend>(CmsLogic.DataExtend.GetExtendsByModule(module));
             *
             *  if (extends.Count > 0)
             *  {
             *
             *      //========= 统计tab =============//
             *      sb.Append("<ul class=\"dataExtend_tabs\">");
             *      foreach (DataExtend e in extends)
             *      {
             *          sb.Append("<li><span>").Append(e.Name).Append("</span></li>");
             *      }
             *      sb.Append("</ul>");
             *
             *      extendItemsHtml = sb.ToString();
             *
             *      sb.Capacity = 1000;
             *      sb.Remove(0, sb.Length);
             *
             *
             *      //======== 生成值 =============//
             *
             *      IEnumerable<DataExtendAttr> attrs;
             *      IDictionary<string, string> extendFields = null;// CmsLogic.DataExtend.GetExtendFiledDictionary(archive.ID);
             *      string attrValue;
             *
             *      foreach (DataExtend e in extends)
             *      {
             *          sb.Append("<div class=\"dataextend_item\">");
             *
             *          attrs = CmsLogic.DataExtend.GetExtendAttrs(e.ID);
             *
             *          foreach (DataExtendAttr p in attrs)
             *          {
             *
             *
             *              attrValue = extendFields.ContainsKey(p.AttrName) ? extendFields[p.AttrName] : p.AttrVal;
             *
             *              sb.Append("<dl><dt>").Append(p.AttrName).Append(":</dt><dd>");
             *
             *              if (p.AttrType == ((int)PropertyUI.Text).ToString())
             *              {
             *                  sb.Append("<input type=\"text\" class=\"tb_normal\" name=\"extend_").Append(p.ID.ToString())
             *                      .Append("\" value=\"").Append(attrValue).Append("\"/>");
             *              }
             *              else if (p.AttrType == ((int)PropertyUI.Upload).ToString())
             *              {
             *                  sb.Append("<input type=\"text\" disabled=\"disabled\" class=\"tb_normal\" id=\"extend_").Append(p.ID.ToString()).Append("\" name=\"extend_").Append(p.ID.ToString())
             *                      .Append("\" value=\"").Append(attrValue).Append("\"/><span id=\"upload_")
             *                      .Append(p.ID.ToString()).Append("\">选择文件</span>")
             *                      .Append("<script type=\"text/javascript\">cms.propertyUpload(")
             *                      .Append("'upload_").Append(p.ID.ToString()).Append("','extend_").Append(p.ID.ToString()).Append("');</script>");
             *              }
             *
             *
             *              sb.Append("</dd></dl>");
             *
             *              //<p><span class="txt">标签:</span>
             *              //    <span class="input"><input type="text" name="tags" size="30"/></span>
             *               //   <span class="msg"></span></p>
             *
             *          }
             *
             *
             *          sb.Append("</div>");
             *      }
             *
             *      extendFieldsHtml = sb.ToString();
             *  }
             *
             *  // extendFieldsHtml = "<div style=\"color:red;padding:20px;\">所选栏目模块不包含任何自定义属性,如需添加请到模块管理-》属性设置</div>";
             *
             * }
             */

            #endregion

            //=============  拼接模块的属性值 ==============//

            StringBuilder sb = new StringBuilder(50);

            string       attrValue;
            IExtendField field;

            sb.Append("<div class=\"dataextend_item\">");


            foreach (IExtendValue extValue in archive.ExtendValues)
            {
                field = extValue.Field;

                attrValue = extValue.Value ?? field.DefaultValue;

                sb.Append("<dl><dt>").Append(field.Name).Append(":</dt><dd>");

                if (field.Type == ((int)PropertyUI.Text).ToString())
                {
                    sb.Append("<input type=\"text\" class=\"tb_normal\" field=\"extend_").Append(field.ID.ToString())
                    .Append("\" value=\"").Append(attrValue).Append("\"/>");
                }
                else if (field.Type == ((int)PropertyUI.Upload).ToString())
                {
                    sb.Append("<input type=\"text\" disabled=\"disabled\" class=\"tb_normal\" id=\"extend_").Append(field.ID.ToString())
                    .Append("\" field=\"extend_").Append(field.ID.ToString())
                    .Append("\" value=\"").Append(attrValue).Append("\"/><span id=\"upload_")
                    .Append(field.ID.ToString()).Append("\">选择文件</span>")
                    .Append("<script type=\"text/javascript\">cms.propertyUpload(")
                    .Append("'upload_").Append(field.ID.ToString()).Append("','extend_").Append(field.ID.ToString())
                    .Append("');</script>");
                }


                sb.Append("</dd></dl>");
            }


            sb.Append("</div>");

            extendFieldsHtml = sb.ToString();



            //获取模板视图下拉项
            StringBuilder sb2 = new StringBuilder();

            //模板目录
            DirectoryInfo dir = new DirectoryInfo(
                String.Format("{0}templates/{1}",
                              AppDomain.CurrentDomain.BaseDirectory,
                              Settings.TPL_MultMode ? "" : base.CurrentSite.Tpl + "/"
                              ));

            EachClass.EachTemplatePage(dir,
                                       sb2,
                                       TemplatePageType.Custom,
                                       TemplatePageType.Archive
                                       );

            tpls = sb2.ToString();
            sb2.Remove(0, sb2.Length);

            ServiceCall.Instance.SiteService.HandleCategoryTree(this.SiteId, 1, (_category, level) =>
            {
                sb2.Append("<option value=\"").Append(_category.ID.ToString()).Append("\"");

                //if (_category.ModuleID != category.ModuleID)
                //{
                //    sb2.Append(" disabled=\"disabled\" class=\"disabled\"");
                //}


                sb2.Append(_category.ID == categoryId ? " selected=\"selected\"" : "").Append(">");


                for (int i = 0; i < level; i++)
                {
                    sb2.Append(CmsCharMap.Dot);
                }

                sb2.Append(_category.Name).Append("</option>");
            });
            nodesHtml = sb2.ToString();

            //标签
            Dictionary <string, bool> flags = ArchiveFlag.GetFlagsDict(archive.Flags);

            string thumbnail = !String.IsNullOrEmpty(archive.Thumbnail)
                    ? archive.Thumbnail
                    : "/" + CmsVariables.FRAMEWORK_ARCHIVE_NoPhoto;

            object json = new
            {
                IsSpecial = flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)) &&
                            flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)],

                IsSystem = flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)) &&
                           flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)],

                IsNotVisible = !(flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)) &&
                                 flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)]),

                AsPage = flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)) &&
                         flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)],

                Id           = archive.Id,
                Title        = archive.Title,
                Alias        = archive.Alias ?? String.Empty,
                Tags         = archive.Tags,
                Source       = archive.Source,
                Outline      = archive.Outline,
                Content      = archive.Content,
                TemplatePath = archive.IsSelfTemplate &&
                               !String.IsNullOrEmpty(archive.TemplatePath) ?
                               archive.TemplatePath :
                               String.Empty,
                Thumbnail = thumbnail
            };


            data = new
            {
                extendFieldsHtml = extendFieldsHtml,
                extendItemsHtml  = extendItemsHtml,
                thumbPrefix      = CmsVariables.Archive_ThumbPrefix,
                nodes            = nodesHtml,
                url  = Request.Url.PathAndQuery,
                tpls = tpls,
                json = JsonSerializer.Serialize(json)
            };

            base.RenderTemplate(
                BasePage.CompressHtml(ResourceMap.GetPageContent(ManagementPage.Archive_Update)),
                data);
        }
Exemple #10
0
        /// <summary>
        /// 获取栏目分页文档
        /// </summary>
        /// <param name="lft"></param>
        /// <param name="rgt"></param>
        /// <param name="author">指定作者,NULL表示不限,可显示所有作者发布的文档</param>
        /// <param name="siteId"></param>
        /// <param name="moduleId">参数暂时不使用为-1</param>
        /// <param name="flags"></param>
        /// <param name="orderByField"></param>
        /// <param name="orderAsc"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="recordCount"></param>
        /// <param name="pages"></param>
        /// <returns></returns>
        public DataTable GetPagedArchives(int siteId, int moduleId,
                                          int lft, int rgt, string author,
                                          string[,] flags, string orderByField, bool orderAsc,
                                          int pageSize, int currentPageIndex,
                                          out int recordCount, out int pages)
        {
            //SQL Condition Template
            const string conditionTpl = "$[siteid]$[module]$[category]$[author]$[flags]";


            //Get records count
            //{0}==$[condition]

            const string sql1 = @"SELECT TOP $[pagesize] a.id AS id,alias,title,
                                    c.name as CategoryName,cid,flags,author,content,source,
                                    createdate,viewcount FROM $PREFIX_archive a
                                    INNER JOIN $PREFIX_category c ON a.cid=c.id
                                    WHERE $[condition] ORDER BY $[orderByField] $[orderASC],a.id";


            string condition,                                                                    //SQL where condition
                   order     = String.IsNullOrEmpty(orderByField) ? "CreateDate" : orderByField, //Order filed ( CreateDate | ViewCount | Agree | Disagree )
                   orderType = orderAsc ? "ASC" : "DESC";                                        //ASC or DESC


            string flag = ArchiveFlag.GetSQLString(flags);

            condition = SQLRegex.Replace(conditionTpl, match =>
            {
                switch (match.Groups[1].Value)
                {
                case "siteid": return(String.Format(" c.siteid={0}", siteId.ToString()));

                case "category": return(lft <= 0 || rgt <= 0 ? ""
                        : String.Format(" AND lft>={0} AND rgt<={1}", lft.ToString(), rgt.ToString()));

                case "module": return(moduleId <= 0 ? ""
                        :String.Format(" AND m.id={0}", moduleId.ToString()));

                case "author": return(String.IsNullOrEmpty(author) ? null
                        : String.Format(" AND author='{0}'", author));

                case "flags": return(String.IsNullOrEmpty(flag)?"": " AND " + flag);
                }
                return(null);
            });

            // throw new Exception(new SqlQuery(base.OptimizeSQL(String.Format(SP.Archive_GetpagedArchivesCountSql, condition)));

            //获取记录条数
            recordCount = int.Parse(base.ExecuteScalar(
                                        new SqlQuery(base.OptimizeSQL(String.Format(SP.Archive_GetpagedArchivesCountSql, condition)), null)).ToString());


            pages = recordCount / pageSize;
            if (recordCount % pageSize != 0)
            {
                pages++;
            }
            //验证当前页数

            if (currentPageIndex > pages && currentPageIndex != 1)
            {
                currentPageIndex = pages;
            }
            if (currentPageIndex < 1)
            {
                currentPageIndex = 1;
            }
            //计算分页
            int skipCount = pageSize * (currentPageIndex - 1);


            //如果调过记录为0条,且为OLEDB时候,则用sql1
            string sql = skipCount == 0 && base.DbType == DataBaseType.OLEDB ?
                         sql1 :
                         SP.Archive_GetPagedArchivesByCategoryId;

            sql = SQLRegex.Replace(sql, m =>
            {
                switch (m.Groups[1].Value)
                {
                case "skipsize": return(skipCount.ToString());

                case "pagesize": return(pageSize.ToString());

                case "condition": return(condition);

                case "orderByField": return(order);

                case "orderASC": return(orderType);
                }
                return(null);
            });
            //throw new Exception(new SqlQuery(base.OptimizeSQL(sql));
            //throw new Exception(sql+"-"+DbHelper.DbType.ToString()+"-"+new SqlQuery(base.OptimizeSQL(SP.ToString());
            //System.Web.HttpContext.Current.Response.Write(sql);
            //throw new Exception(sql);
            return(base.GetDataSet(new SqlQuery(base.OptimizeSQL(sql))).Tables[0]);
        }
Exemple #11
0
        /// <summary>
        /// 文档页
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public string Archive(string tag, string id)
        {
            string   html = String.Empty;
            Archive  archive;
            Category category;

            archive = bll.Get(id);
            if (archive != null)
            {
                category = cbll.Get(a => a.ID == archive.Cid);

                if (category != null)
                {
                    const string pattern     = "^/[0-9a-zA-Z]+/[\\.0-9A-Za-z_-]+\\.html$";
                    const string pagePattern = "^/[\\.0-9A-Za-z_-]+\\.html$";

                    if (ArchiveFlag.GetFlag(archive.Flags, ArchiveInternalFlags.AsPage))
                    {
                        if (!Regex.IsMatch(Request.Path, pagePattern))
                        {
                            Response.StatusCode       = 301;
                            Response.RedirectLocation = String.Format("/{0}.html",
                                                                      String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias
                                                                      );
                            Response.End();
                            return(null);
                        }
                    }
                    else if (!Regex.IsMatch(Request.Path, pattern) ||
                             (String.Compare(tag, category.Tag, true) != 0 || //如果分类tag不对,则301跳转
                              (!String.IsNullOrEmpty(archive.Alias) && String.Compare(id, archive.Alias, true) != 0)
                             ))                                               //设置了别名
                    {
                        Response.StatusCode       = 301;
                        Response.RedirectLocation = String.Format("/{0}/{1}.html",
                                                                  category.Tag,
                                                                  String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias
                                                                  );
                        Response.End();
                        return(null);
                    }


                    //增加浏览次数
                    ++archive.ViewCount;
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            bll.AddViewCount(archive.ID, 1);
                        }
                        catch
                        {
                        }
                    }).Start();

                    //显示页面
                    html = PageGenerator.Generate(PageGeneratorObject.ArchivePage, category, archive);
                    //再次处理模板
                    //html = PageUtility.Render(html, new { }, false);
                }
            }
            else
            {
                html = base.Render404();
            }
            return(html);
        }
Exemple #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);
            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 = 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.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);
        }
Exemple #13
0
        /// <summary>
        /// 获取栏目分页文档
        /// </summary>
        /// <param name="lft"></param>
        /// <param name="rgt"></param>
        /// <param name="siteId"></param>
        /// <param name="moduleId">参数暂时不使用为-1</param>
        /// <param name="publisherId"></param>
        /// <param name="includeChild"></param>
        /// <param name="flags"></param>
        /// <param name="keyword"></param>
        /// <param name="orderByField"></param>
        /// <param name="orderAsc"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPageIndex"></param>
        /// <param name="recordCount"></param>
        /// <param name="pages"></param>
        /// <returns></returns>
        public DataTable GetPagedArchives(int siteId, int moduleId,
                                          int[] catIdArray, int publisherId, bool includeChild,
                                          string[,] flags, string keyword, string orderByField, bool orderAsc,
                                          int pageSize, int currentPageIndex,
                                          out int recordCount, out int pages)
        {
            //SQL Condition Template
            const string conditionTpl = "$[siteid]$[module]$[category]$[author_id]$[flags]$[keyword]";

            string condition,                                                                       //SQL where condition
                   order     = String.IsNullOrEmpty(orderByField) ? "a.sort_number" : orderByField, //Order filed ( CreateDate | ViewCount | Agree | Disagree )
                   orderType = orderAsc ? "ASC" : "DESC";                                           //ASC or DESC

            string flag = ArchiveFlag.GetSQLString(flags);


            condition = SQLRegex.Replace(conditionTpl, match =>
            {
                switch (match.Groups[1].Value)
                {
                case "siteid": return(String.Format(" c.site_id={0}", siteId.ToString()));

                case "category":
                    if (catIdArray.Length > 0)
                    {
                        if (includeChild && catIdArray.Length > 1)
                        {
                            return(String.Format(" AND cat_id IN({0})", this.IntArrayToString(catIdArray)));
                        }
                        return(String.Format(" AND cat_id = {0}", catIdArray[0]));
                    }
                    return(String.Empty);

                case "module":
                    return(moduleId <= 0 ? ""
             : String.Format(" AND m.id={0}", moduleId.ToString()));

                case "author_id":
                    return(publisherId == 0 ? null
       : String.Format(" AND author_id='{0}'", publisherId));

                case "flags": return(String.IsNullOrEmpty(flag) ? "" : " AND " + flag);

                case "keyword":
                    if (String.IsNullOrEmpty(keyword))
                    {
                        return("");
                    }
                    return(String.Format(" AND (title LIKE '%{0}%' OR Content LIKE '%{0}%')", keyword));
                }
                return(null);
            });

            // throw new Exception(base.OptimizeSql(String.Format(DbSql.Archive_GetpagedArchivesCountSql, condition)));

            //获取记录条数
            recordCount = int.Parse(base.ExecuteScalar(
                                        base.NewQuery(String.Format(DbSql.ArchiveGetpagedArchivesCountSql, condition), DalBase.EmptyParameter)).ToString());


            pages = recordCount / pageSize;
            if (recordCount % pageSize != 0)
            {
                pages++;
            }
            //验证当前页数

            if (currentPageIndex > pages && currentPageIndex != 1)
            {
                currentPageIndex = pages;
            }
            if (currentPageIndex < 1)
            {
                currentPageIndex = 1;
            }
            //计算分页
            int skipCount = pageSize * (currentPageIndex - 1);


            string sql = DbSql.Archive_GetPagedArchivesByCategoryId;

            sql = SQLRegex.Replace(sql, m =>
            {
                switch (m.Groups[1].Value)
                {
                case "skipsize": return(skipCount.ToString());

                case "pagesize": return(pageSize.ToString());

                case "condition": return(condition);

                case "orderByField": return(order);

                case "orderASC": return(orderType);
                }
                return(null);
            });

            //throw new Exception(new SqlQuery(base.OptimizeSQL(sql));
            //throw new Exception(sql+"-"+DbHelper.DbType.ToString()+"-"+new SqlQuery(base.OptimizeSQL(SP.ToString());
            //System.Web.HttpContext.Current.Response.Write(sql);
            //throw new Exception(sql);
            return(base.GetDataSet(base.NewQuery(sql, null)).Tables[0]);
        }
Exemple #14
0
        /// <summary>
        /// 文档列表Json数据
        /// </summary>
        public void PagerJsonData_POST()
        {
            HttpRequest request = HttpContext.Current.Request;


            int pageSize,
                pageIndex,
                recordCount,
                pages;

            int?categoryId = null,
               moduleId    = null;

            string _categoryId = request["category_id"],
                   _pageIndex  = request["page_index"] ?? "1",
                   _pageSize   = request["page_size"] ?? "10",
                   _visible    = request["lb_visible"] ?? "-1",
                   _special    = request["lb_special"] ?? "-1",
                   _system     = request["lb_system"] ?? "-1",
                   _aspage     = request["lb_page"] ?? "-1";

            int publisherId;

            int.TryParse(request["publisher_id"], out publisherId);

            bool   includeChild = request["include_child"] == "true";
            String keyword      = Request.Form["keyword"];

            if (!String.IsNullOrEmpty(keyword) && DataChecker.SqlIsInject(keyword))
            {
                throw new ArgumentException("Sql  inject?", keyword);
            }

            if (_categoryId != null)
            {
                int __categoryId;
                int.TryParse(_categoryId, out __categoryId);
                if (__categoryId > 0)
                {
                    categoryId = __categoryId;
                }
            }


            //处理页码大小并保存

            if (!Regex.IsMatch(_pageIndex, "^(?!0)\\d+$"))
            {
                pageIndex = 1;   //If pageindex start with zero or lower
            }
            else
            {
                pageIndex = int.Parse(_pageIndex);
            }

            //分页尺寸
            int.TryParse(_pageSize, out pageSize);


            string[,] flags = new string[, ] {
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem), _system },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial), _special },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible), _visible },
                { ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage), _aspage }
            };



            //文档数据表,并生成Html
            DataTable dt = ServiceCall.Instance.ArchiveService.GetPagedArchives(this.SiteId, categoryId,
                                                                                publisherId, includeChild, flags, keyword, null, false, pageSize, pageIndex, out recordCount, out pages);

            foreach (DataRow dr in dt.Rows)
            {
                dr["content"] = "";
            }

            //  CmsLogic.Archive.GetPagedArchives(this.SiteId, moduleID, categoryID, _publisher_id, flags, null, false, pageSize, pageIndex, out recordCount, out pages);
            //moduleID == null ? CmsLogic.Archive.GetPagedArchives(categoryID, _publisher_id,flags, null, false, pageSize, pageIndex, out recordCount, out pages)
            //: CmsLogic.Archive.GetPagedArchives((SysModuleType)(moduleID ?? 1), _publisher_id, flags,null, false, pageSize, pageIndex, out recordCount, out pages);


            string pagerHtml = Helper.BuildJsonPagerInfo("javascript:window.toPage(1);", "javascript:window.toPage({0});", pageIndex, recordCount, pages);

            base.PagerJson(dt, pagerHtml);
        }
Exemple #15
0
        /// <summary>
        /// 更新文档
        /// </summary>
        public void Update_GET()
        {
            object data;
            int    archiveId = int.Parse(base.Request["archive.id"]);
            string tpls, nodesHtml,
            //栏目JSON
                   extendFieldsHtml = "";                                     //属性Html

            Module module;

            int siteId = this.CurrentSite.SiteId;

            ArchiveDto archive = ServiceCall.Instance.ArchiveService.GetArchiveById(siteId, archiveId);

            int categoryId = archive.Category.Id;

            //=============  拼接模块的属性值 ==============//

            StringBuilder sb = new StringBuilder(50);

            string       attrValue;
            IExtendField field;

            sb.Append("<div class=\"dataextend_item\">");

            foreach (IExtendValue extValue in archive.ExtendValues)
            {
                field     = extValue.Field;
                attrValue = (extValue.Value ?? field.DefaultValue).Replace("<br />", "\n");
                this.AppendExtendFormHtml(sb, field, attrValue);
            }


            sb.Append("</div>");

            extendFieldsHtml = sb.ToString();



            //获取模板视图下拉项
            StringBuilder sb2 = new StringBuilder();

            //模板目录
            DirectoryInfo dir = new DirectoryInfo(
                String.Format("{0}templates/{1}",
                              AppDomain.CurrentDomain.BaseDirectory,
                              base.CurrentSite.Tpl + "/"
                              ));

            IDictionary <String, String> names = Cms.TemplateManager.Get(base.CurrentSite.Tpl).GetNameDictionary();

            EachClass.EachTemplatePage(dir, dir,
                                       sb2,
                                       names,
                                       TemplatePageType.Custom,
                                       TemplatePageType.Archive
                                       );

            tpls = sb2.ToString();

            nodesHtml = Helper.GetCategoryIdSelector(this.SiteId, categoryId);

            //标签
            Dictionary <string, bool> flags = ArchiveFlag.GetFlagsDict(archive.Flags);

            string thumbnail = !String.IsNullOrEmpty(archive.Thumbnail)
                    ? archive.Thumbnail
                    : "/" + CmsVariables.FRAMEWORK_ARCHIVE_NoPhoto;

            object json = new
            {
                IsSpecial = flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)) &&
                            flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSpecial)],

                IsSystem = flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)) &&
                           flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.IsSystem)],

                IsNotVisible = !(flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)) &&
                                 flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.Visible)]),

                AsPage = flags.ContainsKey(ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)) &&
                         flags[ArchiveFlag.GetInternalFlagKey(BuiltInArchiveFlags.AsPage)],

                Id           = archive.Id,
                Title        = archive.Title,
                SmallTitle   = archive.SmallTitle,
                Alias        = archive.Alias ?? String.Empty,
                Tags         = archive.Tags,
                Source       = archive.Source,
                Outline      = archive.Outline,
                Content      = archive.Content,
                TemplatePath = archive.IsSelfTemplate &&
                               !String.IsNullOrEmpty(archive.TemplatePath) ?
                               archive.TemplatePath :
                               String.Empty,
                Thumbnail = thumbnail,
                Location  = archive.Location
            };


            data = new
            {
                extendFieldsHtml = extendFieldsHtml,
                extend_cls       = archive.ExtendValues.Count == 0 ? "hidden" : "",
                thumbPrefix      = CmsVariables.Archive_ThumbPrefix,
                nodes            = nodesHtml,
                url  = Request.Url.PathAndQuery,
                tpls = tpls,
                json = JsonSerializer.Serialize(json)
            };

            base.RenderTemplate(
                BasePage.CompressHtml(ResourceMap.GetPageContent(ManagementPage.Archive_Update)),
                data);
        }
Exemple #16
0
        private DataPackFunc GetDataPackHandler(int categoryId)
        {
            int    publisherId;
            string flag;
            bool   isAutoTag;
            bool   removeLink;
            bool   dlPic;

            publisherId = UserState.Administrator.Current.Id;

            flag = ArchiveFlag.GetFlagString(
                false,
                false,
                request.Form["visible"] == "on",
                false,
                null);

            isAutoTag  = request.Form["autotag"] == "on";
            removeLink = request.Form["removelink"] == "on";
            dlPic      = request.Form["dlpic"] == "on";
            string   domain = null;
            HttpTags _tags  = this.GetTags(siteId);

            return(data =>
            {
                string content = data["content"];
                string thumbnail = data["thumbnail"] ?? (data["image"] ?? "");
                bool thumbIsNull = String.IsNullOrEmpty(thumbnail);

                if (domain == null)
                {
                    Match m = Regex.Match(data.ReferenceUrl, "((http|https)://[^/]+)/(.+?)"
                                          , RegexOptions.IgnoreCase);
                    domain = m.Groups[1].Value;
                }

                //替换src
                content = srcRegex.Replace(content, "$1" + domain + "/");
                if (!thumbIsNull && thumbnail[0] == '/')
                {
                    thumbnail = domain + thumbnail;
                }

                //移除链接
                if (removeLink)
                {
                    content = linkRegex.Replace(content, "$1");
                }

                //远程下载
                if (dlPic)
                {
                    content = AutoUpload(content);
                    if (!thumbIsNull)
                    {
                        thumbnail = downloadThumbnail(thumbnail);
                    }
                }


                //自动替换Tags
                if (isAutoTag)
                {
                    // content = _tags.Tags.RemoveAutoTags(content);
                    content = _tags.Tags.ReplaceSingleTag(content);
                }

                this.CreateNewArchive(categoryId, content, thumbnail, publisherId, flag, data);
            });
        }
Exemple #17
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);
        }
Exemple #18
0
        /// <summary>
        /// 文档页
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public void Archive(string lang, string allhtml)
        {
            string   id       = null;
            string   html     = String.Empty;
            Archive  archive  = null;
            Category category = null;


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

            if (paramRegex.IsMatch(allhtml))
            {
                id      = paramRegex.Match(allhtml).Groups[1].Value;
                archive = bll.Get(id);
            }



            if (archive == null)
            {
                base.RenderNotfound();
                return;
            }
            else
            {
                BuiltInArchiveFlags flag = ArchiveFlag.GetBuiltInFlags(archive.Flags);

                if ((flag & BuiltInArchiveFlags.Visible) != BuiltInArchiveFlags.Visible)
                //|| (flag & BuiltInArchiveFlags.IsSystem) == BuiltInArchiveFlags.IsSystem)
                {
                    base.RenderNotfound();
                    return;
                }


                category = cbll.Get(a => a.ID == archive.Cid);
                if (category == null)
                {
                    base.RenderNotfound();
                    return;
                }
                else
                {
                    string vpath = "/" + lang;

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

                        if (!Regex.IsMatch(Request.Path, pagePattern))
                        {
                            Response.StatusCode       = 301;
                            Response.RedirectLocation = String.Format("/{0}/{1}.html",
                                                                      lang,
                                                                      String.IsNullOrEmpty(archive.Alias) ? archive.ID : archive.Alias
                                                                      );
                            Response.End();
                            return;
                        }
                    }
                    else
                    {
                        //校验栏目是否正确
                        string categoryPath = ArchiveUtility.GetCategoryUrlPath(category);
                        if (!allhtml.StartsWith(categoryPath + "/"))
                        {
                            base.RenderNotfound();
                            return;
                        }

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


                    //增加浏览次数
                    ++archive.ViewCount;
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            bll.AddViewCount(archive.ID, 1);
                        }
                        catch
                        {
                        }
                    }).Start();

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

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

            base.Render(html);
        }