Exemplo n.º 1
0
        public override async Task GetContentItemAspectAsync(ContentItemAspectContext context, PreviewPart part)
        {
            var pattern = GetPattern(part);

            if (!String.IsNullOrEmpty(pattern))
            {
                await context.ForAsync <PreviewAspect>(async previewAspect =>
                {
                    var model = new PreviewPartViewModel()
                    {
                        PreviewPart = part,
                        ContentItem = part.ContentItem
                    };

                    var templateContext = new TemplateContext();
                    templateContext.SetValue("ContentItem", part.ContentItem);
                    templateContext.MemberAccessStrategy.Register <PreviewPartViewModel>();
                    templateContext.SetValue("Model", model);

                    previewAspect.PreviewUrl = await _liquidTemplateManager.RenderAsync(pattern, NullEncoder.Default, templateContext);
                    previewAspect.PreviewUrl = previewAspect.PreviewUrl.Replace("\r", String.Empty).Replace("\n", String.Empty);
                });
            }

            return;
        }
Exemplo n.º 2
0
        public override async Task GetContentItemAspectAsync(ContentItemAspectContext context, PreviewPart part)
        {
            var pattern = GetPattern(part);

            if (!String.IsNullOrEmpty(pattern))
            {
                await context.ForAsync <PreviewAspect>(async previewAspect =>
                {
                    var model = new PreviewPartViewModel()
                    {
                        PreviewPart = part,
                        ContentItem = part.ContentItem
                    };

                    previewAspect.PreviewUrl = await _liquidTemplateManager.RenderStringAsync(pattern, NullEncoder.Default, model,
                                                                                              new Dictionary <string, FluidValue>()
                    {
                        ["ContentItem"] = new ObjectValue(model.ContentItem)
                    });

                    previewAspect.PreviewUrl = previewAspect.PreviewUrl.Replace("\r", String.Empty).Replace("\n", String.Empty);
                });
            }

            return;
        }
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context)
        {
            return(context.ForAsync <ContentItemMetadata>(metadata =>
            {
                if (context.ContentItem.ContentType == "AdvancedForm")
                {
                    metadata.EditorRouteValues = new RouteValueDictionary {
                        { "Area", "AdvancedForms" },
                        { "Controller", "Admin" },
                        { "Action", "Edit" },
                        { "ContentItemId", context.ContentItem.ContentItemId }
                    };
                }

                if (context.ContentItem.ContentType == "AdvancedFormSubmissions")
                {
                    try
                    {
                        string path = context.ContentItem.Content.AutoroutePart.Path.ToString().Split("/")[1];
                        metadata.EditorRouteValues = new RouteValueDictionary {
                            { "Area", "AdvancedForms" },
                            { "Controller", path },
                            { "Action", "Submission" },
                            { "id", context.ContentItem.ContentItemId }
                        };
                    }
                    catch
                    {
                    }
                }

                if (context.ContentItem.ContentType == "AdvancedForm")
                {
                    metadata.AdminRouteValues = new RouteValueDictionary {
                        { "Area", "AdvancedForms" },
                        { "Controller", "Admin" },
                        { "Action", "Edit" },
                        { "ContentItemId", context.ContentItem.ContentItemId }
                    };
                }

                if (context.ContentItem.ContentType == "AdvancedFormSubmissions")
                {
                    try
                    {
                        string path = context.ContentItem.Content.AutoroutePart.Path.ToString().Split("/")[1];
                        metadata.AdminRouteValues = new RouteValueDictionary {
                            { "Area", "AdvancedForms" },
                            { "Controller", path },
                            { "Action", "Submission" },
                            { "id", context.ContentItem.ContentItemId }
                        };
                    }
                    catch
                    {
                    }
                }
                return Task.CompletedTask;
            }));
        }
 public override Task GetContentItemAspectAsync(ContentItemAspectContext context, LocalizationPart part)
 {
     return(context.ForAsync <CultureAspect>(cultureAspect =>
     {
         cultureAspect.Culture = CultureInfo.GetCultureInfo(part.Culture);
         return Task.CompletedTask;
     }));
 }
 public override Task GetContentItemAspectAsync(ContentItemAspectContext context, ListPart part)
 {
     return(context.ForAsync <FeedMetadata>(feedMetadata =>
     {
         // If the value is not defined, it will be represented as null
         feedMetadata.FeedProxyUrl = part.Content.FeedProxyUrl;
         return Task.CompletedTask;
     }));
 }
