コード例 #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);

            nbMessage.Visible = false;

            if (page.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                if (!Page.IsPostBack)
                {
                    BindGrids();
                    LoadBlockTypes();
                }
            }
            else
            {
                gPageBlocks.Visible = false;
                nbMessage.Text      = "You are not authorized to edit these blocks";
                nbMessage.Visible   = true;
            }

            base.OnLoad(e);
        }
コード例 #2
0
        /// <summary>
        /// Binds the layout grid.
        /// </summary>
        private void BindLayoutGrid()
        {
            BlockService blockService = new BlockService();
            int          pageId       = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            gLayoutBlocks.DataSource = blockService.GetByLayoutAndZone(page.SiteId.Value, page.Layout, zoneName).ToList();
            gLayoutBlocks.DataBind();
        }
コード例 #3
0
        /// <summary>
        /// Binds the page grid.
        /// </summary>
        private void BindPageGrid()
        {
            BlockService blockService = new BlockService(new RockContext());
            int          pageId       = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            gPageBlocks.DataSource = blockService.GetByPageAndZone(page.Id, zoneName).ToList();
            gPageBlocks.DataBind();
        }
コード例 #4
0
        /// <summary>
        /// Handles the GridReorder event of the gPageBlocks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        protected void gPageBlocks_GridReorder(object sender, GridReorderEventArgs e)
        {
            BlockService blockService = new BlockService();
            int          pageId       = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            blockService.Reorder(blockService.GetByPageAndZone(page.Id, zoneName).ToList(), e.OldIndex, e.NewIndex, CurrentPersonId);

            BindGrids();
        }
コード例 #5
0
        /// <summary>
        /// Handles the GridReorder event of the gPageBlocks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GridReorderEventArgs"/> instance containing the event data.</param>
        protected void gPageBlocks_GridReorder(object sender, GridReorderEventArgs e)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);
            var          blocks       = blockService.GetByPageAndZone(page.Id, zoneName).ToList();

            blockService.Reorder(blocks, e.OldIndex, e.NewIndex);
            rockContext.SaveChanges();

            BindGrids();
        }
コード例 #6
0
        /// <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)
        {
            int pageId = PageParameter("EditPage").AsInteger();

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);

            string zoneName = this.PageParameter("ZoneName");

            lAllPages.Text = string.Format("All Pages Using '{0}' Layout", page.Layout.Name);

            if (page.Layout.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                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;
            }

            if (page.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
            {
                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;
            }

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

            this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("zone-add-load-{0}", this.ClientID), script, true);

            base.OnInit(e);
        }
コード例 #7
0
        /// <summary>
        /// Handles the Delete event of the gLayoutBlocks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gLayoutBlocks_Delete(object sender, RowEventArgs e)
        {
            BlockService blockService = new BlockService();
            int          pageId       = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);

            Rock.Model.Block block = blockService.Get((int)gLayoutBlocks.DataKeys[e.RowIndex]["id"]);
            if (CurrentBlock != null)
            {
                blockService.Delete(block, CurrentPersonId);
                blockService.Save(block, CurrentPersonId);
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.Layout);
            }

            BindGrids();
        }
コード例 #8
0
        private void TransformXml()
        {
            XslCompiledTransform xslTransformer = new XslCompiledTransform();

            xslTransformer.Load(Server.MapPath(GetAttributeValue("XSLTFile")));

            Rock.Web.Cache.PageCache rootPage = null;

            Guid pageGuid = Guid.Empty;

            if (Guid.TryParse(GetAttributeValue(ROOT_PAGE), out pageGuid))
            {
                rootPage = Rock.Web.Cache.PageCache.Read(pageGuid);
            }

            if (rootPage == null)
            {
                rootPage = CurrentPage;
            }

            int levelsDeep = Convert.ToInt32(GetAttributeValue(NUM_LEVELS));

            Dictionary <string, string> pageParameters = null;

            if (GetAttributeValue("IncludeCurrentParameters").AsBoolean())
            {
                pageParameters = CurrentPageReference.Parameters;
            }

            NameValueCollection queryString = null;

            if (GetAttributeValue("IncludeCurrentQueryString").AsBoolean())
            {
                queryString = CurrentPageReference.QueryString;
            }

            XDocument pageXml = rootPage.MenuXml(levelsDeep, CurrentPerson, CurrentPage, pageParameters, queryString);

            StringBuilder sb = new StringBuilder();
            TextWriter    tw = new StringWriter(sb);

            xslTransformer.Transform(pageXml.CreateReader(), null, tw);

            phContent.Controls.Clear();
            phContent.Controls.Add(new LiteralControl(sb.ToString()));
        }
