protected override void OnLoad(EventArgs e) { base.OnLoad(e); Initialize(); SiteSettings settings = SiteSettings.Get(); if (!settings.InitialSetupCompleted) { Response.Redirect(ResolveUrl("~/graffiti-setup/")); } if (string.IsNullOrEmpty(RedirectUrl)) { GraffitiContext graffitiContext = GraffitiContext.Current; SetContextDefault(graffitiContext, ViewName); LoadContent(graffitiContext); if ( !RolePermissionManager.GetPermissions(CategoryID, GraffitiUsers.Current, graffitiContext["where"].ToString() == "home" || graffitiContext["where"].ToString() == "search").Read) { Response.Redirect(ResolveUrl("~/access-denied/")); } ViewManager.Render(Context, graffitiContext, ThemeName); } else { RedirectTo(VirtualPathUtility.ToAbsolute(RedirectUrl)); } }
public static bool SendMailMessage(MailMessage mm) { using (mm) { SiteSettings settings = SiteSettings.Get(); SmtpClient client = new SmtpClient(); client.Host = settings.EmailServer; if (settings.EmailServerRequiresAuthentication) { client.Credentials = new NetworkCredential(settings.EmailUser, settings.EmailPassword); } if (settings.EmailRequiresSSL) { client.EnableSsl = true; } if (settings.EmailPort > 0) { client.Port = settings.EmailPort; } client.Send(mm); } return(true); }
public static void DestroyDeletedPost(int postid) { Post p = new Post(postid); // Check if post is featured in it's category before deletion Core.Category c = p.Category; if (p.Id == c.FeaturedId) { c.FeaturedId = 0; c.Save(); } // Check site featured post SiteSettings settings = SiteSettings.Get(); if (p.Id == settings.FeaturedId) { settings.FeaturedId = 0; settings.Save(); } PostStatistic.Destroy(PostStatistic.Columns.PostId, postid); Tag.Destroy(Tag.Columns.PostId, postid); Comment.Destroy(Comment.Columns.PostId, postid); DataService.ExecuteNonQuery(new QueryCommand("delete from graffiti_VersionStore where Type = 'post/xml' and ItemId = " + postid)); Post.Destroy(postid); DeletePostDirectory(p); }
private static void ProcessFeaturedPosts(Post p, IGraffitiUser user, bool isFeaturedPost, bool isFeaturedCategory) { SiteSettings settings = SiteSettings.Get(); if (p.IsPublished && isFeaturedPost) { settings.FeaturedId = p.Id; settings.Save(); } else if (settings.FeaturedId == p.Id) { settings.FeaturedId = -1; settings.Save(); } Category c = p.Category; if (p.IsPublished && isFeaturedCategory) { c.FeaturedId = p.Id; c.Save(user.Name); } else if (c.FeaturedId == p.Id) { c.FeaturedId = -1; c.Save(user.Name); } }
protected override void LoadContent(GraffitiContext graffitiContext) { graffitiContext["where"] = "post"; Post post = Post.GetCachedPost(PostId); if (post.IsDeleted || (!post.IsPublished && GraffitiUsers.Current == null)) { RedirectTo(new Urls().Home); } else if (PostName != null && CategoryName != null && (!Util.AreEqualIgnoreCase(PostName, post.Name) || !Util.AreEqualIgnoreCase(CategoryName, post.Category.LinkName))) { RedirectTo(post.Url); } else if (Context.Request.Cookies["Graffiti-Post-" + PostId] == null) { Post.UpdateViewCount(PostId); //SPs.UpdatePostView(PostId).Execute(); HttpCookie cookie = new HttpCookie("Graffiti-Post-" + PostId, PostId.ToString()); Context.Response.Cookies.Add(cookie); } graffitiContext["title"] = post.Title + " : " + SiteSettings.Get().Title; graffitiContext["category"] = post.Category; graffitiContext["post"] = post; graffitiContext.RegisterOnRequestDelegate("feedback", GetPostFeedback); graffitiContext.RegisterOnRequestDelegate("comments", GetPostComments); graffitiContext.RegisterOnRequestDelegate("trackbacks", GetPostTrackbacks); }
private static void QuickSave(int type, string title, string message) { Log l = new Log(); l.Type = type; l.Title = title; l.Message = message; l.Save("", DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet)); }
public static void SendPReqiresApprovalMessage(Post p, IGraffitiUser user) { var users = new List <IGraffitiUser>(); foreach (IGraffitiUser u in GraffitiUsers.GetUsers("*")) { if (GraffitiUsers.IsAdmin(u) || RolePermissionManager.GetPermissions(p.CategoryId, u).Publish) { users.Add(u); } } Macros m = new Macros(); EmailTemplateToolboxContext pttc = new EmailTemplateToolboxContext(); pttc.Put("sitesettings", SiteSettings.Get()); pttc.Put("post", p); pttc.Put("user", user); pttc.Put("macros", m); pttc.Put("home", m.FullUrl(new Urls().Home)); pttc.Put("adminUrl", m.FullUrl(VirtualPathUtility.ToAbsolute("~/graffiti-admin/posts/write/")) + "?id=" + p.Id + "&v=" + p.Version); string adminApprovalUrl = m.FullUrl(VirtualPathUtility.ToAbsolute("~/api/approve.ashx")) + "?key={0}&u={1}&id={2}&v={3}"; EmailTemplate template = new EmailTemplate(); template.Context = pttc; template.Subject = "You have content to approve: " + p.Title; template.TemplateName = "QueuedPost.view"; foreach (IGraffitiUser admin in users) { template.Context.Put("adminApprovalUrl", string.Format(adminApprovalUrl, admin.UniqueId, admin.Name, p.Id, p.Version)); try { template.To = admin.Email; Emailer.Send(template); //Emailer.Send("QueuedPost.view", admin.Email, "You have content to approve: " + p.Title, pttc); } catch (Exception ex) { Log.Error("Email Error", ex.Message); } } Log.Info("Post approval email", "{0} user(s) were sent an email to approve the post \"{1}\" (id: {2}).", users.Count, p.Title, p.Id); }
/// <summary> /// Checks to see if an optionally named/existing theme exists. /// </summary> protected bool ViewExists(string viewName) { if (SiteSettings.Get().CacheViews) { if (!fileCache.ContainsKey(ThemeName + ":" + viewName)) { fileCache[ThemeName + ":" + viewName] = ViewManager.Exists(ThemeName, viewName); } return(fileCache[ThemeName + ":" + viewName]); } else { return(ViewManager.Exists(ThemeName, viewName)); } }
static GRequest() { if (!string.IsNullOrEmpty(SiteSettings.Get().ProxyHost)) { WebProxy proxy = new WebProxy(SiteSettings.Get().ProxyHost, SiteSettings.Get().ProxyPort); proxy.BypassProxyOnLocal = SiteSettings.Get().ProxyBypassOnLocal; if (SiteSettings.Get().ProxyUsername != string.Empty) { proxy.Credentials = new NetworkCredential(SiteSettings.Get().ProxyUsername, SiteSettings.Get().ProxyPassword); } WebProxy = proxy; } }
/// <summary> /// Gets the sites featured post /// </summary> /// <returns></returns> public Post Featured() { SiteSettings settings = SiteSettings.Get(); if (settings.FeaturedId > 0) { Post p = Post.GetCachedPost(settings.FeaturedId); if (p.IsPublished) { return(p); } } return(null); }
protected virtual object GetCategoryPosts(string key, GraffitiContext graffitiContext) { Category category = new CategoryController().GetCachedCategory(CategoryID, false); int pageSize = SiteSettings.Get().PageSize; PostCollection pc = ZCache.Get <PostCollection>(string.Format(CacheKey, PageIndex, CategoryID, category.SortOrder, pageSize)); if (pc == null) { pc = new PostCollection(); Query q = PostCollection.DefaultQuery(PageIndex, pageSize, category.SortOrder); if (Category.IncludeChildPosts) { if (category.ParentId > 0) { q.AndWhere(Post.Columns.CategoryId, CategoryID); } else { var ids = new List <int>(category.Children.Count + 1); foreach (Category child in category.Children) { ids.Add(child.Id); } ids.Add(category.Id); q.AndInWhere(Post.Columns.CategoryId, ids.ToArray()); } } else { q.AndWhere(Post.Columns.CategoryId, CategoryID); } pc.LoadAndCloseReader(q.ExecuteReader()); ZCache.InsertCache(string.Format(CacheKey, PageIndex, CategoryID, category.SortOrder, pageSize), pc, 60); } graffitiContext.TotalRecords = category.PostCount; graffitiContext.PageIndex = PageIndex; graffitiContext.PageSize = SiteSettings.Get().PageSize; return(pc); }
public BlogInfo[] getUsersBlogs(string appKey, string username, string password) { if (ValidateUser(username, password)) { var al = new BlogInfo[1]; BlogInfo bi = new BlogInfo(); bi.blogid = "root_blog"; bi.blogName = SiteSettings.Get().Title; bi.url = new Macros().FullUrl("~/"); al[0] = bi; return(al); } throw new XmlRpcFaultException(0, "User does not exist"); }
public static void SendRequestedChangesMessage(Post p, IGraffitiUser user) { List <IGraffitiUser> users = new List <IGraffitiUser>(); foreach (IGraffitiUser u in GraffitiUsers.GetUsers("*")) { if (GraffitiUsers.IsAdmin(u) || RolePermissionManager.GetPermissions(p.CategoryId, u).Publish) { users.Add(u); } } Macros m = new Macros(); EmailTemplateToolboxContext pttc = new EmailTemplateToolboxContext(); pttc.Put("sitesettings", SiteSettings.Get()); pttc.Put("post", p); pttc.Put("user", user); pttc.Put("macros", m); pttc.Put("home", m.FullUrl(new Urls().Home)); pttc.Put("adminUrl", m.FullUrl(VirtualPathUtility.ToAbsolute("~/graffiti-admin/posts/write/")) + "?id=" + p.Id + "&v=" + p.Version); EmailTemplate template = new EmailTemplate(); template.Context = pttc; template.To = p.User.Email; template.Subject = "Changes Requested: " + p.Title; template.TemplateName = "RequestChanges.view"; try { Emailer.Send(template); //Emailer.Send("RequestChanges.view", p.User.Email, "Changes Requested: " + p.Title, pttc); Log.Info("Post Changes Email", p.User.Email + " was sent an email requesting changes"); } catch (Exception ex) { Log.Error("Email Requested Changes Error", ex.Message); } }
public static bool Send(EmailTemplate template) { Events.Instance().ExecuteBeforeEmailSent(template); string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/emails/" + template.TemplateName)); fileText = TemplateEngine.Evaluate(fileText, template.Context); using (MailMessage mm = new MailMessage(template.From ?? SiteSettings.Get().EmailFrom, template.To)) { mm.Subject = template.Subject; mm.IsBodyHtml = template.IsHTML; mm.Body = fileText; mm.Headers.Add("Reply-To", template.ReplyTo ?? template.From ?? SiteSettings.Get().EmailFrom); SendMailMessage(mm); } Events.Instance().ExecuteAfterEmailSent(template); return(true); }
protected override void LoadContent(GraffitiContext graffitiContext) { IsIndexable = false; graffitiContext["where"] = "category"; Category category = new CategoryController().GetCachedCategory(CategoryID, false); if (CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName, category.LinkName)) { RedirectTo(category.Url); } graffitiContext["title"] = category.Name + " : " + SiteSettings.Get().Title; graffitiContext["category"] = category; graffitiContext.RegisterOnRequestDelegate("posts", GetCategoryPosts); // GetCategoryPosts needs to be called so the pager works GetCategoryPosts("posts", graffitiContext); }
/// <summary> /// Returns a query which applies all of the common filters /// </summary> /// <returns></returns> public static Query DefaultQuery(SortOrderType sot) { Query q = Post.CreateQuery(); q.AndWhere(Post.Columns.IsPublished, true); q.AndWhere(Post.Columns.IsDeleted, false); if (SiteSettings.Get().FilterUncategorizedPostsFromLists) { q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId, Comparison.NotEquals); } q.AndWhere(Post.Columns.Published, SiteSettings.CurrentUserTime, Comparison.LessOrEquals); switch (sot) { case SortOrderType.Ascending: q.OrderByAsc(Post.Columns.Published); break; case SortOrderType.Views: q.OrderByDesc(Post.Columns.Views); break; case SortOrderType.Custom: q.OrderByAsc(Post.Columns.SortOrder); break; case SortOrderType.Alphabetical: q.OrderByAsc(Post.Columns.Title); break; default: q.OrderByDesc(Post.Columns.Published); break; } return(q); }
public static bool Send(string templateFile, string emailTo, string subject, PageTemplateToolboxContext cntxt) { string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/emails/" + templateFile)); fileText = TemplateEngine.Evaluate(fileText, cntxt); SiteSettings settings = SiteSettings.Get(); using (MailMessage mm = new MailMessage(settings.EmailFrom, emailTo)) { mm.Subject = subject; mm.IsBodyHtml = true; mm.Body = fileText; SmtpClient client = new SmtpClient(); client.Host = settings.EmailServer; if (settings.EmailServerRequiresAuthentication) { client.Credentials = new NetworkCredential(settings.EmailUser, settings.EmailPassword); } if (settings.EmailRequiresSSL) { client.EnableSsl = true; } if (settings.EmailPort > 0) { client.Port = settings.EmailPort; } client.Send(mm); } return(true); }
public static void Write(string pageTemplateFile, string virtualPath, PageTemplateToolboxContext cntxt) { if (SiteSettings.Get().GenerateFolders) { string fileText = Util.GetFileText(HttpContext.Current.Server.MapPath("~/__utility/pages/" + pageTemplateFile)); //fileText = string.Format(fileText, list.ToArray()); fileText = TemplateEngine.Evaluate(fileText, cntxt); string absPath = HttpContext.Current.Server.MapPath(virtualPath); FileInfo fi = new FileInfo(absPath); if (!fi.Directory.Exists) { fi.Directory.Create(); } using (StreamWriter sw = new StreamWriter(absPath, false)) { sw.WriteLine(fileText); sw.Close(); } } }
protected override void OnLoad(EventArgs e) { Initialize(); SiteSettings settings = SiteSettings.Get(); string baseUrl = SiteSettings.BaseUrl; if (string.IsNullOrEmpty(TagName)) { Category category = null; if (CategoryID > -1) { category = new CategoryController().GetCachedCategory(CategoryID, false); } if (category == null) { if (!string.IsNullOrEmpty(settings.ExternalFeedUrl) && Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1) { Context.Response.RedirectLocation = settings.ExternalFeedUrl; Context.Response.StatusCode = 301; Context.Response.End(); } } else if (!string.IsNullOrEmpty(category.FeedUrlOverride) && Request.UserAgent.IndexOf("FeedBurner", StringComparison.InvariantCultureIgnoreCase) == -1) { Context.Response.RedirectLocation = category.FeedUrlOverride; Context.Response.StatusCode = 301; Context.Response.End(); } else if (CategoryName != null && !Util.AreEqualIgnoreCase(CategoryName, category.LinkName)) { Context.Response.RedirectLocation = new Uri(Context.Request.Url, category.Url).ToString(); Context.Response.StatusCode = 301; Context.Response.End(); } string cacheKey = CategoryID > -1 ? "Posts-Index-" + Util.PageSize + "-" + CategoryID.ToString() : string.Format("Posts-Categories-P:{0}-C:{1}-T:{2}-PS:{3}", 1, CategoryID, SortOrderType.Descending, Util.PageSize); PostCollection pc = ZCache.Get <PostCollection>(cacheKey); if (pc == null) { Query q = PostCollection.DefaultQuery(); q.Top = Util.PageSize.ToString(); if (SiteSettings.Get().IncludeChildPosts&& macros.IsNotNull(category)) { if (category.ParentId > 0) { q.AndWhere(Post.Columns.CategoryId, CategoryID); } else { var ids = new List <int>(category.Children.Count + 1); foreach (Category child in category.Children) { ids.Add(child.Id); } ids.Add(category.Id); q.AndInWhere(Post.Columns.CategoryId, ids.ToArray()); } } else { if (CategoryID > 0) { q.AndWhere(Post.Columns.CategoryId, CategoryID); } } pc = new PostCollection(); pc.LoadAndCloseReader(q.ExecuteReader()); PostCollection permissionsFiltered = new PostCollection(); permissionsFiltered.AddRange(pc); foreach (Post p in pc) { if (!RolePermissionManager.GetPermissions(p.CategoryId, GraffitiUsers.Current).Read) { permissionsFiltered.Remove(p); } } ZCache.InsertCache(cacheKey, permissionsFiltered, 90); pc = permissionsFiltered; } ValidateAndSetHeaders(pc, settings, Context); StringWriter sw = new StringWriter(); sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); XmlTextWriter writer = new XmlTextWriter(sw); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/"); writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/"); // Allow plugins to add additional xml namespaces Core.Events.Instance().ExecuteRssNamespace(writer); writer.WriteStartElement("channel"); WriteChannel(writer, category, settings); // Allow plugins to add additional xml to the <channel> Core.Events.Instance().ExecuteRssChannel(writer); foreach (Post p in pc) { writer.WriteStartElement("item"); WriteItem(writer, p, settings, baseUrl); // Allow plugins to add additional xml to the <item> Core.Events.Instance().ExecuteRssItem(writer, p); writer.WriteEndElement(); // End Item } writer.WriteEndElement(); // End Channel writer.WriteEndElement(); // End Document // save XML into response Context.Response.ContentEncoding = Encoding.UTF8; Context.Response.ContentType = "application/rss+xml"; Context.Response.Write(sw.ToString()); } else { PostCollection pc = GetTaggedPosts(TagName); ValidateAndSetHeaders(pc, settings, Context); StringWriter sw = new StringWriter(); sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); XmlTextWriter writer = new XmlTextWriter(sw); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns:dc", "http://purl.org/dc/elements/1.1/"); writer.WriteAttributeString("xmlns:slash", "http://purl.org/rss/1.0/modules/slash/"); Core.Events.Instance().ExecuteRssNamespace(writer); writer.WriteStartElement("channel"); WriteChannel(writer, TagName, settings); // Allow plugins to add additional xml to the <channel> Core.Events.Instance().ExecuteRssChannel(writer); foreach (Post p in pc) { writer.WriteStartElement("item"); WriteItem(writer, p, settings, baseUrl); Core.Events.Instance().ExecuteRssItem(writer, p); writer.WriteEndElement(); // End Item } writer.WriteEndElement(); // End Channel writer.WriteEndElement(); // End Document Context.Response.ContentEncoding = Encoding.UTF8; Context.Response.ContentType = "application/rss+xml"; Context.Response.Write(sw.ToString()); } }
public EmailTemplateToolboxContext() { Put("date", DateTime.Now); Put("macros", new Macros()); Put("settings", SiteSettings.Get()); }
public bool editPost(string postid, string username, string password, Post post, bool publish) { if (ValidateUser(username, password)) { Graffiti.Core.Post wp = new Graffiti.Core.Post(postid); IGraffitiUser user = GraffitiUsers.Current; if (post.categories != null && post.categories.Length > 0) { wp.CategoryId = AddOrFetchCategory(post.categories[0], user).Id; } wp.Name = post.wp_slug ?? wp.Name; if (!string.IsNullOrEmpty(post.mt_text_more)) { wp.ExtendedBody = post.mt_text_more; } else { wp.ExtendedBody = null; } wp.PostBody = post.description; wp.Title = post.title; wp.PostStatus = (publish ? PostStatus.Publish : PostStatus.Draft); wp.IsPublished = publish; wp.TagList = post.GetTagList() ?? wp.TagList; try { if (post.dateCreated != DateTime.MinValue) { DateTime dtUTC = post.dateCreated; DateTime dtLocal = dtUTC.ToLocalTime(); wp.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet); //wp.Published = post.dateCreated; } } catch { } try { PostRevisionManager.CommitPost(wp, user, SiteSettings.Get().FeaturedId == wp.Id, wp.Category.FeaturedId == wp.Id); return(true); } catch (Exception ex) { if (ex.Message.IndexOf("UNIQUE") > -1) { throw new XmlRpcFaultException(2, "Sorry, but the name of this post is not unqiue and the post was not saved"); } else { Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid, ex.Message, ex.StackTrace); throw; } } } throw new XmlRpcFaultException(0, "User does not exist"); }
public string newPost(string blogid, string username, string password, MetaWeblog.Post post, bool publish) { if (ValidateUser(username, password)) { IGraffitiUser user = GraffitiUsers.Current; Graffiti.Core.Post postToAdd = new Graffiti.Core.Post(); postToAdd.ContentType = "text/html"; postToAdd.PostStatus = (publish ? PostStatus.Publish : PostStatus.Draft); postToAdd.IsPublished = publish; postToAdd.PostBody = post.description; postToAdd.Title = post.title; postToAdd.TagList = post.GetTagList(); postToAdd.UserName = username; postToAdd.EnableComments = CommentSettings.Get().EnableCommentsDefault; if (post.categories != null && post.categories.Length > 0) { postToAdd.CategoryId = AddOrFetchCategory(post.categories[0], user).Id; } else { postToAdd.CategoryId = CategoryController.UnCategorizedId; } postToAdd.Name = post.GetSlug(); if (!string.IsNullOrEmpty(post.mt_text_more)) { postToAdd.ExtendedBody = post.mt_text_more; } // Get UserTime safely (some clients pass in a DateTime that is not valid) try { if (post.dateCreated != DateTime.MinValue) { DateTime dtUTC = post.dateCreated; DateTime dtLocal = dtUTC.ToLocalTime(); postToAdd.Published = dtLocal.AddHours(SiteSettings.Get().TimeZoneOffSet); } } catch { postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet); } if (postToAdd.Published <= new DateTime(2000, 1, 1)) { postToAdd.Published = DateTime.Now.AddHours(SiteSettings.Get().TimeZoneOffSet); } try { return(PostRevisionManager.CommitPost(postToAdd, user, false, false).ToString()); } catch (Exception ex) { if (ex.Message.IndexOf("UNIQUE") > -1) { throw new XmlRpcFaultException(2, "Duplicate Post Name"); } else { Log.Error("MetaBlog Error", "An error occored editing the post {0}. Exception: {1} Stack: {2}", post.postid, ex.Message, ex.StackTrace); throw; } } } throw new XmlRpcFaultException(0, "User does not exist"); }