Exemple #1
0
        /// <summary>
        /// Deletes a user, and reassigns any content created by that user to another existing user
        /// </summary>
        public static bool DeleteUser(IGraffitiUser user, IGraffitiUser userToAssumeContent, out string errorMessage)
        {
            if (!controller.CanDeleteUsers)
            {
                errorMessage = "The membership system in use does not support deleting users.";
                return(false);
            }
            if (user == null)
            {
                throw new Exception("The supplied user object is null and cannot be deleted");
            }

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

            q.AndWhere(Post.Columns.UserName, user.Name);
            pc.LoadAndCloseReader(q.ExecuteReader());

            if (pc != null && pc.Count > 0)
            {
                if (userToAssumeContent == null)
                {
                    errorMessage = "The user you are trying to delete has created posts. Another existing user must be selected to assign these posts to.";
                    return(false);
                }
                foreach (Post p in pc)
                {
                    if (p.UserName == user.Name)
                    {
                        p.UserName = userToAssumeContent.Name;
                    }
                    if (p.ModifiedBy == user.Name)
                    {
                        p.ModifiedBy = userToAssumeContent.Name;
                    }
                    if (p.CreatedBy == user.Name)
                    {
                        p.CreatedBy = userToAssumeContent.Name;
                    }
                }
            }

            // Remove from roles
            if (user.Roles != null && user.Roles.Length > 0)
            {
                foreach (string roleName in user.Roles)
                {
                    controller.RemoveUserFromRole(user.Name, roleName);
                }
                ZCache.RemoveByPattern("usersByRole-");
            }

            controller.DeleteUser(user);

            ZCache.RemoveCache("user-" + user.Name.ToLower());

            errorMessage = string.Empty;
            return(true);
        }
Exemple #2
0
        /// <summary>
        ///     Writes empty pages to disk.
        /// </summary>
        public void WritePages()
        {
            PageTemplateToolboxContext templateContext = new PageTemplateToolboxContext();

            templateContext.Put("CategoryId", Id);
            templateContext.Put("CategoryName", LinkName);
            templateContext.Put("MetaDescription",
                                !string.IsNullOrEmpty(MetaDescription)
                                                                        ? MetaDescription
                                                                        : HttpUtility.HtmlEncode(Util.RemoveHtml(Body, 255) ?? string.Empty));

            templateContext.Put("MetaKeywords",
                                !string.IsNullOrEmpty(MetaKeywords)
                                                                        ? MetaKeywords
                                                                        : Name);


            if (!IsUncategorized)
            {
                PageWriter.Write("category.view", "~/" + LinkName + "/" + Util.DEFAULT_PAGE, templateContext);
                PageWriter.Write("categoryrss.view", "~/" + LinkName + "/feed/" + Util.DEFAULT_PAGE, templateContext);
            }

            if (__initialCategoryName != null && __initialCategoryName != LinkName)
            {
                PostCollection pc        = new PostCollection();
                Query          postQuery = Post.CreateQuery();
                postQuery.AndWhere(Post.Columns.CategoryId, Id);
                pc.LoadAndCloseReader(postQuery.ExecuteReader());
                foreach (Post p in pc)
                {
                    p.Save();
                }
            }
        }
Exemple #3
0
        public static Query HomeQueryOverride(int pageIndex, int pageSize)
        {
            Query q = Post.CreateQuery();

            q.AndWhere(Post.Columns.IsPublished, true);
            q.AndWhere(Post.Columns.IsDeleted, false);
            q.AndWhere(Post.Columns.IsHome, true);
            q.AndWhere(Post.Columns.Published, SiteSettings.CurrentUserTime, Comparison.LessOrEquals);

            q.PageSize  = pageSize;
            q.PageIndex = pageIndex;

            q.OrderByAsc(Post.Columns.HomeSortOrder);

            return(q);
        }
Exemple #4
0
        /// <summary>
        /// Returns a query which applies all of the common filters
        /// </summary>
        /// <returns></returns>
        public static Query DefaultQuery(SortOrderType sot)
        {
            Query q = Post.CreateQuery();

            q.AndWhere(Post.Columns.IsPublished, true);
            q.AndWhere(Post.Columns.IsDeleted, false);

            if (SiteSettings.Get().FilterUncategorizedPostsFromLists)
            {
                q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId, Comparison.NotEquals);
            }

            q.AndWhere(Post.Columns.Published, SiteSettings.CurrentUserTime, Comparison.LessOrEquals);

            switch (sot)
            {
            case SortOrderType.Ascending:
                q.OrderByAsc(Post.Columns.Published);
                break;

            case SortOrderType.Views:
                q.OrderByDesc(Post.Columns.Views);
                break;

            case SortOrderType.Custom:
                q.OrderByAsc(Post.Columns.SortOrder);
                break;

            case SortOrderType.Alphabetical:
                q.OrderByAsc(Post.Columns.Title);
                break;

            default:
                q.OrderByDesc(Post.Columns.Published);
                break;
            }


            return(q);
        }
