public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var cookies = filterContext.HttpContext.Request.Cookies["OurAcceptCookie"];
        var values  = filterContext.RouteData.Values.Values;

        originalRequest = filterContext.HttpContext.Request.Url.AbsoluteUri;
        RouteValueDictionary requestOrigin = new RouteValueDictionary {
            {
                "url", originalRequest
            }
        };

        if (cookies == null && !values.Contains("CookieConsent"))     //so that it won't loop endlessly
        {
            UrlHelper urlHelper = new UrlHelper(filterContext.RequestContext);
            //filterContext.Result = new RedirectResult(urlHelper.Action("CookieConsent", "Home"));
            filterContext.Result = new RedirectResult(urlHelper.Action("CookieConsent", "Cookie", requestOrigin, "https", "www.my-domain.com/mysitename"));
        }
        else if (cookies != null)
        {
            string    controllerName = filterContext.RouteData.Values["controller"].ToString();
            string    actionName     = filterContext.RouteData.Values["action"].ToString();
            UrlHelper urlHelper      = new UrlHelper(filterContext.RequestContext);
            filterContext.Result = new RedirectResult(urlHelper.AbsolutePath(actionName, controllerName));
        }
    }
Beispiel #2
0
        public ModelResult <Post> AddPost(PostInput postInput, EntityState postState)
        {
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPost", new PluginPostInput(postInput)).ToPostInput();
            postInput = pluginEngine.Process <PluginPostInput>("ProcessInputOfPostOnAdd", new PluginPostInput(postInput)).ToPostInput();

            ModelResult <Post> results = addPost(postInput, () => postInput.ToPost(postState, context.User.Cast <User>(), t => expressions.Clean("TagReplace", t)));

            if (results.IsValid)
            {
                Post   newPost = results.Item;
                string postUrl = urlHelper.AbsolutePath(urlHelper.Post(newPost));

                //TODO: (erikpo) Move this into a module
                addCreatorSubscription(newPost);

                //TODO: (erikpo) Move this into a module
                if (newPost.State == EntityState.Normal && newPost.Published.HasValue)
                {
                    IEnumerable <TrackbackOutbound> trackbacksToAdd    = extractTrackbacks(newPost, postUrl, newPost.Blog.DisplayName);
                    IEnumerable <TrackbackOutbound> unsentTrackbacks   = trackbackOutboundRepository.GetUnsent(newPost.ID);
                    IEnumerable <TrackbackOutbound> trackbacksToRemove = trackbacksToAdd.Where(tb => !unsentTrackbacks.Contains(tb) && !tb.Sent.HasValue);

                    trackbackOutboundRepository.Remove(trackbacksToRemove);
                    trackbackOutboundRepository.Save(trackbacksToAdd);
                }
                else
                {
                    //TODO: (erikpo) Remove all outbound trackbacks
                }

                pluginEngine.ExecuteAll("PostSaved", new { context, post = new PostReadOnly(newPost, postUrl) });
                pluginEngine.ExecuteAll("PostAdded", new { context, post = new PostReadOnly(newPost, postUrl) });

                if (newPost.State == EntityState.Normal && newPost.Published.HasValue && newPost.Published.Value <= DateTime.UtcNow)
                {
                    pluginEngine.ExecuteAll("PostPublished", new { context, post = new PostReadOnly(newPost, postUrl) });
                }
            }

            return(results);
        }
Beispiel #3
0
        public static void RenderRsd(this HtmlHelper htmlHelper, string areaName)
        {
            UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

            htmlHelper.ViewContext.HttpContext.Response.Write(
                htmlHelper.HeadLink(
                    "EditURI",
                    urlHelper.AbsolutePath(urlHelper.Rsd(areaName)),
                    "application/rsd+xml",
                    "RSD"
                    )
                );
        }
        private string generateMessageBody(ScheduleItemSmall post, ScheduleItemComment comment, Site site)
        {
            string body = getPhrase("Messages.NewComment", site.LanguageDefault, getDefaultBody());
            //TODO: (erikpo) Change this to come from the user this message is going to if applicable
            double timeZoneOffset = site.TimeZoneOffset;

            body = body.Replace("{Site.Name}", site.DisplayName);
            body = body.Replace("{User.Name}", comment.CreatorName);
            body = body.Replace("{Post.Title}", post.Title);
            //TODO: (erikpo) Change the published date to be relative (e.g. 5 minutes ago)
            body = body.Replace("{Comment.Created}", comment.Created.AddHours(timeZoneOffset).ToLongTimeString());
            body = body.Replace("{Comment.Body}", comment.Body);
            body = body.Replace("{Comment.Permalink}", urlHelper.AbsolutePath(urlHelper.Comment(comment)));

            return(body);
        }
