public UpdatingBlogModel(PageProperties pageProperties)
        {
            this.PageUrl = pageProperties.PageUrl;
            this.PageUrlHash = pageProperties.PageUrlHash;
            this.Title = pageProperties.Title;
            this.Description = pageProperties.Description;
            this.CustomCss = pageProperties.CustomCss;
            this.CustomJS = pageProperties.CustomJS;
            this.MetaTitle = pageProperties.MetaTitle;
            this.MetaKeywords = pageProperties.MetaKeywords;
            this.MetaDescription = pageProperties.MetaDescription;

            this.Status = pageProperties.Status;
            this.PublishedOn = pageProperties.PublishedOn;

            this.HasSEO = pageProperties.HasSEO;
            this.UseCanonicalUrl = pageProperties.UseCanonicalUrl;
            this.UseNoFollow = pageProperties.UseNoFollow;
            this.UseNoIndex = pageProperties.UseNoIndex;
            this.IsMasterPage = pageProperties.IsMasterPage;
            this.IsArchived = pageProperties.IsArchived;

            this.IsInSitemap = pageProperties.IsInSitemap;

            this.LayoutId = pageProperties.Layout != null ? pageProperties.Layout.Id : (Guid?)null;
            this.MasterPageId = pageProperties.MasterPage != null ? pageProperties.MasterPage.Id : (Guid?)null;
            this.CategoryId = pageProperties.Category != null ? pageProperties.Category.Id : (Guid?)null;
            this.MainImageId = pageProperties.Image != null ? pageProperties.Image.Id : (Guid?)null;
            this.SecondaryImageId = pageProperties.SecondaryImage != null ? pageProperties.SecondaryImage.Id : (Guid?)null;
            this.FeaturedImageId = pageProperties.FeaturedImage != null ? pageProperties.FeaturedImage.Id : (Guid?)null;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Called when page is deleted.
 /// </summary>
 public void OnPageDeleted(PageProperties page)
 {
     if (PageDeleted != null)
     {
         PageDeleted(new SingleItemEventArgs<PageProperties>(page));
     }
 }
Exemplo n.º 3
0
        protected virtual PageProperties CopyDataToDuplicate(PageProperties duplicate)
        {
            duplicate.Language = Language;
            duplicate.LanguageGroupIdentifier = null;
            duplicate.MetaTitle = MetaTitle;
            duplicate.MetaKeywords = MetaKeywords;
            duplicate.MetaDescription = MetaDescription;
            duplicate.UseCanonicalUrl = UseCanonicalUrl;
            duplicate.CustomCss = CustomCss;
            duplicate.CustomJS = CustomJS;
            duplicate.Description = Description;
            duplicate.UseNoFollow = UseNoFollow;
            duplicate.UseNoIndex = UseNoIndex;
            duplicate.Layout = Layout;
            duplicate.MasterPage = MasterPage;
            duplicate.Image = Image;
            duplicate.SecondaryImage = SecondaryImage;
            duplicate.FeaturedImage = FeaturedImage;
            duplicate.Category = Category;
            duplicate.IsArchived = IsArchived;
            duplicate.IsMasterPage = IsMasterPage;
            duplicate.ForceAccessProtocol = ForceAccessProtocol;

            return duplicate;
        }
Exemplo n.º 4
0
        protected override PageProperties CopyDataToDuplicate(PageProperties duplicate)
        {
            var blogPost = (BlogPost)base.CopyDataToDuplicate(duplicate);

            blogPost.Author = Author;

            return blogPost;
        }
Exemplo n.º 5
0
        protected override PageProperties CopyDataToDuplicate(PageProperties duplicate)
        {
            var blogPost = (BlogPost)base.CopyDataToDuplicate(duplicate);

            blogPost.Author = Author;
            blogPost.ActivationDate = ActivationDate;
            blogPost.ExpirationDate = ExpirationDate;

            return blogPost;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SavePageResponse" /> class.
 /// </summary>
 /// <param name="page">The page.</param>
 public SavePageResponse(PageProperties page)
 {
     PageId = page.Id;
     Title = page.Title;
     CreatedOn = page.CreatedOn.ToFormattedDateString();
     ModifiedOn = page.ModifiedOn.ToFormattedDateString();
     PageStatus = page.Status;
     HasSEO = ((IPage)page).HasSEO;
     PageUrl = page.PageUrl;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SavePageResponse" /> class.
 /// </summary>
 /// <param name="page">The page.</param>
 public SavePageResponse(PageProperties page)
 {
     PageId = page.Id;
     Title = page.Title;
     CreatedOn = page.CreatedOn.ToString(CultureInfo.CurrentCulture);
     ModifiedOn = page.ModifiedOn.ToString(CultureInfo.CurrentCulture);
     IsPublished = page.IsPublished;
     HasSEO = ((IPage)page).HasSEO;
     PageUrl = page.PageUrl;
 }
        private void RunTest()
        {
            // Attach to events
            Events.PageEvents.Instance.PageContentInserted   += Instance_EntityCreated;
            Events.PageEvents.Instance.PageContentSorted     += Instance_EntityUpdated;
            Events.PageEvents.Instance.PageContentConfigured += Instance_PageContentConfigured;
            Events.PageEvents.Instance.PageContentDeleted    += Instance_EntityDeleted;
            contentConfigredCount = 0;

            RunApiActionInTransaction(
                (api, session) =>
            {
                page = TestDataProvider.CreateNewPageProperties();
                session.SaveOrUpdate(page);

                Run(session, api.Pages.Page.Content.Post, api.Pages.Page.Content.Get, api.Pages.Page.Content.Put, api.Pages.Page.Content.Delete);
            });

            // Detach from events
            Events.PageEvents.Instance.PageContentInserted   -= Instance_EntityCreated;
            Events.PageEvents.Instance.PageContentSorted     -= Instance_EntityUpdated;
            Events.PageEvents.Instance.PageContentConfigured -= Instance_PageContentConfigured;
            Events.PageEvents.Instance.PageContentDeleted    -= Instance_EntityDeleted;
        }
Exemplo n.º 9
0
        protected virtual PageProperties CopyDataToDuplicate(PageProperties duplicate)
        {
            duplicate.Language = Language;
            duplicate.LanguageGroupIdentifier = null;
            duplicate.MetaTitle           = MetaTitle;
            duplicate.MetaKeywords        = MetaKeywords;
            duplicate.MetaDescription     = MetaDescription;
            duplicate.UseCanonicalUrl     = UseCanonicalUrl;
            duplicate.CustomCss           = CustomCss;
            duplicate.CustomJS            = CustomJS;
            duplicate.Description         = Description;
            duplicate.UseNoFollow         = UseNoFollow;
            duplicate.UseNoIndex          = UseNoIndex;
            duplicate.Layout              = Layout;
            duplicate.MasterPage          = MasterPage;
            duplicate.Image               = Image;
            duplicate.SecondaryImage      = SecondaryImage;
            duplicate.FeaturedImage       = FeaturedImage;
            duplicate.IsArchived          = IsArchived;
            duplicate.IsMasterPage        = IsMasterPage;
            duplicate.ForceAccessProtocol = ForceAccessProtocol;

            return(duplicate);
        }
Exemplo n.º 10
0
        private void AddAccessRules(PageProperties newPage, IEnumerable<IAccessRule> userAccess)
        {
            if (userAccess == null)
            {
                return;
            }

            newPage.AccessRules = new List<AccessRule>();
            foreach (var rule in userAccess)
            {
                newPage.AccessRules.Add(new AccessRule
                {
                    Identity = rule.Identity,
                    AccessLevel = rule.AccessLevel,
                    IsForRole = rule.IsForRole
                });
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Clones the content of the page.
        /// </summary>
        /// <param name="pageContent">Content of the page.</param>
        /// <param name="newPage">The new page.</param>
        private void ClonePageContent(PageContent pageContent, PageProperties newPage)
        {
            var newPageContent = new PageContent();
            newPageContent.Page = newPage;
            newPageContent.Order = pageContent.Order;
            newPageContent.Region = pageContent.Region;

            if (pageContent.Content is HtmlContentWidget || pageContent.Content is ServerControlWidget)
            {
                // Do not need to clone widgets.
                newPageContent.Content = pageContent.Content;
            }
            else
            {
                newPageContent.Content = pageContent.Content.Clone();

                var draft = pageContent.Content.History.FirstOrDefault(c => c.Status == ContentStatus.Draft && !c.IsDeleted);
                if (pageContent.Content.Status == ContentStatus.Published && draft != null)
                {
                    if (newPageContent.Content.History == null)
                    {
                        newPageContent.Content.History = new List<Root.Models.Content>();
                    }

                    var draftClone = draft.Clone();
                    draftClone.Original = newPageContent.Content;
                    newPageContent.Content.History.Add(draftClone);
                    repository.Save(draftClone);
                }
            }

            // Clone page content options.
            foreach (var option in pageContent.Options.Distinct())
            {
                if (newPageContent.Options == null)
                {
                    newPageContent.Options = new List<PageContentOption>();
                }

                var newOption = new PageContentOption
                {
                    Key = option.Key,
                    Value = option.Value,
                    Type = option.Type,
                    PageContent = newPageContent,
                    CustomOption = option.CustomOption
                };
                newPageContent.Options.Add(newOption);
                repository.Save(newOption);
            }

            repository.Save(newPageContent);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the page translation from page translations list, which is most compatible with node translation:
        /// if page translation exists, take page translations
        /// if page translation does not exist, take default language translation
        /// if default language translation does not exist, take node's data
        /// </summary>
        /// <param name="pageTranslations">The page translations.</param>
        /// <param name="nodeLanguage">The node language.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        private PageTranslationViewModel GetPageTranslation(IEnumerable<PageTranslationViewModel> pageTranslations, Guid nodeLanguage, SitemapNode node, Page page)
        {
            var pageTranslation = pageTranslations.FirstOrDefault(p => p.LanguageId == nodeLanguage);

            if (pageTranslation == null)
            {
                pageTranslation = pageTranslations.FirstOrDefault(p => !p.LanguageId.HasValue);
            }

            if (pageTranslation == null && page != null)
            {
                pageTranslation = new PageTranslationViewModel
                                  {
                                      Title = page.Title,
                                      PageUrl = page.PageUrl,
                                      PageUrlHash = page.PageUrlHash
                                  };
            }

            if (pageTranslation == null)
            {
                pageTranslation = new PageTranslationViewModel
                                  {
                                      Title = node.Title,
                                      PageUrl = node.Url,
                                      PageUrlHash = node.UrlHash
                                  };
            }

            return pageTranslation;
        }
Exemplo n.º 13
0
 private void CloneCategories(PageCategory category, PageProperties newPage)
 {
     var newPageCategory = new PageCategory
     {
         Page = newPage,
         Category = category.Category
     };
     repository.Save(newPageCategory);
 }
Exemplo n.º 14
0
        private void ValidateCloningPage(PageProperties page, System.Guid? languageId, System.Guid? languageGroupIdentifier)
        {
            // Validate request, if cloning page with language
            if (languageGroupIdentifier.HasValue)
            {
                var query = repository.AsQueryable<Page>().Where(p => p.LanguageGroupIdentifier == languageGroupIdentifier);
                if (languageId.HasValue && !languageId.Value.HasDefaultValue())
                {
                    var language = repository.AsProxy<Language>(languageId.Value);
                    query = query.Where(p => p.Language == language);
                }
                else
                {
                    query = query.Where(p => p.Language == null);
                }

                if (query.Any())
                {
                    var logMessage = string.Format("Page already has translations for language. Id: {0}, LanguageId: {1}", page.Id, languageId);
                    throw new ValidationException(() => PagesGlobalization.ClonePageWithLanguage_PageAlreadyHasSuchTranslation_Message, logMessage);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the page translation from page translations list, which is most compatible with node translation:
        /// if page translation exists, take page translations
        /// if page translation does not exist, take default language translation
        /// if default language translation does not exist, take node's data
        /// </summary>
        /// <param name="pageTranslations">The page translations.</param>
        /// <param name="nodeLanguage">The node language.</param>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        private PageTranslationViewModel GetPageTranslation(IEnumerable <PageTranslationViewModel> pageTranslations, Guid nodeLanguage, SitemapNode node, Page page)
        {
            var pageTranslation = pageTranslations.FirstOrDefault(p => p.LanguageId == nodeLanguage);

            if (pageTranslation == null)
            {
                pageTranslation = pageTranslations.FirstOrDefault(p => !p.LanguageId.HasValue);
            }

            if (pageTranslation == null && page != null)
            {
                pageTranslation = new PageTranslationViewModel
                {
                    Title       = page.Title,
                    PageUrl     = page.PageUrl,
                    PageUrlHash = page.PageUrlHash
                };
            }

            if (pageTranslation == null)
            {
                pageTranslation = new PageTranslationViewModel
                {
                    Title       = node.Title,
                    PageUrl     = node.Url,
                    PageUrlHash = node.UrlHash
                };
            }

            return(pageTranslation);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SavePageResponse" /> class.
 /// </summary>
 /// <param name="page">The page.</param>
 public SavePageResponse(PageProperties page)
 {
     PageId = page.Id;
     Title = page.Title;
     CreatedOn = page.CreatedOn.ToFormattedDateString();
     ModifiedOn = page.ModifiedOn.ToFormattedDateString();
     PageStatus = page.Status;
     HasSEO = ((IPage)page).HasSEO;
     PageUrl = page.PageUrl;
     IsArchived = page.IsArchived;
     IsMasterPage = page.IsMasterPage;
     LanguageId = page.Language != null ? page.Language.Id : (Guid?)null;
 }
Exemplo n.º 17
0
        private void AddAccessRules(PageProperties newPage, IEnumerable<IAccessRule> userAccess)
        {
            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                accessControlService.UpdateAccessControl(newPage, userAccess != null ? userAccess.ToList() : new List<IAccessRule>());
            }
            else
            {
                if (userAccess == null)
                {
                    return;
                }

                newPage.AccessRules = new List<AccessRule>();
                foreach (var rule in userAccess)
                {
                    newPage.AccessRules.Add(new AccessRule
                    {
                        Identity = rule.Identity,
                        AccessLevel = rule.AccessLevel,
                        IsForRole = rule.IsForRole
                    });
                }
            }
        }
Exemplo n.º 18
0
 public PageJavaScriptAccessor(PageProperties page)
 {
     this.page = page;
 }
Exemplo n.º 19
0
        private void ClonePageOption(PageOption pageOption, PageProperties newPage)
        {
            var newPageOption = new PageOption
            {
                Key = pageOption.Key,
                Type = pageOption.Type,
                Value = pageOption.Value,
                Page = newPage,
                CustomOption = pageOption.CustomOption
            };

            if (newPage.Options == null)
            {
                newPage.Options = new List<PageOption>();
            }

            newPage.Options.Add(newPageOption);
            repository.Save(newPageOption);
        }
Exemplo n.º 20
0
        private void CloneMasterPages(MasterPage masterPage, PageProperties newPage)
        {
            var newMasterPage = new MasterPage
            {
                Master = masterPage.Master,
                Page = newPage
            };

            if (newPage.MasterPages == null)
            {
                newPage.MasterPages = new List<MasterPage>();
            }

            newPage.MasterPages.Add(newMasterPage);
            repository.Save(newMasterPage);
        }
Exemplo n.º 21
0
        protected virtual PageProperties CopyDataToDuplicate(PageProperties duplicate)
        {
            duplicate.MetaTitle = MetaTitle;
            duplicate.MetaKeywords = MetaKeywords;
            duplicate.MetaDescription = MetaDescription;
            duplicate.IsPublic = IsPublic;
            duplicate.UseCanonicalUrl = UseCanonicalUrl;
            duplicate.CustomCss = CustomCss;
            duplicate.CustomJS = CustomJS;
            duplicate.Description = Description;
            duplicate.UseNoFollow = UseNoFollow;
            duplicate.UseNoIndex = UseNoIndex;
            duplicate.Layout = Layout;
            duplicate.Image = Image;
            duplicate.Category = Category;

            return duplicate;
        }
Exemplo n.º 22
0
        private static void AddPageContent(PagesApiContext pagesApi, PageProperties page, HtmlContentWidget header, HtmlContentWidget footer, string mainHtml)
        {
            pagesApi.AddHtmlContentWidgetToPage(new AddWidgetToPageRequest() { PageId = page.Id, ContentId = header.Id, RegionIdentifier = Template.Regions.Header });
            pagesApi.AddHtmlContentWidgetToPage(new AddWidgetToPageRequest() { PageId = page.Id, ContentId = footer.Id, RegionIdentifier = Template.Regions.Footer });

            var contentRequest = new CreatePageHtmlContentRequest()
            {
                PageId = page.Id,
                RegionIdentifier = Template.Regions.Main,
                Name = "Main Content",
                Html = mainHtml,
                ContentStatus = ContentStatus.Published
            };
            pagesApi.CreatePageHtmlContent(contentRequest);
        }
 public PageJavaScriptAccessor(PageProperties page, IEnumerable<IOptionValue> options)
 {
     this.page = page;
     this.options = options;
 }
        public void SetMasterOrLayout(PageProperties page, Guid? masterPageId, Guid? layoutId)
        {
            if (masterPageId.HasValue)
            {
                if (page.MasterPage == null || page.MasterPage.Id != masterPageId.Value)
                {
                    page.MasterPage = repository.AsProxy<Page>(masterPageId.Value);
                }

                page.Layout = null;
            }
            else if (layoutId.HasValue)
            {
                if (page.Layout == null || page.Layout.Id != layoutId.Value)
                {
                    page.Layout = repository.AsProxy<Layout>(layoutId.Value);
                }

                page.MasterPage = null;
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Puts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns><c>PutPageResponse</c> with created or updated item id.</returns>
        public PutPagePropertiesResponse Put(PutPagePropertiesRequest request)
        {
            if (request.Data.IsMasterPage)
            {
                accessControlService.DemandAccess(securityService.GetCurrentPrincipal(), RootModuleConstants.UserRoles.Administration);
            }
            else
            {
                accessControlService.DemandAccess(securityService.GetCurrentPrincipal(), RootModuleConstants.UserRoles.EditContent);
            }

            PageProperties pageProperties = null;

            var isNew = !request.Id.HasValue || request.Id.Value.HasDefaultValue();

            if (!isNew)
            {
                pageProperties =
                    repository.AsQueryable<PageProperties>(e => e.Id == request.Id.GetValueOrDefault())
                        .FetchMany(p => p.Options)
                        .Fetch(p => p.Layout)
                        .ThenFetchMany(l => l.LayoutOptions)
                        .FetchMany(p => p.MasterPages)
                        .FetchMany(f => f.AccessRules)
                        .ToList()
                        .FirstOrDefault();

                isNew = pageProperties == null;
            }
            UpdatingPagePropertiesModel beforeChange = null;
            if (isNew)
            {
                pageProperties = new PageProperties
                                     {
                                         Id = request.Id.GetValueOrDefault(),
                                         Status = PageStatus.Unpublished,
                                         AccessRules = new List<AccessRule>()
                                     };
            }
            else if (request.Data.Version > 0)
            {
                pageProperties.Version = request.Data.Version;
            }

            if (!isNew)
            {
                beforeChange = new UpdatingPagePropertiesModel(pageProperties);
            }

            if (!isNew && pageProperties.IsMasterPage != request.Data.IsMasterPage)
            {
                const string message = "IsMasterPage cannot be changed for updating page. It can be modified only when creating a page.";
                var logMessage = string.Format("{0} PageId: {1}", message, request.Id);
                throw new ValidationException(() => message, logMessage);
            }

            // Load master pages for updating page's master path and page's children master path
            IList<Guid> newMasterIds;
            IList<Guid> oldMasterIds;
            IList<Guid> childrenPageIds;
            IList<MasterPage> existingChildrenMasterPages;
            masterPageService.PrepareForUpdateChildrenMasterPages(pageProperties, request.Data.MasterPageId, out newMasterIds, out oldMasterIds, out childrenPageIds, out existingChildrenMasterPages);

            unitOfWork.BeginTransaction();

            if (!string.IsNullOrEmpty(request.Data.PageUrl) || string.IsNullOrEmpty(pageProperties.PageUrl))
            {
                var pageUrl = request.Data.PageUrl;
                if (string.IsNullOrEmpty(pageUrl) && !string.IsNullOrWhiteSpace(request.Data.Title))
                {
                    pageUrl = pageService.CreatePagePermalink(request.Data.Title, null, null, request.Data.LanguageId, request.Data.Categories);
                }
                else
                {
                    pageUrl = urlService.FixUrl(pageUrl);
                    pageService.ValidatePageUrl(pageUrl, request.Id);
                }

                pageProperties.PageUrl = pageUrl;
                pageProperties.PageUrlHash = pageUrl.UrlHash();
            }

            pageProperties.Title = request.Data.Title;
            pageProperties.Description = request.Data.Description;

            var newStatus = request.Data.IsMasterPage || request.Data.IsPublished ? PageStatus.Published : PageStatus.Unpublished;
            if (!request.Data.IsMasterPage && pageProperties.Status != newStatus)
            {
                accessControlService.DemandAccess(securityService.GetCurrentPrincipal(), RootModuleConstants.UserRoles.PublishContent);
            }

            pageProperties.Status = newStatus;
            pageProperties.PublishedOn = request.Data.IsPublished && !request.Data.PublishedOn.HasValue ? DateTime.Now : request.Data.PublishedOn;

            masterPageService.SetMasterOrLayout(pageProperties, request.Data.MasterPageId, request.Data.LayoutId);

            categoryService.CombineEntityCategories<PageProperties, PageCategory>(pageProperties, request.Data.Categories);

            pageProperties.IsArchived = request.Data.IsArchived;
            pageProperties.IsMasterPage = request.Data.IsMasterPage;
            pageProperties.LanguageGroupIdentifier = request.Data.LanguageGroupIdentifier;
            pageProperties.ForceAccessProtocol = (Core.DataContracts.Enums.ForceProtocolType)(int)request.Data.ForceAccessProtocol;
            pageProperties.Language = request.Data.LanguageId.HasValue && !request.Data.LanguageId.Value.HasDefaultValue()
                                    ? repository.AsProxy<Language>(request.Data.LanguageId.Value)
                                    : null;

            pageProperties.Image = request.Data.MainImageId.HasValue
                                    ? repository.AsProxy<MediaImage>(request.Data.MainImageId.Value)
                                    : null;
            pageProperties.FeaturedImage = request.Data.FeaturedImageId.HasValue
                                    ? repository.AsProxy<MediaImage>(request.Data.FeaturedImageId.Value)
                                    : null;
            pageProperties.SecondaryImage = request.Data.SecondaryImageId.HasValue
                                    ? repository.AsProxy<MediaImage>(request.Data.SecondaryImageId.Value)
                                    : null;

            pageProperties.CustomCss = request.Data.CustomCss;
            pageProperties.CustomJS = request.Data.CustomJavaScript;
            pageProperties.UseCanonicalUrl = request.Data.UseCanonicalUrl;
            pageProperties.UseNoFollow = request.Data.UseNoFollow;
            pageProperties.UseNoIndex = request.Data.UseNoIndex;

            if (request.Data.MetaData != null)
            {
                pageProperties.MetaTitle = request.Data.MetaData.MetaTitle;
                pageProperties.MetaDescription = request.Data.MetaData.MetaDescription;
                pageProperties.MetaKeywords = request.Data.MetaData.MetaKeywords;
            }

            IList<Tag> newTags = null;
            if (request.Data.Tags != null)
            {
                tagService.SavePageTags(pageProperties, request.Data.Tags, out newTags);
            }

            if (request.Data.AccessRules != null)
            {
                pageProperties.AccessRules.RemoveDuplicateEntities();
                var accessRules =
                    request.Data.AccessRules.Select(
                        r => (IAccessRule)new AccessRule { AccessLevel = (Core.Security.AccessLevel)(int)r.AccessLevel, Identity = r.Identity, IsForRole = r.IsForRole })
                        .ToList();
                accessControlService.UpdateAccessControl(pageProperties, accessRules);
            }

            if (request.Data.PageOptions != null)
            {
                var options = request.Data.PageOptions.ToServiceModel();

                var pageOptions = pageProperties.Options != null ? pageProperties.Options.Distinct() : null;
                pageProperties.Options = optionService.SaveOptionValues(options, pageOptions, () => new PageOption { Page = pageProperties });
            }

            if (!isNew)
            {
                // Notify about page properties changing.
                var cancelEventArgs = Events.PageEvents.Instance.OnPagePropertiesChanging(beforeChange, new UpdatingPagePropertiesModel(pageProperties));
                if (cancelEventArgs.Cancel)
                {
                    throw new CmsApiValidationException(
                        cancelEventArgs.CancellationErrorMessages != null && cancelEventArgs.CancellationErrorMessages.Count > 0
                            ? string.Join(",", cancelEventArgs.CancellationErrorMessages)
                            : "Page properties saving was canceled.");
                }
            }

            repository.Save(pageProperties);

            //
            // If creating new page, page id is unknown when children pages are loaded, so Guid may be empty
            // Updating id to saved page's Id manually
            //
            if (isNew && childrenPageIds != null && childrenPageIds.Count == 1 && childrenPageIds[0].HasDefaultValue())
            {
                childrenPageIds[0] = pageProperties.Id;
            }

            masterPageService.UpdateChildrenMasterPages(existingChildrenMasterPages, oldMasterIds, newMasterIds, childrenPageIds);

            unitOfWork.Commit();

            // Fire events.
            Events.RootEvents.Instance.OnTagCreated(newTags);
            if (isNew)
            {
                Events.PageEvents.Instance.OnPageCreated(pageProperties);
            }
            else
            {
                Events.PageEvents.Instance.OnPagePropertiesChanged(pageProperties);
            }

            return new PutPagePropertiesResponse { Data = pageProperties.Id };
        }
Exemplo n.º 26
0
        /// <summary>
        /// Saves the page tags.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="tags">The tags.</param>
        /// <param name="newCreatedTags">The new created tags.</param>
        public void SavePageTags(PageProperties page, IList<string> tags, out IList<Tag> newCreatedTags)
        {
            var trimmedTags = new List<string>();
            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    trimmedTags.Add(tag.Trim());
                }
            }

            newCreatedTags = new List<Tag>();

            Tag tagAlias = null;

            // Tags merge:
            IList<PageTag> pageTags = unitOfWork.Session
                .QueryOver<PageTag>()
                .Where(t => !t.IsDeleted && t.Page.Id == page.Id)
                .JoinQueryOver<Tag>(t => t.Tag, JoinType.InnerJoin)
                .Where(t => !t.IsDeleted)
                .List<PageTag>();

            // Remove deleted tags:
            for (int i = pageTags.Count - 1; i >= 0; i--)
            {
                string tag = null;
                tag = trimmedTags.FirstOrDefault(s => s.ToLower() == pageTags[i].Tag.Name.ToLower());

                if (tag == null)
                {
                    unitOfWork.Session.Delete(pageTags[i]);
                }
            }

            // Add new tags:
            List<string> tagsInsert = new List<string>();
            foreach (string tag in trimmedTags)
            {
                PageTag existPageTag = pageTags.FirstOrDefault(pageTag => pageTag.Tag.Name.ToLower() == tag.ToLower());
                if (existPageTag == null)
                {
                    tagsInsert.Add(tag);
                }
            }

            if (tagsInsert.Count > 0)
            {
                // Get existing tags:
                IList<Tag> existingTags = unitOfWork.Session.QueryOver(() => tagAlias)
                                                            .Where(t => !t.IsDeleted)
                                                            .Where(Restrictions.In(Projections.Property(() => tagAlias.Name), tagsInsert))
                                                            .List<Tag>();

                foreach (string tag in tagsInsert)
                {
                    PageTag pageTag = new PageTag();
                    pageTag.Page = page;

                    Tag existTag = existingTags.FirstOrDefault(t => t.Name.ToLower() == tag.ToLower());
                    if (existTag != null)
                    {
                        pageTag.Tag = existTag;
                    }
                    else
                    {
                        Tag newTag = new Tag();
                        newTag.Name = tag;
                        unitOfWork.Session.SaveOrUpdate(newTag);
                        newCreatedTags.Add(newTag);
                        pageTag.Tag = newTag;
                    }

                    unitOfWork.Session.SaveOrUpdate(pageTag);
                }
            }
        }
        /// <summary>
        /// Retrieves all the master page children, when master page is changed.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="updatingIds">The updating ids.</param>
        /// <param name="childrenPageIds">The children page ids.</param>
        /// <returns>
        /// List of all the childer master pages, which must be changed.
        /// </returns>
        private List<MasterPage> GetChildrenMasterPagesToUpdate(PageProperties page, IList<Guid> updatingIds, out IList<Guid> childrenPageIds)
        {
            // Retrieve all master pages, refering old master and master, which include updating page also as master page
            var query = repository.AsQueryable<MasterPage>().Where(mp => mp.Page.MasterPages.Any(mp1 => mp1.Master.Id == page.Id) || mp.Page.Id == page.Id);

            childrenPageIds = query.Select(mp => mp.Page.Id).Distinct().ToList();
            if (!childrenPageIds.Contains(page.Id))
            {
                childrenPageIds.Add(page.Id);
            }

            return query.Where(mp => updatingIds.Contains(mp.Master.Id)).ToList();
        }
Exemplo n.º 28
0
        /// <summary>
        /// Updates page sitemap nodes.
        /// </summary>
        private void UpdateSitemapNodes(DeletePageViewModel model, PageProperties page, IList<SitemapNode> sitemapNodes, Dictionary<Sitemap, bool> sitemaps,
            List<Language> languages, IList<SitemapNode> updatedNodes, IList<SitemapNode> deletedNodes)
        {
            if (sitemapNodes != null)
            {
                // Archive sitemaps before update.
                sitemaps.Select(pair => pair.Key).ToList().ForEach(sitemap => sitemapService.ArchiveSitemap(sitemap.Id));
                foreach (var node in sitemapNodes)
                {
                    if (!node.IsDeleted)
                    {
                        if (model.UpdateSitemap && sitemaps[node.Sitemap])
                        {
                            // Delete sitemap node.
                            sitemapService.DeleteNode(node, ref deletedNodes);
                        }
                        else
                        {
                            // Unlink sitemap node.
                            if (node.Page != null && node.Page.Id == page.Id)
                            {
                                node.Page = null;
                                node.Title = node.UsePageTitleAsNodeTitle ? page.Title : node.Title;
                                node.Url = page.PageUrl;
                                node.UrlHash = page.PageUrlHash;
                                repository.Save(node);
                                updatedNodes.Add(node);

                                IEnumerable<PageTranslationViewModel> pageTranslations;
                                if (page.LanguageGroupIdentifier.HasValue && !page.LanguageGroupIdentifier.Value.HasDefaultValue())
                                {
                                    pageTranslations = GetPageTranslations(page.LanguageGroupIdentifier.Value);
                                }
                                else
                                {
                                    pageTranslations = new PageTranslationViewModel[0];
                                }

                                // Assigned node URL and title is taken from default language, if such exists.
                                var defaultPageTranslation = pageTranslations.FirstOrDefault(p => !p.LanguageId.HasValue);
                                if (defaultPageTranslation != null)
                                {
                                    node.Url = defaultPageTranslation.PageUrl;
                                    node.UrlHash = defaultPageTranslation.PageUrlHash;
                                    if (node.UsePageTitleAsNodeTitle)
                                    {
                                        node.Title = defaultPageTranslation.Title;
                                    }
                                }

                                // Update sitemap node translations.
                                if (node.Translations == null)
                                {
                                    node.Translations = new List<SitemapNodeTranslation>();
                                }

                                node.Translations.ForEach(
                                    t =>
                                    {
                                        var pageTranslation = GetPageTranslation(pageTranslations, t.Language.Id, node, page);
                                        if (t.UsePageTitleAsNodeTitle)
                                        {
                                            t.Title = pageTranslation.Title;
                                        }

                                        t.UsePageTitleAsNodeTitle = false;
                                        t.Url = pageTranslation.PageUrl;
                                        t.UrlHash = pageTranslation.PageUrlHash;
                                    });

                                // Create non-existing node translations for each language.
                                languages.Where(language => node.Translations.All(nt => nt.Language.Id != language.Id))
                                    .ForEach(language =>
                                    {
                                        var pageTranslation = GetPageTranslation(pageTranslations, language.Id, node, page);

                                        var nodeTranslation = new SitemapNodeTranslation
                                            {
                                                Language = language,
                                                Node = node,
                                                UsePageTitleAsNodeTitle = false,
                                                Title = pageTranslation.Title,
                                                Url = pageTranslation.PageUrl,
                                                UrlHash = pageTranslation.PageUrlHash
                                            };

                                        node.Translations.Add(nodeTranslation);
                                    });
                            }
                        }
                    }
                }
            }
        }
        public void PrepareForUpdateChildrenMasterPages(PageProperties page, Guid? masterPageId, out IList<Guid> newMasterIds, out IList<Guid> oldMasterIds, out IList<Guid> childrenPageIds, out IList<MasterPage>  existingChildrenMasterPages)
        {
            if ((page.MasterPage != null && page.MasterPage.Id != masterPageId) || (page.MasterPage == null && masterPageId.HasValue))
            {
                newMasterIds = masterPageId.HasValue ? GetPageMasterPageIds(masterPageId.Value) : new List<Guid>(0);

                oldMasterIds = page.MasterPage != null && page.MasterPages != null ? page.MasterPages.Select(mp => mp.Master.Id).Distinct().ToList() : new List<Guid>(0);

                var intersectingIds = newMasterIds.Intersect(oldMasterIds).ToArray();
                foreach (var id in intersectingIds)
                {
                    oldMasterIds.Remove(id);
                    newMasterIds.Remove(id);
                }

                var updatingIds = newMasterIds.Union(oldMasterIds).Distinct().ToList();
                existingChildrenMasterPages = GetChildrenMasterPagesToUpdate(page, updatingIds, out childrenPageIds);
            }
            else
            {
                newMasterIds = null;
                oldMasterIds = null;
                childrenPageIds = null;
                existingChildrenMasterPages = null;
            }
        }
        private PageProperties[] CreateNestedOptions(ISession session, int level)
        {
            var pages = new PageProperties[3];

            // Create layout and options
            var layout = TestDataProvider.CreateNewLayout();

            var lo1 = TestDataProvider.CreateNewLayoutOption(layout);
            lo1.Type = OptionType.Text;
            lo1.Key = "l1";
            lo1.DefaultValue = "l1";

            var lo2 = TestDataProvider.CreateNewLayoutOption(layout);
            lo2.Type = OptionType.Text;
            lo2.Key = "l2";
            lo2.DefaultValue = "l2";

            var lo3 = TestDataProvider.CreateNewLayoutOption(layout);
            lo3.Type = OptionType.Text;
            lo3.Key = "l3";
            lo3.DefaultValue = "l3";

            layout.LayoutOptions = new List<LayoutOption> { lo1, lo2, lo3 };
            session.SaveOrUpdate(layout);

            // Create Master page
            var page1 = TestDataProvider.CreateNewPageProperties(layout);

            var o11 = TestDataProvider.CreateNewPageOption(page1);
            o11.Type = OptionType.Text;
            o11.Key = "p1";
            o11.Value = "p1";

            var o12 = TestDataProvider.CreateNewPageOption(page1);
            o12.Type = OptionType.Text;
            o12.Key = "l3";
            o12.Value = "l3p1";

            page1.Options = new List<PageOption> { o11, o12 };
            session.SaveOrUpdate(page1);
            pages[0] = page1;

            if (level > 1)
            {
                // Create First Child With Options
                var page2 = TestDataProvider.CreateNewPageProperties();
                page2.Layout = null;
                page2.MasterPage = page1;

                var o21 = TestDataProvider.CreateNewPageOption(page2);
                o21.Type = OptionType.Text;
                o21.Key = "p2";
                o21.Value = "p2";

                var o22 = TestDataProvider.CreateNewPageOption(page2);
                o22.Type = OptionType.Text;
                o22.Key = "l3";
                o22.Value = "l3p2";

                var o23 = TestDataProvider.CreateNewPageOption(page2);
                o23.Type = OptionType.Text;
                o23.Key = "l2";
                o23.Value = "l2p2";

                page2.Options = new List<PageOption> { o21, o22, o23 };
                session.SaveOrUpdate(page2);
                pages[1] = page2;

                var master21 = new MasterPage { Page = page2, Master = page1 };
                session.SaveOrUpdate(master21);

                if (level > 2)
                {
                    // Create Second Child With Options
                    var page3 = TestDataProvider.CreateNewPageProperties();
                    page3.Layout = null;
                    page3.MasterPage = page2;

                    var o31 = TestDataProvider.CreateNewPageOption(page3);
                    o31.Type = OptionType.Text;
                    o31.Key = "l3";
                    o31.Value = "l3p3";

                    page3.Options = new List<PageOption> { o31 };
                    session.SaveOrUpdate(page3);
                    pages[2] = page3;

                    var master31 = new MasterPage { Page = page3, Master = page1 };
                    session.SaveOrUpdate(master31);
                    var master32 = new MasterPage { Page = page3, Master = page2 };
                    session.SaveOrUpdate(master32);
                }
            }

            session.Flush();
            session.Clear();

            return pages;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Clones the page tags.
        /// </summary>
        /// <param name="pageTag">The page tag.</param>
        /// <param name="newPage">The new page.</param>
        private void ClonePageTags(PageTag pageTag, PageProperties newPage)
        {
            var newPageHtmlControl = new PageTag
            {
                Page = newPage,
                Tag = pageTag.Tag
            };

            repository.Save(newPageHtmlControl);
        }
 public PageStylesheetAccessor(PageProperties page, IEnumerable<IOptionValue> options)
 {
     this.page = page;
     this.options = options;
 }
Exemplo n.º 33
0
        /// <summary>
        /// Clones the page only.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="userAccess">The user access.</param>
        /// <param name="newPageTitle">The new page title.</param>
        /// <param name="newPageUrl">The new page URL.</param>
        /// <param name="cloneAsMasterPage">if set to <c>true</c> clone page as master page.</param>
        /// <returns>
        /// Copy for <see cref="PageProperties" />.
        /// </returns>
        private PageProperties ClonePageOnly(PageProperties page, IEnumerable<IAccessRule> userAccess, string newPageTitle, string newPageUrl, bool cloneAsMasterPage)
        {
            var newPage = page.Duplicate();

            newPage.Title = newPageTitle;
            newPage.MetaTitle = newPageTitle;
            newPage.PageUrl = newPageUrl;
            newPage.PageUrlHash = newPageUrl.UrlHash();
            newPage.Status = PageStatus.Unpublished;

            if (cloneAsMasterPage)
            {
                newPage.IsMasterPage = true;
            }

            if (newPage.IsMasterPage)
            {
                newPage.Status = PageStatus.Published;
                newPage.Language = null;
            }

            // Add security.
            AddAccessRules(newPage, userAccess);

            return newPage;
        }