Example #1
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            var categoryChannelId    = TranslateUtils.ToInt(Request["categoryChannelID"]);
            var categoryDepartmentId = TranslateUtils.ToInt(Request["categoryDepartmentID"]);

            if (categoryChannelId == 0)
            {
                FailMessage("信息采集失败,必须要选择一个主题分类");
                return;
            }

            if (categoryDepartmentId == 0)
            {
                FailMessage("信息采集失败,必须要选择一个机构分类");
                return;
            }

            var categoryClassInfoArrayList = DataProvider.GovPublicCategoryClassDao.GetCategoryClassInfoArrayList(PublishmentSystemId, ETriState.False, ETriState.True);

            if (_contentId == 0)
            {
                var contentInfo = new GovPublicContentInfo();
                try
                {
                    InputTypeParser.AddValuesToAttributes(_tableStyle, _tableName, PublishmentSystemInfo, _relatedIdentities, Request.Form, contentInfo.Attributes, ContentAttribute.HiddenAttributes);

                    contentInfo.NodeId        = categoryChannelId;
                    contentInfo.Description   = tbDescription.Text;
                    contentInfo.PublishDate   = dtbPublishDate.DateTime;
                    contentInfo.EffectDate    = dtbEffectDate.DateTime;
                    contentInfo.IsAbolition   = TranslateUtils.ToBool(rblIsAbolition.SelectedValue);
                    contentInfo.AbolitionDate = dtbAbolitionDate.DateTime;
                    contentInfo.DocumentNo    = tbDocumentNo.Text;
                    contentInfo.Publisher     = tbPublisher.Text;
                    contentInfo.Keywords      = tbKeywords.Text;

                    contentInfo.DepartmentId = categoryDepartmentId;
                    SetCategoryAttributes(contentInfo, categoryClassInfoArrayList);
                    contentInfo.PublishmentSystemId = PublishmentSystemId;
                    contentInfo.AddUserName         = Body.AdministratorName;
                    if (contentInfo.AddDate.Year == DateUtils.SqlMinValue.Year)
                    {
                        FailMessage($"内容添加失败:系统时间不能为{DateUtils.SqlMinValue.Year}年");
                        return;
                    }
                    contentInfo.LastEditUserName = contentInfo.AddUserName;
                    contentInfo.LastEditDate     = DateTime.Now;

                    if (phContentAttributes.Visible)
                    {
                        foreach (ListItem listItem in ContentAttributes.Items)
                        {
                            var value         = listItem.Selected.ToString();
                            var attributeName = listItem.Value;
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    contentInfo.CheckedLevel = TranslateUtils.ToIntWithNagetive(ContentLevel.SelectedValue);
                    contentInfo.IsChecked    = contentInfo.CheckedLevel >= PublishmentSystemInfo.CheckContentLevel;

                    contentInfo.ContentGroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(ContentGroupNameCollection.Items);
                    var tagCollection = TagUtils.ParseTagsString(Tags.Text);
                    contentInfo.Tags = TranslateUtils.ObjectCollectionToString(tagCollection, " ");

                    contentInfo.Identifier = GovPublicManager.GetIdentifier(PublishmentSystemInfo, categoryChannelId, categoryDepartmentId, contentInfo);
                    var contentId = DataProvider.ContentDao.Insert(_tableName, PublishmentSystemInfo, contentInfo);

                    //更新分类内容数
                    foreach (GovPublicCategoryClassInfo categoryClassInfo in categoryClassInfoArrayList)
                    {
                        var categoryId = TranslateUtils.ToInt(contentInfo.GetExtendedAttribute(categoryClassInfo.ContentAttributeName));
                        if (categoryId > 0)
                        {
                            DataProvider.GovPublicCategoryDao.UpdateContentNum(PublishmentSystemInfo, categoryClassInfo.ContentAttributeName, categoryId);
                        }
                    }

                    if (contentInfo.IsChecked)
                    {
                        CreateManager.CreateContentAndTrigger(PublishmentSystemId, _nodeInfo.NodeId, contentInfo.Id);
                    }

                    contentInfo.Id = contentId;
                }
                catch (Exception ex)
                {
                    FailMessage(ex, $"内容添加失败:{ex.Message}");
                    LogUtils.AddErrorLog(ex);
                    return;
                }

                Body.AddSiteLog(PublishmentSystemId, categoryChannelId, contentInfo.Id, "添加内容",
                                $"栏目:{NodeManager.GetNodeNameNavigation(PublishmentSystemId, contentInfo.NodeId)},内容标题:{contentInfo.Title}");

                ContentUtility.Translate(PublishmentSystemInfo, _nodeInfo.NodeId, contentInfo.Id, Request.Form["translateCollection"], ETranslateContentTypeUtils.GetEnumType(ddlTranslateType.SelectedValue), Body.AdministratorName);

                PageUtils.Redirect(PageGovPublicContentAddAfter.GetRedirectUrl(PublishmentSystemId, categoryChannelId, contentInfo.Id, Request.QueryString["ReturnUrl"]));
            }
            else
            {
                var contentInfo = DataProvider.GovPublicContentDao.GetContentInfo(PublishmentSystemInfo, _contentId);
                try
                {
                    var oldNodeId = 0;
                    if (contentInfo.NodeId != categoryChannelId)
                    {
                        oldNodeId          = contentInfo.NodeId;
                        contentInfo.NodeId = categoryChannelId;
                    }

                    var identifier = contentInfo.Identifier;
                    InputTypeParser.AddValuesToAttributes(_tableStyle, _tableName, PublishmentSystemInfo, _relatedIdentities, Request.Form, contentInfo.Attributes, ContentAttribute.HiddenAttributes);

                    contentInfo.DepartmentId = categoryDepartmentId;
                    SetCategoryAttributes(contentInfo, categoryClassInfoArrayList);

                    contentInfo.Description   = tbDescription.Text;
                    contentInfo.PublishDate   = dtbPublishDate.DateTime;
                    contentInfo.EffectDate    = dtbEffectDate.DateTime;
                    contentInfo.IsAbolition   = TranslateUtils.ToBool(rblIsAbolition.SelectedValue);
                    contentInfo.AbolitionDate = dtbAbolitionDate.DateTime;
                    contentInfo.DocumentNo    = tbDocumentNo.Text;
                    contentInfo.Publisher     = tbPublisher.Text;
                    contentInfo.Keywords      = tbKeywords.Text;

                    var contentAttributeNameWithCategoryId = SetCategoryAttributes(contentInfo, categoryClassInfoArrayList);
                    contentInfo.LastEditUserName = Body.AdministratorName;
                    contentInfo.LastEditDate     = DateTime.Now;

                    contentInfo.ContentGroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(ContentGroupNameCollection.Items);
                    var tagsLast      = contentInfo.Tags;
                    var tagCollection = TagUtils.ParseTagsString(Tags.Text);
                    contentInfo.Tags = TranslateUtils.ObjectCollectionToString(tagCollection, " ");

                    if (phContentAttributes.Visible)
                    {
                        foreach (ListItem listItem in ContentAttributes.Items)
                        {
                            var value         = listItem.Selected.ToString();
                            var attributeName = listItem.Value;
                            contentInfo.SetExtendedAttribute(attributeName, value);
                        }
                    }

                    var checkedLevel = TranslateUtils.ToIntWithNagetive(ContentLevel.SelectedValue);
                    if (checkedLevel != LevelManager.LevelInt.NotChange)
                    {
                        contentInfo.IsChecked    = checkedLevel >= PublishmentSystemInfo.CheckContentLevel;
                        contentInfo.CheckedLevel = checkedLevel;
                    }

                    if (string.IsNullOrEmpty(identifier))
                    {
                        identifier = GovPublicManager.GetIdentifier(PublishmentSystemInfo, contentInfo.NodeId, contentInfo.DepartmentId, contentInfo);
                    }
                    else if (GovPublicManager.IsIdentifierChanged(categoryChannelId, categoryDepartmentId, dtbEffectDate.DateTime, contentInfo))
                    {
                        identifier = GovPublicManager.GetIdentifier(PublishmentSystemInfo, contentInfo.NodeId, contentInfo.DepartmentId, contentInfo);
                    }
                    contentInfo.Identifier = identifier;

                    DataProvider.ContentDao.Update(_tableName, PublishmentSystemInfo, contentInfo);

                    if (phTags.Visible)
                    {
                        TagUtils.UpdateTags(tagsLast, contentInfo.Tags, tagCollection, PublishmentSystemId, _contentId);
                    }

                    ContentUtility.Translate(PublishmentSystemInfo, _nodeInfo.NodeId, contentInfo.Id, Request.Form["translateCollection"], ETranslateContentTypeUtils.GetEnumType(ddlTranslateType.SelectedValue), Body.AdministratorName);

                    //更新分类内容数
                    foreach (GovPublicCategoryClassInfo categoryClassInfo in categoryClassInfoArrayList)
                    {
                        if (!string.IsNullOrEmpty(contentAttributeNameWithCategoryId[categoryClassInfo.ContentAttributeName]))
                        {
                            var oldCategoryId = TranslateUtils.ToInt(contentAttributeNameWithCategoryId[categoryClassInfo.ContentAttributeName]);
                            var newCategoryId = TranslateUtils.ToInt(contentInfo.GetExtendedAttribute(categoryClassInfo.ContentAttributeName));

                            if (oldCategoryId > 0)
                            {
                                DataProvider.GovPublicCategoryDao.UpdateContentNum(PublishmentSystemInfo, categoryClassInfo.ContentAttributeName, oldCategoryId);
                            }
                            if (newCategoryId > 0)
                            {
                                DataProvider.GovPublicCategoryDao.UpdateContentNum(PublishmentSystemInfo, categoryClassInfo.ContentAttributeName, newCategoryId);
                            }
                        }
                    }

                    if (oldNodeId > 0)
                    {
                        DataProvider.NodeDao.UpdateContentNum(PublishmentSystemInfo, oldNodeId, true);
                        DataProvider.NodeDao.UpdateContentNum(PublishmentSystemInfo, categoryChannelId, true);
                    }
                }
                catch (Exception ex)
                {
                    FailMessage(ex, $"内容修改失败:{ex.Message}");
                    LogUtils.AddErrorLog(ex);
                    return;
                }

                if (contentInfo.IsChecked)
                {
                    CreateManager.CreateContentAndTrigger(PublishmentSystemId, categoryChannelId, _contentId);
                }

                Body.AddSiteLog(PublishmentSystemId, categoryChannelId, _contentId, "修改内容",
                                $"栏目:{NodeManager.GetNodeNameNavigation(PublishmentSystemId, contentInfo.NodeId)},内容标题:{contentInfo.Title}");

                PageUtils.Redirect(ReturnUrl);
            }
        }
        public IHttpActionResult Upload()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId    = request.GetQueryInt("siteId");
                var channelId = request.GetQueryInt("channelId");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentAdd))
                {
                    return(Unauthorized());
                }

                var fileName = request.HttpRequest["fileName"];

                var fileCount = request.HttpRequest.Files.Count;

                string filePath = null;

                if (fileCount > 0)
                {
                    var file = request.HttpRequest.Files[0];

                    if (string.IsNullOrEmpty(fileName))
                    {
                        fileName = Path.GetFileName(file.FileName);
                    }

                    var extendName = fileName.Substring(fileName.LastIndexOf(".", StringComparison.Ordinal)).ToLower();
                    if (extendName == ".doc" || extendName == ".docx")
                    {
                        filePath = PathUtils.GetTemporaryFilesPath(fileName);
                        DirectoryUtils.CreateDirectoryIfNotExists(filePath);
                        file.SaveAs(filePath);
                    }
                }

                FileInfo fileInfo = null;
                if (!string.IsNullOrEmpty(filePath))
                {
                    fileInfo = new FileInfo(filePath);
                }
                if (fileInfo != null)
                {
                    return(Ok(new
                    {
                        fileName,
                        length = fileInfo.Length,
                        ret = 1
                    }));
                }

                return(Ok(new
                {
                    ret = 0
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #3
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new RequestImpl();

                var downloadUrl = string.Empty;

                var siteId            = request.GetPostInt("siteId");
                var channelId         = request.GetPostInt("channelId");
                var exportType        = request.GetPostString("exportType");
                var isAllCheckedLevel = request.GetPostBool("isAllCheckedLevel");
                var checkedLevelKeys  = request.GetPostObject <List <int> >("checkedLevelKeys");
                var isAllDate         = request.GetPostBool("isAllDate");
                var startDate         = request.GetPostDateTime("startDate");
                var endDate           = request.GetPostDateTime("endDate");
                var columnNames       = request.GetPostObject <List <string> >("columnNames");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasChannelPermissions(siteId, channelId,
                                                                    ConfigManager.ChannelPermissions.ChannelEdit))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var columns       = ContentManager.GetContentColumns(siteInfo, channelInfo, true);
                var pluginIds     = PluginContentManager.GetContentPluginIds(channelInfo);
                var pluginColumns = PluginContentManager.GetContentColumns(pluginIds);

                var contentInfoList = new List <ContentInfo>();
                var count           = ContentManager.GetCount(siteInfo, channelInfo);
                var pages           = Convert.ToInt32(Math.Ceiling((double)count / siteInfo.Additional.PageSize));
                if (pages == 0)
                {
                    pages = 1;
                }

                if (count > 0)
                {
                    for (var page = 1; page <= pages; page++)
                    {
                        var offset = siteInfo.Additional.PageSize * (page - 1);
                        var limit  = siteInfo.Additional.PageSize;

                        var pageContentIds = ContentManager.GetContentIdList(siteInfo, channelInfo, offset, limit);

                        var sequence = offset + 1;

                        foreach (var contentId in pageContentIds)
                        {
                            var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                            if (contentInfo == null)
                            {
                                continue;
                            }

                            if (!isAllCheckedLevel)
                            {
                                var checkedLevel = contentInfo.CheckedLevel;
                                if (contentInfo.IsChecked)
                                {
                                    checkedLevel = siteInfo.Additional.CheckContentLevel;
                                }
                                if (!checkedLevelKeys.Contains(checkedLevel))
                                {
                                    continue;
                                }
                            }

                            if (!isAllDate)
                            {
                                if (contentInfo.AddDate < startDate || contentInfo.AddDate > endDate)
                                {
                                    continue;
                                }
                            }

                            contentInfoList.Add(ContentManager.Calculate(sequence++, contentInfo, columns, pluginColumns));
                        }
                    }

                    if (contentInfoList.Count > 0)
                    {
                        if (exportType == "zip")
                        {
                            var fileName     = $"{channelInfo.ChannelName}.zip";
                            var filePath     = PathUtils.GetTemporaryFilesPath(fileName);
                            var exportObject = new ExportObject(siteId, request.AdminName);
                            contentInfoList.Reverse();
                            if (exportObject.ExportContents(filePath, contentInfoList))
                            {
                                downloadUrl = PageUtils.GetTemporaryFilesUrl(fileName);
                            }
                        }
                        else if (exportType == "excel")
                        {
                            var fileName = $"{channelInfo.ChannelName}.csv";
                            var filePath = PathUtils.GetTemporaryFilesPath(fileName);
                            ExcelObject.CreateExcelFileForContents(filePath, siteInfo, channelInfo, contentInfoList, columnNames);
                            downloadUrl = PageUtils.GetTemporaryFilesUrl(fileName);
                        }
                    }
                }

                return(Ok(new
                {
                    Value = downloadUrl,
                    IsSuccess = !string.IsNullOrEmpty(downloadUrl)
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #4
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId            = request.GetPostInt("siteId");
                var channelId         = request.GetPostInt("channelId");
                var channelContentIds =
                    MinContentInfo.ParseMinContentInfoList(request.GetPostString("channelContentIds"));
                var isUp  = request.GetPostBool("isUp");
                var taxis = request.GetPostInt("taxis");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentEdit))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (ETaxisTypeUtils.Equals(channelInfo.Additional.DefaultTaxisType, ETaxisType.OrderByTaxis))
                {
                    isUp = !isUp;
                }

                if (isUp == false)
                {
                    channelContentIds.Reverse();
                }

                foreach (var channelContentId in channelContentIds)
                {
                    var contentChannelInfo = ChannelManager.GetChannelInfo(siteId, channelContentId.ChannelId);
                    var tableName          = ChannelManager.GetTableName(siteInfo, contentChannelInfo);
                    var contentInfo        = ContentManager.GetContentInfo(siteInfo, contentChannelInfo, channelContentId.Id);
                    if (contentInfo == null)
                    {
                        continue;
                    }

                    var isTop = contentInfo.IsTop;
                    for (var i = 1; i <= taxis; i++)
                    {
                        if (isUp)
                        {
                            if (DataProvider.ContentDao.SetTaxisToUp(tableName, channelContentId.ChannelId, channelContentId.Id, isTop) == false)
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (DataProvider.ContentDao.SetTaxisToDown(tableName, channelContentId.ChannelId, channelContentId.Id, isTop) == false)
                            {
                                break;
                            }
                        }
                    }
                }

                foreach (var distinctChannelId in channelContentIds.Select(x => x.ChannelId).Distinct())
                {
                    CreateManager.TriggerContentChangedEvent(siteId, distinctChannelId);
                }

                request.AddSiteLog(siteId, channelId, 0, "对内容排序", string.Empty);

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #5
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new RequestImpl();

                var siteId        = request.GetPostInt("siteId");
                var channelId     = request.GetPostInt("channelId");
                var contentIdList = TranslateUtils.StringCollectionToIntList(request.GetPostString("contentIds"));
                var pageType      = request.GetPostString("pageType");
                var groupNames    = TranslateUtils.StringCollectionToStringList(request.GetPostString("groupNames"));
                var groupName     = request.GetPostString("groupName");
                var description   = request.GetPostString("description");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentEdit))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (pageType == "setGroup")
                {
                    foreach (var contentId in contentIdList)
                    {
                        var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                        if (contentInfo == null)
                        {
                            continue;
                        }

                        var list = TranslateUtils.StringCollectionToStringList(contentInfo.GroupNameCollection);
                        foreach (var name in groupNames)
                        {
                            if (!list.Contains(name))
                            {
                                list.Add(name);
                            }
                        }
                        contentInfo.GroupNameCollection = TranslateUtils.ObjectCollectionToString(list);

                        DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                    }

                    request.AddSiteLog(siteId, "批量设置内容组", $"内容组:{TranslateUtils.ObjectCollectionToString(groupNames)}");
                }
                else if (pageType == "cancelGroup")
                {
                    foreach (var contentId in contentIdList)
                    {
                        var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                        if (contentInfo == null)
                        {
                            continue;
                        }

                        var list = TranslateUtils.StringCollectionToStringList(contentInfo.GroupNameCollection);
                        foreach (var name in groupNames)
                        {
                            if (list.Contains(name))
                            {
                                list.Remove(name);
                            }
                        }
                        contentInfo.GroupNameCollection = TranslateUtils.ObjectCollectionToString(list);

                        DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                    }

                    request.AddSiteLog(siteId, "批量取消内容组", $"内容组:{TranslateUtils.ObjectCollectionToString(groupNames)}");
                }
                else if (pageType == "addGroup")
                {
                    var groupInfo = new ContentGroupInfo
                    {
                        GroupName   = AttackUtils.FilterXss(groupName),
                        SiteId      = siteId,
                        Description = AttackUtils.FilterXss(description)
                    };

                    if (ContentGroupManager.IsExists(siteId, groupInfo.GroupName))
                    {
                        DataProvider.ContentGroupDao.Update(groupInfo);
                        request.AddSiteLog(siteId, "修改内容组", $"内容组:{groupInfo.GroupName}");
                    }
                    else
                    {
                        DataProvider.ContentGroupDao.Insert(groupInfo);
                        request.AddSiteLog(siteId, "添加内容组", $"内容组:{groupInfo.GroupName}");
                    }

                    foreach (var contentId in contentIdList)
                    {
                        var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                        if (contentInfo == null)
                        {
                            continue;
                        }

                        var list = TranslateUtils.StringCollectionToStringList(contentInfo.GroupNameCollection);
                        if (!list.Contains(groupInfo.GroupName))
                        {
                            list.Add(groupInfo.GroupName);
                        }
                        contentInfo.GroupNameCollection = TranslateUtils.ObjectCollectionToString(list);

                        DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                    }

                    request.AddSiteLog(siteId, "批量设置内容组", $"内容组:{groupInfo.GroupName}");
                }

                return(Ok(new
                {
                    Value = contentIdList
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #6
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new RequestImpl();

                var siteId        = request.GetPostInt("siteId");
                var channelId     = request.GetPostInt("channelId");
                var contentIdList = TranslateUtils.StringCollectionToIntList(request.GetPostString("contentIds"));
                var pageType      = request.GetPostString("pageType");
                var isRecommend   = request.GetPostBool("isRecommend");
                var isHot         = request.GetPostBool("isHot");
                var isColor       = request.GetPostBool("isColor");
                var isTop         = request.GetPostBool("isTop");
                var hits          = request.GetPostInt("hits");

                if (!request.IsUserLoggin ||
                    !request.UserPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                       ConfigManager.ChannelPermissions.ContentEdit))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (pageType == "setAttributes")
                {
                    if (isRecommend || isHot || isColor || isTop)
                    {
                        foreach (var contentId in contentIdList)
                        {
                            var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                            if (contentInfo == null)
                            {
                                continue;
                            }

                            if (isRecommend)
                            {
                                contentInfo.IsRecommend = true;
                            }
                            if (isHot)
                            {
                                contentInfo.IsHot = true;
                            }
                            if (isColor)
                            {
                                contentInfo.IsColor = true;
                            }
                            if (isTop)
                            {
                                contentInfo.IsTop = true;
                            }
                            DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                        }

                        request.AddSiteLog(siteId, "设置内容属性");
                    }
                }
                else if (pageType == "cancelAttributes")
                {
                    if (isRecommend || isHot || isColor || isTop)
                    {
                        foreach (var contentId in contentIdList)
                        {
                            var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                            if (contentInfo == null)
                            {
                                continue;
                            }

                            if (isRecommend)
                            {
                                contentInfo.IsRecommend = false;
                            }
                            if (isHot)
                            {
                                contentInfo.IsHot = false;
                            }
                            if (isColor)
                            {
                                contentInfo.IsColor = false;
                            }
                            if (isTop)
                            {
                                contentInfo.IsTop = false;
                            }
                            DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                        }

                        request.AddSiteLog(siteId, "取消内容属性");
                    }
                }
                else if (pageType == "setHits")
                {
                    foreach (var contentId in contentIdList)
                    {
                        var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                        if (contentInfo == null)
                        {
                            continue;
                        }

                        contentInfo.Hits = hits;
                        DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                    }

                    request.AddSiteLog(siteId, "设置内容点击量");
                }

                return(Ok(new
                {
                    Value = contentIdList
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #7
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            int insertChannelId;

            try
            {
                var channelId = AuthRequest.GetQueryInt("ChannelId");
                var nodeInfo  = new ChannelInfo
                {
                    ParentId                = channelId,
                    ContentModelPluginId    = DdlContentModelPluginId.SelectedValue,
                    ContentRelatedPluginIds =
                        ControlUtils.GetSelectedListControlValueCollection(CblContentRelatedPluginIds)
                };

                if (TbNodeIndexName.Text.Length != 0)
                {
                    var nodeIndexNameArrayList = DataProvider.ChannelDao.GetIndexNameList(SiteId);
                    if (nodeIndexNameArrayList.IndexOf(TbNodeIndexName.Text) != -1)
                    {
                        FailMessage("栏目添加失败,栏目索引已存在!");
                        return;
                    }
                }

                if (TbFilePath.Text.Length != 0)
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(TbFilePath.Text))
                    {
                        FailMessage("栏目页面路径不符合系统要求!");
                        return;
                    }

                    if (PathUtils.IsDirectoryPath(TbFilePath.Text))
                    {
                        TbFilePath.Text = PageUtils.Combine(TbFilePath.Text, "index.html");
                    }

                    var filePathArrayList = DataProvider.ChannelDao.GetAllFilePathBySiteId(SiteId);
                    if (filePathArrayList.IndexOf(TbFilePath.Text) != -1)
                    {
                        FailMessage("栏目添加失败,栏目页面路径已存在!");
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(TbChannelFilePathRule.Text))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(TbChannelFilePathRule.Text))
                    {
                        FailMessage("栏目页面命名规则不符合系统要求!");
                        return;
                    }
                    if (PathUtils.IsDirectoryPath(TbChannelFilePathRule.Text))
                    {
                        FailMessage("栏目页面命名规则必须包含生成文件的后缀!");
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(TbContentFilePathRule.Text))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(TbContentFilePathRule.Text))
                    {
                        FailMessage("内容页面命名规则不符合系统要求!");
                        return;
                    }
                    if (PathUtils.IsDirectoryPath(TbContentFilePathRule.Text))
                    {
                        FailMessage("内容页面命名规则必须包含生成文件的后缀!");
                        return;
                    }
                }

                var extendedAttributes = new ExtendedAttributes();
                var relatedIdentities  = RelatedIdentities.GetChannelRelatedIdentities(SiteId, _channelId);
                var styleInfoList      = TableStyleManager.GetTableStyleInfoList(DataProvider.ChannelDao.TableName, relatedIdentities);
                BackgroundInputTypeParser.SaveAttributes(extendedAttributes, SiteInfo, styleInfoList, Request.Form, null);
                var attributes = extendedAttributes.ToNameValueCollection();
                nodeInfo.Additional.Load(attributes);
                //foreach (string key in attributes)
                //{
                //    nodeInfo.Additional.SetExtendedAttribute(key, attributes[key]);
                //}

                nodeInfo.ChannelName         = TbNodeName.Text;
                nodeInfo.IndexName           = TbNodeIndexName.Text;
                nodeInfo.FilePath            = TbFilePath.Text;
                nodeInfo.ChannelFilePathRule = TbChannelFilePathRule.Text;
                nodeInfo.ContentFilePathRule = TbContentFilePathRule.Text;

                var list = new ArrayList();
                foreach (ListItem item in CblNodeGroupNameCollection.Items)
                {
                    if (item.Selected)
                    {
                        list.Add(item.Value);
                    }
                }
                nodeInfo.GroupNameCollection         = TranslateUtils.ObjectCollectionToString(list);
                nodeInfo.ImageUrl                    = TbImageUrl.Text;
                nodeInfo.Content                     = ContentUtility.TextEditorContentEncode(SiteInfo, Request.Form[ChannelAttribute.Content]);
                nodeInfo.Keywords                    = TbKeywords.Text;
                nodeInfo.Description                 = TbDescription.Text;
                nodeInfo.Additional.IsChannelAddable = TranslateUtils.ToBool(RblIsChannelAddable.SelectedValue);
                nodeInfo.Additional.IsContentAddable = TranslateUtils.ToBool(RblIsContentAddable.SelectedValue);

                nodeInfo.LinkUrl  = TbLinkUrl.Text;
                nodeInfo.LinkType = DdlLinkType.SelectedValue;

                nodeInfo.Additional.DefaultTaxisType = ETaxisTypeUtils.GetValue(ETaxisTypeUtils.GetEnumType(DdlTaxisType.SelectedValue));

                nodeInfo.ChannelTemplateId = DdlChannelTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlChannelTemplateId.SelectedValue) : 0;
                nodeInfo.ContentTemplateId = DdlContentTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlContentTemplateId.SelectedValue) : 0;

                nodeInfo.AddDate = DateTime.Now;
                insertChannelId  = DataProvider.ChannelDao.Insert(nodeInfo);
                //栏目选择投票样式后,内容
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                FailMessage(ex, $"栏目添加失败:{ex.Message}");
                return;
            }

            CreateManager.CreateChannel(SiteId, insertChannelId);

            AuthRequest.AddSiteLog(SiteId, "添加栏目", $"栏目:{TbNodeName.Text}");

            SuccessMessage("栏目添加成功!");
            AddWaitAndRedirectScript(ReturnUrl);
        }
