コード例 #1
0
        public async Task <ShapeBinding> GetShapeBindingAsync(string shapeType)
        {
            if (!AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                return(null);
            }

            var localTemplates = _previewTemplatesProvider.GetTemplates();

            if (localTemplates != null)
            {
                if (localTemplates.Templates.TryGetValue(shapeType, out var localTemplate))
                {
                    return(BuildShapeBinding(shapeType, localTemplate));
                }
            }

            if (_templatesDocument == null)
            {
                _templatesDocument = await _templatesManager.GetTemplatesDocumentAsync();
            }

            if (_templatesDocument.Templates.TryGetValue(shapeType, out var template))
            {
                return(BuildShapeBinding(shapeType, template));
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
ファイル: AdminMenuFilter.cs プロジェクト: princeppy/Orchard2
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // Should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            // Should only run on the Admin
            if (!AdminAttribute.IsApplied(filterContext.HttpContext))
            {
                return;
            }

            // Populate main nav
            IShape menuShape = _shapeFactory.Create("Menu",
                                                    Arguments.From(new
            {
                MenuName  = "admin",
                RouteData = filterContext.RouteData,
            }));

            // Enable shape caching
            menuShape.Metadata.CacheContext
            .Cache("menu-admin")
            .AddContext("roles", "features")
            ;

            _layoutAccessor.GetLayout().Navigation.Add(menuShape);
        }
コード例 #3
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                if (_scriptsCache == null)
                {
                    var settings = (await _siteService.GetSiteSettingsAsync()).As <CookiesSettings>();

                    //if (!string.IsNullOrWhiteSpace(settings?.ServicesScript))
                    //{
                    _scriptsCache = new HtmlString($"<script src=\"/TarteAuCitron.OrchardCore/Scripts/tarteaucitron.js\"></script>\n<script>tarteaucitron.init({{ \"privacyUrl\": \"{settings.PrivacyUrl}\", \"hashtag\": \"#tarteaucitron\", \"cookieName\": \"{settings.CookieName}\", \"orientation\": \"{settings.Orientation}\", \"showAlertSmall\": {settings.ShowAlertSmall.ToString().ToLower()}, \"cookieslist\": {settings.Cookieslist.ToString().ToLower()}, \"adblocker\": {settings.AdBlocker.ToString().ToLower()}, \"AcceptAllCta\" : {settings.AcceptAllCta.ToString().ToLower()}, \"highPrivacy\": {settings.HighPrivacy.ToString().ToLower()}, \"handleBrowserDNTRequest\": {settings.HandleBrowserDNTRequest.ToString().ToLower()}, \"removeCredit\": {settings.RemoveCredit.ToString().ToLower()}, \"moreInfoLink\": {settings.MoreInfoLink.ToString().ToLower()}, \"useExternalCss\": false, \"readmoreLink\": \"{settings.ReadMoreLink}\"}});</script>\n<script>{settings.ServicesScript}</script>");
                    //}
                }

                if (_scriptsCache != null)
                {
                    //_resourceManager.RegisterLink();
                    _resourceManager.RegisterHeadScript(_scriptsCache);
                }
            }

            await next.Invoke();
        }
コード例 #4
0
        public bool TryGetDescriptorBinding(string shapeType, out ShapeBinding shapeBinding)
        {
            if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                shapeBinding = null;
                return(false);
            }

            var localTemplates = _previewTemplatesProvider.GetTemplates();

            if (localTemplates != null)
            {
                if (localTemplates.Templates.TryGetValue(shapeType, out var localTemplate))
                {
                    shapeBinding = BuildShapeBinding(shapeType, localTemplate);
                    return(true);
                }
            }

            if (_templatesDocument.Templates.TryGetValue(shapeType, out var template))
            {
                shapeBinding = BuildShapeBinding(shapeType, template);

                return(true);
            }
            else
            {
                shapeBinding = null;
                return(false);
            }
        }
コード例 #5
0
ファイル: LiveChatFilter.cs プロジェクト: nickaynes/test789
        public async void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var settings = siteSettings.As <LiveChatSettings>();

            // Display only when enabled
            if (settings == null || !settings.Enable)
            {
                return;
            }

            // Don't display on admin pages
            if (AdminAttribute.IsApplied(filterContext.HttpContext))
            {
                return;
            }

            // Should only run on a full view rendering result
            if (!(filterContext.Result is ViewResult))
            {
                return;
            }

            var content = new HtmlString(settings.Text);

            _resourceManager.RegisterFootScript(content);
        }
