protected void UrlCheck_ServerValidate(object source, ServerValidateEventArgs args) { // Retrieve the story given the url Dal.Story story = Incremental.Kick.Dal.Story.FetchStoryByUrl(args.Value); // If the story already exists in the database if (story != null) { // Make page invalid args.IsValid = false; // Let user kick the existing story by providing a link to it UrlCheck.ErrorMessage = string.Format("The story already exists. You might want to <a href=\"{0}\">kick it</a> instead.<br/>", UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, story.Category.CategoryIdentifier)); return; } // check to see its bannination status bool banninated = BannedUrlHelper.IsUrlBanninated(args.Value, HostCache.GetHost(HostHelper.GetHostAndPort(Request.Url)).HostID); // If the url matches if (banninated) { // Make page invalid args.IsValid = false; // Let user kick the existing story by providing a link to it UrlCheck.ErrorMessage = "This URL cannot be submitted.<br/>"; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/opensearchdescription+xml"; using (XmlTextWriter writer = new XmlTextWriter(context.Response.OutputStream, System.Text.Encoding.UTF8)) { //get the details from host object Host host = HostCache.GetHost(HostHelper.GetHostAndPort(context.Request.Url)); writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); writer.WriteStartElement("OpenSearchDescription", "http://a9.com/-/spec/opensearch/1.1/"); writer.WriteElementString("ShortName", host.SiteTitle); writer.WriteElementString("Description", host.SiteDescription); writer.WriteElementString("Contact", host.Email); writer.WriteStartElement("Image"); writer.WriteAttributeString("height", "16"); writer.WriteAttributeString("weight", "16"); writer.WriteAttributeString("type", "image/x-icon"); writer.WriteString(string.Format("{0}/favicon.ico", host.RootUrl)); writer.WriteEndElement(); writer.WriteStartElement("Url"); writer.WriteAttributeString("type", "text/html"); writer.WriteAttributeString("method", "GET"); writer.WriteAttributeString("template", string.Format("{0}/search?q={{searchTerms}}&user=False&page={{startPage?}}", host.RootUrl)); writer.WriteEndElement(); writer.Flush(); } }
public ApiStory ToApi() { Host host = HostCache.GetHost(this.HostID); return(new ApiStory( this.Title, host.RootUrl + UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, this.StoryIdentifier, CategoryCache.GetCategory(this.CategoryID, this.HostID).CategoryIdentifier), this.Description, this.CreatedOn, this.PublishedOn, this.IsPublishedToHomepage, this.KickCount, this.CommentCount, UserCache.GetUser(this.UserID).ToApi(host))); }
protected void Application_PostAuthenticateRequest(object sender, EventArgs e) { // If the referrer url is marked as blocked then redirect the user to another location // Check only pages referred by some website, pages referred by external hosts, and requests for .aspx pages if (Request.UrlReferrer != null && Request.UrlReferrer.Host != Request.Url.Host && Request.PhysicalPath.EndsWith(".aspx")) { BlockedReferralCollection blockedReferrals = BlockedReferralCache.GetBlockedReferrals(HostCache.GetHost(HostHelper.GetHostAndPort(Request.Url)).HostID); if (blockedReferrals.Exists( delegate(BlockedReferral referral) { return(Request.UrlReferrer.Host.Contains(referral.BlockedReferralHostname)); })) { Server.Transfer("~/Pages/Docs/SpamReferral.aspx"); } } }
public static void MarkAsSpam(int storyID, int hostID, User moderator) { Story story = Story.FetchByID(storyID); if (story.HostID != hostID) { throw new ArgumentException("The story does not belong to the host"); } else { story.IsSpam = true; story.UpdatedOn = DateTime.Now; story.Save(); UserAction.RecordStoryDeletion(hostID, story, moderator); EmailHelper.SendStoryDeletedEmail(Story.FetchByID(storyID), HostCache.GetHost(hostID)); } }
public string CheckStory(string url) { // check for dupes Story story = Story.FetchStoryByUrl(url); if (story != null) { return(string.Format("The story already exists. You might want to <a href=\"{0}\">kick it</a> instead.<br/>", UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, story.Category.CategoryIdentifier))); } //check for bannination if (BannedUrlHelper.IsUrlBanninated(url, HostCache.GetHost(HostHelper.GetHostAndPort(Request.Url)).HostID)) { return("This url cannot be submitted.<br/>"); } //returning null = everything's otay return(null); }
public virtual void ProcessRequest(HttpContext context) { this._hostProfile = HostCache.GetHost(HostHelper.GetHostAndPort(context.Request.Url)); this.GetStoryData(context); int storyCount = Math.Min( !string.IsNullOrEmpty(context.Request["count"]) ? Convert.ToUInt16(context.Request["count"]) : _stories.Count, _stories.Count); context.Response.ContentType = "text/javascript"; this.WriteJavaScriptLine(@"<div class=""KickStoryList"">", context); foreach (Story story in this._stories.GetRange(0, storyCount)) { this.WriteJavaScriptLine(@"<div class=""KickStory"">", context); this.WriteJavaScriptLine(String.Format(@"<a href=""{0}"">{1}</a>", UrlFactory.CreateUrl(UrlFactory.PageName.ViewStory, story.StoryIdentifier, CategoryCache.GetCategory(story.CategoryID, this._hostProfile.HostID).CategoryIdentifier, this._hostProfile), story.Title), context); this.WriteJavaScriptLine(@"</div>", context); } this.WriteJavaScriptLine(@"</div>", context); }
public static string AddStory(int hostID, string title, string description, string url, short categoryID, User user, string ipAddress) { if (user.IsBanned) { return(GetStoryIdentifier(title)); //to stop the spammers } //TODO: improve the validation string storyIdentifier = GetStoryIdentifier(title); if (description.Length > 2500) { description = description.Substring(0, 2500); } url = url.Trim(); if (url.Length > 980) { throw new Exception("The url is too long"); } title = HttpUtility.HtmlEncode(title); description = HttpUtility.HtmlEncode(description); Story story = new Story(); story.HostID = hostID; story.StoryIdentifier = storyIdentifier; story.Title = title; story.Description = description; story.Url = url; story.CategoryID = categoryID; story.UserID = user.UserID; story.KickCount = 0; story.SpamCount = 0; story.ViewCount = 0; story.CommentCount = 0; story.IsPublishedToHomepage = false; story.IsSpam = false; story.AdsenseID = user.AdsenseID; story.IPAddress = ipAddress; story.PublishedOn = DateTime.Now; story.UpdatedOn = DateTime.Now; story.Save(); UserAction.RecordStorySubmission(hostID, user, story); UserCache.KickStory(story.StoryID, user.UserID, hostID, ipAddress); TagBR.AddUserStoryTags(CategoryCache.GetCategory(categoryID, hostID).TagIdentifier, user, story.StoryID, hostID); System.Diagnostics.Trace.WriteLine("AddStory: " + title); //now send a trackback ping Host host = HostCache.GetHost(hostID); string storyUrl = host.RootUrl + "/" + CategoryCache.GetCategory(categoryID, hostID).CategoryIdentifier + "/" + story.StoryIdentifier; TrackbackHelper.SendTrackbackPing_Begin(url, title, storyUrl, "You've been kicked (a good thing) - Trackback from " + host.SiteTitle, host.SiteTitle); return(story.StoryIdentifier); }