Exemple #1
0
        public ItemHashtag(Core core, long itemTagId)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(ItemHashtag_ItemLoad);

            SelectQuery query = ItemHashtag_GetSelectQueryStub(core);
            query.AddCondition("item_hashtag_id", itemTagId);

            DataTable itemTagTable = db.Query(query);

            if (itemTagTable.Rows.Count == 1)
            {
                loadItemInfo(itemTagTable.Rows[0]);
                tag = new Tag(core, itemTagTable.Rows[0]);
            }
            else
            {
                throw new InvalidItemHashtagException();
            }
        }
Exemple #2
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;
            }
        }
Exemple #3
0
 public void AddTag(Tag tag)
 {
     this.tagIds.Add(tag.Id);
 }
Exemple #4
0
        public static ItemHashtag Create(Core core, NumberedItem item, Tag tag)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            Item newItem = Item.Create(core, typeof(ItemHashtag), new FieldValuePair("item_id", item.Id),
                new FieldValuePair("item_type_id", item.ItemKey.TypeId),
                new FieldValuePair("hashtag_id", tag.Id));

            return (ItemHashtag)newItem;
        }
Exemple #5
0
        public static List<long> FormTags(Core core, string name)
        {
            if (core == null)
            {
                throw new NullCoreException();
            }

            List<long> tagIds = new List<long>();

            string formValue = core.Http.Form[name + "-ids"];
            if (!string.IsNullOrEmpty(formValue))
            {
                string[] ids = formValue.Split(new char[] { ',' });

                foreach (string idString in ids)
                {
                    long id;
                    long.TryParse(idString, out id);

                    if (id > 0)
                    {
                        tagIds.Add(id);
                    }
                }
            }

            int limit = 10;
            string tagsText = core.Http.Form[name + "-text"];

            if (!string.IsNullOrEmpty(tagsText))
            {
                string[] tagText = tagsText.Split(new char[] { ',', ';', ' ' });

                foreach (string tag in tagText)
                {
                    if (limit > 0)
                    {
                        string normalisedTag = string.Empty;
                        Tag.NormaliseTag(tag, ref normalisedTag);

                        if (!string.IsNullOrEmpty(normalisedTag) && normalisedTag.Length >= 2)
                        {
                            try
                            {
                                Tag existingTag = new Tag(core, normalisedTag);

                                tagIds.Add(existingTag.Id);
                                limit--;
                            }
                            catch (InvalidTagException)
                            {
                                Tag newTag = Tag.Create(core, tag);

                                tagIds.Add(newTag.Id);
                                limit--;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return tagIds;
        }