コード例 #6
0
        public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next)
        {
            // Dont run in the admin
            if (AdminAttribute.IsApplied(filterContext.HttpContext))
            {
                await next();

                return;
            }

            // You can decide when the filter should be executed here. If this is a ViewResult or PageResult the shape
            // injection wouldn't make any sense since there wouldn't be any zones.
            if (!(filterContext.Result is ViewResult || filterContext.Result is PageResult))
            {
                await next();

                return;
            }

            // The layout can be handled easily if this is dynamic.
            dynamic layout = await _layoutAccessor.GetLayoutAsync();



            // The dynamic Layout object will contain a Zones dictionary that you can use to access a zone.
            var contentZone = layout.Zones["Content"];

            // Here you can add an ad-hoc generated shape to the content zone.
            contentZone.Add(await _shapeFactory.New.NotificationsPanel());

            await next();

            return;
        }
コード例 #7
0
        public async Task <LookAndFeelSelectorResult> GetLookAndFeelAsync()
        {
            // Should only run on the front end not Admin
            if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                return(null);
            }


            // Should only run if user is authenticated
            var user = _httpContextAccessor.HttpContext.User;

            if (!user.Identity.IsAuthenticated)
            {
                return(null);
            }

            var settings = (await _siteService.GetSiteSettingsAsync()).As <LookAndFeelAuthenticatedUserSettings>();

            if (settings != null)
            {
                string theme  = settings.Theme;
                string layout = settings.Layout;
                if (!string.IsNullOrEmpty(theme))
                {
                    return(new LookAndFeelSelectorResult {
                        Priority = 20, Theme = theme, Layout = layout
                    });
                }
            }

            return(null);
        }
コード例 #8
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Only display on admin pages
            if (!(context.Result is ViewResult || context.Result is PageResult) ||
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                await next();

                return;
            }

            try {
                dynamic layout = await _layoutAccessor.GetLayoutAsync();

                layout.Zones["NavbarTop"].Add(
                    await _shapeFactory.New.DeploymentNavBar()
                    );
            } catch (Exception e) {
                _logger.LogError(e, "Failed to add DeploymentNavBar to Header Shapes");
            }

            await next();

            return;
        }
コード例 #9
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            // Should only run if user is authenticated
            if (!(context.HttpContext.User.Identity.IsAuthenticated))
            {
                await next.Invoke();

                return;
            }

            // Should only run on the front end home Page
            if (!IsHomePage(context.HttpContext))
            {
                await next.Invoke();

                return;
            }

            // Should only run on the front end not Admin
            if (AdminAttribute.IsApplied(context.HttpContext))
            {
                await next.Invoke();

                return;
            }


            //redirect to custom action to render specific view
//            context.Result =
//                new RedirectToRouteResult(
//                    "my-user-home-page");
            //redirect to custom action to render specific view
            context.Result = new RedirectToActionResult("Index", "AuthenticatedUser", new { area = "Intelli" });
            //  context.Result = new RedirectToRouteResult("my-user-home-page");
        }
コード例 #10
0
        private Task BuildViewModel(WizardConfigPartViewModel model, WizardConfigPart configPart)
        {
            model.Theme       = configPart.Theme;
            model.IsAdminMode = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);


            return(Task.CompletedTask);
        }
コード例 #11
0
        private Task BuildViewModel(TabPanelPartViewModel model, TabPanelPart part)
        {
            model.Title       = part.Title;
            model.Icon        = part.Icon;
            model.IsAdminMode = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);


            return(Task.CompletedTask);
        }
コード例 #12
0
        private Task BuildViewModel(PartPanelPartViewModel model, PartPanelPart part)
        {
            model.ContentItem   = part.ContentItem;
            model.Part          = part.Part;
            model.Hidden        = part.Hidden;
            model.PartPanelPart = part;

            model.IsAdminMode = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);
            return(Task.CompletedTask);
        }
