Пример #1
0
        public List <FeaturedItem> GetFeaturedItemsModel()
        {
            //IPublishedContent homePage = CurrentPage.AncestorOrSelf(1).DescendantsOrSelf().Where(x => x.DocumentTypeAlias.Equals(HOME_PAGE_DOC_TYPE_ALIAS, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            IPublishedContent   homePage = _currentPage.AncestorOrSelf(_homeDocTypeAlias);
            List <FeaturedItem> model    = new List <FeaturedItem>();

            ArchetypeModel featuredItems = homePage.GetPropertyValue <ArchetypeModel>(_featuredItemsAlias);

            foreach (ArchetypeFieldsetModel fieldSet in featuredItems)
            {
                //name, categoryAlias, image, page
                string name     = fieldSet.GetValue <string>(_nameAlias);
                string category = fieldSet.GetValue <string>(_categoryAlias);
                int    imageId  = fieldSet.GetValue <int>(_imageAlias);
                int    pageId   = fieldSet.GetValue <int>(_pageAlias);

                var               mediaItem    = _uHelper.Media(imageId);
                string            imageUrl     = mediaItem.Url;
                IPublishedContent linkedToPage = _uHelper.TypedContent(pageId);
                string            linkUrl      = linkedToPage.Url;
                model.Add(new FeaturedItem()
                {
                    Name = name, Category = category, ImageUrl = imageUrl, LinkUrl = linkUrl
                });
            }
            return(model);
        }
Пример #2
0
        public List <FeaturedItem> GetFeaturedItemsModel()
        {
            List <FeaturedItem> model         = new List <FeaturedItem>();
            IPublishedContent   homePage      = _currentPage.AncestorOrSelf(_homeDocTypeAlias);
            ArchetypeModel      featuredItems = homePage.GetPropertyValue <ArchetypeModel>(_featuredItemsAlias);

            foreach (ArchetypeFieldsetModel fieldSet in featuredItems)
            {
                string imageUrl = fieldSet.GetValue <IPublishedContent>(_imageAlias).Url;
                string linkUrl  = fieldSet.GetValue <IPublishedContent>(_pageAlias).Url;

                model.Add(new FeaturedItem(fieldSet.GetValue <string>(_nameAlias), fieldSet.GetValue <string>(_categoryAlias), imageUrl, linkUrl));
            }
            return(model);
        }
Пример #3
0
        /// <summary>
        /// Gets the strongly typed auxiliary content (e.g. website settings) for the current site.
        /// </summary>
        /// <example>
        /// Homepage node has a composition doc type of AuxiliaryFolder (strongly-typed interface: IAuxiliaryFolder)
        /// which has a property called WebsiteSettings (MNTP limited to doc type WebsiteSettings).
        /// To get the website settings on the current node call:
        /// Model.GetAuxiliaryContent&lt;IAuxiliaryFolder, WebsiteSettings&gt;(x => x.WebsiteSettings)
        /// This will return the selected WebsiteSettings node with its strongly-typed model.
        /// </example>
        /// <param name="content"></param>
        /// <param name="property">The strongly typed property that contains the MNTP value for the auxiliary content</param>
        /// <returns></returns>
        public static TAuxiliaryType GetAuxiliaryContent <TAuxiliaryFolder, TAuxiliaryType>(this IPublishedContent content, Func <TAuxiliaryFolder, IEnumerable <IPublishedContent> > property)
            where TAuxiliaryFolder : class, IPublishedContent
            where TAuxiliaryType : class, IPublishedContent
        {
            var auxiliaryFolderNode = content?.AncestorOrSelf <TAuxiliaryFolder>();

            if (auxiliaryFolderNode == null)
            {
                if (UmbracoContext.Current?.PageId == null || UmbracoContext.Current.PageId == content?.Id)
                {
                    // no Umbraco context found or it's for the same node we already checked
                    return(default(TAuxiliaryType));
                }

                // try to get it based on current page ID, in case 'content' is a Nested Content node.
                var currentPage = UmbracoContext.Current.ContentCache.GetById(UmbracoContext.Current.PageId.Value);

                auxiliaryFolderNode = currentPage?.AncestorOrSelf <TAuxiliaryFolder>();
            }

            if (auxiliaryFolderNode == null)
            {
                return(default(TAuxiliaryType));
            }

            return(property(auxiliaryFolderNode)?.FirstOrDefault() as TAuxiliaryType);
        }