コード例 #9
0
        /// <summary>
        /// Handles the Delete event of the gPageBlocks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gPageBlocks_Delete(object sender, RowEventArgs e)
        {
            BlockService blockService = new BlockService();
            int          pageId       = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            Rock.Model.Block block = blockService.Get(e.RowKeyId);
            if (CurrentBlock != null)
            {
                blockService.Delete(block, CurrentPersonId);
                blockService.Save(block, CurrentPersonId);
                page.FlushBlocks();
            }

            BindGrids();
        }
コード例 #10
0
        /// <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)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);

            string zoneName = this.PageParameter("ZoneName");

            lAllPages.Text = string.Format("All Pages Using '{0}' Layout", page.Layout);

            // TODO: Managing layout block instances should probably be controlled by site security
            if (page.IsAuthorized("Administrate", CurrentPerson))
            {
                gLayoutBlocks.DataKeyNames      = new string[] { "id" };
                gLayoutBlocks.Actions.ShowAdd   = true;
                gLayoutBlocks.Actions.AddClick += LayoutBlocks_Add;
                gLayoutBlocks.GridReorder      += gLayoutBlocks_GridReorder;
                gLayoutBlocks.GridRebind       += gLayoutBlocks_GridRebind;
            }

            if (page.IsAuthorized("Administrate", CurrentPerson))
            {
                gPageBlocks.DataKeyNames      = new string[] { "id" };
                gPageBlocks.Actions.ShowAdd   = true;
                gPageBlocks.Actions.AddClick += gPageBlocks_GridAdd;
                gPageBlocks.GridReorder      += gPageBlocks_GridReorder;
                gPageBlocks.GridRebind       += gPageBlocks_GridRebind;
            }

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

            this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("zone-add-load-{0}", this.ClientID), script, true);

            base.OnInit(e);
        }
コード例 #11
0
        /// <summary>
        /// Handles the Delete event of the gLayoutBlocks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gLayoutBlocks_Delete(object sender, RowEventArgs e)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);

            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);

            Rock.Model.Block block = blockService.Get((int)gLayoutBlocks.DataKeys[e.RowIndex]["id"]);
            if (block != null)
            {
                blockService.Delete(block);
                rockContext.SaveChanges();
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.LayoutId);
            }

            BindGrids();
        }
コード例 #12
0
        protected override void OnInit(EventArgs e)
        {
            CurrentPage.AddScriptLink(Page, "~/Scripts/bootstrap-tabs.js");

            int pageId = Convert.ToInt32(PageParameter("EditPage"));

            _page     = Rock.Web.Cache.PageCache.Read(pageId);
            _zoneName = this.PageParameter("ZoneName");

            lAllPages.Text = string.Format("All Pages Using '{0}' Layout", CurrentPage.Layout);

            // TODO: Managing layout block instances should probably be controlled by site security
            if (_page.IsAuthorized("Administrate", CurrentPerson))
            {
                gLayoutBlocks.DataKeyNames         = new string[] { "id" };
                gLayoutBlocks.Actions.IsAddEnabled = true;
                gLayoutBlocks.Actions.AddClick    += LayoutBlocks_Add;
                gLayoutBlocks.GridReorder         += gLayoutBlocks_GridReorder;
                gLayoutBlocks.GridRebind          += gLayoutBlocks_GridRebind;
            }

            if (_page.IsAuthorized("Administrate", CurrentPerson))
            {
                gPageBlocks.DataKeyNames         = new string[] { "id" };
                gPageBlocks.Actions.IsAddEnabled = true;
                gPageBlocks.Actions.AddClick    += gPageBlocks_GridAdd;
                gPageBlocks.GridReorder         += gPageBlocks_GridReorder;
                gPageBlocks.GridRebind          += gPageBlocks_GridRebind;
            }

            string script = string.Format(@"
        Sys.Application.add_load(function () {{
            $('#modal-popup div.modal-header h3 small', window.parent.document).html('{0}');
            $('#{1} a').click(function() {{ $('#{3}').val('Page'); }});
            $('#{2} a').click(function() {{ $('#{3}').val('Layout'); }});
        }});
    ", _zoneName, liPage.ClientID, liLayout.ClientID, hfOption.ClientID);

            this.Page.ClientScript.RegisterStartupScript(this.GetType(), string.Format("zone-add-load-{0}", this.ClientID), script, true);

            base.OnInit(e);
        }
コード例 #13
0
        /// <summary>
        /// Handles the Delete event of the gPageBlocks control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gPageBlocks_Delete(object sender, RowEventArgs e)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);

            Rock.Model.Block block = blockService.Get(e.RowKeyId);
            if (block != null)
            {
                blockService.Delete(block);
                rockContext.SaveChanges();
                page.FlushBlocks();
            }

            BindGrids();
        }
コード例 #14
0
        private void Render()
        {
            Rock.Web.Cache.PageCache rootPage = null;

            Guid pageGuid = Guid.Empty;

            if (Guid.TryParse(GetAttributeValue(ROOT_PAGE), out pageGuid))
            {
                rootPage = Rock.Web.Cache.PageCache.Read(pageGuid);
            }

            if (rootPage == null)
            {
                rootPage = CurrentPage;
            }

            int levelsDeep = Convert.ToInt32(GetAttributeValue(NUM_LEVELS));

            Dictionary <string, string> pageParameters = null;

            if (GetAttributeValue("IncludeCurrentParameters").AsBoolean())
            {
                pageParameters = CurrentPageReference.Parameters;
            }

            NameValueCollection queryString = null;

            if (GetAttributeValue("IncludeCurrentQueryString").AsBoolean())
            {
                queryString = CurrentPageReference.QueryString;
            }

            var pageProperties = new Dictionary <string, object>();

            pageProperties.Add("page", rootPage.GetMenuProperties(levelsDeep, CurrentPerson, CurrentPage, pageParameters, queryString));
            string content = GetTemplate().Render(Hash.FromDictionary(pageProperties));

            phContent.Controls.Clear();
            phContent.Controls.Add(new LiteralControl(content));
        }
コード例 #15
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 = CurrentPage.IsAuthorized("Administrate", CurrentPerson);
                }

                if (canConfigure)
                {
                    rGrid.DataKeyNames         = new string[] { "id" };
                    rGrid.Actions.IsAddEnabled = 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);
        }
コード例 #16
0
        // Copies the Model object to the Cached object
        private static PageCache CopyModel(Rock.Model.Page pageModel)
        {
            // Creates new object by copying properties of model
            var page = new Rock.Web.Cache.PageCache(pageModel);

            if (pageModel.Attributes != null)
            {
                foreach (var attribute in pageModel.Attributes)
                {
                    page.AttributeIds.Add(attribute.Value.Id);
                }
            }

            page.PageContexts = new Dictionary <string, string>();
            if (pageModel.PageContexts != null)
            {
                foreach (var pageContext in pageModel.PageContexts)
                {
                    page.PageContexts.Add(pageContext.Entity, pageContext.IdParameter);
                }
            }

            return(page);
        }
コード例 #17
0
ファイル: Pages.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        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 = CurrentPage.IsAuthorized( "Administrate", CurrentPerson );

                if ( canConfigure )
                {
                    rGrid.DataKeyNames = new string[] { "id" };
                    rGrid.Actions.IsAddEnabled = 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 );
        }
コード例 #18
0
ファイル: ZoneBlocks.ascx.cs プロジェクト: NewPointe/Rockit
        /// <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 )
            {
                lAllPages.Text = string.Format( "All Pages Using '{0}' Layout", _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() {{ $('#{3}').val('Page'); }});
                    $('#{2} a').click(function() {{ $('#{3}').val('Layout'); }});
                }});",
                    _ZoneName,
                    liPage.ClientID,
                    liLayout.ClientID,
                    hfOption.ClientID );

                this.Page.ClientScript.RegisterStartupScript( this.GetType(), string.Format( "zone-add-load-{0}", this.ClientID ), script, true );
            }
        }
