public void OnResultExecuting(ResultExecutingContext context)
            {
                if (!_privacySettings.DisplayGdprConsentOnForms)
                {
                    return;
                }

                if (context.HttpContext.Items.Keys.Contains("GdprConsentRendered"))
                {
                    return;
                }

                var result = context.Result;

                // should only run on a full view rendering result or HTML ContentResult
                if (!result.IsHtmlViewResult())
                {
                    return;
                }

                _widgetProvider.RegisterWidget("gdpr_consent",
                                               new ComponentWidgetInvoker("GdprConsent", new { isSmall = false }));

                _widgetProvider.RegisterWidget("gdpr_consent_small",
                                               new ComponentWidgetInvoker("GdprConsent", new { isSmall = true }));

                context.HttpContext.Items["GdprConsentRendered"] = true;
            }
Exemple #2
0
 /// <summary>
 /// Registers custom HTML content for multiple widget zones by pattern
 /// </summary>
 /// <param name="zones">The widget zone pattern to inject the HTML content to</param>
 /// <param name="html">HTML to inject</param>
 /// <param name="order">Sort order within the specified widget zones</param>
 public static void RegisterHtml(this IWidgetProvider provider, Regex zonePattern, IHtmlContent html, int order = 0)
 {
     provider.RegisterWidget(zonePattern, new HtmlWidgetInvoker(html)
     {
         Order = order
     });
 }
Exemple #3
0
 /// <summary>
 /// Registers custom HTML content for widget zones
 /// </summary>
 /// <param name="zones">The names of the widget zones to inject the HTML content to</param>
 /// <param name="html">HTML to inject</param>
 /// <param name="order">Sort order within the specified widget zones</param>
 public static void RegisterHtml(this IWidgetProvider provider, string[] zones, IHtmlContent html, int order = 0)
 {
     provider.RegisterWidget(zones, new HtmlWidgetInvoker(html)
     {
         Order = order
     });
 }
Exemple #4
0
        protected override async Task ProcessCoreAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.SuppressOutput();

            if (Target.IsEmpty())
            {
                return;
            }

            if (Key.HasValue())
            {
                var uniqueKeys = GetUniqueKeys();
                if (uniqueKeys.Contains(Key))
                {
                    return;
                }
                uniqueKeys.Add(Key);
            }

            var childContent = await output.GetChildContentAsync();

            var widget = new HtmlWidgetInvoker(childContent)
            {
                Order = Ordinal
            };

            _widgetProvider.RegisterWidget(Target, widget);
        }
Exemple #5
0
 /// <summary>
 /// Registers custom HTML content for a single widget zone
 /// </summary>
 /// <param name="zone">The name of the widget zones to inject the HTML content to</param>
 /// <param name="html">HTML to inject</param>
 /// <param name="order">Sort order within the specified widget zone</param>
 public static void RegisterHtml(this IWidgetProvider provider, string zone, IHtmlContent html, int order = 0)
 {
     Guard.NotEmpty(zone, nameof(zone));
     provider.RegisterWidget(new[] { zone }, new HtmlWidgetInvoker(html)
     {
         Order = order
     });
 }
