示例#1
0
        public static void Show(Core core, UPage page)
        {
            core.Template.SetTemplate("GuestBook", "viewguestbook");

            page.User.LoadProfileInfo();

            if (!page.User.Access.Can("VIEW"))
            {
                core.Functions.Generate403();
                return;
            }

            /* pages */
            core.Display.ParsePageList(page.Owner, true);

            core.Template.Parse("PAGE_TITLE", string.Format(core.Prose.GetString("USERS_GUEST_BOOK"), page.Owner.DisplayNameOwnership));

            if (core.Session.IsLoggedIn)
            {
                if (page.User.Access.Can("COMMENT"))
                {
                    core.Template.Parse("CAN_COMMENT", "TRUE");
                }
            }

            core.Template.Parse("IS_USER_GUESTBOOK", "TRUE");

            List<string[]> breadCrumbParts = new List<string[]>();
            breadCrumbParts.Add(new string[] { "profile", core.Prose.GetString("PROFILE") });
            breadCrumbParts.Add(new string[] { "comments", core.Prose.GetString("GUEST_BOOK") });

            core.Display.DisplayComments(core.Template, page.User, page.User, UserGuestBookHook);
            core.Display.ParsePagination("COMMENT_PAGINATION", core.Hyperlink.BuildGuestBookUri(page.User), 10, page.User.Comments);
            page.User.ParseBreadCrumbs(breadCrumbParts);
        }
示例#2
0
        // TODO: use user
        public static void Show(Core core, UPage page, string user)
        {
            core.Template.SetTemplate("GuestBook", "viewguestbook");

            page.User.LoadProfileInfo();

            if (!page.User.Access.Can("VIEW"))
            {
                core.Functions.Generate403();
                return;
            }

            /* pages */
            core.Display.ParsePageList(page.Owner, true);

            core.Template.Parse("PAGE_TITLE", string.Format(core.Prose.GetString("USERS_GUEST_BOOK"), page.Owner.DisplayNameOwnership));

            if (core.Session.IsLoggedIn)
            {
                if (page.User.Access.Can("COMMENT"))
                {
                    core.Template.Parse("CAN_COMMENT", "TRUE");
                }
            }

            core.Template.Parse("IS_USER_GUESTBOOK", "TRUE");

            long userId = core.LoadUserProfile(user);

            List<User> commenters = new List<User>();
            commenters.Add(page.User);
            commenters.Add(core.PrimitiveCache[userId]);

            List<string[]> breadCrumbParts = new List<string[]>();
            breadCrumbParts.Add(new string[] { "profile", core.Prose.GetString("PROFILE") });
            breadCrumbParts.Add(new string[] { "comments", core.Prose.GetString("COMMENTS") });
            breadCrumbParts.Add(new string[] {core.PrimitiveCache[userId].Key, core.PrimitiveCache[userId].DisplayName});

            // Load the comment count
            long comments = 0;

            SelectQuery query = new SelectQuery("guestbook_comment_counts");
            query.AddField(new QueryFunction("comment_comments", QueryFunctions.Sum, "comments"));

            QueryCondition qc1 = query.AddCondition("owner_id", commenters[0].Id);
            qc1.AddCondition("user_id", commenters[1].Id);

            QueryCondition qc2 = query.AddCondition(ConditionRelations.Or, "owner_id", commenters[1].Id);
            qc2.AddCondition("user_id", commenters[0].Id);

            DataTable commentCountDataTable = core.Db.Query(query);

            if (commentCountDataTable.Rows.Count > 0)
            {
                if (!(commentCountDataTable.Rows[0]["comments"] is DBNull))
                {
                    comments = (long)(Decimal)commentCountDataTable.Rows[0]["comments"];
                }
            }

            core.Display.DisplayComments(core.Template, page.User, page.User, commenters, comments, UserGuestBookHook);

            core.Display.ParsePagination("COMMENT_PAGINATION", core.Hyperlink.BuildGuestBookUri(page.User, core.PrimitiveCache[userId]), 10, comments);
            page.User.ParseBreadCrumbs(breadCrumbParts);
        }
示例#3
0
 /// <summary>
 /// Gets a list of blog entries made in a year.
 /// </summary>
 /// <param name="page">Page calling</param>
 /// <param name="year">Year to select</param>
 /// /// <param name="month">Month to select</param>
 /// <param name="currentPage">Current page</param>
 /// <param name="perPage">Number to show on each page</param>
 /// <returns>A list of blog entries</returns>
 public List<BlogEntry> GetEntry(UPage page, int year, int month, int currentPage, int perPage)
 {
     return GetEntries(null, null, -1, year, month, currentPage, perPage);
 }
示例#4
0
        /// <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;
            }
        }
示例#5
0
 /// <summary>
 /// Gets a blog entry.
 /// </summary>
 /// <param name="page">Page calling</param>
 /// <param name="post">Post id to get</param>
 /// <returns>A blog entry as a list</returns>
 public List<BlogEntry> GetEntry(UPage page, int post)
 {
     return GetEntries(null, null, post, -1, -1, 1, 1);
 }
示例#6
0
 /// <summary>
 /// Gets a list of blog entries in a category.
 /// </summary>
 /// <param name="page">Page calling</param>
 /// <param name="category">Category to select</param>
 /// <param name="currentPage">Current page</param>
 /// <param name="perPage">Number to show on each page</param>
 /// <returns>A list of blog entries</returns>
 public List<BlogEntry> GetEntry(UPage page, string category, string tag, int currentPage, int perPage)
 {
     return GetEntries(category, tag, -1, -1, -1, currentPage, perPage);
 }
示例#7
0
 /// <summary>
 /// Show the blog entries for a month in a year
 /// </summary>
 /// <param name="core">Core token</param>
 /// <param name="page">Page calling</param>
 /// <param name="year">Year to show</param>
 /// <param name="month">Month to show</param>
 public static void Show(Core core, UPage page, int year, int month)
 {
     Show(core, page, null, null, -1, year, month);
 }
示例#8
0
 /// <summary>
 /// Show the blog entry
 /// </summary>
 /// <param name="core">Core token</param>
 /// <param name="page">Page calling</param>
 /// <param name="post">Post to show</param>
 /// <param name="year">Year to show</param>
 /// <param name="month">Month to show</param>
 public static void Show(Core core, UPage page, long post, int year, int month)
 {
     Show(core, page, null, null, post, year, month);
 }
示例#9
0
 /// <summary>
 /// Show the blog entries for a year
 /// </summary>
 /// <param name="core">Core token</param>
 /// <param name="page">Page calling</param>
 /// <param name="year">Year to show</param>
 public static void Show(Core core, UPage page, int year)
 {
     Show(core, page, null, null, -1, year, -1);
 }
示例#10
0
 /// <summary>
 /// Show the blog category
 /// </summary>
 /// <param name="core">Core token</param>
 /// <param name="page">Page calling</param>
 /// <param name="category">Category to show</param>
 public static void Show(Core core, UPage page, string category)
 {
     Show(core, page, category, null, -1, -1, -1);
 }
示例#11
0
 /// <summary>
 /// Show the blog
 /// </summary>
 /// <param name="core">Core token</param>
 /// <param name="page">Page calling</param>
 public static void Show(Core core, UPage page)
 {
     Show(core, page, null, null, -1, -1, -1);
 }
示例#12
0
 public ShowUPageEventArgs(UPage page)
     : base(page)
 {
 }
示例#13
0
 public ShowUPageEventArgs(UPage page, long itemId)
     : base(page, itemId)
 {
 }