public void Displayed(ShapeDisplayedContext context) { if (context.ShapeMetadata.Type.Equals("Zone")) { return; } this.profiler.StepStop(StepKeys.ShapeProfiling); }
public void Displayed(ShapeDisplayedContext context) { // TODO: Configure duration of sliding expiration var cacheContext = context.ShapeMetadata.Cache(); // If the shape is not cached, evaluate the ESIs if (cacheContext == null) { string content; using (var sw = new StringWriter()) { context.ChildContent.WriteTo(sw, HtmlEncoder.Default); content = sw.ToString(); } ProcessESIs(ref content, GetDistributedCache); context.ChildContent = new HtmlString(content); } else if (!_cached.Contains(cacheContext) && context.ChildContent != null) { var cacheEntries = GetCacheEntries(cacheContext).ToList(); string cacheKey = GetCacheKey(cacheContext.CacheId, cacheEntries); using (var sw = new StringWriter()) { context.ChildContent.WriteTo(sw, HtmlEncoder.Default); var content = sw.ToString(); _cached.Add(cacheContext); _cache[cacheKey] = content; var contexts = String.Join(ContextSeparator.ToString(), cacheContext.Contexts.ToArray()); context.ChildContent = new HtmlString($"[[cache id='{cacheContext.CacheId}' contexts='{contexts}']]"); var bytes = Encoding.UTF8.GetBytes(content); // Default duration is sliding expiration (permanent as long as it's used) DistributedCacheEntryOptions options = new DistributedCacheEntryOptions { SlidingExpiration = new TimeSpan(0, 1, 0) }; // If a custom duration is specified, replace the default options if (cacheContext.Duration.HasValue) { options = new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = cacheContext.Duration }; } _dynamicCache.SetAsync(cacheKey, bytes, options).Wait(); _tagCache.Tag(cacheKey, cacheContext.Tags.ToArray()); } } }
public void Displayed(ShapeDisplayedContext context) { }
public void OnDisplayed(ShapeDisplayedContext context) { this.profiler.StepStop(StepKeys.ShapeProfiling); }
void IShapeDisplayEvents.Displayed(ShapeDisplayedContext context) { Displayed(context); }
public IHtmlString Execute(DisplayContext context) { var shape = _convertAsShapeCallsite.Target(_convertAsShapeCallsite, context.Value); // non-shape arguments are returned as a no-op if (shape == null) { return(CoerceHtmlString(context.Value)); } var shapeMetadata = shape.Metadata; // can't really cope with a shape that has no type information if (shapeMetadata == null || string.IsNullOrEmpty(shapeMetadata.Type)) { return(CoerceHtmlString(context.Value)); } var result = _performanceMonitor.PublishTimedAction(() => { var workContext = _workContextAccessor.GetContext(context.ViewContext); var shapeTable = _shapeTableLocator.Value.Lookup(workContext.CurrentTheme.Id); var displayingContext = new ShapeDisplayingContext { Shape = shape, ShapeMetadata = shapeMetadata }; _shapeDisplayEvents.Invoke(sde => sde.Displaying(displayingContext), Logger); // find base shape association using only the fundamental shape type. // alternates that may already be registered do not affect the "displaying" event calls ShapeBinding shapeBinding; if (TryGetDescriptorBinding(shapeMetadata.Type, Enumerable.Empty <string>(), shapeTable, out shapeBinding)) { shapeBinding.ShapeDescriptor.Displaying.Invoke(action => action(displayingContext), Logger); // copy all binding sources (all templates for this shape) in order to use them as Localization scopes shapeMetadata.BindingSources = shapeBinding.ShapeDescriptor.BindingSources.Where(x => x != null).ToList(); if (!shapeMetadata.BindingSources.Any()) { shapeMetadata.BindingSources.Add(shapeBinding.ShapeDescriptor.BindingSource); } } // invoking ShapeMetadata displaying events shapeMetadata.Displaying.Invoke(action => action(displayingContext), Logger); // use pre-fectched content if available (e.g. coming from specific cache implmentation) if (displayingContext.ChildContent != null) { shape.Metadata.ChildContent = displayingContext.ChildContent; } else { // now find the actual binding to render, taking alternates into account ShapeBinding actualBinding; if (TryGetDescriptorBinding(shapeMetadata.Type, shapeMetadata.Alternates, shapeTable, out actualBinding)) { shape.Metadata.ChildContent = Process(actualBinding, shape, context); } else { throw new OrchardException(T("Shape type {0} not found", shapeMetadata.Type)); } } foreach (var frameType in shape.Metadata.Wrappers) { ShapeBinding frameBinding; if (TryGetDescriptorBinding(frameType, Enumerable.Empty <string>(), shapeTable, out frameBinding)) { shape.Metadata.ChildContent = Process(frameBinding, shape, context); } } var displayedContext = new ShapeDisplayedContext { Shape = shape, ShapeMetadata = shape.Metadata, ChildContent = shape.Metadata.ChildContent, }; _shapeDisplayEvents.Invoke(sde => { var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent; sde.Displayed(displayedContext); // update the child content if the context variable has been reassigned if (prior != displayedContext.ChildContent) { displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent; } }, Logger); if (shapeBinding != null) { shapeBinding.ShapeDescriptor.Displayed.Invoke(action => { var prior = displayedContext.ChildContent = displayedContext.ShapeMetadata.ChildContent; action(displayedContext); // update the child content if the context variable has been reassigned if (prior != displayedContext.ChildContent) { displayedContext.ShapeMetadata.ChildContent = displayedContext.ChildContent; } }, Logger); } // invoking ShapeMetadata displayed events shapeMetadata.Displayed.Invoke(action => action(displayedContext), Logger); return(shapeBinding); }, (r, t) => new ShapeMessage(shape.Metadata) { Duration = t.Duration, BindingName = r.BindingName, BindingSource = r.BindingSource }, TimelineCategories.Shapes, r => "Shape Displaying", r => r.BindingSource); return(shape.Metadata.ChildContent); }
public override void Displayed(ShapeDisplayedContext context) { }
public override void Displayed(ShapeDisplayedContext context) { // TODO aggiungere anche i field che usano TinyMce (verificare se serve) if (String.CompareOrdinal(context.ShapeMetadata.Type, "Body_Editor") != 0) { return; } if (!String.Equals(context.Shape.EditorFlavor, "html", StringComparison.InvariantCultureIgnoreCase)) { return; } base.Displayed(context); var settings = _orchardServices.WorkContext.CurrentSite.As <TinyMceSiteSettingsPart>(); var htmlOrig = context.ChildContent.ToHtmlString(); var plugins = _tinyMceEnhancementService.GetCorePluginsList(); var externalPlugins = ""; var scriptList = new List <string>(); if (string.IsNullOrWhiteSpace(settings.AdditionalPlugins) == false) { // external plugins example: // external_plugins: { // 'testing': 'http://www.testing.com/plugin.min.js', // 'maths': 'http://www.maths.com/plugin.min.js' // } var namesList = settings.AdditionalPlugins.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var pluginList = new List <string>(); var serverRelativeUrlBase = string.IsNullOrWhiteSpace(HttpContext.Current.Request.ApplicationPath) ? "" : "/" + HttpContext.Current.Request.ApplicationPath.TrimStart('/'); foreach (var item in namesList) { if (item.Contains('/')) { //scriptList.Add($"<script src=\"{serverRelativeUrlBase}/Modules/Laser.Orchard.StartupConfig/Scripts/tinymceplugins/{item}\" type=\"text/javascript\"></script>"); var pluginName = item.Split('/')[0]; pluginList.Add($"'{pluginName}': '{serverRelativeUrlBase}/Modules/Laser.Orchard.StartupConfig/Scripts/tinymceplugins/{item}'"); } else { pluginList.Add($"'{item}': '{serverRelativeUrlBase}/Modules/Laser.Orchard.StartupConfig/Scripts/tinymceplugins/{item}/plugin.min.js'"); } } externalPlugins = @", external_plugins: { " + string.Join(",\r\n", pluginList) + @" }"; } var init = ""; if (string.IsNullOrWhiteSpace(settings.InitScript)) { init = _tinyMceEnhancementService.GetDefaultInitScript(); } else { init = settings.InitScript + @", plugins: [""" + plugins + @"""]"; } var additionalScripts = new StringBuilder(); foreach (var script in scriptList) { additionalScripts.AppendLine(script); } var html = @"<script type=""text/javascript""> $(function() { tinyMCE.init({ " + init + externalPlugins + @", " + Constants.DefaultSetup + @" }); }); </script> " + additionalScripts.ToString() + htmlOrig; context.ChildContent = new HtmlString(html); }
private void FrontendDisplayed(ShapeDisplayedContext context, TinyMceSiteSettingsPart settings) { var htmlOrig = context.ChildContent.ToHtmlString(); var plugins = _tinyMceEnhancementService.GetFrontendCorePluginsList(); var externalPlugins = ""; var scriptList = new List <string>(); // There are two different AdditionalPlugins fields: // - AdditionalPlugins are used for backoffice plugins // - FrontendAdditionalPlugins are used for frontend content edit (in this case, plugins needing admin panel access authorization need to be disabled) var additionalPlugins = settings.FrontendAdditionalPlugins; if (!string.IsNullOrWhiteSpace(additionalPlugins)) { // external plugins example: // external_plugins: { // 'testing': 'http://www.testing.com/plugin.min.js', // 'maths': 'http://www.maths.com/plugin.min.js' // } var namesList = additionalPlugins.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); var pluginList = new List <string>(); var serverRelativeUrlBase = string.IsNullOrWhiteSpace(HttpContext.Current.Request.ApplicationPath) ? "" : "/" + HttpContext.Current.Request.ApplicationPath.TrimStart('/'); foreach (var item in namesList) { if (item.Contains('/')) { //scriptList.Add($"<script src=\"{serverRelativeUrlBase}/Modules/Laser.Orchard.StartupConfig/Scripts/tinymceplugins/{item}\" type=\"text/javascript\"></script>"); var pluginName = item.Split('/')[0]; pluginList.Add($"'{pluginName}': '{serverRelativeUrlBase}/Modules/Laser.Orchard.StartupConfig/Scripts/tinymceplugins/{item}'"); } else { pluginList.Add($"'{item}': '{serverRelativeUrlBase}/Modules/Laser.Orchard.StartupConfig/Scripts/tinymceplugins/{item}/plugin.min.js'"); } } externalPlugins = @", external_plugins: { " + string.Join(",\r\n", pluginList) + @" }"; } var init = ""; // There are two different InitScript fields: // - InitScript is used for backoffice plugins // - FrontendInitScript is used for frontend content edit (in this case, plugins needing admin panel access authorization need to be disabled) var initScript = settings.FrontendInitScript; if (string.IsNullOrWhiteSpace(initScript)) { init = _tinyMceEnhancementService.GetFrontendDefaultInitScript(); } else { init = initScript + @", plugins: [""" + plugins + @"""]"; } var additionalScripts = new StringBuilder(); foreach (var script in scriptList) { additionalScripts.AppendLine(script); } var html = @"<script type=""text/javascript""> $(function() { tinyMCE.init({ " + init + externalPlugins + @", " + Constants.FrontendDefaultSetup + @" }); }); </script> " + additionalScripts.ToString() + htmlOrig; context.ChildContent = new HtmlString(html); }