Exemple #1
0
        /// <summary>
        /// Output just the scripts for the Agility preview and development bar.
        /// </summary>
        /// <param name="helper"></param>
        public static HtmlString RenderAgilityPreviewBarScripts(this IHtmlHelper helper)
        {
            Agility.Web.Objects.AgilityPage p = AgilityContext.Page;
            if (p != null)
            {
                StringBuilder sb = new StringBuilder();

                //inject the status panel scripts
                if (AgilityContext.IsPreview || Current.Settings.DevelopmentMode)
                {
                    string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery();
                    sb.Append(script);
                }


                //handle dependencies on ouput cache...
                if (AgilityContext.OutputCacheKeys.Count > 0)
                {
                    AgilityCache.AddResponseCacheDependancy(AgilityContext.OutputCacheKeys);
                }

                return(new HtmlString(sb.ToString()));
            }
            else if (AgilityContext.IsTemplatePreview)
            {
                //template preview...
                string script = StatusPanelEmitter.GetStatusPanelScriptNoJQuery();

                return(new HtmlString(script));
            }
            else
            {
                return(new HtmlString(""));
            }
        }
Exemple #2
0
 /// <summary>
 /// Render only the Agility Preview Bar CSS.  This should ONLY be used if the Agility CSS and Meta information is being outputted separately.
 /// </summary>
 /// <param name="helper"></param>
 public static HtmlString RenderAgilityPreviewBarCss(this IHtmlHelper helper)
 {
     //add the StatusPanelEmitter if in preview mode, development mode, or edit in place
     if (AgilityContext.IsPreview ||
         Current.Settings.DevelopmentMode ||
         AgilityContext.IsTemplatePreview)
     {
         return(new HtmlString(StatusPanelEmitter.GetStatusPanelCss()));
     }
     else
     {
         return(new HtmlString(""));
     }
 }
Exemple #3
0
        /// <summary>
        /// Render the bottom scripts and the Preview bar scripts, including a jQuery reference.
        /// </summary>
        /// <param name="helper"></param>
        public static HtmlString RenderAgilityScripts(this IHtmlHelper helper)
        {
            StringBuilder sb = new StringBuilder();

            Agility.Web.Objects.AgilityPage p = AgilityContext.Page;
            if (p != null)
            {
                //inject the status panel scripts
                if (AgilityContext.IsPreview || Current.Settings.DevelopmentMode)
                {
                    string script = StatusPanelEmitter.GetStatusPanelScript();
                    sb.Append(script);
                    // helper.ViewContext.Writer.Write(script);
                }

                if (!string.IsNullOrEmpty(p.CustomAnalyticsScript))
                {
                    string script = p.CustomAnalyticsScript;

                    if (script.IndexOf(GLOBAL_SCRIPT_SEPARATOR) != -1)
                    {
                        string scriptBottomPage = script.Substring(script.IndexOf(GLOBAL_SCRIPT_SEPARATOR) + GLOBAL_SCRIPT_SEPARATOR.Length);
                        if (!string.IsNullOrEmpty(scriptBottomPage))
                        {
                            sb.Append(scriptBottomPage);
                            // helper.ViewContext.Writer.Write(scriptBottomPage);
                        }
                    }
                }


                //add the Javascript tracking stuff
                if (p.IncludeInStatsTracking)
                {
                    //global script
                    if (!string.IsNullOrEmpty(AgilityContext.Domain.StatsTrackingScript))
                    {
                        string scriptTopGlobal = AgilityContext.Domain.StatsTrackingScript;

                        if (scriptTopGlobal.IndexOf(GLOBAL_SCRIPT_SEPARATOR) != -1)
                        {
                            string scriptBottomGlobal = scriptTopGlobal.Substring(scriptTopGlobal.IndexOf(GLOBAL_SCRIPT_SEPARATOR) + GLOBAL_SCRIPT_SEPARATOR.Length);
                            if (!string.IsNullOrEmpty(scriptBottomGlobal))
                            {
                                sb.Append(scriptBottomGlobal);
                                // helper.ViewContext.Writer.Write(scriptBottomGlobal);
                            }
                        }
                    }
                }



                //handle dependencies on ouput cache...
                if (AgilityContext.OutputCacheKeys.Count > 0)
                {
                    AgilityCache.AddResponseCacheDependancy(AgilityContext.OutputCacheKeys);
                }
            }
            else if (AgilityContext.IsTemplatePreview)
            {
                //template preview...
                string script = StatusPanelEmitter.GetStatusPanelScript();

                sb.Append(script);
                // helper.ViewContext.Writer.Write(script);
            }

            return(new HtmlString(sb.ToString()));
        }
