protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (!Page.Request.Browser.IsBrowser("IE") || Page.Request.Browser.IsBrowser("Safari") || Page.Request.Browser.IsBrowser("Opera") || Page.Request.Browser.IsBrowser("Gecko"))
            {
                IGraffitiUser user = GraffitiUsers.Current;
                if (user.UniqueId == Guid.Empty)
                {
                    GraffitiUsers.Save(user, user.Name);
                    user = GraffitiUsers.GetUser(user.Name, true);
                }

                Files.UploadUrlQueryString = "Username="******"&Ticket=" + Server.UrlEncode(user.UniqueId.ToString());
            }
        }
Ejemplo n.º 2
0
        public override void ProcessRequest(HttpContext context)
        {
            if (context.Request.QueryString["Username"] != null && context.Request.QueryString["Ticket"] != null)
            {
                IGraffitiUser user = GraffitiUsers.GetUser(context.Request.QueryString["Username"], true);
                if (user == null || user.UniqueId.ToString() != context.Request.QueryString["Ticket"] || user.UniqueId == Guid.Empty)
                {
                    throw new InvalidOperationException("The upload form can only be used by users who are logged in");
                }
            }
            else
            {
                IGraffitiUser user = GraffitiUsers.Current;
                if (user == null)
                {
                    throw new InvalidOperationException("The upload form can only be used by users who are logged in");
                }
            }

            base.ProcessRequest(context);
        }
Ejemplo n.º 3
0
        private static string CreateUpdatePost(XmlDocument doc, IGraffitiUser user)
        {
            Post         post            = null;
            XmlAttribute postidAttribute = doc.SelectSingleNode("/post").Attributes["id"];

            if (postidAttribute == null)
            {
                post = new Post();
            }
            else
            {
                int pid = Int32.Parse(postidAttribute.Value);
                if (pid > 0)
                {
                    post = new Post(pid);
                }
                else
                {
                    post = new Post();
                }
            }
            XmlNode node = doc.SelectSingleNode("/post");



            if (GraffitiUsers.IsUserInRole(user.Name, GraffitiUsers.AdminRole))
            {
                XmlNode usernameNode = node.SelectSingleNode("author");
                if (usernameNode != null && !string.IsNullOrEmpty(usernameNode.Value))
                {
                    post.UserName = GraffitiUsers.GetUser(usernameNode.Value).Name;
                }
            }

            if (string.IsNullOrEmpty(post.UserName) && post.IsNew)
            {
                post.UserName = user.Name;
            }


            post.PostBody = GetNodeValue(node.SelectSingleNode("postBody"), null);
            if (string.IsNullOrEmpty(post.PostBody))
            {
                throw new RESTConflict("The Post body element is missing and is required");
            }


            post.CategoryId = GetNodeValue(node.SelectSingleNode("categoryId"), -1);
            if (post.CategoryId <= 0)
            {
                throw new RESTConflict("The category element is missing (or has an invalid value) and is required");
            }

            post.Title = GetNodeValue(node.SelectSingleNode("title"), null);
            if (string.IsNullOrEmpty(post.Title))
            {
                throw new RESTConflict("The title element is missing and is required");
            }

            post.ExtendedBody = GetNodeValue(node.SelectSingleNode("extendedBody"), null);

            XmlNode publishedDateNode = node.SelectSingleNode("publishedDate");

            if (publishedDateNode != null && !string.IsNullOrEmpty(publishedDateNode.InnerText) &&
                DateTime.Parse(publishedDateNode.InnerText) > new DateTime(2000, 1, 1))
            {
                post.Published = DateTime.Parse(publishedDateNode.InnerText);
            }
            else if (post.IsNew)
            {
                post.Published = SiteSettings.CurrentUserTime;
            }

            post.Name = GetNodeValue(node.SelectSingleNode("name"), post.Name);


            post.Status = GetNodeValue(node.SelectSingleNode("status"), post.IsNew ? (int)PostStatus.Draft : post.Status);

            post.TagList = GetNodeValue(node.SelectSingleNode("tags"), null);

            post.ContentType = GetNodeValue(node.SelectSingleNode("contenttype"), null);

            post.SortOrder = GetNodeValue(node.SelectSingleNode("sortOrder"), post.SortOrder);

            post.HomeSortOrder = GetNodeValue(node.SelectSingleNode("homeSortOrder"), post.HomeSortOrder);

            post.MetaDescription = GetNodeValue(node.SelectSingleNode("metaDescription"), post.MetaDescription);
            post.MetaKeywords    = GetNodeValue(node.SelectSingleNode("metaKeywords"), post.MetaKeywords);
            post.IsHome          = GetNodeValue(node.SelectSingleNode("isHome"), post.IsHome);
            post.EnableComments  = GetNodeValue(node.SelectSingleNode("enableComments"), post.EnableComments);

            XmlNodeList customFields = node.SelectNodes("customFields/customField");

            foreach (XmlNode cNode in customFields)
            {
                post[cNode.Attributes["key"].Value] = cNode.InnerText;
            }

            Permission perm = RolePermissionManager.GetPermissions(post.CategoryId, user);

            if (GraffitiUsers.IsAdmin(user) || perm.Publish)
            {
                post.IsDeleted = GetNodeValue(node.SelectSingleNode("isDeleted"), post.IsDeleted);
            }

            int id =
                PostRevisionManager.CommitPost(post, user, SiteSettings.Get().FeaturedId == post.Id,
                                               post.Category.FeaturedId == post.Id);

            return(string.Format("<result id=\"{0}\">true</result>", id));
        }
