Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        public void GetHostAndPortTest(string uriString, string expectedHostAndPort)
        {
            //fails with international tld (.jp, etc.)
            Uri    uri             = new Uri(uriString);
            string hostNameAndPort = HostHelper.GetHostAndPort(uri);

            Assert.AreEqual(hostNameAndPort, expectedHostAndPort);
        }
Ejemplo n.º 3
0
 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");
         }
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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/>";
            }
        }