/// <summary> /// Initializes a new meta data object from the specified <paramref name="site"/> and <paramref name="content"/>. /// </summary> /// <param name="site">A reference to the current site.</param> /// <param name="content">A reference the content item representing the current page.</param> public SpaMetaData(SpaSiteModel site, IPublishedContent content) { string seoTitle = content.GetString(Constants.SkyConstants.Properties.SeoTitle); string seoMetaDescription = content.GetString(Constants.SkyConstants.Properties.SeoMetaDescription); string contentName = content.Name; string contentTitleText = content.GetSpaTitle().Replace("­", "").Replace("<br />", ""); string contentTeaserText = StringUtils.StripHtml(content.GetString(Constants.SkyConstants.Properties.Teaser) ?? ""); MetaTitle = GetString(seoTitle, contentTitleText, contentName) + " - " + site.Name; MetaDescription = GetString(seoMetaDescription, contentTeaserText); // Should the page be hidden from search engines? if (HttpContext.Current.Request.Url.Host.Contains(SkyConstants.SolutionId + ".")) { HideFromSearch = true; Robots = "noindex, nofollow"; } else if (content.GetBoolean("hideFromSearch")) { HideFromSearch = true; Robots = "noindex, follow"; } else { Robots = "index, follow"; } string siteUrl = site.Content.GetSpaUrlWithDomain(); string ogTitle = content.GetString(SkyConstants.Properties.OpenGraphTitle); string ogDescription = content.GetString(SkyConstants.Properties.OpenGraphDescription); SpaImage ogImage = content.TypedMedia(SkyConstants.Properties.OpenGraphImage, SpaImage.GetFromContent) ?? content.TypedMedia(Constants.SkyConstants.Properties.Image, SpaImage.GetFromContent); OpenGraphTitle = GetString(ogTitle, contentTitleText, contentName); OpenGraphDescription = GetString(ogDescription, seoMetaDescription, contentTeaserText); OpenGraphSiteName = site.Name; OpenGraphUrl = content.GetSpaUrl(); OpenGraphImages = new List <SpaOpenGraphImage>(); if (ogImage != null) { if (ogImage.Width >= 1200 && ogImage.Height >= 630) { string cropUrl = siteUrl + ogImage.GetCropUrl(1200, 630).TrimStart('/'); OpenGraphImages.Add(new SpaOpenGraphImage(cropUrl, 1200, 630)); } else if (ogImage.Width >= 600 && ogImage.Height >= 315) { string cropUrl = siteUrl + ogImage.GetCropUrl(600, 315); OpenGraphImages.Add(new SpaOpenGraphImage(cropUrl, 600, 315)); } } }
public Master GetContent(SpaSiteModel site, IPublishedContent content) { if (content.HasProperty(SkyConstants.Properties.UmbracoInternalRedirect) && content.HasValue(SkyConstants.Properties.UmbracoInternalRedirect)) { content = new UmbracoHelper(UmbracoContext.Current).TypedContent(content.GetPropertyValue <Udi>(SkyConstants.Properties.UmbracoInternalRedirect)); } switch (content.DocumentTypeAlias) { case SkyConstants.DocumentTypes.FrontPage: return(FrontPageModel.GetFromContent(site, content)); case SkyConstants.DocumentTypes.SubPage: return(SubPageModel.GetFromContent(site, content)); default: return(null); } }
public Master(SpaSiteModel site, IPublishedContent content) { Id = content.Id; Title = content.GetSpaTitle(); Url = content.GetSpaUrl(); Meta = SpaMetaData.GetFromContent(site, content); Intro = new SpaIntro(content); Path = content.Path.Split(',').Select(x => Convert.ToInt32(x)).Skip(1).ToArray(); Template = content.GetTemplateAlias(); Culture = content.GetCulture().Name; Created = content.CreateDate; Updated = content.UpdateDate; NoCache = content.GetPropertyValue <bool>(Constants.SkyConstants.Properties.NoCache); JsonDebug = content.HasProperty(Constants.SkyConstants.Properties.JsonData) && content.HasValue(Constants.SkyConstants.Properties.JsonData) ? JObject.Parse(content.GetPropertyValue <string>(Constants.SkyConstants.Properties.JsonData).Remove(0, 1)) : null; }
public SpaContentModel(SpaSiteModel site, string appHost, string appProtocol) { AppHost = appHost; AppProtocol = appProtocol; SiteId = site.Id; }
/// <summary> /// Initializes a new meta data object from the specified <paramref name="site"/> and <paramref name="content"/>. /// </summary> /// <param name="site">A reference to the current site.</param> /// <param name="content">A reference the content item representing the current page.</param> /// <returns>An instance of <see cref="SpaMetaData"/>.</returns> public static SpaMetaData GetFromContent(SpaSiteModel site, IPublishedContent content) { return(new SpaMetaData(site, content)); }
public static SubPageModel GetFromContent(SpaSiteModel site, IPublishedContent content) { return(content == null ? null : new SubPageModel(site, content)); }
public SubPageModel(SpaSiteModel site, IPublishedContent content) : base(site, content) { }
public FrontPageModel(SpaSiteModel site, IPublishedContent content) : base(site, content) { Test = content.GetPropertyValue <string>("test"); }
public object GetData(string url = "", [FromUri] string parts = "", int navLevels = 1, bool navContext = false, int nodeId = -1, int appSiteId = -1, string appHost = "", string appProtocol = "") { // Use the current URL as fallback for "appHost" and "appProtocol" appHost = String.IsNullOrWhiteSpace(appHost) ? Request.RequestUri.Host : appHost; appProtocol = String.IsNullOrWhiteSpace(appProtocol) ? Request.RequestUri.Scheme : appProtocol; HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*"); Stopwatch watch = Stopwatch.StartNew(); HttpStatusCode statusCode = HttpStatusCode.OK; try { HttpResponseMessage response; // if nodeId exists, prefer content from that node if (nodeId > 0) { IPublishedContent c = UmbracoContext.Current.ContentCache.GetById(nodeId); if (c != null) { url = c.Url; } } // Try get siteId from domain if (appSiteId == -1 && !string.IsNullOrWhiteSpace(appHost)) { appSiteId = Domain.GetRootFromDomain(appHost); } #region Setup // Get a reference to the site node IPublishedContent site = UmbracoContext.ContentCache.GetById(appSiteId); if (site == null) { return(ReturnServerError()); } // Parse the options from the query string SpaApiRequest options = new SpaApiRequest(appSiteId, url, parts) { Protocol = appProtocol, HostName = appHost }; if (BeforeSetup(options, site, out response)) { return(response); } #region Content lookup IPublishedContent content = null; if (options.IsPreview) { // Get the ID from the request int id = url.GetPreviewId(); // Attempt to set the preview context if (SpaHelpers.SetPreviewContext(id)) { // Look up the page in the content cache (with preview enabled) content = UmbracoContext.ContentCache.GetById(true, id); } // Show the 404 page if we don't have a content page at this point if (content == null) { // Get the culture ID int cultureNodeId = GetCultureIdFromUrl(options); // Lookup the culture node in the content cache IPublishedContent cultureNode = UmbracoContext.ContentCache.GetById(cultureNodeId); // Look for a 404 page configuration on the culture node if (cultureNode != null) { content = cultureNode.TypedContent(SkyConstants.Properties.NotFoundPage); } // If we have no content at this point, we just return a simple if (content == null) { return(CreateSpaResponse(JsonMetaResponse.GetError(statusCode, "Page not found"))); } } } else { // Get a reference to the current page (fetched regardless of "parts" as the URL determines the culture) content = GetContentFromInput(site, nodeId, url); // Handle "umbracoInternalRedirectId" when present if (content != null && content.HasValue(global::Umbraco.Core.Constants.Conventions.Content.InternalRedirectId)) { content = Umbraco.TypedContent(global::Umbraco.Core.Constants.Conventions.Content.InternalRedirectId); } } #endregion #region Handle any 404/redirects URLs if (content == null) { // Got any redirects? if (HandleRedirects(options, out response)) { return(response); } // Set the status code (404) statusCode = HttpStatusCode.NotFound; // Get the culture ID int cultureNodeId = GetCultureIdFromUrl(options); // Lookup the culture node in the content cache IPublishedContent cultureNode = UmbracoContext.ContentCache.GetById(cultureNodeId); // Look for a 404 page configuration on the culture node if (cultureNode != null) { content = cultureNode.GetPropertyValue <IPublishedContent>(SkyConstants.Properties.NotFoundPage); } // If we have no content at this point, we just return a simple if (content == null) { return(CreateSpaResponse(JsonMetaResponse.GetError(statusCode, "Page not found"))); } } #endregion // If "content" matches the locale node, we get the content of the front page instead if (content.DocumentTypeAlias == SkyConstants.DocumentTypes.Culture) { content = content.FirstChild() ?? content; } // Set the current culture Thread.CurrentThread.CurrentCulture = content.GetCulture(); Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; // Initialize the main model SpaPartDataModel model = new SpaPartDataModel(appSiteId, content.Id); // Get a reference to the culture node (eg. "Dansk" or "English") IPublishedContent culture = content.AncestorOrSelf(2); // Initialize the site/culture settings SpaSiteModel siteModel = new SpaSiteModel(site, culture); #endregion #region Content if (options.Parts.Contains(SpaApiPart.Content)) { SpaContentModel spaContent = new SpaContentModel(siteModel, appHost, appProtocol); model.Content = spaContent.GetContent(siteModel, content); } #endregion #region Navigation if (options.Parts.Contains(SpaApiPart.Navigation)) { // to handle navigation right, we try to load the initial nodeId, so we dont get FirstChild on cultureNode //IPublishedContent navContent = UmbracoContext.Current.ContentCache.GetById(nodeId) ?? content; model.Navigation = new SpaNavigationModel(content, navLevels, navContext); } #endregion #region Site if (options.Parts.Contains(SpaApiPart.Site) && appSiteId > 0) { model.Site = siteModel; } #endregion watch.Stop(); model.ExecuteTimeMs = watch.ElapsedMilliseconds; return(CreateSpaResponse(statusCode, model)); } catch (Exception ex) { LogHelper.Error <SpaController>("SpaController Exception: ", ex); return(ReturnServerError()); } }