Exemple #1
0
        public async Task <FetchArticlesResponse> FetchArticlesBySource(string source, int pageNumber = 1, int pageSize = Constants.DefaultArticlesPageSize)
        {
            if (string.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentNullException(nameof(source));
            }

            var request = new ArticlesRequest
            {
                Sources = new List <string> {
                    source
                },
                Language = Languages.EN,
                Page     = pageNumber,
                PageSize = pageSize,
            };

            var actionUrl = ToActionRelativeUrl("top-headlines", request);
            var articles  = await GetAsync <ArticlesResult>(actionUrl);

            var result = new FetchArticlesResponse(pageNumber, pageSize);

            if (articles?.Articles != null)
            {
                result.Articles   = articles.Articles;
                result.TotalCount = articles.TotalResults;
            }

            return(result);
        }
Exemple #2
0
        public async Task <FetchArticlesResponse> FetchArticlesBySearchQuery(string query, int pageNumber = 1, int pageSize = Constants.DefaultArticlesPageSize)
        {
            var result = new FetchArticlesResponse(pageNumber, pageSize);

            if (string.IsNullOrWhiteSpace(query))
            {
                return(result);
            }

            var request = new ArticlesRequest
            {
                Query    = query,
                Country  = Countries.US,
                Language = Languages.EN,
                Page     = pageNumber,
                PageSize = pageSize,
            };

            var actionUrl = ToActionRelativeUrl("top-headlines", request);
            var articles  = await GetAsync <ArticlesResult>(actionUrl);

            if (articles?.Articles != null)
            {
                result.Articles   = articles.Articles;
                result.TotalCount = articles.TotalResults;
            }

            return(result);
        }
Exemple #3
0
        public ActionResult AjaxList(ArticlesRequest request)
        {
            var create = _unityContainer.Resolve <ListArticles>();
            var table  = create.AjaxQuery(request);

            return(Json(new { tables = table, html = create.pageHtml }));
        }
Exemple #4
0
        public ActionResult Articles(int page = 0, string tab = null, string all = null, string q = null, int folder = 0, string filter = null)
        {
            var request = new ArticlesRequest {
                User = CurrentUser, Page = page, PageSize = PageSize
            };
            bool includeAll = bool.TryParse(all, out includeAll) ? includeAll : false;

            request.DoNotFilterByTags = includeAll;
            request.SearchQuery       = q;
            request.Filter            = filter ?? "week";

            switch (tab)
            {
            case "month": request.Month = true; break;

            case "week": request.Week = true; break;

            case "folder": request.FolderId = folder; break;

            case "untaged": request.Untaged = true; break;

            case "favorite": request.Favorites = true; break;

            case "votes": request.Votes = true; break;

            case "myfeeds": request.MyFeeds = true; break;

            default: request.Week = q.IsNullOrEmpty(); break;
            }

            return(GetIndexView(request));
        }
Exemple #5
0
        private ActionResult GetIndexView(ArticlesRequest request)
        {
            var hvm = new EntriesVM();

            hvm.Request = request;

            if (!request.SearchQuery.IsNullOrEmpty())
            {
                var isPro = PaymentService.IsPro(CurrentUser);
                if (!isPro)
                {
                    var numberOfSearchesAlready = FeedService.GetUserSearchesForDate(CurrentUser);
                    if (numberOfSearchesAlready >= NumberOfFreeSearches)
                    {
                        hvm.ExcededFreeSearchCount = true;
                    }
                }
                FeedService.AddSearch(request.SearchQuery, CurrentUser);
            }

            if (!hvm.ExcededFreeSearchCount)
            {
                hvm.Articles = FeedService.GetArticles(request);
            }

            SaveRequestToCookie();

            hvm.CurrentUser = CurrentUser;
            return(View("Index", hvm));
        }