Exemple #6
0
        protected override async Task ProcessCoreAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (TargetZone.IsEmpty())
            {
                output.SuppressOutput();
                return;
            }

            if (output.Attributes.ContainsName("data-origin"))
            {
                var origin = output.Attributes["data-origin"];
                var x      = origin;
            }

            if (Key.HasValue() && _widgetProvider.ContainsWidget(TargetZone, Key))
            {
                output.SuppressOutput();
                return;
            }

            TagHelperContent childContent = await output.GetChildContentAsync();

            TagHelperContent content;

            if (output.TagName == "widget")
            {
                if (childContent.IsEmptyOrWhiteSpace)
                {
                    output.SuppressOutput();
                    return;
                }

                // Never render <widget> tag, only the content
                output.TagName = null;
                content        = childContent;
            }
            else
            {
                output.Content.SetHtmlContent(childContent);
                content = new DefaultTagHelperContent();
                output.CopyTo(content);
            }

            output.SuppressOutput();

            if (!content.IsEmptyOrWhiteSpace)
            {
                var widget = new HtmlWidgetInvoker(content)
                {
                    Order = Ordinal, Prepend = Prepend, Key = Key
                };
                _widgetProvider.RegisterWidget(TargetZone, widget);
            }
        }
        protected override async Task ProcessCoreAsync(TagHelperContext context, TagHelperOutput output)
        {
            output.SuppressOutput();

            Action ??= ConfirmType == ConfirmActionType.Delete ? "Delete" : HtmlHelper.ViewContext.RouteData.Values.GetActionName();
            Controller ??= HtmlHelper.ViewContext.RouteData.Values.GetControllerName();

            var model = new ConfirmModel
            {
                ButtonId    = ButtonId,
                FormPostUrl = _urlHelper.Action(Action, Controller),
                ConfirmType = ConfirmType,

                // Labels
                Title      = Title,
                AcceptText = AcceptText ?? (ConfirmType == ConfirmActionType.Delete ? T("Admin.Common.Delete") : T("Common.OK")),
                CancelText = CancelText ?? (ConfirmType == ConfirmActionType.Delete ? T("Admin.Common.NoCancel") : T("Common.Cancel")),
                Message    = Message ?? (ConfirmType == ConfirmActionType.Delete ? T("Admin.Common.DeleteConfirmation") : T("Admin.Common.AskToProceed")),

                // Modal setings
                Backdrop      = Backdrop,
                Center        = Center,
                CenterContent = CenterContent,
                Size          = Size,

                // Icon class & color
                IconClass   = IconClass ?? GetIconClass(ConfirmType),
                IconColor   = IconColor ?? GetIconColor(ConfirmType),
                ButtonStyle = ButtonColor ?? GetButtonStyle(ConfirmType)
            };

            if (ViewContext.ViewData.Model is EntityModelBase entityModel && entityModel.Id != 0 && ConfirmType == ConfirmActionType.Delete)
            {
                model.Id = entityModel.Id;
                // TODO: (mc) (core) This is really bad, but sufficient for the moment.
                model.EntityType = ButtonId.Replace("-delete", string.Empty);
            }

            // Render confirm dialog.
            var partial = await HtmlHelper.PartialAsync("Confirm", model, null);

            var widget = new HtmlWidgetInvoker(partial);

            _widgetProvider.RegisterWidget("end", widget);
        }
Exemple #8
0
            /// <summary>
            /// Registers actions to render user menus in widget zones.
            /// </summary>
            private async Task ProcessUserMenusAsync()
            {
                var menusInfo = await _menuStorage.GetUserMenuInfosAsync();

                foreach (var info in menusInfo)
                {
                    var widget = new ComponentWidgetInvoker("Menu", new
                    {
                        name     = info.SystemName,
                        template = info.Template
                    })
                    {
                        Order = info.DisplayOrder
                    };

                    _widgetProvider.RegisterWidget(info.WidgetZones, widget);
                }
            }