コード例 #13
0
        public async Task <LookAndFeelSelectorResult> GetLookAndFeelAsync()
        {
            // Should only run on the front end not Admin
            if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                return(null);
            }

            var currentContentItem = await _currentContentItemAccessor.GetCurrentContentItem();

            /*
             * var currentContentItemId = _currentContentItemAccessor.CurrentContentItemId();
             * if (currentContentItemId == null)
             * {
             *   return null;
             *
             * }
             *
             *
             * //this is cached so any other calls in request _contentManager.GetAsync will use the same cached item https://github.com/OrchardCMS/OrchardCore/issues/5052
             * var currentContentItem = await _contentManager.GetAsync(currentContentItemId);
             */
            if (currentContentItem == null)
            {
                return(null);
            }


            var settings = (await _siteService.GetSiteSettingsAsync()).As <LookAndFeelContentTypeSettings>();


            var contentTypeSettings =
                ContentTypeLookAndFeelSettings(settings.SetUpProperties); // site.LookAndFeelSettings();

            contentTypeSettings.TryGetValue(currentContentItem.ContentType, out var themeSettings);
            if (!string.IsNullOrEmpty(themeSettings)) //this is a comma separated string Theme,Layout
            {
                var    themeProperties = themeSettings.Split(',');
                string theme           = themeProperties[0];
                string layout          = themeProperties.Length > 1 ? themeProperties[1] : string.Empty;
                if (!string.IsNullOrEmpty(theme))
                {
                    return(new LookAndFeelSelectorResult {
                        Priority = 10, Theme = theme, Layout = layout
                    });
                }
            }


            //  }

            return(null);
        }
コード例 #14
0
        public override IDisplayResult Edit(ActionsPanelPart part, BuildPartEditorContext context)
        {
            //return Initialize<LayoutPartViewModel>("LayoutPart_Edit", m => BuildViewModel(m, part));
            //add to bus to be picked up by content ishapetableprovider for shifting
            // _httpContextAccessor.HttpContext.Items["PartPanelContainer_CustomerPart"] ="PartPanelContainer_CustomerPart";
            // _httpContextAccessor.HttpContext.Items["PartPanelContainer_SupplierPart"] ="PartPanelContainer_SupplierPart";
            return(Initialize <FlowPartEditViewModel>("ActionsPanelPart_Edit", m =>
            {
                var settings = context.TypePartDefinition.GetSettings <ActionsPanelPartSettings>();   // GetPartSettings(part);
                bool isAdminMode = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);
                if (isAdminMode == true)
                {
                    if (settings.AllowOverrideActionsPanelPerInstance == true)
                    {
                        //if in admin mode show settings
                        m.FlowPartDisplayMode = settings.FlowPartDisplayMode;
                        m.FlowPartEditMode = settings.FlowPartEditMode;
                        m.FlowPartCreateMode = settings.FlowPartCreateMode;
                    }
                }



                /*
                 * _httpContextAccessor.HttpContext.Items["ActionsPanelPartCorrelationId"] = part.ContentItem.ContentItemId;
                 *
                 *
                 * Dictionary<string, string> flattenedProps =  new Dictionary<string, string>();//
                 * if (context.IsNew)
                 * {
                 *  flattenedProps= Intelli.Core.Helpers.Helpers.GetNotificationPropertiesFromMessageContent(JObject.FromObject(settings.FlowPartCreateMode));
                 * }
                 * else
                 * {
                 *  flattenedProps= Intelli.Core.Helpers.Helpers.GetNotificationPropertiesFromMessageContent(JObject.FromObject(settings.FlowPartEditMode));
                 * }
                 *
                 * var shifted = flattenedProps.Where(x => x.Key.EndsWith("PartPanelPart.Part"));
                 * foreach (var shiftedPanel in shifted)
                 * {
                 *  _httpContextAccessor.HttpContext.Items[$"PartPanelContainer_{shiftedPanel.Value}"] =$"PartPanelContainer_{shiftedPanel.Value}";
                 * }
                 *
                 */
                //based on iscreate or iseditmode pass in appropriate flowpart
                m.FlowPart = context.IsNew == true ? settings.FlowPartCreateMode : settings.FlowPartEditMode;
                m.IsNew = context.IsNew;
                m.Updater = context.Updater;
                //  m.BuildPartDisplayContext = context;
            })
                   .Location("Detail", "Content:5"));
        }
コード例 #15
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end (or optionally also on the admin) for a full view.
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                (_options.AllowOnAdmin || !AdminAttribute.IsApplied(context.HttpContext)))
            {
                dynamic layout = await _layoutAccessor.GetLayoutAsync();

                var footerZone = layout.Zones["Footer"];
                footerZone.Add(await _shapeFactory.CreateAsync("MiniProfiler"));
            }

            await next.Invoke();
        }