Exemple #6
0
        public List <ListArticle> AjaxQuery(ArticlesRequest request)
        {
            var data  = new List <ListArticle>();
            var query = IArticlesService.Query(request);

            if (query != null)
            {
                var roles = _securityHelper.GetCurrentUser().CurrentUser.Roles.ToList();
                data = query.ModelList.Select(x => new ListArticle(x)).ToList();
                foreach (var item in data)
                {
                    if (roles[0].IsSuper || roles[0].Permissions.Contains("EditArticles"))
                    {
                        item.boor += "<a href='#' onclick=OperatorThis('Edit','/Articles/Edit/" + item.articleId + "') class='tablelink'>编辑 &nbsp;</a> ";
                    }
                    if (roles[0].IsSuper || roles[0].Permissions.Contains("DeleteArticles"))
                    {
                        item.boor += "<a href='#' onclick=OperatorThis('Delete','/Articles/Delete/" + item.articleId + "') class='tablelink'>删除 </a> ";
                    }
                }
                pageHtml = MvcPage.AjaxPager((int)request.PageIndex, (int)request.PageSize, query.TotalCount);
            }
            else
            {
                pageHtml = MvcPage.AjaxPager((int)request.PageIndex, (int)request.PageSize, 0);
            }
            return(data);
        }
Exemple #7
0
        public ActionResult GetArticles()
        {
            var json = GetJson(HttpContext.Request);

            ValidateJson(json);
            var user = GetUserCached(json);
            int page = json["page"].Value <int>() + 1;

            var request = new ArticlesRequest
            {
                _PageSize    = 30,
                _Page        = page,
                User         = user,
                IsFromMobile = true
            };
            var view = json["view"].Value <string>();

            switch (view)
            {
            case "week": request.Week = true; break;

            case "month": request.Month = true; break;

            case "votes": request.Votes = true; break;

            case "untagged": request.Untaged = true; break;

            case "favorites": request.Favorites = true; break;

            case "myfeeds": request.MyFeeds = true; break;
            }

            if (view.StartsWith("feed"))
            {
                request.FeedId = int.Parse(view.Replace("feed", string.Empty));
            }

            if (view.StartsWith("folder"))
            {
                request.FolderId = int.Parse(view.Replace("folder", string.Empty));
            }

            if (view.StartsWith("tag"))
            {
                request.TagId = int.Parse(view.Replace("tag", string.Empty));
            }

            var articles = FeedService.GetArticles(request);

            return(Json(new
            {
                articles = articles
            }));
        }
Exemple #8
0
        private string ToActionRelativeUrl(string action, ArticlesRequest requestParams = null)
        {
            if (string.IsNullOrWhiteSpace(action))
            {
                throw new ArgumentNullException(nameof(action));
            }

            var actionUrlBuilder = new StringBuilder($"/{action}?");

            if (requestParams != null)
            {
                if (!string.IsNullOrWhiteSpace(requestParams.Query))
                {
                    actionUrlBuilder.Append($"q={requestParams.Query}&");
                }

                if (requestParams.Country != null)
                {
                    actionUrlBuilder.Append($"country={requestParams.Country}&");
                }

                if (requestParams.Language != null)
                {
                    actionUrlBuilder.Append($"language={requestParams.Language}&");
                }

                if (requestParams.Category != null)
                {
                    actionUrlBuilder.Append($"category={requestParams.Category}&");
                }

                if (requestParams.Sources != null && requestParams.Sources.Count > 0)
                {
                    actionUrlBuilder.Append($"sources={string.Join(",", requestParams.Sources)}&");
                }

                if (requestParams.Page > 0)
                {
                    actionUrlBuilder.Append($"page={requestParams.Page}&");
                }

                if (requestParams.PageSize > 0)
                {
                    actionUrlBuilder.Append($"pageSize={requestParams.PageSize}&");
                }
            }

            actionUrlBuilder.Append($"apiKey={ServiceConfig.NewsServiceApiKey}");
            var actionUrl = actionUrlBuilder.ToString();

            return(actionUrl);
        }