Exemplo n.º 6
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context)
        {
            return(context.ForAsync <ContentItemMetadata>(metadata =>
            {
                if (metadata.CreateRouteValues == null)
                {
                    metadata.CreateRouteValues = new RouteValueDictionary {
                        { "Area", "OrchardCore.Contents" },
                        { "Controller", "Admin" },
                        { "Action", "Create" },
                        { "Id", context.ContentItem.ContentType }
                    };
                }

                if (metadata.EditorRouteValues == null)
                {
                    metadata.EditorRouteValues = new RouteValueDictionary {
                        { "Area", "OrchardCore.Contents" },
                        { "Controller", "Admin" },
                        { "Action", "Edit" },
                        { "ContentItemId", context.ContentItem.ContentItemId }
                    };
                }

                if (metadata.AdminRouteValues == null)
                {
                    metadata.AdminRouteValues = new RouteValueDictionary {
                        { "Area", "OrchardCore.Contents" },
                        { "Controller", "Admin" },
                        { "Action", "Edit" },
                        { "ContentItemId", context.ContentItem.ContentItemId }
                    };
                }

                if (metadata.DisplayRouteValues == null)
                {
                    metadata.DisplayRouteValues = new RouteValueDictionary {
                        { "Area", "OrchardCore.Contents" },
                        { "Controller", "Item" },
                        { "Action", "Display" },
                        { "ContentItemId", context.ContentItem.ContentItemId }
                    };
                }

                if (metadata.RemoveRouteValues == null)
                {
                    metadata.RemoveRouteValues = new RouteValueDictionary {
                        { "Area", "OrchardCore.Contents" },
                        { "Controller", "Admin" },
                        { "Action", "Remove" },
                        { "ContentItemId", context.ContentItem.ContentItemId }
                    };
                }

                return Task.CompletedTask;
            }));
        }
Exemplo n.º 7
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, AttachContentPart part)
        {
            return(context.ForAsync <BodyAspect>(async bodyAspect =>
            {
                if (_bodyAspect != null)
                {
                    bodyAspect.Body = _bodyAspect;
                    return;
                }

                try
                {
                    var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
                    var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => String.Equals(x.PartDefinition.Name, "MarkdownBodyPart"));
                    var settings = contentTypePartDefinition.GetSettings <MarkdownBodyPartSettings>();

                    // The default Markdown option is to entity escape html
                    // so filters must be run after the markdown has been processed.
                    var html = _markdownService.ToHtml(part.AttachContent);

                    // The liquid rendering is for backwards compatability and can be removed in a future version.
                    if (!settings.SanitizeHtml)
                    {
                        var model = new AttachContentPartViewModel()
                        {
                            AttachContentPart = part,
                            ContentItem = part.ContentItem
                        };

                        html = await _liquidTemplateManager.RenderStringAsync(html, _htmlEncoder, model,
                                                                              new Dictionary <string, FluidValue>()
                        {
                            ["ContentItem"] = new ObjectValue(model.ContentItem)
                        });
                    }

                    html = await _shortcodeService.ProcessAsync(html,
                                                                new Context
                    {
                        ["ContentItem"] = part.ContentItem,
                        ["TypePartDefinition"] = contentTypePartDefinition
                    });

                    if (settings.SanitizeHtml)
                    {
                        html = _htmlSanitizerService.Sanitize(html);
                    }

                    bodyAspect.Body = _bodyAspect = new HtmlString(html);
                }
                catch
                {
                    bodyAspect.Body = HtmlString.Empty;
                }
            }));
        }
Exemplo n.º 8
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, TaxonomyPart part)
        {
            return(context.ForAsync <ContainedContentItemsAspect>(aspect =>
            {
                aspect.Accessors.Add((jObject) =>
                {
                    return jObject["TaxonomyPart"]["Terms"] as JArray;
                });

                return Task.CompletedTask;
            }));
        }