コード例 #16
0
 public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
 {
     // Should only run on the front-end for a full view
     if ((context.Result is ViewResult || context.Result is PageResult) &&
         !AdminAttribute.IsApplied(context.HttpContext))
     {
         var settings = (await _siteService.GetSiteSettingsAsync()).As <GoogleAnalyticsSettings>();
         if (!string.IsNullOrWhiteSpace(settings?.TrackingID))
         {
             _resourceManager.RegisterHeadScript(new HtmlString($"<script async src=\"https://www.googletagmanager.com/gtag/js?id={settings.TrackingID}\"></script>"));
             _resourceManager.RegisterHeadScript(new HtmlString($"<script>window.dataLayer = window.dataLayer || [];function gtag() {{ dataLayer.push(arguments); }}gtag('js', new Date());gtag('config', '{settings.TrackingID}')</script>"));
         }
     }
     await next.Invoke();
 }
コード例 #17
0
        public void Discover(ShapeTableBuilder builder)
        {
            builder.Describe("FlowPart_Edit")
            .OnDisplaying(displaying =>
            {
//                    IF FLOWPART_EDIT  IS SHAPE
//
//                    IF CONTENTTYPE = tABSContainer and  isnot in admin
//                        thena add alternate  TabsContainer-FlowPart-FrontEnd.Edit.cshtml
                var isAdminMode = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);
                if (isAdminMode == false)
                {
                    if (displaying.Shape is IShape flowPartShape)
                    {
                        var flowPartEditViewModel = displaying.Shape as FlowPartEditViewModel;
                        if (flowPartEditViewModel?.FlowPart.ContentItem != null)
                        {
                            var contentType = flowPartEditViewModel.FlowPart.ContentItem.ContentType;
                            if (contentType == "TabsContainer")
                            {
                                // e.g.TabsContainer-FlowPart-FrontEnd.Edit.cshtml
                                displaying.Shape.Metadata.Alternates.Add($"{contentType}__FlowPart__FrontEnd_Edit");
                            }

                            if (contentType == "TabPanel")
                            {
                                // e.g.TabPanel-FlowPart-FrontEnd.Edit.cshtml
                                displaying.Shape.Metadata.Alternates.Add($"{contentType}__FlowPart__FrontEnd_Edit");
                            }


                            //wizard widget
                            if (contentType == "Wizard")
                            {
                                // e.g.TabsContainer-FlowPart-FrontEnd.Edit.cshtml
                                displaying.Shape.Metadata.Alternates.Add($"{contentType}__FlowPart__FrontEnd_Edit");
                            }

                            if (contentType == "WizardStep")
                            {
                                // e.g.TabPanel-FlowPart-FrontEnd.Edit.cshtml
                                displaying.Shape.Metadata.Alternates.Add($"{contentType}__FlowPart__FrontEnd_Edit");
                            }
                        }
                    }
                }
            });
        }
