Пример #1
0
        public static string PageTitle <TModel>(this HtmlHelper <TModel> htmlHelper, params string[] items) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (items == null || items.Length == 0)
            {
                return(model.Site.DisplayName);
            }

            StringBuilder sb       = new StringBuilder(50);
            List <string> itemList = new List <string>(items);

            itemList.RemoveAll(s => s == null);

            itemList.Insert(0, model.Site.DisplayName);

            for (int i = itemList.Count - 1; i >= 0; i--)
            {
                sb.Append(itemList[i]);

                if (i > 0)
                {
                    sb.Append(model.Site.PageTitleSeparator);
                }
            }

            return(htmlHelper.Encode(sb.ToString()));
        }
Пример #2
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                string      areaName = filterContext.RouteData.Values["areaName"] as string;
                Area        area     = !string.IsNullOrEmpty(areaName) ? areaService.GetArea(areaName) : null;
                Post        post     = null;
                List <Post> posts    = new List <Post>();

                if (area != null && string.Compare(area.Name, "IE8", true) == 0)
                {
                    posts.AddRange(postService.GetPosts(0, 50, area, (DateTime?)null));
                }

                if (area != null && string.Compare(area.Name, "MIX09", true) == 0)
                {
                    post = postService.GetPosts(0, 1, area, (DateTime?)null).FirstOrDefault();
                }
                else
                {
                    post = postService.GetRandomPost();
                }

                model.AddModelItem(new SidebarViewModel(post, posts));
            }
        }
Пример #3
0
 private void setLocalization(OxiteModel model)
 {
     if (model != null)
     {
         model.AddModelItem(locService.GetTranslations());
     }
 }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model == null)
            {
                return;
            }

            IList <KeyValuePair <ArchiveData, int> > archives;
            string       areaName = filterContext.RouteData.Values["areaName"] as string;
            INamedEntity container;

            if (!string.IsNullOrEmpty(areaName))
            {
                archives = postService.GetArchives(new Area {
                    Name = areaName
                });
                container = areaService.GetArea(areaName);
            }
            else
            {
                archives  = postService.GetArchives();
                container = new HomePageContainer();
            }

            model.AddModelItem(new ArchiveViewModel(archives, container));
        }
Пример #5
0
 private void setModel(OxiteModel model)
 {
     if (model != null)
     {
         model.Site = new SiteViewModel(site, appSettings.GetString("SiteName", "Oxite"));
     }
 }
Пример #6
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                model.AntiForgeryToken = new AntiForgeryToken(site.ID.ToString());
            }
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                model.AddModelItem(new AreaListViewModel(areaService.GetAreas()));
            }
        }
Пример #8
0
 public static string Gravatar(this HtmlHelper htmlHelper, OxiteModel model, UserBase user, string size)
 {
     return(htmlHelper.Gravatar(
                user != null ? user.HashedEmail.CleanAttribute() : null,
                user != null ? (user.DisplayName ?? user.Name).CleanAttribute() : null,
                size,
                model.Site.GravatarDefault
                ));
 }
Пример #9
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                model.Site = new SiteViewModel(site, appSettings.GetString("SiteName", "Oxite"));
            }
        }
        public void SignInSetsContainerToSignIn()
        {
            UserController controller = new UserController(null, null);

            OxiteModel result = controller.SignIn();

            Assert.NotNull(result);
            Assert.IsType <SignInPageContainer>(result.Container);
        }
Пример #11
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model == null)
            {
                return;
            }

            model.AddModelItem(new PageListViewModel(pageService.GetPages()));
        }
Пример #12
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)));
            }
        }
Пример #13
0
        public static string OxiteAntiForgeryToken <TModel>(this HtmlHelper <TModel> htmlHelper, Func <TModel, OxiteModel> getRootModel) where TModel : class
        {
            OxiteModel rootModel = getRootModel(htmlHelper.ViewData.Model);

            if (rootModel != null)
            {
                return(htmlHelper.AntiForgeryToken(rootModel.Site.ID.ToString()));
            }

            return("");
        }
Пример #14
0
        public static void RenderFavIcon <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (!string.IsNullOrEmpty(model.Site.FavIconUrl))
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                htmlHelper.ViewContext.HttpContext.Response.Write(htmlHelper.HeadLink("shortcut icon", urlHelper.AppPath(model.Site.FavIconUrl), null, null));
            }
        }
Пример #15
0
        public static string Gravatar <TModel>(this HtmlHelper <TModel> htmlHelper, UserBase user, string size) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            return(htmlHelper.Gravatar(
                       user != null ? user.HashedEmail.CleanAttribute() : null,
                       user != null ? (user.DisplayName ?? user.Name).CleanAttribute() : null,
                       size,
                       model.Site.GravatarDefault
                       ));
        }
Пример #16
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model == null)
            {
                return;
            }

            model.AddModelItem(new TagCloudViewModel(tagService.GetTagsWithPostCount()));
        }
