public DateTime GetLastPublishedDateByUri(string uri) { TcmUri tcmUri = new TcmUri(uri); PageMetaFactory pMetaFactory = GetPageMetaFactory(tcmUri.PublicationId); var pageInfo = pMetaFactory.GetMeta(uri); return(pageInfo?.LastPublicationDate ?? DateTime.Now); }
/// <summary> /// Get all urls of published pages /// </summary> /// <param name="includeExtensions"></param> /// <param name="pathStarts"></param> /// <param name="publicationID"></param> /// <returns></returns> public string[] GetAllPublishedPageUrls(string[] includeExtensions, string[] pathStarts) { Query pageQuery = new Query(); ItemTypeCriteria isPage = new ItemTypeCriteria(64); // TODO There must be an enum of these somewhere PublicationCriteria currentPublication = new PublicationCriteria(PublicationId); //Todo: add logic to determine site on url Criteria pageInPublication = CriteriaFactory.And(isPage, currentPublication); if (includeExtensions.Length > 0) { PageURLCriteria[] extensionsCriteria = new PageURLCriteria[includeExtensions.Length]; int criteriaCount = 0; foreach (string pageExtension in includeExtensions) { extensionsCriteria.SetValue(new PageURLCriteria("%" + pageExtension, Criteria.Like), criteriaCount); criteriaCount++; } Criteria allExtensions = CriteriaFactory.Or(extensionsCriteria); pageInPublication = CriteriaFactory.And(pageInPublication, allExtensions); } if (pathStarts.Length > 0) { PageURLCriteria[] pathCriteria = new PageURLCriteria[pathStarts.Length]; int criteriaCount = 0; foreach (string requiredPath in pathStarts) { pathCriteria.SetValue(new PageURLCriteria(requiredPath + "%", Criteria.Like), criteriaCount); criteriaCount++; } Criteria allPaths = CriteriaFactory.Or(pathCriteria); pageInPublication = CriteriaFactory.And(pageInPublication, allPaths); } Query findPages = new Query(pageInPublication); string[] pageUris = findPages.ExecuteQuery(); // Need to get PageMeta data to find all the urls List <string> pageUrls = new List <string>(); foreach (string uri in pageUris) { TcmUri tcmUri = new TcmUri(uri); PageMetaFactory metaFactory = GetPageMetaFactory(tcmUri.PublicationId); IPageMeta currentMeta = metaFactory.GetMeta(uri); pageUrls.Add(currentMeta.UrlPath); } return(pageUrls.ToArray()); }
public DateTime GetLastPublishedDateByUri(string uri) { PageMetaFactory pMetaFactory = new PageMetaFactory(PublicationId); var pageInfo = pMetaFactory.GetMeta(uri); if (pageInfo == null) { return(DateTime.Now); } else { return(pageInfo.LastPublicationDate); } }
/// <summary> /// Get all urls of published pages /// </summary> /// <param name="includeExtensions"></param> /// <param name="pathStarts"></param> /// <param name="publicationID"></param> /// <returns></returns> public string[] GetAllPublishedPageUrls(string[] includeExtensions, string[] pathStarts) { Query pageQuery = new Query(); ItemTypeCriteria isPage = new ItemTypeCriteria(64); // TODO There must be an enum of these somewhere PublicationCriteria currentPublication = new PublicationCriteria(PublicationId); //Todo: add logic to determine site on url Criteria pageInPublication = CriteriaFactory.And(isPage, currentPublication); if (includeExtensions.Length > 0) { PageURLCriteria[] extensionsCriteria = new PageURLCriteria[includeExtensions.Length]; int criteriaCount = 0; foreach (string pageExtension in includeExtensions) { extensionsCriteria.SetValue(new PageURLCriteria("%" + pageExtension, Criteria.Like), criteriaCount); criteriaCount++; } Criteria allExtensions = CriteriaFactory.Or(extensionsCriteria); pageInPublication = CriteriaFactory.And(pageInPublication, allExtensions); } if (pathStarts.Length > 0) { PageURLCriteria[] pathCriteria = new PageURLCriteria[pathStarts.Length]; int criteriaCount = 0; foreach (string requiredPath in pathStarts) { pathCriteria.SetValue(new PageURLCriteria(requiredPath + "%", Criteria.Like), criteriaCount); criteriaCount++; } Criteria allPaths = CriteriaFactory.Or(pathCriteria); pageInPublication = CriteriaFactory.And(pageInPublication, allPaths); } Query findPages = new Query(pageInPublication); string[] pageUris = findPages.ExecuteQuery(); // Need to get PageMeta data to find all the urls List<string> pageUrls = new List<string>(); PageMetaFactory metaFactory = new PageMetaFactory(PublicationId); //Todo: add logic to determine site on url foreach (string uri in pageUris) { IPageMeta currentMeta = metaFactory.GetMeta(uri); pageUrls.Add(currentMeta.UrlPath); } return pageUrls.ToArray(); }
public override PageModel GetPageModel(int pageId, ILocalization localization, bool addIncludes = true) { bool caching = ServiceCacheProvider.Instance.DisableCaching; ServiceCacheProvider.Instance.DisableCaching = true; PageModel pageModel = base.GetPageModel(pageId, localization, addIncludes); if (pageModel != null) { // Enhance the page model with custom metadata PageMetaFactory pageMetaFactory = new PageMetaFactory(int.Parse(localization.Id)); string cmId = $"ish:{localization.Id}-{pageId}-16"; var pageMeta = pageMetaFactory.GetMeta(cmId); if (pageMeta != null) { var customMeta = pageMeta.CustomMeta; // Put the information about the toc entries on the metadata // This is required by the UI so it knows the location of the page in the Toc if (customMeta.GetFirstValue(TocNaventriesMeta) != null) { NameValuePair pair = (NameValuePair)customMeta.NameValues[TocNaventriesMeta]; var values = (ArrayList)pair.MultipleValues; if (values != null) { pageModel.Meta.Add(TocNaventriesMeta, string.Join(", ", values.ToArray())); } } // Put the information about used conditions form page metadata if (customMeta.GetFirstValue(PageConditionsUsedMeta) != null) { pageModel.Meta.Add(PageConditionsUsedMeta, (string)customMeta.GetFirstValue(PageConditionsUsedMeta)); } // Add logical Ref ID information if (customMeta.GetFirstValue(RefFieldName) != null) { pageModel.Meta.Add(RefFieldName, (string)customMeta.GetFirstValue(RefFieldName)); } } } ServiceCacheProvider.Instance.DisableCaching = caching; return(pageModel); }
public static IPageMeta GetPageMetaFromSEO(HttpRequestBase request, string url) { PageMetaFactory pageMetaFactory = new PageMetaFactory(SiteGlobal.PublicationId); IPageMeta pageMeta = pageMetaFactory.GetMetaByUrl(SiteGlobal.PublicationId, url); if (pageMeta == null) { // Check if it is a Vanity URL var publicationCriteria = new PublicationCriteria(SiteGlobal.PublicationId); var pageCriteria = new ItemTypeCriteria((int)TridionItemType.Page); var vanityUrlCriteria = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("SEOUrl", Criteria.Equal), url); // -- Query query = new Query(); query.Criteria = CriteriaFactory.And(new Criteria[] { publicationCriteria, pageCriteria, vanityUrlCriteria }); IEnumerable <string> pages = query.ExecuteQuery(); //If no result, we try taking the ApplicationPath ['/en'] fro the url if (!pages.Any() && url.ToLower().StartsWith(request.ApplicationPath.ToLower())) { var urlWithoutAppPath = url.Substring(request.ApplicationPath.Length); var vanityUrlCriteria2 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("SEOUrl", Criteria.Equal), urlWithoutAppPath); query.Criteria = CriteriaFactory.And(new Criteria[] { publicationCriteria, pageCriteria, vanityUrlCriteria2 }); pages = query.ExecuteQuery(); //If no result, we try taking the '/' from the begining of the url. if (!pages.Any()) { urlWithoutAppPath = urlWithoutAppPath.TrimStart('/'); vanityUrlCriteria2 = new CustomMetaValueCriteria(new CustomMetaKeyCriteria("SEOUrl", Criteria.Equal), urlWithoutAppPath); query.Criteria = CriteriaFactory.And(new Criteria[] { publicationCriteria, pageCriteria, vanityUrlCriteria2 }); pages = query.ExecuteQuery(); } } if (pages.Any()) { pageMeta = pageMetaFactory.GetMeta(pages.First()); } } return(pageMeta); }
protected override ViewModel EnrichModel(ViewModel model) { PageModel pageModel = model as PageModel; if (pageModel == null) { return(model); } ILocalization localization = WebRequestContext.Localization; PageMetaFactory pageMetaFactory = new PageMetaFactory(localization.Id); var pageMeta = pageMetaFactory.GetMeta(pageModel.Id); if (pageMeta != null) { var customMeta = pageMeta.CustomMeta; if (customMeta.GetFirstValue(TocNaventriesMeta) != null) { // Take the generated product family name from the metadata NameValuePair tocNavEntries = (NameValuePair)customMeta.NameValues[TocNaventriesMeta]; List <string> values = (List <string>)tocNavEntries?.MultipleValues; if (values != null) { pageModel.Meta.Add(TocNaventriesMeta, string.Join(", ", values)); } } // Put the information about used conditions form page metadata if (customMeta.GetFirstValue(PageConditionsUsedMeta) != null) { pageModel.Meta.Add(PageConditionsUsedMeta, (string)customMeta.GetFirstValue(PageConditionsUsedMeta)); } // Add logical Ref ID information if (customMeta.GetFirstValue(PageLogicalRefObjectId) != null) { pageModel.Meta.Add(PageLogicalRefObjectId, (string)customMeta.GetFirstValue(PageLogicalRefObjectId)); } } return(model); }
/// <summary> /// Gets the raw string (xml) from the broker db by URI /// </summary> /// <param name="Url">TCM URI of the page</param> /// <returns>String with page xml or empty string if no page was found</returns> public string GetContentByUri(string tcmUri) { LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContentByUri({0})", LoggingCategory.Performance, tcmUri); string content = null; TcmUri tcm = new TcmUri(tcmUri); PageMetaFactory metaFactory = GetPageMetaFactory(tcm.PublicationId); PageModelRequest req = new PageModelRequest { PublicationId = tcm.PublicationId, DataModelType = DataModelType.DD4T, PageInclusion = PageInclusion.INCLUDE, Path = metaFactory.GetMeta(tcm.ItemId).UrlPath }; try { content = ModelServiceClient.PerformRequest(req).Response; } catch { } // LoggerService.Debug(">>DD4T.Providers.DxaModelService::GetContentByUrl({0}) returns {1}", LoggingCategory.Performance, tcmUri, content); return(content); }
public DateTime GetLastPublishedDateByUri(string uri) { PageMetaFactory pMetaFactory = new PageMetaFactory(PublicationId); var pageInfo = pMetaFactory.GetMeta(uri); if (pageInfo == null) { return DateTime.Now; } else { return pageInfo.LastPublicationDate; } }