Ejemplo n.º 1
0
        public Template GetPostTemplate(Core core, Primitive owner)
        {
            Template template = new Template(Assembly.GetExecutingAssembly(), "postblog");
            template.Medium = core.Template.Medium;
            template.SetProse(core.Prose);

            string formSubmitUri = core.Hyperlink.AppendSid(owner.AccountUriStub, true);
            template.Parse("U_ACCOUNT", formSubmitUri);
            template.Parse("S_ACCOUNT", formSubmitUri);

            template.Parse("USER_DISPLAY_NAME", owner.DisplayName);

            Blog blog = null;

            try
            {
                blog = new Blog(core, (User)owner);
            }
            catch (InvalidBlogException)
            {
                if (owner.ItemKey.Equals(core.LoggedInMemberItemKey))
                {
                    blog = Blog.Create(core);
                }
                else
                {
                    return null;
                }
            }

            /* Title TextBox */
            TextBox titleTextBox = new TextBox("title");
            titleTextBox.MaxLength = 127;

            /* Post TextBox */
            TextBox postTextBox = new TextBox("post");
            postTextBox.IsFormatted = true;
            postTextBox.Lines = 15;

            /* Tags TextBox */
            TagSelectBox tagsTextBox = new TagSelectBox(core, "tags");
            //tagsTextBox.MaxLength = 127;

            CheckBox publishToFeedCheckBox = new CheckBox("publish-feed");
            publishToFeedCheckBox.IsChecked = true;

            PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "permissions", blog.ItemKey);
            HiddenField aclModeField = new HiddenField("aclmode");
            aclModeField.Value = "simple";

            template.Parse("S_PERMISSIONS", permissionSelectBox);
            template.Parse("S_ACLMODE", aclModeField);

            DateTime postTime = DateTime.Now;

            SelectBox postYearsSelectBox = new SelectBox("post-year");
            for (int i = DateTime.Now.AddYears(-7).Year; i <= DateTime.Now.Year; i++)
            {
                postYearsSelectBox.Add(new SelectBoxItem(i.ToString(), i.ToString()));
            }

            postYearsSelectBox.SelectedKey = postTime.Year.ToString();

            SelectBox postMonthsSelectBox = new SelectBox("post-month");
            for (int i = 1; i < 13; i++)
            {
                postMonthsSelectBox.Add(new SelectBoxItem(i.ToString(), core.Functions.IntToMonth(i)));
            }

            postMonthsSelectBox.SelectedKey = postTime.Month.ToString();

            SelectBox postDaysSelectBox = new SelectBox("post-day");
            for (int i = 1; i < 32; i++)
            {
                postDaysSelectBox.Add(new SelectBoxItem(i.ToString(), i.ToString()));
            }

            postDaysSelectBox.SelectedKey = postTime.Day.ToString();

            template.Parse("S_POST_YEAR", postYearsSelectBox);
            template.Parse("S_POST_MONTH", postMonthsSelectBox);
            template.Parse("S_POST_DAY", postDaysSelectBox);
            template.Parse("S_POST_HOUR", postTime.Hour.ToString());
            template.Parse("S_POST_MINUTE", postTime.Minute.ToString());

            SelectBox licensesSelectBox = new SelectBox("license");
            System.Data.Common.DbDataReader licensesReader = core.Db.ReaderQuery(ContentLicense.GetSelectQueryStub(core, typeof(ContentLicense)));

            licensesSelectBox.Add(new SelectBoxItem("0", "Default License"));
            while(licensesReader.Read())
            {
                ContentLicense li = new ContentLicense(core, licensesReader);
                licensesSelectBox.Add(new SelectBoxItem(li.Id.ToString(), li.Title));
            }

            licensesReader.Close();
            licensesReader.Dispose();

            SelectBox categoriesSelectBox = new SelectBox("category");
            SelectQuery query = Category.GetSelectQueryStub(core, typeof(Category));
            query.AddSort(SortOrder.Ascending, "category_title");

            System.Data.Common.DbDataReader categoriesReader = core.Db.ReaderQuery(query);

            while (categoriesReader.Read())
            {
                Category cat = new Category(core, categoriesReader);
                categoriesSelectBox.Add(new SelectBoxItem(cat.Id.ToString(), cat.Title));
            }

            categoriesReader.Close();
            categoriesReader.Dispose();

            categoriesSelectBox.SelectedKey = 1.ToString();

            /* Parse the form fields */
            template.Parse("S_TITLE", titleTextBox);
            template.Parse("S_BLOG_TEXT", postTextBox);
            template.Parse("S_TAGS", tagsTextBox);

            template.Parse("S_BLOG_LICENSE", licensesSelectBox);
            template.Parse("S_BLOG_CATEGORY", categoriesSelectBox);

            template.Parse("S_PUBLISH_FEED", publishToFeedCheckBox);

            return template;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Default show procedure for account sub module.
        /// </summary>
        /// <param name="sender">Object calling load event</param>
        /// <param name="e">Load EventArgs</param>
        void AccountBlogWrite_Show(object sender, EventArgs e)
        {
            SetTemplate("account_post");

            VariableCollection javaScriptVariableCollection = core.Template.CreateChild("javascript_list");
            javaScriptVariableCollection.Parse("URI", @"/scripts/jquery.sceditor.bbcode.min.js");

            VariableCollection styleSheetVariableCollection = core.Template.CreateChild("style_sheet_list");
            styleSheetVariableCollection.Parse("URI", @"/styles/jquery.sceditor.theme.default.min.css");

            core.Template.Parse("OWNER_STUB", Owner.UriStubAbsolute);

            Blog blog = new Blog(core, (User)Owner);

            /* Title TextBox */
            TextBox titleTextBox = new TextBox("title");
            titleTextBox.MaxLength = 127;

            /* Post TextBox */
            TextBox postTextBox = new TextBox("post");
            postTextBox.IsFormatted = true;
            postTextBox.Lines = 15;

            /* Tags TextBox */
            TagSelectBox tagsTextBox = new TagSelectBox(core, "tags");
            //tagsTextBox.MaxLength = 127;

            CheckBox publishToFeedCheckBox = new CheckBox("publish-feed");
            publishToFeedCheckBox.IsChecked = true;

            long postId = core.Functions.RequestLong("id", 0);
            byte licenseId = (byte)0;
            short categoryId = (short)1;
            DateTime postTime = core.Tz.Now;

            SelectBox postYearsSelectBox = new SelectBox("post-year");
            for (int i = core.Tz.Now.AddYears(-7).Year; i <= core.Tz.Now.Year; i++)
            {
                postYearsSelectBox.Add(new SelectBoxItem(i.ToString(), i.ToString()));
            }

            postYearsSelectBox.SelectedKey = postTime.Year.ToString();

            SelectBox postMonthsSelectBox = new SelectBox("post-month");
            for (int i = 1; i < 13; i++)
            {
                postMonthsSelectBox.Add(new SelectBoxItem(i.ToString(), core.Functions.IntToMonth(i)));
            }

            postMonthsSelectBox.SelectedKey = postTime.Month.ToString();

            SelectBox postDaysSelectBox = new SelectBox("post-day");
            for (int i = 1; i < 32; i++)
            {
                postDaysSelectBox.Add(new SelectBoxItem(i.ToString(), i.ToString()));
            }

            postDaysSelectBox.SelectedKey = postTime.Day.ToString();

            if (postId > 0 && core.Http.Query["mode"] == "edit")
            {
                try
                {
                    BlogEntry be = new BlogEntry(core, postId);

                    titleTextBox.Value = be.Title;
                    postTextBox.Value = be.Body;

                    licenseId = be.License;
                    categoryId = be.Category;

                    postTime = be.GetPublishedDate(tz);

                    List<Tag> tags = Tag.GetTags(core, be);

                    //string tagList = string.Empty;

                    foreach (Tag tag in tags)
                    {
                        /*if (tagList != string.Empty)
                        {
                            tagList += ", ";
                        }
                        tagList += tag.TagText;*/
                        tagsTextBox.AddTag(tag);
                    }

                    //tagsTextBox.Value = tagList;

                    if (be.OwnerId != core.LoggedInMemberId)
                    {
                        DisplayError("You must be the owner of the blog entry to modify it.");
                        return;
                    }
                }
                catch (InvalidBlogEntryException)
                {
                    DisplayError(core.Prose.GetString("Blog", "BLOG_ENTRY_DOES_NOT_EXIST"));
                    return;
                }
            }
            else
            {
                template.Parse("IS_NEW", "TRUE");

                PermissionGroupSelectBox permissionSelectBox = new PermissionGroupSelectBox(core, "permissions", blog.ItemKey);
                HiddenField aclModeField = new HiddenField("aclmode");
                aclModeField.Value = "simple";

                template.Parse("S_PERMISSIONS", permissionSelectBox);
                template.Parse("S_ACLMODE", aclModeField);
            }

            template.Parse("S_POST_YEAR", postYearsSelectBox);
            template.Parse("S_POST_MONTH", postMonthsSelectBox);
            template.Parse("S_POST_DAY", postDaysSelectBox);
            template.Parse("S_POST_HOUR", postTime.Hour.ToString());
            template.Parse("S_POST_MINUTE", postTime.Minute.ToString());

            SelectBox licensesSelectBox = new SelectBox("license");
            DataTable licensesTable = db.Query(ContentLicense.GetSelectQueryStub(core, typeof(ContentLicense)));

            licensesSelectBox.Add(new SelectBoxItem("0", "Default License"));
            foreach (DataRow licenseRow in licensesTable.Rows)
            {
                ContentLicense li = new ContentLicense(core, licenseRow);
                licensesSelectBox.Add(new SelectBoxItem(li.Id.ToString(), li.Title));
            }

            licensesSelectBox.SelectedKey = licenseId.ToString();

            SelectBox categoriesSelectBox = new SelectBox("category");
            SelectQuery query = Category.GetSelectQueryStub(core, typeof(Category));
            query.AddSort(SortOrder.Ascending, "category_title");

            DataTable categoriesTable = db.Query(query);

            foreach (DataRow categoryRow in categoriesTable.Rows)
            {
                Category cat = new Category(core, categoryRow);
                categoriesSelectBox.Add(new SelectBoxItem(cat.Id.ToString(), cat.Title));
            }

            categoriesSelectBox.SelectedKey = categoryId.ToString();

            /* Parse the form fields */
            template.Parse("S_TITLE", titleTextBox);
            template.Parse("S_BLOG_TEXT", postTextBox);
            template.Parse("S_TAGS", tagsTextBox);

            template.Parse("S_BLOG_LICENSE", licensesSelectBox);
            template.Parse("S_BLOG_CATEGORY", categoriesSelectBox);

            template.Parse("S_PUBLISH_FEED", publishToFeedCheckBox);

            template.Parse("S_ID", postId.ToString());

            foreach (Emoticon emoticon in core.Emoticons)
            {
                if (emoticon.Category == "modifier") continue;
                if (emoticon.Category == "people" && emoticon.Code.Length < 3)
                {
                    VariableCollection emoticonVariableCollection = template.CreateChild("emoticon_list");
                    emoticonVariableCollection.Parse("CODE", emoticon.Code);
                    emoticonVariableCollection.Parse("URI", emoticon.File);
                }
                else
                {
                    VariableCollection emoticonVariableCollection = template.CreateChild("emoticon_hidden_list");
                    emoticonVariableCollection.Parse("CODE", emoticon.Code);
                    emoticonVariableCollection.Parse("URI", emoticon.File);
                }
            }

            Save(new EventHandler(AccountBlogWrite_Save));
            if (core.Http.Form["publish"] != null)
            {
                AccountBlogWrite_Save(this, new EventArgs());
            }
        }