コード例 #19
0
        /// <summary>
        /// Determine the logical page being requested by evaluating the routedata, or querystring and
        /// then loading the appropriate layout (ASPX) page
        /// </summary>
        /// <param name="requestContext"></param>
        /// <returns></returns>
        System.Web.IHttpHandler IRouteHandler.GetHttpHandler(RequestContext requestContext)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }

            string pageId  = "";
            int    routeId = -1;

            // Pages using the default routing URL will have the page id in the RouteData.Values collection
            if (requestContext.RouteData.Values["PageId"] != null)
            {
                pageId = (string)requestContext.RouteData.Values["PageId"];
            }
            // Pages that use a custom URL route will have the page id in the RouteDate.DataTokens collection
            else if (requestContext.RouteData.DataTokens["PageId"] != null)
            {
                pageId  = (string)requestContext.RouteData.DataTokens["PageId"];
                routeId = Int32.Parse((string)requestContext.RouteData.DataTokens["RouteId"]);
            }
            // If page has not been specified get the site by the domain and use the site's default page
            else
            {
                string host     = requestContext.HttpContext.Request.Url.Host;
                string cacheKey = "Rock:DomainSites";

                ObjectCache cache = MemoryCache.Default;
                Dictionary <string, int> sites = cache[cacheKey] as Dictionary <string, int>;
                if (sites == null)
                {
                    sites = new Dictionary <string, int>();
                }

                Rock.Web.Cache.SiteCache site = null;
                if (sites.ContainsKey(host))
                {
                    site = Rock.Web.Cache.SiteCache.Read(sites[host]);
                }
                else
                {
                    int siteId = 1;

                    Rock.Model.SiteDomainService siteDomainService = new Rock.Model.SiteDomainService();
                    Rock.Model.SiteDomain        siteDomain        = siteDomainService.GetByDomainContained(requestContext.HttpContext.Request.Url.Host);
                    if (siteDomain != null)
                    {
                        siteId = siteDomain.SiteId;
                    }
                    else
                    {
                        var siteService = new Rock.Model.SiteService();
                        var rockSite    = siteService.Get(SystemGuid.Site.SITE_ROCK_CHMS);
                        if (rockSite != null)
                        {
                            siteId = rockSite.Id;
                        }
                    }

                    sites.Add(host, siteId);
                    site = Rock.Web.Cache.SiteCache.Read(siteId);
                }

                cache[cacheKey] = sites;

                if (site != null && site.DefaultPageId.HasValue)
                {
                    pageId = site.DefaultPageId.Value.ToString();
                }

                if (string.IsNullOrEmpty(pageId))
                {
                    throw new SystemException("Invalid Site Configuration");
                }
            }

            Rock.Web.Cache.PageCache page = null;

            if (!string.IsNullOrEmpty(pageId))
            {
                page = Rock.Web.Cache.PageCache.Read(Convert.ToInt32(pageId));
                if (page == null)
                {
                    return(new HttpHandlerError(404));
                }
            }

            if (page != null && !String.IsNullOrEmpty(page.LayoutPath))
            {
                // load the route id
                page.RouteId = routeId;

                // Return the page using the cached route
                Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(page.LayoutPath, typeof(Rock.Web.UI.RockPage));
                cmsPage.CurrentPage = page;
                return(cmsPage);
            }
            else
            {
                string theme      = "RockCms";
                string layout     = "Default";
                string layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

                if (page != null)
                {
                    // load the route id
                    page.RouteId = routeId;

                    theme      = page.Site.Theme;
                    layout     = page.Layout;
                    layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

                    page.LayoutPath = layoutPath;
                }
                else
                {
                    page = Cache.PageCache.Read(new Model.Page());
                }

                try
                {
                    // Return the page for the selected theme and layout
                    Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));
                    cmsPage.CurrentPage = page;
                    return(cmsPage);
                }
                catch (System.Web.HttpException)
                {
                    // The Selected theme and/or layout didn't exist, attempt first to use the default layout in the selected theme
                    layout = "Default";

                    // If not using the Rock theme, verify that default Layout exists in the selected theme directory
                    if (theme != "RockCms" &&
                        !File.Exists(requestContext.HttpContext.Server.MapPath(string.Format("~/Themes/{0}/Layouts/Default.aspx", theme))))
                    {
                        // If default layout doesn't exist in the selected theme, switch to the Default layout
                        theme  = "RockCms";
                        layout = "Default";
                    }

                    // Build the path to the aspx file to
                    layoutPath = Rock.Web.Cache.PageCache.FormatPath(theme, layout);

                    if (page != null)
                    {
                        page.LayoutPath = layoutPath;
                    }

                    // Return the default layout and/or theme
                    Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));
                    cmsPage.CurrentPage = page;
                    return(cmsPage);
                }
            }
        }
