예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.RequestType != "POST" || !context.Request.IsAuthenticated)
                return;

            IGraffitiUser user = GraffitiUsers.Current;
            if (user == null)
                return;

            if (!RolePermissionManager.CanViewControlPanel(user))
                return;

            context.Response.ContentType = "text/plain";

            switch (context.Request.QueryString["command"])
            {
                case "deleteComment":

                    Comment c = new Comment(context.Request.Form["commentid"]);

                    if (RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Publish)
                    {
                        Comment.Delete(context.Request.Form["commentid"]);
                        context.Response.Write("success");
                    }

                    break;

                case "deleteCommentWithStatus":

                    Comment c1 = new Comment(context.Request.Form["commentid"]);

                    if (RolePermissionManager.GetPermissions(c1.Post.CategoryId, GraffitiUsers.Current).Publish)
                    {
                        Comment.Delete(context.Request.Form["commentid"]);
                        context.Response.Write("The comment was deleted. <a href=\"javascript:void(0);\" onclick=\"Comments.unDelete('" + new Urls().AdminAjax + "'," + context.Request.Form["commentid"] + "); return false;\">Undo?</a>");
                    }
                    break;

                case "unDelete":
                    Comment c2 = new Comment(context.Request.Form["commentid"]);

                    if (RolePermissionManager.GetPermissions(c2.Post.CategoryId, GraffitiUsers.Current).Publish)
                    {
                        Comment comment = new Comment(context.Request.Form["commentid"]);
                        comment.IsDeleted = false;
                        comment.Save();
                        context.Response.Write("The comment was un-deleted. You may need to refresh the page to see it");
                    }
                    break;

                case "approve":
                    Comment c3 = new Comment(context.Request.Form["commentid"]);

                    if (RolePermissionManager.GetPermissions(c3.Post.CategoryId, GraffitiUsers.Current).Publish)
                    {
                        Comment cmt = new Comment(context.Request.Form["commentid"]);
                        cmt.IsDeleted = false;
                        cmt.IsPublished = true;
                        cmt.Save();
                        context.Response.Write("The comment was un-deleted and/or approved. You may need to refresh the page to see it");
                    }
                    break;

                case "deletePost":
                    try
                    {
                        Post postToDelete = new Post(context.Request.Form["postid"]);

                        Permission perm = RolePermissionManager.GetPermissions(postToDelete.CategoryId, user);

                        if (GraffitiUsers.IsAdmin(user) || perm.Publish)
                        {
                            postToDelete.IsDeleted = true;
                            postToDelete.Save(user.Name, DateTime.Now);

                            //Post.Delete(context.Request.Form["postid"]);
                            //ZCache.RemoveByPattern("Posts-");
                            //ZCache.RemoveCache("Post-" + context.Request.Form["postid"]);
                            context.Response.Write("The post was deleted. <a href=\"javascript:void(0);\" onclick=\"Posts.unDeletePost('" + new Urls().AdminAjax + "'," + context.Request.Form["postid"] + "); return false;\">Undo?</a>");
                        }
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "unDeletePost":
                    Post p = new Post(context.Request.Form["postid"]);
                    p.IsDeleted = false;
                    p.Save();
                    //ZCache.RemoveByPattern("Posts-");
                    //ZCache.RemoveCache("Post-" + context.Request.Form["postid"]);
                    //context.Response.Write("The post was un-deleted. You may need to fresh the page to see it");
                    break;

                case "permanentDeletePost":
                    Post tempPost = new Post(context.Request.Form["postid"]);
                    Post.DestroyDeletedPost(tempPost.Id);
                    context.Response.Write(tempPost.Title);
                    break;

                case "createdWidget":
                    string widgetID = context.Request.Form["id"];
                    List<WidgetDescription> the_widgets = Widgets.GetAvailableWidgets();
                    Widget widget = null;
                    foreach (WidgetDescription wia in the_widgets)
                    {
                        if (wia.UniqueId == widgetID)
                        {
                            widget = Widgets.Create(wia.WidgetType);
                            break;
                        }
                    }

                    context.Response.Write(widget.Id.ToString());

                    break;

                case "updateWidgetsOrder":

                    try
                    {
                        string listID = context.Request.Form["id"];
                        string list = "&" + context.Request.Form["list"];

                        Widgets.ReOrder(listID, list);

                        //StreamWriter sw = new StreamWriter(context.Server.MapPath("~/widgets.txt"), true);
                        //sw.WriteLine(DateTime.Now);
                        //sw.WriteLine();
                        //sw.WriteLine(context.Request.Form["left"]);
                        //sw.WriteLine(context.Request.Form["right"]);
                        //sw.WriteLine(context.Request.Form["queue"]);
                        //sw.WriteLine();
                        //sw.Close();

                        context.Response.Write("Saved!");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "deleteWidget":

                    string deleteID = context.Request.Form["id"];
                    Widgets.Delete(deleteID);
                    context.Response.Write("The widget was removed!");

                    break;

                case "createTextLink":
                    DynamicNavigationItem di = new DynamicNavigationItem();
                    di.NavigationType = DynamicNavigationType.Link;
                    di.Text = context.Request.Form["text"];
                    di.Href = context.Request.Form["href"];
                    di.Id = Guid.NewGuid();
                    NavigationSettings.Add(di);
                    context.Response.Write(di.Id);

                    break;

                case "deleteTextLink":
                    Guid g = new Guid(context.Request.Form["id"]);
                    NavigationSettings.Remove(g);
                    context.Response.Write("Success");
                    break;

                case "reOrderNavigation":
                    try
                    {
                        string navItems = "&" + context.Request.Form["navItems"];
                        NavigationSettings.ReOrder(navItems);
                        context.Response.Write("Success");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "addNavigationItem":

                    try
                    {
                        if (context.Request.Form["type"] == "Post")
                        {
                            Post navPost = Post.FetchByColumn(Post.Columns.UniqueId, new Guid(context.Request.Form["id"]));
                            DynamicNavigationItem item = new DynamicNavigationItem();
                            item.PostId = navPost.Id;
                            item.Id = navPost.UniqueId;
                            item.NavigationType = DynamicNavigationType.Post;
                            NavigationSettings.Add(item);
                            context.Response.Write("Success");
                        }
                        else if (context.Request.Form["type"] == "Category")
                        {
                            Category navCategory = Category.FetchByColumn(Category.Columns.UniqueId, new Guid(context.Request.Form["id"]));
                            DynamicNavigationItem item = new DynamicNavigationItem();
                            item.CategoryId = navCategory.Id;
                            item.Id = navCategory.UniqueId;
                            item.NavigationType = DynamicNavigationType.Category;
                            NavigationSettings.Add(item);
                            context.Response.Write("Success");
                        }

                    }
                    catch (Exception exp)
                    {
                        context.Response.Write(exp.Message);
                    }

                    break;

                case "reOrderPosts":
                    try
                    {
                        Dictionary<int, Post> posts = new Dictionary<int, Post>();
                        DataBuddy.Query query = Post.CreateQuery();
                        query.AndWhere(Post.Columns.CategoryId, int.Parse(context.Request.QueryString["id"]));
                        foreach (Post post in PostCollection.FetchByQuery(query))
                        {
                            posts[post.Id] = post;
                        }

                        string postOrder = context.Request.Form["posts"];
                        int orderNumber = 1;
                        foreach (string sId in postOrder.Split('&'))
                        {
                            Post post = null;
                            posts.TryGetValue(int.Parse(sId), out post);
                            if (post != null && post.SortOrder != orderNumber)
                            {
                                post.SortOrder = orderNumber;
                                post.Save();
                            }

                            orderNumber++;
                        }

                        context.Response.Write("Success");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "reOrderHomePosts":
                    try
                    {
                        Dictionary<int, Post> posts = new Dictionary<int, Post>();
                        DataBuddy.Query query = Post.CreateQuery();
                        query.AndWhere(Post.Columns.IsHome, true);
                        foreach (Post post in PostCollection.FetchByQuery(query))
                        {
                            posts[post.Id] = post;
                        }

                        string postOrder = context.Request.Form["posts"];
                        int orderNumber = 1;
                        foreach (string sId in postOrder.Split('&'))
                        {
                            Post post = null;
                            posts.TryGetValue(int.Parse(sId), out post);
                            if (post != null && post.HomeSortOrder != orderNumber)
                            {
                                post.HomeSortOrder = orderNumber;
                                post.Save();
                            }

                            orderNumber++;
                        }

                        context.Response.Write("Success");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "categoryForm":

                    int selectedCategory = int.Parse(context.Request.QueryString["category"] ?? "-1");
                    int postId = int.Parse(context.Request.QueryString["post"] ?? "-1");
                    NameValueCollection nvcCustomFields;
                    if (postId > 0)
                        nvcCustomFields = new Post(postId).CustomFields();
                    else
                        nvcCustomFields = new NameValueCollection();

                    CustomFormSettings cfs = CustomFormSettings.Get(selectedCategory);

                    if (cfs.HasFields)
                    {
                        foreach (CustomField cf in cfs.Fields)
                        {
                            if (context.Request.Form[cf.Id.ToString()] != null)
                                nvcCustomFields[cf.Name] = context.Request.Form[cf.Id.ToString()];
                        }

                        context.Response.Write(cfs.GetHtmlForm(nvcCustomFields, (postId < 1)));
                    }
                    else
                        context.Response.Write("");

                    break;

                case "toggleEventStatus":

                    try
                    {
                        EventDetails ed = Events.GetEvent(context.Request.QueryString["t"]);
                        ed.Enabled = !ed.Enabled;

                        if (ed.Enabled)
                            ed.Event.EventEnabled();
                        else
                            ed.Event.EventDisabled();

                        Events.Save(ed);

                        context.Response.Write(ed.Enabled ? "Enabled" : "Disabled");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "buildMainFeed":
                    try
                    {
                        FileInfo mainFeedFileInfo = new FileInfo(HttpContext.Current.Server.MapPath("~/Feed/Default.aspx"));

                        if (!mainFeedFileInfo.Directory.Exists)
                            mainFeedFileInfo.Directory.Create();

                        using (StreamWriter sw = new StreamWriter(mainFeedFileInfo.FullName, false))
                        {
                            sw.WriteLine("<%@ Page Language=\"C#\" Inherits=\"Graffiti.Core.RSS\" %>");
                            sw.Close();
                        }

                        context.Response.Write("Success");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                        return;
                    }

                    break;

                case "removeFeedData":
                    try
                    {
                        FeedManager.RemoveFeedData();
                        context.Response.Write("Success");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

                case "buildCategoryPages":

                    try
                    {
                        CategoryCollection cc = new CategoryController().GetCachedCategories();
                        foreach (Category cat in cc)
                            cat.WritePages();

                        context.Response.Write("Success");
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                        return;
                    }

                    break;

                case "buildPages":

                    try
                    {

                        Query q = Post.CreateQuery();
                        q.PageIndex = Int32.Parse(context.Request.Form["p"]);
                        q.PageSize = 20;
                        q.OrderByDesc(Post.Columns.Id);

                        PostCollection pc = PostCollection.FetchByQuery(q);
                        if (pc.Count > 0)
                        {

                            foreach (Post postToWrite in pc)
                            {
                                postToWrite.WritePages();
                                foreach (string tagName in Util.ConvertStringToList(postToWrite.TagList))
                                {
                                    if (!string.IsNullOrEmpty(tagName))
                                        Tag.WritePage(tagName);
                                }

                            }

                            context.Response.Write("Next");
                        }
                        else
                        {
                            context.Response.Write("Success");
                        }

                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                        return;
                    }

                    break;

                case "importPosts":

                    try
                    {
                        Post newPost = new Post();
                        newPost.Title = HttpContext.Current.Server.HtmlDecode(context.Request.Form["subject"].ToString());

                        string postName = HttpContext.Current.Server.HtmlDecode(context.Request.Form["name"].ToString());

                        PostCollection pc = new PostCollection();

                        if (!String.IsNullOrEmpty(postName))
                        {
                            Query q = Post.CreateQuery();
                            q.AndWhere(Post.Columns.Name, Util.CleanForUrl(postName));
                            pc.LoadAndCloseReader(q.ExecuteReader());
                        }

                        if (pc.Count > 0)
                        {
                            newPost.Name = "[RENAME ME - " + Guid.NewGuid().ToString().Substring(0, 7) + "]";
                            newPost.Status = (int)PostStatus.Draft;
                        }
                        else if (String.IsNullOrEmpty(postName))
                        {
                            newPost.Name = "[RENAME ME - " + Guid.NewGuid().ToString().Substring(0, 7) + "]";
                            newPost.Status = (int)PostStatus.Draft;
                        }
                        else
                        {
                            newPost.Name = postName;
                            newPost.Status = (int)PostStatus.Publish;
                        }

                        if (String.IsNullOrEmpty(newPost.Title))
                            newPost.Title = newPost.Name;

                        newPost.PostBody = HttpContext.Current.Server.HtmlDecode(context.Request.Form["body"].ToString());
                        newPost.CreatedOn = Convert.ToDateTime(context.Request.Form["createdon"]);
                        newPost.CreatedBy = context.Request.Form["author"];
                        newPost.ModifiedBy = context.Request.Form["author"];
                        newPost.TagList = context.Request.Form["tags"];
                        newPost.ContentType = "text/html";
                        newPost.CategoryId = Convert.ToInt32(context.Request.Form["category"]);
                        newPost.UserName = context.Request.Form["author"];
                        newPost.EnableComments = true;
                        newPost.Published = Convert.ToDateTime(context.Request.Form["createdon"]);
                        newPost.IsPublished = Convert.ToBoolean(context.Request.Form["published"]);

                        // this was causing too many posts to be in draft status.
                        // updated text on migrator to flag users to just move their content/binary directory
                        // into graffiti's root
                        //if (context.Request.Form["method"] == "dasBlog")
                        //{
                        //    if (newPost.Body.ToLower().Contains("/content/binary/"))
                        //        newPost.Status = (int)PostStatus.Draft;
                        //}

                        newPost.Save(GraffitiUsers.Current.Name);

                        int postid = Convert.ToInt32(context.Request.Form["postid"]);

                        IMigrateFrom temp = null;

                        switch (context.Request.Form["method"])
                        {
                            case "CS2007Database":

                                CS2007Database db = new CS2007Database();
                                temp = (IMigrateFrom)db;

                                break;
                            case "Wordpress":

                                Wordpress wp = new Wordpress();
                                temp = (IMigrateFrom)wp;

                                break;

                            case "BlogML":

                                BlogML bml = new BlogML();
                                temp = (IMigrateFrom)bml;

                                break;

                            case "CS21Database":
                                CS21Database csDb = new CS21Database();
                                temp = (IMigrateFrom)csDb;

                                break;

                            case "dasBlog":
                                dasBlog dasb = new dasBlog();
                                temp = (IMigrateFrom)dasb;

                                break;
                        }

                        List<MigratorComment> comments = temp.GetComments(postid);

                        foreach (MigratorComment cmnt in comments)
                        {
                            Comment ct = new Comment();
                            ct.PostId = newPost.Id;
                            ct.Body = cmnt.Body;
                            ct.Published = cmnt.PublishedOn;
                            ct.IPAddress = cmnt.IPAddress;
                            ct.WebSite = cmnt.WebSite;
                            ct.Email = string.IsNullOrEmpty(cmnt.Email) ? "" : cmnt.Email;
                            ct.Name = string.IsNullOrEmpty(cmnt.UserName) ? "" : cmnt.UserName;
                            ct.IsPublished = cmnt.IsPublished;
                            ct.IsTrackback = cmnt.IsTrackback;
                            ct.SpamScore = cmnt.SpamScore;
                            ct.DontSendEmail = true;
                            ct.DontChangeUser = true;

                            ct.Save();

                            Comment ctemp = new Comment(ct.Id);
                            ctemp.DontSendEmail = true;
                            ctemp.DontChangeUser = true;
                            ctemp.Body = HttpContext.Current.Server.HtmlDecode(ctemp.Body);
                            ctemp.Save();
                        }

                        if (newPost.Status == (int)PostStatus.Publish)
                            context.Response.Write("Success" + context.Request.Form["panel"]);
                        else
                            context.Response.Write("Warning" + context.Request.Form["panel"]);
                    }
                    catch (Exception ex)
                    {

                        context.Response.Write(context.Request.Form["panel"] + ":" + ex.Message);
                    }

                    break;

                case "saveHomeSortStatus":

                    SiteSettings siteSettings = SiteSettings.Get();
                    siteSettings.UseCustomHomeList = bool.Parse(context.Request.Form["ic"]);
                    siteSettings.Save();
                    context.Response.Write("Success");

                    break;

                case "checkCategoryPermission":

                    try
                    {
                        int catID = Int32.Parse(context.Request.QueryString["category"]);
                        string permissionName = context.Request.QueryString["permission"];
                        Permission perm = RolePermissionManager.GetPermissions(catID, user);

                        bool permissionResult = false;
                        switch (permissionName)
                        {
                            case "Publish":
                                permissionResult = perm.Publish;
                                break;
                            case "Read":
                                permissionResult = perm.Read;
                                break;
                            case "Edit":
                                permissionResult = perm.Edit;
                                break;
                        }

                        context.Response.Write(permissionResult.ToString().ToLower());
                    }
                    catch (Exception ex)
                    {
                        context.Response.Write(ex.Message);
                    }
                    break;

            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            Macros macros = new Macros();
            context.Response.ContentType = "text/xml";

            int postId = 0;
            try { postId = int.Parse(context.Request.QueryString["id"]); }
            catch { }

            if (postId <= 0)
                TrackbackResponse(context, "PostId is invalid or missing");

            if (context.Request.HttpMethod == "POST")
            {
                string title = SafeParam(context, "title");
                string excerpt = SafeParam(context, "excerpt");
                string url = SafeParam(context, "url");
                string blog_name = SafeParam(context, "blog_name");

                try
                {
                    // Check if params are valid
                    if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(title) || string.IsNullOrEmpty(blog_name) || string.IsNullOrEmpty(excerpt))
                    {
                        TrackbackResponse(context, "One or more parameters are invalid or missing");
                    }

                    Post trackedEntry = Post.GetCachedPost(postId);
                    if (trackedEntry == null)
                    {
                        TrackbackResponse(context, "The link does not exist");
                        return;
                    }

                    if (!trackedEntry.EnableComments || !trackedEntry.EnableNewComments)
                    {
                        TrackbackResponse(context, "Trackbacks are not enabled");
                        return;
                    }

                    if (!IsNewTrackBack(trackedEntry.Id, url))
                    {
                        TrackbackResponse(context, "Trackbacks already exists");
                        return;
                    }

                    string pageTitle = null;
                    if (!LinkParser.SourceContainsTarget(url, macros.FullUrl(trackedEntry.Url), out pageTitle))
                    {
                        TrackbackResponse(context, "Sorry couldn't find a relevant link in " + url);
                    }

                    if (string.IsNullOrEmpty(pageTitle))
                    {
                        TrackbackResponse(context, "Could not find a readable HTML title in the remote page at " + url);
                        return;
                    }

                    if (!string.IsNullOrEmpty(excerpt))
                        excerpt = Util.RemoveHtml(excerpt, 250);

                    // Create the Trackback item
                    Comment comment = new Comment();
                    comment.IsTrackback = true;
                    comment.PostId = trackedEntry.Id;
                    comment.Name = title;
                    comment.WebSite = url;
                    comment.Body = excerpt;
                    comment.IPAddress = context.Request.UserHostAddress;
                    comment.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet);
                    comment.Save();

                    // Log success message to EventLog
                    string message = String.Format("Trackback request received from {0} and saved to post {1}.", url, trackedEntry.Title);
                    Log.Info("Trackback Received", message);

                    context.Response.Write(successResponseXML);
                    context.Response.End();
                }
                catch (System.Threading.ThreadAbortException) { }
                catch (System.Exception ex)
                {
                    if (ex.Message != null)
                        TrackbackResponse(context, string.Format("Error occurred while processing Trackback: {0}", ex.Message));
                    else
                        TrackbackResponse(context, "Unknown error occurred while processing Trackback.");
                }

            }
        }
예제 #3
0
        private string GetBreadCrumbs()
        {
            Urls urls = new Urls();
            StringBuilder crumbs = new StringBuilder();

            if (this.Page.MasterPageFile.EndsWith("AdminModal.master"))
                crumbs.Append("<div class=\"breadcrumbs_modal\">");
            else
                crumbs.Append("<div class=\"breadcrumbs\">");

            switch (_sectionName)
            {
                case Section.ThemeEdit:
                    {
                        crumbs.Append(GetHyperLink("Presentation", ResolveUrl("~/graffiti-admin/presentation/"), true));
                        crumbs.Append(GetHyperLink("Themes", ResolveUrl("~/graffiti-admin/presentation/themes/"), true));

                        string theme = HttpContext.Current.Request.QueryString[QueryStringKey.Theme];
                        crumbs.Append(GetHyperLink(theme, String.Format("EditTheme.aspx?{0}={1}", QueryStringKey.Theme, theme), false));
                    }
                    break;

                case Section.ConfigureTheme:
                    {
                        crumbs.Append(GetHyperLink("Presentation", ResolveUrl("~/graffiti-admin/presentation/"), true));
                        crumbs.Append(GetHyperLink("Themes", ResolveUrl("~/graffiti-admin/presentation/themes/"), true));

                        string theme = HttpContext.Current.Request.QueryString[QueryStringKey.Theme];
                        crumbs.Append(GetHyperLink(theme, String.Format("EditTheme.aspx?{0}={1}", QueryStringKey.Theme, theme), true));

                        crumbs.Append(GetHyperLink("Configure Theme", ResolveUrl("~/graffiti-admin/presentation/themes/ConfigureTheme.aspx?" + QueryStringKey.Theme + "=" + theme), false));
                    }
                    break;

                case Section.Widget:

                    crumbs.Append(GetHyperLink("Presentation", ResolveUrl("~/graffiti-admin/presentation/"), true));
                    crumbs.Append(GetHyperLink("Widgets", ResolveUrl("~/graffiti-admin/presentation/widgets/"), true));

                    break;

                case Section.WidgetEdit:

                    crumbs.Append(GetHyperLink("Presentation", ResolveUrl("~/graffiti-admin/presentation/"), true));
                    crumbs.Append(GetHyperLink("Widgets", ResolveUrl("~/graffiti-admin/presentation/widgets/"), true));

                    Widget widget = Widgets.Fetch(new Guid(HttpContext.Current.Request.QueryString[QueryStringKey.Id]));
                    crumbs.Append(GetHyperLink(widget.Name, String.Format("edit.aspx?{0}={1}", QueryStringKey.Id, widget.Id), false));

                    break;

                case Section.SiteSettings:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Settings", ResolveUrl("~/graffiti-admin/site-options/settings/"), false));

                    break;

                case Section.Configuration:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Configuration", ResolveUrl("~/graffiti-admin/site-options/configuration/"), false));

                    break;

                case Section.Utilities:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Utilities", ResolveUrl("~/graffiti-admin/site-options/utilities/"), false));

                    break;

                case Section.RebuildPages:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Utilities", ResolveUrl("~/graffiti-admin/site-options/utilities/"), true));
                    crumbs.Append(GetHyperLink("Rebuild Pages", ResolveUrl("~/graffiti-admin/site-options/utilities/RebuildPages.aspx"), false));

                    break;

                case Section.Logs:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Utilities", ResolveUrl("~/graffiti-admin/site-options/utilities/"), true));
                    crumbs.Append(GetHyperLink("Logs", ResolveUrl("~/graffiti-admin/site-options/utilities/LogViewer.aspx"), false));

                    break;

                case Section.Migrator:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Utilities", ResolveUrl("~/graffiti-admin/site-options/utilities/"), true));
                    crumbs.Append(GetHyperLink("Migrator", ResolveUrl("~/graffiti-admin/site-options/utilities/migrator/"), false));

                    break;

                case Section.Comments:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Comments", ResolveUrl("~/graffiti-admin/site-options/comments/"), false));

                    break;

                case Section.CustomFields:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Custom Fields", ResolveUrl("~/graffiti-admin/site-options/custom-fields/"), true));

                    string customFieldId = HttpContext.Current.Request.QueryString[QueryStringKey.Id];
                    int fieldCategoryId = int.Parse(HttpContext.Current.Request.QueryString["category"] ?? "-1");

                    if (!String.IsNullOrEmpty(customFieldId))
                    {
                        CustomFormSettings csf = CustomFormSettings.Get(fieldCategoryId, false);

                        CustomField cf = null;
                        Guid g = new Guid(customFieldId);
                        foreach (CustomField cfx in csf.Fields)
                        {
                            if (cfx.Id == g)
                            {
                                cf = cfx;
                                break;
                            }
                        }

                        if (cf != null)
                        {
                            crumbs.Append(GetHyperLink(cf.Name, ResolveUrl("~/graffiti-admin/site-options/custom-fields/?id=" + cf.Id), false));
                        }
                    }

                    break;

                case Section.Themes:

                    crumbs.Append(GetHyperLink("Presentation", ResolveUrl("~/graffiti-admin/presentation/"), true));
                    crumbs.Append(GetHyperLink("Themes", ResolveUrl("~/graffiti-admin/presentation/themes/"), false));

                    break;

                case Section.SortHomePosts:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Home Page", ResolveUrl("~/graffiti-admin/site-options/homesort/"), false));

                    break;

                case Section.Licensing:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Licensing", ResolveUrl("~/graffiti-admin/site-options/licensing/"), false));

                    break;

                case Section.Categories:
                    {
                        string id = HttpContext.Current.Request.QueryString[QueryStringKey.Id];

                        if (String.IsNullOrEmpty(id))
                            return string.Empty;

                        List<Category> categories = new List<Category>();

                        Category c = new Category(id);
                        categories.Add(c);

                        Category parent;

                        if (c.ParentId != -1)
                        {
                            parent = c;

                            bool noMoreParents = false;

                            while (!noMoreParents)
                            {
                                parent = new Category(parent.ParentId);
                                if (parent.Id != 0)
                                {
                                    categories.Insert(0, parent);
                                }
                                else
                                {
                                    noMoreParents = true;
                                }
                            }
                        }

                        crumbs.Append(GetHyperLink("Categories", ResolveUrl("~/graffiti-admin/categories/"), true));

                        int counter = 0;
                        int catCount = categories.Count;

                        foreach (Category tempcat in categories)
                        {
                            counter++;

                            bool addArrow = counter == catCount ? false : true;

                            crumbs.Append(GetHyperLink(tempcat.Name, ResolveUrl("~/graffiti-admin/categories/?id=" + tempcat.Id), addArrow));
                        }
                    }
                    break;

                case Section.SortPosts:
                    {
                        string id = HttpContext.Current.Request.QueryString[QueryStringKey.Id];

                        if (String.IsNullOrEmpty(id))
                            return string.Empty;

                        List<Category> categories = new List<Category>();

                        Category c = new Category(id);
                        categories.Add(c);

                        Category parent;

                        if (c.ParentId != -1)
                        {
                            parent = c;

                            bool noMoreParents = false;

                            while (!noMoreParents)
                            {
                                parent = new Category(parent.ParentId);
                                if (parent.Id != 0)
                                {
                                    categories.Insert(0, parent);
                                }
                                else
                                {
                                    noMoreParents = true;
                                }
                            }
                        }

                        crumbs.Append(GetHyperLink("Categories", ResolveUrl("~/graffiti-admin/categories/"), true));
                        foreach (Category tempcat in categories)
                        {
                            crumbs.Append(GetHyperLink(tempcat.Name, ResolveUrl("~/graffiti-admin/categories/?id=" + tempcat.Id), true));
                        }

                        crumbs.Append(GetHyperLink("Order Posts", ResolveUrl("~/graffiti-admin/categories/PostSortOrder.aspx?id=" + id), false));
                    }
                    break;

                case Section.SiteComments:

                    string commentId = HttpContext.Current.Request.QueryString[QueryStringKey.Id];

                    if (String.IsNullOrEmpty(commentId))
                        return string.Empty;

                    Comment comment = new Comment(commentId);

                    crumbs.Append(GetHyperLink("Comments", ResolveUrl("~/graffiti-admin/comments/"), true));
                    crumbs.Append(GetHyperLink(comment.Name + " @ " + comment.Published, ResolveUrl("~/graffiti-admin/comments/?id=" + comment.Id), false));

                    break;

                case Section.Navigation:

                    crumbs.Append(GetHyperLink("Presentation", ResolveUrl("~/graffiti-admin/presentation/"), true));
                    crumbs.Append(GetHyperLink("Navigation", ResolveUrl("~/graffiti-admin/presentation/navigation/"), false));

                    break;

                case Section.UserManagement:

                    crumbs.Append(GetHyperLink("User Management", ResolveUrl("~/graffiti-admin/user-management/"), true));

                    string user = HttpContext.Current.Request.QueryString[QueryStringKey.User];

                    if (!String.IsNullOrEmpty(user))
                    {
                        crumbs.Append(GetHyperLink("Users", ResolveUrl("~/graffiti-admin/user-management/users"), true));

                        IGraffitiUser graffitiUser = GraffitiUsers.GetUser(user);
                        crumbs.Append(GetHyperLink(graffitiUser.Name, ResolveUrl("~/graffiti-admin/user-management/users/?user="******"Users", ResolveUrl("~/graffiti-admin/user-management/users"), false));
                    }

                    break;

                case Section.Roles:

                    crumbs.Append(GetHyperLink("User Management", ResolveUrl("~/graffiti-admin/user-management/"), true));

                    string role = HttpUtility.HtmlEncode(HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.QueryString[QueryStringKey.Role]));

                    if (!String.IsNullOrEmpty(role))
                    {
                        crumbs.Append(GetHyperLink("Roles", ResolveUrl("~/graffiti-admin/user-management/roles"), true));

                        crumbs.Append(GetHyperLink(role, ResolveUrl("~/graffiti-admin/user-management/roles/?role=" + role), false));
                    }
                    else
                    {
                        crumbs.Append(GetHyperLink("Roles", ResolveUrl("~/graffiti-admin/user-management/roles"), false));
                    }

                    break;

                case Section.ChangePassword:

                    string cpUser = HttpContext.Current.Request.QueryString[QueryStringKey.User];

                    if (String.IsNullOrEmpty(cpUser))
                        return string.Empty;

                    IGraffitiUser graffitiUser1 = GraffitiUsers.GetUser(cpUser);

                    crumbs.Append(GetHyperLink("User Management", ResolveUrl("~/graffiti-admin/user-management/"), true));
                    crumbs.Append(GetHyperLink("Users", ResolveUrl("~/graffiti-admin/user-management/users/"), true));
                    crumbs.Append(GetHyperLink(graffitiUser1.Name, ResolveUrl("~/graffiti-admin/user-management/users/?user="******"Change Password", ResolveUrl("~/graffiti-admin/user-management/users/changepassword.aspx?user="******"Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Plug-Ins", ResolveUrl("~/graffiti-admin/site-options/plug-ins/"), false));

                    break;

                case Section.PlugInsEdit:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Plug-Ins", ResolveUrl("~/graffiti-admin/site-options/plug-ins/"), true));

                    EventDetails ed = Graffiti.Core.Events.GetEvent(HttpContext.Current.Request.QueryString["t"]);

                    crumbs.Append(GetHyperLink(ed.Event.Name, ResolveUrl("~/graffiti-admin/site-options/plug-ins/edit.aspx?t=") + HttpContext.Current.Request.QueryString["t"], false));

                    break;

                case Section.Packages:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Packages", ResolveUrl("~/graffiti-admin/site-options/packages/"), false));

                    break;

                case Section.EmailSettings:

                    crumbs.Append(GetHyperLink("Site Options", ResolveUrl("~/graffiti-admin/site-options/"), true));
                    crumbs.Append(GetHyperLink("Email Settings", ResolveUrl("~/graffiti-admin/site-options/email-settings/"), false));

                    break;

                case Section.WidgetMarketplace:

                    crumbs.Append(GetHyperLink("All Widgets", urls.AdminMarketplace("Widgets"), true));

                    CatalogInfo widgets = Marketplace.Marketplace.Catalogs[CatalogType.Widgets];

                    int categoryId = 0;
                    string category = HttpContext.Current.Request.QueryString["category"];
                    if (!string.IsNullOrEmpty(category))
                    {
                        try { categoryId = int.Parse(category); }
                        catch {}
                    }

                    if ((categoryId != 0) && widgets.Categories.ContainsKey(categoryId))
                    {
                        CategoryInfo categoryInfo = widgets.Categories[categoryId];
                        crumbs.Append(GetHyperLink(categoryInfo.Name, urls.AdminMarketplace("Widgets") + "&category=" + categoryInfo.Id.ToString(), false));
                    }

                    string creatorId = string.Empty;
                    if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["creator"]))
                        creatorId = HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["creator"]);

                    if (!string.IsNullOrEmpty(creatorId) && (Marketplace.Marketplace.Creators.ContainsKey(creatorId)))
                    {
                        CreatorInfo creatorInfo = Marketplace.Marketplace.Creators[creatorId];
                        crumbs.Append(GetHyperLink(creatorInfo.Name, urls.AdminMarketplace("Widgets") + "&creator=" + HttpUtility.UrlEncode(creatorInfo.Id), false));
                    }

                    int itemId = 0;
                    string item = HttpContext.Current.Request.QueryString["item"];
                    if (!string.IsNullOrEmpty(item))
                    {
                        try { itemId = int.Parse(item); }
                        catch { }
                    }

                    if ((itemId != 0) && (widgets.Items.ContainsKey(itemId)))
                    {
                        ItemInfo itemInfo = widgets.Items[itemId];
                        CategoryInfo categoryInfo = itemInfo.Category;
                        if (categoryInfo != null)
                        {
                            crumbs.Append(GetHyperLink(categoryInfo.Name, urls.AdminMarketplace("Widgets") + "&category=" + categoryInfo.Id.ToString(), true));
                            crumbs.Append(GetHyperLink(itemInfo.Name, urls.AdminMarketplaceItem("Widgets", itemInfo.Id), false));
                        }
                    }

                    break;

                case Section.ThemeMarketplace:

                    crumbs.Append(GetHyperLink("All Themes", urls.AdminMarketplace("Themes"), true));

                    CatalogInfo themeCatalog = Marketplace.Marketplace.Catalogs[CatalogType.Themes];

                    categoryId = 0;
                    category = HttpContext.Current.Request.QueryString["category"];
                    if (!string.IsNullOrEmpty(category))
                    {
                        try { categoryId = int.Parse(category); }
                        catch { }
                    }

                    if ((categoryId != 0) && (themeCatalog.Categories.ContainsKey(categoryId)))
                    {
                        CategoryInfo categoryInfo = themeCatalog.Categories[categoryId];
                        crumbs.Append(GetHyperLink(categoryInfo.Name, urls.AdminMarketplace("Themes") + "&category=" + categoryInfo.Id.ToString(), false));
                    }

                    creatorId = string.Empty;
                    if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["creator"]))
                        creatorId = HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["creator"]);

                    if (!string.IsNullOrEmpty(creatorId) && (Marketplace.Marketplace.Creators.ContainsKey(creatorId)))
                    {
                        CreatorInfo creatorInfo = Marketplace.Marketplace.Creators[creatorId];
                        crumbs.Append(GetHyperLink(creatorInfo.Name, urls.AdminMarketplace("Themes") + "&creator=" + HttpUtility.UrlEncode(creatorInfo.Id), false));
                    }

                    itemId = 0;
                    item = HttpContext.Current.Request.QueryString["item"];
                    if (!string.IsNullOrEmpty(item))
                    {
                        try { itemId = int.Parse(item); }
                        catch { }
                    }

                    if ((itemId != 0) && (themeCatalog.Items.ContainsKey(itemId)))
                    {
                        ItemInfo itemInfo = themeCatalog.Items[itemId];
                        CategoryInfo categoryInfo = itemInfo.Category;
                        if (categoryInfo != null)
                        {
                            crumbs.Append(GetHyperLink(categoryInfo.Name, urls.AdminMarketplace("Themes") + "&category=" + categoryInfo.Id.ToString(), true));
                            crumbs.Append(GetHyperLink(itemInfo.Name, urls.AdminMarketplaceItem("Themes", itemInfo.Id), false));
                        }
                    }

                    break;

                case Section.PluginMarketplace:

                    crumbs.Append(GetHyperLink("All Plugins", urls.AdminMarketplace("Plugins"), true));

                    CatalogInfo plugins = Marketplace.Marketplace.Catalogs[CatalogType.Plugins];

                    categoryId = 0;
                    category = HttpContext.Current.Request.QueryString["category"];
                    if (!string.IsNullOrEmpty(category))
                    {
                        try { categoryId = int.Parse(category); }
                        catch { }
                    }

                    if ((categoryId != 0) && plugins.Categories.ContainsKey(categoryId))
                    {
                        CategoryInfo categoryInfo = plugins.Categories[categoryId];
                        crumbs.Append(GetHyperLink(categoryInfo.Name, urls.AdminMarketplace("Plugins") + "&category=" + categoryInfo.Id.ToString(), false));
                    }

                    creatorId = string.Empty;
                    if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["creator"]))
                        creatorId = HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["creator"]);

                    if (!string.IsNullOrEmpty(creatorId) && (Marketplace.Marketplace.Creators.ContainsKey(creatorId)))
                    {
                        CreatorInfo creatorInfo = Marketplace.Marketplace.Creators[creatorId];
                        crumbs.Append(GetHyperLink(creatorInfo.Name, urls.AdminMarketplace("Plugins") + "&creator=" + HttpUtility.UrlEncode(creatorInfo.Id), false));
                    }

                    itemId = 0;
                    item = HttpContext.Current.Request.QueryString["item"];
                    if (!string.IsNullOrEmpty(item))
                    {
                        try { itemId = int.Parse(item); }
                        catch { }
                    }

                    if ((itemId != 0) && (plugins.Items.ContainsKey(itemId)))
                    {
                        ItemInfo itemInfo = plugins.Items[itemId];
                        CategoryInfo categoryInfo = itemInfo.Category;
                        if (categoryInfo != null)
                        {
                            crumbs.Append(GetHyperLink(categoryInfo.Name, urls.AdminMarketplace("Plugins") + "&category=" + categoryInfo.Id.ToString(), true));
                            crumbs.Append(GetHyperLink(itemInfo.Name, urls.AdminMarketplaceItem("Plugins", itemInfo.Id), false));
                        }
                    }

                    break;

                // more breadcrumb logic here, add a value to the enum
            }

            crumbs.Append("</div>");

            return crumbs.ToString();
        }