Exemple #4
0
        public static HtmlString RenderAgilityCss(this IHtmlHelper helper)
        {
            AgilityContext.HttpContext = helper.ViewContext.HttpContext;
            AgilityPage currentPage = AgilityContext.Page;

            StringBuilder sb = new StringBuilder(Environment.NewLine);

            if (currentPage != null)
            {
                //canonical link
                if (!string.IsNullOrEmpty(AgilityContext.CanonicalLink))
                {
                    sb.AppendFormat("<link rel=\"canonical\" href=\"{0}\" />", AgilityContext.CanonicalLink);
                    sb.Append(Environment.NewLine);
                }

                //set the page specific meta tags
                sb.Append("<meta name=\"description\" content=\"").Append(currentPage.MetaTags).Append("\" />");
                sb.Append(Environment.NewLine);

                if (!string.IsNullOrEmpty(currentPage.MetaKeyWords))
                {
                    sb.Append("<meta name=\"keywords\" content=\"").Append(currentPage.MetaKeyWords).Append("\" />");
                    sb.Append(Environment.NewLine);
                }

                string rawTags = currentPage.MetaTagsRaw;
                if (rawTags == null)
                {
                    rawTags = string.Empty;
                }

                if (!string.IsNullOrEmpty(rawTags))
                {
                    sb.Append(Agility.Web.Util.Url.ResolveTildaUrlsInHtml(rawTags));
                    sb.Append(Environment.NewLine);
                }

                if (!string.IsNullOrEmpty(AgilityContext.TwitterCardSite))
                {
                    if (rawTags.IndexOf("<meta name=\"twitter:site\"", StringComparison.CurrentCultureIgnoreCase) == -1)
                    {
                        string site = AgilityContext.TwitterCardSite;
                        if (!site.StartsWith("@"))
                        {
                            site = string.Format("@{0}", site);
                        }

                        sb.AppendFormat("<meta name=\"twitter:site\" value=\"{0}\" />", site);
                    }

                    string twitterCardType = "summary";
                    if (!string.IsNullOrEmpty(AgilityContext.FeaturedImageUrl))
                    {
                        twitterCardType = "summary_large_image";
                        sb.AppendFormat("<meta name=\"twitter:image:src\" content=\"{0}\" />", AgilityContext.FeaturedImageUrl);
                    }

                    sb.AppendFormat("<meta name=\"twitter:card\" content=\"{0}\" />", twitterCardType);
                    sb.AppendFormat("<meta name=\"twitter:title\" content=\"{0}\" />", currentPage.Title);
                    sb.AppendFormat("<meta name=\"twitter:description\" content=\"{0}\" />", currentPage.MetaTags);
                }

                if (Current.Settings.OutputOpenGraph)
                {
                    sb.AppendFormat("<meta name=\"og:title\" content=\"{0}\" />", currentPage.Title);
                    sb.AppendFormat("<meta name=\"og:description\" content=\"{0}\" />", currentPage.MetaTags);
                    if (!string.IsNullOrEmpty(AgilityContext.FeaturedImageUrl))
                    {
                        sb.AppendFormat("<meta name=\"og:image\" content=\"{0}\" />", AgilityContext.FeaturedImageUrl);
                        sb.Append(Environment.NewLine);
                    }
                }

                //content language
                sb.Append("<meta http-equiv='content-language' content='").Append(currentPage.LanguageCode).Append("'/>");
                sb.Append(Environment.NewLine);

                //default css...
                string globalCss = AgilityContext.Domain.GlobalCss;
                if (AgilityContext.Domain != null)
                {
                    globalCss = AgilityContext.Domain.GlobalCss;
                }
                if (!string.IsNullOrEmpty(globalCss))
                {
                    string url = AgilityHelpers.ResolveUrl(helper,
                                                           string.Format("~/{0}/global.css",
                                                                         Agility.Web.HttpModules.AgilityHttpModule.ECMS_EDITOR_CSS_KEY));
                    sb.AppendFormat("<link rel=\"stylesheet\" type=\"text/css\" href=\"{0}\" />", url);
                }


                //set the custom agility meta tags

                sb.Append("<meta name=\"generator\" content=\"Agility CMS\" />");
                sb.Append(Environment.NewLine);

                //Timestamp is now in not modified since
                // sb.AppendFormat("<meta name=\"agility_timestamp\" content=\"{0:yyyy/MM/dd hh:mm:ss tt}\" />", DateTime.Now);

                sb.AppendFormat("<meta name=\"agility_attributes\" content=\"Mode={0}, IsPreview={1}, Language={2}, Machine={3}, CustomOutputCache={4}\" />",
                                AgilityContext.CurrentMode,
                                AgilityContext.IsPreview,
                                AgilityContext.LanguageCode,
                                Environment.MachineName,
                                AgilityCache.UseAgilityOutputCache);
                sb.Append(Environment.NewLine);
            }

            //add the StatusPanelEmitter if in preview mode, development mode, or edit in place
            if (AgilityContext.IsPreview ||
                Current.Settings.DevelopmentMode ||
                AgilityContext.IsTemplatePreview)
            {
                sb.Append(StatusPanelEmitter.GetStatusPanelCssOnly());
            }

            return(new HtmlString(sb.ToString()));
        }