Example #1
0
        public MetaWeblog.Post getPost(string postid, string username, string password)
        {
            if (ValidateUser(username, password))
            {
                VersionStoreCollection vsc = VersionStore.GetVersionHistory(Convert.ToInt32(postid));

                Graffiti.Core.Post p = new Graffiti.Core.Post();

                if (vsc != null && vsc.Count > 0)
                {
                    List <Graffiti.Core.Post> the_Posts = new List <Graffiti.Core.Post>();
                    foreach (VersionStore vs in vsc)
                    {
                        the_Posts.Add(ObjectManager.ConvertToObject <Graffiti.Core.Post>(vs.Data));
                    }

                    the_Posts.Sort(delegate(Graffiti.Core.Post p1, Graffiti.Core.Post p2) { return(Comparer <int> .Default.Compare(p2.Version, p1.Version)); });
                    p = the_Posts[0];
                }
                else
                {
                    p = new Graffiti.Core.Post(postid);
                }

                return(ConvertToPost(p));
            }

            throw new XmlRpcFaultException(0, "User does not exist");
        }
Example #2
0
        public static VersionStoreCollection GetVersionHistory(int postId)
        {
            Query versionQuery = CreateQuery();

            versionQuery.AndWhere(Columns.Type, "post/xml");
            versionQuery.AndWhere(Columns.ItemId, postId);
            versionQuery.OrderByDesc(Columns.Version);

            return(VersionStoreCollection.FetchByQuery(versionQuery));
        }
Example #3
0
        internal static VersionStoreCollection GetVersionHistory(string filePath, bool checkLicensed)
        {
            Query versionQuery = CreateQuery();

            versionQuery.AndWhere(Columns.Name, filePath);
            versionQuery.AndWhere(Columns.Type, Util.GetMapping(filePath));
            versionQuery.OrderByAsc(Columns.Version);

            return(VersionStoreCollection.FetchByQuery(versionQuery));
        }
Example #4
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();
        }
Example #5
0
        private static void RemoveFilesAndFolders(Package p)
        {
            if (p.Files != null)
            {
                foreach (string file in p.Files)
                {
                    string fileName = HttpContext.Current.Server.MapPath(VirtualPathUtility.ToAbsolute("~" + file));

                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }

                    if (File.Exists(fileName + ".old"))
                    {
                        File.Move(fileName + ".old", fileName);
                    }
                    else
                    {
                        VersionStoreCollection vsc = VersionStore.GetVersionHistory(fileName, false);

                        if (vsc != null && vsc.Count > 0)
                        {
                            WriteFile(fileName, vsc[0].Data);

                            VersionStore.Destroy(VersionStore.Columns.UniqueId, vsc[0].UniqueId);
                        }
                    }
                }
            }

            if (p.Directories != null)
            {
                foreach (string dir in p.Directories)
                {
                    if (Directory.Exists(dir) && Directory.GetFiles(dir).Length == 0)
                    {
                        Directory.Delete(dir);
                    }
                }
            }
        }
Example #6
0
        /// <summary>
        /// Renames a user account
        /// </summary>
        public static void RenameUser(string oldUserName, string newUserName)
        {
            if (!controller.CanDeleteUsers)
            {
                throw new Exception("The membership system in use does not support deleting users");
            }

            IGraffitiUser user = GetUser(oldUserName);

            if (user == null)
            {
                throw new Exception("The supplied username does not exist!");
            }

            oldUserName = oldUserName.ToLower();
            newUserName = newUserName.ToLower();
            controller.RenameUser(oldUserName, newUserName);

            // Check if the user has created/modified any content
            PostCollection pc = new PostCollection();
            Query          q  = Post.CreateQuery();

            q.OrWhere(Post.Columns.UserName, oldUserName);
            q.OrWhere(Post.Columns.CreatedBy, oldUserName);
            q.OrWhere(Post.Columns.ModifiedBy, oldUserName);
            pc.LoadAndCloseReader(q.ExecuteReader());

            if (pc != null && pc.Count > 0)
            {
                foreach (Post p in pc)
                {
                    if (p.UserName == oldUserName)
                    {
                        p.UserName = newUserName;
                    }
                    if (p.ModifiedBy == oldUserName)
                    {
                        p.ModifiedBy = newUserName;
                    }
                    if (p.CreatedBy == oldUserName)
                    {
                        p.CreatedBy = newUserName;
                    }

                    p.Save();
                }
            }

            // Check if user has created any comments
            CommentCollection cc = new CommentCollection();

            q = Comment.CreateQuery();
            q.OrWhere(Comment.Columns.UserName, oldUserName);
            q.OrWhere(Comment.Columns.CreatedBy, oldUserName);
            q.OrWhere(Comment.Columns.ModifiedBy, oldUserName);
            cc.LoadAndCloseReader(q.ExecuteReader());

            if (cc != null && cc.Count > 0)
            {
                foreach (Comment c in cc)
                {
                    if (c.UserName == oldUserName)
                    {
                        c.UserName = newUserName;
                    }
                    if (c.ModifiedBy == oldUserName)
                    {
                        c.ModifiedBy = newUserName;
                    }
                    if (c.CreatedBy == oldUserName)
                    {
                        c.CreatedBy = newUserName;
                    }

                    c.Save();
                }
            }

            //Check if the user has created any post versions
            VersionStoreCollection vsc = new VersionStoreCollection();

            vsc = VersionStoreCollection.FetchAll();

            if (vsc != null && vsc.Count > 0)
            {
                foreach (VersionStore v in vsc)
                {
                    Post vp = ObjectManager.ConvertToObject <Graffiti.Core.Post>(v.Data);

                    if (v.CreatedBy == oldUserName)
                    {
                        v.CreatedBy = newUserName;
                    }
                    if (v.Type == "post/xml")
                    {
                        if (vp.UserName == oldUserName)
                        {
                            vp.UserName = newUserName;
                        }
                        if (vp.ModifiedBy == oldUserName)
                        {
                            vp.ModifiedBy = newUserName;
                        }
                        if (vp.CreatedBy == oldUserName)
                        {
                            vp.CreatedBy = newUserName;
                        }
                        v.Data = vp.ToXML();
                    }

                    v.Save();
                }
            }

            ZCache.RemoveCache("user-" + oldUserName);
            // Clear roles cache
            if (user.Roles != null && user.Roles.Length > 0)
            {
                ZCache.RemoveByPattern("usersByRole-");
            }
        }