Пример #17
0
        public void AddModelItemThenGetModelItemReturnsItem()
        {
            OxiteModel model = new OxiteModel();

            OxiteModelTests modelItem = new OxiteModelTests();

            model.AddModelItem(modelItem);

            var actualItem = model.GetModelItem <OxiteModelTests>();

            Assert.Same(modelItem, actualItem);
        }
Пример #18
0
        public static string OpenSearchOSDXLink <TModel>(this HtmlHelper <TModel> htmlHelper) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (model.Site.IncludeOpenSearch && htmlHelper.ViewContext.HttpContext.Request.UserAgent.Contains("Windows NT 6.1"))
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                return(htmlHelper.Link(string.Format(model.Localize("Search.WindowsSearch", "Search {0} in Windows"), model.Site.DisplayName), urlHelper.AppPath(urlHelper.OpenSearchOSDX()), new { @class = "windowsSearch" }));
            }

            return("");
        }
Пример #19
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            ViewResult result = filterContext.Result as ViewResult;

            if (result != null)
            {
                OxiteModel model = result.ViewData.Model as OxiteModel;
                if (model != null)
                {
                    model.AddModelItem(locService.GetTranslations());
                }
            }
        }
Пример #20
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                UserBase user = filterContext.HttpContext.User.Identity.IsAuthenticated
                    ? userService.GetUser(filterContext.HttpContext.User.Identity.Name)
                    : filterContext.HttpContext.Request.Cookies.GetAnonymousUser();

                if (user != null)
                {
                    model.User = new UserViewModel(user);
                }
            }
        }
Пример #21
0
        public static string Published <TModel>(this HtmlHelper <TModel> htmlHelper, Post post) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            if (post.State == EntityState.Removed)
            {
                return(model.Localize("Removed"));
            }

            if (post.Published.HasValue)
            {
                return(ConvertToLocalTime(htmlHelper, post.Published.Value, htmlHelper.ViewData.Model).ToLongDateString());
            }

            return(model.Localize("Draft"));
        }
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                //recent posts - all up
                IList <Post> posts = postService.GetPostsWithDrafts(0, 5);

                //recent comments - all up
                IList <ParentAndChild <PostBase, Comment> > comments = postService.GetComments(0, 10, true, true);

                IList <Area> areas = areaService.GetAreas();

                model.AddModelItem(new AdminDataViewModel(posts, comments, areas));
            }
        }
Пример #23
0
        public void OnActionExecutedAddsAllPhrasesToModel()
        {
            FakeLocalizationService locService = new FakeLocalizationService();

            OxiteModel model = new OxiteModel();

            ActionExecutedContext context = new ActionExecutedContext()
            {
                Result = new ViewResult() { ViewData = new ViewDataDictionary(model) }
            };

            LocalizationActionFilter filter = new LocalizationActionFilter(locService);

            filter.OnActionExecuted(context);

            Assert.NotNull(model.GetModelItem<ICollection<Phrase>>());
            Assert.Same(locService.Phrases, model.GetModelItem<ICollection<Phrase>>());
        }
Пример #24
0
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            OxiteModel model = filterContext.Controller.ViewData.Model as OxiteModel;

            if (model != null)
            {
                string areaName = filterContext.RouteData.Values["areaName"] as string;
                if (areaName != null)
                {
                    Area area = areaService.GetArea(areaName);
                    model.AddModelItem(new TagCloudViewModel(tagService.GetTagsUsedIn(area)));
                }
                else
                {
                    model.AddModelItem(new TagCloudViewModel(tagService.GetTagsWithPostCount()));
                }
            }
        }
Пример #25
0
        public static DateTime ConvertToLocalTime(this HtmlHelper htmlHelper, DateTime dateTime, OxiteModel model)
        {
            if (model.User == null)
            {
                if (model.Site.TimeZoneOffset != 0)
                {
                    return(dateTime.Add(TimeSpan.FromHours(model.Site.TimeZoneOffset)));
                }

                return(dateTime);
            }

            return(dateTime); //TODO: (erikpo) Get the timezone offset from the current user and apply it
        }
Пример #26
0
        public void GetModelReturnsNullIfNotFound()
        {
            OxiteModel model = new OxiteModel();

            Assert.Null(model.GetModelItem <OxiteModelTests>());
        }
Пример #27
0
 public OxiteModelPartial(OxiteModel rootModel, T partialModel)
 {
     RootModel    = rootModel;
     PartialModel = partialModel;
 }
Пример #28
0
        public static string TextBoxWithValidation <TModel>(this HtmlHelper <TModel> htmlHelper, string validationKey, string name, object value, object htmlAttributes) where TModel : OxiteModel
        {
            OxiteModel model = htmlHelper.ViewData.Model;

            return(htmlHelper.TextBox(name, value, htmlAttributes) + htmlHelper.ValidationMessage(validationKey, model.Localize(validationKey)));
        }