Exemplo n.º 9
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, MarkdownBodyPart part)
        {
            return(context.ForAsync <BodyAspect>(bodyAspect =>
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
                var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(MarkdownBodyPart));
                var settings = contentTypePartDefinition.GetSettings <MarkdownBodyPartSettings>();
                var html = Markdig.Markdown.ToHtml(part.Markdown ?? "");

                bodyAspect.Body = new HtmlString(html);
                return Task.CompletedTask;
            }));
        }
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, HtmlBodyPart part)
        {
            return(context.ForAsync <BodyAspect>(bodyAspect =>
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
                var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == nameof(HtmlBodyPart));
                var settings = contentTypePartDefinition.GetSettings <HtmlBodyPartSettings>();
                var body = part.Html;

                bodyAspect.Body = new HtmlString(body);
                return Task.CompletedTask;
            }));
        }
Exemplo n.º 11
0
 public override Task GetContentItemAspectAsync(ContentItemAspectContext context, CrossReferencePart part)
 {
     return(context.ForAsync <ContentItemMetadata>(contentItemMetadata =>
     {
         contentItemMetadata.AdminRouteValues = new RouteValueDictionary
         {
             { "Area", "OrchardCore.Contents" },
             { "Controller", "Admin" },
             { "Action", "Display" },
             { "ContentItemId", context.ContentItem.ContentItemId }
         };
         return Task.CompletedTask;
     }));
 }
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return(Task.CompletedTask);
            }

            return(context.ForAsync <FullTextAspect>(async fullTextAspect =>
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);
                var settings = contentTypeDefinition.GetSettings <FullTextAspectSettings>();

                if (settings.IncludeDisplayText)
                {
                    fullTextAspect.Segments.Add(context.ContentItem.DisplayText);
                }

                if (settings.IncludeBodyAspect)
                {
                    // Lazy resolution to prevent cyclic dependency of content handlers
                    var contentManager = _serviceProvider.GetRequiredService <IContentManager>();
                    var bodyAspect = await contentManager.PopulateAspectAsync <BodyAspect>(context.ContentItem);

                    if (bodyAspect != null && bodyAspect.Body != null)
                    {
                        using (var sw = new StringWriter())
                        {
                            // Don't encode the body
                            bodyAspect.Body.WriteTo(sw, NullHtmlEncoder.Default);
                            fullTextAspect.Segments.Add(sw.ToString());
                        }
                    }
                }

                if (settings.IncludeFullTextTemplate && !String.IsNullOrEmpty(settings.FullTextTemplate))
                {
                    var templateContext = new TemplateContext();
                    templateContext.SetValue("ContentItem", context.ContentItem);
                    templateContext.SetValue("Model", context.ContentItem);

                    var result = await _liquidTemplateManager.RenderAsync(settings.FullTextTemplate, NullHtmlEncoder.Default, templateContext);
                    fullTextAspect.Segments.Add(result);
                }
            }));
        }
Exemplo n.º 13
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, AutoroutePart part)
        {
            return(context.ForAsync <RouteHandlerAspect>(aspect =>
            {
                var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
                var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => String.Equals(x.PartDefinition.Name, "AutoroutePart"));
                var settings = contentTypePartDefinition.GetSettings <AutoroutePartSettings>();
                if (settings.ManageContainedItemRoutes)
                {
                    aspect.Path = part.Path;
                    aspect.Absolute = part.Absolute;
                    aspect.Disabled = part.Disabled;
                }

                return Task.CompletedTask;
            }));
        }
