コード例 #1
0
        void RenderOverlayPage()
        {
            //string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-iframe-overlay.htm");
            List<IAdminMenuItem> items = new List<IAdminMenuItem>();
            foreach (Type t in Core.Modules.GetInterfaceImplementations(typeof(IAdminMenuItem)))
                items.Add((IAdminMenuItem)Activator.CreateInstance(t));
            items.Sort(delegate(IAdminMenuItem a, IAdminMenuItem b)
            {
                int f = a.Priority.CompareTo(b.Priority);
                if (f != 0) return f;
                return a.MenuLinkText.CompareTo(b.MenuLinkText);
            });
            StringBuilder links = new StringBuilder();
            StringBuilder head = new StringBuilder();
            foreach (IAdminMenuItem item in items)
            {
                links.AppendFormat("<span class=\"divider\"> | </span><a class=\"tab\" href=\"javascript:void(0)\" onclick=\"{0}\">{1}</a>",
                    item.MenuLinkOnClick, item.MenuLinkText);
                head.Append(item.HeadContent);
            }

            string html = WebUtility.CacheTextFile("resources/admin/frames/admin-iframe-overlay.htm");
            SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
            HttpContext.Current.Response.Write(
                scr.Execute()
                .Replace("[head-content]", head.ToString())
                .Replace("[menu-links]",links.ToString())
            );
        }
コード例 #2
0
ファイル: Template.cs プロジェクト: priaonehaha/sprocketcms
 public MasterTemplate(XmlElement xml)
 {
     name = xml.GetAttribute("Name");
     if (xml.HasAttribute("File"))
     {
         sprocketPath = xml.GetAttribute("File");
         filePath = WebUtility.MapPath(sprocketPath);
         if (!File.Exists(filePath))
         {
             script = new SprocketScript("[The template \"" + Name + "\" references a nonexistant file]", "Template: " + Name, "Template: " + Name);
         }
         else
         {
             script = new SprocketScript(File.ReadAllText(filePath), "Template: " + Name, "Template: " + Name);
             fileDate = File.GetLastWriteTime(filePath);
         }
     }
     else
     {
         string text;
         XmlElement body = xml.SelectSingleNode("Body") as XmlElement;
         if (body == null)
             text = "Master template \"" + name + "\" does not have any body text/html. In the XML definition, either reference a file with the \"File=\" attribute, or supply a child element called \"<Body>\" and place the text there.";
         else
             text = body.InnerText;
         script = new SprocketScript(text, "Template: " + name, "Template: " + name);
     }
     ReadPageAdminSettings(xml);
 }
コード例 #3
0
		void WebEvents_OnLoadRequestedPath(HandleFlag handled)
		{
			if (handled.Handled) return;
			if (SprocketPath.Sections[0] == "admin")
			{
				if (!WebAuthentication.Instance.IsLoggedIn)
				{
					HttpContext.Current.Response.Write("Access Denied.");
					handled.Set();
					return;
				}
				switch (SprocketPath.Value)
				{
					case "admin":
						{
							string html = WebUtility.CacheTextFile("resources/admin/frames/admin-iframes.htm");
							//string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-iframes.htm");
							SprocketScript scr = new SprocketScript(html, "Admin Frames", "Admin Frames");
							HttpContext.Current.Response.Write(scr.Execute());
						}
						break;

					case "admin/overlay":
						RenderOverlayPage();
						break;

					case "admin/frames":
						{
							string html = WebUtility.CacheTextFile("resources/admin/frames/admin-frames.htm");
							//string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-frames.htm");
							SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
							HttpContext.Current.Response.Write(scr.Execute());
						}
						break;

					case "admin/addressbar":
						{
							string html = WebUtility.CacheTextFile("resources/admin/frames/admin-address-bar.htm");
							//string html = ResourceLoader.LoadTextResource("Sprocket.Web.CMS.Admin.admin-address-bar.htm");
							SprocketScript scr = new SprocketScript(html, "Admin Overlay Frame", "Admin Overlay Frame");
							HttpContext.Current.Response.Write(scr.Execute());
						}
						break;

					default:
						return;
				}
				handled.Set();
			}
		}
コード例 #4
0
ファイル: Template.cs プロジェクト: priaonehaha/sprocketcms
 public MasterTemplate(XmlElement xml)
 {
     name = xml.GetAttribute("Name");
     if (xml.HasAttribute("File"))
     {
         filePath = WebUtility.MapPath(xml.GetAttribute("File"));
         if (!File.Exists(filePath))
         {
             script = new SprocketScript("[The template \"" + Name + "\" references a nonexistant file]", "Template: " + Name, "Template: " + Name);
         }
         else
         {
             script = new SprocketScript(File.ReadAllText(filePath), "Template: " + Name, "Template: " + Name);
             fileDate = File.GetLastWriteTime(filePath);
         }
     }
     else
         script = new SprocketScript(xml.InnerText, "Template: " + name, "Template: " + name);
 }
コード例 #5
0
		public Template(string name, SprocketScript script, Dictionary<string, DateTime> fileTimes)
		{
			this.fileTimes = fileTimes;
			this.script = script;
			this.name = name;
		}