コード例 #20
0
ファイル: ZoneBlocks.ascx.cs プロジェクト: jh2mhs8/Rock-ChMS
        protected override void OnInit( EventArgs e )
        {
            CurrentPage.AddScriptLink( Page, "~/Scripts/bootstrap-tabs.js" );

            int pageId = Convert.ToInt32( PageParameter( "EditPage" ) );
            _page = Rock.Web.Cache.PageCache.Read( pageId );
            _zoneName = this.PageParameter( "ZoneName" );

            lAllPages.Text = string.Format( "All Pages Using '{0}' Layout", CurrentPage.Layout );

            // TODO: Managing layout block instances should probably be controlled by site security
            if ( _page.IsAuthorized( "Administrate", CurrentPerson ) )
            {
                gLayoutBlocks.DataKeyNames = new string[] { "id" };
                gLayoutBlocks.Actions.IsAddEnabled = true;
                gLayoutBlocks.Actions.AddClick += LayoutBlocks_Add;
                gLayoutBlocks.GridReorder += gLayoutBlocks_GridReorder;
                gLayoutBlocks.GridRebind += gLayoutBlocks_GridRebind;
            }

            if ( _page.IsAuthorized( "Administrate", CurrentPerson ) )
            {
                gPageBlocks.DataKeyNames = new string[] { "id" };
                gPageBlocks.Actions.IsAddEnabled = true;
                gPageBlocks.Actions.AddClick += gPageBlocks_GridAdd;
                gPageBlocks.GridReorder += gPageBlocks_GridReorder;
                gPageBlocks.GridRebind += gPageBlocks_GridRebind;
            }

            string script = string.Format( @"
            Sys.Application.add_load(function () {{
            $('#modal-popup div.modal-header h3 small', window.parent.document).html('{0}');
            $('#{1} a').click(function() {{ $('#{3}').val('Page'); }});
            $('#{2} a').click(function() {{ $('#{3}').val('Layout'); }});
            }});
            ", _zoneName, liPage.ClientID, liLayout.ClientID, hfOption.ClientID );

            this.Page.ClientScript.RegisterStartupScript( this.GetType(), string.Format( "zone-add-load-{0}", this.ClientID ), script, true );

            base.OnInit( e );
        }
コード例 #21
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int pageId = PageParameter("EditPage").AsInteger() ?? 0;

            Rock.Web.Cache.PageCache page = Rock.Web.Cache.PageCache.Read(pageId);
            string zoneName = this.PageParameter("ZoneName");

            Rock.Model.Block block;

            var          rockContext  = new RockContext();
            BlockService blockService = new BlockService(rockContext);

            int blockId = hfBlockId.ValueAsInt();

            if (blockId == 0)
            {
                block = new Rock.Model.Block();

                BlockLocation location = hfBlockLocation.Value.ConvertToEnum <BlockLocation>();
                if (location == BlockLocation.Layout)
                {
                    block.LayoutId = page.LayoutId;
                    block.PageId   = null;
                }
                else
                {
                    block.LayoutId = null;
                    block.PageId   = page.Id;
                }

                block.Zone = zoneName;

                Rock.Model.Block lastBlock = blockService.GetByPageAndZone(page.Id, zoneName).OrderByDescending(b => b.Order).FirstOrDefault();

                if (lastBlock != null)
                {
                    block.Order = lastBlock.Order + 1;
                }
                else
                {
                    block.Order = 0;
                }

                blockService.Add(block);
            }
            else
            {
                block = blockService.Get(blockId);
            }

            block.Name        = tbBlockName.Text;
            block.BlockTypeId = Convert.ToInt32(ddlBlockType.SelectedValue);

            rockContext.SaveChanges();

            Rock.Security.Authorization.CopyAuthorization(page, block);

            if (block.Layout != null)
            {
                Rock.Web.Cache.PageCache.FlushLayoutBlocks(page.LayoutId);
            }
            else
            {
                page.FlushBlocks();
            }

            BindGrids();

            pnlDetails.Visible = false;
            pnlLists.Visible   = true;
        }