Exemple #9
0
        public void Query()
        {
            var request = new ArticlesRequest();
            var query   = IArticlesService.Query(request);

            if (query != null)
            {
                List     = query.ModelList.Select(x => new ListArticle(x)).ToList();
                pageHtml = MvcPage.AjaxPager((int)request.PageIndex, (int)request.PageSize, query.TotalCount);
            }
            else
            {
                List     = new List <ListArticle>();
                pageHtml = MvcPage.AjaxPager((int)request.PageIndex, (int)request.PageSize, 0);
            }
        }
Exemple #10
0
        public HttpResponseMessage Post()
        {
            try
            {
                HttpContext.Current.Request.InputStream.Seek(0, SeekOrigin.Begin);
                string requestJSON = new StreamReader(HttpContext.Current.Request.InputStream).ReadToEnd().ToString();

                ArticlesRequest req = JsonConvert.DeserializeObject <ArticlesRequest>(requestJSON);

                using (ElectronicsEntities ee = new ElectronicsEntities())
                {
                    var id = ee.SetArticle(req.ID, req.IsTextOnly && !string.IsNullOrEmpty(req.MainText) && req.MainText.IndexOf(" ") > 0 ? req.MainText.Substring(0, req.MainText.IndexOf(" ")) : req.Title, req.MainText ?? "", req.FilePath ?? "", req.Description ?? "", string.Join(",", req.Authors), string.Join(",", req.Subjects), req.IsImageOnly, req.IsTextOnly).FirstOrDefault();

                    return(Globals.FinishResponse(id));
                }
            }
            catch (Exception ex)
            {
                return(Globals.FinishResponse(new { Error = true }));
            }
        }
Exemple #11
0
        public async Task <FetchArticlesResponse> FetchArticlesByCategory(Categories?category = null, int pageNumber = 1, int pageSize = Constants.DefaultArticlesPageSize)
        {
            var request = new ArticlesRequest
            {
                Country  = Countries.US,
                Language = Languages.EN,
                Category = category,
                Page     = pageNumber,
                PageSize = pageSize,
            };

            var actionUrl = ToActionRelativeUrl("top-headlines", request);
            var articles  = await GetAsync <ArticlesResult>(actionUrl);

            var result = new FetchArticlesResponse(pageNumber, pageSize);

            if (articles?.Articles != null)
            {
                result.Articles   = articles.Articles;
                result.TotalCount = articles.TotalResults;
            }

            return(result);
        }
