private static IEnumerable <Item> GetMultiVariateTestDataSourceItems(this RenderingReference reference)
        {
            var list = new List <Item>();

            if (reference != null && !string.IsNullOrEmpty(reference.Settings.MultiVariateTest))
            {
                using (new SecurityDisabler())
                {
                    // Sitecore 7 to Sitecore 8:
                    //var mvVariateTestForLang = Sitecore.Analytics.Testing.TestingUtils.TestingUtil.MultiVariateTesting.GetVariableItem(reference);

                    // Sitecore 8.1 and above:
                    var contentTestStore     = new Sitecore.ContentTesting.Data.SitecoreContentTestStore();
                    var mvVariateTestForLang = contentTestStore.GetMultivariateTestVariable(reference, reference.Language);

                    var variableItem = (mvVariateTestForLang != null) ? mvVariateTestForLang.InnerItem : null;
                    if (variableItem == null)
                    {
                        return(list);
                    }
                    foreach (Item mvChild in variableItem.Children)
                    {
                        var mvDataSourceItem = mvChild.GetInternalLinkFieldItem("Datasource");
                        if (mvDataSourceItem != null)
                        {
                            list.Add(mvDataSourceItem);
                        }
                    }
                }
            }
            return(list);
        }
        protected override void ApplyVariation(CustomizeRenderingArgs args, ComponentTestContext context)
        {
            // Begin copied from sitecore
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(context, "context");
            ComponentTestRunner componentTestRunner = new ComponentTestRunner();

            try
            {
                componentTestRunner.Run(context);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                string    str       = (ItemUtil.IsNull(context.Component.RenderingID) ? string.Empty : context.Component.RenderingID.ToString());
                string    str1      = (args.PageContext.Item != null ? args.PageContext.Item.ID.ToString() : string.Empty);
                Log.Warn("Failed to execute MV testing on component with id \"{0}\". Item ID:\"{1}\"".FormatWith(new object[] { str, str1 }), exception, this);
            }
            RenderingReference renderingReference = context.Components.FirstOrDefault <RenderingReference>((RenderingReference c) => c.UniqueId == context.Component.UniqueId);

            if (renderingReference == null)
            {
                args.Renderer = new EmptyRenderer();
                return;
            }
            this.ApplyChanges(args.Rendering, renderingReference);
            // End copied from sitecore

            // Apply Parameters Too
            TransferRenderingParameters(args.Rendering, renderingReference);
        }
Ejemplo n.º 3
0
        private static IEnumerable <Item> GetMultiVariateTestDataSources(this RenderingReference reference)
        {
            var list = new List <Item>();

            if (reference != null && !string.IsNullOrEmpty(reference.Settings.MultiVariateTest))
            {
                using (new SecurityDisabler())
                {
                    var testStore = new Sitecore.ContentTesting.Data.SitecoreContentTestStore();
                    var tests     = testStore.GetMultivariateTestVariable(reference, reference.Language);

                    if (tests != null && tests.InnerItem != null)
                    {
                        foreach (Item child in tests.InnerItem.Children)
                        {
                            var datasource = child.GetInternalLinkFieldItem("Datasource");
                            if (datasource != null)
                            {
                                list.Add(datasource);
                            }
                        }
                    }
                }
            }
            return(list);
        }
 public GetCompatibleRenderingsRuleContext(RenderingReference currentRendering, IEnumerable <ID> compatibleRenderings, Item item)
     : base(currentRendering == null ? ID.Null : currentRendering.RenderingID)
 {
     CurrentRendering     = currentRendering;
     CompatibleRenderings = new List <ID>(compatibleRenderings);
     Item = item;
 }
        /// <summary>
        /// Renders the control page design mode.
        ///
        /// </summary>
        /// <param name="output">The output.</param><param name="isDesignAllowed">if set to <c>true</c> [is design allowed].</param><param name="control">The control.</param>
        private void RenderControlPageDesignMode(HtmlTextWriter output, bool isDesignAllowed, Control control)
        {
            Assert.ArgumentNotNull((object)output, "output");
            Assert.ArgumentNotNull((object)control, "control");
            RenderingReference renderingReference = Client.Page.GetRenderingReference(control);
            bool flag = false;

            if (renderingReference != null)
            {
                string uniqueId = renderingReference.UniqueId;
                if (Sitecore.Data.ID.IsID(uniqueId))
                {
                    string controlId = ShortID.Encode(uniqueId);
                    Item   obj       = this.GetItem();
                    Assert.IsNotNull((object)obj, "item");
                    ChromeData controlData = Placeholder72.GetControlData(renderingReference, obj);
                    output.Write(Placeholder72.GetControlStartMarker(controlId, controlData, isDesignAllowed));
                    control.RenderControl(output);
                    output.Write(Placeholder72.GetControlEndMarker(controlData));
                    flag = true;
                }
            }
            if (flag)
            {
                return;
            }
            control.RenderControl(output);
        }