예제 #4
0
        public static int ScoreComment(Comment comment, Post p)
        {
            int score = 0;

            CommentSettings cs = Get();

            if (string.IsNullOrEmpty(comment.Body))
                throw new Exception("No comment body found");

            if (!cs.EnableCommentOnPost(p))
                throw new Exception("No new comments are allowed on this post");

            if(comment.Body.Trim().Length < 20)
            {
                score += (-1*(comment.Body.Trim().Length - 20));
            }

            score += Regex.Matches(comment.Body, @"(http|ftp|https):\/\/[\w]+(.[\w]+)([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])", RegexOptions.IgnoreCase).Count;

            score += CountWords(comment);

            if (!String.IsNullOrEmpty(cs.AkismetId))
            {
                try
                {
                    AkismetComment akComment = GetComment(comment);
                    Akismet akismet = new Akismet(cs.AkismetId, akComment.Blog, SiteSettings.Version);

                    if (akismet.CommentCheck(akComment))
                        score += cs.AkismetScore;
                }
                catch(Exception ex)
                {
                    Log.Error("Spam - Akismet", "Akismet scoring failed.\n\nReason: {0}", ex);
                }
            }

            return score;
        }
예제 #5
0
        private void CreatePingBack(string sourceURI, string targetURI)
        {
            // Check Parameters
            if (string.IsNullOrEmpty(sourceURI))
            {
                throw new XmlRpcFaultException(errorCode_SourceURIDoesNotExist, "No source URI parameter found, please try harder!");
            }
            if (string.IsNullOrEmpty(targetURI))
            {
                throw new XmlRpcFaultException(errorCode_TargetURIDoesNotExist, "The target URI does not exist!");
            }

            // Retrieve referenced post
            Post trackedEntry = null;
            try
            {
                trackedEntry = GetPostFromUrl(targetURI);
            }
            catch
            {
                throw new XmlRpcFaultException(errorCode_TargetURIInvalid, "The target URI is invalid.");
            }
            if (trackedEntry == null)
            {
                throw new XmlRpcFaultException(errorCode_TargetURIInvalid, "The target URI is invalid.");
            }

            // Check if trackbacks/pingbacks are enabled
            if (!trackedEntry.EnableComments || !trackedEntry.EnableNewComments)
            {
                throw new XmlRpcFaultException(errorCode_AccessDenied, "Pingbacks are not enabled.");
            }

            // Check if this is a duplicate pingback (or trackback)
            if (!IsNewTrackBack(trackedEntry.Id, sourceURI))
            {
                throw new XmlRpcFaultException(errorCode_DuplicatePingBack, "A pingback for this source URI already exists.");
            }

            // Retrieve the source document and check if it actually contains a link to the target
            string pageTitle = null;
            if (!LinkParser.SourceContainsTarget(sourceURI, new Macros().FullUrl(trackedEntry.Url), out pageTitle))
            {
                throw new XmlRpcFaultException(errorCode_SourceDoesNotContainTarget, "Sorry couldn't find a relevant link in " + sourceURI);
            }

            if (string.IsNullOrEmpty(pageTitle))
                throw new XmlRpcFaultException(errorCode_SourceDoesNotContainTarget, "Could not find a readable HTML title in the remote page at " + sourceURI);

            // Create the Trackback item
            Comment comment = new Comment();
            comment.IsTrackback = true;
            comment.PostId = trackedEntry.Id;
            comment.Name = pageTitle;
            comment.WebSite = sourceURI;
            comment.Body = "Pingback from " + pageTitle;
            comment.IPAddress = Context.Request.UserHostAddress;
            comment.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet);
            comment.Save();

            // Log success message to EventLog
            string message = String.Format("Pingback request received from {0} and saved to post {1}.", sourceURI, trackedEntry.Title);
            Log.Info("Pingback Received", message);
        }
