diff --git a/umbraco/presentation/default.aspx.cs b/umbraco/presentation/default.aspx.cs index fc3c04521a..71f42ee330 100644 --- a/umbraco/presentation/default.aspx.cs +++ b/umbraco/presentation/default.aspx.cs @@ -206,6 +206,9 @@ namespace umbraco if (!UmbracoSettings.UseAspNetMasterPages) initUmbracoPage(); base.OnInit(e); + + // Add Umbraco header + Response.AddHeader("X-Umbraco-Version", string.Format("{0}.{1}", GlobalSettings.VersionMajor, GlobalSettings.VersionMinor)); } private void initUmbracoPage() diff --git a/umbraco/presentation/macro.cs b/umbraco/presentation/macro.cs index e83466dad8..23516756a7 100644 --- a/umbraco/presentation/macro.cs +++ b/umbraco/presentation/macro.cs @@ -1,11 +1,11 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Data; using System.Diagnostics; using System.IO; using System.Net; using System.Reflection; +using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Web; @@ -14,19 +14,18 @@ using System.Web.UI; using System.Web.UI.WebControls; using System.Xml; using System.Xml.Xsl; - using umbraco.BusinessLogic; -using umbraco.cms.businesslogic; -using Content = umbraco.cms.businesslogic.Content; -using umbraco.cms.businesslogic.macro; using umbraco.cms.businesslogic.member; using umbraco.DataLayer; using umbraco.interfaces; +using umbraco.IO; +using umbraco.Models; +using umbraco.presentation.nodeFactory; +using umbraco.presentation.templateControls; using umbraco.presentation.xslt.Exslt; using umbraco.scripting; -using umbraco.presentation.nodeFactory; -using templateControls = umbraco.presentation.templateControls; -using umbraco.IO; +using Content = umbraco.cms.businesslogic.Content; +using Macro = umbraco.cms.businesslogic.macro.Macro; namespace umbraco { @@ -37,85 +36,65 @@ namespace umbraco { #region private properties - private readonly StringBuilder mContent = new StringBuilder(); - private readonly Cache macroCache = HttpRuntime.Cache; - - private readonly String macroCacheIdentifier = "umbMacro"; - private readonly string macrosAddedKey = "macrosAdded"; - private readonly string loadUserControlKey = "loadUserControl"; - - // Alias hashable private static Hashtable _macroAlias = new Hashtable(); /// Cache for . private static Dictionary m_PredefinedExtensions; + private readonly string loadUserControlKey = "loadUserControl"; + + private readonly StringBuilder mContent = new StringBuilder(); + private readonly Cache macroCache = HttpRuntime.Cache; + + private readonly String macroCacheIdentifier = "umbMacro"; + private readonly int macroType; + private readonly string macrosAddedKey = "macrosAdded"; + private readonly Hashtable propertyDefinitions = new Hashtable(); + // Macro-elements private int macroID; - private bool cacheByPersonalization; - private bool cacheByPage; - private int cacheRefreshRate; - private String alias; - private String name; - private String xsltFile; + private Hashtable properties = new Hashtable(); + private String scriptAssembly; private String scriptFile; private String scriptType; - private String scriptAssembly; - private Hashtable properties = new Hashtable(); - private readonly Hashtable propertyDefinitions = new Hashtable(); - private readonly int macroType; - private bool dontRenderInEditor; + private String xsltFile; protected static ISqlHelper SqlHelper { - get { return umbraco.BusinessLogic.Application.SqlHelper; } + get { return BusinessLogic.Application.SqlHelper; } } #endregion #region public properties + public enum eMacroType + { + XSLT = 1, + CustomControl = 2, + UserControl = 3, + Unknown = 4, + Python = 5, + Script = 6 + } + public int MacroID { set { macroID = value; } get { return macroID; } } - public bool CacheByPersonalization - { - set { cacheByPersonalization = value; } - get { return cacheByPersonalization; } - } + public bool CacheByPersonalization { set; get; } - public bool CacheByPage - { - set { cacheByPage = value; } - get { return cacheByPage; } - } + public bool CacheByPage { set; get; } - public bool DontRenderInEditor - { - get { return dontRenderInEditor; } - set { dontRenderInEditor = value; } - } + public bool DontRenderInEditor { get; set; } - public int RefreshRate - { - set { cacheRefreshRate = value; } - get { return cacheRefreshRate; } - } + public int RefreshRate { set; get; } - public String Alias - { - set { alias = value; } - get { return alias; } - } + public String Alias { set; get; } - public String Name - { - set { name = value; } - get { return name; } - } + public String Name { set; get; } public String XsltFile { @@ -158,16 +137,6 @@ namespace umbraco get { return mContent.ToString(); } } - public enum eMacroType - { - XSLT = 1, - CustomControl = 2, - UserControl = 3, - Unknown = 4, - Python = 5, - Script = 6 - } - #endregion /// @@ -177,31 +146,6 @@ namespace umbraco { } - public override string ToString() - { - return Name; - } - - public static macro ReturnFromAlias(string alias) - { - if (_macroAlias.ContainsKey(alias)) - return new macro((int)_macroAlias[alias]); - else - { - try - { - int macroID = Macro.GetByAlias(alias).Id; - _macroAlias.Add(alias, macroID); - return new macro(macroID); - } - catch - { - HttpContext.Current.Trace.Warn("macro", "No macro with alias '" + alias + "' found"); - return null; - } - } - } - /// /// Creates a macro object /// @@ -212,7 +156,7 @@ namespace umbraco if (macroCache[macroCacheIdentifier + id] != null) { - macro tempMacro = (macro)macroCache[macroCacheIdentifier + id]; + var tempMacro = (macro)macroCache[macroCacheIdentifier + id]; Name = tempMacro.Name; Alias = tempMacro.Alias; ScriptType = tempMacro.ScriptType; @@ -231,8 +175,11 @@ namespace umbraco } else { - using (IRecordsReader macroDef = SqlHelper.ExecuteReader("select * from cmsMacro left join cmsMacroProperty property on property.macro = cmsMacro.id left join cmsMacroPropertyType editPropertyType on editPropertyType.id = property.macroPropertyType where cmsMacro.id = @macroID order by property.macroPropertySortOrder", - SqlHelper.CreateParameter("@macroID", id))) + using ( + IRecordsReader macroDef = + SqlHelper.ExecuteReader( + "select * from cmsMacro left join cmsMacroProperty property on property.macro = cmsMacro.id left join cmsMacroPropertyType editPropertyType on editPropertyType.id = property.macroPropertyType where cmsMacro.id = @macroID order by property.macroPropertySortOrder", + SqlHelper.CreateParameter("@macroID", id))) { if (!macroDef.HasRecords) HttpContext.Current.Trace.Warn("Macro", "No definition found for id " + id); @@ -271,11 +218,13 @@ namespace umbraco { string typeAlias; - if (TryGetColumnString(macroDef, "macroPropertyTypeAlias", out typeAlias) && !properties.ContainsKey(tmpStr)) + if (TryGetColumnString(macroDef, "macroPropertyTypeAlias", out typeAlias) && + !properties.ContainsKey(tmpStr)) properties.Add(tmpStr, typeAlias); string baseType; - if (TryGetColumnString(macroDef, "macroPropertyTypeBaseType", out baseType) && !propertyDefinitions.ContainsKey(tmpStr)) + if (TryGetColumnString(macroDef, "macroPropertyTypeBaseType", out baseType) && + !propertyDefinitions.ContainsKey(tmpStr)) propertyDefinitions.Add(tmpStr, baseType); } } @@ -304,9 +253,33 @@ namespace umbraco macroType = (int)eMacroType.Unknown; } + public override string ToString() + { + return Name; + } + + public static macro ReturnFromAlias(string alias) + { + if (_macroAlias.ContainsKey(alias)) + return new macro((int)_macroAlias[alias]); + else + { + try + { + int macroID = Macro.GetByAlias(alias).Id; + _macroAlias.Add(alias, macroID); + return new macro(macroID); + } + catch + { + HttpContext.Current.Trace.Warn("macro", "No macro with alias '" + alias + "' found"); + return null; + } + } + } + public static bool TryGetColumnString(IRecordsReader reader, string columnName, out string value) { - if (reader.ContainsField(columnName) && !reader.IsNull(columnName)) { value = reader.GetString(columnName); @@ -469,8 +442,10 @@ namespace umbraco case (int)eMacroType.Script: try { - HttpContext.Current.Trace.Write("umbracoMacro", "DLR Script script added (" + ScriptFile + ")"); - macroControl = loadMacroDLR(this, attributes, pageElements); + HttpContext.Current.Trace.Write("umbracoMacro", + "DLR Script script added (" + ScriptFile + ")"); + MacroModel model = new MacroModel(this, attributes); + macroControl = loadMacroDLR(model); break; } catch (Exception e) @@ -479,7 +454,7 @@ namespace umbraco "Error loading python script (file: " + ScriptFile + ", Type: '" + scriptType + "'", e); - LiteralControl result = new LiteralControl("Error loading DLR script (file: " + ScriptFile + ")"); + var result = new LiteralControl("Error loading DLR script (file: " + ScriptFile + ")"); /* string args = "