protected void Page_Load(object sender, EventArgs e) { NameValueCollection nvcCustomFields = null; IGraffitiUser user = GraffitiUsers.Current; bool isAdmin = GraffitiUsers.IsAdmin(user); CategoryController cc = new CategoryController(); Category uncategorized = cc.GetCachedCategory(CategoryController.UncategorizedName, false); Post post = null; if (Request.QueryString["id"] != null) { post = new Post(Request.QueryString["id"]); } ProcessCategoryDropdownList(cc, isAdmin, uncategorized); if (!IsPostBack) { ClientScripts.RegisterScriptsForDateTimeSelector(this); Util.CanWriteRedirect(Context); SetDefaultFormValues(isAdmin); if (Request.QueryString["nid"] != null) { post = new Post(Request.QueryString["nid"]); if (post.IsLoaded) { if (isAdmin) { SetMessage("Your post was saved. View: <a href=\"" + post.Url + "\">" + post.Title + "</a>.", StatusType.Success); } else { SetMessage( "Your post was saved. However, since you do not have permission to publish new content, it will need to be approved before it is viewable.", StatusType.Success); } FormWrapper.Visible = false; } } if (post != null) { bool isOriginalPublished = post.IsPublished; int currentVersionNumber = post.Version; VersionStoreCollection vsc = VersionStore.GetVersionHistory(post.Id); if (vsc.Count > 0) { var the_Posts = new List <Post>(); foreach (VersionStore vs in vsc) { the_Posts.Add(ObjectManager.ConvertToObject <Post>(vs.Data)); } the_Posts.Add(post); the_Posts.Sort(delegate(Post p1, Post p2) { return(Comparer <int> .Default.Compare(p2.Version, p1.Version)); }); string versionHtml = "<div style=\"width: 280px; overflow: hidden; padding: 6px 0; border-bottom: 1px solid #ccc;\"><b>Revision {0}</b> ({1})<div>by {2}</div><div style=\"font-style: italic;\">{3}</div></div>"; string versionText = "Revision {0}"; foreach (Post px in the_Posts) { VersionHistory.Items.Add( new DropDownListItem( string.Format(versionHtml, px.Version, px.ModifiedOn.ToString("dd-MMM-yyyy"), GraffitiUsers.GetUser(px.ModifiedBy).ProperName, px.Notes), string.Format(versionText, px.Version), px.Version.ToString())); } int versionToEdit = Int32.Parse(Request.QueryString["v"] ?? "-1"); if (versionToEdit > -1) { foreach (Post px in the_Posts) { if (px.Version == versionToEdit) { post = px; // add logic to change category if it was deleted here CategoryCollection cats = new CategoryController().GetCachedCategories(); Category temp = cats.Find( delegate(Category c) { return(c.Id == post.CategoryId); }); if (temp == null && post.CategoryId != 1) { post.CategoryId = uncategorized.Id; SetMessage( "The category ID on this post revision could not be located. It has been marked as Uncategorized. ", StatusType.Warning); } break; } } } else { post = the_Posts[0]; } VersionHistoryArea.Visible = true; VersionHistory.SelectedValue = post.Version.ToString(); VersionHistory.Attributes["onchange"] = "window.location = '" + VirtualPathUtility.ToAbsolute("~/graffiti-admin/posts/write/") + "?id=" + Request.QueryString["id"] + "&v=' + this.options[this.selectedIndex].value;"; } if (post.Id > 0) { nvcCustomFields = post.CustomFields(); txtTitle.Text = Server.HtmlDecode(post.Title); txtContent.Text = post.PostBody; txtContent_extend.Text = post.ExtendedBody; txtTags.Text = post.TagList; txtName.Text = Util.UnCleanForUrl(post.Name); EnableComments.Checked = post.EnableComments; PublishDate.DateTime = post.Published; txtNotes.Text = post.Notes; postImage.Text = post.ImageUrl; FeaturedSite.Checked = (post.Id == SiteSettings.Get().FeaturedId); FeaturedCategory.Checked = (post.Id == post.Category.FeaturedId); txtKeywords.Text = Server.HtmlDecode(post.MetaKeywords ?? string.Empty); txtMetaScription.Text = Server.HtmlDecode(post.MetaDescription ?? string.Empty); HomeSortOverride.Checked = post.IsHome; ListItem li = CategoryList.Items.FindByValue(post.CategoryId.ToString()); if (li != null) { CategoryList.SelectedIndex = CategoryList.Items.IndexOf(li); } else { CategoryList.SelectedIndex = CategoryList.Items.IndexOf(CategoryList.Items.FindByValue(uncategorized.Id.ToString())); } li = PublishStatus.Items.FindByValue(post.Status.ToString()); if (li != null && post.Status != (int)PostStatus.PendingApproval && post.Status != (int)PostStatus.RequiresChanges) { PublishStatus.SelectedIndex = PublishStatus.Items.IndexOf(li); } else if (post.Status == (int)PostStatus.PendingApproval || post.Status == (int)PostStatus.RequiresChanges) { // turn published on if it is in req changes ListItem li2 = PublishStatus.Items.FindByValue(Convert.ToString((int)PostStatus.Publish)); if (li2 != null) { PublishStatus.SelectedIndex = PublishStatus.Items.IndexOf(li2); } } if (post.Version != currentVersionNumber && !isOriginalPublished) { SetMessage("You are editing an unpublished revision of this post.", StatusType.Warning); } else if (post.Version != currentVersionNumber && isOriginalPublished) { SetMessage( "The post your are editing has been published. However, the revision you are editing has not been published.", StatusType.Warning); } else if (!isOriginalPublished) { SetMessage("You are editing an unpublished revision of this post.", StatusType.Warning); } } else { FormWrapper.Visible = false; SetMessage("The post with the id " + Request.QueryString["id"] + " could not be found.", StatusType.Warning); } } else { ListItem liUncat = CategoryList.Items.FindByText(CategoryController.UncategorizedName); if (liUncat != null) { CategoryList.SelectedIndex = CategoryList.Items.IndexOf(liUncat); } } } if (FormWrapper.Visible) { NavigationConfirmation.RegisterPage(this); NavigationConfirmation.RegisterControlForCancel(Publish_Button); Page.ClientScript.RegisterStartupScript(GetType(), "Writer-Page-StartUp", "$(document).ready(function() { var eBody = $('#extended_body')[0]; " + (!string.IsNullOrEmpty(txtContent_extend.Text) ? "eBody.style.position = 'static'; eBody.style.visibility = 'visible';" : "eBody.style.position = 'absolute'; eBody.style.visibility = 'hidden';") + "categoryChanged($('#" + CategoryList.ClientID + "')[0]); Publish_Status_Change();});", true); Page.ClientScript.RegisterHiddenField("dateChangeFlag", "false"); } CustomFormSettings cfs = CustomFormSettings.Get(int.Parse(CategoryList.SelectedItem.Value)); if (cfs.HasFields) { if (nvcCustomFields == null) { nvcCustomFields = new NameValueCollection(); foreach (CustomField cf in cfs.Fields) { if (Request.Form[cf.Id.ToString()] != null) { nvcCustomFields[cf.Name] = Request.Form[cf.Id.ToString()]; } } } bool isNewPost = (post != null) && (post.Id < 1); the_CustomFields.Text = cfs.GetHtmlForm(nvcCustomFields, isNewPost); } else { CustomFieldsTab.Tab.Enabled = false; the_CustomFields.Text = ""; } PublishStatus.Attributes.Add("onchange", "Publish_Status_Change();"); }
private void SetVersioning(string fileName) { // set up versioning VersionStoreCollection vsc = VersionStore.GetVersionHistory(fileName); if (vsc.Count > 1) { VersionHistoryArea.Visible = true; string versionHtml = "<div style=\"width: 280px; overflow: hidden; padding: 6px 0; border-bottom: 1px solid #ccc;\"><b>Revision {0}</b> ({1})<div>by {2}</div><div style=\"font-style: italic;\"></div></div>"; string versionText = "Revision {0}"; foreach (VersionStore vs in vsc) { VersionHistory.Items.Add( new DropDownListItem( string.Format(versionHtml, vs.Version, vs.CreatedOn, vs.CreatedBy), string.Format(versionText, vs.Version), vs.Version.ToString())); } VersionHistory.Attributes["onchange"] = "window.location = '" + ResolveUrl( "~/graffiti-admin/site-options/utilities/FileBrowser.aspx") + "?path=" + Server.UrlEncode(Request.QueryString["path"]) + "&f=" + Server.UrlEncode(Request.QueryString["f"]) + "&edit=true" + "&v=' + this.options[this.selectedIndex].value;"; VersionStore selected; if (!String.IsNullOrEmpty(Request.QueryString["v"])) { if (!String.IsNullOrEmpty(version)) { selected = vsc.Find( delegate(VersionStore vs) { return(vs.Version.ToString() == version); }); } else { selected = vsc.Find( delegate(VersionStore vs) { return(vs.Version.ToString() == Request.QueryString["v"]); }); } } else { selected = vsc[vsc.Count - 1]; } if (selected != null) { VersionHistory.SelectedValue = selected.Version.ToString(); EditBox.Text = selected.Data; if (selected.Version < vsc[vsc.Count - 1].Version) { EditMessage.Text = "You are editing a previous version of this file. If you click <b>Save Changes</b>, a new version of this file (revision " + (vsc.Count + 1) + ") will be created."; EditMessage.Type = StatusType.Warning; } } } else { VersionHistoryArea.Visible = false; } }