Beispiel #5
0
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            //TODO: (erikpo) Check a ViewTrackingEnabled Site setting to add these or not
            object viewTrackingValue = filterContext.RouteData.Values["viewTracking"];
            bool   viewTracking      = viewTrackingValue != null && viewTrackingValue is bool?(bool)viewTrackingValue : true;

            //TODO: (erikpo) some of this logic should probably move into an ActionCriteria class
            if (viewTracking && !filterContext.HttpContext.Request.ApplicationPath.TrimStart('/').StartsWith("Admin") && string.Compare(filterContext.HttpContext.Request.HttpMethod, "POST", true) != 0)
            {
                ResponseFilter responseFilter  = new ResponseFilter(filterContext.HttpContext.Response.Filter);
                UrlHelper      urlHelper       = new UrlHelper(filterContext.RequestContext);
                string         viewTrackingUrl = urlHelper.AbsolutePath(filterContext.HttpContext.Request.Url.AbsolutePath).TrimEnd('/');
                const string   imgTag          = "<img src=\"{0}/_View_\" width=\"1\" height=\"1\" />";

                //TODO: (erikpo) Add a site setting for whether the img should be at the beginning or the end of the inside of the body tag
                if (filterContext.RouteData.Values["dataFormat"] == null || ((string)filterContext.RouteData.Values["dataFormat"]) == "")
                {
                    responseFilter.Inserts.Add(new ResponseInsert(string.Format(imgTag, viewTrackingUrl), ResponseInsertMode.PrependTo, "body"));
                }
                else if (string.Compare((string)filterContext.RouteData.Values["dataFormat"], "RSS", true) == 0)
                {
                    int modelListCount = getModelListCount(filterContext.Controller.ViewData.Model);

                    for (int i = 0; i < modelListCount; i++)
                    {
                        int index = i;

                        responseFilter.Inserts.Add(new ResponseInsert(HttpUtility.HtmlEncode(string.Format(imgTag, viewTrackingUrl)), ResponseInsertMode.AppendTo, doc => findElementsInRss(doc, index), insertValue));
                    }
                }
                else if (string.Compare((string)filterContext.RouteData.Values["dataFormat"], "ATOM", true) == 0)
                {
                    int modelListCount = getModelListCount(filterContext.Controller.ViewData.Model);

                    for (int i = 0; i < modelListCount; i++)
                    {
                        int index = i;

                        responseFilter.Inserts.Add(new ResponseInsert(HttpUtility.HtmlEncode(string.Format(imgTag, viewTrackingUrl)), ResponseInsertMode.AppendTo, doc => findElementsInAtom(doc, index), insertValue));
                    }
                }

                filterContext.HttpContext.Response.Filter = responseFilter;
            }
        }
Beispiel #6
0
        public static void RenderOpenSearch <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (model.Site.IncludeOpenSearch)
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                htmlHelper.ViewContext.HttpContext.Response.Write(htmlHelper.HeadLink("search", urlHelper.AbsolutePath(urlHelper.OpenSearch()), "application/opensearchdescription+xml", string.Format(model.Localize("SearchFormat", "{0} Search"), model.Site.DisplayName)));
            }
        }
Beispiel #7
0
        public static string PingbackDiscovery(this HtmlHelper htmlHelper, Post post)
        {
            UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

            return(htmlHelper.HeadLink("pingback", urlHelper.AbsolutePath(urlHelper.Pingback(post)), "", ""));
        }