コード例 #22
0
        protected override void OnInit(EventArgs e)
        {
            Rock.Web.UI.DialogMasterPage masterPage = this.Page.Master as Rock.Web.UI.DialogMasterPage;
            if (masterPage != null)
            {
                masterPage.OnSave += new EventHandler <EventArgs>(masterPage_OnSave);
            }

            try
            {
                int pageId = Convert.ToInt32(PageParameter("Page"));
                _page = Rock.Web.Cache.PageCache.Read(pageId);

                if (_page.IsAuthorized("Administrate", CurrentPerson))
                {
                    phAttributes.Controls.Clear();
                    Rock.Attribute.Helper.AddEditControls(_page, phAttributes, !Page.IsPostBack);

                    List <string> blockContexts = new List <string>();
                    foreach (var block in _page.Blocks)
                    {
                        var blockControl = TemplateControl.LoadControl(block.BlockType.Path) as Rock.Web.UI.RockBlock;
                        if (blockControl != null)
                        {
                            blockControl.CurrentPage  = _page;
                            blockControl.CurrentBlock = block;
                            foreach (var context in blockControl.ContextTypesRequired)
                            {
                                if (!blockContexts.Contains(context))
                                {
                                    blockContexts.Add(context);
                                }
                            }
                        }
                    }

                    phContextPanel.Visible = blockContexts.Count > 0;

                    int i = 0;
                    foreach (string context in blockContexts)
                    {
                        var tbContext = new LabeledTextBox();
                        tbContext.ID        = string.Format("context_{0}", i++);
                        tbContext.Required  = true;
                        tbContext.LabelText = context;

                        if (_page.PageContexts.ContainsKey(context))
                        {
                            tbContext.Text = _page.PageContexts[context];
                        }

                        phContext.Controls.Add(tbContext);
                    }
                }
                else
                {
                    DisplayError("You are not authorized to edit this page");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
コード例 #23
0
        private void TransformXml()
        {
            string outputString = string.Empty;

            // ensure xslt file exists
            string xsltFile = Server.MapPath(GetAttributeValue("XSLTFile"));

            if (System.IO.File.Exists(xsltFile))
            {
                // try compiling the XSLT
                try
                {
                    XslCompiledTransform xslTransformer = new XslCompiledTransform();
                    xslTransformer.Load(xsltFile);

                    Rock.Web.Cache.PageCache rootPage = null;

                    Guid pageGuid = Guid.Empty;
                    if (Guid.TryParse(GetAttributeValue(ROOT_PAGE), out pageGuid))
                    {
                        rootPage = Rock.Web.Cache.PageCache.Read(pageGuid);
                    }

                    if (rootPage == null)
                    {
                        rootPage = CurrentPage;
                    }

                    int levelsDeep = Convert.ToInt32(GetAttributeValue(NUM_LEVELS));

                    Dictionary <string, string> pageParameters = null;
                    if (GetAttributeValue("IncludeCurrentParameters").AsBoolean())
                    {
                        pageParameters = CurrentPageReference.Parameters;
                    }

                    NameValueCollection queryString = null;
                    if (GetAttributeValue("IncludeCurrentQueryString").AsBoolean())
                    {
                        queryString = CurrentPageReference.QueryString;
                    }

                    XDocument pageXml = rootPage.MenuXml(levelsDeep, CurrentPerson, CurrentPage, pageParameters, queryString);

                    // if debug the output the xml
                    string showDebugValue = GetAttributeValue("ShowDebug") ?? string.Empty;
                    bool   showDebug      = showDebugValue.Equals("true", StringComparison.OrdinalIgnoreCase);

                    if (showDebug || string.IsNullOrWhiteSpace(xsltFile))
                    {
                        outputString = "<pre><code>" + HttpUtility.HtmlEncode(pageXml.ToString()) + "</code></pre>";
                    }
                    else
                    {
                        // transform xml
                        StringBuilder sb = new StringBuilder();
                        TextWriter    tw = new StringWriter(sb);

                        xslTransformer.Transform(pageXml.CreateReader(), null, tw);

                        outputString = sb.ToString();
                    }
                }
                catch (Exception ex)
                {
                    // xslt compile error
                    string exMessage = "An excception occurred while compiling the XSLT template.";

                    if (ex.InnerException != null)
                    {
                        exMessage += "<br /><em>" + ex.InnerException.Message + "</em>";
                    }

                    outputString = "<div class='alert warning' style='margin: 24px auto 0 auto; max-width: 500px;' ><strong>XSLT Compile Error</strong><p>" + exMessage + "</p></div>";
                }
            }
            else
            {
                outputString = "<div class='alert warning' style='margin: 24px auto 0 auto; max-width: 500px;' ><strong>Warning!</strong><p>The XSLT file required to process the page list could not be found.</p><p><em>" + xsltFile + "</em></p>";
            }

            phContent.Controls.Clear();

            phContent.Controls.Add(new LiteralControl(outputString));
        }