コード例 #18
0
ファイル: FaviconFilter.cs プロジェクト: nickaynes/test789
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // should only run on the front-end for a full view
            if (!((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext)))
            {
                await next.Invoke();

                return;
            }

            try
            {
                var pathBase     = context.HttpContext.Request.PathBase;
                var siteSettings = await _siteService.GetSiteSettingsAsync();

                var faviconSettings = siteSettings.As <ContentItem>("FaviconSettings")?.As <FaviconSettings>() ?? null;

                if (faviconSettings != null && faviconSettings.HasAppleTouchIcon)
                {
                    _resourceManager.RegisterLink(new LinkEntry {
                        Href = $"{pathBase}/icon.png", Rel = "apple-touch-icon"
                    });
                }

                if (faviconSettings != null && faviconSettings.HasFavicon)
                {
                    _resourceManager.RegisterLink(new LinkEntry {
                        Href = $"{pathBase}/favicon.ico", Rel = "shortcut icon"
                    });
                }

                if (faviconSettings != null && faviconSettings.HasWebAppManifest)
                {
                    _resourceManager.RegisterLink(new LinkEntry {
                        Href = $"{pathBase}/site.webmanifest", Rel = "manifest"
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Error defining meta/link tags for favicon feature");
            }

            await next.Invoke();
        }
コード例 #19
0
        public override async Task <IDisplayResult> UpdateAsync(ListPart listPart, IUpdateModel updater,
                                                                UpdatePartEditorContext context)
        {
            var isAdminMode = AdminAttribute.IsApplied(_httpContextAccessor.HttpContext);

            if (isAdminMode)
            {
                var settings = context.TypePartDefinition.GetSettings <ListPartSettings>();
                if (settings.AllowOverrideDataFillModePerInstance)
                {
                    await updater.TryUpdateModelAsync(listPart, Prefix, m => m.ContainedContentTypes,
                                                      m => m.DataFillMode, m => m.SelectedWorkMapContentItemIds);
                }
            }


            return(Edit(listPart, context));
        }
コード例 #20
0
        public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, ResultExecutionDelegate next)
        {
            // Dont run in the admin
            if (AdminAttribute.IsApplied(filterContext.HttpContext))
            {
                await next();

                return;
            }

            // You can decide when the filter should be executed here. If this is a ViewResult or PageResult the shape
            // injection wouldn't make any sense since there wouldn't be any zones.
            if (!(filterContext.Result is ViewResult || filterContext.Result is PageResult))
            {
                await next();

                return;
            }


            //todo
            //this is a temp solution to inject styles because when registering them from shape MessageRoomsListByUser.cshtml is does not work
            //@* https://github.com/OrchardCMS/OrchardCore/issues/3947 *@

            _resourceManager.RegisterResource("stylesheet", "vendor-emoji-picker").AtHead();
            _resourceManager.RegisterResource("stylesheet", "vendor-comments").AtHead();
            _resourceManager.RegisterResource("stylesheet", "vendor-comments-chat").AtHead();
            _resourceManager.RegisterResource("stylesheet", "vendor-bootstrap-linkpreview").AtHead();
            _resourceManager.RegisterResource("stylesheet", "vendor-chatbox-popup").AtHead();

            // The layout can be handled easily if this is dynamic.
            dynamic layout = await _layoutAccessor.GetLayoutAsync();

            //  var asideRightZone = layout.Zones["AsideRightNav"];
            // asideRightZone.Add(await _shapeFactory.New.MessageRoomsSideBarPanel());
            //add sidebar zone  before closing the body tag
            layout.Zones["BodyTagClosingZone"].Add(await _shapeFactory.New.MessageRoomsSideBarPanel());


            //add button to main content area to trigger sidebar toggle
            layout.Zones["MainLayoutActionsZone"].Add(await _shapeFactory.New.MessageRoomsSideBarTriggerAction());

            await next();
        }
コード例 #21
0
 public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
 {
     // Should only run on the front-end for a full view
     if ((context.Result is ViewResult || context.Result is PageResult) &&
         !AdminAttribute.IsApplied(context.HttpContext))
     {
         var site     = (await _siteService.GetSiteSettingsAsync());
         var settings = site.As <FacebookSettings>();
         if (!string.IsNullOrWhiteSpace(settings?.AppId))
         {
             if (settings.FBInit)
             {
                 var setting = _resourceManager.RegisterResource("script", "fb");
                 setting.AtLocation(ResourceLocation.Foot);
             }
         }
     }
     await next.Invoke();
 }
コード例 #22
0
        public async Task <ThemeSelectorResult> GetThemeAsync()
        {
            if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                string adminThemeName = await _adminThemeService.GetAdminThemeNameAsync();

                if (String.IsNullOrEmpty(adminThemeName))
                {
                    return(null);
                }

                return(new ThemeSelectorResult
                {
                    Priority = 100,
                    ThemeName = adminThemeName
                });
            }

            return(null);
        }
コード例 #23
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            // Should only run on the Admin
            if (!AdminAttribute.IsApplied(context.HttpContext))
            {
                await next.Invoke();

                return;
            }

            // Should only run on the Admin Home Page
            if (!(context.HttpContext.GetRouteValue("area").ToString() == "OrchardCore.Media" && context.HttpContext.GetRouteValue("controller").ToString() == "Admin" && context.HttpContext.GetRouteValue("action").ToString() == "Index"))
            {
                await next.Invoke();

                return;
            }
            //redirect to inspiniaadmin custom actions
            context.Result = new RedirectToActionResult("Index", "MediaAdmin", new { area = "InspiniaAdmin2" });

            //  await next();
            // var httpMethod = context.HttpContext.Request.Method;
            //var routeValues = context.RouteData.Values;