Пример #4
0
        public static IHtmlString the_tags(this IPublishedContent post,
                                           string propertyAlias,
                                           string before = "Tags: ", string sep = ",", string after = "")
        {
            var tags = post.GetPropertyValue <string[]>(propertyAlias);

            if (tags.Any())
            {
                var blogRoot = post.AncestorOrSelf(Blog.Presets.DocTypes.Blog);
                var tagBase  = blogRoot.GetPropertyValue <string>(Blog.Presets.Properties.TagBase, "tags");

                var links = new List <string>();

                foreach (var tag in tags)
                {
                    var url = $"{blogRoot.Url}{tagBase}/{tag}";
                    links.Add($"<a href=\"{url}\">{tag}</a>");
                }

                if (links.Any())
                {
                    return(new HtmlString($"{before}{string.Join(sep, links)}{after}"));
                }
            }

            return(new HtmlString(""));
        }
Пример #5
0
        public NavigationViewModel GetPrimaryNavigation(IPublishedContent model)
        {
            if (model == null)
            {
                return(null);
            }

            var homepage = model.AncestorOrSelf <Homepage>();

            if (homepage == null)
            {
                return(null);
            }

            var primaryNavigation = homepage?.PrimaryNavigation?.Where(_visible);

            if (primaryNavigation == null)
            {
                return(null);
            }

            return(new NavigationViewModel
            {
                CurrentPage = model,
                Items = primaryNavigation.Select(x => Map(x, model))
            });
        }