Example #8
0
        public static ContentInfo Calculate(int sequence, ContentInfo contentInfo, List <ContentColumn> columns, Dictionary <string, Dictionary <string, Func <IContentContext, string> > > pluginColumns)
        {
            if (contentInfo == null)
            {
                return(null);
            }

            var retVal = new ContentInfo(contentInfo.ToDictionary());

            foreach (var column in columns)
            {
                //添加审核人的名称转换
                //if (column.AttributeName == "CheckUserName")
                //{
                //    column.IsCalculate = true;
                //}

                if (!column.IsCalculate)
                {
                    continue;
                }

                if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.Sequence))
                {
                    retVal.Set(ContentAttribute.Sequence, sequence);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.AdminId))
                {
                    var value = string.Empty;
                    if (contentInfo.AdminId > 0)
                    {
                        var adminInfo = AdminManager.GetAdminInfoByUserId(contentInfo.AdminId);
                        if (adminInfo != null)
                        {
                            value = string.IsNullOrEmpty(adminInfo.DisplayName) ? adminInfo.UserName : adminInfo.DisplayName;
                        }
                    }
                    retVal.Set(ContentAttribute.AdminId, value);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.UserId))
                {
                    var value = string.Empty;
                    if (contentInfo.UserId > 0)
                    {
                        var userInfo = UserManager.GetUserInfoByUserId(contentInfo.UserId);
                        if (userInfo != null)
                        {
                            value = string.IsNullOrEmpty(userInfo.DisplayName) ? userInfo.UserName : userInfo.DisplayName;
                        }
                    }
                    retVal.Set(ContentAttribute.UserId, value);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.SourceId))
                {
                    retVal.Set(ContentAttribute.SourceId, SourceManager.GetSourceName(contentInfo.SourceId));
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.AddUserName))
                {
                    var value = string.Empty;
                    if (!string.IsNullOrEmpty(contentInfo.AddUserName))
                    {
                        var adminInfo = AdminManager.GetAdminInfoByUserName(contentInfo.AddUserName);
                        if (adminInfo != null)
                        {
                            value = string.IsNullOrEmpty(adminInfo.DisplayName) ? adminInfo.UserName : adminInfo.DisplayName;
                        }
                    }
                    retVal.Set(ContentAttribute.AddUserName, value);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.LastEditUserName))
                {
                    var value = string.Empty;
                    if (!string.IsNullOrEmpty(contentInfo.LastEditUserName))
                    {
                        var adminInfo = AdminManager.GetAdminInfoByUserName(contentInfo.LastEditUserName);
                        if (adminInfo != null)
                        {
                            value = string.IsNullOrEmpty(adminInfo.DisplayName) ? adminInfo.UserName : adminInfo.DisplayName;
                        }
                    }
                    retVal.Set(ContentAttribute.LastEditUserName, value);
                }
                //else if (StringUtils.EqualsIgnoreCase(column.AttributeName, ContentAttribute.CheckUserName))
                //{
                //    var value = string.Empty;
                //    if (!string.IsNullOrEmpty(contentInfo.))
                //    {
                //        var adminInfo = AdminManager.GetAdminInfoByUserName(contentInfo.CheckUserName);
                //        if (adminInfo != null)
                //        {
                //            value = string.IsNullOrEmpty(adminInfo.DisplayName) ? adminInfo.UserName : adminInfo.DisplayName;
                //        }
                //    }
                //    retVal.Set(ContentAttribute.CheckUserName, value);
                //}
            }

            if (pluginColumns != null)
            {
                foreach (var pluginId in pluginColumns.Keys)
                {
                    var contentColumns = pluginColumns[pluginId];
                    if (contentColumns == null || contentColumns.Count == 0)
                    {
                        continue;
                    }

                    foreach (var columnName in contentColumns.Keys)
                    {
                        var attributeName = $"{pluginId}:{columnName}";
                        if (columns.All(x => x.AttributeName != attributeName))
                        {
                            continue;
                        }

                        try
                        {
                            var func  = contentColumns[columnName];
                            var value = func(new ContentContextImpl
                            {
                                SiteId    = contentInfo.SiteId,
                                ChannelId = contentInfo.ChannelId,
                                ContentId = contentInfo.Id
                            });

                            retVal.Set(attributeName, value);
                        }
                        catch (Exception ex)
                        {
                            LogUtils.AddErrorLog(pluginId, ex);
                        }
                    }
                }
            }

            return(retVal);
        }
