Exemple #1
0
        protected override void OnInit( EventArgs e )
        {
            try
            {
                int pageId = Convert.ToInt32( PageParameter( "EditPage" ) );
                _page = Rock.Web.Cache.PageCache.Read( pageId );

                if ( _page != null )
                    canConfigure = _page.IsAuthorized( "Administrate", CurrentPerson );
                else
                    canConfigure = RockPage.IsAuthorized( "Administrate", CurrentPerson );

                if ( canConfigure )
                {
                    rGrid.DataKeyNames = new string[] { "id" };
                    rGrid.Actions.ShowAdd = true;
                    rGrid.Actions.AddClick += rGrid_GridAdd;
                    rGrid.GridReorder += new GridReorderEventHandler( rGrid_GridReorder );
                    rGrid.GridRebind += new GridRebindEventHandler( rGrid_GridRebind );
                }
                else
                {
                    DisplayError( "You are not authorized to configure this page" );
                }
            }
            catch ( SystemException ex )
            {
                DisplayError( ex.Message );
            }

            base.OnInit( e );
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            int pageId = PageParameter("EditPage").AsInteger();

            _Page     = Rock.Web.Cache.PageCache.Read(pageId);
            _ZoneName = this.PageParameter("ZoneName");

            if (_Page != null)
            {
                lAllPagesOnSite.Text = string.Format("Site");


                gSiteBlocks.DataKeyNames              = new string[] { "Id" };
                gSiteBlocks.Actions.ShowAdd           = true;
                gSiteBlocks.Actions.ShowExcelExport   = false;
                gSiteBlocks.Actions.ShowMergeTemplate = false;
                gSiteBlocks.Actions.AddClick         += SiteBlocks_Add;
                gSiteBlocks.GridReorder += gSiteBlocks_GridReorder;
                gSiteBlocks.GridRebind  += gSiteBlocks_GridRebind;

                lAllPagesForLayout.Text = string.Format("Layout ({0})", _Page.Layout.Name);

                gLayoutBlocks.DataKeyNames              = new string[] { "Id" };
                gLayoutBlocks.Actions.ShowAdd           = true;
                gLayoutBlocks.Actions.ShowExcelExport   = false;
                gLayoutBlocks.Actions.ShowMergeTemplate = false;
                gLayoutBlocks.Actions.AddClick         += LayoutBlocks_Add;
                gLayoutBlocks.GridReorder += gLayoutBlocks_GridReorder;
                gLayoutBlocks.GridRebind  += gLayoutBlocks_GridRebind;

                gPageBlocks.DataKeyNames              = new string[] { "Id" };
                gPageBlocks.Actions.ShowAdd           = true;
                gPageBlocks.Actions.ShowExcelExport   = false;
                gPageBlocks.Actions.ShowMergeTemplate = false;
                gPageBlocks.Actions.AddClick         += gPageBlocks_GridAdd;
                gPageBlocks.GridReorder += gPageBlocks_GridReorder;
                gPageBlocks.GridRebind  += gPageBlocks_GridRebind;

                LoadBlockTypes(!Page.IsPostBack);

                string script = string.Format(
                    @"Sys.Application.add_load(function () {{
                    $('div.modal-header h3').html('{0} Zone');
                    $('#{1} a').click(function() {{ $('#{4}').val('Page'); }});
                    $('#{2} a').click(function() {{ $('#{4}').val('Layout'); }});
                    $('#{3} a').click(function() {{ $('#{4}').val('Site'); }});
                }});",
                    _ZoneName,
                    liPage.ClientID,
                    liLayout.ClientID,
                    liSite.ClientID,
                    hfOption.ClientID);

                this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("zone-add-load-{0}", this.ClientID), script, true);
            }
        }
Exemple #3
0
        /// <summary>
        /// Used to save an item to the current HTTPRequests items collection.  This is useful if multiple blocks
        /// on the same page will need access to the same object.  The first block can read the object and save
        /// it using this method for the other blocks to reference
        /// </summary>
        /// <param name="key"></param>
        /// <param name="item"></param>
        public void SaveSharedItem(string key, object item)
        {
            string itemKey = string.Format("{0}:Item:{1}", PageCache.CacheKey(Id), key);

            System.Collections.IDictionary items = HttpContext.Current.Items;
            if (items.Contains(itemKey))
            {
                items[itemKey] = item;
            }
            else
            {
                items.Add(itemKey, item);
            }
        }
