Ejemplo n.º 1
0
        public IHttpActionResult Get()
        {
            try
            {
                var request = Context.AuthenticatedRequest;
                var siteId  = request.GetQueryInt("siteId");
                var ruleId  = request.GetQueryInt("ruleId");

                if (!request.IsAdminLoggin ||
                    !request.AdminPermissions.HasSitePermissions(siteId, Utils.PluginId))
                {
                    return(Unauthorized());
                }

                GatherRuleInfo ruleInfo;
                List <string>  contentHtmlClearList;
                List <string>  contentHtmlClearTagList;
                Dictionary <string, string> attributesDict;
                if (ruleId > 0)
                {
                    ruleInfo             = Main.GatherRuleRepository.GetGatherRuleInfo(ruleId);
                    contentHtmlClearList =
                        TranslateUtils.StringCollectionToStringList(ruleInfo.ContentHtmlClearCollection);
                    contentHtmlClearTagList = TranslateUtils.StringCollectionToStringList(ruleInfo.ContentHtmlClearTagCollection);
                    attributesDict          = TranslateUtils.JsonDeserialize <Dictionary <string, string> >(ruleInfo.ContentAttributesXml);
                }
                else
                {
                    ruleInfo = new GatherRuleInfo
                    {
                        SiteId                        = siteId,
                        Charset                       = ECharsetUtils.GetValue(ECharset.utf_8),
                        IsOrderByDesc                 = true,
                        GatherUrlIsCollection         = true,
                        ContentHtmlClearCollection    = "",
                        ContentHtmlClearTagCollection = ""
                    };
                    contentHtmlClearList = new List <string>
                    {
                        "script",
                        "object",
                        "iframe"
                    };
                    contentHtmlClearTagList = new List <string>
                    {
                        "font",
                        "div",
                        "span"
                    };
                    attributesDict = new Dictionary <string, string>();
                }

                var channels        = new List <KeyValuePair <int, string> >();
                var channelIdList   = Context.ChannelApi.GetChannelIdList(siteId);
                var isLastNodeArray = new bool[channelIdList.Count];
                foreach (var theChannelId in channelIdList)
                {
                    var channelInfo = Context.ChannelApi.GetChannelInfo(siteId, theChannelId);

                    var title = Utils.GetChannelListBoxTitle(siteId, channelInfo.Id, channelInfo.ChannelName, channelInfo.ParentsCount, channelInfo.LastNode, isLastNodeArray);
                    channels.Add(new KeyValuePair <int, string>(channelInfo.Id, title));
                }

                var charsets = ECharsetUtils.GetAllCharsets();

                return(Ok(new
                {
                    Value = ruleInfo,
                    Channels = channels,
                    Charsets = charsets,
                    ContentHtmlClearList = contentHtmlClearList,
                    ContentHtmlClearTagList = contentHtmlClearTagList,
                    AttributesDict = attributesDict
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }