Exemplo n.º 1
0
        /// <summary>
        /// Gets the state of the AMP output filter.
        /// </summary>
        /// <returns>
        ///  DISABLED - filter is disabled for current page
        ///  ENABLED_AND_ACTIVE - filter is enabled for current page and activated (page is being accessed from AMP domain)
        ///  ENABLED_AND_INACTIVE - filter is enabled for current page but not active
        /// </returns>
        public static int GetFilterState()
        {
            // Check if AMP filter is enabled in site settings
            if (!Settings.AmpFilterEnabled)
            {
                return(Constants.DISABLED);
            }

            // Apply filter only in LiveSite or Preview mode
            if (PortalContext.ViewMode != ViewModeEnum.LiveSite && PortalContext.ViewMode != ViewModeEnum.Preview)
            {
                return(Constants.DISABLED);
            }

            // Check if current page is allowed to use AMP filter
            ObjectQuery <AmpFilterInfo> q = AmpFilterInfoProvider.GetAmpFilters().WhereEquals("PageNodeGuid", DocumentContext.CurrentPageInfo.NodeGUID.ToString());

            if (q.Count == 0)
            {
                return(Constants.DISABLED);
            }

            // Check if the domain from which we are accessing is set for AMP filter
            string currentDomain = CMSHttpContext.Current.Request.Url.IsDefaultPort ? CMSHttpContext.Current.Request.Url.Host : CMSHttpContext.Current.Request.Url.Host + ":" + CMSHttpContext.Current.Request.Url.Port;
            string ampDomain     = Settings.AmpFilterDomainAlias;

            if (!currentDomain.Equals(ampDomain))
            {
                return(Constants.ENABLED_AND_INACTIVE);
            }

            return(Constants.ENABLED_AND_ACTIVE);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns CSS stylesheet for current page.
        /// Stylesheet can be:
        ///     - normal CSS of current page
        ///     - default CSS for all AMP pages
        ///     - CSS set as AMP stylesheet for current page
        /// </summary>
        private string GetStylesheetText()
        {
            string cssText = "";

            // Checking which CSS file to use
            ObjectQuery <AmpFilterInfo> q = AmpFilterInfoProvider.GetAmpFilters().WhereEquals("PageNodeGuid", DocumentContext.CurrentPageInfo.NodeGUID.ToString());
            AmpFilterInfo ampFilterInfo   = q.FirstOrDefault();

            bool useDefaultStylesheet = ampFilterInfo?.UseDefaultStylesheet ?? true;

            if (useDefaultStylesheet)
            {
                // Get the ID of default AMP CSS
                string defaultID = Settings.AmpFilterDefaultCSS;
                var    cssID     = ValidationHelper.GetInteger(defaultID, 0);

                // Default AMP CSS is not set, using ordinary CSS of current page
                if (cssID == 0)
                {
                    cssText = DocumentContext.CurrentDocumentStylesheet?.StylesheetText;
                }
                else
                {
                    // Use default AMP CSS stylesheet
                    var cssInfo = CssStylesheetInfoProvider.GetCssStylesheetInfo(cssID);
                    if (cssInfo != null)
                    {
                        cssText = cssInfo.StylesheetText;
                    }
                }
            }
            else
            {
                // Use specific AMP CSS set for this page
                int stylesheetID = ampFilterInfo?.StylesheetID ?? 0;
                var cssInfo      = CssStylesheetInfoProvider.GetCssStylesheetInfo(stylesheetID);
                if (cssInfo != null)
                {
                    cssText = cssInfo.StylesheetText;
                }
            }

            // Resolve macros
            cssText = MacroResolver.Resolve(cssText);

            // Resolve client URL
            return(HTMLHelper.ResolveCSSClientUrls(cssText, CMSHttpContext.Current.Request.Url.ToString()));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Updates the object using appropriate provider.
 /// </summary>
 protected override void SetObject()
 {
     AmpFilterInfoProvider.SetAmpFilterInfo(this);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Deletes the object using appropriate provider.
 /// </summary>
 protected override void DeleteObject()
 {
     AmpFilterInfoProvider.DeleteAmpFilterInfo(this);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns data only for current site context
 /// </summary>
 /// <param name="data">Data set</param>
 private DataSet Control_OnAfterRetrieveData(DataSet data)
 {
     return(AmpFilterInfoProvider.GetAmpFilters().WhereEquals("SiteID", SiteContext.CurrentSiteID).Result);
 }