protected void Page_Load(object sender, EventArgs e) { ClientLoader.DataBind(); _scriptOnLoad = ""; string reqMacroID = UmbracoContext.Current.Request["umb_macroID"]; string reqMacroAlias = UmbracoContext.Current.Request["umb_macroAlias"]; bool ignoreForm = string.IsNullOrEmpty(UmbracoContext.Current.Request["class"]); pane_insert.Text = ui.Text("insertMacro"); Page.Title = ui.Text("insertMacro"); if (!String.IsNullOrEmpty(reqMacroID) || !String.IsNullOrEmpty(reqMacroAlias)) { pane_edit.Visible = true; pane_insert.Visible = false; edit_buttons.Visible = true; insert_buttons.Visible = false; // Put user code to initialize the page here if (!string.IsNullOrEmpty(reqMacroID)) { m = new Macro(int.Parse(reqMacroID)); } else { m = new Macro(reqMacroAlias); } pane_edit.Text = ui.Text("edit") + " " + m.Name; Page.Title = ui.Text("edit") + " " + m.Name; String macroAssembly = ""; String macroType = ""; if (m.Properties.Length == 0) { if (ignoreForm) { renderMacro_Click(null, EventArgs.Empty); } else { Literal fb = new Literal(); fb.Text = "<p>" + ui.Text("macroDoesNotHaveProperties") + "</p><p><a href='#' onClick='tinyMCEPopup.close();'>" + ui.Text("closeThisWindow") + "</a>"; macroProperties.Controls.Add(fb); edit_buttons.Visible = false; } } else { foreach (MacroProperty mp in m.Properties) { macroAssembly = mp.Type.Assembly; macroType = mp.Type.Type; try { Assembly assembly = Assembly.LoadFrom(IOHelper.MapPath(SystemDirectories.Bin + "/" + macroAssembly + ".dll")); Type type = assembly.GetType(macroAssembly + "." + macroType); IMacroGuiRendering typeInstance = Activator.CreateInstance(type) as IMacroGuiRendering; if (typeInstance != null) { Control control = Activator.CreateInstance(type) as Control; control.ID = mp.Alias; if (!IsPostBack) { string propertyValue = Request["umb_" + mp.Alias]; if (propertyValue != null) { // replace linebreaks and quotes propertyValue = propertyValue.Replace("\\r", "\r").Replace("\\n", "\n").Replace("\\\"", "\""); // check encoding propertyValue = HttpUtility.UrlDecode(propertyValue); if (propertyValue != "") { type.GetProperty("Value").SetValue(control, Convert.ChangeType( propertyValue, type.GetProperty("Value").PropertyType), null); } } } uicontrols.PropertyPanel pp = new global::umbraco.uicontrols.PropertyPanel(); pp.Text = mp.Name; pp.Controls.Add(control); _scriptOnLoad += "\t\tregisterAlias('" + control.ID + "');\n"; // pp.Controls.Add(new LiteralControl("<script type=\"text/javascript\"></script>\n")); macroProperties.Controls.Add(pp); _dataFields.Add(control); //macroProperties.Controls.Add(new LiteralControl("</td></tr>")); } else { Trace.Warn("umbEditContent", "Type doesn't exist or is not umbraco.interfaces.DataFieldI ('" + macroAssembly + "." + macroType + "')"); } } catch (Exception fieldException) { Trace.Warn("umbEditContent", "Error creating type '" + macroAssembly + "." + macroType + "'", fieldException); } } } } else { IRecordsReader macroRenderings; if (UmbracoContext.Current.Request["editor"] != "") { macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro where macroUseInEditor = 1 order by macroName"); } else { macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro order by macroName"); } umb_macroAlias.DataSource = macroRenderings; umb_macroAlias.DataValueField = "macroAlias"; umb_macroAlias.DataTextField = "macroName"; umb_macroAlias.DataBind(); macroRenderings.Close(); } }
protected void Page_Load(object sender, EventArgs e) { ClientLoader.DataBind(); _scriptOnLoad = ""; string reqMacroID = UmbracoContext.Current.Request["umb_macroID"]; string reqMacroAlias = UmbracoContext.Current.Request["umb_macroAlias"]; bool ignoreForm = string.IsNullOrEmpty(UmbracoContext.Current.Request["class"]); pane_insert.Text = ui.Text("insertMacro"); Page.Title = ui.Text("insertMacro"); if (!String.IsNullOrEmpty(reqMacroID) || !String.IsNullOrEmpty(reqMacroAlias)) { pane_edit.Visible = true; pane_insert.Visible = false; edit_buttons.Visible = true; insert_buttons.Visible = false; // Put user code to initialize the page here if (!string.IsNullOrEmpty(reqMacroID)) { m = new Macro(int.Parse(reqMacroID)); } else { m = new Macro(reqMacroAlias); } pane_edit.Text = ui.Text("edit") + " " + m.Name; Page.Title = ui.Text("edit") + " " + m.Name; String macroAssembly = ""; String macroType = ""; if (m.Properties.Length == 0) { if (ignoreForm) { renderMacro_Click(null, EventArgs.Empty); } else { Literal fb = new Literal(); fb.Text = "<p>" + ui.Text("macroDoesNotHaveProperties") + "</p><p><a href='#' onClick='tinyMCEPopup.close();'>" + ui.Text("closeThisWindow") + "</a>"; macroProperties.Controls.Add(fb); edit_buttons.Visible = false; } } else { foreach (MacroProperty mp in m.Properties) { macroAssembly = mp.Type.Assembly; macroType = mp.Type.Type; try { Assembly assembly = Assembly.LoadFrom( IOHelper.MapPath(SystemDirectories.Bin + "/" + macroAssembly + ".dll")); Type type = assembly.GetType(macroAssembly + "." + macroType); IMacroGuiRendering typeInstance = Activator.CreateInstance(type) as IMacroGuiRendering; if (typeInstance != null) { Control control = Activator.CreateInstance(type) as Control; control.ID = mp.Alias; if (!IsPostBack) { string propertyValue = Request["umb_" + mp.Alias]; if (propertyValue != null) { // replace linebreaks and quotes propertyValue = propertyValue.Replace("\\r", "\r").Replace("\\n", "\n").Replace("\\\"", "\""); // check encoding propertyValue = HttpUtility.UrlDecode(propertyValue); if (propertyValue != "") { type.GetProperty("Value").SetValue(control, Convert.ChangeType( propertyValue, type.GetProperty("Value").PropertyType), null); } } } uicontrols.PropertyPanel pp = new global::umbraco.uicontrols.PropertyPanel(); pp.Text = mp.Name; pp.Controls.Add(control); _scriptOnLoad += "\t\tregisterAlias('" + control.ID + "');\n"; // pp.Controls.Add(new LiteralControl("<script type=\"text/javascript\"></script>\n")); macroProperties.Controls.Add(pp); _dataFields.Add(control); //macroProperties.Controls.Add(new LiteralControl("</td></tr>")); } else { Trace.Warn("umbEditContent", "Type doesn't exist or is not umbraco.interfaces.DataFieldI ('" + macroAssembly + "." + macroType + "')"); } } catch (Exception fieldException) { Trace.Warn("umbEditContent", "Error creating type '" + macroAssembly + "." + macroType + "'", fieldException); } } } } else { IRecordsReader macroRenderings; if (UmbracoContext.Current.Request["editor"] != "") macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro where macroUseInEditor = 1 order by macroName"); else macroRenderings = SqlHelper.ExecuteReader("select macroAlias, macroName from cmsMacro order by macroName"); umb_macroAlias.DataSource = macroRenderings; umb_macroAlias.DataValueField = "macroAlias"; umb_macroAlias.DataTextField = "macroName"; umb_macroAlias.DataBind(); macroRenderings.Close(); } }