Ejemplo n.º 6
0
        public override void Apply(T ruleContext)
        {
            if (RenderingId != null)
            {
                Assert.IsNotNullOrEmpty(RenderingId, "RenderingID");
                if (RenderingId != null)
                {
                    var rendering = Context.Database.GetItem(RenderingId);
                    if (rendering != null)
                    {
                        Assert.IsNotNull(rendering, "rendering");

                        if (rendering != null)
                        {
                            var rendRef = new RenderingReference(rendering);

                            if (!String.IsNullOrEmpty(Placeholder) && String.Compare(Placeholder, "specific", StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                rendRef.Placeholder = Placeholder;
                            }

                            if (ruleContext != null)
                            {
                                ruleContext.References.Add(rendRef);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private static RenderingReference GetRenderingByItemId(Guid itemId, string placeholder)
        {
            var renderingItem = (RenderingItem)Context.Database.GetItem(new ID(itemId));

            if (renderingItem == null)
            {
                return(null);
            }

            var renderingReference = new RenderingReference(renderingItem);

            renderingReference.Settings.Caching          = renderingItem.Caching;
            renderingReference.Settings.Conditions       = renderingItem.Conditions;
            renderingReference.Settings.DataSource       = renderingItem.DataSource;
            renderingReference.Settings.MultiVariateTest = renderingItem.MultiVariateTest;
            renderingReference.Settings.Parameters       = renderingItem.Parameters;
            renderingReference.Settings.Placeholder      = renderingItem.Placeholder;

            if (!string.IsNullOrWhiteSpace(placeholder))
            {
                renderingReference.Placeholder = placeholder;
            }

            return(renderingReference);
        }
        private static void GetCustomRules(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item, RenderingReference reference)
        {
            string configId = Sitecore.Configuration.Settings.GetSetting("customRulesConfigFolder");
            if (string.IsNullOrEmpty(configId))
            {
                Error("Sitecore setting 'customRulesConfigFolder' not found", args.ContextItem);
                return;
            }
            Database db = Sitecore.Context.ContentDatabase ?? Sitecore.Context.Database;
            Item configFolder = db.GetItem(configId);
            if (configFolder == null)
            {
                Error(string.Format("Config folder {0} not found", configId), args.ContextItem);
                return;
            }

            if (configFolder.HasChildren && configFolder.Children.Any(r => !string.IsNullOrEmpty(r["rendering"]) && new ID(r["rendering"]) == reference.RenderingID))
            {
                Item configItem = configFolder.Children.First(r => new ID(r["rendering"]) == reference.RenderingID);
                Item datasourceItem = db.GetItem(configItem["item"]);
                if (datasourceItem == null)
                {
                    Error(string.Format("No Item containing rules set on config item at {0}", configItem.Paths.FullPath), args.ContextItem);
                    return;
                }
                string fieldName = configItem["rule field"];
                RunPromoRule(args, item, reference, datasourceItem, fieldName);
            }
        }
        protected override void Evaluate(CustomizeRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.PageContext.Item;

            if (item != null)
            {
                RenderingReference    renderingReference    = CustomizeRenderingProcessor.GetRenderingReference(args.Rendering, Context.Language, args.PageContext.Database);
                GetRenderingRulesArgs getRenderingRulesArgs = new GetRenderingRulesArgs(item, renderingReference);
                GetRenderingRulesPipeline.Run(getRenderingRulesArgs);
                RuleList <ConditionalRenderingsRuleContext> ruleList = getRenderingRulesArgs.RuleList;
                if (ruleList != null && ruleList.Count != 0)
                {
                    List <RenderingReference> references = new List <RenderingReference>
                    {
                        renderingReference
                    };
                    ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(references, renderingReference)
                    {
                        Item = item
                    };
                    conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;
                    RunRules(ruleList, conditionalRenderingsRuleContext);
                    ApplyActions(args, conditionalRenderingsRuleContext);
                    args.IsCustomized = true;
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// This function is responsible for pulling the actual Rendering for current device that's loaded and
        /// essentially
        /// </summary>
        /// <param name="rootItem">The root item in which we need to get the child items to render.</param>
        /// <param name="placeholder">The place holder in which we want to place the child items into.</param>
        private void RenderChildItems(Item rootItem, PlaceHolder placeholder)
        {
            rootItem.GetChildren()
            .ToList()
            .ForEach(item =>
            {
                // We need to get the path of the actual Sublayout's path
                // First we need to get the device's rendering for this child item (assume the first returned rendering)
                RenderingReference renderingReference = item
                                                        .Visualization
                                                        .GetRenderings(Sitecore.Context.Device, false)
                                                        .First();

                // Now, get the actual sublayout item itself
                Item sublayoutItem = Sitecore.Context.Database
                                     .GetItem(renderingReference.RenderingID);

                // Create a new sublayout with the sublayout's path and data item path.
                Sublayout sublayout = new Sublayout
                {
                    Path       = sublayoutItem["Path"],
                    DataSource = item.Paths.Path
                };

                // now place this sublayout on the grid.
                placeholder.Controls.Add(sublayout);
            });
        }
Ejemplo n.º 11
0
 private static string GetDisplayName(RenderingReference rendering)
 {
     return((rendering.RenderingItem != null &&
             !string.IsNullOrEmpty(rendering.RenderingItem.DisplayName))
                ? rendering.RenderingItem.DisplayName
                : string.Empty);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a Sublayout that supports the Rendering for the specified item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static Sublayout GetSublayoutForItem(Sitecore.Data.Items.Item item)
        {
            RenderingReference rendering =
                item.Visualization.GetRenderings(Sitecore.Context.Device, false).FirstOrDefault();

            if (null != rendering)
            {
                var sublayout = new Sublayout();

                sublayout.DataSource = item.ID.ToString();
                sublayout.Path       = rendering.RenderingItem.InnerItem["Path"];
                sublayout.Cacheable  = rendering.RenderingItem.Caching.Cacheable;

                // Copy cache settings
                if (rendering.RenderingItem.Caching.Cacheable)
                {
                    sublayout.VaryByData        = rendering.RenderingItem.Caching.VaryByData;
                    sublayout.VaryByDevice      = rendering.RenderingItem.Caching.VaryByDevice;
                    sublayout.VaryByLogin       = rendering.RenderingItem.Caching.VaryByLogin;
                    sublayout.VaryByParm        = rendering.RenderingItem.Caching.VaryByParm;
                    sublayout.VaryByQueryString = rendering.RenderingItem.Caching.VaryByQueryString;
                    sublayout.VaryByUser        = rendering.RenderingItem.Caching.VaryByUser;
                }

                return(sublayout);
            }

            return(null);
        }
        /// <summary>
        /// Gets the control data.
        ///
        /// </summary>
        /// <param name="reference">The reference.</param><param name="item">The item.</param>
        /// <returns>
        /// The chrome data.
        /// </returns>
        public static ChromeData GetControlData(RenderingReference reference, Item item)
        {
            Assert.ArgumentNotNull((object)reference, "reference");
            Assert.ArgumentNotNull((object)item, "item");
            Item obj = item;

            if (!string.IsNullOrEmpty(reference.Settings.DataSource))
            {
                if (MainUtil.IsFullPath(reference.Settings.DataSource))
                {
                    if (Sitecore.Context.Database != null)
                    {
                        obj = Sitecore.Context.Database.GetItem(reference.Settings.DataSource);
                    }
                }
                else
                {
                    obj = item.Axes.GetItem(reference.Settings.DataSource);
                }
            }
            GetChromeDataArgs args = new GetChromeDataArgs("rendering", obj ?? item);

            args.CustomData["renderingReference"] = (object)reference;
            GetChromeDataPipeline.Run(args);
            return(args.ChromeData);
        }
        protected virtual void Evaluate(CustomizeRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.PageContext.Item;

            if (item != null)
            {
                RenderingReference    renderingReference    = GetRenderingReference(args.Rendering, args.Rendering.Item.Language, args.Rendering.Item.Database);
                GetRenderingRulesArgs getRenderingRulesArgs = new GetRenderingRulesArgs(item, renderingReference);
                GetRenderingRulesPipeline.Run(getRenderingRulesArgs);
                RuleList <ConditionalRenderingsRuleContext> ruleList = getRenderingRulesArgs.RuleList;
                if (ruleList != null && ruleList.Count != 0)
                {
                    List <RenderingReference> references = new List <RenderingReference>
                    {
                        renderingReference
                    };
                    ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(references, renderingReference)
                    {
                        Item = item
                    };
                    conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;
                    var matchingRule = GetMatchingRule(ruleList, conditionalRenderingsRuleContext);
                    ApplyActions(args, conditionalRenderingsRuleContext, matchingRule);
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets rendering data source based on cascaded value or the item specified.
        /// </summary>
        /// <param name="renderingReference"></param>
        private void SetRenderingDataSource(RenderingReference rendering)
        {
            var parameters = WebUtil.ParseQueryString(rendering.Settings.Parameters);

            if (DataSourceIsEmpty(rendering.Settings.DataSource) && parameters.ContainsKey(Cascade))
            {
                RenderingReference renderingOnOtherItem = null;

                var shouldCascade = parameters[Cascade];

                /* If not, check if 'cascade' is checked */

                if ("1".Equals(shouldCascade))
                {
                    RenderingReference remoteItemRendering = GetRemoteItemRendering(parameters, rendering);

                    /* Otherwise loop through ancestors */

                    if (remoteItemRendering == null)
                    {
                        renderingOnOtherItem = FindRenderingOnAncestor(Context.Item.Parent, rendering);

                        if (renderingOnOtherItem != null)
                        {
                            rendering.Settings.DataSource = renderingOnOtherItem.Settings.DataSource;
                        }
                    }
                    else
                    {
                        rendering.Settings.DataSource = remoteItemRendering.Settings.DataSource;
                    }
                }
            }
        }
 public static Item GetDataSourceItem(this RenderingReference reference)
 {
     if (reference != null)
     {
         return GetDataSourceItem(reference.Settings.DataSource, reference.Database);
     }
     return null;
 }
 public static Item GetDataSourceItem(this RenderingReference reference, Language itemLanguage)
 {
     if (reference != null)
     {
         return(GetDataSourceItem(reference.Settings.DataSource, reference.Database, itemLanguage));
     }
     return(null);
 }
        private static bool IncludeRendering(RenderingReference rendering)
        {
            if (rendering == null)
            {
                return(false);
            }

            return(!string.IsNullOrEmpty(rendering.Settings.DataSource));
        }
        private void InjectScript(Literal literal)
        {
            RenderingReference reference = new RenderingReference(literal)
            {
                Placeholder = "webedit",
                AddToFormIfUnused = true
            };

            Sitecore.Context.Page.AddRendering(reference);
        }
        private static IEnumerable <Item> GetPersonalizationDataSourceItem(this RenderingReference reference)
        {
            var list = new List <Item>();

            if (reference != null && reference.Settings.Rules != null && reference.Settings.Rules.Count > 0)
            {
                list.AddRange(reference.Settings.Rules.Rules.SelectMany(r => r.Actions).OfType <SetDataSourceAction <ConditionalRenderingsRuleContext> >().Select(setDataSourceAction => GetDataSourceItem(setDataSourceAction.DataSource, reference.Database)).Where(dataSourceItem => dataSourceItem != null));
            }
            return(list);
        }
 private static void RunPromoRule(Sitecore.Pipelines.InsertRenderings.InsertRenderingsArgs args, Sitecore.Data.Items.Item item, RenderingReference reference, Item promo, string fieldName)
 {
     if (promo != null && !string.IsNullOrEmpty(fieldName))
     {
         RuleList<ConditionalRenderingsRuleContext> rules = RuleFactory.GetRules<ConditionalRenderingsRuleContext>(promo.Fields[fieldName]);
         var ruleContext = new ConditionalRenderingsRuleContext(args.Renderings, reference);
         ruleContext.Item = item;
         rules.Run(ruleContext);
     }
 }
Ejemplo n.º 22
0
        protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        {
            base.ApplyActions(args, context);
            RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);

            if (renderingReference != null)
            {
                ExtensionMethods.TransferRenderingParameters(args.Rendering, renderingReference);
            }
        }
 public override void Insert()
 {
    SiteContext site = Context.Site;
    if (((site != null) && (site.EnableWebEdit && (site.DisplayMode == DisplayMode.Edit))) && (WebUtil.GetQueryString("sc_webedit") != "0"))
    {
      RenderingReference reference = new RenderingReference(new TaxonomyScriptRegister())
        { Placeholder = "webedit", AddToFormIfUnused = true };
      Context.Page.AddRendering(reference);
    }
 }
        protected override void ApplyVariation(CustomizeRenderingArgs args, ComponentTestContext context)
        {
            base.ApplyVariation(args, context);

            RenderingReference renderingReference = context.Components.FirstOrDefault((RenderingReference c) => c.UniqueId == context.Component.UniqueId);

            if (renderingReference != null)
            {
                ExtensionMethods.TransferRenderingParameters(args.Rendering, renderingReference);
            }
        }
        //public override void Process(CustomizeRenderingArgs args)
        //{
        //    Assert.ArgumentNotNull(args, "args");
        //    if (Tracker.IsActive)
        //    {
        //        Evaluate(args);
        //    }
        //}

        //protected override void Evaluate(CustomizeRenderingArgs args)
        //{
        //    Assert.ArgumentNotNull(args, "args");
        //    Item item = args.PageContext.Item;
        //    if (item != null)
        //    {
        //        RenderingReference renderingReference = CustomizeRenderingProcessor.GetRenderingReference(args.Rendering, Context.Language, args.PageContext.Database);
        //        GetRenderingRulesArgs getRenderingRulesArgs = new GetRenderingRulesArgs(item, renderingReference);
        //        GetRenderingRulesPipeline.Run(getRenderingRulesArgs);
        //        RuleList<ConditionalRenderingsRuleContext> ruleList = getRenderingRulesArgs.RuleList;
        //        if (ruleList != null && ruleList.Count != 0)
        //        {
        //            List<RenderingReference> references = new List<RenderingReference>
        //        {
        //            renderingReference
        //        };
        //            ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(references, renderingReference)
        //            {
        //                Item = item
        //            };
        //            conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;
        //            RunRules(ruleList, conditionalRenderingsRuleContext);
        //            ApplyActions(args, conditionalRenderingsRuleContext);
        //            args.IsCustomized = true;
        //            //var matchingRule = GetMatchingRule(ruleList, conditionalRenderingsRuleContext);
        //            //ApplyActions(args, conditionalRenderingsRuleContext, matchingRule);
        //        }
        //    }
        //}

        //protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        //{
        //    Assert.ArgumentNotNull(args, "args");
        //    Assert.ArgumentNotNull(context, "context");
        //    RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);
        //    if (renderingReference == null)
        //    {
        //        args.Renderer = new EmptyRenderer();
        //    }
        //    else
        //    {
        //        ApplyChanges(args.Rendering, renderingReference);
        //    }
        //}

        ////protected virtual void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context, Rule<ConditionalRenderingsRuleContext> matchingRule)
        ////{
        ////    Assert.ArgumentNotNull(args, "args");
        ////    Assert.ArgumentNotNull(context, "context");
        ////    Assert.ArgumentNotNull(matchingRule, "matchingRule");

        ////    matchingRule.Actions?.Each(a => a.Apply(context));

        ////    var parameters = WebUtil.ParseQueryString(context.Reference.Settings.Parameters, true);
        ////    if (!string.IsNullOrWhiteSpace(parameters["FieldNames"]))
        ////    {
        ////        args.Rendering.Parameters["FieldNames"] = parameters["FieldNames"];
        ////    }
        ////}
        //protected virtual Rule<ConditionalRenderingsRuleContext> GetMatchingRule(RuleList<ConditionalRenderingsRuleContext> rules, ConditionalRenderingsRuleContext context)
        //{
        //    Assert.ArgumentNotNull(rules, "rules");
        //    Assert.ArgumentNotNull(context, "context");

        //    var matchingRule = rules.Rules.FirstOrDefault(r => r.Evaluate(context)) ?? rules.Rules.FirstOrDefault(r => r.UniqueId == ID.Null);
        //    return matchingRule;
        //}

        //protected override void ApplyChanges(Rendering rendering, RenderingReference reference)
        //{
        //    Assert.ArgumentNotNull(rendering, "rendering");
        //    Assert.ArgumentNotNull(reference, "reference");
        //    TransferRenderingVariant(rendering, reference);
        //}
        private static void TransferRenderingVariant(Rendering rendering, RenderingReference reference, string variantId)
        {
            Assert.ArgumentNotNull(rendering, "rendering");
            Assert.ArgumentNotNull(reference, "reference");
            if (reference.RenderingItem != null && !string.IsNullOrWhiteSpace(variantId))
            {
                var parameters = WebUtil.ParseQueryString(reference.Settings.Parameters, true);
                //rendering.Parameters["FieldNames"] = "{4C961442-BEA7-4759-9AA2-A8DF74357451}";//parameters["FieldNames"];
                rendering.Parameters["FieldNames"] = variantId;
            }
        }
    public override void Insert()
    {
      SiteContext siteContext = Context.Site;

      if (((siteContext != null) && (siteContext.EnableWebEdit && (siteContext.DisplayMode == DisplayMode.Edit))) && (WebUtil.GetQueryString("sc_webedit") != "0"))
      {
        UserControlRenderer editControl = new UserControlRenderer { Src = "/sitecore/shell/Applications/Taxonomy/Controls/PageEditor/TaxomomiesRendering.ascx" };

        RenderingReference menuRenderingReference = new RenderingReference(editControl) { Placeholder = "webedit", AddToFormIfUnused = true };
        Context.Page.AddRendering(menuRenderingReference);
      }
    }
 protected virtual ITemplate GetColumnRendering(Item item)
 {
     if (item.Visualization.GetRenderings(Sitecore.Context.Device, true).Length > 0)
     {
         RenderingReference reference = item.Visualization.GetRenderings(Sitecore.Context.Device, true).FirstOrDefault <RenderingReference>();
         if (reference != null)
         {
             return(reference.GetControl() as ITemplate);
         }
     }
     return(null);
 }
        public override void Insert()
        {
            SiteContext site = Context.Site;

            if (((site != null) && (site.EnableWebEdit && (site.DisplayMode == DisplayMode.Edit))) && (WebUtil.GetQueryString("sc_webedit") != "0"))
            {
                RenderingReference reference = new RenderingReference(new TaxonomyScriptRegister())
                {
                    Placeholder = "webedit", AddToFormIfUnused = true
                };
                Context.Page.AddRendering(reference);
            }
        }
        /// <summary>
        /// Returns matching rendering on an ancestor item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="rendering"></param>
        /// <returns></returns>
        private static RenderingReference FindRenderingOnAncestor(Item item, RenderingReference rendering)
        {
            if (item == null) return null;

            var renderingOnParentItem = GetSameRenderingOnItem(item, rendering);

            if (renderingOnParentItem != null && renderingOnParentItem.Settings.DataSource != "")
            {
                return renderingOnParentItem;
            }

            return FindRenderingOnAncestor(item.Parent, rendering);
        }
Ejemplo n.º 30
0
        protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(context, "context");
            RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);

            if (renderingReference == null)
            {
                args.Renderer = new EmptyRenderer();
                return;
            }
            this.ApplyChanges(args.Rendering, renderingReference);
        }
Ejemplo n.º 31
0
        protected override RenderingReference DoActivateCondition(RenderingDefinition rendering, ID conditionID, Language lang, Database database, Item item, SiteContext site)
        {
            // Copied from Sitecore
            Assert.ArgumentNotNull(rendering, "rendering");
            Assert.ArgumentNotNull(conditionID, "conditionID");
            Assert.ArgumentNotNull(lang, "lang");
            Assert.ArgumentNotNull(database, "database");
            Assert.ArgumentNotNull(item, "item");
            Assert.ArgumentNotNull(site, "site");
            RenderingReference renderingReference             = new RenderingReference(rendering, lang, database);
            RuleList <ConditionalRenderingsRuleContext> rules = renderingReference.Settings.Rules;
            Rule <ConditionalRenderingsRuleContext>     rule  = rules.Rules.FirstOrDefault <Rule <ConditionalRenderingsRuleContext> >((Rule <ConditionalRenderingsRuleContext> r) => r.UniqueId == conditionID);

            if (rule == null)
            {
                return(renderingReference);
            }
            List <RenderingReference> renderingReferences = new List <RenderingReference>()
            {
                renderingReference
            };
            ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(renderingReferences, renderingReference)
            {
                Item = item
            };

            rule.SetCondition(new TrueCondition <ConditionalRenderingsRuleContext>());
            rules = new RuleList <ConditionalRenderingsRuleContext>(rule);
            using (SiteContextSwitcher siteContextSwitcher = new SiteContextSwitcher(site))
            {
                using (DatabaseSwitcher databaseSwitcher = new DatabaseSwitcher(item.Database))
                {
                    rules.Run(conditionalRenderingsRuleContext);
                }
            }
            Assert.IsTrue(conditionalRenderingsRuleContext.References.Count == 1, "The references count should equal 1");
            RenderingReference renderingReference1 = conditionalRenderingsRuleContext.References[0];

            Assert.IsNotNull(renderingReference1, "result");
            rendering.Datasource = renderingReference1.Settings.DataSource;
            if (renderingReference1.RenderingItem != null)
            {
                rendering.ItemID = renderingReference1.RenderingItem.ID.ToString();
            }
            // End copied from Sitecore

            // Apply Parameters Too
            rendering.Parameters = renderingReference1.Settings.Parameters;

            return(renderingReference1);
        }
Ejemplo n.º 32
0
        public override void Process(HttpRequestArgs args)
        {
            if (Context.Item != null && Context.Item.Fields["MVCPlaceHolderKey"] != null)
            {
                var reference =
                    new RenderingReference(new MvcRouterControl())
                        {
                            Placeholder = Context.Item.Fields["MVCPlaceHolderKey"].GetValue(true)
                        };
                Context.Page.AddRendering(reference);
            }

            base.Process(args);
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Returns matching rendering on an ancestor item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="rendering"></param>
        /// <returns></returns>
        private static RenderingReference FindRenderingOnAncestor(Item item, RenderingReference rendering)
        {
            if (item == null)
            {
                return(null);
            }

            var renderingOnParentItem = GetSameRenderingOnItem(item, rendering);

            if (renderingOnParentItem != null && renderingOnParentItem.Settings.DataSource != "")
            {
                return(renderingOnParentItem);
            }

            return(FindRenderingOnAncestor(item.Parent, rendering));
        }
        public override void Insert()
        {
            SiteContext siteContext = Context.Site;

            if (((siteContext != null) && (siteContext.EnableWebEdit && (siteContext.DisplayMode == DisplayMode.Edit))) && (WebUtil.GetQueryString("sc_webedit") != "0"))
            {
                UserControlRenderer editControl = new UserControlRenderer {
                    Src = "/sitecore/shell/Applications/Taxonomy/Controls/PageEditor/TaxomomiesRendering.ascx"
                };

                RenderingReference menuRenderingReference = new RenderingReference(editControl)
                {
                    Placeholder = "webedit", AddToFormIfUnused = true
                };
                Context.Page.AddRendering(menuRenderingReference);
            }
        }
Ejemplo n.º 35
0
        protected override void ApplyActions(CustomizeRenderingArgs args, ConditionalRenderingsRuleContext context)
        {
            // Begin copied from sitecore
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(context, "context");
            RenderingReference renderingReference = context.References.Find((RenderingReference r) => r.UniqueId == context.Reference.UniqueId);

            if (renderingReference == null)
            {
                args.Renderer = new EmptyRenderer();
                return;
            }
            this.ApplyChanges(args.Rendering, renderingReference);
            // End copied from sitecore

            // Apply Parameters Too
            TransferRenderingParameters(args.Rendering, renderingReference);
        }
Ejemplo n.º 36
0
        protected override void Evaluate(CustomizeRenderingArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item item = args.PageContext.Item;

            if (item == null)
            {
                return;
            }
            RenderingReference    renderingReference = CustomizeRenderingProcessor.GetRenderingReference(args.Rendering, Context.Language, args.PageContext.Database);
            GetRenderingRulesArgs expr_3E            = new GetRenderingRulesArgs(item, renderingReference);

            GetRenderingRulesPipeline.Run(expr_3E);
            RuleList <ConditionalRenderingsRuleContext> ruleList = expr_3E.RuleList;

            if (ruleList == null || ruleList.Count == 0)
            {
                return;
            }

            // after the ruleList has been retrieved AND ruleList > 0, instantiate a new personalization rulelist which has a fix to continue evaluation of conditions
            // even when some exceptions occur.
            PersonalizationRuleList <ConditionalRenderingsRuleContext> personalizationRuleList = new PersonalizationRuleList <ConditionalRenderingsRuleContext>();

            foreach (var r in ruleList.Rules)
            {
                personalizationRuleList.Add(r);
            }

            ConditionalRenderingsRuleContext conditionalRenderingsRuleContext = new ConditionalRenderingsRuleContext(new List <RenderingReference>
            {
                renderingReference
            }, renderingReference)
            {
                Item = item
            };

            conditionalRenderingsRuleContext.Parameters["mvc.rendering"] = args.Rendering;

            // runRules for the personalizationRuleList
            this.RunRules(personalizationRuleList, conditionalRenderingsRuleContext);
            this.ApplyActions(args, conditionalRenderingsRuleContext);
            args.IsCustomized = true;
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Get rendering on specified item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="rendering"></param>
        /// <returns></returns>
        private static RenderingReference GetSameRenderingOnItem(Item item, RenderingReference rendering)
        {
            LayoutField layoutField = item.Fields[FieldIDs.LayoutField];

            if (layoutField == null)
            {
                return(null);
            }

            RenderingReference[] references = layoutField.GetReferences(Context.Device);

            if (references == null || references.Length == 0)
            {
                return(null);
            }

            var renderingOnParentItem = references.FirstOrDefault(r => r.UniqueId == rendering.UniqueId);

            return(renderingOnParentItem);
        }
        /// <summary>
        /// Gets the matching rendering item on the remote item specified, if one has been specified.
        /// </summary>
        /// <returns></returns>
        private RenderingReference GetRemoteItemRendering(SafeDictionary<string> parameters, RenderingReference rendering)
        {
            RenderingReference renderingReference = null;

            var cascadeItem = parameters[RemoteItem];

            if (!String.IsNullOrEmpty(cascadeItem))
            {
                Guid itemReference = Guid.Empty;
                if (Guid.TryParse(cascadeItem, out itemReference))
                {
                    Item referenceItem = Sitecore.Context.Database.GetItem(new ID(itemReference));

                    if (referenceItem != null)
                    {
                        renderingReference = GetSameRenderingOnItem(referenceItem, rendering);
                    }
                }
            }

            return renderingReference;
        }
        /// <summary>
        /// Sets rendering data source based on cascaded value or the item specified.
        /// </summary>
        /// <param name="renderingReference"></param>
        private void SetRenderingDataSource(RenderingReference rendering)
        {
            var parameters = WebUtil.ParseQueryString(rendering.Settings.Parameters);

            if (DataSourceIsEmpty(rendering.Settings.DataSource) && parameters.ContainsKey(Cascade))
            {
                RenderingReference renderingOnOtherItem = null;

                var shouldCascade = parameters[Cascade];

                /* If not, check if 'cascade' is checked */

                if ("1".Equals(shouldCascade))
                {
                    RenderingReference remoteItemRendering = GetRemoteItemRendering(parameters, rendering);

                    /* Otherwise loop through ancestors */

                    if (remoteItemRendering == null)
                    {
                        renderingOnOtherItem = FindRenderingOnAncestor(Context.Item.Parent, rendering);

                        if (renderingOnOtherItem != null)
                        {
                            rendering.Settings.DataSource = renderingOnOtherItem.Settings.DataSource;
                        }
                    }
                    else
                    {
                        rendering.Settings.DataSource = remoteItemRendering.Settings.DataSource;
                    }
                }
            }
        }
        /// <summary>
        /// Get rendering on specified item.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="rendering"></param>
        /// <returns></returns>
        private static RenderingReference GetSameRenderingOnItem(Item item, RenderingReference rendering)
        {
            LayoutField layoutField = item.Fields[FieldIDs.LayoutField];

            if (layoutField == null) return null;

            RenderingReference[] references = layoutField.GetReferences(Context.Device);

            if (references == null || references.Length == 0) return null;

            var renderingOnParentItem = references.FirstOrDefault(r => r.UniqueId == rendering.UniqueId);

            return renderingOnParentItem;
        }
 private static string GetDisplayName(RenderingReference rendering)
 {
     return (rendering.RenderingItem != null &&
             !string.IsNullOrEmpty(rendering.RenderingItem.DisplayName))
                ? rendering.RenderingItem.DisplayName
                : string.Empty;
 }