Example #9
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            var isChanged = false;

            try
            {
                var nodeInfo = ChannelManager.GetChannelInfo(SiteId, _channelId);

                if (!nodeInfo.IndexName.Equals(TbNodeIndexName.Text) && TbNodeIndexName.Text.Length != 0)
                {
                    var nodeIndexNameList = DataProvider.ChannelDao.GetIndexNameList(SiteId);
                    if (nodeIndexNameList.IndexOf(TbNodeIndexName.Text) != -1)
                    {
                        FailMessage("栏目修改失败,栏目索引已存在!");
                        return;
                    }
                }

                if (PhFilePath.Visible)
                {
                    TbFilePath.Text = TbFilePath.Text.Trim();
                    if (!nodeInfo.FilePath.Equals(TbFilePath.Text) && TbFilePath.Text.Length != 0)
                    {
                        if (!DirectoryUtils.IsDirectoryNameCompliant(TbFilePath.Text))
                        {
                            FailMessage("栏目页面路径不符合系统要求!");
                            return;
                        }

                        if (PathUtils.IsDirectoryPath(TbFilePath.Text))
                        {
                            TbFilePath.Text = PageUtils.Combine(TbFilePath.Text, "index.html");
                        }

                        var filePathArrayList = DataProvider.ChannelDao.GetAllFilePathBySiteId(SiteId);
                        if (filePathArrayList.IndexOf(TbFilePath.Text) != -1)
                        {
                            FailMessage("栏目修改失败,栏目页面路径已存在!");
                            return;
                        }
                    }
                }

                var extendedAttributes = new ExtendedAttributes();
                var relatedIdentities  = RelatedIdentities.GetChannelRelatedIdentities(SiteId, _channelId);
                var styleInfoList      = TableStyleManager.GetTableStyleInfoList(DataProvider.ChannelDao.TableName,
                                                                                 relatedIdentities);
                BackgroundInputTypeParser.SaveAttributes(extendedAttributes, SiteInfo, styleInfoList, Request.Form, null);
                if (extendedAttributes.Count > 0)
                {
                    nodeInfo.Additional.Load(extendedAttributes.ToDictionary());
                }

                nodeInfo.ChannelName = TbNodeName.Text;
                nodeInfo.IndexName   = TbNodeIndexName.Text;
                if (PhFilePath.Visible)
                {
                    nodeInfo.FilePath = TbFilePath.Text;
                }

                var list = new ArrayList();
                foreach (ListItem item in CblNodeGroupNameCollection.Items)
                {
                    if (item.Selected)
                    {
                        list.Add(item.Value);
                    }
                }
                nodeInfo.GroupNameCollection = TranslateUtils.ObjectCollectionToString(list);
                nodeInfo.ImageUrl            = TbImageUrl.Text;
                nodeInfo.Content             = ContentUtility.TextEditorContentEncode(SiteInfo, Request.Form[ChannelAttribute.Content]);
                if (TbKeywords.Visible)
                {
                    nodeInfo.Keywords = TbKeywords.Text;
                }
                if (TbDescription.Visible)
                {
                    nodeInfo.Description = TbDescription.Text;
                }

                if (PhLinkUrl.Visible)
                {
                    nodeInfo.LinkUrl = TbLinkUrl.Text;
                }
                if (PhLinkType.Visible)
                {
                    nodeInfo.LinkType = DdlLinkType.SelectedValue;
                }
                nodeInfo.Additional.DefaultTaxisType = ETaxisTypeUtils.GetValue(ETaxisTypeUtils.GetEnumType(DdlTaxisType.SelectedValue));
                if (PhChannelTemplateId.Visible)
                {
                    nodeInfo.ChannelTemplateId = DdlChannelTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlChannelTemplateId.SelectedValue) : 0;
                }
                nodeInfo.ContentTemplateId = DdlContentTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlContentTemplateId.SelectedValue) : 0;

                DataProvider.ChannelDao.Update(nodeInfo);

                AuthRequest.AddSiteLog(SiteId, _channelId, 0, "修改栏目", $"栏目:{nodeInfo.ChannelName}");

                isChanged = true;
            }
            catch (Exception ex)
            {
                FailMessage(ex, $"栏目修改失败:{ex.Message}");
                LogUtils.AddErrorLog(ex);
            }

            if (isChanged)
            {
                CreateManager.CreateChannel(SiteId, _channelId);

                if (string.IsNullOrEmpty(_returnUrl))
                {
                    LayerUtils.Close(Page);
                }
                else
                {
                    LayerUtils.CloseAndRedirect(Page, _returnUrl);
                }
            }
        }
