public ActionResult SubverseLinkFlairs(string subversetoshow, int?messageId) { // get model for selected subverse var subverseModel = SubverseCache.Retrieve(subversetoshow); //var subverseModel = _db.Subverses.Find(subversetoshow); if (subverseModel == null || messageId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var submissionId = _db.Messages.Find(messageId); if (submissionId == null || submissionId.Subverses.name != subversetoshow) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // check if caller is subverse owner or moderator, if not, deny listing if (!Utils.User.IsUserSubverseModerator(User.Identity.Name, subversetoshow) && !Utils.User.IsUserSubverseAdmin(User.Identity.Name, subversetoshow)) { return(new HttpUnauthorizedResult()); } var subverseLinkFlairs = _db.Subverseflairsettings .Where(n => n.Subversename == subversetoshow) .Take(10) .ToList() .OrderBy(s => s.Id); ViewBag.SubmissionId = messageId; ViewBag.SubverseName = subversetoshow; return(PartialView("~/Views/AjaxViews/_LinkFlairSelectDialog.cshtml", subverseLinkFlairs)); }
public ApiSubverseInfo SubverseInfo(string subverseName) { var subverse = SubverseCache.Retrieve(subverseName); if (subverse == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } // get subscriber count for selected subverse var subscriberCount = _db.Subscriptions.AsEnumerable().Count(r => r.SubverseName.Equals(subverseName, StringComparison.OrdinalIgnoreCase)); var resultModel = new ApiSubverseInfo { Name = subverse.name, CreationDate = subverse.creation_date, Description = subverse.description, RatedAdult = subverse.rated_adult, Sidebar = subverse.sidebar, SubscriberCount = subscriberCount, Title = subverse.title, Type = subverse.type }; return(resultModel); }
public async Task<ActionResult> Submit([Bind(Include = "Id,Votes,Name,Date,Type,Linkdescription,Title,Rank,MessageContent,Subverse")] Message message) { // abort if model state is invalid if (!ModelState.IsValid) return View(); // save temp values for the view in case submission fails ViewBag.selectedSubverse = message.Subverse; ViewBag.message = message.MessageContent; ViewBag.title = message.Title; ViewBag.linkDescription = message.Linkdescription; // check if user is banned if (Utils.User.IsUserGloballyBanned(message.Name) || Utils.User.IsUserBannedFromSubverse(User.Identity.Name, message.Subverse)) { ViewBag.SelectedSubverse = message.Subverse; return View("~/Views/Home/Comments.cshtml", message); } // check if user has reached hourly posting quota for target subverse if (Utils.User.UserHourlyPostingQuotaForSubUsed(User.Identity.Name, message.Subverse)) { ModelState.AddModelError("", "You have reached your hourly submission quota for this subverse."); return View(); } // check if user has reached daily posting quota for target subverse if (Utils.User.UserDailyPostingQuotaForSubUsed(User.Identity.Name, message.Subverse)) { ModelState.AddModelError("", "You have reached your daily submission quota for this subverse."); return View(); } // verify recaptcha if user has less than 25 CCP var userCcp = Karma.CommentKarma(User.Identity.Name); if (userCcp < 25) { bool isCaptchaCodeValid = await ReCaptchaUtility.Validate(Request); if (!isCaptchaCodeValid) { ModelState.AddModelError("", "Incorrect recaptcha answer."); // TODO // SET PREVENT SPAM DELAY TO 0 return View(); } } // if user CCP or SCP is less than -50, allow only X submissions per 24 hours var userScp = Karma.LinkKarma(User.Identity.Name); if (userCcp <= -50 || userScp <= -50) { var quotaUsed = Utils.User.UserDailyPostingQuotaForNegativeScoreUsed(User.Identity.Name); if (quotaUsed) { ModelState.AddModelError("", "You have reached your daily submission quota. Your current quota is " + MvcApplication.DailyPostingQuotaForNegativeScore + " submission(s) per 24 hours."); return View(); } } // abort if model state is invalid if (!ModelState.IsValid) return View("Submit"); // check if subverse exists var targetSubverse = SubverseCache.Retrieve(message.Subverse); if (targetSubverse == null || message.Subverse.Equals("all", StringComparison.OrdinalIgnoreCase)) { ModelState.AddModelError(string.Empty, "Sorry, The subverse you are trying to post to does not exist."); return View("Submit"); } // check if subverse has "authorized_submitters_only" set and dissalow submission if user is not allowed submitter if (targetSubverse.authorized_submitters_only) { if (!Utils.User.IsUserSubverseModerator(User.Identity.Name, targetSubverse.name)) { // user is not a moderator, check if user is an administrator if (!Utils.User.IsUserSubverseAdmin(User.Identity.Name, targetSubverse.name)) { ModelState.AddModelError("", "You are not authorized to submit links or start discussions in this subverse. Please contact subverse moderators for authorization."); return View("Submit"); } } } // everything was okay, process incoming submission // submission is a link post // generate a thumbnail if submission is a direct link to image or video if (message.Type == 2 && message.MessageContent != null && message.Linkdescription != null) { // strip unicode if title contains unicode if (Submissions.ContainsUnicode(message.Linkdescription)) { message.Linkdescription = Submissions.StripUnicode(message.Linkdescription); } // abort if title is < than 10 characters if (message.Linkdescription.Length < 10) { ModelState.AddModelError(string.Empty, "Sorry, the title may not be less than 10 characters."); return View("Submit"); } var domain = UrlUtility.GetDomainFromUri(message.MessageContent); // make sure the input URI is valid if (!UrlUtility.IsUriValid(message.MessageContent)) { ModelState.AddModelError(string.Empty, "Sorry, the URI you are trying to submit is invalid."); return View("Submit"); } // check if target subvere allows submissions from globally banned hostnames if (!targetSubverse.exclude_sitewide_bans) { // check if hostname is banned before accepting submission if (BanningUtility.IsHostnameBanned(domain)) { ModelState.AddModelError(string.Empty, "Sorry, the hostname you are trying to submit is banned."); return View("Submit"); } } // check if same link was submitted before and deny submission var existingSubmission = _db.Messages.FirstOrDefault(s => s.MessageContent.Equals(message.MessageContent, StringComparison.OrdinalIgnoreCase) && s.Subverse.Equals(message.Subverse, StringComparison.OrdinalIgnoreCase)); // submission is a repost, discard it and inform the user if (existingSubmission != null) { ModelState.AddModelError(string.Empty, "Sorry, this link has already been submitted by someone else."); // todo: offer the option to repost after informing the user about it return RedirectToRoute( "SubverseComments", new { controller = "Comment", action = "Comments", id = existingSubmission.Id, subversetoshow = existingSubmission.Subverse } ); } // check if user has reached daily crossposting quota if (Utils.User.DailyCrossPostingQuotaUsed(User.Identity.Name, message.MessageContent)) { ModelState.AddModelError("", "You have reached your daily crossposting quota for this URL."); return View(); } // check if target subverse has thumbnails setting enabled before generating a thumbnail if (targetSubverse.enable_thumbnails) { // try to generate and assign a thumbnail to submission model message.Thumbnail = ThumbGenerator.ThumbnailFromSubmissionModel(message); } // flag the submission as anonymized if it was submitted to a subverse with active anonymized_mode if (targetSubverse.anonymized_mode) { message.Anonymized = true; } else { message.Name = User.Identity.Name; } // accept submission and save it to the database message.Subverse = targetSubverse.name; // grab server timestamp and modify submission timestamp to have posting time instead of "started writing submission" time message.Date = DateTime.Now; message.Likes = 1; _db.Messages.Add(message); // update last submission received date for target subverse targetSubverse.last_submission_received = DateTime.Now; _db.SaveChanges(); } else if (message.Type == 1 && message.Title != null) { // submission is a self post // strip unicode if message contains unicode if (Submissions.ContainsUnicode(message.Title)) { message.Title = Submissions.StripUnicode(message.Title); } // abort if title less than 10 characters if (message.Title.Length < 10) { ModelState.AddModelError(string.Empty, "Sorry, the the message title may not be less than 10 characters."); return View("Submit"); } // accept submission and save it to the database // trim trailing blanks from subverse name if a user mistakenly types them message.Subverse = targetSubverse.name; // flag the submission as anonymized if it was submitted to a subverse with active anonymized_mode if (targetSubverse.anonymized_mode) { message.Anonymized = true; } else { message.Name = User.Identity.Name; } // grab server timestamp and modify submission timestamp to have posting time instead of "started writing submission" time message.Date = DateTime.Now; message.Likes = 1; _db.Messages.Add(message); // update last submission received date for target subverse targetSubverse.last_submission_received = DateTime.Now; if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave)) { message.MessageContent = ContentProcessor.Instance.Process(message.MessageContent, ProcessingStage.InboundPreSave, message); } _db.SaveChanges(); if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave)) { ContentProcessor.Instance.Process(message.MessageContent, ProcessingStage.InboundPostSave, message); } } return RedirectToRoute( "SubverseComments", new { controller = "Comment", action = "Comments", id = message.Id, subversetoshow = message.Subverse } ); }
// GET: comments for a given submission public ActionResult Comments(int?id, string subversetoshow, int?startingcommentid, string sort, int?commentToHighLight) { var subverse = SubverseCache.Retrieve(subversetoshow); //var subverse = _db.Subverses.Find(subversetoshow); if (subverse == null) { return(View("~/Views/Errors/Error_404.cshtml")); } //HACK: Disable subverse if (subverse.admin_disabled.HasValue && subverse.admin_disabled.Value) { ViewBag.Subverse = subverse.name; return(View("~/Views/Errors/SubverseDisabled.cshtml")); } ViewBag.SelectedSubverse = subverse.name; ViewBag.SubverseAnonymized = subverse.anonymized_mode; //Temp cache user votes for this thread ViewBag.VoteCache = UserVotesBySubmission(id.Value); ViewBag.SavedCommentCache = UserSavedCommentsBySubmission(id.Value); if (startingcommentid != null) { ViewBag.StartingCommentId = startingcommentid; } if (commentToHighLight != null) { ViewBag.CommentToHighLight = commentToHighLight; } if (sort != null) { ViewBag.SortingMode = sort; } if (id == null) { return(View("~/Views/Errors/Error.cshtml")); } var submission = _db.Messages.Find(id); if (submission == null) { return(View("~/Views/Errors/Error_404.cshtml")); } // make sure that the combination of selected subverse and message subverse are linked if (!submission.Subverse.Equals(subversetoshow, StringComparison.OrdinalIgnoreCase)) { return(View("~/Views/Errors/Error_404.cshtml")); } // experimental: register a new session for this subverse string clientIpAddress = String.Empty; if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) { clientIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; } else if (Request.UserHostAddress.Length != 0) { clientIpAddress = Request.UserHostAddress; } if (clientIpAddress == String.Empty) { return(View("~/Views/Home/Comments.cshtml", submission)); } // generate salted hash of client IP address string ipHash = IpHash.CreateHash(clientIpAddress); var currentSubverse = (string)RouteData.Values["subversetoshow"]; // register a new session for this subverse SessionTracker.Add(currentSubverse, ipHash); // register a new view for this thread // check if this hash is present for this submission id in viewstatistics table var existingView = _db.Viewstatistics.Find(submission.Id, ipHash); // this IP has already viwed this thread, skip registering a new view if (existingView != null) { return(View("~/Views/Home/Comments.cshtml", submission)); } // this is a new view, register it for this submission var view = new Viewstatistic { submissionId = submission.Id, viewerId = ipHash }; _db.Viewstatistics.Add(view); submission.Views++; _db.SaveChanges(); return(View("~/Views/Home/Comments.cshtml", submission)); }
// GET: rss/{subverseName} public ActionResult Rss(string subverseName) { var submissions = new List <Message>(); if (subverseName != null && subverseName != "all") { // return only frontpage submissions from a given subverse var subverse = SubverseCache.Retrieve(subverseName); // _db.Subverses.Find(subverseName); if (subverse != null) { //HACK: Disable subverse if (subverse.admin_disabled.HasValue && subverse.admin_disabled.Value) { ViewBag.Subverse = subverse.name; return(View("~/Views/Errors/SubverseDisabled.cshtml")); } submissions = (from message in _db.Messages where message.Name != "deleted" && message.Subverse == subverse.name select message) .OrderByDescending(s => s.Rank) .Take(25) .ToList(); } } else if (subverseName == "all") { // return submissions from all subs submissions = (from message in _db.Messages join subverse in _db.Subverses on message.Subverse equals subverse.name where message.Name != "deleted" && subverse.private_subverse != true && subverse.forced_private != true && message.Rank > 0.00009 where !(from bu in _db.Bannedusers select bu.Username).Contains(message.Name) select message).OrderByDescending(s => s.Rank).ThenByDescending(s => s.Date).Take(25).ToList(); } else { // return site-wide frontpage submissions submissions = (from message in _db.Messages where message.Name != "deleted" join defaultsubverse in _db.Defaultsubverses on message.Subverse equals defaultsubverse.name select message) .OrderByDescending(s => s.Rank) .Take(25) .ToList(); } var feed = new SyndicationFeed("Voat", "Have your say", new Uri("http://www.voat.co")) { Language = "en-US", ImageUrl = new Uri("http://" + System.Web.HttpContext.Current.Request.Url.Authority + "/Graphics/voat-logo.png") }; var feedItems = new List <SyndicationItem>(); foreach (var submission in submissions) { var commentsUrl = new Uri("http://" + System.Web.HttpContext.Current.Request.Url.Authority + "/v/" + submission.Subverse + "/comments/" + submission.Id); var subverseUrl = new Uri("http://" + System.Web.HttpContext.Current.Request.Url.Authority + "/v/" + submission.Subverse); var authorName = submission.Name; if (submission.Type == 1) { // message type submission if (submission.Anonymized || submission.Subverses.anonymized_mode) { authorName = submission.Id.ToString(CultureInfo.InvariantCulture); } var item = new SyndicationItem( submission.Title, submission.MessageContent + "</br>" + "Submitted by " + "<a href='u/" + authorName + "'>" + authorName + "</a> to <a href='" + subverseUrl + "'>" + submission.Subverse + "</a> | <a href='" + commentsUrl + "'>" + submission.Comments.Count() + " comments", commentsUrl, submission.Id.ToString(CultureInfo.InvariantCulture), submission.Date); feedItems.Add(item); } else { // link type submission var linkUrl = new Uri(submission.MessageContent); authorName = submission.Name; if (submission.Anonymized || submission.Subverses.anonymized_mode) { authorName = submission.Id.ToString(CultureInfo.InvariantCulture); } // add a thumbnail if submission has one if (submission.Thumbnail != null) { var thumbnailUrl = new Uri("http://" + System.Web.HttpContext.Current.Request.Url.Authority + "/Thumbs/" + submission.Thumbnail).ToString(); var item = new SyndicationItem( submission.Linkdescription, "<a xmlns='http://www.w3.org/1999/xhtml' href='" + commentsUrl + "'><img title='" + submission.Linkdescription + "' alt='" + submission.Linkdescription + "' src='" + thumbnailUrl + "' /></a>" + "</br>" + "Submitted by " + "<a href='u/" + authorName + "'>" + authorName + "</a> to <a href='" + subverseUrl + "'>" + submission.Subverse + "</a> | <a href='" + commentsUrl + "'>" + submission.Comments.Count() + " comments</a>" + " | <a href='" + linkUrl + "'>link</a>", commentsUrl, submission.Id.ToString(CultureInfo.InvariantCulture), submission.Date); feedItems.Add(item); } else { var item = new SyndicationItem( submission.Linkdescription, "Submitted by " + "<a href='u/" + authorName + "'>" + authorName + "</a> to <a href='" + subverseUrl + "'>" + submission.Subverse + "</a> | <a href='" + commentsUrl + "'>" + submission.Comments.Count() + " comments", commentsUrl, submission.Id.ToString(CultureInfo.InvariantCulture), submission.Date); feedItems.Add(item); } } } feed.Items = feedItems; return(new FeedResult(new Rss20FeedFormatter(feed))); }