예제 #6
0
        private static AkismetComment GetComment(Comment zComment)
        {
            Joel.Net.AkismetComment comment = new Joel.Net.AkismetComment();
            comment.Blog = new Macros().FullUrl(new Urls().Home);
            comment.CommentAuthor = zComment.Name;
            comment.CommentAuthorUrl = zComment.WebSite;
            comment.CommentContent = zComment.Body;
            comment.CommentType = "comment";
            comment.UserAgent = HttpContext.Current.Request.UserAgent;
            comment.UserIp = zComment.IPAddress;

            return comment;
        }
예제 #7
0
        private static int CountWords(Comment comment)
        {
            try
            {
                string words =
                    Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/spam/badwords.txt"));

                int count = 0;
                foreach (string word in words.Split(new char[] {';', '\n'}, StringSplitOptions.RemoveEmptyEntries))
                {
                    count += CountWord(word, comment);
                }

                return count;
            }
            catch(Exception ex)
            {
                Log.Error("Spam - Comment Count", "Counting bad words failed. \n\nReason: {0}", ex);
            }

            return 0;
        }
예제 #8
0
        private static int CountWord(string word, Comment comment)
        {
            Regex r = new Regex(word.Trim(), RegexOptions.IgnoreCase);

            int count = r.Matches(comment.Body).Count;
            count += r.Matches(comment.Name).Count;
            if (comment.WebSite != null)
                count += r.Matches(comment.WebSite).Count;

            return count;
        }
