/// <summary>
        /// Parses shared personalization for the given virtual path to obtain the applied content scriptlet
        /// </summary>
        /// <param name="virtualPath">The virtual path to check for personalization data</param>
        /// <returns>The name of the content scriptlet applied in personalization data, or string.Empty
        /// if the value could not be determined</returns>
        private static string GetContentScriptletFromPersonalization(SharedPersonalization sp, string themeName)
        {
            // LOOK FOR SHARED PERSONALIZATION SET ON THE GIVEN VIRTUAL PATH
            if (sp != null)
            {
                // DECODE THE PERSONALIZATION BLOB
                Dictionary <string, PersonalizationInfo> props = sp.DecodePageSettings();

                // LOOP THE KEYS FOR THE PERSONALIZED PROPERTIES
                foreach (string key in props.Keys)
                {
                    // SEE IF THIS PERSONALIZATION DATA APPLIES TO SCRIPTLETPART
                    PersonalizationInfo pinfo = props[key];
                    if (pinfo.ControlType.Name == "ScriptletPart")
                    {
                        // SEE IF THERE IS A VALUE SET FOR THE CONTENT SCRIPTLET
                        if (pinfo.Properties.ContainsKey("Content"))
                        {
                            // TRY TO LOAD THE SPECIFIED CONTENT SCRIPTLET
                            string contentScriptlet = pinfo.Properties["Content"].ToString();
                            //Scriptlet s = ScriptletDataSource.Load(contentScriptlet, ScriptletType.Content);
                            Scriptlet s = ScriptletDataSource.Load(themeName, contentScriptlet, ScriptletType.Content);
                            if (s != null)
                            {
                                return(s.Identifier);
                            }
                        }
                    }
                }
            }

            // EITHER SHARED PERSONALIZATION WAS NOT SET, CONTENT SCRIPTLET SETTING IS UNAVAILABLE,
            // OR THE SPECIFIED CONTENT SCRIPTLET IS INVALID
            return(string.Empty);
        }
Example #2
0
 protected override void CreateChildControls()
 {
     Controls.Clear();
     _ScriptletChoices = new DropDownList();
     _ScriptletChoices.Items.Add(new ListItem("- choose scriptlet -", string.Empty));
     _ScriptletChoices.AppendDataBoundItems = true;
     _ScriptletChoices.DataTextField        = "Identifier";
     _ScriptletChoices.DataValueField       = "ScriptletType";
     _ScriptletChoices.DataSource           = ScriptletDataSource.CacheLoad(this.Page.Theme, ScriptletType.Unspecified, "Identifier");
     _ScriptletChoices.DataBind();
     this.Controls.Add(_ScriptletChoices);
 }
