/// <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()); } }
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; }