Exemplo n.º 14
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, HtmlBodyPart part)
        {
            return(context.ForAsync <BodyAspect>(async bodyAspect =>
            {
                try
                {
                    var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(part.ContentItem.ContentType);
                    var contentTypePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(x => string.Equals(x.PartDefinition.Name, "HtmlBodyPart"));
                    var settings = contentTypePartDefinition.GetSettings <HtmlBodyPartSettings>();

                    var html = part.Html;

                    if (!settings.SanitizeHtml)
                    {
                        var model = new HtmlBodyPartViewModel()
                        {
                            Html = part.Html,
                            HtmlBodyPart = part,
                            ContentItem = part.ContentItem
                        };

                        html = await _liquidTemplateManager.RenderStringAsync(html, _htmlEncoder, model,
                                                                              new Dictionary <string, FluidValue>()
                        {
                            ["ContentItem"] = new ObjectValue(model.ContentItem)
                        });
                    }

                    html = await _shortcodeService.ProcessAsync(html,
                                                                new Context
                    {
                        ["ContentItem"] = part.ContentItem,
                        ["TypePartDefinition"] = contentTypePartDefinition
                    });

                    bodyAspect.Body = new HtmlString(html);
                }
                catch
                {
                    bodyAspect.Body = HtmlString.Empty;
                }
            }));
        }
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, FacebookPluginPart part)
        {
            return(context.ForAsync <BodyAspect>(async bodyAspect =>
            {
                try
                {
                    var model = new FacebookPluginPartViewModel()
                    {
                        Liquid = part.Liquid,
                        FacebookPluginPart = part,
                        ContentItem = part.ContentItem
                    };

                    var result = await _liquidTemplateManager.RenderAsync(part.Liquid, _htmlEncoder, model,
                                                                          scope => scope.SetValue("ContentItem", model.ContentItem));

                    bodyAspect.Body = new HtmlString(result);
                }
                catch
                {
                    bodyAspect.Body = HtmlString.Empty;
                }
            }));
        }
Exemplo n.º 16
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, CreatableContentPart part)
        {
            return(context.ForAsync <ContentItemMetadata>(metadata =>
            {
                // Should only run when not in the Admin
                if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
                {
                    // await next();
                    return Task.CompletedTask;
                }

                if (metadata.CreateRouteValues == null)
                {
                    metadata.CreateRouteValues = new RouteValueDictionary
                    {
                        { "Area", "Intelli.EditableContent" },
                        { "Controller", "Contents" },
                        { "Action", "Create" },
                        { "Id", context.ContentItem.ContentType }
                    };
                }

//                    if (metadata.EditorRouteValues == null)
//                    {
//                        metadata.EditorRouteValues = new RouteValueDictionary
//                        {
//                            {"Area", "Intelli.EditableContent"},
//                            {"Controller", "Contents"},
//                            {"Action", "Edit"},
//                            {"ContentItemId", context.ContentItem.ContentItemId}
//                        };
//                    }

//                    if (metadata.AdminRouteValues == null)
//                    {
//                        metadata.AdminRouteValues = new RouteValueDictionary
//                        {
//                            {"Area", "OrchardCore.LearnNow"},
//                            {"Controller", "Admin"},
//                            {"Action", "Edit"},
//                            {"ContentItemId", context.ContentItem.ContentItemId}
//                        };
//                    }
//
//                    if (metadata.DisplayRouteValues == null)
//                    {
//                        metadata.DisplayRouteValues = new RouteValueDictionary
//                        {
//                            {"Area", "Intelli.LearnNow"},
//                            {"Controller", "Item"},
//                            {"Action", "Display"},
//                            {"ContentItemId", context.ContentItem.ContentItemId}
//                        };
//                    }
//
//                    if (metadata.RemoveRouteValues == null)
//                    {
//                        metadata.RemoveRouteValues = new RouteValueDictionary
//                        {
//                            {"Area", "Intelli.LearnNow"},
//                            {"Controller", "Admin"},
//                            {"Action", "Remove"},
//                            {"ContentItemId", context.ContentItem.ContentItemId}
//                        };
//                    }

                return Task.CompletedTask;
            }
                                                          ));
        }