Example #10
0
        public IHttpActionResult GetSiteContents(int siteId)
        {
            try
            {
                var  request  = new RequestImpl();
                var  sourceId = request.GetPostInt(ContentAttribute.SourceId.ToCamelCase());
                bool isAuth;
                if (sourceId == SourceManager.User)
                {
                    isAuth = request.IsUserLoggin && request.UserPermissions.HasChannelPermissions(siteId, siteId, ConfigManager.ChannelPermissions.ContentView);
                }
                else
                {
                    isAuth = request.IsApiAuthenticated &&
                             AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeContents) ||
                             request.IsUserLoggin &&
                             request.UserPermissions.HasChannelPermissions(siteId, siteId,
                                                                           ConfigManager.ChannelPermissions.ContentView) ||
                             request.IsAdminLoggin &&
                             request.AdminPermissions.HasChannelPermissions(siteId, siteId,
                                                                            ConfigManager.ChannelPermissions.ContentView);
                }
                if (!isAuth)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                if (!request.AdminPermissionsImpl.HasChannelPermissions(siteId, siteId,
                                                                        ConfigManager.ChannelPermissions.ContentView))
                {
                    return(Unauthorized());
                }

                var tableName = siteInfo.TableName;

                var parameters = new ApiContentsParameters(request);

                var tupleList = DataProvider.ContentDao.ApiGetContentIdListBySiteId(tableName, siteId, parameters, out var count);
                var value     = new List <Dictionary <string, object> >();
                foreach (var tuple in tupleList)
                {
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, tuple.Item1, tuple.Item2);
                    if (contentInfo != null)
                    {
                        value.Add(contentInfo.ToDictionary());
                    }
                }

                return(Ok(new PageResponse(value, parameters.Top, parameters.Skip, request.HttpRequest.Url.AbsoluteUri)
                {
                    Count = count
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #11
0
        public IHttpActionResult GetChannelContents(int siteId, int channelId)
        {
            try
            {
                var  request  = new RequestImpl();
                var  sourceId = request.GetPostInt(ContentAttribute.SourceId.ToCamelCase());
                bool isAuth;
                if (sourceId == SourceManager.User)
                {
                    isAuth = request.IsUserLoggin && request.UserPermissions.HasChannelPermissions(siteId, channelId, ConfigManager.ChannelPermissions.ContentView);
                }
                else
                {
                    isAuth = request.IsApiAuthenticated &&
                             AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeContents) ||
                             request.IsUserLoggin &&
                             request.UserPermissions.HasChannelPermissions(siteId, channelId,
                                                                           ConfigManager.ChannelPermissions.ContentView) ||
                             request.IsAdminLoggin &&
                             request.AdminPermissions.HasChannelPermissions(siteId, channelId,
                                                                            ConfigManager.ChannelPermissions.ContentView);
                }
                if (!isAuth)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (!request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentView))
                {
                    return(Unauthorized());
                }

                var tableName = ChannelManager.GetTableName(siteInfo, channelInfo);

                var top     = request.GetQueryInt("top", 20);
                var skip    = request.GetQueryInt("skip");
                var like    = request.GetQueryString("like");
                var orderBy = request.GetQueryString("orderBy");

                int count;
                var contentIdList = DataProvider.ContentDao.ApiGetContentIdListByChannelId(tableName, siteId, channelId, top, skip, like, orderBy, request.QueryString, out count);
                var value         = new List <Dictionary <string, object> >();
                foreach (var contentId in contentIdList)
                {
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                    if (contentInfo != null)
                    {
                        value.Add(contentInfo.ToDictionary());
                    }
                }

                return(Ok(new PageResponse(value, top, skip, request.HttpRequest.Url.AbsoluteUri)
                {
                    Count = count
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #12
0
        public IHttpActionResult Get(int siteId, int channelId, int id)
        {
            try
            {
                var  request  = new RequestImpl();
                var  sourceId = request.GetPostInt(ContentAttribute.SourceId.ToCamelCase());
                bool isAuth;
                if (sourceId == SourceManager.User)
                {
                    isAuth = request.IsUserLoggin && request.UserPermissions.HasChannelPermissions(siteId, channelId, ConfigManager.ChannelPermissions.ContentView);
                }
                else
                {
                    isAuth = request.IsApiAuthenticated &&
                             AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeContents) ||
                             request.IsUserLoggin &&
                             request.UserPermissions.HasChannelPermissions(siteId, channelId,
                                                                           ConfigManager.ChannelPermissions.ContentView) ||
                             request.IsAdminLoggin &&
                             request.AdminPermissions.HasChannelPermissions(siteId, channelId,
                                                                            ConfigManager.ChannelPermissions.ContentView);
                }
                if (!isAuth)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (!request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentView))
                {
                    return(Unauthorized());
                }

                var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, id);
                if (contentInfo == null)
                {
                    return(NotFound());
                }

                return(Ok(new
                {
                    Value = contentInfo
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #13
0
        public IHttpActionResult Create(int siteId, int channelId)
        {
            try
            {
                var  request  = new RequestImpl();
                var  sourceId = request.GetPostInt(ContentAttribute.SourceId.ToCamelCase());
                bool isAuth;
                if (sourceId == SourceManager.User)
                {
                    isAuth = request.IsUserLoggin && request.UserPermissions.HasChannelPermissions(siteId, channelId, ConfigManager.ChannelPermissions.ContentAdd);
                }
                else
                {
                    isAuth = request.IsApiAuthenticated &&
                             AccessTokenManager.IsScope(request.ApiToken, AccessTokenManager.ScopeContents) ||
                             request.IsUserLoggin &&
                             request.UserPermissions.HasChannelPermissions(siteId, channelId,
                                                                           ConfigManager.ChannelPermissions.ContentAdd) ||
                             request.IsAdminLoggin &&
                             request.AdminPermissions.HasChannelPermissions(siteId, channelId,
                                                                            ConfigManager.ChannelPermissions.ContentAdd);
                }
                if (!isAuth)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                if (!channelInfo.Additional.IsContentAddable)
                {
                    return(BadRequest("此栏目不能添加内容"));
                }

                var attributes = request.GetPostObject <Dictionary <string, object> >();
                if (attributes == null)
                {
                    return(BadRequest("无法从body中获取内容实体"));
                }
                var checkedLevel = request.GetPostInt("checkedLevel");

                var tableName = ChannelManager.GetTableName(siteInfo, channelInfo);
                var adminName = request.AdminName;

                var isChecked = checkedLevel >= siteInfo.Additional.CheckContentLevel;
                if (isChecked)
                {
                    if (sourceId == SourceManager.User || request.IsUserLoggin)
                    {
                        isChecked = request.UserPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                                      ConfigManager.ChannelPermissions.ContentCheck);
                    }
                    else if (request.IsAdminLoggin)
                    {
                        isChecked = request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                                       ConfigManager.ChannelPermissions.ContentCheck);
                    }
                }

                var contentInfo = new ContentInfo(attributes)
                {
                    SiteId           = siteId,
                    ChannelId        = channelId,
                    AddUserName      = adminName,
                    LastEditDate     = DateTime.Now,
                    LastEditUserName = adminName,
                    AdminId          = request.AdminId,
                    UserId           = request.UserId,
                    SourceId         = sourceId,
                    IsChecked        = isChecked,
                    CheckedLevel     = checkedLevel
                };

                contentInfo.Id = DataProvider.ContentDao.Insert(tableName, siteInfo, channelInfo, contentInfo);

                foreach (var service in PluginManager.Services)
                {
                    try
                    {
                        service.OnContentFormSubmit(new ContentFormSubmitEventArgs(siteId, channelId, contentInfo.Id, new AttributesImpl(attributes), contentInfo));
                    }
                    catch (Exception ex)
                    {
                        LogUtils.AddErrorLog(service.PluginId, ex, nameof(IService.ContentFormSubmit));
                    }
                }

                if (contentInfo.IsChecked)
                {
                    CreateManager.CreateContent(siteId, channelId, contentInfo.Id);
                    CreateManager.TriggerContentChangedEvent(siteId, channelId);
                }

                request.AddSiteLog(siteId, channelId, contentInfo.Id, "添加内容",
                                   $"栏目:{ChannelManager.GetChannelNameNavigation(siteId, contentInfo.ChannelId)},内容标题:{contentInfo.Title}");

                return(Ok(new
                {
                    Value = contentInfo
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #14
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                var targetNodeID = int.Parse(NodeIDTo.SelectedValue);

                var targetPublishmentSystemID   = int.Parse(PublishmentSystemIDDropDownList.SelectedValue);
                var targetPublishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(targetPublishmentSystemID);
                var isChecked    = false;
                var checkedLevel = 0;
                if (targetPublishmentSystemInfo.CheckContentLevel == 0 || AdminUtility.HasChannelPermissions(Body.AdministratorName, targetPublishmentSystemID, targetNodeID, AppManager.Cms.Permission.Channel.ContentAdd, AppManager.Cms.Permission.Channel.ContentCheck))
                {
                    isChecked    = true;
                    checkedLevel = 0;
                }
                else
                {
                    var UserCheckLevel  = 0;
                    var OwnHighestLevel = false;

                    if (AdminUtility.HasChannelPermissions(Body.AdministratorName, targetPublishmentSystemID, targetNodeID, AppManager.Cms.Permission.Channel.ContentCheckLevel1))
                    {
                        UserCheckLevel = 1;
                        if (AdminUtility.HasChannelPermissions(Body.AdministratorName, targetPublishmentSystemID, targetNodeID, AppManager.Cms.Permission.Channel.ContentCheckLevel2))
                        {
                            UserCheckLevel = 2;
                            if (AdminUtility.HasChannelPermissions(Body.AdministratorName, targetPublishmentSystemID, targetNodeID, AppManager.Cms.Permission.Channel.ContentCheckLevel3))
                            {
                                UserCheckLevel = 3;
                                if (AdminUtility.HasChannelPermissions(Body.AdministratorName, targetPublishmentSystemID, targetNodeID, AppManager.Cms.Permission.Channel.ContentCheckLevel4))
                                {
                                    UserCheckLevel = 4;
                                    if (AdminUtility.HasChannelPermissions(Body.AdministratorName, targetPublishmentSystemID, targetNodeID, AppManager.Cms.Permission.Channel.ContentCheckLevel5))
                                    {
                                        UserCheckLevel = 5;
                                    }
                                }
                            }
                        }
                    }

                    if (UserCheckLevel >= targetPublishmentSystemInfo.CheckContentLevel)
                    {
                        OwnHighestLevel = true;
                    }
                    if (OwnHighestLevel)
                    {
                        isChecked    = true;
                        checkedLevel = 0;
                    }
                    else
                    {
                        isChecked    = false;
                        checkedLevel = UserCheckLevel;
                    }
                }

                try
                {
                    var translateType = ETranslateTypeUtils.GetEnumType(TranslateType.SelectedValue);

                    var nodeIDStrArrayList = ControlUtils.GetSelectedListControlValueArrayList(NodeIDFrom);

                    var nodeIDArrayList = new ArrayList();//需要转移的栏目ID
                    foreach (string nodeIDStr in nodeIDStrArrayList)
                    {
                        var nodeID = int.Parse(nodeIDStr);
                        if (translateType != ETranslateType.Content)//需要转移栏目
                        {
                            if (!NodeManager.IsAncestorOrSelf(PublishmentSystemId, nodeID, targetNodeID))
                            {
                                nodeIDArrayList.Add(nodeID);
                            }
                        }

                        if (translateType == ETranslateType.Content)//转移内容
                        {
                            TranslateContent(targetPublishmentSystemInfo, nodeID, targetNodeID, isChecked, checkedLevel);
                        }
                    }

                    if (translateType != ETranslateType.Content)//需要转移栏目
                    {
                        var nodeIDArrayListToTranslate = new ArrayList(nodeIDArrayList);
                        foreach (int nodeID in nodeIDArrayList)
                        {
                            var subNodeIDArrayList = DataProvider.NodeDao.GetNodeIdListForDescendant(nodeID);
                            if (subNodeIDArrayList != null && subNodeIDArrayList.Count > 0)
                            {
                                foreach (int nodeIDToDelete in subNodeIDArrayList)
                                {
                                    if (nodeIDArrayListToTranslate.Contains(nodeIDToDelete))
                                    {
                                        nodeIDArrayListToTranslate.Remove(nodeIDToDelete);
                                    }
                                }
                            }
                        }

                        var nodeInfoList = new List <NodeInfo>();
                        foreach (int nodeID in nodeIDArrayListToTranslate)
                        {
                            var nodeInfo = NodeManager.GetNodeInfo(PublishmentSystemId, nodeID);
                            nodeInfoList.Add(nodeInfo);
                        }

                        TranslateChannelAndContent(nodeInfoList, targetPublishmentSystemID, targetNodeID, translateType, isChecked, checkedLevel, null, null);

                        if (IsDeleteAfterTranslate.Visible && EBooleanUtils.Equals(IsDeleteAfterTranslate.SelectedValue, EBoolean.True))
                        {
                            foreach (int nodeID in nodeIDArrayListToTranslate)
                            {
                                try
                                {
                                    DataProvider.NodeDao.Delete(nodeID);
                                }
                                catch { }
                            }
                        }
                    }
                    Submit.Enabled = false;

                    var builder = new StringBuilder();
                    foreach (ListItem listItem in NodeIDFrom.Items)
                    {
                        if (listItem.Selected)
                        {
                            builder.Append(listItem.Text).Append(",");
                        }
                    }
                    if (builder.Length > 0)
                    {
                        builder.Length = builder.Length - 1;
                    }
                    Body.AddSiteLog(PublishmentSystemId, "批量转移", $"栏目:{builder},转移后删除:{IsDeleteAfterTranslate.SelectedValue}");

                    SuccessMessage("批量转移成功!");
                    if (Body.IsQueryExists("ChannelIDCollection"))
                    {
                        PageUtils.Redirect(returnUrl);
                    }
                    else
                    {
                        PageUtils.Redirect(GetRedirectUrl(PublishmentSystemId));
                    }
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "批量转移失败!");
                    LogUtils.AddErrorLog(ex);
                }
            }
        }
Example #15
0
        public IHttpActionResult GetConfig()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId        = request.GetQueryInt("siteId");
                var channelId     = request.GetQueryInt("channelId");
                var contentIdList = TranslateUtils.StringCollectionToIntList(request.GetQueryString("contentIds"));

                if (!request.IsUserLoggin ||
                    !request.UserPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                       ConfigManager.ChannelPermissions.ContentCheck))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var retVal = new List <Dictionary <string, object> >();
                foreach (var contentId in contentIdList)
                {
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                    if (contentInfo == null)
                    {
                        continue;
                    }

                    var dict = contentInfo.ToDictionary();
                    dict["checkState"] =
                        CheckManager.GetCheckState(siteInfo, contentInfo);
                    retVal.Add(dict);
                }

                var isChecked     = CheckManager.GetUserCheckLevel(request.AdminPermissionsImpl, siteInfo, channelId, out var checkedLevel);
                var checkedLevels = CheckManager.GetCheckedLevels(siteInfo, isChecked, checkedLevel, true);

                var allChannels =
                    ChannelManager.GetChannels(siteId, request.AdminPermissionsImpl, ConfigManager.ChannelPermissions.ContentAdd);

                return(Ok(new
                {
                    Value = retVal,
                    CheckedLevels = checkedLevels,
                    CheckedLevel = checkedLevel,
                    AllChannels = allChannels
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #16
0
 public static string GetStlErrorMessage(string elementName, Exception ex)
 {
     LogUtils.AddErrorLog(ex);
     return($"<!-- {elementName} error: {ex.Message} -->");
 }
Example #17
0
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId             = request.GetPostInt("siteId");
                var channelId          = request.GetPostInt("channelId");
                var contentIdList      = TranslateUtils.StringCollectionToIntList(request.GetPostString("contentIds"));
                var checkedLevel       = request.GetPostInt("checkedLevel");
                var isTranslate        = request.GetPostBool("isTranslate");
                var translateChannelId = request.GetPostInt("translateChannelId");
                var reasons            = request.GetPostString("reasons");

                if (!request.IsUserLoggin ||
                    !request.UserPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                       ConfigManager.ChannelPermissions.ContentCheck))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var isChecked = checkedLevel >= siteInfo.Additional.CheckContentLevel;
                if (isChecked)
                {
                    checkedLevel = 0;
                }
                var tableName = ChannelManager.GetTableName(siteInfo, channelInfo);

                var contentInfoList = new List <ContentInfo>();
                foreach (var contentId in contentIdList)
                {
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                    if (contentInfo == null)
                    {
                        continue;
                    }

                    contentInfo.Set(ContentAttribute.CheckUserName, request.AdminName);
                    contentInfo.Set(ContentAttribute.CheckDate, DateTime.Now);
                    contentInfo.Set(ContentAttribute.CheckReasons, reasons);

                    contentInfo.IsChecked    = isChecked;
                    contentInfo.CheckedLevel = checkedLevel;

                    if (isTranslate && translateChannelId > 0)
                    {
                        var translateChannelInfo = ChannelManager.GetChannelInfo(siteId, translateChannelId);
                        contentInfo.ChannelId = translateChannelInfo.Id;
                        DataProvider.ContentDao.Update(siteInfo, translateChannelInfo, contentInfo);
                    }
                    else
                    {
                        DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                    }

                    contentInfoList.Add(contentInfo);

                    var checkInfo = new ContentCheckInfo(0, tableName, siteId, contentInfo.ChannelId, contentInfo.Id, request.AdminName, isChecked, checkedLevel, DateTime.Now, reasons);
                    DataProvider.ContentCheckDao.Insert(checkInfo);
                }

                if (isTranslate && translateChannelId > 0)
                {
                    ContentManager.RemoveCache(siteId, channelId, tableName);
                    var translateTableName = ChannelManager.GetTableName(siteInfo, translateChannelId);
                    ContentManager.RemoveCache(siteInfo.Id, translateChannelId, translateTableName);
                }

                request.AddSiteLog(siteId, "批量审核内容");

                foreach (var contentInfo in contentInfoList)
                {
                    CreateManager.CreateContent(siteId, contentInfo.ChannelId, contentInfo.Id);
                }
                CreateManager.TriggerContentChangedEvent(siteId, channelId);
                if (isTranslate && translateChannelId > 0)
                {
                    CreateManager.TriggerContentChangedEvent(siteId, translateChannelId);
                }

                return(Ok(new
                {
                    Value = contentIdList
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #18
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (Page.IsPostBack && Page.IsValid)
            {
                try
                {
                    foreach (var nodeID in _idsDictionary.Keys)
                    {
                        var tableName     = NodeManager.GetTableName(PublishmentSystemInfo, nodeID);
                        var contentIDList = _idsDictionary[nodeID];

                        if (!_isDeleteFromTrash)
                        {
                            if (bool.Parse(RetainFiles.SelectedValue) == false)
                            {
                                DirectoryUtility.DeleteContents(PublishmentSystemInfo, nodeID, contentIDList);
                                SuccessMessage("成功删除内容以及生成页面!");
                            }
                            else
                            {
                                SuccessMessage("成功删除内容,生成页面未被删除!");
                            }

                            if (contentIDList.Count == 1)
                            {
                                var contentID    = contentIDList[0];
                                var contentTitle = BaiRongDataProvider.ContentDao.GetValue(tableName, contentID, ContentAttribute.Title);
                                Body.AddSiteLog(PublishmentSystemId, nodeID, contentID, "删除内容",
                                                $"栏目:{NodeManager.GetNodeNameNavigation(PublishmentSystemId, nodeID)},内容标题:{contentTitle}");
                            }
                            else
                            {
                                Body.AddSiteLog(PublishmentSystemId, "批量删除内容",
                                                $"栏目:{NodeManager.GetNodeNameNavigation(PublishmentSystemId, nodeID)},内容条数:{contentIDList.Count}");
                            }

                            DataProvider.ContentDao.TrashContents(PublishmentSystemId, tableName, contentIDList);

                            //引用内容,需要删除
                            var tableList = BaiRongDataProvider.TableCollectionDao.GetAuxiliaryTableListCreatedInDbByAuxiliaryTableType(EAuxiliaryTableType.BackgroundContent, EAuxiliaryTableType.JobContent, EAuxiliaryTableType.VoteContent);
                            foreach (AuxiliaryTableInfo table in tableList)
                            {
                                var targetContentIdList = BaiRongDataProvider.ContentDao.GetReferenceIdList(table.TableEnName, contentIDList);
                                if (targetContentIdList.Count > 0)
                                {
                                    var targetContentInfo = DataProvider.ContentDao.GetContentInfo(ETableStyleUtils.GetEnumType(table.AuxiliaryTableType.ToString()), table.TableEnName, TranslateUtils.ToInt(targetContentIdList[0].ToString()));
                                    DataProvider.ContentDao.DeleteContents(targetContentInfo.PublishmentSystemId, table.TableEnName, targetContentIdList, targetContentInfo.NodeId);
                                }
                            }

                            CreateManager.CreateContentTrigger(PublishmentSystemId, nodeID);
                        }
                        else
                        {
                            SuccessMessage("成功从回收站清空内容!");
                            DataProvider.ContentDao.DeleteContents(PublishmentSystemId, tableName, contentIDList, nodeID);

                            Body.AddSiteLog(PublishmentSystemId, "从回收站清空内容", $"内容条数:{contentIDList.Count}");
                        }
                    }


                    AddWaitAndRedirectScript(_returnUrl);
                }
                catch (Exception ex)
                {
                    FailMessage(ex, "删除内容失败!");

                    LogUtils.AddErrorLog(ex);
                }
            }
        }
        public IHttpActionResult Login()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var account     = request.GetPostString("account");
                var password    = request.GetPostString("password");
                var isAutoLogin = request.GetPostBool("isAutoLogin");

                AdministratorInfo adminInfo;

                if (!DataProvider.AdministratorDao.Validate(account, password, true, out var userName, out var errorMessage))
                {
                    adminInfo = AdminManager.GetAdminInfoByUserName(userName);
                    if (adminInfo != null)
                    {
                        DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfFailedLogin(adminInfo); // 记录最后登录时间、失败次数+1
                    }
                    return(BadRequest(errorMessage));
                }

                adminInfo = AdminManager.GetAdminInfoByUserName(userName);
                DataProvider.AdministratorDao.UpdateLastActivityDateAndCountOfLogin(adminInfo); // 记录最后登录时间、失败次数清零
                var accessToken = request.AdminLogin(adminInfo.UserName, isAutoLogin);
                var expiresAt   = DateTime.Now.AddDays(Constants.AccessTokenExpireDays);

                var sessionId = StringUtils.Guid();
                var cacheKey  = Constants.GetSessionIdCacheKey(adminInfo.Id);
                CacheUtils.Insert(cacheKey, sessionId);

                var isEnforcePasswordChange = false;
                if (ConfigManager.SystemConfigInfo.IsAdminEnforcePasswordChange)
                {
                    if (adminInfo.LastChangePasswordDate == null)
                    {
                        isEnforcePasswordChange = true;
                    }
                    else
                    {
                        var ts = new TimeSpan(DateTime.Now.Ticks - adminInfo.LastChangePasswordDate.Value.Ticks);
                        if (ts.TotalDays > ConfigManager.SystemConfigInfo.AdminEnforcePasswordChangeDays)
                        {
                            isEnforcePasswordChange = true;
                        }
                    }
                }

                return(Ok(new
                {
                    Value = adminInfo,
                    AccessToken = accessToken,
                    ExpiresAt = expiresAt,
                    SessionId = sessionId,
                    IsEnforcePasswordChange = isEnforcePasswordChange
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId            = request.GetPostInt("siteId");
                var channelContentIds =
                    MinContentInfo.ParseMinContentInfoList(request.GetPostString("channelContentIds"));
                var pageType    = request.GetPostString("pageType");
                var isRecommend = request.GetPostBool("isRecommend");
                var isHot       = request.GetPostBool("isHot");
                var isColor     = request.GetPostBool("isColor");
                var isTop       = request.GetPostBool("isTop");
                var hits        = request.GetPostInt("hits");

                if (!request.IsAdminLoggin)
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                if (pageType == "setAttributes")
                {
                    if (isRecommend || isHot || isColor || isTop)
                    {
                        foreach (var channelContentId in channelContentIds)
                        {
                            var channelInfo = ChannelManager.GetChannelInfo(siteId, channelContentId.ChannelId);
                            var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, channelContentId.Id);
                            if (contentInfo == null)
                            {
                                continue;
                            }

                            if (isRecommend)
                            {
                                contentInfo.IsRecommend = true;
                            }
                            if (isHot)
                            {
                                contentInfo.IsHot = true;
                            }
                            if (isColor)
                            {
                                contentInfo.IsColor = true;
                            }
                            if (isTop)
                            {
                                contentInfo.IsTop = true;
                            }
                            DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                        }

                        request.AddSiteLog(siteId, "设置内容属性");
                    }
                }
                else if (pageType == "cancelAttributes")
                {
                    if (isRecommend || isHot || isColor || isTop)
                    {
                        foreach (var channelContentId in channelContentIds)
                        {
                            var channelInfo = ChannelManager.GetChannelInfo(siteId, channelContentId.ChannelId);
                            var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, channelContentId.Id);
                            if (contentInfo == null)
                            {
                                continue;
                            }

                            if (isRecommend)
                            {
                                contentInfo.IsRecommend = false;
                            }
                            if (isHot)
                            {
                                contentInfo.IsHot = false;
                            }
                            if (isColor)
                            {
                                contentInfo.IsColor = false;
                            }
                            if (isTop)
                            {
                                contentInfo.IsTop = false;
                            }
                            DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                        }

                        request.AddSiteLog(siteId, "取消内容属性");
                    }
                }
                else if (pageType == "setHits")
                {
                    foreach (var channelContentId in channelContentIds)
                    {
                        var channelInfo = ChannelManager.GetChannelInfo(siteId, channelContentId.ChannelId);
                        var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, channelContentId.Id);
                        if (contentInfo == null)
                        {
                            continue;
                        }

                        contentInfo.Hits = hits;
                        DataProvider.ContentDao.Update(siteInfo, channelInfo, contentInfo);
                    }

                    request.AddSiteLog(siteId, "设置内容点击量");
                }

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId       = request.GetPostInt("siteId");
                var channelId    = request.GetPostInt("channelId");
                var importType   = request.GetPostString("importType");
                var checkedLevel = request.GetPostInt("checkedLevel");
                var isOverride   = request.GetPostBool("isOverride");
                var fileNames    = request.GetPostObject <List <string> >("fileNames");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentAdd))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var isChecked = checkedLevel >= siteInfo.Additional.CheckContentLevel;

                var contentIdList = new List <int>();

                if (importType == "zip")
                {
                    foreach (var fileName in fileNames)
                    {
                        var localFilePath = PathUtils.GetTemporaryFilesPath(fileName);

                        if (!EFileSystemTypeUtils.Equals(EFileSystemType.Zip, PathUtils.GetExtension(localFilePath)))
                        {
                            continue;
                        }

                        var importObject = new ImportObject(siteId, request.AdminName);
                        contentIdList.AddRange(importObject.ImportContentsByZipFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default));
                    }
                }
                else if (importType == "csv")
                {
                    foreach (var fileName in fileNames)
                    {
                        var localFilePath = PathUtils.GetTemporaryFilesPath(fileName);

                        if (!EFileSystemTypeUtils.Equals(EFileSystemType.Csv, PathUtils.GetExtension(localFilePath)))
                        {
                            continue;
                        }

                        var importObject = new ImportObject(siteId, request.AdminName);
                        contentIdList.AddRange(importObject.ImportContentsByCsvFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default));
                    }
                }
                else if (importType == "txt")
                {
                    foreach (var fileName in fileNames)
                    {
                        var localFilePath = PathUtils.GetTemporaryFilesPath(fileName);
                        if (!EFileSystemTypeUtils.Equals(EFileSystemType.Txt, PathUtils.GetExtension(localFilePath)))
                        {
                            continue;
                        }

                        var importObject = new ImportObject(siteId, request.AdminName);
                        contentIdList.AddRange(importObject.ImportContentsByTxtFile(channelInfo, localFilePath, isOverride, isChecked, checkedLevel, request.AdminId, 0, SourceManager.Default));
                    }
                }

                foreach (var contentId in contentIdList)
                {
                    CreateManager.CreateContent(siteId, channelInfo.Id, contentId);
                }
                CreateManager.CreateChannel(siteId, channelInfo.Id);

                request.AddSiteLog(siteId, channelId, 0, "导入内容", string.Empty);

                return(Ok(new
                {
                    Value = true
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #22
0
        public void Delete_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            try
            {
                var channelIdList = TranslateUtils.StringCollectionToIntList(AuthRequest.GetQueryString("ChannelIDCollection"));
                channelIdList.Sort();
                channelIdList.Reverse();

                var channelIdListToDelete = new List <int>();
                foreach (var channelId in channelIdList)
                {
                    if (channelId == SiteId)
                    {
                        continue;
                    }
                    if (HasChannelPermissions(channelId, ConfigManager.ChannelPermissions.ChannelDelete))
                    {
                        channelIdListToDelete.Add(channelId);
                    }
                }

                var builder = new StringBuilder();
                foreach (var channelId in channelIdListToDelete)
                {
                    builder.Append(ChannelManager.GetChannelName(SiteId, channelId)).Append(",");
                }

                if (builder.Length > 0)
                {
                    builder.Length -= 1;
                }

                if (_deleteContents)
                {
                    SuccessMessage(bool.Parse(RblRetainFiles.SelectedValue) == false
                        ? "成功删除内容以及生成页面!"
                        : "成功删除内容,生成页面未被删除!");

                    foreach (var channelId in channelIdListToDelete)
                    {
                        var tableName     = ChannelManager.GetTableName(SiteInfo, channelId);
                        var contentIdList = DataProvider.ContentDao.GetContentIdList(tableName, channelId);
                        DeleteManager.DeleteContents(SiteInfo, channelId, contentIdList);
                        DataProvider.ContentDao.UpdateTrashContents(SiteId, channelId, tableName, contentIdList);
                    }

                    AuthRequest.AddSiteLog(SiteId, "清空栏目下的内容", $"栏目:{builder}");
                }
                else
                {
                    if (bool.Parse(RblRetainFiles.SelectedValue) == false)
                    {
                        DeleteManager.DeleteChannels(SiteInfo, channelIdListToDelete);
                        SuccessMessage("成功删除栏目以及相关生成页面!");
                    }
                    else
                    {
                        SuccessMessage("成功删除栏目,相关生成页面未被删除!");
                    }

                    foreach (var channelId in channelIdListToDelete)
                    {
                        var tableName = ChannelManager.GetTableName(SiteInfo, channelId);
                        DataProvider.ContentDao.UpdateTrashContentsByChannelId(SiteId, channelId, tableName);
                        DataProvider.ChannelDao.Delete(SiteId, channelId);
                    }

                    AuthRequest.AddSiteLog(SiteId, "删除栏目", $"栏目:{builder}");
                }

                AddWaitAndRedirectScript(ReturnUrl);
            }
            catch (Exception ex)
            {
                FailMessage(ex, _deleteContents ? "删除内容失败!" : "删除栏目失败!");

                LogUtils.AddErrorLog(ex);
            }
        }
Example #23
0
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            var contentId   = AuthRequest.GetQueryInt("id");
            var redirectUrl = string.Empty;

            if (contentId == 0)
            {
                try
                {
                    var dict = BackgroundInputTypeParser.SaveAttributes(SiteInfo, _styleInfoList, Request.Form, ContentAttribute.AllAttributes.Value);

                    var contentInfo = new ContentInfo(dict)
                    {
                        ChannelId           = _channelInfo.Id,
                        SiteId              = SiteId,
                        AddUserName         = AuthRequest.AdminName,
                        LastEditDate        = DateTime.Now,
                        GroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(CblContentGroups.Items),
                        Title = TbTitle.Text
                    };

                    var formatString    = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatStrong"]);
                    var formatEm        = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatEM"]);
                    var formatU         = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatU"]);
                    var formatColor     = Request.Form[ContentAttribute.Title + "_formatColor"];
                    var theFormatString = ContentUtility.GetTitleFormatString(formatString, formatEm, formatU, formatColor);
                    contentInfo.Set(ContentAttribute.GetFormatStringAttributeName(ContentAttribute.Title), theFormatString);

                    contentInfo.LastEditUserName = contentInfo.AddUserName;

                    foreach (ListItem listItem in CblContentAttributes.Items)
                    {
                        var value         = listItem.Selected.ToString();
                        var attributeName = listItem.Value;
                        contentInfo.Set(attributeName, value);
                    }
                    contentInfo.LinkUrl = TbLinkUrl.Text;
                    contentInfo.AddDate = TbAddDate.DateTime;

                    contentInfo.CheckedLevel = TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue);
                    contentInfo.IsChecked    = contentInfo.CheckedLevel >= SiteInfo.Additional.CheckContentLevel;
                    contentInfo.Tags         = TranslateUtils.ObjectCollectionToString(TagUtils.ParseTagsString(TbTags.Text), " ");

                    foreach (var service in PluginManager.Services)
                    {
                        try
                        {
                            service.OnContentFormSubmit(new ContentFormSubmitEventArgs(SiteId, _channelInfo.Id,
                                                                                       contentInfo.Id, TranslateUtils.ToDictionary(Request.Form), contentInfo));
                        }
                        catch (Exception ex)
                        {
                            LogUtils.AddErrorLog(service.PluginId, ex, nameof(IService.ContentFormSubmit));
                        }
                    }


                    //判断是不是有审核权限
                    int checkedLevelOfUser;
                    var isCheckedOfUser = CheckManager.GetUserCheckLevel(AuthRequest.AdminPermissionsImpl, SiteInfo, contentInfo.ChannelId, out checkedLevelOfUser);
                    if (CheckManager.IsCheckable(contentInfo.IsChecked, contentInfo.CheckedLevel, isCheckedOfUser, checkedLevelOfUser))
                    {
                        if (contentInfo.IsChecked)
                        {
                            contentInfo.CheckedLevel = 0;
                        }

                        contentInfo.Set(ContentAttribute.CheckUserName, AuthRequest.AdminName);
                        contentInfo.Set(ContentAttribute.CheckDate, DateUtils.GetDateAndTimeString(DateTime.Now));
                        contentInfo.Set(ContentAttribute.CheckReasons, string.Empty);
                    }

                    contentInfo.Id = DataProvider.ContentDao.Insert(_tableName, SiteInfo, _channelInfo, contentInfo);

                    TagUtils.UpdateTags(string.Empty, TbTags.Text, SiteId, contentInfo.Id);

                    CreateManager.CreateContent(SiteId, _channelInfo.Id, contentInfo.Id);
                    CreateManager.TriggerContentChangedEvent(SiteId, _channelInfo.Id);

                    AuthRequest.AddSiteLog(SiteId, _channelInfo.Id, contentInfo.Id, "添加内容",
                                           $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, contentInfo.ChannelId)},内容标题:{contentInfo.Title}");

                    ContentUtility.Translate(SiteInfo, _channelInfo.Id, contentInfo.Id, Request.Form["translateCollection"], ETranslateContentTypeUtils.GetEnumType(DdlTranslateType.SelectedValue), AuthRequest.AdminName);

                    redirectUrl = PageContentAddAfter.GetRedirectUrl(SiteId, _channelInfo.Id, contentInfo.Id,
                                                                     ReturnUrl);
                }
                catch (Exception ex)
                {
                    LogUtils.AddErrorLog(ex);
                    FailMessage($"内容添加失败:{ex.Message}");
                }
            }
            else
            {
                var contentInfo = ContentManager.GetContentInfo(SiteInfo, _channelInfo, contentId);
                try
                {
                    contentInfo.LastEditUserName = AuthRequest.AdminName;
                    contentInfo.LastEditDate     = DateTime.Now;

                    var dict = BackgroundInputTypeParser.SaveAttributes(SiteInfo, _styleInfoList, Request.Form, ContentAttribute.AllAttributes.Value);
                    contentInfo.Load(dict);

                    contentInfo.GroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(CblContentGroups.Items);

                    contentInfo.Title = TbTitle.Text;
                    var formatString    = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatStrong"]);
                    var formatEm        = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatEM"]);
                    var formatU         = TranslateUtils.ToBool(Request.Form[ContentAttribute.Title + "_formatU"]);
                    var formatColor     = Request.Form[ContentAttribute.Title + "_formatColor"];
                    var theFormatString = ContentUtility.GetTitleFormatString(formatString, formatEm, formatU, formatColor);
                    contentInfo.Set(ContentAttribute.GetFormatStringAttributeName(ContentAttribute.Title), theFormatString);
                    foreach (ListItem listItem in CblContentAttributes.Items)
                    {
                        var value         = listItem.Selected.ToString();
                        var attributeName = listItem.Value;
                        contentInfo.Set(attributeName, value);
                    }
                    contentInfo.LinkUrl = TbLinkUrl.Text;
                    contentInfo.AddDate = TbAddDate.DateTime;

                    var checkedLevel = TranslateUtils.ToIntWithNagetive(DdlContentLevel.SelectedValue);
                    if (checkedLevel != CheckManager.LevelInt.NotChange)
                    {
                        contentInfo.IsChecked    = checkedLevel >= SiteInfo.Additional.CheckContentLevel;
                        contentInfo.CheckedLevel = checkedLevel;
                    }

                    TagUtils.UpdateTags(contentInfo.Tags, TbTags.Text, SiteId, contentId);
                    contentInfo.Tags = TranslateUtils.ObjectCollectionToString(TagUtils.ParseTagsString(TbTags.Text), " ");

                    foreach (var service in PluginManager.Services)
                    {
                        try
                        {
                            service.OnContentFormSubmit(new ContentFormSubmitEventArgs(SiteId, _channelInfo.Id,
                                                                                       contentInfo.Id, TranslateUtils.ToDictionary(Request.Form), contentInfo));
                        }
                        catch (Exception ex)
                        {
                            LogUtils.AddErrorLog(service.PluginId, ex, nameof(IService.ContentFormSubmit));
                        }
                    }

                    DataProvider.ContentDao.Update(SiteInfo, _channelInfo, contentInfo);

                    ContentUtility.Translate(SiteInfo, _channelInfo.Id, contentInfo.Id, Request.Form["translateCollection"], ETranslateContentTypeUtils.GetEnumType(DdlTranslateType.SelectedValue), AuthRequest.AdminName);

                    CreateManager.CreateContent(SiteId, _channelInfo.Id, contentId);
                    CreateManager.TriggerContentChangedEvent(SiteId, _channelInfo.Id);

                    AuthRequest.AddSiteLog(SiteId, _channelInfo.Id, contentId, "修改内容",
                                           $"栏目:{ChannelManager.GetChannelNameNavigation(SiteId, contentInfo.ChannelId)},内容标题:{contentInfo.Title}");

                    redirectUrl = ReturnUrl;

                    //更新引用该内容的信息
                    //如果不是异步自动保存,那么需要将引用此内容的content修改
                    //var sourceContentIdList = new List<int>
                    //{
                    //    contentInfo.Id
                    //};
                    //var tableList = DataProvider.TableDao.GetTableCollectionInfoListCreatedInDb();
                    //foreach (var table in tableList)
                    //{
                    //    var targetContentIdList = DataProvider.ContentDao.GetReferenceIdList(table.TableName, sourceContentIdList);
                    //    foreach (var targetContentId in targetContentIdList)
                    //    {
                    //        var targetContentInfo = DataProvider.ContentDao.GetContentInfo(table.TableName, targetContentId);
                    //        if (targetContentInfo == null || targetContentInfo.GetString(ContentAttribute.TranslateContentType) != ETranslateContentType.ReferenceContent.ToString()) continue;

                    //        contentInfo.Id = targetContentId;
                    //        contentInfo.SiteId = targetContentInfo.SiteId;
                    //        contentInfo.ChannelId = targetContentInfo.ChannelId;
                    //        contentInfo.SourceId = targetContentInfo.SourceId;
                    //        contentInfo.ReferenceId = targetContentInfo.ReferenceId;
                    //        contentInfo.Taxis = targetContentInfo.Taxis;
                    //        contentInfo.Set(ContentAttribute.TranslateContentType, targetContentInfo.GetString(ContentAttribute.TranslateContentType));
                    //        DataProvider.ContentDao.Update(table.TableName, contentInfo);

                    //        //资源:图片,文件,视频
                    //        var targetSiteInfo = SiteManager.GetSiteInfo(targetContentInfo.SiteId);
                    //        var bgContentInfo = contentInfo as BackgroundContentInfo;
                    //        var bgTargetContentInfo = targetContentInfo as BackgroundContentInfo;
                    //        if (bgTargetContentInfo != null && bgContentInfo != null)
                    //        {
                    //            if (bgContentInfo.ImageUrl != bgTargetContentInfo.ImageUrl)
                    //            {
                    //                //修改图片
                    //                var sourceImageUrl = PathUtility.MapPath(SiteInfo, bgContentInfo.ImageUrl);
                    //                CopyReferenceFiles(targetSiteInfo, sourceImageUrl);
                    //            }
                    //            else if (bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl)) != bgTargetContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl)))
                    //            {
                    //                var sourceImageUrls = TranslateUtils.StringCollectionToStringList(bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.ImageUrl)));

                    //                foreach (string imageUrl in sourceImageUrls)
                    //                {
                    //                    var sourceImageUrl = PathUtility.MapPath(SiteInfo, imageUrl);
                    //                    CopyReferenceFiles(targetSiteInfo, sourceImageUrl);
                    //                }
                    //            }
                    //            if (bgContentInfo.FileUrl != bgTargetContentInfo.FileUrl)
                    //            {
                    //                //修改附件
                    //                var sourceFileUrl = PathUtility.MapPath(SiteInfo, bgContentInfo.FileUrl);
                    //                CopyReferenceFiles(targetSiteInfo, sourceFileUrl);

                    //            }
                    //            else if (bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl)) != bgTargetContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl)))
                    //            {
                    //                var sourceFileUrls = TranslateUtils.StringCollectionToStringList(bgContentInfo.GetString(ContentAttribute.GetExtendAttributeName(BackgroundContentAttribute.FileUrl)));

                    //                foreach (var fileUrl in sourceFileUrls)
                    //                {
                    //                    var sourceFileUrl = PathUtility.MapPath(SiteInfo, fileUrl);
                    //                    CopyReferenceFiles(targetSiteInfo, sourceFileUrl);
                    //                }
                    //            }
                    //        }
                    //    }
                    //}
                }
                catch (Exception ex)
                {
                    LogUtils.AddErrorLog(ex);
                    FailMessage($"内容修改失败:{ex.Message}");
                    return;
                }
            }

            PageUtils.Redirect(redirectUrl);
        }
        protected override void Render(HtmlTextWriter output)
        {
            if (StyleInfoList == null || StyleInfoList.Count == 0 || Attributes == null)
            {
                return;
            }

            var pageScripts = new NameValueCollection();

            var builder = new StringBuilder();

            foreach (var styleInfo in StyleInfoList)
            {
                if (StringUtils.EqualsIgnoreCase(styleInfo.AttributeName, ContentAttribute.Title))
                {
                    continue;
                }

                string extra;
                var    value = BackgroundInputTypeParser.Parse(SiteInfo, ChannelId, styleInfo, Attributes, pageScripts, out extra);

                if (string.IsNullOrEmpty(value) && string.IsNullOrEmpty(extra))
                {
                    continue;
                }
                //modify
                if (styleInfo.DisplayName == "ÊÓƵ")
                {
                    continue;
                }
                if (styleInfo.DisplayName == "¸½¼þ")
                {
                    continue;
                }
                if (styleInfo.InputType == InputType.TextEditor)
                {
                    var commands = WebUtils.GetTextEditorCommands(SiteInfo, styleInfo.AttributeName);
                    builder.Append($@"
<div class=""form-group form-row"">
    <label class=""
"">{styleInfo.DisplayName}</label>
    <div class=""col-sm-10"">
        {commands}
        <div class=""m-t-10"">
            {value}
        </div>
    </div>
    <div class=""col-sm-1"">
        {extra}
    </div>
</div>");
                }
                else
                {
                    var html = $@"
<div class=""form-group form-row"">
    <label class=""col-sm-1 col-form-label text-right"">{styleInfo.DisplayName}</label>
    <div class=""col-sm-6"">
        {value}
    </div>
    <div class=""col-sm-5"">
        {extra}
    </div>
</div>";

                    if (styleInfo.InputType == InputType.Customize)
                    {
                        var eventArgs = new ContentFormLoadEventArgs(SiteInfo.Id, ChannelId, ContentId, Attributes, styleInfo.AttributeName, html);
                        foreach (var service in PluginManager.Services)
                        {
                            try
                            {
                                html = service.OnContentFormLoad(eventArgs);
                            }
                            catch (Exception ex)
                            {
                                LogUtils.AddErrorLog(service.PluginId, ex, nameof(IService.ContentFormLoad));
                            }
                        }
                    }

                    builder.Append(html);
                }
            }

            output.Write(builder.ToString());

            foreach (string key in pageScripts.Keys)
            {
                output.Write(pageScripts[key]);
            }
        }
        public IHttpActionResult Submit()
        {
            try
            {
                var request = new AuthenticatedRequest();

                var siteId            = request.GetPostInt("siteId");
                var channelId         = request.GetPostInt("channelId");
                var isFirstLineTitle  = request.GetPostBool("isFirstLineTitle");
                var isFirstLineRemove = request.GetPostBool("isFirstLineRemove");
                var isClearFormat     = request.GetPostBool("isClearFormat");
                var isFirstLineIndent = request.GetPostBool("isFirstLineIndent");
                var isClearFontSize   = request.GetPostBool("isClearFontSize");
                var isClearFontFamily = request.GetPostBool("isClearFontFamily");
                var isClearImages     = request.GetPostBool("isClearImages");
                var checkedLevel      = request.GetPostInt("checkedLevel");
                var fileNames         = TranslateUtils.StringCollectionToStringList(request.GetPostString("fileNames"));

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentAdd))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var tableName     = ChannelManager.GetTableName(siteInfo, channelInfo);
                var styleInfoList = TableStyleManager.GetContentStyleInfoList(siteInfo, channelInfo);
                var isChecked     = checkedLevel >= siteInfo.Additional.CheckContentLevel;

                var contentIdList = new List <int>();

                foreach (var fileName in fileNames)
                {
                    if (string.IsNullOrEmpty(fileName))
                    {
                        continue;
                    }

                    var formCollection = WordUtils.GetWordNameValueCollection(siteId, isFirstLineTitle, isFirstLineRemove, isClearFormat, isFirstLineIndent, isClearFontSize, isClearFontFamily, isClearImages, fileName);

                    if (string.IsNullOrEmpty(formCollection[ContentAttribute.Title]))
                    {
                        continue;
                    }

                    var dict = BackgroundInputTypeParser.SaveAttributes(siteInfo, styleInfoList, formCollection, ContentAttribute.AllAttributes.Value);

                    var contentInfo = new ContentInfo(dict)
                    {
                        ChannelId   = channelInfo.Id,
                        SiteId      = siteId,
                        AddUserName = request.AdminName,
                        AddDate     = DateTime.Now
                    };

                    contentInfo.LastEditUserName = contentInfo.AddUserName;
                    contentInfo.LastEditDate     = contentInfo.AddDate;
                    contentInfo.IsChecked        = isChecked;
                    contentInfo.CheckedLevel     = checkedLevel;

                    contentInfo.Title = formCollection[ContentAttribute.Title];

                    contentInfo.Id = DataProvider.ContentDao.Insert(tableName, siteInfo, channelInfo, contentInfo);

                    contentIdList.Add(contentInfo.Id);
                }

                if (isChecked)
                {
                    foreach (var contentId in contentIdList)
                    {
                        CreateManager.CreateContent(siteId, channelInfo.Id, contentId);
                    }
                    CreateManager.TriggerContentChangedEvent(siteId, channelInfo.Id);
                }

                return(Ok(new
                {
                    Value = contentIdList
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
        protected override object Process()
        {
            var siteId    = AuthRequest.SiteId;
            var channelId = AuthRequest.ChannelId;
            var contentId = AuthRequest.ContentId;

            var siteInfo      = SiteManager.GetSiteInfo(siteId);
            var channelInfo   = ChannelManager.GetChannelInfo(siteId, channelId);
            var tableName     = ChannelManager.GetTableName(siteInfo, channelInfo);
            var styleInfoList = TableStyleManager.GetContentStyleInfoList(siteInfo, channelInfo);

            var form = AuthRequest.HttpRequest.Form;

            var dict        = BackgroundInputTypeParser.SaveAttributes(siteInfo, styleInfoList, form, ContentAttribute.AllAttributes.Value);
            var contentInfo = new ContentInfo(dict)
            {
                ChannelId        = channelId,
                SiteId           = siteId,
                AddUserName      = AuthRequest.AdminName,
                LastEditUserName = AuthRequest.AdminName,
                LastEditDate     = DateTime.Now
            };

            //contentInfo.GroupNameCollection = ControlUtils.SelectedItemsValueToStringCollection(CblContentGroups.Items);
            var tagCollection = TagUtils.ParseTagsString(form["TbTags"]);

            contentInfo.Title = form["TbTitle"];
            var formatString    = TranslateUtils.ToBool(form[ContentAttribute.Title + "_formatStrong"]);
            var formatEm        = TranslateUtils.ToBool(form[ContentAttribute.Title + "_formatEM"]);
            var formatU         = TranslateUtils.ToBool(form[ContentAttribute.Title + "_formatU"]);
            var formatColor     = form[ContentAttribute.Title + "_formatColor"];
            var theFormatString = ContentUtility.GetTitleFormatString(formatString, formatEm, formatU, formatColor);

            contentInfo.Set(ContentAttribute.GetFormatStringAttributeName(ContentAttribute.Title), theFormatString);
            //foreach (ListItem listItem in CblContentAttributes.Items)
            //{
            //    var value = listItem.Selected.ToString();
            //    var attributeName = listItem.Value;
            //    contentInfo.Set(attributeName, value);
            //}
            //contentInfo.LinkUrl = TbLinkUrl.Text;
            contentInfo.AddDate   = TranslateUtils.ToDateTime(form["TbAddDate"]);
            contentInfo.IsChecked = false;
            contentInfo.Tags      = TranslateUtils.ObjectCollectionToString(tagCollection, " ");

            foreach (var service in PluginManager.Services)
            {
                try
                {
                    service.OnContentFormSubmit(new ContentFormSubmitEventArgs(siteId, channelId, contentInfo.Id, TranslateUtils.ToDictionary(form), contentInfo));
                }
                catch (Exception ex)
                {
                    LogUtils.AddErrorLog(service.PluginId, ex, nameof(IService.ContentFormSubmit));
                }
            }

            contentInfo.SourceId = SourceManager.Preview;
            contentInfo.Id       = DataProvider.ContentDao.Insert(tableName, siteInfo, channelInfo, contentInfo);

            return(new
            {
                previewUrl = ApiRoutePreview.GetContentPreviewUrl(siteId, channelId, contentId, contentInfo.Id)
            });
        }
        public IHttpActionResult GetConfig()
        {
            try
            {
                var request = new RequestImpl();

                var siteId        = request.GetQueryInt("siteId");
                var channelId     = request.GetQueryInt("channelId");
                var contentIdList = TranslateUtils.StringCollectionToIntList(request.GetQueryString("contentIds"));

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                        ConfigManager.ChannelPermissions.ContentTranslate))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var retval = new List <Dictionary <string, object> >();
                foreach (var contentId in contentIdList)
                {
                    var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                    if (contentInfo == null)
                    {
                        continue;
                    }

                    var dict = contentInfo.ToDictionary();
                    dict["checkState"] =
                        CheckManager.GetCheckState(siteInfo, contentInfo);
                    retval.Add(dict);
                }

                var sites    = new List <object>();
                var channels = new List <object>();

                var siteIdList = request.AdminPermissions.GetSiteIdList();
                foreach (var permissionSiteId in siteIdList)
                {
                    var permissionSiteInfo = SiteManager.GetSiteInfo(permissionSiteId);
                    sites.Add(new
                    {
                        permissionSiteInfo.Id,
                        permissionSiteInfo.SiteName
                    });
                }

                var channelIdList = request.AdminPermissions.GetChannelIdList(siteInfo.Id,
                                                                              ConfigManager.ChannelPermissions.ContentAdd);
                foreach (var permissionChannelId in channelIdList)
                {
                    var permissionChannelInfo = ChannelManager.GetChannelInfo(siteInfo.Id, permissionChannelId);
                    channels.Add(new
                    {
                        permissionChannelInfo.Id,
                        ChannelName = ChannelManager.GetChannelNameNavigation(siteInfo.Id, permissionChannelId)
                    });
                }

                return(Ok(new
                {
                    Value = retval,
                    Sites = sites,
                    Channels = channels,
                    Site = siteInfo
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }
Example #28
0
        public RequestImpl(HttpRequest request)
        {
            try
            {
                HttpRequest = request;

                var apiToken = ApiToken;
                if (!string.IsNullOrEmpty(apiToken))
                {
                    var tokenInfo = AccessTokenManager.GetAccessTokenInfo(apiToken);
                    if (tokenInfo != null)
                    {
                        if (!string.IsNullOrEmpty(tokenInfo.AdminName))
                        {
                            var adminInfo = AdminManager.GetAdminInfoByUserName(tokenInfo.AdminName);
                            if (adminInfo != null && !adminInfo.IsLockedOut)
                            {
                                AdminInfo     = adminInfo;
                                IsAdminLoggin = true;
                            }
                        }

                        IsApiAuthenticated = true;
                    }
                }

                var userToken = UserToken;
                if (!string.IsNullOrEmpty(userToken))
                {
                    var tokenImpl = ParseAccessToken(userToken);
                    if (tokenImpl.UserId > 0 && !string.IsNullOrEmpty(tokenImpl.UserName))
                    {
                        var userInfo = UserManager.GetUserInfoByUserId(tokenImpl.UserId);
                        if (userInfo != null && !userInfo.IsLockedOut && userInfo.IsChecked && userInfo.UserName == tokenImpl.UserName)
                        {
                            UserInfo     = userInfo;
                            IsUserLoggin = true;
                        }
                    }
                }

                var adminToken = AdminToken;
                if (!string.IsNullOrEmpty(adminToken))
                {
                    var tokenImpl = ParseAccessToken(adminToken);
                    if (tokenImpl.UserId > 0 && !string.IsNullOrEmpty(tokenImpl.UserName))
                    {
                        var adminInfo = AdminManager.GetAdminInfoByUserId(tokenImpl.UserId);
                        if (adminInfo != null && !adminInfo.IsLockedOut && adminInfo.UserName == tokenImpl.UserName)
                        {
                            AdminInfo     = adminInfo;
                            IsAdminLoggin = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
            }
        }
        public override void Submit_OnClick(object sender, EventArgs e)
        {
            if (!Page.IsPostBack || !Page.IsValid)
            {
                return;
            }

            ChannelInfo channelInfo;

            try
            {
                var channelName             = TbNodeName.Text;
                var indexName               = TbNodeIndexName.Text;
                var filePath                = TbFilePath.Text;
                var channelFilePathRule     = TbChannelFilePathRule.Text;
                var contentFilePathRule     = TbContentFilePathRule.Text;
                var contentModelPluginId    = DdlContentModelPluginId.SelectedValue;
                var contentRelatedPluginIds = ControlUtils.GetSelectedListControlValueCollection(CblContentRelatedPluginIds);
                var groupNameCollection     = TranslateUtils.ObjectCollectionToString(ControlUtils.GetSelectedListControlValueStringList(CblNodeGroupNameCollection));
                var imageUrl                = TbImageUrl.Text;
                var content           = ContentUtility.TextEditorContentEncode(SiteInfo, Request.Form[ChannelAttribute.Content]);
                var keywords          = TbKeywords.Text;
                var description       = TbDescription.Text;
                var isChannelAddable  = TranslateUtils.ToBool(RblIsChannelAddable.SelectedValue);
                var isContentAddable  = TranslateUtils.ToBool(RblIsContentAddable.SelectedValue);
                var linkUrl           = TbLinkUrl.Text;
                var linkType          = DdlLinkType.SelectedValue;
                var defaultTaxisType  = ETaxisTypeUtils.GetValue(ETaxisTypeUtils.GetEnumType(DdlTaxisType.SelectedValue));
                var channelTemplateId = DdlChannelTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlChannelTemplateId.SelectedValue) : 0;
                var contentTemplateId = DdlContentTemplateId.Items.Count > 0 ? TranslateUtils.ToInt(DdlContentTemplateId.SelectedValue) : 0;

                channelInfo = ChannelManager.GetChannelInfo(SiteId, _channelId);
                if (!channelInfo.IndexName.Equals(indexName) && !string.IsNullOrEmpty(indexName))
                {
                    var indexNameList = DataProvider.ChannelDao.GetIndexNameList(SiteId);
                    if (indexNameList.IndexOf(indexName) != -1)
                    {
                        FailMessage("栏目属性修改失败,栏目索引已存在!");
                        return;
                    }
                }

                if (channelInfo.ContentModelPluginId != contentModelPluginId)
                {
                    channelInfo.ContentModelPluginId = contentModelPluginId;
                }
                channelInfo.ContentRelatedPluginIds = contentRelatedPluginIds;

                filePath = filePath.Trim();
                if (!channelInfo.FilePath.Equals(filePath) && !string.IsNullOrEmpty(filePath))
                {
                    if (!DirectoryUtils.IsDirectoryNameCompliant(filePath))
                    {
                        FailMessage("栏目页面路径不符合系统要求!");
                        return;
                    }

                    if (PathUtils.IsDirectoryPath(filePath))
                    {
                        filePath = PageUtils.Combine(filePath, "index.html");
                    }

                    var filePathList = DataProvider.ChannelDao.GetAllFilePathBySiteId(SiteId);
                    if (filePathList.IndexOf(filePath) != -1)
                    {
                        FailMessage("栏目修改失败,栏目页面路径已存在!");
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(channelFilePathRule))
                {
                    var filePathRule = channelFilePathRule.Replace("|", string.Empty);
                    if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                    {
                        FailMessage("栏目页面命名规则不符合系统要求!");
                        return;
                    }
                    if (PathUtils.IsDirectoryPath(filePathRule))
                    {
                        FailMessage("栏目页面命名规则必须包含生成文件的后缀!");
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(contentFilePathRule))
                {
                    var filePathRule = contentFilePathRule.Replace("|", string.Empty);
                    if (!DirectoryUtils.IsDirectoryNameCompliant(filePathRule))
                    {
                        FailMessage("内容页面命名规则不符合系统要求!");
                        return;
                    }
                    if (PathUtils.IsDirectoryPath(filePathRule))
                    {
                        FailMessage("内容页面命名规则必须包含生成文件的后缀!");
                        return;
                    }
                }

                var styleInfoList      = TableStyleManager.GetChannelStyleInfoList(channelInfo);
                var extendedAttributes = BackgroundInputTypeParser.SaveAttributes(SiteInfo, styleInfoList, Request.Form, null);
                channelInfo.Additional.Load(extendedAttributes);

                channelInfo.ChannelName         = channelName;
                channelInfo.IndexName           = indexName;
                channelInfo.FilePath            = filePath;
                channelInfo.ChannelFilePathRule = channelFilePathRule;
                channelInfo.ContentFilePathRule = contentFilePathRule;

                channelInfo.GroupNameCollection = groupNameCollection;
                channelInfo.ImageUrl            = imageUrl;
                channelInfo.Content             = content;

                channelInfo.Keywords    = keywords;
                channelInfo.Description = description;

                channelInfo.Additional.IsChannelAddable = isChannelAddable;
                channelInfo.Additional.IsContentAddable = isContentAddable;

                channelInfo.LinkUrl  = linkUrl;
                channelInfo.LinkType = linkType;
                channelInfo.Additional.DefaultTaxisType = defaultTaxisType;
                channelInfo.ChannelTemplateId           = channelTemplateId;
                channelInfo.ContentTemplateId           = contentTemplateId;

                DataProvider.ChannelDao.Update(channelInfo);
            }
            catch (Exception ex)
            {
                FailMessage(ex, $"栏目修改失败:{ex.Message}");
                LogUtils.AddErrorLog(ex);
                return;
            }

            CreateManager.CreateChannel(SiteId, channelInfo.Id);

            AuthRequest.AddSiteLog(SiteId, "修改栏目", $"栏目:{TbNodeName.Text}");

            SuccessMessage("栏目修改成功!");
            PageUtils.Redirect(ReturnUrl);
        }
Example #30
0
        public IHttpActionResult List()
        {
            try
            {
                var request = new RequestImpl();

                var siteId    = request.GetQueryInt("siteId");
                var channelId = request.GetQueryInt("channelId");
                var page      = request.GetQueryInt("page");

                if (!request.IsUserLoggin ||
                    !request.UserPermissionsImpl.HasChannelPermissions(siteId, channelId,
                                                                       ConfigManager.ChannelPermissions.ContentView))
                {
                    return(Unauthorized());
                }

                var siteInfo = SiteManager.GetSiteInfo(siteId);
                if (siteInfo == null)
                {
                    return(BadRequest("无法确定内容对应的站点"));
                }

                var channelInfo = ChannelManager.GetChannelInfo(siteId, channelId);
                if (channelInfo == null)
                {
                    return(BadRequest("无法确定内容对应的栏目"));
                }

                var columns       = ContentManager.GetContentColumns(siteInfo, channelInfo, false);
                var pluginIds     = PluginContentManager.GetContentPluginIds(channelInfo);
                var pluginColumns = PluginContentManager.GetContentColumns(pluginIds);

                var pageContentInfoList = new List <ContentInfo>();
                var count = ContentManager.GetCount(siteInfo, channelInfo);

                var pages = Convert.ToInt32(Math.Ceiling((double)count / siteInfo.Additional.PageSize));
                if (pages == 0)
                {
                    pages = 1;
                }

                if (count > 0)
                {
                    var offset = siteInfo.Additional.PageSize * (page - 1);
                    var limit  = siteInfo.Additional.PageSize;

                    var pageContentIds = ContentManager.GetContentIdList(siteInfo, channelInfo, offset, limit);

                    var sequence = offset + 1;
                    foreach (var contentId in pageContentIds)
                    {
                        var contentInfo = ContentManager.GetContentInfo(siteInfo, channelInfo, contentId);
                        if (contentInfo == null)
                        {
                            continue;
                        }

                        pageContentInfoList.Add(ContentManager.Calculate(sequence++, contentInfo, columns, pluginColumns));
                    }
                }

                var permissions = new
                {
                    IsAdd         = request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.ContentAdd) && channelInfo.Additional.IsContentAddable,
                    IsDelete      = request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.ContentDelete),
                    IsEdit        = request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.ContentEdit),
                    IsTranslate   = request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.ContentTranslate),
                    IsCheck       = request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.ContentCheck),
                    IsCreate      = request.UserPermissionsImpl.HasSitePermissions(siteInfo.Id, ConfigManager.WebSitePermissions.Create) || request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.CreatePage),
                    IsChannelEdit = request.UserPermissionsImpl.HasChannelPermissions(siteInfo.Id, channelInfo.Id, ConfigManager.ChannelPermissions.ChannelEdit)
                };

                return(Ok(new
                {
                    Value = pageContentInfoList,
                    Count = count,
                    Pages = pages,
                    Permissions = permissions,
                    Columns = columns
                }));
            }
            catch (Exception ex)
            {
                LogUtils.AddErrorLog(ex);
                return(InternalServerError(ex));
            }
        }