Beispiel #8
0
        public static string TrackbackBlock <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel
        {
            OxiteModelItem <Post> model = htmlHelper.ViewData.Model as OxiteModelItem <Post>;

            if (model != null)
            {
                Post post = ((OxiteModelItem <Post>)model).Item;

                if (post != null)
                {
                    UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                    return(string.Format("<!--<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:trackback=\"http://madskills.com/public/xml/rss/module/trackback/\"><rdf:Description rdf:about=\"{2}\" dc:identifier=\"{2}\" dc:title=\"{0}\" trackback:ping=\"{1}\" /></rdf:RDF>-->", htmlHelper.Encode(post.Title), urlHelper.AbsolutePath(urlHelper.Trackback(post)), urlHelper.AbsolutePath(urlHelper.Post(post))));
                }
            }

            return("");
        }
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            OxiteModelList <Post> model = filterContext.Controller.ViewData.Model as OxiteModelList <Post>;

            if (model != null)
            {
                UrlHelper      urlHelper      = new UrlHelper(filterContext.RequestContext);
                ResponseFilter responseFilter = new ResponseFilter(filterContext.HttpContext.Response.Filter, filterContext.HttpContext);

                for (int i = 0; i < model.List.Count; i++)
                {
                    Post   post   = model.List[i];
                    string imgTag = HttpUtility.HtmlEncode(string.Format("<div><img src=\"{0}\" width=\"1\" height=\"1\" alt=\"\" /></div>", urlHelper.AbsolutePath(urlHelper.PostViewBug(post, viewType))));

                    int index = i;

                    responseFilter.Inserts.Add(new ResponseInsert(imgTag, ResponseInsertMode.AppendTo, doc => findElements(doc, index), (elements, mode, value) => insertValue(elements, mode, value)));
                }

                filterContext.HttpContext.Response.Filter = responseFilter;
            }
        }
        public ModelResult <PostComment> AddComment(Post post, CommentInput commentInput)
        {
            CommentIn commentIn = new CommentIn(commentInput);

            pluginEngine.ExecuteAll("ProcessInputOfComment", new { context, comment = commentIn });
            commentInput = commentIn.ToCommentInput();

            commentInput = pluginEngine.Process("ProcessInputOfCommentOnAdd", new CommentIn(commentInput)).ToCommentInput();

            if (pluginEngine.AnyTrue("IsCommentSpam", new { context, comment = commentIn }))
            {
                return(new ModelResult <PostComment>(new ValidationStateDictionary(typeof(CommentInput), new ValidationState(new[] { new ValidationError("Comment.IsSpam", commentInput, "The supplied comment was considered to be spam and was not added") }))));
            }

            ValidationStateDictionary validationState = ValidateCommentInput(commentInput);

            if (!validationState.IsValid)
            {
                return(new ModelResult <PostComment>(validationState));
            }

            EntityState commentState;

            try
            {
                commentState = context.User.IsAuthenticated ? EntityState.Normal : (EntityState)Enum.Parse(typeof(EntityState), context.Site.CommentStateDefault);
            }
            catch
            {
                commentState = EntityState.PendingApproval;
            }

            //TODO: (erikpo) Replace with some logic to set the language from the user's browser or from a dropdown list
            Language    language = languageRepository.GetLanguage(context.Site.LanguageDefault ?? "en");
            PostComment comment;

            using (TransactionScope transaction = new TransactionScope())
            {
                string commentSlug = generateUniqueCommentSlug(post);

                comment = commentInput.ToComment(context.User.Cast <User>(), context.HttpContext.Request.GetUserIPAddress().ToLong(), context.HttpContext.Request.UserAgent, language, commentSlug, commentState);

                comment = blogsCommentRepository.Save(comment, post.Blog.Name, post.Slug);

                if (comment.State == EntityState.Normal)
                {
                    invalidateCachedCommentDependencies(comment);
                }

                transaction.Complete();
            }

            //TODO: (erikpo) The following calls to setup the subscription and send out emails for those subscribed needs to happen in the transaction (but can't currently because of issues with them being in different repositories

            //TODO: (erikpo) Move into a module
            if (commentInput.Subscribe)
            {
                if (context.User.IsAuthenticated)
                {
                    postRepository.AddSubscription(post, comment.CreatorUserID);
                }
                else
                {
                    postRepository.AddSubscription(post, comment);
                }
            }

            //TODO: (erikpo) Move into a module
            messageOutboundRepository.Save(generateMessages(post, comment));

            PostSmallReadOnly postProxy    = new PostSmallReadOnly(comment.Post);
            CommentReadOnly   commentProxy = new CommentReadOnly(comment, urlHelper.AbsolutePath(urlHelper.Comment(comment)));

            pluginEngine.ExecuteAll("CommentAdded", new { context, parent = postProxy, comment = commentProxy });

            if (comment.State == EntityState.Normal)
            {
                pluginEngine.ExecuteAll("CommentApproved", new { context, parent = postProxy, comment = commentProxy });
            }

            return(new ModelResult <PostComment>(comment, validationState));
        }