RockPage is the base abstract class that all page templates in Rock should inherit from
Inheritance: System.Web.UI.Page
        public MobileBlockResponse BlockPostRequest(int id, string arg = "")
        {
            HttpContent requestContent = Request.Content;
            string      content        = requestContent.ReadAsStringAsync().Result;
            var         body           = JsonConvert.DeserializeObject <Dictionary <string, string> >(content);
            var         person         = GetPerson();

            HttpContext.Current.Items.Add("CurrentPerson", person);
            var    blockCache = BlockCache.Read(id);
            var    pageCache  = PageCache.Read(blockCache.PageId ?? 0);
            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            if (blockCache.IsAuthorized(Authorization.VIEW, person))
            {
                var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);

                if (control is RockBlock && control is IMobileResource)
                {
                    control.SetBlock(pageCache, blockCache);
                    var mobileResource      = control as IMobileResource;
                    var mobileBlockResponse = mobileResource.HandleRequest(arg, body);
                    mobileBlockResponse.TTL = 0;
                    return(mobileBlockResponse);
                }
            }
            return(new MobileBlockResponse());
        }
        public MobileBlockResponse BlockGetRequest(int id, string request = "")
        {
            var person = GetPerson();

            HttpContext.Current.Items.Add("CurrentPerson", person);
            var    blockCache = BlockCache.Read(id);
            var    pageCache  = PageCache.Read(blockCache.PageId ?? 0);
            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            if (blockCache.IsAuthorized(Authorization.VIEW, person))
            {
                var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);

                if (control is RockBlock && control is IMobileResource)
                {
                    control.SetBlock(pageCache, blockCache);
                    var mobileResource      = control as IMobileResource;
                    var mobileBlockResponse = mobileResource.HandleRequest(request, new Dictionary <string, string>());
                    HttpContext.Current.Response.Headers.Set("TTL", mobileBlockResponse.TTL.ToString());
                    return(mobileBlockResponse);
                }
            }
            HttpContext.Current.Response.Headers.Set("TTL", "0");
            return(new MobileBlockResponse());
        }
