Ejemplo n.º 1
0
        private void GetPostsForRevision(XmlTextWriter writer)
        {
            string v = Request.QueryString["revision"];
            string p = Request.QueryString["id"];

            if (string.IsNullOrEmpty(p))
            {
                throw new RESTConflict("The Post Id (id) querystring value is missing");
            }

            int postid = Int32.Parse(p);

            int version = (Int32.Parse(v ?? "-1"));

            Query q = VersionStore.CreateQuery();

            q.AndWhere(VersionStore.Columns.ItemId, postid);
            q.AndWhere(VersionStore.Columns.Type, "post/xml");
            if (version > 0)
            {
                q.AndWhere(VersionStore.Columns.Version, version);
            }

            VersionStoreCollection vsc   = VersionStoreCollection.FetchByQuery(q);
            PostCollection         posts = new PostCollection();

            posts.Add(new Post(postid));

            foreach (VersionStore vs in vsc)
            {
                posts.Add(ObjectManager.ConvertToObject <Post>(vs.Data));
            }

            posts.Sort(delegate(Post p1, Post p2) { return(Comparer <int> .Default.Compare(p2.Version, p1.Version)); });

            writer.WriteStartElement("posts");
            writer.WriteAttributeString("pageIndex", "1");
            writer.WriteAttributeString("pageSize", posts.Count.ToString());
            writer.WriteAttributeString("totalPosts", posts.Count.ToString());
            foreach (Post post in posts)
            {
                if (version <= 0 || post.Version == version)
                {
                    ConvertPostToXML(post, writer);
                }
            }

            writer.WriteEndElement();
        }
Ejemplo n.º 2
0
        private void SetFileDetails(FileInfo fi)
        {
            FileViews.SetActiveView(FileDetails);

            FileDetailsLastModified.Text = fi.LastWriteTime.ToLongDateString() + " " +
                                           fi.LastWriteTime.ToShortTimeString();
            if (FileFilters.IsLinkable(fi.Name))
            {
                FileDetailsName.Text        = fi.Name;
                FileDetailsName.NavigateUrl = "~/" + (Request.QueryString["path"] ?? "") + "/" + fi.Name;
            }
            else
            {
                FileDetailsName.Visible = false;
                FileDetailsText.Text    = fi.Name;
            }

            DownloadButton.Visible = FileFilters.IsDownloadable(fi.Name);
            EditButton.Visible     = FileFilters.IsEditable(fi.Name);
            DeleteButton.Visible   = FileFilters.IsDeletable(fi.Name);

            if (fi.Extension == ".dll")
            {
                Assembly assembly = Assembly.LoadFile(fi.FullName);
                FileDetailsAssemblyVersion.Text = assembly.GetName().Version.ToString();
            }
            else
            {
                assemblyLI.Visible = false;
            }

            if (FileFilters.IsVersionable(fi.Name))
            {
                FileDetailsRevision.Text = (VersionStore.CurrentVersion(fi) == 0 ? 1 : VersionStore.CurrentVersion(fi)).ToString();
            }
            else
            {
                FileDetailsRevision.Text = "n.a.";
                revsionLI.Visible        = false;
            }

            FileDetailsSize.Text = fi.Length.ToString("0,0") + " kB";
        }
Ejemplo n.º 3
0
        protected void SaveFile_Click(object sender, EventArgs e)
        {
            FileInfo fi = GetFile();

            if (FileFilters.IsEditable(fi.Name) && FileFilters.IsValidFile(fi.Name))
            {
                try
                {
                    bool isversioned = FileFilters.IsVersionable(fi.Name);

                    if (isversioned && VersionStore.CurrentVersion(fi) == 0)
                    {
                        VersionStore.VersionFile(fi);
                    }

                    using (StreamWriter sw = new StreamWriter(fi.FullName, false))
                    {
                        sw.Write(EditBox.Text);
                        sw.Close();
                    }

                    if (isversioned)
                    {
                        fi = GetFile();
                        VersionStore.VersionFile(fi);

                        version = VersionStore.CurrentVersion(fi).ToString();

                        SetVersioning(fi.FullName);
                    }

                    EditMessage.Text = "<strong>" + fi.Name + "</strong> was successfully updated.";
                    EditMessage.Type = StatusType.Success;
                }
                catch (Exception ex)
                {
                    EditMessage.Text = "Your file could not be updated. \n\n Reason: " + ex.Message;
                    EditMessage.Type = StatusType.Error;
                }
            }
        }
Ejemplo n.º 4
0
 public EntitiesController(VersionStore versionStore, Database db)
 {
     _versionStore = versionStore;
     _db           = db;
 }
Ejemplo n.º 5
0
    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();");
    }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
 public VersionRebuild(Database db, VersionStore store)
 {
     _db    = db;
     _store = store;
 }