Example #3
0
        private string GetMergedTemplate()
        {
            Scriptlet layout = ScriptletDataSource.Load(this.Page.Theme, this.Layout, ScriptletType.Layout, true);

            //IF THE DESIRED LAYOUT IS NOT FOUND, RETURN DEFAULT THREE COLUMN LAYOUT
            if (layout == null)
            {
                return("<table width=100%><tr><td colspan=3>[[layout:header]]</td></tr><tr><td></td><td>[[layout:leftsidebar]]</td><td>[[layout:content]]</td><td>[[layout:rightsidebar]]</td></tr><tr><td colspan=3>[[layout:footer]]</td></tr></table>");
            }
            //CHECK FOR HEADER OPTIONS
            if (!string.IsNullOrEmpty(layout.HeaderData))
            {
                this.Page.Header.Controls.Add(new LiteralControl(layout.HeaderData));
            }
            string          mergedTemplate   = layout.ScriptletData;
            MatchCollection nestedScriptlets = Regex.Matches(mergedTemplate, "\\[\\[(header|footer|sidebar|sidebar2|leftsidebar|rightsidebar|content):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase);

            if (nestedScriptlets.Count > 0)
            {
                StringBuilder mergedTemplateBuilder = new StringBuilder();
                int           currentIndex          = 0;
                foreach (Match match in nestedScriptlets)
                {
                    //output the literal content up to the match index
                    if (currentIndex < match.Index)
                    {
                        mergedTemplateBuilder.Append(mergedTemplate.Substring(currentIndex, (match.Index - currentIndex)));
                        currentIndex = match.Index;
                    }
                    //include the nested scriptlet
                    ScriptletType nestedType       = (ScriptletType)Enum.Parse(typeof(ScriptletType), match.Groups[1].Value);
                    string        nestedIdentifier = match.Groups[2].Value.Trim();
                    Scriptlet     nestedScriptlet  = ScriptletDataSource.Load(this.Page.Theme, nestedIdentifier, nestedType, true);
                    if (nestedScriptlet != null)
                    {
                        if (!string.IsNullOrEmpty(nestedScriptlet.HeaderData))
                        {
                            this.Page.Header.Controls.Add(new LiteralControl(nestedScriptlet.HeaderData));
                        }
                        mergedTemplateBuilder.Append(nestedScriptlet.ScriptletData);
                    }
                    //advance the current index
                    currentIndex += match.Length;
                }
                //output any remaining literal content
                if (currentIndex < mergedTemplate.Length)
                {
                    mergedTemplateBuilder.Append(mergedTemplate.Substring(currentIndex));
                }
                mergedTemplate = mergedTemplateBuilder.ToString();
            }
            return(mergedTemplate);
        }
        /// <summary>
        /// Scans a content scriptlet to determine if it contains reference to a OnePageCheckout control
        /// </summary>
        /// <param name="identifier">The identifier of the content scriptlet</param>
        /// <returns>True if the one page checkout control is discovered in the specified scriptlet</returns>
        private static bool IsOnePageCheckoutSetInScriptlet(string themeName, string identifier)
        {
            // TRY TO LOAD THE SPECIFIED SCRIPTLET

            Scriptlet s = ScriptletDataSource.Load(themeName, identifier, ScriptletType.Content);

            if (s != null)
            {
                // SEE IF SCRIPTLET CONTAINS A REFERENCE TO ONE PAGE CHECKOUT CONTROL
                // IF IT HAS ONE PAGE CHECKOUT, RETURN 1 (TRUE) ELSE 0 (FALSE)
                return(s.ScriptletData.Contains("[[ConLib:OnePageCheckout"));
            }
            else
            {
                // THE SCRIPTLET COULD NOT BE LOADED, ONE PAGE CHECKOUT IDENTIFIER NOT PRESENT
                return(false);
            }
        }
        private void HandleEdit(DropDownList choices, ScriptletType scriptletType)
        {
            Control c = RecursiveFindControl(this.Page, "EditScriptlet");

            if (c != null)
            {
                Scriptlet s = ScriptletDataSource.Load(this.Page.Theme, choices.SelectedValue, scriptletType);
                if (s != null)
                {
                    System.Reflection.PropertyInfo i = c.GetType().GetProperty("Identifier");
                    i.SetValue(c, s.Identifier, null);
                    System.Reflection.PropertyInfo t = c.GetType().GetProperty("ScriptletType");
                    t.SetValue(c, s.ScriptletType, null);
                    //we do not want the edit-mode section to disappear when user clicked on
                    //the edit icon without selecting any valid scriptlet in the dropdown
                    c = RecursiveFindControl(this.Page, "phEditor");
                    if (c != null)
                    {
                        c.Visible = false;
                    }
                }
            }
        }
        protected override void CreateChildControls()
        {
            bool      created    = false;
            Scriptlet Identifier = ScriptletDataSource.Load(this.Page.Theme, this.Identifier, (ScriptletType)Enum.Parse(typeof(ScriptletType), this.ScriptletType), true);
            string    IdentifierScriptletData = string.Empty;

            if (Identifier != null)
            {
                if (!string.IsNullOrEmpty(Identifier.HeaderData))
                {
                    this.Page.Header.Controls.Add(new LiteralControl(Identifier.HeaderData));
                }
                IdentifierScriptletData = Identifier.ScriptletData;
            }
            string template = IdentifierScriptletData;

            //PROCESS THE MERGED NVELOCITY TEMPLATE
            System.Collections.Hashtable parameters = new System.Collections.Hashtable();
            object store    = Token.Instance.Store;
            object customer = Token.Instance.User;

            parameters.Add("store", store);
            parameters.Add("customer", customer);
            //TODO: OBSOLETE PARAMETERS, REMOVE FOR AC7.1
            parameters.Add("Store", store);
            parameters.Add("User", customer);

            //CHECK FOR CATEGORY
            int      categoryId = GetCategoryId();
            Category category   = CategoryDataSource.Load(categoryId);

            if (category != null)
            {
                parameters.Add("Category", category);
            }

            //CHECK FOR PRODUCT
            int     productId = GetProductId();
            Product product   = ProductDataSource.Load(productId);

            if (product != null)
            {
                parameters.Add("Product", product);
            }

            //CHECK FOR WEBPAGE
            int     webpageId = GetWebpageId();
            Webpage webpage   = WebpageDataSource.Load(webpageId);

            if (webpage != null)
            {
                parameters.Add("Webpage", webpage);
            }

            //CHECK FOR LINK
            int  linkId = GetLinkId();
            Link link   = LinkDataSource.Load(linkId);

            if (link != null)
            {
                parameters.Add("Link", link);
            }

            string result = NVelocityEngine.Instance.Process(parameters, template);

            if (this.Page != null)
            {
                string baseUrl = this.Page.ResolveUrl("~");
                result = result.Replace("href=\"~/", "href=\"" + baseUrl);
                result = result.Replace("src=\"~/", "src=\"" + baseUrl);
                //DISABLE THE ABILITY TO REFER TO ANY USER CONTROL
                //MatchCollection userControls = Regex.Matches(result, "\\[\\[(ConLib|UserControl):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase);
                MatchCollection userControls = Regex.Matches(result, "\\[\\[(ConLib):([^\\]]+)\\]\\]", RegexOptions.IgnoreCase);
                if (userControls.Count > 0)
                {
                    int currentIndex = 0;
                    foreach (Match match in userControls)
                    {
                        //output the literal content up to the match index
                        if (currentIndex < match.Index)
                        {
                            this.Controls.Add(new LiteralControl(result.Substring(currentIndex, (match.Index - currentIndex))));
                            currentIndex = match.Index;
                        }
                        string controlPath;
                        Dictionary <string, string> attributes;
                        ParseControlPath(match.Groups[2].Value.Trim(), out controlPath, out attributes);
                        if (match.Groups[1].Value.ToLowerInvariant() == "conlib")
                        {
                            controlPath = "~/ConLib/" + controlPath + ".ascx";
                        }
                        //LOAD AND OUTPUT THE CONTROL
                        try
                        {
                            Control control = this.Page.LoadControl(controlPath);
                            if (control != null)
                            {
                                //TRY TO SET PARAMS
                                foreach (string propName in attributes.Keys)
                                {
                                    //CHECK WHETHER PROPERTY EXISTS
                                    System.Reflection.PropertyInfo pi = control.GetType().GetProperty(propName);
                                    if (pi != null)
                                    {
                                        //SET THE PROPERTY WITH THE GIVEN VALUE
                                        object value = Convert.ChangeType(attributes[propName], pi.PropertyType);
                                        pi.SetValue(control, value, null);
                                    }
                                }
                                //ADD CONTROL TO THE COLLECTION
                                this.Controls.Add(control);
                            }
                        }
                        catch (Exception ex)
                        {
                            this.Controls.Add(new LiteralControl(match.Value + " " + ex.Message));
                        }
                        //advance the current index
                        currentIndex += match.Length;
                    }
                    //output any remaining literal content
                    if (currentIndex < result.Length)
                    {
                        this.Controls.Add(new LiteralControl(result.Substring(currentIndex)));
                    }
                    created = true;
                }
            }
            if (!created)
            {
                this.Controls.Add(new LiteralControl(result));
            }
        }
        protected override void CreateChildControls()
        {
            Controls.Clear();

            string pageTheme = this.Page.Theme;

            _LayoutChoices = new DropDownList();
            _LayoutChoices.Items.Add(new ListItem("- choose layout -", string.Empty));
            _LayoutChoices.AppendDataBoundItems = true;
            _LayoutChoices.DataTextField        = "Identifier";
            _LayoutChoices.DataValueField       = "Identifier";
            _LayoutChoices.DataSource           = ScriptletDataSource.CacheLoad(pageTheme, ScriptletType.Layout, "Identifier");
            _LayoutChoices.DataBind();
            _LayoutChoices.EnableViewState = false;
            this.Controls.Add(_LayoutChoices);

            _EditLayout               = new ImageButton();
            _EditLayout.SkinID        = "EditIcon";
            _EditLayout.AlternateText = "Edit";
            _EditLayout.ImageAlign    = ImageAlign.Top;
            //_EditLayout.OnClientClick = "return editScriptlet(" + _LayoutChoices.ClientID + ",\"layout\");";
            _EditLayout.EnableViewState = false;
            _EditLayout.Click          += new ImageClickEventHandler(_EditLayout_Click);
            this.Controls.Add(_EditLayout);

            _ContentChoices = new DropDownList();
            _ContentChoices.Items.Add(new ListItem("- choose content -", string.Empty));
            _ContentChoices.AppendDataBoundItems = true;
            _ContentChoices.DataTextField        = "Identifier";
            _ContentChoices.DataValueField       = "Identifier";
            _ContentChoices.DataSource           = ScriptletDataSource.CacheLoad(pageTheme, ScriptletType.Content, "Identifier");
            _ContentChoices.DataBind();
            _ContentChoices.EnableViewState = false;
            this.Controls.Add(_ContentChoices);

            _EditContent               = new ImageButton();
            _EditContent.SkinID        = "EditIcon";
            _EditContent.AlternateText = "Edit";
            _EditContent.ImageAlign    = ImageAlign.Top;
            //_EditContent.OnClientClick = "return editScriptlet(" + _ContentChoices.ClientID + ",\"content\");";
            _EditContent.Click          += new ImageClickEventHandler(_EditContent_Click);
            _EditContent.EnableViewState = false;
            this.Controls.Add(_EditContent);

            _HeaderChoices = new DropDownList();
            _HeaderChoices.Items.Add(new ListItem("- choose header -", string.Empty));
            _HeaderChoices.AppendDataBoundItems = true;
            _HeaderChoices.DataTextField        = "Identifier";
            _HeaderChoices.DataValueField       = "Identifier";
            _HeaderChoices.DataSource           = ScriptletDataSource.CacheLoad(pageTheme, ScriptletType.Header, "Identifier");
            _HeaderChoices.DataBind();
            _HeaderChoices.EnableViewState = false;
            this.Controls.Add(_HeaderChoices);

            _EditHeader                 = new ImageButton();
            _EditHeader.SkinID          = "EditIcon";
            _EditHeader.AlternateText   = "Edit";
            _EditHeader.ImageAlign      = ImageAlign.Top;
            _EditHeader.Click          += new ImageClickEventHandler(_EditHeader_Click);
            _EditHeader.EnableViewState = false;
            this.Controls.Add(_EditHeader);

            _LeftSidebarChoices = new DropDownList();
            _LeftSidebarChoices.Items.Add(new ListItem("- choose left sidebar -", string.Empty));
            _LeftSidebarChoices.AppendDataBoundItems = true;
            _LeftSidebarChoices.DataTextField        = "Identifier";
            _LeftSidebarChoices.DataValueField       = "Identifier";
            _LeftSidebarChoices.DataSource           = ScriptletDataSource.CacheLoad(pageTheme, ScriptletType.Sidebar, "Identifier");
            _LeftSidebarChoices.DataBind();
            _LeftSidebarChoices.EnableViewState = false;
            this.Controls.Add(_LeftSidebarChoices);

            _EditLeftSidebar               = new ImageButton();
            _EditLeftSidebar.SkinID        = "EditIcon";
            _EditLeftSidebar.AlternateText = "Edit";
            _EditLeftSidebar.ImageAlign    = ImageAlign.Top;
            //_EditLeftSidebar.OnClientClick = "return editScriptlet(" + _LeftSidebarChoices.ClientID + ",\"sidebar\");";
            _EditLeftSidebar.Click          += new ImageClickEventHandler(_EditLeftSidebar_Click);
            _EditLeftSidebar.EnableViewState = false;
            this.Controls.Add(_EditLeftSidebar);

            _RightSidebarChoices = new DropDownList();
            _RightSidebarChoices.Items.Add(new ListItem("- choose right sidebar -", string.Empty));
            _RightSidebarChoices.AppendDataBoundItems = true;
            _RightSidebarChoices.DataTextField        = "Identifier";
            _RightSidebarChoices.DataValueField       = "Identifier";
            _RightSidebarChoices.DataSource           = ScriptletDataSource.CacheLoad(pageTheme, ScriptletType.Sidebar, "Identifier");
            _RightSidebarChoices.DataBind();
            _RightSidebarChoices.EnableViewState = false;
            this.Controls.Add(_RightSidebarChoices);

            _EditRightSidebar               = new ImageButton();
            _EditRightSidebar.SkinID        = "EditIcon";
            _EditRightSidebar.AlternateText = "Edit";
            _EditRightSidebar.ImageAlign    = ImageAlign.Top;
            //_EditRightSidebar.OnClientClick = "return editScriptlet(" + _RightSidebarChoices.ClientID + ",\"sidebar\");";
            _EditRightSidebar.Click          += new ImageClickEventHandler(_EditRightSidebar_Click);
            _EditRightSidebar.EnableViewState = false;
            this.Controls.Add(_EditRightSidebar);

            _FooterChoices = new DropDownList();
            _FooterChoices.Items.Add(new ListItem("- choose footer -", string.Empty));
            _FooterChoices.AppendDataBoundItems = true;
            _FooterChoices.DataTextField        = "Identifier";
            _FooterChoices.DataValueField       = "Identifier";
            _FooterChoices.DataSource           = ScriptletDataSource.CacheLoad(pageTheme, ScriptletType.Footer, "Identifier");
            _FooterChoices.DataBind();
            _FooterChoices.EnableViewState = false;
            this.Controls.Add(_FooterChoices);

            _EditFooter                 = new ImageButton();
            _EditFooter.SkinID          = "EditIcon";
            _EditFooter.AlternateText   = "Edit";
            _EditFooter.ImageAlign      = ImageAlign.Top;
            _EditFooter.Click          += new ImageClickEventHandler(_EditFooter_Click);
            _EditFooter.EnableViewState = false;
            this.Controls.Add(_EditFooter);
        }