Ejemplo n.º 3
0
        internal static void ShowRegister(object sender, ShowPageEventArgs e)
        {
            e.Template.SetTemplate("Groups", "creategroup.html");

            if (e.Core.Session.IsLoggedIn == false)
            {
                e.Template.Parse("REDIRECT_URI", "/sign-in/?redirect=/groups/register");
                e.Core.Display.ShowMessage("Not Logged In", "You must be logged in to register a new group.");
                return;
            }

            e.Template.Parse("S_POST", e.Core.Hyperlink.AppendSid("/groups/register/", true));

            string selected = "checked=\"checked\" ";
            long category = 1;
            bool categoryError = false;
            bool typeError = false;
            bool categoryFound = true;
            string slug = e.Core.Http.Form["slug"];
            string title = e.Core.Http.Form["title"];

            try
            {
                category = short.Parse(e.Core.Http["category"]);
            }
            catch
            {
                categoryError = true;
            }

            if (string.IsNullOrEmpty(slug))
            {
                slug = title;
            }

            if (!string.IsNullOrEmpty(title))
            {
                // normalise slug if it has been fiddeled with
                slug = slug.ToLower().Normalize(NormalizationForm.FormD);
                string normalisedSlug = "";

                for (int i = 0; i < slug.Length; i++)
                {
                    if (CharUnicodeInfo.GetUnicodeCategory(slug[i]) != UnicodeCategory.NonSpacingMark)
                    {
                        normalisedSlug += slug[i];
                    }
                }
                slug = Regex.Replace(normalisedSlug, @"([\W]+)", "-");
            }

            SelectBox categoriesSelectBox = new SelectBox("category");

            SelectQuery query = Item.GetSelectQueryStub(e.Core, typeof(Category));
            query.AddSort(SortOrder.Ascending, "category_title");

            DataTable categoriesTable = e.Db.Query(query);
            foreach (DataRow categoryRow in categoriesTable.Rows)
            {
                Category cat = new Category(e.Core, categoryRow);

                categoriesSelectBox.Add(new SelectBoxItem(cat.Id.ToString(), cat.Title));

                if (category == cat.Id)
                {
                    categoryFound = true;
                }
            }

            categoriesSelectBox.SelectedKey = category.ToString();

            if (!categoryFound)
            {
                categoryError = true;
            }

            if (e.Core.Http.Form["submit"] == null)
            {
                prepareNewCaptcha(e.Core);

                e.Template.Parse("S_CATEGORIES", categoriesSelectBox);
                e.Template.Parse("S_OPEN_CHECKED", selected);
            }
            else
            {
                // submit the form
                e.Template.Parse("GROUP_TITLE", (string)e.Core.Http.Form["title"]);
                e.Template.Parse("GROUP_NAME_SLUG", slug);
                e.Template.Parse("GROUP_DESCRIPTION", (string)e.Core.Http.Form["description"]);
                e.Template.Parse("S_CATEGORIES", categoriesSelectBox);

                switch ((string)e.Core.Http.Form["type"])
                {
                    case "open":
                        e.Template.Parse("S_OPEN_CHECKED", selected);
                        break;
                    case "request":
                        e.Template.Parse("S_REQUEST_CHECKED", selected);
                        break;
                    case "closed":
                        e.Template.Parse("S_CLOSED_CHECKED", selected);
                        break;
                    case "private":
                        e.Template.Parse("S_PRIVATE_CHECKED", selected);
                        break;
                    default:
                        typeError = true;
                        break;
                }

                DataTable confirmTable = e.Db.Query(string.Format("SELECT confirm_code FROM confirm WHERE confirm_type = 2 AND session_id = '{0}' LIMIT 1",
                    Mysql.Escape(e.Core.Session.SessionId)));

                if (confirmTable.Rows.Count != 1)
                {
                    e.Template.Parse("ERROR", "Captcha is invalid, please try again.");
                    prepareNewCaptcha(e.Core);
                }
                else if (((string)confirmTable.Rows[0]["confirm_code"]).ToLower() != ((string)e.Core.Http.Form["captcha"]).ToLower())
                {
                    e.Template.Parse("ERROR", "Captcha is invalid, please try again.");
                    prepareNewCaptcha(e.Core);
                }
                else if (!UserGroup.CheckGroupNameValid(slug))
                {
                    e.Template.Parse("ERROR", "Group slug is invalid, you may only use letters, numbers, period, underscores or a dash (a-z, 0-9, '_', '-', '.').");
                    prepareNewCaptcha(e.Core);
                }
                else if (!UserGroup.CheckGroupNameUnique(e.Core, slug))
                {
                    e.Template.Parse("ERROR", "Group slug is already taken, please choose another one.");
                    prepareNewCaptcha(e.Core);
                }
                else if (categoryError)
                {
                    e.Template.Parse("ERROR", "Invalid Category selected, you may have to reload the page.");
                    prepareNewCaptcha(e.Core);
                }
                else if (typeError)
                {
                    e.Template.Parse("ERROR", "Invalid group type selected, you may have to reload the page.");
                    prepareNewCaptcha(e.Core);
                }
                else if ((string)e.Core.Http.Form["agree"] != "true")
                {
                    e.Template.Parse("ERROR", "You must accept the " + e.Core.Settings.SiteTitle + " Terms of Service to create a group.");
                    prepareNewCaptcha(e.Core);
                }
                else
                {
                    UserGroup newGroup = null;
                    try
                    {
                        newGroup = UserGroup.Create(e.Core, e.Core.Http.Form["title"], slug, e.Core.Http.Form["description"], category, e.Core.Http.Form["type"]);
                    }
                    catch (InvalidOperationException)
                    {
                        /*Response.Write("InvalidOperationException<br />");
                        Response.Write(e.Db.QueryList);
                        Response.End();*/
                    }
                    catch (InvalidGroupException)
                    {
                        /*Response.Write("InvalidGroupException<br />");
                        Response.Write(e.Db.QueryList);
                        Response.End();*/
                    }

                    if (newGroup == null)
                    {
                        e.Template.Parse("ERROR", "Bad registration details");
                        prepareNewCaptcha(e.Core);
                    }
                    else
                    {
                        // captcha is a use once thing, destroy all for this session
                        e.Db.UpdateQuery(string.Format("DELETE FROM confirm WHERE confirm_type = 2 AND session_id = '{0}'",
                            Mysql.Escape(e.Core.Session.SessionId)));

                        //Response.Redirect("/", true);
                        e.Template.Parse("REDIRECT_URI", newGroup.Uri);
                        e.Core.Display.ShowMessage("Group Created", "You have have created a new group. You will be redirected to the group home page in a second.");
                        return; /* stop processing the display of this page */
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static List<UserGroup> GetUserGroups(Core core, Category category, int page, int perPage)
        {
            List<UserGroup> groups = new List<UserGroup>();

            SelectQuery query = GetSelectQueryStub(core, UserGroupLoadOptions.Common);
            query.AddCondition("group_category", category.Id);
            query.LimitStart = (page - 1) * perPage;
            query.LimitCount = perPage;

            System.Data.Common.DbDataReader groupsReader = core.Db.ReaderQuery(query);

            while (groupsReader.Read())
            {
                groups.Add(new UserGroup(core, groupsReader, UserGroupLoadOptions.Common));
            }

            groupsReader.Close();
            groupsReader.Dispose();

            return groups;
        }
Ejemplo n.º 5
0
 public static List<UserGroup> GetUserGroups(Core core, Category category, int page)
 {
     return GetUserGroups(core, category, page, GROUPS_PER_PAGE);
 }
Ejemplo n.º 6
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;
            }
        }
Ejemplo n.º 7
0
        public static void ShowCategory(object sender, ShowPageEventArgs e)
        {
            e.Template.SetTemplate("Groups", "groups_default");

            string categoryPath = e.Core.PagePathParts[1].Value;

            Category category = null;

            try
            {
                category = new Category(e.Core, categoryPath);
            }
            catch (InvalidCategoryException)
            {
                return;
            }

            e.Template.Parse("CATEGORY_TITLE", category.Title);
            e.Template.Parse("U_CREATE_GROUP_C", e.Core.Hyperlink.AppendSid("/groups/register?category=" + category.Id.ToString()));
            e.Template.Parse("U_CREATE_GROUP", e.Core.Hyperlink.AppendSid("/groups/register?category=" + category.Id.ToString()));

            List<UserGroup> groups = UserGroup.GetUserGroups(e.Core, category, e.Page.TopLevelPageNumber);

            VariableCollection categoriesVariableCollection = e.Template.CreateChild("category_list");

            e.Template.Parse("GROUPS", groups.Count.ToString());

            foreach (UserGroup group in groups)
            {
                VariableCollection groupsVariableCollection = categoriesVariableCollection.CreateChild("group_list");

                groupsVariableCollection.Parse("GROUP_DISPLAY_NAME", group.DisplayName);
                groupsVariableCollection.Parse("U_PROFILE", group.Uri);
                groupsVariableCollection.Parse("ICON", group.Icon);
                groupsVariableCollection.Parse("TILE", group.Tile);
                groupsVariableCollection.Parse("MOBILE_COVER", group.MobileCoverPhoto);

                groupsVariableCollection.Parse("ID", group.Id);
                groupsVariableCollection.Parse("TYPE", group.TypeId);
                e.Core.Display.ParseBbcode(groupsVariableCollection, "DESCRIPTION", group.GroupInfo.Description);
                groupsVariableCollection.Parse("MEMBERS", e.Core.Functions.LargeIntegerToString(group.Members));

                if (e.Core.Session.IsLoggedIn && !group.IsGroupMember(e.Core.LoggedInMemberItemKey))
                {
                    groupsVariableCollection.Parse("U_JOIN", group.JoinUri);
                }
            }

            e.Core.Display.ParsePagination(UserGroup.BuildCategoryUri(e.Core, category), UserGroup.GROUPS_PER_PAGE, category.Groups);

            List<string[]> breadCrumbParts = new List<string[]>();
            breadCrumbParts.Add(new string[] { "groups", e.Core.Prose.GetString("GROUPS") });
            breadCrumbParts.Add(new string[] { category.Path, category.Title });

            e.Page.ParseCoreBreadCrumbs(breadCrumbParts);
        }