Exemplo n.º 17
0
        public override Task GetContentItemAspectAsync(ContentItemAspectContext context, SeoMetaPart part)
        {
            return(context.ForAsync <SeoAspect>(async aspect =>
            {
                aspect.Render = part.Render;

                if (!String.IsNullOrEmpty(part.PageTitle))
                {
                    aspect.PageTitle = part.PageTitle;
                }

                if (!String.IsNullOrEmpty(part.MetaDescription))
                {
                    aspect.MetaDescription = part.MetaDescription;
                }

                if (!String.IsNullOrEmpty(part.MetaKeywords))
                {
                    aspect.MetaKeywords = part.MetaKeywords;
                }



                if (!String.IsNullOrEmpty(part.MetaRobots))
                {
                    aspect.MetaRobots = part.MetaRobots;
                }

                aspect.CustomMetaTags = part.CustomMetaTags;

                var siteSettings = await _siteService.GetSiteSettingsAsync();

                var actionContext = _actionContextAccessor.ActionContext;

                if (actionContext == null)
                {
                    actionContext = await GetActionContextAsync(_httpContextAccessor.HttpContext);
                }

                var urlHelper = _urlHelperFactory.GetUrlHelper(actionContext);

                if (!String.IsNullOrEmpty(part.Canonical))
                {
                    aspect.Canonical = part.Canonical;
                }
                else
                {
                    var contentItemMetadata = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(part.ContentItem);
                    var relativeUrl = urlHelper.RouteUrl(contentItemMetadata.DisplayRouteValues);
                    aspect.Canonical = urlHelper.ToAbsoluteUrl(relativeUrl);
                }

                // OpenGraph
                if (part.OpenGraphImage?.Paths?.Length > 0)
                {
                    aspect.OpenGraphImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.OpenGraphImage.Paths[0]));
                }
                else if (part.DefaultSocialImage?.Paths?.Length > 0)
                {
                    aspect.OpenGraphImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.DefaultSocialImage.Paths[0]));
                }

                if (part.OpenGraphImage?.MediaTexts?.Length > 0)
                {
                    aspect.OpenGraphImageAlt = part.OpenGraphImage.MediaTexts[0];
                }
                else if (part.DefaultSocialImage?.MediaTexts?.Length > 0)
                {
                    aspect.OpenGraphImageAlt = part.DefaultSocialImage.MediaTexts[0];
                }

                if (!String.IsNullOrEmpty(part.OpenGraphTitle))
                {
                    aspect.OpenGraphTitle = part.OpenGraphTitle;
                }
                else
                {
                    aspect.OpenGraphTitle = part.PageTitle;
                }

                if (!String.IsNullOrEmpty(part.OpenGraphDescription))
                {
                    aspect.OpenGraphDescription = part.OpenGraphDescription;
                }
                else
                {
                    aspect.OpenGraphDescription = part.MetaDescription;
                }

                // Twitter

                if (part.TwitterImage?.Paths?.Length > 0)
                {
                    aspect.TwitterImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.TwitterImage.Paths[0]));
                }
                else if (part.DefaultSocialImage?.Paths?.Length > 0)
                {
                    aspect.TwitterImage = urlHelper.ToAbsoluteUrl(_mediaFileStore.MapPathToPublicUrl(part.DefaultSocialImage.Paths[0]));
                }

                if (part.TwitterImage?.MediaTexts?.Length > 0)
                {
                    aspect.TwitterImageAlt = part.TwitterImage.MediaTexts[0];
                }
                else if (part.DefaultSocialImage?.MediaTexts?.Length > 0)
                {
                    aspect.TwitterImageAlt = part.DefaultSocialImage.MediaTexts[0];
                }

                if (!String.IsNullOrEmpty(part.TwitterTitle))
                {
                    aspect.TwitterTitle = part.TwitterTitle;
                }
                else
                {
                    aspect.TwitterTitle = part.PageTitle;
                }

                if (!String.IsNullOrEmpty(part.TwitterDescription))
                {
                    aspect.TwitterDescription = part.TwitterDescription;
                }
                else
                {
                    aspect.TwitterDescription = part.MetaDescription;
                }

                if (!String.IsNullOrEmpty(part.TwitterCard))
                {
                    aspect.TwitterCard = part.TwitterCard;
                }

                if (!String.IsNullOrEmpty(part.TwitterCreator))
                {
                    aspect.TwitterCreator = part.TwitterCreator;
                }

                if (!String.IsNullOrEmpty(part.TwitterSite))
                {
                    aspect.TwitterSite = part.TwitterSite;
                }

                aspect.GoogleSchema = part.GoogleSchema;
            }));
        }