Ejemplo n.º 4
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.º 5
0
    protected void EditPerson_Click(object sender, EventArgs e)
    {
        try
        {
            IGraffitiUser currentUser = GraffitiUsers.Current;
            IGraffitiUser user        = GraffitiUsers.GetUser(Request.QueryString["user"]);
            bool          isAdmin     = GraffitiUsers.IsAdmin(currentUser);

            if (!isAdmin && user.Name != currentUser.Name)
            {
                throw new SecurityException("You do not have permission to edit this user");
            }

            user.ProperName = Server.HtmlEncode(txtProperName.Text.Trim());
            user.Bio        = Editor.Text.Trim();
            user.Email      = txtExistingEmail.Text.Trim();

            if (!string.IsNullOrEmpty(txtWebsite.Text.Trim()))
            {
                user.WebSite = Server.HtmlEncode(txtWebsite.Text.Trim());
            }
            else
            {
                user.WebSite = null;
            }

            if (!string.IsNullOrEmpty(txtAvatar.Text.Trim()))
            {
                user.Avatar = Server.HtmlEncode(txtAvatar.Text.Trim());
            }
            else
            {
                user.Avatar = null;
            }

            if (isAdmin)
            {
                foreach (string role in user.Roles)
                {
                    GraffitiUsers.RemoveUserFromRole(user.Name, role);
                }

                GraffitiUsers.AddUserToRole(user.Name, GraffitiUsers.EveryoneRole);

                if (chkAdmin.Checked == true)
                {
                    GraffitiUsers.AddUserToRole(user.Name, GraffitiUsers.AdminRole);
                }

                foreach (DataListItem dli in Roles.Items)
                {
                    CheckBox role = dli.FindControl("role") as CheckBox;

                    if (role.Checked)
                    {
                        GraffitiUsers.AddUserToRole(user.Name, role.Text);
                    }
                }
            }

            GraffitiUsers.Save(user, GraffitiUsers.Current.Name);

            Message.Text = "The user <strong>" + user.ProperName + "</strong> was updated.";
            Message.Type = StatusType.Success;
        }
        catch (Exception ex)
        {
            string exMessage = ex.Message;
            if (!string.IsNullOrEmpty(exMessage) && exMessage.IndexOf("UNIQUE") > -1)
            {
                exMessage = "This username (or email) already exists.";
            }

            Message.Text = "A user with the name of " + txtExistingUserName.Text + " could not be updated.<br />" +
                           exMessage;
            Message.Type = StatusType.Error;
        }
    }
