/// <summary> /// Gets the cache object associated with this Entity /// </summary> /// <returns></returns> public IEntityCache GetCacheObject() { return(LavaShortcodeCache.Get(this.Id)); }
/// <summary> /// Renders the specified context. /// </summary> /// <param name="context">The context.</param> /// <param name="result">The result.</param> public override void Render(Context context, TextWriter result) { // get enabled security commands if (context.Registers.ContainsKey("EnabledCommands")) { _enabledSecurityCommands = context.Registers["EnabledCommands"].ToString(); } var shortcode = LavaShortcodeCache.Get(_shortcode.Id); if (shortcode != null) { var parms = ParseMarkup(_markup, context); // add a unique id so shortcodes have easy access to one parms.AddOrReplace("uniqueid", "id-" + Guid.NewGuid().ToString()); // keep track of the recursion depth int currentRecurrsionDepth = 0; if (parms.ContainsKey("RecursionDepth")) { currentRecurrsionDepth = parms["RecursionDepth"].ToString().AsInteger() + 1; if (currentRecurrsionDepth > _maxRecursionDepth) { result.Write("A recursive loop was detected and processing of this shortcode has stopped."); return; } } parms.AddOrReplace("RecursionDepth", currentRecurrsionDepth); var lavaTemplate = shortcode.Markup; var blockMarkup = _blockMarkup.ToString().ResolveMergeFields(_internalMergeFields, _enabledSecurityCommands); // pull child parameters from block content Dictionary <string, object> childParamters; blockMarkup = GetChildParameters(blockMarkup, out childParamters); foreach (var item in childParamters) { parms.AddOrReplace(item.Key, item.Value); } // merge the block markup in if (blockMarkup.IsNotNullOrWhiteSpace()) { Regex rgx = new Regex(@"{{\s*blockContent\s*}}", RegexOptions.IgnoreCase); lavaTemplate = rgx.Replace(lavaTemplate, blockMarkup); parms.AddOrReplace("blockContentExists", true); } else { parms.AddOrReplace("blockContentExists", false); } // next ensure they did not use any entity commands in the block that are not allowed // this is needed as the shortcode it configured to allow entities for processing that // might allow more entities than the source block, template, action, etc allows var securityCheck = blockMarkup.ResolveMergeFields(new Dictionary <string, object>(), _enabledSecurityCommands); Regex securityPattern = new Regex(String.Format(RockLavaBlockBase.NotAuthorizedMessage, ".*")); Match securityMatch = securityPattern.Match(securityCheck); if (securityMatch.Success) { result.Write(securityMatch.Value); // return security error message } else { if (shortcode.EnabledLavaCommands.IsNotNullOrWhiteSpace()) { _enabledSecurityCommands = shortcode.EnabledLavaCommands; } var results = lavaTemplate.ResolveMergeFields(parms, _enabledSecurityCommands); result.Write(results.Trim()); base.Render(context, result); } } else { result.Write($"An error occurred while processing the {0} shortcode.", _tagName); } }