//            var workflowTypeEntries = _workflowTypeRouteEntries.GetWorkflowRouteEntries(httpMethod, routeValues);
//            var workflowEntries = _workflowRouteEntries.GetWorkflowRouteEntries(httpMethod, routeValues);
//
//            if (workflowTypeEntries.Any())
//            {
//                var workflowTypeIds = workflowTypeEntries.Select(x => Int32.Parse(x.WorkflowId)).ToList();
//                var workflowTypes = (await _workflowTypeStore.GetAsync(workflowTypeIds)).ToDictionary(x => x.Id);
//
//                foreach (var entry in workflowTypeEntries)
//                {
//                    var workflowType = workflowTypes[Int32.Parse(entry.WorkflowId)];
//                    var activity = workflowType.Activities.Single(x => x.ActivityId == entry.ActivityId);
//                    await _workflowManager.StartWorkflowAsync(workflowType, activity);
//                }
//            }
        }
コード例 #24
0
        public async Task OnResultExecutionAsync(
            ResultExecutingContext context,
            ResultExecutionDelegate next)
        {
            //Only inject in client
            if (!AdminAttribute.IsApplied(context.HttpContext) && (context.Result is ViewResult ||
                                                                   context.Result is PageResult))
            {
                var settings = (await _siteService.GetSiteSettingsAsync()).As <BuyMeCoffeeSettings>();

                if (!string.IsNullOrEmpty(settings.DataId))
                {
                    // build the script
                    var script = ScriptBuilder(settings);

                    _resourceManager.RegisterHeadScript(new HtmlString(script));
                }
            }

            await next.Invoke();
        }
コード例 #25
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            if ((context.Result is ViewResult || context.Result is PageResult) && !AdminAttribute.IsApplied(context.HttpContext))
            {
                if (_scriptsCache == null)
                {
                    var settings = (await _siteService.GetSiteSettingsAsync()).As <CivicCookieControlSettings>();

                    if (settings?.IsValid ?? false)
                    {
                        _scriptsCache = new HtmlString($"<script src=\"https://cc.cdn.civiccomputing.com/9/cookieControl-9.x.min.js\"></script><script>var config = {_cookieControlSettingsService.ToJson(settings)}; CookieControl.load( config );</script>");
                    }
                }

                if (_scriptsCache != null)
                {
                    _resourceManager.RegisterHeadScript(_scriptsCache);
                }
            }

            await next.Invoke();
        }
コード例 #26
0
        public async Task <ThemeSelectorResult> GetThemeAsync()
        {
            // Should only run on the front-end for a full view
            if (!AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
            {
                var customLookAndFeel = await  GetLookAndFeelAsync();

                if (customLookAndFeel != null && !String.IsNullOrWhiteSpace(customLookAndFeel.Theme))
                {
                    //var currentThemeName = await _siteThemeService.GetCurrentThemeNameAsync();
                    //if (string.IsNullOrEmpty(currentThemeName))
                    //   return null;
                    //set to higher priority tham SiteThemeSelector to win
                    //  return new ThemeSelectorResult { Priority = 1, ThemeName = context.HttpContext.Items["IntelliTheme"].ToString() };

                    // Priority should override current theme priority, but not admin theme priority.
                    // Admin Theme Priority = 100
                    // Current Theme Priority = 0

                    //check and set custom layout
                    if (!string.IsNullOrEmpty(customLookAndFeel.Layout))
                    {
                        _httpContextAccessor.HttpContext.Items["IntelliLayout"] = customLookAndFeel.Layout;
//                       var layoutAccessor = _serviceProvider.GetService<ILayoutAccessor>();
//                       IShape layoutShape = await layoutAccessor.GetLayoutAsync();
//                       layoutShape?.Metadata.Alternates.Add("Layout__" + customLookAndFeel.Layout);
                    }

                    return(new ThemeSelectorResult
                    {
                        Priority = Priority,
                        ThemeName = customLookAndFeel.Theme
                    });
                }
            }

            return(null);
        }
コード例 #27
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                if (_scriptsCache == null)
                {
                    var settings = (await _siteService.GetSiteSettingsAsync()).As <GoogleTagManagerSettings>();

                    if (!string.IsNullOrWhiteSpace(settings?.ContainerID))
                    {
                        _scriptsCache = new HtmlString("<!-- Google Tag Manager -->\n<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n  })(window,document,'script','dataLayer','" + settings.ContainerID + "');</script>\n<!-- End Google Tag Manager -->");
                    }
                }

                if (_scriptsCache != null)
                {
                    _resourceManager.RegisterHeadScript(_scriptsCache);
                }
            }

            await next.Invoke();
        }