Ejemplo n.º 6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        LiHyperLink.SetNameToCompare(Context, "UserManagement");

        IGraffitiUser currentUser = GraffitiUsers.Current;


        if (Request.QueryString["user"] != null)
        {
            if (!IsPostBack)
            {
                user = GraffitiUsers.GetUser(Request.QueryString["user"]);


                if (user == null)
                {
                    throw new Exception("This user does not exist or cannot be edited.");
                }

                if (!GraffitiUsers.IsAdmin(currentUser) && user.Name != currentUser.Name)
                {
                    throw new SecurityException("You do not have permission to edit this user");
                }


                if (Request.QueryString["new"] != null && !IsPostBack)
                {
                    Message.Text = "The user <strong>" + user.Name + "</strong> was created.";
                    Message.Type = StatusType.Success;
                }
                PageText.Text            = "Update " + user.ProperName + "'s profile.";
                AdminUserLinks.Visible   = true;
                PasswordLink.NavigateUrl = string.Format("~/graffiti-admin/user-management/users/changepassword.aspx?user={0}", Request.QueryString["user"]);
                if (GraffitiUsers.CanRenameUsers && GraffitiUsers.IsAdmin(GraffitiUsers.Current))
                {
                    AdminUserLinksDelim.Visible = true;
                    RenameLink.Visible          = true;
                    RenameLink.NavigateUrl      = string.Format("javascript:Telligent_Modal.Open('RenameUser.aspx?user={0}', 400, 200, null);", Request.QueryString["user"]);
                }
                txtExistingUserName.Text = Server.HtmlDecode(user.Name);
                txtProperName.Text       = Server.HtmlDecode(user.ProperName);
                txtExistingEmail.Text    = user.Email;
                txtAvatar.Text           = user.Avatar;
                Editor.Text     = user.Bio;
                txtWebsite.Text = string.IsNullOrEmpty(user.WebSite)
                                                                                         ? new Macros().FullUrl(new Urls().Home)
                                                                                         : Server.HtmlEncode(user.WebSite);

                bool isAdmin = GraffitiUsers.IsUserInRole(GraffitiUsers.Current.Name, GraffitiUsers.AdminRole);

                role_section.Visible = isAdmin;
                AllRoles.Visible     = isAdmin;

                if (!isAdmin)
                {
                    Cancel_Edit.NavigateUrl = "~/graffiti-admin/";
                }

                if (isAdmin)
                {
                    RolePermissionsCollection rp = RolePermissionManager.GetRolePermissions();

                    RolePermissionsCollection newrp = new RolePermissionsCollection();
                    newrp.AddRange(rp);

                    RolePermissions temp = newrp.Find(delegate(RolePermissions r)
                    {
                        return(r.RoleName == GraffitiUsers.EveryoneRole);
                    });

                    if (temp != null)
                    {
                        newrp.Remove(temp);
                    }

                    newrp.Sort(delegate(RolePermissions rp1, RolePermissions rp2)
                    {
                        return(Comparer <string> .Default.Compare(rp1.RoleName, rp2.RoleName));
                    });

                    Roles.DataSource = newrp;
                    Roles.DataBind();

                    foreach (string role in user.Roles)
                    {
                        if (role == GraffitiUsers.AdminRole)
                        {
                            chkAdmin.Checked = true;

                            if (GraffitiUsers.Current.Name == user.Name)
                            {
                                chkAdmin.Enabled = false;
                            }
                        }
                    }
                }
            }

            new_user_container.Visible = false;
            User_List.Visible          = false;
            user_edit_form.Visible     = true;
        }
        else
        {
            if (!GraffitiUsers.IsUserInRole(currentUser.Name, GraffitiUsers.AdminRole))
            {
                Response.Redirect("?user="******"*");

            User_List.DataSource = users;
            User_List.DataBind();

            // filter out everyone if they are not a content publisher for licensing
            List <IGraffitiUser> filteredUsers = new List <IGraffitiUser>();
            filteredUsers.AddRange(users);

            bool isEveryonePublisher = RolePermissionManager.IsEveryoneAContentPublisher();

            if (!isEveryonePublisher)
            {
                foreach (IGraffitiUser user in users)
                {
                    if (user.Roles != null && user.Roles[0] == GraffitiUsers.EveryoneRole)
                    {
                        filteredUsers.Remove(user);
                    }
                }
            }
        }
    }