示例#3
0
        public MobilePage GetPage(int id, string parameter = "")
        {
            var person = GetPerson();

            if (!HttpContext.Current.Items.Contains("CurrentPerson"))
            {
                HttpContext.Current.Items.Add("CurrentPerson", person);
            }

            var pageCache = PageCache.Read(id);

            if (!pageCache.IsAuthorized(Authorization.VIEW, person))
            {
                return(new MobilePage());
            }

            SavePageViewInteraction(pageCache, person);

            string theme      = pageCache.Layout.Site.Theme;
            string layout     = pageCache.Layout.FileName;
            string layoutPath = PageCache.FormatPath(theme, layout);

            Rock.Web.UI.RockPage cmsPage = (Rock.Web.UI.RockPage)BuildManager.CreateInstanceFromVirtualPath(layoutPath, typeof(Rock.Web.UI.RockPage));

            MobilePage mobilePage = new MobilePage();

            mobilePage.Layout    = AvalancheUtilities.GetLayout(pageCache.Layout.Name);
            mobilePage.Title     = pageCache.PageTitle;
            mobilePage.ShowTitle = pageCache.PageDisplayTitle;
            foreach (var attribute in pageCache.AttributeValues)
            {
                mobilePage.Attributes.Add(attribute.Key, attribute.Value.ValueFormatted);
            }
            foreach (var block in pageCache.Blocks)
            {
                if (block.IsAuthorized(Authorization.VIEW, person))
                {
                    var blockCache = BlockCache.Read(block.Id);
                    try
                    {
                        var control = ( RockBlock )cmsPage.TemplateControl.LoadControl(blockCache.BlockType.Path);
                        if (control is RockBlock && control is IMobileResource)
                        {
                            control.SetBlock(pageCache, blockCache);
                            var mobileResource = control as IMobileResource;
                            var mobileBlock    = mobileResource.GetMobile(parameter);
                            mobileBlock.BlockId = blockCache.Id;
                            mobileBlock.Zone    = blockCache.Zone;
                            mobilePage.Blocks.Add(mobileBlock);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionLogService.LogException(e, HttpContext.Current);
                    }
                }
            }
            HttpContext.Current.Response.Headers.Set("TTL", pageCache.OutputCacheDuration.ToString());
            return(mobilePage);
        }
示例#4
0
        /// <summary>
        /// Gets the parent page references.
        /// </summary>
        /// <returns></returns>
        public static List<PageReference> GetParentPageReferences(RockPage rockPage, PageCache currentPage, PageReference currentPageReference)
        {
            // Get previous page references in nav history
            var pageReferenceHistory = HttpContext.Current.Session["RockPageReferenceHistory"] as List<PageReference>;

            // Current page heirarchy references
            var pageReferences = new List<PageReference>();

            if (currentPage != null)
            {
                var parentPage = currentPage.ParentPage;
                if ( parentPage != null )
                {
                    var currentParentPages = parentPage.GetPageHierarchy();
                    if ( currentParentPages != null && currentParentPages.Count > 0 )
                    {
                        currentParentPages.Reverse();
                        foreach ( PageCache page in currentParentPages )
                        {
                            PageReference parentPageReference = null;
                            if ( pageReferenceHistory != null )
                            {
                                parentPageReference = pageReferenceHistory.Where( p => p.PageId == page.Id ).FirstOrDefault();
                            }

                            if ( parentPageReference == null )
                            {
                                parentPageReference = new PageReference( );
                                parentPageReference.PageId = page.Id;

                                parentPageReference.BreadCrumbs = new List<BreadCrumb>();
                                parentPageReference.QueryString = new NameValueCollection();
                                parentPageReference.Parameters = new Dictionary<string, string>();

                                string bcName = page.BreadCrumbText;
                                if ( bcName != string.Empty )
                                {
                                    parentPageReference.BreadCrumbs.Add( new BreadCrumb( bcName, parentPageReference.BuildUrl() ) );
                                }

                                foreach ( var block in page.Blocks.Where( b=> b.BlockLocation == Model.BlockLocation.Page) )
                                {
                                    try
                                    {
                                        System.Web.UI.Control control = rockPage.TemplateControl.LoadControl(block.BlockType.Path);
                                        if (control is RockBlock)
                                        {
                                            RockBlock rockBlock = control as RockBlock;
                                            rockBlock.SetBlock(page, block);
                                            rockBlock.GetBreadCrumbs(parentPageReference).ForEach(c => parentPageReference.BreadCrumbs.Add(c));
                                        }
                                        control = null;
                                    }
                                    catch (Exception ex)
                                    {
                                        ExceptionLogService.LogException(ex, HttpContext.Current, currentPage.Id, currentPage.Layout.SiteId);
                                    }
                                }

                            }

                            parentPageReference.BreadCrumbs.ForEach( c => c.Active = false );
                            pageReferences.Add( parentPageReference );
                        }
                    }
                }
            }

            return pageReferences;
        }
示例#5
0
        /// <summary>
        /// Gets the common merge fields for Lava operations. By default it'll include CurrentPerson, Context, PageParameter, and Campuses
        /// </summary>
        /// <param name="rockPage">The rock page.</param>
        /// <param name="currentPerson">The current person.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static Dictionary<string, object> GetCommonMergeFields( RockPage rockPage, Person currentPerson = null, CommonMergeFieldsOptions options = null )
        {
            var mergeFields = new Dictionary<string, object>();

            if ( rockPage == null && HttpContext.Current != null )
            {
                rockPage = HttpContext.Current.Handler as RockPage;
            }

            if ( options == null )
            {
                options = new CommonMergeFieldsOptions();
            }

            if ( currentPerson == null )
            {
                if ( rockPage != null )
                {
                    currentPerson = rockPage.CurrentPerson;
                }
                else if ( HttpContext.Current != null && HttpContext.Current.Items.Contains( "CurrentPerson" ) )
                {
                    currentPerson = HttpContext.Current.Items["CurrentPerson"] as Person;
                }
            }

            if ( options.GetLegacyGlobalMergeFields )
            {
                var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
                if ( globalAttributes.LavaSupportLevel != Lava.LavaSupportLevel.NoLegacy )
                {
                    var legacyGlobalAttributeMergeFields = Rock.Web.Cache.GlobalAttributesCache.GetLegacyMergeFields( currentPerson );
                    foreach ( var legacyGlobalAttributeMergeField in legacyGlobalAttributeMergeFields )
                    {
                        mergeFields.Add( legacyGlobalAttributeMergeField.Key, legacyGlobalAttributeMergeField.Value );
                    }
                }
            }

            if ( options.GetPageContext && rockPage != null )
            {
                var contextObjects = new Dictionary<string, object>();
                foreach ( var contextEntityType in rockPage.GetContextEntityTypes() )
                {
                    var contextEntity = rockPage.GetCurrentContext( contextEntityType );
                    if ( contextEntity != null && contextEntity is DotLiquid.ILiquidizable )
                    {
                        var type = Type.GetType( contextEntityType.AssemblyName ?? contextEntityType.Name );
                        if ( type != null )
                        {
                            contextObjects.Add( type.Name, contextEntity );
                        }
                    }
                }

                if ( contextObjects.Any() )
                {
                    mergeFields.Add( "Context", contextObjects );
                }
            }

            HttpRequest request = null;
            try
            {
                if ( rockPage != null )
                {
                    request = rockPage.Request;
                }
                else if ( HttpContext.Current != null )
                {
                    request = HttpContext.Current.Request;
                }
            }
            catch
            {
                // intentionally ignore exception (.Request will throw an exception instead of simply returning null if it isn't available)
            }

            if ( options.GetPageParameters && rockPage != null && request != null)
            {
                mergeFields.Add( "PageParameter", rockPage.PageParameters() );
            }

            if ( options.GetOSFamily || options.GetDeviceFamily )
            {
                if ( request != null && !string.IsNullOrEmpty( request.UserAgent ) )
                {
                    Parser uaParser = Parser.GetDefault();
                    ClientInfo client = uaParser.Parse( request.UserAgent );
                    if ( options.GetOSFamily )
                    {
                        mergeFields.Add( "OSFamily", client.OS.Family.ToLower() );
                    }

                    if ( options.GetDeviceFamily )
                    {
                        mergeFields.Add( "DeviceFamily", client.Device.Family );
                    }
                }
            }

            if ( options.GetCurrentPerson )
            {
                if ( currentPerson != null )
                {
                    mergeFields.Add( "CurrentPerson", currentPerson );
                }
            }

            if ( options.GetCampuses )
            {
                mergeFields.Add( "Campuses", CampusCache.All() );
            }

            return mergeFields;
        }
示例#6
0
 /// <summary>
 /// Gets the page properties merge object.
 /// </summary>
 /// <param name="rockPage">The rock page.</param>
 /// <returns></returns>
 public static Dictionary<string, object> GetPagePropertiesMergeObject( RockPage rockPage )
 {
     Dictionary<string, object> pageProperties = new Dictionary<string, object>();
     pageProperties.Add( "Id", rockPage.PageId.ToString() );
     pageProperties.Add( "BrowserTitle", rockPage.BrowserTitle );
     pageProperties.Add( "PageTitle", rockPage.PageTitle );
     pageProperties.Add( "Site", rockPage.Site.Name );
     pageProperties.Add( "SiteId", rockPage.Site.Id.ToString() );
     pageProperties.Add( "LayoutId", rockPage.Layout.Id.ToString() );
     pageProperties.Add( "Layout", rockPage.Layout.Name );
     pageProperties.Add( "SiteTheme", rockPage.Site.Theme );
     pageProperties.Add( "PageIcon", rockPage.PageIcon );
     pageProperties.Add( "Description", rockPage.MetaDescription );
     return pageProperties;
 }