Click here to Skip to main content
15,881,852 members
Articles / Web Development / ASP.NET

Fireblog A Blog application under linux with mono

Rate me:
Please Sign up or sign in to vote.
2.05/5 (8 votes)
29 Dec 20041 min read 49.2K   311   18  
Fireblog is the fireball implementation of a WebBlog application completely written under mono on linux
using System;
using System.Drawing;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fireball.Web.Controls
{
	public class AddPostControl:WebControl
	{
		public AddPostControl()
		{
			//NOP
		}	
		
		protected override void Render(HtmlTextWriter writer)
		{
			if(Page.Session["login"] == null)
			{
				Page.Response.Redirect("login.aspx");
			}
			
			this.RenderBeginTag(writer);
			
			writer.Write("<table border='0' cellpadding='0' cellspacing='1' width='100%' class=\"news_table\">");	
			writer.Write("<td class='news_title'>");
			writer.Write("Add Post");
			writer.Write("</td></tr>");			
			writer.Write("<tr><td class='addpost_content'>");
				
			if(Page.Request.QueryString["send"] == null)
			{			
				writer.Write("<form id='form1' method='post' runat='server' action='addpost.aspx?send=0'>");
				writer.Write("<div>Title:</div>");
				writer.Write("<input type='text' name='title' STYLE='width:100%'/>");
				writer.Write("<div>Message:</div>");
				writer.Write("<textarea name='message' STYLE='width:100%'></textarea>");
				//writer.Write("<input type='hidden' id='hidden' value='val' />");
				writer.Write("<input type='submit' id='submit' value='Add Post' STYLE='width:150px'/>");
				writer.Write("</form>");			
			}
			else
			{
			
				string title = Page.Request.Form["title"];
				string message = Page.Request.Form["message"];
				string username = Page.Session["login"].ToString();
				
				bool errors = false;
				
				if(title == null && (title == string.Empty))
					errors = true;
					
				if(message == null && (message == string.Empty))
					errors = true;	
					
				if(errors != true)			
				{					
					XmlDocument xdoc = new XmlDocument();
					
					xdoc.Load("./data/posts.xml");
					
					XmlNode xnode = xdoc.CreateElement("article");
					
					//title attribute
					XmlAttribute xtitle = xdoc.CreateAttribute("title");
					
					xtitle.Value =  title;
					
					xnode.Attributes.Append(xtitle);
					//title attribute
					
					//postdate attribute
					XmlAttribute xpost = xdoc.CreateAttribute("postDate");
					
					xpost.Value =  DateTime.Now.ToString();
					
					xnode.Attributes.Append(xpost);				
					//postdate attribute
					
					//postdate attribute
					XmlAttribute xby = xdoc.CreateAttribute("by");
					
					xby.Value =  username;
					
					xnode.Attributes.Append(xby);				
					//postdate attribute
					
					xnode.InnerText = message;
					
					XmlNode xposts = xdoc.SelectSingleNode("posts");
					
					if(xposts.HasChildNodes == true)
					{					
						xposts.InsertBefore(xnode,xposts.ChildNodes[0]);	
					}
					else
					{
						xposts.AppendChild(xnode);
					}
					
					xdoc.Save("./data/posts.xml");		
					
					writer.Write("<p align='center'>Post Added Succefully</p>");
				}
				else
				{
					writer.Write("<p align='center'>Error on Adding the post</p>");
				}
				
				writer.Write("<p><a href='addpost.aspx'>Return to AddPost Page</a></p>");
			}
			
			writer.Write("</td></tr>");
			writer.Write("</table>");
			
			this.RenderEndTag(writer);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions