public ActionResult Flag(int id) { var article = FeedService.GetArticle(id); if (article == null) { return(Json(false)); } if (article.FlaggedBy.Contains(CurrentUser.Id)) { return(Json(false)); } article.FlaggedBy.Add(CurrentUser.Id); article.Flagged = article.FlaggedBy.Count >= 3 || CurrentUser.IsAdmin;; FeedService.UpdateArticle(article); if (article.Flagged && article.FlaggedBy.Count > 0) { IISTaskManager.Run(() => { var userToAddRep = article.FlaggedBy.First(); var user = UserService.GetUser(userToAddRep); if (user != null) { user.Reputation += 2; UserService.UpdateUser(user); } }); } return(Json(true)); }
public ActionResult CheckIfUrlIsOk(int articleId) { var ok = true; var metaKey = "x-frame-options-allowed"; var article = FeedService.GetArticle(articleId); var alreadyChecked = article.GetMetadataValue <bool?>(metaKey); if (alreadyChecked.HasValue) { return(Json(alreadyChecked)); } try { var url = article.Url; var request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "HEAD"; request.Headers["Accept-Encoding"] = "gzip,deflate"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36"; request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; request.KeepAlive = true; request.Timeout = 10000; request.MaximumAutomaticRedirections = 3; request.MaximumResponseHeadersLength = 1024 * 64 * 64; if (request != null) { var response = request.GetResponse() as HttpWebResponse; var headers = response.Headers; var xFrameOptions = string.Empty; if (response != null) { response.Close(); } if (response.Headers != null) { xFrameOptions = response.Headers["X-Frame-Options"]; } if (!xFrameOptions.IsNullOrEmpty()) { if (xFrameOptions == "deny" || xFrameOptions == "SAMEORIGIN" || !xFrameOptions.Contains("rssheap")) { ok = false; FeedService.FlagArticle(articleId); } } } } catch { } article.AddMetadata(metaKey, ok); article.SaveMetadata(); return(Json(ok)); }
public ActionResult Flag() { var json = GetJson(HttpContext.Request); ValidateJson(json); var user = GetUserCached(json); var id = json.Value <int>("id"); var article = FeedService.GetArticle(id); if (article == null) { return(Json(false)); } if (article.FlaggedBy.Contains(user.Id)) { return(Json(false)); } article.FlaggedBy.Add(user.Id); article.Flagged = article.FlaggedBy.Count >= 3 || user.IsAdmin;; FeedService.UpdateArticle(article); if (article.Flagged && article.FlaggedBy.Count > 0) { IISTaskManager.Run(() => { var userToAddRepId = article.FlaggedBy.First(); var userToAddRep = UserService.GetUser(userToAddRepId); if (userToAddRep != null) { userToAddRep.Reputation += 2; UserService.UpdateUser(user); } }); } return(Json(new { ok = "true" })); }
public ActionResult ShortUrl(string shorturl) { var article = FeedService.GetArticle(shorturl); if (article == null) { return(NotFoundResult()); } IISTaskManager.Run(() => { ActionExtensions.TryAction(() => { if (Request.Url.Host.Contains("rssheap")) { var tracker = new PageviewTracker("UA-51717870-1", "rssheap.com"); tracker.Parameters.DocumentPath = "/a/" + shorturl; tracker.Parameters.DocumentTitle = article.Name; tracker.Parameters.DocumentReferrer = Request.UrlReferrer?.AbsolutePath; tracker.Parameters.UserLanguage = (Request.UserLanguages != null && Request.UserLanguages.Count() > 0) ? Request.UserLanguages.First() : null; tracker.Parameters.UserAgentOverride = HttpUtility.UrlEncode(Request.UserAgent); tracker.Parameters.IPOverride = Request.UserHostAddress; tracker.Send(); } if (CurrentUser != null) { IncreaseViewsCount(article.Id, CurrentUser.Id); } }); }); return(new TemporaryRedirectResult(article.Url)); }