Пример #6
0
        /// <summary>
        /// Returns the website settings node
        /// </summary>
        /// <param name="content"></param>
        /// <returns></returns>
        public static IPublishedContent GetWebsiteSettings(this IPublishedContent content)
        {
            var umbracoHelper  = new UmbracoHelper(UmbracoContext.Current);
            var umbracoContext = umbracoHelper.UmbracoContext;
            var homepage       = content.AncestorOrSelf(1);

            //If it's a nested content element or the 'website settings' node, it has no knowledge of the home page and we need to get it some other way.
            if (!homepage.HasProperty("websiteSettings"))
            {
                var currentPage = umbracoContext.ContentCache.GetById(umbracoContext.PageId.Value);
                homepage = currentPage.AncestorOrSelf(1);
            }
            //It can be a page inside the website components folder rendering by itself.
            if (!homepage.HasProperty("websiteSettings"))
            {
                var currentPage = umbracoContext.ContentCache.GetById(umbracoContext.PageId.Value);
                // the website components folder may not be at the root such as when there are multiple websites.
                var websiteComponents = currentPage.AncestorsOrSelf().FirstOrDefault(c => c.DocumentTypeAlias.ToLower().Contains("websitecomponents"));
                if (websiteComponents != null)
                {
                    var rootNodes = umbracoHelper.TypedContentAtRoot();
                    homepage = rootNodes.FirstOrDefault(c => c.HasValue("websiteComponents") && c.GetLink("websiteComponents").Id == websiteComponents.Id);
                }
            }
            var link = homepage.GetLink("websiteSettings");

            return(umbracoHelper.TypedContent(link.Id));
        }
        public static IPublishedContent PageContentByAlias(string pageName)
        {
            UmbracoHelper     umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
            IPublishedContent currentPage   = umbracoHelper.AssignedContentItem;
            IPublishedContent pageContent   = currentPage.AncestorOrSelf(1).DescendantOrSelf(pageName);

            return(pageContent);
        }
        public GlobalModel(IPublishedContent content)
        {
            var rootNode = content.AncestorOrSelf(1);

            CompanyName = rootNode.GetPropertyValue<string>("companyName");
            CompanyAddress = rootNode.GetPropertyValue<string>("companyAddress");
            CompanyPhone = rootNode.GetPropertyValue<string>("companyPhone");
            CompanyEmail = rootNode.GetPropertyValue<string>("companyEmail");
        }
        /// <summary>
        /// Check if Property of a node is a supported data type
        /// </summary>
        /// <param name="list">List with already linked Nodes</param>
        /// <param name="node">Content Node to check</param>
        /// <param name="currentUdi">UDI from current Content Node</param>
        /// <param name="isContent">true, if User is in Content Section; false, if User is in Media Section</param>
        /// <returns>List of LinkedNodesDataModel</returns>
        private List <LinkedNodesDataModel> GetRelatedProperty(List <LinkedNodesDataModel> list,
                                                               IPublishedContent node, string currentUdi, bool isContent)
        {
            string nodePath = GetRelatedPath(node);

            foreach (var prop in node.Properties.Where(x => x.PropertyType.EditorAlias == "Umbraco.ContentPicker" ||
                                                       x.PropertyType.EditorAlias == "Umbraco.MultiNodeTreePicker" ||
                                                       x.PropertyType.EditorAlias == "Umbraco.MultiUrlPicker" ||
                                                       x.PropertyType.EditorAlias == "Umbraco.NestedContent" ||
                                                       x.PropertyType.EditorAlias == "Umbraco.Grid" ||
                                                       x.PropertyType.EditorAlias == "Umbraco.TinyMCE" ||
                                                       x.PropertyType.EditorAlias == "Umbraco.MediaPicker"))
            {
                try
                {
                    if (node.AncestorOrSelf(1).ContentType.Alias.ToString() != "b5HelpContentAppRepository")
                    {
                        IPublishedContent relatedNode = prop.GetValue() as IPublishedContent;
                        IEnumerable <IPublishedContent> relatedNodeList = new List <IPublishedContent>();

                        // relatedNode is null dependent from the datatype settings (i.e. Media Picker => Single oder multiple items)
                        if (relatedNode == null)
                        {
                            relatedNodeList = prop.GetValue() as IEnumerable <IPublishedContent>;
                        }

                        switch (prop.PropertyType.EditorAlias)
                        {
                        case "Umbraco.ContentPicker":
                        case "Umbraco.MediaPicker":
                            list = AddRelatedNodePicker(list, node, relatedNode, prop, nodePath, currentUdi,
                                                        relatedNodeList);
                            break;

                        case "Umbraco.MultiNodeTreePicker":
                            list = AddRelatedNodeMultiNodeTreePicker(list, node, prop, nodePath, currentUdi);
                            break;

                        case "Umbraco.MultiUrlPicker":
                            list = AddRelatedNodeMultiUrlPicker(list, node, prop, nodePath, currentUdi);
                            break;

                        case "Umbraco.NestedContent":
                        case "Umbraco.Grid":
                        case "Umbraco.TinyMCE":
                            list = AddRelatedNodeFromJsonSource(list, node, prop, nodePath, currentUdi, isContent);
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error <LinkedNodesDataModel>(ex);
                }
            }
            return(list);
        }
        public GlobalModel(IPublishedContent content)
        {
            var rootNode = content.AncestorOrSelf(1);

            CompanyName    = rootNode.GetPropertyValue <string>("companyName");
            CompanyAddress = rootNode.GetPropertyValue <string>("companyAddress");
            CompanyPhone   = rootNode.GetPropertyValue <string>("companyPhone");
            CompanyEmail   = rootNode.GetPropertyValue <string>("companyEmail");
        }
        public static IntranetMaster Map(IPublishedContent content, IntranetMaster model)
        {
            // Reference to the root (frontpage) node
            IPublishedContent rootNode = content.AncestorOrSelf(1);

            //Reference to the level 2 node
            IPublishedContent level2Node = content.AncestorOrSelf(2);

            // Get main navigation
            //model.MainNavigation = NavigationMapper.GetMainNavigation(rootNode, content);

            // Get top navigation
            //model.TopNavigation = NavigationMapper.GetTopNavigation(rootNode, content);

            model.LeftNavigation = NavigationMapper.GetIntranetMainNavigation(level2Node, content);

            model.MetaDescription = content.GetProperty("metaDescription") != null
                                        ? content.GetPropertyValue<string>("metaDescription")
                                        : string.Empty;

            model.MetaKeywords = content.GetProperty("metaKeywords") != null
                                     ? content.GetPropertyValue<string>("metaKeywords")
                                     : string.Empty;

            model.RedirectUrl = content.GetProperty("redirectURL") != null
                                    ? content.GetPropertyValue<string>("redirectURL")
                                    : string.Empty;

            model.BodyCssClass = level2Node != null
                                     ? level2Node.GetPropertyValue<string>("cssClassName")
                                     : string.Empty;

            model.SiteName = rootNode.GetProperty("siteName") != null
                                 ? rootNode.GetPropertyValue<string>("siteName")
                                 : string.Empty;

            model.SiteDescription = rootNode.GetProperty("siteDescription") != null
                                 ? rootNode.GetPropertyValue<string>("siteDescription")
                                 : string.Empty;

            model.Name = content.Name;

            return model;
        }
Пример #12
0
        public SiteHeaderModel GetModel(IPublishedContent currentPage)
        {
            SiteHeaderModel model = null;

            using (var cref = _umbracoContextFactory.EnsureUmbracoContext())
            {
                var blockRoot = cref.UmbracoContext.Content.GetByXPath($"//{BlockRoot.DocumentTypeAlias}").FirstOrDefault();

                if (blockRoot != null)
                {
                    var headerNode = blockRoot.Value <IPublishedContent>(BlockRoot.DefaultHeader);

                    model = base.GetModel <SiteHeaderModel>(headerNode);

                    model.MenuTitle = headerNode.Value <string>(SiteHeader.MenuTitle);

                    #region NavigationItems

                    var homePage = currentPage.AncestorOrSelf(1);// cref.UmbracoContext.Content.GetByXPath($"//{Home.DocumentTypeAlias}").FirstOrDefault();

                    //Simple nav - do not go to 2nd level

                    model.Navigation.NavigationItems.Add(homePage.UmbracoNodeToNavigationItem(PageBase.Title));

                    var availableChildren = homePage.Children.Where(x => x.HasProperty(Navigation.HideInHeader) && !x.Value <bool>(Navigation.HideInHeader)).ToList();

                    model.Navigation.NavigationItems.AddRange(availableChildren.Select(x => x.UmbracoNodeToNavigationItem(PageBase.Title)));

                    #endregion NavigationItems

                    #region HeaderInfo

                    model.UseHomepageHeader = homePage.Id == currentPage.Id;

                    model.HeaderText = currentPage.Value <string>(PageBase.Title);

                    model.SubText = currentPage.Value <string>(PageBase.SubTitle);

                    if (currentPage.HasValue(PageBase.BannerImage))
                    {
                        var cropSize = model.UseHomepageHeader ? ImageCropSizes.HomepageBannerCrop : ImageCropSizes.PageBannerCrop;

                        model.BannerImage = _imageBuilder.GetModel(currentPage.Value <IPublishedContent>(PageBase.BannerImage), cropSize);
                    }

                    if (currentPage.HasProperty(Home.BannerCTA))
                    {
                        model.BannerCTA = currentPage.Value <Link>(Home.BannerCTA)?.UmbracoLinkToLinkModel();
                    }

                    #endregion HeaderInfo
                }
            }

            return(model);
        }
Пример #13
0
        public LastBlogPosts GetLatestBlogPostModel()
        {
            IPublishedContent homePage     = _currentPage.AncestorOrSelf("home");
            string            title        = homePage.GetPropertyValue <string>("lastBlogPostsTitle");
            string            introduction = homePage.GetPropertyValue("lastBlogPostsIntroduction").ToString();

            LastBlogPosts model = new LastBlogPosts(title, introduction);

            return(model);
        }
        private IPublishedContent GetGAEventRoot()
        {
            if (_content == null)
            {
                return(null);
            }

            return(_content.AncestorOrSelf(1)
                   .Siblings()
                   .FirstOrDefault(n => n.DocumentTypeAlias == Keys.DocumentTypes.GAEventTrackingRootAlias));
        }
Пример #15
0
        private List <IPublishedContent> GetFooterChildNodes(IPublishedContent node)
        {
            var homePage = node.AncestorOrSelf(1);
            var footer   = homePage.Children.FirstOrDefault(content => content.DocumentTypeAlias.Equals("Footer", StringComparison.OrdinalIgnoreCase));

            if (footer == null)
            {
                return(new List <IPublishedContent>());
            }
            return(footer.Children.ToList());
        }
        /// <summary>
        /// Return the node where default settings are stored.
        /// </summary>
        public static IPublishedContent TopPage(this IPublishedContent content)
        {
            var topPage = (IPublishedContent)System.Web.HttpContext.Current.Items["TopPage"];

            if (topPage == null)
            {
                topPage = content.AncestorOrSelf(1);
                System.Web.HttpContext.Current.Items["TopPage"] = topPage;
            }

            return(topPage);
        }
Пример #17
0
        public static Website Website(this IPublishedContent content)
        {
            var website = HttpContext.Current.Items["Website"] as Website;

            if (website == null)
            {
                website = content.AncestorOrSelf <Website>();
                HttpContext.Current.Items["Website"] = website;
            }

            return(website);
        }
Пример #18
0
        //public Footer Footer { get; private set; }
        public static Settings GetFromContent(IPublishedContent content, Settings model)
        {
            IPublishedContent root = content.AncestorOrSelf(1);

            model.Email = root.GetPropertyValue<string>("email");
            model.Mobile = root.GetPropertyValue<string>("mobile");
            model.Sitename = root.GetPropertyValue<string>("sitename");

            //model.Footer = Footer.GetFromContent(content, new Footer());

            return model;
        }
Пример #19
0
        /// <summary>
        /// Looks for the Theme property specified ont he Site root node (Ancestor at Level 1)
        /// </summary>
        /// <param name="CurrentPage"></param>
        /// <returns></returns>
        public static string GetSiteThemeName(IPublishedContent CurrentPage)
        {
            var themeProp = ThemePropertyAlias();

            if (!string.IsNullOrEmpty(themeProp))
            {
                return(CurrentPage.AncestorOrSelf(1).Value <string>(themeProp));
            }
            else
            {
                return("");
            }
        }
Пример #20
0
        private HomePageModel getHomePage(IPublishedContent publishedContent)
        {
            var home = publishedContent.AncestorOrSelf(1);

            return(new HomePageModel
            {
                Icon = home.GetCropUrl("icon", "icon"),
                Id = home.Id,
                Name = home.Name,
                Url = home.Url(),
                LogoUrl = home.GetPropertyValue <string>("logoimage")
            });
        }
Пример #21
0
        public string GetValueFromAncestor(IPublishedContent node, string ancestorAlias, string propertyAlias)
        {
            string cacheKey = "USNBlog_GetValueFromAncestor_" + ancestorAlias;

            var root = USNCacheHelper.GetFromRequestCache(cacheKey) as IPublishedContent;

            if (root == null)
            {
                root = node.AncestorOrSelf(ancestorAlias);
                USNCacheHelper.AddToRequestCache(cacheKey, root);
            }

            return(root.GetProperty(propertyAlias).Value.ToString());
        }
Пример #22
0
        /// <summary>
        /// <para>Renders a sorted list of partials.</para>
        /// <para>The sortorder is based on the PartialSorter JSON configuration, merged with the PartialSorter property value.</para>
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="page">The content page to render the partial views for.</param>
        /// <param name="model">The model to pass to the partials views.</param>
        /// <param name="sorterPageId">The id of the page containing the PartialSorter property. If empty, the first found child with a document alias ending with 'settings' is used.</param>
        /// <param name="sorterPropertyAlias">The PartialSorter property alias. If empty, the first found PartialSorter is used.</param>
        /// <returns>All parsed partial views.</returns>
        public static MvcHtmlString SortedPartials(this HtmlHelper helper, IPublishedContent page, object model, int sorterPageId = 0, string sorterPropertyAlias = null)
        {
            HashSet <string> partials = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            IPublishedContent sorterPage = null;

            if (sorterPageId > 0)
            {
                sorterPage = new UmbracoHelper(UmbracoContext.Current).TypedContent(sorterPageId);
            }
            else
            {
                IPublishedContent homePage = page.AncestorOrSelf(1);
                if (homePage != null)
                {
                    sorterPage = homePage.Children.FirstOrDefault(c => c.DocumentTypeAlias.EndsWith("settings", StringComparison.OrdinalIgnoreCase));
                }
            }

            if (sorterPage != null)
            {
                if (String.IsNullOrWhiteSpace(sorterPropertyAlias))
                {
                    PublishedPropertyType propertyType = sorterPage.ContentType.PropertyTypes.FirstOrDefault(p => p.PropertyEditorAlias == Constants.PropertyEditor.Alias);

                    if (propertyType != null)
                    {
                        sorterPropertyAlias = propertyType.PropertyTypeAlias;
                    }
                }

                if (!String.IsNullOrEmpty(sorterPropertyAlias))
                {
                    GetSortedPartialsForDocumentType(sorterPage, sorterPropertyAlias, page.DocumentTypeAlias, partials);
                    MergeSortedPartialsWithDefaultConfig(sorterPage.Id, sorterPropertyAlias, page.DocumentTypeAlias, partials);
                }
            }

            StringBuilder outputBuilder = new StringBuilder();

            foreach (string partial in partials)
            {
                if (!String.IsNullOrWhiteSpace(partial))
                {
                    outputBuilder.Append(helper.Partial(partial, model));
                }
            }

            return(outputBuilder.Length > 0 ? new MvcHtmlString(outputBuilder.ToString()) : null);
        }
        public bool HasPageHero(IPublishedContent currentPage)
        {
            var isPageHeroComposition         = currentPage is IPageHeroComposition;
            var isPageHeroCarouselComposition = currentPage is IPageHeroCarouselComposition;
            var isArticulatePost = currentPage is ArticulatePost;
            var blogRoot         = currentPage.AncestorOrSelf <ArticulateModel>();
            var hasBlogRoot      = blogRoot != null;

            if (isPageHeroComposition == false && isPageHeroCarouselComposition == false && isArticulatePost == false && hasBlogRoot == false)
            {
                return(false);
            }

            if (isPageHeroComposition)
            {
                return((currentPage as IPageHeroComposition).HasPageHeroImage());
            }

            if (isArticulatePost)
            {
                var post      = (currentPage as ArticulatePost);
                var postImage = post.PostImage;

                if (postImage == null)
                {
                    return(false);
                }

                return(postImage.HasCrop("wide"));
            }
            else if (hasBlogRoot)
            {
                var blogBanner = blogRoot.BlogBanner;

                if (blogBanner == null)
                {
                    return(false);
                }

                return(blogBanner.HasCrop("wide"));
            }

            if (isPageHeroCarouselComposition)
            {
                return(ExistenceUtility.IsNullOrEmpty((currentPage as IPageHeroCarouselComposition).HeroImages) == false);
            }

            return(false);
        }
        /// <summary>
        /// Return the Website generated model (highest node) where default settings are stored.
        /// </summary>
        public static Website Website(this IPublishedContent content, bool noCache = false)
        {
            var website = (Website)System.Web.HttpContext.Current.Items["Website"];

            if (website == null || noCache)
            {
                website = content.AncestorOrSelf(1) as Website;

                if (!noCache)
                {
                    System.Web.HttpContext.Current.Items["Website"] = website;
                }
            }

            return(website);
        }
        public override object ProcessValue()
        {
            IPublishedContent currentPage = Context.Content;

            return(currentPage?
                   .AncestorOrSelf(StaticValues.DocumentTypes.Homepage)?
                   .Children
                   .Where(_contentIsVisible)
                   .Select(x => new TreeNode
            {
                Id = x.Id,
                Name = x.GetTitleOrName(StaticValues.Properties.Title),
                Url = x.GetUrl(StaticValues.DocumentTypes.Redirect, StaticValues.Properties.RedirectUrl),
                Current = x.IsAncestorOrSelf(currentPage),
                NewWindow = x.DocumentTypeAlias == StaticValues.DocumentTypes.Redirect
            }));
        }
Пример #26
0
        public BaseViewModel CreateViewModel(IPublishedContent content)
        {
            var websiteNode     = content.AncestorOrSelf(1);
            var socialItemsNode = websiteNode.GetPropertyValue <ArchetypeModel>("items");
            var socialItems     = socialItemsNode.Select(x =>
                                                         new NavSocials()
            {
                Name             = x.GetValue <string>("name"),
                FontAwesomeClass = x.GetValue <string>("fontAwesomeClass"),
                Url = x.GetValue <string>("url"),
            });

            return(new FooterViewModel
            {
                NavSocials = socialItems.ToList()
            });
        }
Пример #27
0
        public IPublishedContent GetConfiguration(Guid currentContentId, string configAlias)
        {
            string            configurationPropertyValue = string.Empty;
            IPublishedContent configurationNode          = null;

            if (umbracoHelper.TypedContent(currentContentId) != null)
            {
                IPublishedContent content              = umbracoHelper.Content(currentContentId);
                IPublishedContent homeNode             = content.AncestorOrSelf(NodeAlias.Homepage);
                IPublishedContent configCollectionNode = homeNode.Children.Where(n => n.DocumentTypeAlias == NodeAlias.Configuration).FirstOrDefault();
                if (configCollectionNode != null)
                {
                    configurationNode = configCollectionNode.Children.Where(n => n.DocumentTypeAlias == configAlias).FirstOrDefault();
                }
            }
            return(configurationNode);
        }
Пример #28
0
        public IPublishedContent GetLanding(IPublishedContent node)
        {
            string cacheKey = "GetLanding_USNBlogLanding_" + node.Id;

            var cached = USNCacheHelper.GetFromRequestCache(cacheKey) as IPublishedContent;

            if (cached != null)
            {
                return(cached);
            }

            var landing = node.AncestorOrSelf("USNBlogLandingPage");

            // cache the result
            USNCacheHelper.AddToRequestCache(cacheKey, landing);

            return(landing);
        }
Пример #29
0
        /// <summary>
        /// Gets landing node, caches result.
        /// </summary>
        /// <param name="node">A node which is a descendant of landing.</param>
        /// <returns></returns>
        public IPublishedContent GetLanding(IPublishedContent node)
        {
            string cacheKey = "GetLanding_uBlogsyLanding";

            var cached = CacheHelper.GetFromRequestCache(cacheKey) as IPublishedContent;

            if (cached != null)
            {
                return(cached);
            }

            var landing = node.AncestorOrSelf("uBlogsyLanding");

            // cache the result
            CacheHelper.AddToRequestCache(cacheKey, landing);

            return(landing);
        }
Пример #30
0
        private Dictionary <string, object> MapUmbracoContext(IPublishedContent content)
        {
            var settings =
                from child in content.AncestorOrSelf("culture")?.Children
                where child.ContentType.Alias == "settings"
                select child;

            var defaultSettings = settings.First();


            var context = new Dictionary <string, object>();

            if (defaultSettings != null)
            {
                context.Add("settings", MapUmbracoSettings(defaultSettings));
            }

            return(context);
        }
Пример #31
0
        public static SiteSettings SiteSettings(this IPublishedContent content)
        {
            IPublishedContent root = content.AncestorOrSelf(1);

            foreach (IPublishedContent child in root.Children)
            {
                RelatedLinks footerLinks = child.GetPropertyValue <RelatedLinks>(PropertyNames.FooterLinks);
                if (footerLinks == null)
                {
                    continue;
                }

                return(new SiteSettings
                {
                    FooterLinks = footerLinks.Cast <RelatedLink>().Select(x => new KeyValuePair <string, string>(x.Link, x.Caption)),
                    SiteUrl = child.GetPropertyValue <string>(PropertyNames.SiteUrl)
                });
            }

            return(null);
        }
Пример #32
0
        /// <summary>
        /// Gets landing node, caches result.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public IPublishedContent GetSiteRoot(IPublishedContent node, string rootNodeTypeAlias)
        {
            string cacheKey = "GetSiteRoot_uBlogsySiteRoot";
            string noBlogsySiteRootcacheKey = "GetSiteRoot_No_uBlogsySiteRoot";

            // this is all a little bit hacky...

            // try to get the "no site root result" from cache
            var cachedNoSiteRoot = CacheHelper.GetFromRequestCache(noBlogsySiteRootcacheKey) as string;

            if (!string.IsNullOrEmpty(cachedNoSiteRoot) && cachedNoSiteRoot == noBlogsySiteRootcacheKey)
            {
                // we've already cached the fact that there is no root.
                return(null);
            }

            // try to get the siteRoot from cache
            var cached = CacheHelper.GetFromRequestCache(cacheKey) as IPublishedContent;

            if (cached != null)
            {
                return(cached);
            }

            // try to get the site root
            var root = node.AncestorOrSelf(rootNodeTypeAlias);

            // uBlogsySiteRoot was not found, so just return null
            if (root == null)
            {
                // cache the fact that there is no site root
                CacheHelper.AddToRequestCache(noBlogsySiteRootcacheKey, noBlogsySiteRootcacheKey);
                return(null);
            }

            // cache the result
            CacheHelper.AddToRequestCache(cacheKey, root);

            return(root);
        }
Пример #33
0
        public NavigationViewModel GetSiteMap(IPublishedContent model)
        {
            if (model == null)
            {
                return(null);
            }

            var homepage = model.AncestorOrSelf <Homepage>();

            if (homepage == null)
            {
                return(null);
            }

            var siteMap = homepage?.Children?.Where(_visible);

            return(new NavigationViewModel
            {
                CurrentPage = model,
                Items = siteMap.Select(x => Map(x, model))
            });
        }
Пример #34
0
        public static IEnumerable<MenuItem> Map(IPublishedContent currentPage, bool sideNav = false)
        {
            List<MenuItem> menuItemList = new List<MenuItem>();

            MenuItem frontPage = new MenuItem();
            var siteRoot = currentPage.AncestorOrSelf(1);

            if (!siteRoot.GetPropertyValue<bool>("umbracoNaviHide"))
            {
                frontPage.Name = siteRoot.Name;
                frontPage.Url = siteRoot.Url;
                menuItemList.Add(frontPage);
            }

            foreach (var child in siteRoot.Children.Where(x => x.GetPropertyValue<bool>("showInTopMenu") == sideNav && x.GetPropertyValue<bool>("umbracoNaviHide") == false))
            {
                MenuItem menuItem = new MenuItem();
                menuItem.Name = child.Name;

                if (child.IsDocumentType("Link"))
                {
                    menuItem.OpenInNewWindow = child.GetPropertyValue<bool>("targetNewWindow");
                    menuItem.Url = child.GetPropertyValue<string>("linkUrl");
                }
                else
                {
                    menuItem.Url = child.Url;
                }
                menuItemList.Add(menuItem);
            }
            if (menuItemList.Any())
            {
                return menuItemList;
            }
            return null;
        }
Пример #35
0
 public BaseModel(IPublishedContent content)
     : base(content)
 {
     this.HomePage = content.AncestorOrSelf(1);
 }
Пример #36
0
 public static IPublishedContent SinglePageOfType(this UmbracoHelper umbraco, IPublishedContent currentPage,
     string nodeTypeAlias)
 {
     var home = currentPage.AncestorOrSelf(1);
     var xpath = String.Format("//{0}[@id={1}]//{2}",home.DocumentTypeAlias, home.Id,nodeTypeAlias);
     var node = umbraco.TypedContentSingleAtXPath(xpath);
     return node;
 }
Пример #37
0
 public static bool IsHomepageOf(IPublishedContent homepage, IPublishedContent someNode)
 {
     var someNodesHomepage = someNode.AncestorOrSelf("Homepage");
     return someNodesHomepage.Id.Equals(homepage.Id);
 }
Пример #38
0
 private List<IPublishedContent> GetFooterChildNodes(IPublishedContent node)
 {
     var homePage = node.AncestorOrSelf(1);
     var footer = homePage.Children.FirstOrDefault(content => content.DocumentTypeAlias.Equals("Footer", StringComparison.OrdinalIgnoreCase));
     if (footer == null)
         return new List<IPublishedContent>();
     return footer.Children.ToList();
 }
Пример #39
0
 public BaseModel(IPublishedContent content, CultureInfo culture)
     : base(content, culture)
 {
     this.HomePage = content.AncestorOrSelf(1);
 }