コード例 #28
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                if (_scriptsCache == null)
                {
                    var settings = (await _siteService.GetSiteSettingsAsync()).As <GoogleAdSenseSettings>();

                    if (!string.IsNullOrWhiteSpace(settings?.PublisherID))
                    {
                        _scriptsCache = new HtmlString($"\n<script async src=\"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js\"></script>");
                    }
                }

                if (_scriptsCache != null)
                {
                    _resourceManager.RegisterHeadScript(_scriptsCache);
                }
            }

            await next.Invoke();
        }
コード例 #29
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                if (_scriptsCache == null)
                {
                    var settings = (await _siteService.GetSiteSettingsAsync()).As <MatomoSettings>();

                    if (!string.IsNullOrWhiteSpace(settings?.SiteID) && !string.IsNullOrWhiteSpace(settings?.ServerUri))
                    {
                        _scriptsCache = new HtmlString($"<script>var _paq = window._paq || [];_paq.push(['trackPageView']);_paq.push(['enableLinkTracking']);_paq.push(['setTrackerUrl', 'https://{settings.ServerUri}/matomo.php']);_paq.push(['setSiteId', '{settings.SiteID}']);</script> <script src=\"https://{settings.ServerUri}/matomo.js\" async defer></script> ");
                    }
                }

                if (_scriptsCache != null)
                {
                    _resourceManager.RegisterHeadScript(_scriptsCache);
                }
            }

            await next.Invoke();
        }
コード例 #30
0
        public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
        {
            // Should only run on the front-end for a full view
            if ((context.Result is ViewResult || context.Result is PageResult) &&
                !AdminAttribute.IsApplied(context.HttpContext))
            {
                // Even if the Admin attribute is not applied we might be using the admin theme, for instance in Login views.
                // In this case don't render Layers.
                var selectedTheme = (await _themeManager.GetThemeAsync())?.Id;
                var adminTheme    = await _adminThemeService.GetAdminThemeNameAsync();

                if (selectedTheme == adminTheme)
                {
                    await next.Invoke();

                    return;
                }

                var widgets = await _memoryCache.GetOrCreateAsync("OrchardCore.Layers.LayerFilter:AllWidgets", entry =>
                {
                    entry.AddExpirationToken(_signal.GetToken(LayerMetadataHandler.LayerChangeToken));
                    return(_layerService.GetLayerWidgetsAsync(x => x.Published));
                });

                var layers = (await _layerService.GetLayersAsync()).Layers.ToDictionary(x => x.Name);

                dynamic layout = await _layoutAccessor.GetLayoutAsync();

                var updater = _modelUpdaterAccessor.ModelUpdater;

                var engine = _scriptingManager.GetScriptingEngine("js");
                var scope  = engine.CreateScope(_scriptingManager.GlobalMethodProviders.SelectMany(x => x.GetMethods()), _serviceProvider, null, null);

                var layersCache = new Dictionary <string, bool>();

                foreach (var widget in widgets)
                {
                    var layer = layers[widget.Layer];

                    if (layer == null)
                    {
                        continue;
                    }

                    bool display;
                    if (!layersCache.TryGetValue(layer.Name, out display))
                    {
                        if (String.IsNullOrEmpty(layer.Rule))
                        {
                            display = false;
                        }
                        else
                        {
                            display = Convert.ToBoolean(engine.Evaluate(scope, layer.Rule));
                        }

                        layersCache[layer.Rule] = display;
                    }

                    if (!display)
                    {
                        continue;
                    }

                    var widgetContent = await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, updater);

                    widgetContent.Classes.Add("widget");
                    widgetContent.Classes.Add("widget-" + widget.ContentItem.ContentType.HtmlClassify());

                    var wrapper = new WidgetWrapper
                    {
                        Widget  = widget.ContentItem,
                        Content = widgetContent
                    };

                    wrapper.Metadata.Alternates.Add("Widget_Wrapper__" + widget.ContentItem.ContentType);
                    wrapper.Metadata.Alternates.Add("Widget_Wrapper__Zone__" + widget.Zone);

                    var contentZone = layout.Zones[widget.Zone];
                    contentZone.Add(wrapper);
                }
            }

            await next.Invoke();
        }