Exemple #5
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-");
            }
        }
Exemple #6
0
        public IEnumerable Query(IDictionary paramaters)
        {
            string type = paramaters["type"] as string;

            if (type != null)
            {
                paramaters.Remove("type");
            }
            else
            {
                type = "post";
            }

            switch (type)
            {
            case "post":

                Query postQuery = Post.CreateQuery();
                SetLimits(postQuery, paramaters);

                string categoryName = paramaters["category"] as string;
                if (categoryName != null)
                {
                    paramaters.Remove("category");
                }

                if (categoryName == "none")
                {
                    categoryName = CategoryController.UncategorizedName;
                }

                if (categoryName != null)
                {
                    paramaters["categoryid"] = new CategoryController().GetCachedCategory(categoryName, false).Id;
                }

                if (paramaters["isDeleted"] == null)
                {
                    paramaters["isDeleted"] = false;
                }

                if (paramaters["isPublished"] == null)
                {
                    paramaters["isPublished"] = true;
                }

                string orderBy = paramaters["orderby"] as string;
                if (orderBy != null)
                {
                    paramaters.Remove("orderBy");
                }
                else
                {
                    orderBy = "Published DESC";
                }

                postQuery.Orders.Add(orderBy);

                string cacheKey = "Posts-";
                foreach (string key in paramaters.Keys)
                {
                    Column col = GetPostColumn(key);
                    postQuery.AndWhere(col, paramaters[key]);
                    cacheKey += "|" + col.Name + "|" + paramaters[key];
                }

                PostCollection pc = ZCache.Get <PostCollection>(cacheKey);
                if (pc == null)
                {
                    pc = new PostCollection();
                    pc.LoadAndCloseReader(postQuery.ExecuteReader());
                    ZCache.InsertCache(cacheKey, pc, 90);
                }
                return(pc);

            case "comment":

                break;

            case "category":

                break;
            }

            return(null);
        }
Exemple #7
0
        protected override void BeforeValidate()
        {
            base.BeforeValidate();

            if (IsNew)
            {
                if (UniqueId == Guid.Empty)
                {
                    UniqueId = Guid.NewGuid();
                }
            }

            if (string.IsNullOrEmpty(FormattedName))
            {
                FormattedName = Util.CleanForUrl(Name);
            }

            //We append the parent link name if it exists
            if (ParentId <= 0)
            {
                LinkName = Util.CleanForUrl(FormattedName);
            }
            else
            {
                LinkName = new CategoryController().GetCachedCategory(ParentId, false).LinkName + "/" + Util.CleanForUrl(FormattedName);
            }

            if (!Util.IsValidFileName(LinkName))
            {
                throw new Exception("Sorry, you cannot use the reserved word *" + LinkName + "* for a file name.");
            }

            if (string.IsNullOrEmpty(FeedUrlOverride))
            {
                FeedUrlOverride = null;
            }

            //We need to protected against category names colliding with uncategorized posts.
            //Uncategorized posts also do the same check
            if (Name != CategoryController.UncategorizedName)
            {
                Query q = Post.CreateQuery();
                q.AndWhere(Post.Columns.Name, LinkName);
                q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId);
                if (q.GetRecordCount() > 0)
                {
                    throw new Exception("Categories cannot have the same name as an uncategorized post");
                }
            }

            //Check for changes. At this time, we do not support renaming
            //categories if it has a post.
            //if(__initialCategoryName != null && __initialCategoryName != LinkName)
            //{
            //    Query q = Post.CreateQuery();
            //    q.AddWhere(Post.Columns.CategoryId, Id);
            //    if (q.GetRecordCount() > 0)
            //        throw new Exception("Sorry, at this time you cannot rename a category with posts in it.");
            //}

            if (string.IsNullOrEmpty(Body) || Body == "<p>&nbsp;</p>")
            {
                Body = null;
            }
        }