コード例 #6
0
			private SprocketScript BuildTemplateScript(string name, Stack<string> embedStack, Dictionary<string, DateTime> fileTimes)
			{
				if(embedStack.Contains(name))
					return new SprocketScript("[Circular dependency detected in template heirarchy at \"" + name + "\"]", "Template: " + name, "Template: " + name);
				embedStack.Push(name);

				if (!templateXML.ContainsKey(name))
					return new SprocketScript("[There was no template found named \"" + name + "\"]", "Template: " + name, "Template: " + name); ;
				XmlElement xml = templateXML[name];

				SprocketScript script = null;
				if (xml.HasAttribute("Master"))
				{
					script = BuildTemplateScript(xml.GetAttribute("Master"), embedStack, fileTimes);
					foreach (XmlElement replace in xml.SelectNodes("Replace[@Section]"))
					{
						string sectionName = replace.GetAttribute("Section");
						if (replace.HasAttribute("File"))
						{
							string sprocketPath = replace.GetAttribute("File");
							string path = WebUtility.MapPath(sprocketPath);
							if (File.Exists(path))
							{
								fileTimes[path] = new FileInfo(path).LastWriteTime;
								using (StreamReader reader = new StreamReader(path))
								{
									script.OverrideSection(sectionName, new SprocketScript(reader.ReadToEnd(), sprocketPath, sprocketPath));
									reader.Close();
								}
							}
							else
								script.OverrideSection(sectionName, new SprocketScript("[Unable to replace section \"" + sectionName + "\". The referenced file doesn't exist]", name, name));
						}
						else if(replace.HasAttribute("Template"))
							script.OverrideSection(sectionName, BuildTemplateScript(replace.GetAttribute("Template"), embedStack, fileTimes));
						else
						{
							if(replace.HasChildNodes)
								script.OverrideSection(sectionName, new SprocketScript(replace.FirstChild.Value, "Template Section " + sectionName, "Template Section " + sectionName));
						}
					}
				}
				else if (xml.HasAttribute("File"))
				{
					//	return new SprocketScript("[The template \"" + name + "\" is lacking a Master or File attribute]", "Template: " + name, "Template: " + name);
					string path = WebUtility.MapPath(xml.GetAttribute("File"));
					if (!File.Exists(path))
						return new SprocketScript("[The template \"" + name + "\" references a nonexistant file]", "Template: " + name, "Template: " + name);
					fileTimes[path] = new FileInfo(path).LastWriteTime;
					using (StreamReader reader = new StreamReader(path))
					{
						script = new SprocketScript(reader.ReadToEnd(), "Template: " + name, "Template: " + name);
						reader.Close();
					}
				}
				else
				{
					if(xml.ChildNodes.Count > 0)
						if(xml.FirstChild.NodeType == XmlNodeType.CDATA || xml.FirstChild.NodeType == XmlNodeType.Text)
							script = new SprocketScript(xml.FirstChild.Value, "Template: " + name, "Template: " + name);
					if(script == null)
						script = new SprocketScript(xml.InnerText, "Template: " + name, "Template: " + name);
				}

				embedStack.Pop();
				return script;
			}
コード例 #7
0
		public void OverrideSection(string sectionName, SprocketScript script)
		{
			sectionOverrides[sectionName] = script;
		}
コード例 #8
0
ファイル: Template.cs プロジェクト: priaonehaha/sprocketcms
        private string sectionName; //, templateName = null; support templates as replacements some other time

        #endregion Fields

        #region Constructors

        public TemplateSectionReplacement(XmlElement xml)
        {
            sectionName = xml.GetAttribute("Section");
            if (xml.HasAttribute("File"))
            {
                filePath = WebUtility.MapPath(xml.GetAttribute("File"));
                if (!File.Exists(filePath))
                    script = new SprocketScript("[Can't replace section \"" + sectionName + "\"; Path \"" + xml.GetAttribute("File") + "\" doesn't exist]",
                        "Template Section Replacement: " + sectionName, guid.ToString());
                else
                {
                    fileDate = File.GetLastWriteTime(filePath);
                    script = new SprocketScript(File.ReadAllText(filePath), "Template Section Replacement: " + sectionName, guid.ToString());
                }
            }
            //else if (xml.HasAttribute("Template"))
            //    templateName = xml.GetAttribute("Template");
            else
                script = new SprocketScript(xml.InnerText, "Template Section Replacement: " + sectionName, guid.ToString());
        }
コード例 #9
0
 public AdminSection(SprocketScript script, ObjectRank rank)
 {
     this.script = script;
     this.rank = rank;
 }
コード例 #10
0
ファイル: Template.cs プロジェクト: priaonehaha/sprocketcms
        private string sectionName; //, templateName = null; support templates as replacements some other time

        #endregion Fields

        #region Constructors

        public TemplateSectionReplacement(XmlElement xml)
        {
            sectionName = xml.GetAttribute("Section");
            if (xml.HasAttribute("File"))
            {
                filePath = WebUtility.MapPath(xml.GetAttribute("File"));
                if (!File.Exists(filePath))
                    script = new SprocketScript("[Can't replace section \"" + sectionName + "\"; Path \"" + xml.GetAttribute("File") + "\" doesn't exist]",
                        "Template Section Replacement: " + sectionName, guid.ToString());
                else
                {
                    fileDate = File.GetLastWriteTime(filePath);
                    script = new SprocketScript(File.ReadAllText(filePath), "Template Section Replacement: " + sectionName, guid.ToString());
                }
            }
            else
            {
                XmlElement inner = xml.SelectSingleNode("Body") as XmlElement;
                script = new SprocketScript(inner == null ?
                    "[Template replacement for section \"" + sectionName + "\" must specify a File attribute or Body child element"
                    : inner.InnerText, "Template Section Replacement: " + sectionName, guid.ToString());
            }

            XmlNodeList cfnodes = xml.SelectNodes("PageAdminSections/PageAdminSection");
            foreach (XmlElement cfnode in cfnodes)
                pageAdminSections.Add(Template.ReadPageAdminSectionXml(cfnode));
        }