Exemple #12
0
        public ActionResult Next(NameValueCollection q)
        {
            var a      = q["articleid"].ToInt();
            var tab    = q["tab"];
            var filter = q["filter"];
            var folder = q["folder"].ToInt();
            var feed   = q["feed"].ToInt();
            var tag    = q["tag"].ToInt();
            var guid   = q["guid"];

            var user = CurrentUser;

            if (user == null)
            {
                if (!guid.IsNullOrEmpty())
                {
                    user = UserService.GetUserByGuid(guid);
                    if (user == null)
                    {
                        System.Web.Security.FormsAuthentication.RedirectToLoginPage();
                        return(null);
                    }
                }
                else
                {
                    System.Web.Security.FormsAuthentication.RedirectToLoginPage();
                    return(null);
                }
            }

            var vm = new ArticleVM
            {
                User = user
            };

            var request = new ArticlesRequest {
                User = user, IsSingleArticleRequest = true, ArticleId = a
            };

            request.Filter = filter ?? "week";

            switch (tab)
            {
            case "month": request.Month = true; break;

            case "week": request.Week = true; break;

            case "folder": request.FolderId = folder; break;

            case "untaged": request.Untaged = true; break;

            case "favorite": request.Favorites = true; break;

            case "votes": request.Votes = true; break;

            case "myfeeds": request.MyFeeds = true; break;
            }

            request.FeedId = feed;
            request.TagId  = tag;

            vm.Article = FeedService.GetArticles(request).FirstOrDefault();

            if (vm.Article == null)
            {
                //probably it was the last item from the list
                if (request.Week)
                {
                    q["tab"]       = "month";
                    q["articleid"] = "";
                    q["next"]      = "true";
                    return(Next(q));
                }
                else if (request.Month)
                {
                    q["tab"]       = "votes";
                    q["articleid"] = "";
                    q["next"]      = "true";
                    return(Next(q));
                }
                else if (!q["next"].ToBool())
                {
                    q["tab"]       = "week";
                    q["articleid"] = "";
                    q["next"]      = "true";
                    return(Next(q));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            vm.Query = q;
            return(View("Article", vm));
        }
Exemple #13
0
        public void Atom(string guid, string tab = null, string q = null, int folder = 0)
        {
            var user = UserService.GetUserByGuid(guid);

            if (user == null)
            {
                return;
            }

            var title = string.Empty;
            var link  = string.Empty;

            var request = new ArticlesRequest {
                User = user, PageSize = PageSize
            };

            request.SearchQuery              = q;
            request.IncludeArticleBody       = true;
            request.User.HideVisitedArticles = true;
            request.Filter = "votes";
            switch (tab)
            {
            case "month":
                request.Month = true;
                title         = "Month articles via " + user.UserName + " in rssheap";
                link          = "http://rssheap.com/articles?tab=month";
                break;

            case "week":
                request.Week = true;
                title        = "Week articles via " + user.UserName + " in rssheap";
                link         = "http://rssheap.com/articles";
                break;

            case "folder":
                request.FolderId = folder;
                var folderObj = UserService.GetUserFolder(user.Id, folder);
                if (folderObj != null)
                {
                    title = "Articles in " + folderObj.Name + " folder via " + user.UserName + " in rssheap";
                    link  = "http://rssheap.com?tab=folder&folder=" + folderObj.Id;
                }
                break;

            case "untaged":
                request.Untaged = true;
                title           = "Untagged articles via " + user.UserName + " in rssheap";
                link            = "http://rssheap.com/articles?tab=untaged";
                break;

            case "favorite":
                request.Favorites = true;
                title             = "Favorite articles via " + user.UserName + " in rssheap";
                link = "http://rssheap.com/articles?tab=favorite";
                break;

            case "votes":
                request.Votes = true;
                title         = "All articles by votes via " + user.UserName + " in rssheap";
                link          = "http://rssheap.com/articles?tab=votes";
                break;

            case "myfeeds":
                request.MyFeeds = true;
                title           = "My feeds articles by votes via " + user.UserName + " in rssheap";
                link            = "http://rssheap.com/articles?tab=myfeeds";
                break;

            default:
            {
                request.Week = q.IsNullOrEmpty();
                title        = "Week articles via " + user.UserName + " in rssheap";
                link         = "http://rssheap.com/articles";
                break;
            }
            }

            var articles = FeedService.GetArticles(request);
            var items    = new List <SyndicationItem>();

            foreach (var a in articles)
            {
                var si = new SyndicationItem();
                si.Id = a.Id.ToString();
                si.Links.Add(new SyndicationLink(new Uri("http://www.rssheap.com/a/" + a.ShortUrl)));
                si.Title = new TextSyndicationContent(a.Name);
                if (a.Published == DateTime.MinValue)
                {
                    a.Published = DateTime.Now.AddYears(-2);
                }
                si.LastUpdatedTime = a.Published;
                si.PublishDate     = a.Published;
                si.Content         = new TextSyndicationContent(a.Body, TextSyndicationContentKind.Html);

                items.Add(si);
            }

            var updated = DateTime.Now;

            if (items.Count > 0)
            {
                updated = articles.OrderBy(i => i.Published).First().Published;
            }
            var feed = new SyndicationFeed(title, string.Empty, new Uri(link), link, updated, items);

            feed.LastUpdatedTime = updated;

            Response.ContentType = "text/xml";

            // Return the feed's XML content as the response
            var feedWriter = XmlWriter.Create(Response.OutputStream);
            Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed);

            atomFormatter.WriteTo(feedWriter);
            feedWriter.Close();
        }
Exemple #14
0
 public List <Article> GetArticles(ArticlesRequest request)
 {
     return(DataProvider.GetArticles(request));
 }
Exemple #15
0
        /// <summary>
        /// Used to inject the user guid in the query string (for example, newsletter links)
        /// </summary>
        public string GetHref(ArticlesRequest request, string guid)
        {
            var url   = "/article/?p=";
            var query = "articleid=" + Id;

            if (request.Week)
            {
                query += "&tab=week";
            }

            if (request.Month)
            {
                query += "&tab=month";
            }

            if (request.FolderId > 0)
            {
                query += "&tab=folder";
            }

            if (request.Untaged)
            {
                query += "&tab=untaged";
            }

            if (request.Favorites)
            {
                query += "&tab=favorite";
            }

            if (request.Votes)
            {
                query += "&tab=votes";
            }

            if (request.MyFeeds)
            {
                query += "&tab=myfeeds";
            }

            if (request.FeedId > 0)
            {
                query += "&feed=" + request.FeedId;
            }

            if (request.FolderId > 0)
            {
                query += "&folder=" + request.FolderId;
            }

            if (!guid.IsNullOrEmpty())
            {
                query += "&guid=" + guid;
            }

            if (request.TagId > 0)
            {
                query += "&tag=" + request.TagId;
            }

            query += "&filter=" + request.Filter;

            return(url + Convert.ToBase64String(Encoding.UTF8.GetBytes(query)));
        }
Exemple #16
0
 public string GetHref(ArticlesRequest request)
 {
     return(GetHref(request, null));
 }
Exemple #17
0
        public string GetSelect(ArticlesRequest request)
        {
            Request = request;

            var select = string.Empty;

            select = "select * from (" + Environment.NewLine;

            if (request.IsSingleArticleRequest)
            {
                select += @"
                  select Article.Id as 'Article.Id', Article.Name as 'Article.Name', Article.Body as 'Article.Body', Article.ShortUrl as 'Article.ShortUrl', 
                  Article.Url as 'Article.Url', Article.Published as 'Article.Published', Article.Published, Article.Created as 'Article.Created',
                  Article.ViewsCount as 'Article.ViewsCount', Article.LikesCount as 'Article.LikesCount', Article.LikesCount, Article.FavoriteCount as 'Article.FavoriteCount',
                  Article.Flagged as 'Article.Flagged', Article.FlaggedBy as 'Article.FlaggedBy',
                  Feed.Id as 'Feed.Id', Feed.Name as 'Feed.Name', Feed.Descriptions as 'Feed.Descriptions', Feed.Url as 'Feed.Url', Feed.SiteUrl as 'Feed.SiteUrl',
                  (select Votes from UserArticleVote where UserId = " + request.User.Id + @" and ArticleId = Article.Id) as Votes,
                  (select Id from UserFavoriteArticle where ArticleId = Article.Id and UserId = " + request.User.Id + @") as MyFavoriteId,
                  (select count(*) from UserFavoriteArticle where ArticleId = Article.Id) as FavoriteCount";

                if (request.AppVersion == 2 || !request.IsFromMobile)
                {
                    select = select.Replace(", Article.Body as 'Article.Body'", ", '' as 'Article.Body'");
                }
            }
            else
            {
                select += @"
                select Article.Id as 'Article.Id', Article.Name as 'Article.Name', Article.Published as 'Article.Published', Article.Published,
                Article.ViewsCount as 'Article.ViewsCount', Article.LikesCount as 'Article.LikesCount', Article.LikesCount,
                0 as 'Article.Flagged', '' as 'Article.FlaggedBy',
                Article.ShortUrl as 'Article.ShortUrl',
                Feed.Id as 'Feed.Id', Feed.Name as 'Feed.Name', Feed.SiteUrl as 'Feed.SiteUrl' ";

                if (request.IncludeArticleBody)
                {
                    select += ", Article.Body as 'Article.Body' ";
                }

                if (request.AppVersion == 2 || !request.IsFromMobile)
                {
                    select = select.Replace(", Article.Body as 'Article.Body' ", ", '' as 'Article.Body' ");
                }
            }

            select += @" from Article

            inner join Feed on Article.FeedId = Feed.Id ";

            select += GetJoins() + Environment.NewLine;
            select += GetWhere() + Environment.NewLine;

            if (request.User.HideOlderThanDateTime > DateTime.MinValue)
            {
                select += " and Article.Published >= '" + request.User.HideOlderThanDateTime.ToMySQLString() + "'";
            }

            select += " group by Article.Name " + Environment.NewLine;

            select += Environment.NewLine + ") as T " + Environment.NewLine;

            select += @" order by " + GetOrderBy();

            select += GetLimit();


            return(select);
        }
Exemple #18
0
        public ActionResult GetArticle()
        {
            var json = GetJson(HttpContext.Request);

            ValidateJson(json);
            var    user     = GetUserCached(json);
            int    index    = json["index"].Value <int>();
            string platform = string.Empty;

            if (json["platform"] != null)
            {
                platform = json["platform"].Value <string>();
            }

            var request = new ArticlesRequest
            {
                PageSize = 2,
                Page     = index,
                User     = user,
                IsSingleArticleRequest = true,
                IsFromMobile           = true
            };
            var view = json["view"].Value <string>();

            switch (view)
            {
            case "week": request.Week = true; break;

            case "month": request.Month = true; break;

            case "votes": request.Votes = true; break;

            case "untagged": request.Untaged = true; break;

            case "favorites": request.Favorites = true; break;

            case "myfeeds": request.MyFeeds = true; break;
            }

            if (view.StartsWith("feed"))
            {
                request.FeedId = int.Parse(view.Replace("feed", string.Empty));
            }

            if (view.StartsWith("folder"))
            {
                request.FolderId = int.Parse(view.Replace("folder", string.Empty));
            }

            if (view.StartsWith("tag"))
            {
                request.TagId = int.Parse(view.Replace("tag", string.Empty));
            }

            var articles = FeedService.GetArticles(request);

            foreach (var article in articles)
            {
                try
                {
                    var doc = new HtmlDocument
                    {
                        OptionAutoCloseOnEnd = true,
                        OptionFixNestedTags  = true
                    };
                    doc.LoadHtml(article.Body);

                    var htmlNode = doc.DocumentNode.SelectSingleNode("/html");
                    if (htmlNode == null)
                    {
                        doc = new HtmlDocument
                        {
                            OptionAutoCloseOnEnd = true,
                            OptionFixNestedTags  = true
                        };
                        var node = HtmlNode.CreateNode("<html><head></head><body></body></html>");
                        doc.DocumentNode.AppendChild(node);

                        var html = "<div class=\"article\">";
                        html += "<div class=\"article-content\">";
                        html += "<div class=\"ctn post-text\">";
                        html += "<br/>";
                        html += article.Body;
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";

                        doc.DocumentNode.SelectSingleNode("/html/body").AppendChild(HtmlNode.CreateNode(html));
                    }

                    var head = doc.DocumentNode.SelectSingleNode("/html/head");
                    if (head != null)
                    {
                        var cssArticle = doc.CreateElement("link");
                        cssArticle.SetAttributeValue("rel", "stylesheet");
                        cssArticle.SetAttributeValue("href", "http://rssheap.com/assets/css/article.css?ver=101");
                        head.AppendChild(cssArticle);

                        var css = doc.CreateElement("link");
                        css.SetAttributeValue("rel", "stylesheet");
                        css.SetAttributeValue("href", "http://rssheap.com/assets/css/styles.css?ver=101");
                        head.AppendChild(css);

                        var cssMy = doc.CreateElement("link");
                        cssMy.SetAttributeValue("rel", "stylesheet");
                        cssMy.SetAttributeValue("href", "http://rssheap.com/assets/css/styles_my.css?ver=101");
                        head.AppendChild(cssMy);

                        var link = doc.CreateElement("link");
                        link.SetAttributeValue("rel", "stylesheet");
                        link.SetAttributeValue("href", "http://rssheap.com/assets/css/responsive-fix.css?ver=13");
                        head.AppendChild(link);

                        var link2 = doc.CreateElement("link");
                        link2.SetAttributeValue("rel", "stylesheet");
                        link2.SetAttributeValue("href", "http://rssheap.com/assets/css/mobile.css?ver=15");
                        head.AppendChild(link2);
                    }

                    if (platform == "ios")
                    {
                        var body = doc.DocumentNode.SelectSingleNode("//body");
                        if (body.Attributes["onLoad"] == null)
                        {
                            body.Attributes.Add("onLoad", "window.location.href='ready://' + document.body.offsetHeight;");
                        }
                        else
                        {
                            body.Attributes["onLoad"].Value = "window.location.href='ready://' + document.body.offsetHeight;";
                        }
                    }

                    //remove width attribute
                    foreach (var node in doc.DocumentNode.Descendants().ToList())
                    {
                        if (node.Attributes["width"] != null)
                        {
                            node.Attributes.Remove("width");
                        }

                        if (node.Attributes["height"] != null)
                        {
                            node.Attributes.Remove("height");
                        }

                        if (node.Name == "pre")
                        {
                            var codeNode = "<code>" + node.InnerHtml;
                            node.ParentNode.ReplaceChild(HtmlNode.CreateNode(codeNode), node);
                        }

                        if (node.Attributes["style"] != null)
                        {
                            string style    = node.Attributes["style"].Value;
                            string pattern  = @"width(.*?)(;)";
                            var    regex    = new Regex(pattern, RegexOptions.IgnoreCase);
                            string newStyle = regex.Replace(style, String.Empty);
                            node.Attributes["style"].Value = newStyle;
                        }
                    }

                    var sw = new StringWriter();
                    doc.Save(sw);
                    article.Body = sw.ToString();
                }
                catch (Exception ex)
                {
                    Mail.SendMeAnEmail("Error in Api GetArticle", ex.ToString());
                }
            }

            return(Json(new
            {
                articles
            }));
        }
Exemple #19
0
        public ActionResult GetArticle()
        {
            var json = GetJson(HttpContext.Request);

            ValidateJson(json);
            var    user     = GetUserCached(json);
            int    index    = json["index"].Value <int>();
            string platform = string.Empty;

            if (json["platform"] != null)
            {
                platform = json["platform"].Value <string>();
            }

            var request = new ArticlesRequest
            {
                PageSize = 2,
                Page     = index,
                User     = user,
                IsSingleArticleRequest = true,
                IsFromMobile           = true,
                AppVersion             = 2
            };
            var view = json["view"].Value <string>();

            switch (view)
            {
            case "week": request.Week = true; break;

            case "month": request.Month = true; break;

            case "votes": request.Votes = true; break;

            case "untagged": request.Untaged = true; break;

            case "favorites": request.Favorites = true; break;

            case "myfeeds": request.MyFeeds = true; break;
            }

            if (view.StartsWith("feed"))
            {
                request.FeedId = int.Parse(view.Replace("feed", string.Empty));
            }

            if (view.StartsWith("folder"))
            {
                request.FolderId = int.Parse(view.Replace("folder", string.Empty));
            }

            if (view.StartsWith("tag"))
            {
                request.TagId = int.Parse(view.Replace("tag", string.Empty));
            }

            var articles = FeedService.GetArticles(request);

            return(Json(new
            {
                articles
            }));
        }