Example #7
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();");
    }
Example #8
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;
            }
        }
Example #9
0
        /// <summary>
        /// Renames a user account
        /// </summary>
        public static void RenameUser(string oldUserName, string newUserName)
        {
            if (!controller.CanDeleteUsers)
            {
                throw new Exception("The membership system in use does not support deleting users");
            }

            IGraffitiUser user = GetUser(oldUserName);
            if (user == null)
            {
                throw new Exception("The supplied username does not exist!");
            }

            oldUserName = oldUserName.ToLower();
            newUserName = newUserName.ToLower();
            controller.RenameUser(oldUserName, newUserName);

            // Check if the user has created/modified any content
            PostCollection pc = new PostCollection();
            Query q = Post.CreateQuery();
            q.OrWhere(Post.Columns.UserName, oldUserName);
            q.OrWhere(Post.Columns.CreatedBy, oldUserName);
            q.OrWhere(Post.Columns.ModifiedBy, oldUserName);
            pc.LoadAndCloseReader(q.ExecuteReader());

            if (pc != null && pc.Count > 0)
            {
                foreach (Post p in pc)
                {
                    if (p.UserName == oldUserName)
                        p.UserName = newUserName;
                    if (p.ModifiedBy == oldUserName)
                        p.ModifiedBy = newUserName;
                    if (p.CreatedBy == oldUserName)
                        p.CreatedBy = newUserName;

                    p.Save();
                }
            }

            // Check if user has created any comments
            CommentCollection cc = new CommentCollection();
            q = Comment.CreateQuery();
            q.OrWhere(Comment.Columns.UserName, oldUserName);
            q.OrWhere(Comment.Columns.CreatedBy, oldUserName);
            q.OrWhere(Comment.Columns.ModifiedBy, oldUserName);
            cc.LoadAndCloseReader(q.ExecuteReader());

            if (cc != null && cc.Count > 0)
            {
                foreach (Comment c in cc)
                {
                    if (c.UserName == oldUserName)
                        c.UserName = newUserName;
                    if (c.ModifiedBy == oldUserName)
                        c.ModifiedBy = newUserName;
                    if (c.CreatedBy == oldUserName)
                        c.CreatedBy = newUserName;

                    c.Save();
                }
            }

            //Check if the user has created any post versions
            VersionStoreCollection vsc = new VersionStoreCollection();
            vsc = VersionStoreCollection.FetchAll();

            if (vsc != null && vsc.Count > 0)
            {
                foreach (VersionStore v in vsc)
                {
                    Post vp = ObjectManager.ConvertToObject<Graffiti.Core.Post>(v.Data);

                    if (v.CreatedBy == oldUserName)
                        v.CreatedBy = newUserName;
                    if (v.Type == "post/xml")
                    {
                        if (vp.UserName == oldUserName)
                            vp.UserName = newUserName;
                        if (vp.ModifiedBy == oldUserName)
                            vp.ModifiedBy = newUserName;
                        if (vp.CreatedBy == oldUserName)
                            vp.CreatedBy = newUserName;
                        v.Data = vp.ToXML();
                    }

                    v.Save();
                }
            }

            ZCache.RemoveCache("user-" + oldUserName);
            // Clear roles cache
            if (user.Roles != null && user.Roles.Length > 0)
                ZCache.RemoveByPattern("usersByRole-");
        }