Exemple #4
0
        /// <summary>
        /// Flushes the block instances for all the pages that use a specific layout.
        /// </summary>
        public static void FlushLayoutBlocks(int layoutId)
        {
            ObjectCache cache = MemoryCache.Default;

            foreach (var item in cache)
            {
                if (item.Key.StartsWith("Rock:Page:"))
                {
                    PageCache page = cache[item.Key] as PageCache;
                    if (page != null && page.LayoutId == layoutId)
                    {
                        page.FlushBlocks();
                    }
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Flushes all the pages that use a specific layout.
        /// </summary>
        public static void FlushLayout(string layout)
        {
            ObjectCache cache = MemoryCache.Default;

            foreach (var item in cache)
            {
                if (item.Key.StartsWith("Rock:Page:"))
                {
                    PageCache page = cache[item.Key] as PageCache;
                    if (page != null && page.Layout == layout)
                    {
                        cache.Remove(item.Key);
                    }
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Adds Page model to cache, and returns cached object
        /// </summary>
        /// <param name="pageModel"></param>
        /// <returns></returns>
        public static PageCache Read(Rock.Model.Page pageModel)
        {
            string cacheKey = PageCache.CacheKey(pageModel.Id);

            ObjectCache cache = MemoryCache.Default;
            PageCache   page  = cache[cacheKey] as PageCache;

            if (page != null)
            {
                return(page);
            }
            else
            {
                page = PageCache.CopyModel(pageModel);
                cache.Set(cacheKey, page, new CacheItemPolicy());

                return(page);
            }
        }
Exemple #7
0
        /// <summary>
        /// Adds Page model to cache, and returns cached object
        /// </summary>
        /// <param name="pageModel"></param>
        /// <returns></returns>
        public static PageCache Read(Page pageModel)
        {
            string cacheKey = PageCache.CacheKey(pageModel.Id);

            ObjectCache cache = MemoryCache.Default;
            PageCache   page  = cache[cacheKey] as PageCache;

            if (page != null)
            {
                return(page);
            }
            else
            {
                page = new PageCache(pageModel);

                var cachePolicy = new CacheItemPolicy();
                cache.Set(cacheKey, page, cachePolicy);
                cache.Set(page.Guid.ToString(), page.Id, cachePolicy);

                return(page);
            }
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            try
            {
                int pageId = Convert.ToInt32(PageParameter("EditPage"));
                _page = Rock.Web.Cache.PageCache.Read(pageId);

                if (_page != null)
                {
                    canConfigure = _page.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);
                }
                else
                {
                    canConfigure = IsUserAuthorized(Authorization.ADMINISTRATE);
                }

                if (canConfigure)
                {
                    rGrid.DataKeyNames              = new string[] { "Id" };
                    rGrid.Actions.ShowAdd           = true;
                    rGrid.Actions.AddClick         += rGrid_GridAdd;
                    rGrid.Actions.ShowExcelExport   = false;
                    rGrid.Actions.ShowMergeTemplate = false;
                    rGrid.GridReorder += new GridReorderEventHandler(rGrid_GridReorder);
                    rGrid.GridRebind  += new GridRebindEventHandler(rGrid_GridRebind);
                }
                else
                {
                    DisplayError("You are not authorized to configure this page");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
Exemple #9
0
 /// <summary>
 /// Removes page from cache
 /// </summary>
 /// <param name="id"></param>
 public static void Flush(int id)
 {
     FlushCache(PageCache.CacheKey(id));
 }
Exemple #10
0
 /// <summary>
 /// Adds Page model to cache, and returns cached object
 /// </summary>
 /// <param name="pageModel"></param>
 /// <returns></returns>
 public static PageCache Read(Page pageModel)
 {
     return(GetOrAddExisting(PageCache.CacheKey(pageModel.Id),
                             () => LoadByModel(pageModel)));
 }
Exemple #11
0
 /// <summary>
 /// Returns Page object from cache.  If page does not already exist in cache, it
 /// will be read and added to cache
 /// </summary>
 /// <param name="id">The identifier.</param>
 /// <param name="rockContext">The rock context.</param>
 /// <returns></returns>
 public static PageCache Read(int id, RockContext rockContext = null)
 {
     return(GetOrAddExisting(PageCache.CacheKey(id),
                             () => LoadById(id, rockContext)));
 }
Exemple #12
0
        /// <summary>
        /// Menus the XML element.
        /// </summary>
        /// <param name="levelsDeep">The levels deep.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="currentPage">The current page.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns></returns>
        private XElement MenuXmlElement(int levelsDeep, Person person, RockContext rockContext, PageCache currentPage = null, Dictionary <string, string> parameters = null, NameValueCollection queryString = null)
        {
            if (levelsDeep >= 0 && this.DisplayInNav(person))
            {
                string iconUrl = string.Empty;
                if (this.IconFileId.HasValue)
                {
                    iconUrl = string.Format(
                        "{0}/GetImage.ashx?{1}",
                        HttpContext.Current.Request.ApplicationPath,
                        this.IconFileId.Value);
                }

                bool isCurrentPage = currentPage != null && currentPage.Id == this.Id;

                XElement pageElement = new XElement(
                    "page",
                    new XAttribute("id", this.Id),
                    new XAttribute("title", string.IsNullOrWhiteSpace(this.PageTitle) ? this.InternalName : this.PageTitle),
                    new XAttribute("current", isCurrentPage.ToString()),
                    new XAttribute("url", new PageReference(this.Id, 0, parameters, queryString).BuildUrl()),
                    new XAttribute("display-description", this.MenuDisplayDescription.ToString().ToLower()),
                    new XAttribute("display-icon", this.MenuDisplayIcon.ToString().ToLower()),
                    new XAttribute("display-child-pages", this.MenuDisplayChildPages.ToString().ToLower()),
                    new XAttribute("icon-css-class", this.IconCssClass ?? string.Empty),
                    new XElement("description", this.Description ?? string.Empty),
                    new XElement("icon-url", iconUrl));

                XElement childPagesElement = new XElement("pages");

                pageElement.Add(childPagesElement);

                if (levelsDeep > 0 && this.MenuDisplayChildPages)
                {
                    foreach (PageCache page in GetPages(rockContext))
                    {
                        if (page != null)
                        {
                            XElement childPageElement = page.MenuXmlElement(levelsDeep - 1, person, rockContext, currentPage, parameters, queryString);
                            if (childPageElement != null)
                            {
                                childPagesElement.Add(childPageElement);
                            }
                        }
                    }
                }

                return(pageElement);
            }
            else
            {
                return(null);
            }
        }
Exemple #13
0
        /// <summary>
        /// Returns XML for a page menu.
        /// </summary>
        /// <param name="levelsDeep">The page levels deep.</param>
        /// <param name="person">The person.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="currentPage">The current page.</param>
        /// <param name="parameters">The parameters.</param>
        /// <param name="queryString">The query string.</param>
        /// <returns></returns>
        public XDocument MenuXml(int levelsDeep, Person person, RockContext rockContext, PageCache currentPage = null, Dictionary <string, string> parameters = null, NameValueCollection queryString = null)
        {
            XElement menuElement = MenuXmlElement(levelsDeep, person, rockContext, currentPage, parameters, queryString);

            return(new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), menuElement));
        }
Exemple #14
0
        /// <summary>
        /// Parses the ASPX file and its MasterPage for Rock:Zone controls
        /// </summary>
        /// <param name="layoutPath">The layout path.</param>
        /// <returns></returns>
        private List <string> FindZoneNames(Rock.Web.Cache.PageCache page)
        {
            string theme      = page.Layout.Site.Theme;
            string layout     = page.Layout.FileName;
            string layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

            HtmlAgilityPack.HtmlDocument layoutAspx = new HtmlAgilityPack.HtmlDocument();
            layoutAspx.OptionFixNestedTags = true;
            string layoutFullPath = HttpContext.Current.Server.MapPath(layoutPath);

            layoutAspx.Load(layoutFullPath);

            List <HtmlNode> masterControlNodes = new List <HtmlNode>();

            Regex masterPageRegEx = new Regex("<%@.*MasterPageFile=\"([^\"]*)\".*%>", RegexOptions.Compiled);

            var masterPageMatch = masterPageRegEx.Match(layoutAspx.DocumentNode.FirstChild.InnerText);

            if (masterPageMatch.Success && masterPageMatch.Groups.Count > 1)
            {
                string masterPageFileName = Path.Combine(Path.GetDirectoryName(layoutFullPath), masterPageMatch.Groups[1].Value);
                HtmlAgilityPack.HtmlDocument masterAspx = new HtmlAgilityPack.HtmlDocument();
                masterAspx.OptionFixNestedTags = true;
                masterAspx.Load(masterPageFileName);
                FindAllZoneControls(masterAspx.DocumentNode.ChildNodes, masterControlNodes);
            }

            List <HtmlNode> layoutControlNodes = new List <HtmlNode>();

            FindAllZoneControls(layoutAspx.DocumentNode.ChildNodes, layoutControlNodes);

            List <string> zoneNames = new List <string>();

            foreach (var masterNode in masterControlNodes)
            {
                if (masterNode.Name.Equals("Rock:Zone", StringComparison.OrdinalIgnoreCase))
                {
                    zoneNames.Add(masterNode.Attributes["Name"].Value);
                }
                else if (masterNode.Name.Equals("asp:ContentPlaceHolder", StringComparison.OrdinalIgnoreCase) && masterNode.Id.Equals("main"))
                {
                    zoneNames.AddRange(layoutControlNodes.Where(a => a.Attributes["Name"] != null).Select(a => a.Attributes["Name"].Value).ToList());
                }
            }


            // if the layout block doesn't have a master page, or if there are other ContentPlaceHolders that we didn't know about, add any other zones that we haven't added already
            var layoutZones = layoutControlNodes.Where(a => a.Attributes["Name"] != null).Select(a => a.Attributes["Name"].Value).ToList();

            foreach (var layoutZone in layoutZones)
            {
                if (!zoneNames.Contains(layoutZone))
                {
                    zoneNames.Add(layoutZone);
                }
            }


            // remove any spaces
            zoneNames = zoneNames.Select(a => a.Replace(" ", string.Empty)).ToList();

            return(zoneNames);
        }
Exemple #15
0
        /// <summary>
        /// Removes page from cache
        /// </summary>
        /// <param name="id"></param>
        public static void Flush(int id)
        {
            ObjectCache cache = MemoryCache.Default;

            cache.Remove(PageCache.CacheKey(id));
        }