Exemple #9
0
        // TODO: (core) Implement IWidgetProviderExtensions.RegisterViewComponent()

        /// <summary>
        /// Registers a custom widget for a single widget zone.
        /// </summary>
        /// <param name="zone">The name of the widget zone to inject the HTML content to</param>
        /// <param name="widget">Widget to register</param>
        public static void RegisterWidget(this IWidgetProvider provider, string zone, WidgetInvoker widget)
        {
            Guard.NotEmpty(zone, nameof(zone));
            provider.RegisterWidget(new[] { zone }, widget);
        }
        protected override async Task ProcessCoreAsync(TagHelperContext context, TagHelperOutput output)
        {
            if (TargetZone.IsEmpty())
            {
                output.SuppressOutput();
                return;
            }

            if (Key.HasValue() && _widgetProvider.ContainsWidget(TargetZone, Key))
            {
                output.SuppressOutput();
                return;
            }

            if (ViewContext.HttpContext.Request.IsAjaxRequest())
            {
                // Don't re-inject content during AJAX requests, the target zones are most probably rendered already.
                // Just output the content in-place.
                if (output.TagName == "widget")
                {
                    output.TagName = null;
                }
                else if (output.TagName == "meta")
                {
                    output.SuppressOutput();
                }

                return;
            }

            TagHelperContent childContent = await output.GetChildContentAsync();

            TagHelperContent content;

            if (output.TagName == "widget")
            {
                if (childContent.IsEmptyOrWhiteSpace)
                {
                    output.SuppressOutput();
                    return;
                }

                // Never render <widget> tag, only the content
                output.TagName = null;
                content        = childContent;
            }
            else
            {
                output.Content.SetHtmlContent(childContent);
                content = new DefaultTagHelperContent();
                output.CopyTo(content);
            }

            output.SuppressOutput();

            if (!content.IsEmptyOrWhiteSpace)
            {
                var widget = new HtmlWidgetInvoker(content)
                {
                    Order = Ordinal, Prepend = Prepend, Key = Key
                };
                _widgetProvider.RegisterWidget(TargetZone, widget);
            }
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            var store                = Services.StoreContext.CurrentStore;
            var taxDisplayType       = Services.WorkContext.GetTaxDisplayTypeFor(Services.WorkContext.CurrentCustomer, store.Id);
            var taxInfo              = T(taxDisplayType == TaxDisplayType.IncludingTax ? "Tax.InclVAT" : "Tax.ExclVAT");
            var availableStoreThemes = !_themeSettings.AllowCustomerToSelectTheme
                ? new List <StoreThemeModel>()
                : _themeRegistry.GetThemeManifests()
                                       .Select(x =>
            {
                return(new StoreThemeModel
                {
                    Name = x.ThemeName,
                    Title = x.ThemeTitle
                });
            })
                                       .ToList();

            var model = new FooterModel
            {
                StoreName           = store.Name,
                ShowLegalInfo       = _taxSettings.ShowLegalHintsInFooter,
                ShowThemeSelector   = availableStoreThemes.Count > 1,
                HideNewsletterBlock = _customerSettings.HideNewsletterBlock,
                ShowSocialLinks     = _socialSettings.ShowSocialLinksInFooter,
                FacebookLink        = _socialSettings.FacebookLink,
                TwitterLink         = _socialSettings.TwitterLink,
                PinterestLink       = _socialSettings.PinterestLink,
                YoutubeLink         = _socialSettings.YoutubeLink,
                InstagramLink       = _socialSettings.InstagramLink,
            };

            var shippingInfoUrl = await Url.TopicAsync("shippinginfo");

            if (shippingInfoUrl.HasValue())
            {
                model.LegalInfo = T("Tax.LegalInfoFooter", taxInfo, shippingInfoUrl);
            }
            else
            {
                model.LegalInfo = T("Tax.LegalInfoFooter2", taxInfo);
            }

            var hint = Services.Settings.GetSettingByKey("Rnd_SmCopyrightHint", string.Empty, store.Id);

            if (hint.IsEmpty())
            {
                hint = _hints[CommonHelper.GenerateRandomInteger(0, _hints.Length - 1)];

                await Services.Settings.ApplySettingAsync("Rnd_SmCopyrightHint", hint, store.Id);

                await Services.DbContext.SaveChangesAsync();
            }

            model.SmartStoreHint = $"<a href='https://www.smartstore.com/' class='sm-hint' target='_blank'><strong>{hint}</strong></a> by SmartStore AG &copy; {DateTime.Now.Year}";

            if (ShouldRenderGDPR())
            {
                _widgetProvider.RegisterWidget("gdpr_consent_small",
                                               new ComponentWidgetInvoker("GdprConsent", new { isSmall = true }));

                HttpContext.Items["GdprConsentRendered"] = true;
            }

            return(View(model));
        }