/// <summary> /// /// </summary> /// <param name="callName"></param> public override void ExecuteCall(string callName) { switch (callName) { case "get_posts": long userId = core.Functions.RequestLong("id", core.Session.LoggedInMember.Id); int page = Math.Max(core.Functions.RequestInt("page", 1), 1); int perPage = Math.Max(Math.Min(20, core.Functions.RequestInt("per_page", 10)), 1); try { Blog blog = new Blog(core, userId); List<BlogEntry> blogEntries = blog.GetEntries(string.Empty, string.Empty, 0, 0, 0, page, perPage); core.Response.WriteObject(blogEntries); } catch (InvalidBlogException) { } break; case "get_post": long postId = core.Functions.RequestLong("id", 0); if (postId > 0) { BlogEntry entry = new BlogEntry(core, postId); if (entry.Access.Can("VIEW")) { core.Response.WriteObject(entry); } } break; } }
void AccountBlogManage_Show(object sender, EventArgs e) { SetTemplate("account_blog_manage"); Blog myBlog; try { myBlog = new Blog(core, LoggedInMember); } catch (InvalidBlogException) { myBlog = Blog.Create(core); } if (myBlog.Access.Can("POST_ITEMS")) { template.Parse("U_WRITE_NEW_POST", BuildUri("write")); } template.Parse("U_PERMISSIONS", core.Hyperlink.AppendAbsoluteSid(string.Format("/api/acl?id={0}&type={1}", myBlog.Id, ItemType.GetTypeId(core, typeof(Blog))), true)); List<BlogEntry> blogEntries = myBlog.GetEntries(null, null, -1, -1, -1, core.TopLevelPageNumber, 25); foreach (BlogEntry be in blogEntries) { VariableCollection blogVariableCollection = template.CreateChild("blog_list"); DateTime postedTime = be.GetPublishedDate(tz); blogVariableCollection.Parse("COMMENTS", be.Comments.ToString()); blogVariableCollection.Parse("VIEWS", be.Info.ViewedTimes.ToString()); blogVariableCollection.Parse("TITLE", be.Title); blogVariableCollection.Parse("POSTED", tz.DateTimeToString(postedTime)); blogVariableCollection.Parse("U_VIEW", core.Hyperlink.BuildBlogPostUri(LoggedInMember, postedTime.Year, postedTime.Month, be.Id)); blogVariableCollection.Parse("U_EDIT", BuildUri("write", "edit", be.Id)); blogVariableCollection.Parse("U_EDIT_PERMISSIONS", core.Hyperlink.AppendAbsoluteSid(string.Format("/api/acl?id={0}&type={1}", be.Id, ItemType.GetTypeId(core, typeof(BlogEntry))), true)); blogVariableCollection.Parse("U_STATISTICS", core.Hyperlink.AppendAbsoluteSid(string.Format("/api/statistics?mode=item&id={0}&type={1}", be.Id, ItemType.GetTypeId(core, typeof(BlogEntry))), true)); blogVariableCollection.Parse("U_DELETE", BuildUri("write", "delete", be.Id)); } core.Display.ParsePagination(template, BuildUri(), 25, myBlog.Entries); }
/// <summary> /// Show the blog /// </summary> /// <param name="core">Core token</param> /// <param name="page">Page calling</param> /// <param name="category">Category to show</param> /// <param name="post">Post to show</param> /// <param name="year">Year to show</param> /// <param name="month">Month to show</param> /// <remarks>A number of conditions may be omitted. Integer values can be omitted by passing -1. String values by passing a null or empty string.</remarks> private static void Show(Core core, UPage page, string category, string tag, long post, int year, int month) { core.Template.SetTemplate("Blog", "viewblog"); bool rss = false; long comments = 0; string postTitle = null; Blog myBlog; try { myBlog = new Blog(core, page.User); } catch (InvalidBlogException) { return; } if (!myBlog.Access.Can("VIEW")) { core.Functions.Generate403(); return; } try { rss = bool.Parse(core.Http.Query["rss"]); } catch { } /*if (rss) { core.Http.SwitchContextType("text/xml"); }*/ page.User.LoadProfileInfo(); bool moreContent = false; long lastPostId = 0; List<BlogEntry> blogEntries = myBlog.GetEntries(category, tag, post, year, month, page.TopLevelPageNumber, 10, page.TopLevelPageOffset, false, false, out moreContent); if (!rss) { core.Display.ParsePageList(page.User, true); core.Template.Parse("U_PROFILE", page.User.Uri); core.Template.Parse("U_FRIENDS", core.Hyperlink.BuildFriendsUri(page.User)); core.Template.Parse("USER_THUMB", page.Owner.Thumbnail); core.Template.Parse("USER_COVER_PHOTO", page.Owner.CoverPhoto); core.Template.Parse("USER_MOBILE_COVER_PHOTO", page.Owner.MobileCoverPhoto); if (string.IsNullOrEmpty(myBlog.Title)) { core.Template.Parse("PAGE_TITLE", core.Prose.GetString("BLOG")); } else { core.Template.Parse("PAGE_TITLE", myBlog.Title); core.Template.Parse("PAGE_SUB_TITLE", core.Prose.GetString("BLOG")); } core.Template.Parse("BLOG_TITLE", myBlog.Title); if (page.User.UserId == core.LoggedInMemberId) { core.Template.Parse("U_POST", core.Hyperlink.BuildAccountSubModuleUri(myBlog.Owner, "blog", "write")); } } if (!rss) { DataTable archiveTable = core.Db.Query(string.Format("SELECT DISTINCT YEAR(FROM_UNIXTIME(post_time_ut)) as year, MONTH(FROM_UNIXTIME(post_time_ut)) as month FROM blog_postings WHERE user_id = {0} AND post_status = 'PUBLISH' ORDER BY year DESC, month DESC;", page.User.UserId, core.LoggedInMemberId)); core.Template.Parse("ARCHIVES", archiveTable.Rows.Count.ToString()); for (int i = 0; i < archiveTable.Rows.Count; i++) { VariableCollection archiveVariableCollection = core.Template.CreateChild("archive_list"); archiveVariableCollection.Parse("TITLE", string.Format("{0} {1}", core.Functions.IntToMonth((int)archiveTable.Rows[i]["month"]), ((int)archiveTable.Rows[i]["year"]).ToString())); archiveVariableCollection.Parse("URL", Blog.BuildUri(core, page.User, (int)archiveTable.Rows[i]["year"], (int)archiveTable.Rows[i]["month"])); } DataTable categoriesTable = core.Db.Query(string.Format("SELECT DISTINCT post_category, category_title, category_path FROM blog_postings INNER JOIN global_categories ON post_category = category_id WHERE user_id = {0} AND post_status = 'PUBLISH' ORDER BY category_title DESC;", page.User.UserId, core.LoggedInMemberId)); core.Template.Parse("CATEGORIES", categoriesTable.Rows.Count.ToString()); for (int i = 0; i < categoriesTable.Rows.Count; i++) { VariableCollection categoryVariableCollection = core.Template.CreateChild("category_list"); categoryVariableCollection.Parse("TITLE", (string)categoriesTable.Rows[i]["category_title"]); categoryVariableCollection.Parse("URL", Blog.BuildUri(core, page.User, (string)categoriesTable.Rows[i]["category_path"])); } List<BlogRollEntry> blogRollEntries = myBlog.GetBlogRoll(); core.Template.Parse("BLOG_ROLL_ENTRIES", blogRollEntries.Count.ToString()); foreach (BlogRollEntry bre in blogRollEntries) { VariableCollection breVariableCollection = core.Template.CreateChild("blog_roll_list"); if (!string.IsNullOrEmpty(bre.Title)) { breVariableCollection.Parse("TITLE", bre.Title); } else if (bre.User != null) { breVariableCollection.Parse("TITLE", bre.User.DisplayName); } breVariableCollection.Parse("URI", bre.Uri); } } if (!string.IsNullOrEmpty(category)) { core.Template.Parse("U_RSS", core.Hyperlink.BuildBlogRssUri(page.User, category)); } else if (post > 0) { core.Template.Parse("U_RSS", core.Hyperlink.BuildBlogPostRssUri(page.User, year, month, post)); } else if (month > 0) { core.Template.Parse("U_RSS", core.Hyperlink.BuildBlogRssUri(page.User, year, month)); } else if (year > 0) { core.Template.Parse("U_RSS", core.Hyperlink.BuildBlogRssUri(page.User, year)); } else { core.Template.Parse("U_RSS", core.Hyperlink.BuildBlogRssUri(page.User)); } if (rss) { XmlSerializer serializer = new XmlSerializer(typeof(RssDocument)); RssDocument doc = new RssDocument(); doc.version = "2.0"; doc.channels = new RssChannel[1]; doc.channels[0] = new RssChannel(); doc.channels[0].title = string.Format("RSS Feed for {0} blog", page.User.DisplayNameOwnership); doc.channels[0].description = string.Format("RSS Feed for {0} blog", page.User.DisplayNameOwnership); if (!string.IsNullOrEmpty(category)) { doc.channels[0].link = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User, category)); } else if (post > 0) { doc.channels[0].link = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User, year, month, post)); } else if (month > 0) { doc.channels[0].link = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User, year, month)); } else if (year > 0) { doc.channels[0].link = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User, year)); } else { doc.channels[0].link = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User)); } doc.channels[0].category = "Blog"; doc.channels[0].items = new RssDocumentItem[blogEntries.Count]; for (int i = 0; i < blogEntries.Count; i++) { DateTime postDateTime = blogEntries[i].GetPublishedDate(core.Tz); doc.channels[0].items[i] = new RssDocumentItem(); doc.channels[0].items[i].description = core.Bbcode.Parse(HttpUtility.HtmlEncode(blogEntries[i].Body), core.Session.LoggedInMember, page.User); doc.channels[0].items[i].link = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User, postDateTime.Year, postDateTime.Month, blogEntries[i].PostId)); doc.channels[0].items[i].guid = core.Hyperlink.StripSid(Blog.BuildAbsoluteUri(core, page.User, postDateTime.Year, postDateTime.Month, blogEntries[i].PostId)); doc.channels[0].items[i].pubdate = postDateTime.ToString(); if (i == 0) { doc.channels[0].pubdate = postDateTime.ToString(); } } core.Http.WriteXml(serializer, doc); if (core.Db != null) { core.Db.CloseConnection(); } core.Http.End(); } else { int postsOnPage = 0; List<NumberedItem> tagItems = new List<NumberedItem>(); for (int i = 0; i < blogEntries.Count; i++) { tagItems.Add(blogEntries[i]); } Dictionary<ItemKey, List<Tag>> tags = Tag.GetTags(core, tagItems); for (int i = 0; i < blogEntries.Count; i++) { postsOnPage++; VariableCollection blogPostVariableCollection = core.Template.CreateChild("blog_list"); blogPostVariableCollection.Parse("TITLE", blogEntries[i].Title); DateTime postDateTime = blogEntries[i].GetPublishedDate(core.Tz); blogPostVariableCollection.Parse("DATE", core.Tz.DateTimeToString(postDateTime)); blogPostVariableCollection.Parse("URL", blogEntries[i].Uri); blogPostVariableCollection.Parse("ID", blogEntries[i].Id); blogPostVariableCollection.Parse("TYPE_ID", blogEntries[i].ItemKey.TypeId); /*if ((!core.IsMobile) && (!string.IsNullOrEmpty(blogEntries[i].BodyCache))) { core.Display.ParseBbcodeCache(blogPostVariableCollection, "POST", blogEntries[i].BodyCache); } else*/ if (post > 0) { core.Display.ParseBbcode(blogPostVariableCollection, "POST", blogEntries[i].Body, page.User); } else { core.Display.ParseBbcode(blogPostVariableCollection, "POST", blogEntries[i].SummaryString, page.User); } if (core.Session.IsLoggedIn) { if (blogEntries[i].Owner.IsItemOwner(core.Session.LoggedInMember)) { blogPostVariableCollection.Parse("IS_OWNER", "TRUE"); blogPostVariableCollection.Parse("U_DELETE", blogEntries[i].DeleteUri); } } if (blogEntries[i].Info.Likes > 0) { blogPostVariableCollection.Parse("LIKES", string.Format(" {0:d}", blogEntries[i].Info.Likes)); blogPostVariableCollection.Parse("DISLIKES", string.Format(" {0:d}", blogEntries[i].Info.Dislikes)); } if (blogEntries[i].Info.Comments > 0) { blogPostVariableCollection.Parse("POST_COMMENTS", string.Format(" ({0:d})", blogEntries[i].Info.Comments)); } if (blogEntries[i].Access.IsPublic()) { blogPostVariableCollection.Parse("SHAREABLE", "TRUE"); blogPostVariableCollection.Parse("PUBLIC", "TRUE"); } if (blogEntries[i].PostId == post) { comments = blogEntries[i].Comments; core.Template.Parse("BLOG_POST_COMMENTS", core.Functions.LargeIntegerToString(comments)); core.Template.Parse("BLOGPOST_ID", blogEntries[i].PostId.ToString()); } if (tags.ContainsKey(blogEntries[i].ItemKey)) { foreach (Tag t in tags[blogEntries[i].ItemKey]) { VariableCollection tagsVariableCollection = blogPostVariableCollection.CreateChild("tags_list"); tagsVariableCollection.Parse("U_SEARCH", t.Uri); tagsVariableCollection.Parse("TEXT", t.TagText); } } if (post > 0) { postTitle = blogEntries[i].Title; } lastPostId = blogEntries[i].Id; } if (post > 0) { if (postsOnPage != 1) { core.Functions.Generate404(); return; } //if (myBlog.Access.Can("COMMENT_ITEMS")) { if (blogEntries[0].Access.Can("COMMENT")) { core.Template.Parse("CAN_COMMENT", "TRUE"); } } core.Display.DisplayComments(core.Template, page.User, blogEntries[0]); core.Template.Parse("SINGLE", "TRUE"); blogEntries[0].Viewed(core.Session.LoggedInMember); ItemView.LogView(core, blogEntries[0]); page.Core.Meta.Add("twitter:card", "summary"); if (!string.IsNullOrEmpty(page.Core.Settings.TwitterName)) { page.Core.Meta.Add("twitter:site", page.Core.Settings.TwitterName); } if (blogEntries[0].Owner is User && !string.IsNullOrEmpty(((User)blogEntries[0].Owner).UserInfo.TwitterUserName)) { page.Core.Meta.Add("twitter:creator", ((User)blogEntries[0].Owner).UserInfo.TwitterUserName); } page.Core.Meta.Add("twitter:title", blogEntries[0].Title); page.Core.Meta.Add("og:title", blogEntries[0].Title); page.Core.Meta.Add("twitter:description", Functions.TrimStringToWord(HttpUtility.HtmlDecode(page.Core.Bbcode.StripTags(HttpUtility.HtmlEncode(blogEntries[0].Body))).Trim(), 200, true)); page.Core.Meta.Add("og:type", "article"); page.Core.Meta.Add("og:url", page.Core.Hyperlink.StripSid(page.Core.Hyperlink.AppendCurrentSid(blogEntries[0].Uri))); page.Core.Meta.Add("og:description", Functions.TrimStringToWord(HttpUtility.HtmlDecode(page.Core.Bbcode.StripTags(HttpUtility.HtmlEncode(blogEntries[0].Body))).Trim(), 200, true)); List<string> images = core.Bbcode.ExtractImages(blogEntries[0].Body, blogEntries[0].Owner, false, true); if (images.Count > 0) { page.Core.Meta.Add("twitter:image", images[0]); page.Core.Meta.Add("og:image", images[0]); } } core.Template.Parse("BLOGPOSTS", postsOnPage.ToString()); if (Subscription.IsSubscribed(core, page.User.ItemKey)) { core.Template.Parse("SUBSCRIBED", "TRUE"); } core.Template.Parse("U_SUBSCRIBE", core.Hyperlink.BuildSubscribeUri(page.User.ItemKey)); core.Template.Parse("U_UNSUBSCRIBE", core.Hyperlink.BuildUnsubscribeUri(page.User.ItemKey)); core.Template.Parse("SUBSCRIBERS", core.Functions.LargeIntegerToString(page.User.Info.Subscribers)); string pageUri = ""; string breadcrumbExtension = (page.User.UserInfo.ProfileHomepage == "/blog") ? "" : "blog/"; List<string[]> breadCrumbParts = new List<string[]>(); breadCrumbParts.Add(new string[] { "blog", core.Prose.GetString("BLOG") }); if (!string.IsNullOrEmpty(category)) { try { Category cat = new Category(core, category); breadCrumbParts.Add(new string[] { "categories/" + category, cat.Title }); pageUri = Blog.BuildUri(core, page.User, category); } catch (InvalidCategoryException) { core.Functions.Generate404(); return; } } else if (!string.IsNullOrEmpty(tag)) { Tag currentTag = new Tag(core, tag); breadCrumbParts.Add(new string[] { "tag/" + tag, currentTag.TagText }); pageUri = Blog.BuildTagUri(core, page.User, tag); } else { if (year > 0) { breadCrumbParts.Add(new string[] { year.ToString(), year.ToString() }); } if (month > 0) { breadCrumbParts.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) }); } if (post > 0) { breadCrumbParts.Add(new string[] { post.ToString(), postTitle }); } if (post > 0) { pageUri = Blog.BuildUri(core, page.User, year, month, post); } else if (month > 0) { pageUri = Blog.BuildUri(core, page.User, year, month); } else if (year > 0) { pageUri = Blog.BuildUri(core, page.User, year); } else { pageUri = myBlog.Uri; } } page.User.ParseBreadCrumbs(breadCrumbParts); if (post <= 0) { core.Display.ParseBlogPagination(core.Template, "PAGINATION", pageUri, 0, moreContent ? lastPostId : 0); } else { core.Display.ParsePagination(pageUri, 10, comments); } page.CanonicalUri = pageUri; } }