private void RenameInTree(Page page, string name, string pageName) { name = Common.CleanToSafeString(name); XmlNode newTreeNode = _treeDocument.CreateElement(name); XmlNode parentNode = page.TreeNode.ParentNode; string newPageidentifier = string.Empty; if (parentNode != null) { newPageidentifier = parentNode.Name; } // Copy children and attributes newTreeNode.InnerXml = page.TreeNode.InnerXml; CommonXml.CopyAttributes(page.TreeNode, newTreeNode); CommonXml.SetAttributeValue(newTreeNode, "name", name); CommonXml.SetAttributeValue(newTreeNode, "pagename", pageName); CommonXml.SetAttributeValue(newTreeNode, "pageidentifier", newPageidentifier + "/" + name); // Replace old node with new if (parentNode != null) { parentNode.ReplaceChild(newTreeNode, page.TreeNode); } }
private void GetFileAttributes(XmlNode xmlNode, String fileName) { DataSet dataSet = new DataSet(); try { dataSet.ReadXml(_directoryInfo.FullName + "\\data\\gallery.xml"); if (dataSet.Tables["file"] != null) { DataRow[] dataRows = dataSet.Tables["file"].Select("name='" + fileName + "'"); if (dataRows.Length != 0) { CommonXml.SetAttributeValue(xmlNode, "title", dataRows[0]["title"].ToString()); CommonXml.SetAttributeValue(xmlNode, "description", dataRows[0]["description"].ToString()); } } } catch { dataSet = null; } finally { if (dataSet != null) { dataSet.Dispose(); } } }
private void LoadBaseData() { XmlNode userNode = Content.GetSubControl("basedata")["currentuser"]; CommonXml.GetNode(userNode, "username").InnerText = CurrentUser; XmlNode groupNode = CommonXml.GetNode(userNode, "groups"); object[] resultsGroups = Plugins.InvokeAll("users", "list_groups", CurrentUser); List <string> userGroups = new List <string>(Common.Common.FlattenToStrings(resultsGroups)); foreach (string group in userGroups) { CommonXml.GetNode(groupNode, "group", EmptyNodeHandling.ForceCreateNew).InnerText = group; } ControlList baseData = Content.GetSubControl("basedata"); baseData["pageviewcount"].InnerText = PageViewCount().ToString(CultureInfo.InvariantCulture); baseData["defaultpage"].InnerText = Settings["sitetree/stdpage"]; foreach (string pageInHistory in History()) { XmlDocument ownerDocument = baseData["history"].OwnerDocument; if (ownerDocument != null) { XmlNode historyNode = ownerDocument.CreateElement("item"); historyNode.InnerText = pageInHistory; baseData["history"].AppendChild(historyNode); } } }
private void LoadCookies(ControlList control) { XmlItemList cookieData = new XmlItemList(CommonXml.GetNode(control.ParentNode, "items", EmptyNodeHandling.CreateNew)); foreach (String key in Process.HttpPage.Response.Cookies.Keys) { if (Process.Settings["general/cookies"].Contains("," + key + ",")) { HttpCookie httpCookie = Process.HttpPage.Response.Cookies[key]; if (httpCookie != null) { cookieData[key.Replace(".", String.Empty)] = HttpUtility.UrlEncode(httpCookie.Value); } } } foreach (String key in Process.HttpPage.Request.Cookies.Keys) { if (Process.Settings["general/cookies"].Contains("," + key + ",") && String.IsNullOrEmpty(cookieData[key.Replace(".", String.Empty)])) { HttpCookie httpCookie = Process.HttpPage.Request.Cookies[key]; if (httpCookie != null) { cookieData[key.Replace(".", String.Empty)] = HttpUtility.UrlEncode(httpCookie.Value); } } } }
/// <summary> /// Pluginses the specified page. /// </summary> /// <param name="page">The page.</param> private void Plugins(Page page) { for (int i = 0; i < page.Containers.Count; i++) { for (int b = 0; b < page.Containers[i].Elements.Count; b++) { XmlNode xmlElementNode = page.Containers[i].Elements[b].Node; String plugin = CommonXml.GetNode(xmlElementNode, "plugin").InnerText; String action = CommonXml.GetNode(xmlElementNode, "action").InnerText; if (plugin != String.Empty & action != String.Empty) { String pathTrail = CommonXml.GetNode(xmlElementNode, "value").InnerText; AvailablePlugin availablePlugin = Process.Plugins.AvailablePlugins.Find(plugin); if (availablePlugin != null) { IPlugin2 plugin2 = availablePlugin.Instance as IPlugin2; if (plugin2 != null) { IPlugin2 iPlugin = availablePlugin.Instance as IPlugin2; iPlugin.Load(new ControlList(xmlElementNode), action, String.Empty, pathTrail); } else { IPlugin iPlugin = availablePlugin.Instance; iPlugin.Load(new ControlList(xmlElementNode), action, pathTrail); } } } } } }
private void FrontPage() { object[] results = Process.Plugins.InvokeAll("users", "list_groups", Process.CurrentUser); List <string> userGroups = new List <string>(Common.FlattenToStrings(results)); foreach (string group in userGroups) { string xPath = string.Format("groups/item[@name='{0}']", group); XmlNode node; try { node = Process.Settings.GetAsNode(xPath); } catch { node = null; } if (node == null) { continue; } string frontPage = CommonXml.GetAttributeValue(node, "frontpage"); if (string.IsNullOrEmpty(frontPage)) { continue; } Process.HttpPage.Response.Redirect(frontPage + "/"); } }
private static void Parse(Page httpPage, Process process) { if (process.QueryEvents["xml"] == "true") { httpPage.Response.AddHeader("Content-Type", "text/xml"); httpPage.Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); httpPage.Response.Write(process.XmlData.OuterXml); } else { if (process.MainTemplate != null) { string output = CommonXml.TransformXsl(process.MainTemplate, process.XmlData, process.Cache); // ToDo: dirty hack string[] badtags = { "<ul />", "<li />", "<h1 />", "<h2 />", "<h3 />", "<div />", "<p />", "<font />", "<b />", "<strong />", "<i />" }; output = badtags.Aggregate(output, (current, a) => current.Replace(a, string.Empty)); Regex regex = new Regex("(?<email>(mailto:)([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3}))", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled); foreach (Match match in regex.Matches(output)) { output = output.Replace(match.Groups["email"].Value, HtmlObfuscate(match.Groups["email"].Value)); } httpPage.Response.Write(output); } } }
/// <summary> /// Handles the different root. /// </summary> /// <param name="control">The control.</param> /// <param name="value">The value.</param> /// <param name="xmlNode">The XML node.</param> private static void HandleDifferentRoot(ControlList control, ref String value, XmlNode xmlNode) { String realName; String treeRootName; if (value.IndexOf("|", StringComparison.Ordinal) > 0) { treeRootName = value.Substring(0, value.IndexOf("|", StringComparison.Ordinal)); value = value.Substring(value.IndexOf("|", StringComparison.Ordinal) + 1); realName = GetTreeRootName(value); } else { treeRootName = GetTreeRootName(value); realName = treeRootName; } XmlDocument ownerDocument = control["sitetree"].OwnerDocument; if (ownerDocument != null) { XmlNode treeNode = ownerDocument.CreateElement(treeRootName); XmlNode copyNode = xmlNode.SelectSingleNode(value); if (copyNode != null) { treeNode.InnerXml = copyNode.InnerXml; } CommonXml.AppendAttribute(treeNode, "realname", realName); control["sitetree"].AppendChild(treeNode); } }
private void LoopThroughProcess(string[] args, XmlNode xmlNode, Process process) { if (args[0] != string.Empty) { args[0] = CommonXml.RenameIntegerPath(args[0]); xmlNode = xmlNode.SelectSingleNode(args[0]); if (xmlNode != null) { if (process.CheckGroups(CommonXml.GetAttributeValue(xmlNode, "rights"))) { XmlNodeList contentNodes = xmlNode.SelectNodes("*"); LoopThroughProcessOneByOne(contentNodes, "template", process, args); LoopThroughProcessOneByOne(contentNodes, "handle", process, args); LoopThroughProcessOneByOne(contentNodes, "redirect", process, args); LoopThroughProcessOneByOne(contentNodes, "load", process, args); args = Common.Common.RemoveOne(args); if (args != null) { LoopThroughProcess(args, xmlNode, process); } } else { string redirectUrl = GetRedirectUrl(process.CurrentProcess); process.HttpPage.Response.Redirect(redirectUrl); // ToDo: is this the way to do it } } } }
private void HandlePlugin(XmlNode contentNode, string[] args, Process process) { if (contentNode.Attributes != null) { IPlugin provider = GetProvider(contentNode.Attributes["provider"].Value); if (provider != null) { switch (contentNode.Name) { case "load": ControlList control = process.Content.GetSubControl(CommonXml.GetAttributeValue(contentNode, "place")); string action = CommonXml.GetAttributeValue(contentNode, "action"); string value = GetValue(contentNode, process); string pathTrail = JoinPath(Common.Common.RemoveOne(args)); if (provider is IPlugin2) { ((IPlugin2)provider).Load(control, action, value, pathTrail); } else { provider.Load(control, action, pathTrail); } break; case "handle": string mainEvent = process.QueryEvents["main"]; if (mainEvent != string.Empty) { provider.Handle(mainEvent); } break; } } } }
public void GetXml(XmlNode xmlNode, SubFolder subFolder) { XmlNode folderNode = CommonXml.GetNode(xmlNode, "folder", EmptyNodeHandling.ForceCreateNew); CommonXml.SetAttributeValue(folderNode, "name", Name); foreach (FileInfo fileInfo in _directoryInfo.GetFiles()) { XmlNode fileNode = CommonXml.GetNode(folderNode, "file", EmptyNodeHandling.ForceCreateNew); CommonXml.SetAttributeValue(fileNode, "name", fileInfo.Name); CommonXml.SetAttributeValue(fileNode, "extension", fileInfo.Extension); GetFileAttributes(fileNode, fileInfo.Name); } if (subFolder == SubFolder.IncludeSubfolders) { foreach (DirectoryInfo directoryInfo in _directoryInfo.GetDirectories()) { if (Filter(directoryInfo.Name)) { FolderElement folderElement = new FolderElement(directoryInfo.FullName); folderElement.GetXml(folderNode, SubFolder.IncludeSubfolders); } } } }
private void CopyInfoFromTree() { this["name"] = _treeNode.Name; this["menuname"] = CommonXml.GetAttributeValue(_treeNode, "menuname"); this["pageidentifier"] = CommonXml.GetXPath(_treeNode); this["status"] = CommonXml.GetAttributeValue(_treeNode, "status"); }
private XmlNode GetControlNode(String name) { String xPath = String.Format("{0}", name); XmlNode node = CommonXml.GetNode(ParentNode, xPath); return(node); }
private string GetDocumentFilename(XmlNode treeNode) { string path = CommonXml.GetXPath(treeNode); string documentFilename = GetDocumentFilename(path); return(documentFilename); }
private void DeleteFile(XmlNode pageNode) { string path = CommonXml.GetXPath(pageNode); PagePath pagePath = new PagePath(path); Common.DeleteFile(GetDocumentFilename(pagePath.Path, pagePath.Name)); Common.DeleteDirectory(GetDocumentContainerDirectory(pagePath.Path, pagePath.Name)); }
public bool CheckPassword(String password) { String pwd1 = CommonXml.GetNode(Node, "password").InnerText; String pwd2 = Common.Common.CleanToSafeString(password).GetHashCode().ToString(CultureInfo.InvariantCulture); bool isValid = pwd1.Equals(pwd2); return(isValid); }
public Users(Process.Process process) { _userFileName = process.Settings["users/filename"]; _userDocument = new XmlDocument(); _userDocument.Load(_userFileName); _userList = new UserList(CommonXml.GetNode(_userDocument.DocumentElement, "users")); _groupList = new GroupList(CommonXml.GetNode(_userDocument.DocumentElement, "groups")); }
public Page(XmlNode pageNode, XmlNode treeNode, SiteTree siteTree) : base(pageNode) { _treeNode = treeNode; _siteTree = siteTree; CopyInfoFromTree(); _containers = new ContainerList(CommonXml.GetNode(Node, "containers")); }
public void AddMessage(string message, MessageType messageType, string type) { XmlNode xmlNode = CommonXml.GetNode(XmlData.DocumentElement, "messages", EmptyNodeHandling.CreateNew); xmlNode = CommonXml.GetNode(xmlNode, "item", EmptyNodeHandling.ForceCreateNew); xmlNode.InnerText = message; CommonXml.SetAttributeValue(xmlNode, "messagetype", messageType.ToString()); CommonXml.SetAttributeValue(xmlNode, "type", type); }
/// <summary> /// Creates the file. /// </summary> /// <param name="path">The path.</param> /// <param name="name">The name.</param> /// <param name="menuName">Name of the menu.</param> private void CreateFile(string path, string name, string menuName) { string fileDirectory = GetDocumentDirectory(path); string filename = GetDocumentFilename(path, name); Directory.CreateDirectory(fileDirectory); XmlDocument document = new XmlDocument(); CommonXml.GetNode(document, "page/attributes/pagename", EmptyNodeHandling.CreateNew).InnerText = menuName; CommonXml.SaveXmlDocument(filename, document); }
/// <summary> /// Creates the in tree. /// </summary> /// <param name="path">The path.</param> /// <param name="name">The name.</param> /// <param name="menuName">Name of the menu.</param> /// <returns></returns> private XmlNode CreateInTree(string path, string name, string menuName) { XmlNode parentNode = GetPageNode(path); XmlNode pageNode = _treeDocument.CreateElement(name); parentNode.AppendChild(pageNode); CommonXml.AppendAttribute(pageNode, "menuname", menuName); return(pageNode); }
private void HandleAttributeChange(string name, string value) { switch (name) { case "name": _siteTree.Rename(this, value); break; default: CommonXml.SetAttributeValue(_treeNode, name, value); break; } }
/// <summary> /// Saves the page. /// </summary> /// <param name="page">The page.</param> /// <param name="saveTree">if set to <c>true</c> [save tree].</param> private void SavePage(Page page, bool saveTree) { if (page != null) { string filename = GetDocumentFilename(page.TreeNode); CommonXml.SaveXmlDocument(filename, page.Node.OwnerDocument); if (saveTree) { Save(); } } }
public string this[string name] { get { string attribute = CommonXml.GetAttributeValue(_xmlNode, name); return(attribute); } set { CommonXml.SetAttributeValue(_xmlNode, name, value); } }
/// <summary> /// Loads the folder. /// </summary> /// <param name="value">The value.</param> /// <param name="control">The control.</param> private void LoadFolder(string value, ControlList control) { if (!string.IsNullOrEmpty(value)) { string path = value; if (Tree.FolderExists(path)) { FolderElement folderElement = Tree.GetFolder(path); XmlNode xmlNode = control["folder"]; folderElement.GetXml(xmlNode, SubFolder.OnlyThisFolder); CommonXml.SetAttributeValue(xmlNode, "path", path); } } }
//private static void PrepareConfiguration(HttpApplicationState app, HttpServerUtility server) //{ // Cache cache = new Cache(app); // List<string> configurationPaths = new List<string>(); // configurationPaths.Add(server.MapPath("~/Custom/Components")); // configurationPaths.Add(server.MapPath("~/System/Components")); // string[] settingsPaths = new string[3]; // configurationPaths.CopyTo(settingsPaths); // settingsPaths[2] = server.MapPath("~/Custom/App_Data/CustomSettings.xml"); // Configuration.CombineSettings(settingsPaths, cache); // string[] processPaths = new string[3]; // configurationPaths.CopyTo(processPaths); // processPaths[2] = server.MapPath("~/Custom/App_Data/CustomProcess.xml"); // Configuration.CombineProcessTree(processPaths, cache); //} private static string Parse(Process process) { //string output = CommonXml.TransformXsl(process.mainTemplate, process.XmlData, process.Cache, firstRun); string output = CommonXml.TransformXsl(process); // todo: dirty hack string[] badtags = { "<ul />", "<li />", "<h1 />", "<h2 />", "<h3 />", "<div />", "<p />", "<font />", "<b />", "<strong />", "<i />" }; foreach (string a in badtags) { output.Replace(a, ""); } return(output); }
private void HandleLog() { XmlNode messagesNode = CommonXml.GetNode(Process.XmlData, "messages", EmptyNodeHandling.Ignore); if (messagesNode == null) { return; } String logFileName = Process.Settings["errorlog/logpath"]; XmlNodeList items = messagesNode.SelectNodes("item"); if (items != null) { foreach (XmlNode item in items) { bool writtenToLogFile = false; try { if (CommonXml.GetAttributeValue(item, "writtenToLogFile") == "true") { writtenToLogFile = true; } } catch { writtenToLogFile = false; } if (writtenToLogFile) { continue; } if (CommonXml.GetAttributeValue(item, "messagetype") != "Error") { continue; } String errorType = CommonXml.GetAttributeValue(item, "type"); String message = item.InnerText; File.AppendAllText(logFileName, String.Format("{0};{1};{2}\r\n", DateTime.Now.ToUniversalTime(), errorType, message)); CommonXml.SetAttributeValue(item, "writtenToLogFile", "true"); } } }
private void AddMessage(String message, MessageType messageType, String type) { XmlNode xmlNode = CommonXml.GetNode(XmlData.DocumentElement, "messages", EmptyNodeHandling.CreateNew); xmlNode = CommonXml.GetNode(xmlNode, "item", EmptyNodeHandling.ForceCreateNew); xmlNode.InnerText = message; CommonXml.SetAttributeValue(xmlNode, "messagetype", messageType.ToString()); CommonXml.SetAttributeValue(xmlNode, "type", type); IPlugin plugin = Plugins["ErrorLog"]; if (plugin != null) { plugin.Handle("log"); } }
/// <summary> /// Rebuilds this instance. /// </summary> private void Rebuild() { XmlNodeList xmlNodeList = TreeDocument.SelectNodes("//*[@pageidentifier and not(@pageidentifier = '')]"); if (xmlNodeList != null) { foreach (XmlNode pageNode in xmlNodeList) { string path = CommonXml.GetXPath(pageNode); Page page = GetPage(path); page["pageidentifier"] = path; SavePage(page, false); CommonXml.SetAttributeValue(pageNode, "pageidentifier", path); } } }
private string this[string path, RelativePathHandling relativePathHandling] { get { XmlNode settingsNode = CommonXml.GetNode(_combinedSettings.SelectSingleNode("settings"), path, EmptyNodeHandling.CreateNew); string value = settingsNode.InnerText; return(relativePathHandling == RelativePathHandling.ConvertToAbsolute ? ConvertPath(value) : value); } set { CommonXml.GetNode(_customSettings.SelectSingleNode("settings"), path, EmptyNodeHandling.CreateNew).InnerText = value; CommonXml.GetNode(_combinedSettings.SelectSingleNode("settings"), path, EmptyNodeHandling.CreateNew).InnerText = value; Save(); } }