예제 #9
0
        /// <summary>
        /// Renders an href with the user details for the comment
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public string CommentLink(Comment comment)
        {
            string webSite = comment.WebSite;

            if (!string.IsNullOrEmpty(webSite))
            {
                Uri uri;
                // attempt to create a Uri out of this
                if (!Uri.TryCreate(webSite, UriKind.Absolute, out uri))
                    // if that didn't work as-is, try appending the HTTP scheme to it
                    Uri.TryCreate("http://" + webSite, UriKind.Absolute, out uri);

                // only show this if it is HTTP or HTTPS
                if (uri != null && (
                                              uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))
                    return string.Format("<a href=\"{0}\">{1}</a>", uri, comment.Name);
            }

            // either the website was not set, it couldn't be converted to a Uri, or was not HTTP or HTTPS
            return comment.Name;
        }
예제 #10
0
파일: ajax.cs 프로젝트: chartek/graffiticms
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.RequestType != "POST")
            return;

            if (context.Items["UserId"] == null)
            return;

            context.Response.ContentType = "text/plain";

            switch (context.Request.QueryString["command"])
            {
            case "newComment":

                Comment comment = new Comment();

                comment.Name = context.Request.Form["author"];
                comment.WebSite = context.Request.Form["url"];
                comment.Email = context.Request.Form["email"];

                comment.Body = context.Request.Form["comment"];

                if (!context.Request.IsAuthenticated && String.IsNullOrEmpty(comment.Name))
                {
                    context.Response.Write("Please enter your name");
                    return;
                }

                if (String.IsNullOrEmpty(comment.Body))
                {
                    context.Response.Write("Please enter a comment");
                    return;
                }

                comment.IPAddress = context.Request.UserHostAddress;
                comment.PostId = Int32.Parse(context.Request.Form["comment_post_ID"]);

                comment.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet);

                comment.Save();
                context.Response.Write("Your comment has been received and will be published shortly. Thanks!");

                break;

            case "newContactMessage":

                string subject = context.Request.Form["subject"];
                string email = context.Request.Form["email"];
                string name = context.Request.Form["name"];
                string message = context.Request.Form["message"];

                if (string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(message))
                {
                    context.Response.Write("All of the fields are required, your message has not been sent");
                    context.Response.End();
                    return;
                }

                if (!Regex.IsMatch(email, @"\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b", RegexOptions.IgnoreCase))
                {
                    context.Response.Write("The email address you entered is not valid");
                    context.Response.End();
                    return;
                }

                EmailTemplateToolboxContext templateContext = new EmailTemplateToolboxContext();
                templateContext.Put("subject", context.Server.HtmlEncode(subject));
                templateContext.Put("email", context.Server.HtmlEncode(email));
                templateContext.Put("name", context.Server.HtmlEncode(name));
                templateContext.Put("message", Util.ConvertTextToHTML(message));
                templateContext.Put("ip", context.Request.UserHostAddress);

                EmailTemplate et = new EmailTemplate();
                et.Subject = "Contact Request: " + subject;
                et.Context = templateContext;
                et.From = email;
                et.TemplateName = "contact.view";

                Log.Info("Contact Received", "Subject: {0}\nFrom:{1} ({2})\nIP:{3}\n\n{4}", subject, name, email, context.Request.UserHostAddress, message);

                foreach (IGraffitiUser user in GraffitiUsers.GetUsers(GraffitiUsers.AdminRole))
                {
                    et.To = user.Email;
                    Emailer.Send(et);
                }

                context.Response.Write("Your message was received. Thanks!");

                break;
            }
        }