Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            long.TryParse(Request["id"], out id);

            if (id > 0)
            {
                posts = PostDA.SelectByID(id);

                if (posts == null)
                {
                    mess = "Bài viết này không có, bạn hãy liên hệ với Admin về sự cố này.";
                    return;
                }
                else
                {
                    listPost = PostDA.SelectPostRelation(posts.CateID.Value, posts.ObjectID.Value, id, 4);
                }

                content = (posts.Content);
                shortContent = LanguageConvert.StripHtml(posts.Content, false);
                matchString = Regex.Match(content, "(?<=<img.*?src=\")[^\"]*(?=\".*?((/>)|(>.*</img)))", RegexOptions.IgnoreCase).Value;
                shortContent = shortContent.Replace("\"", "'");
                shortContent = shortContent.Length > 150 ? shortContent.Substring(0, shortContent.IndexOf(" ", 140)) : shortContent;

                urlShare = LinkBuilder.getLinkPost(posts.ID, posts.ObjectID.Value, posts.Title);
                string domain = CommentTotal.getDomain();
                urlShare = domain + urlShare;
                is_owner = (Current_user.Username == posts.UserName) ? true : false;
                Page.Title = posts.Title + " | T2S";
                Page.MetaDescription = shortContent;
                Page.MetaKeywords = posts.Tags;
                if (!IsPostBack)
                {
                    posts.View += 1;

                    PostDA.Update(posts);
                }

                //listComment = CommentDA.SelectByObjectID(id,page,pagesize);
                #region comment
                commentajax1.objectID = id;
                commentajax1.objecttype = "comment";
                commentajax1.receiverID = posts.AccountID;
                commentajax1.receiverUsername = posts.UserName;
                string url = Request.RawUrl;
                commentajax1.target_link = url;
                commentajax1.target_object_name = posts.Title.Length > 100 ? posts.Title.Substring(0, posts.Title.IndexOf(" ", 80)) : posts.Title;
                #endregion comment
            }
            else
            {
                //string cateSlug = Request["page"];
                //listPost = PostDA.SelectByCateNameSlug(cateSlug,page,pagesize);
                //countPage = PostDA.countAll(cateSlug);
            }
        }
Example #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //listPost = PostDA.SelectByPageSize(page,pagesize);
     listPost = PostDA.SelectListPostNewest(20);
 }
Example #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     listPostHot = PostDA.TopPostHotView(8);
 }
Example #4
0
        static void Main(string[] args)
        {
            int score = 0;

            Console.Write("TEST1: Ist die Post Klasse abstrakt? ");
            score += AssertTrue(() => typeof(Post).IsAbstract);

            Console.Write("TEST2: Kann ein TextPost angelegt werden? ");
            DateTime time = DateTime.Now.AddMinutes(-10);
            TextPost tp1  = new TextPost("Mein Titel");
            TextPost tp2  = new TextPost("Mein 2. Titel", time);

            score += AssertTrue(() => tp1.Title == "Mein Titel" && tp2.Created == time);

            Console.Write("TEST3: Kann ein ImagePost angelegt werden? ");
            ImagePost ip1 = new ImagePost("Mein Titel");
            ImagePost ip2 = new ImagePost("Mein Titel", time);

            score += AssertTrue(() => ip1.Title == "Mein Titel" && ip2.Created == time);

            Console.Write("TEST4: Stimmt die Länge des Postings? ");
            TextPost tp3 = new TextPost("Mein Titel", time);
            TextPost tp4 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };

            score += AssertTrue(() => tp3.Length == 0 && tp4.Length == 7);

            Console.Write("TEST5: Stimmt das HTML Property von TextPost? ");
            Post tp5 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };

            score += AssertTrue(() => tp5.Html == "<p>Content</p>");

            Console.Write("TEST6: Stimmt das HTML Property von ImagePost? ");
            Post ip3 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };

            score += AssertTrue(() => ip3.Html == "<img src=\"http://image.png\">");

            Console.Write("TEST7: Stimmt die ToString Repräsentation von Post? ");
            object ip4 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };

            score += AssertTrue(() => ip4.ToString() == "<img src=\"http://image.png\">");

            Console.Write("TEST8: Ist das Length Property von TextPost readonly? ");
            PropertyInfo info = typeof(TextPost).GetMember("Length")[0] as PropertyInfo;

            score += AssertTrue(() => info.CanWrite == false);

            Console.Write("TEST9: Ist das Title Property von Post readonly? ");
            PropertyInfo info2 = typeof(Post).GetMember("Title")[0] as PropertyInfo;

            score += AssertTrue(() => info2.CanWrite == false);

            Console.Write("TEST10: Funktioniert die PostCollection? ");
            TextPost tp6 = new TextPost("Mein Titel", time)
            {
                Content = "Content"
            };
            ImagePost ip5 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png"
            };
            PostCollection pc1 = new PostCollection();

            pc1.Add(tp6);
            pc1.Add(ip5);
            score += AssertTrue(() => pc1.Count == 2);

            Console.Write("TEST11: Funktioniert CalcRating mit Lambdas? ");
            TextPost tp7 = new TextPost("Mein Titel", time)
            {
                Content = "Content", Rating = 10
            };
            ImagePost ip6 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png", Rating = -1
            };
            PostCollection pc2 = new PostCollection();

            pc2.Add(tp7);
            pc2.Add(ip6);
            score += AssertTrue(() => pc2.CalcRating(p => p.Rating > 0 ? p.Rating : 0) == 10);

            Console.Write("TEST12: Funktioniert ProcessPosts mit Lambdas? ");
            TextPost tp8 = new TextPost("Mein Titel", time)
            {
                Content = "Content", Rating = 10
            };
            ImagePost ip7 = new ImagePost("Mein Titel", time)
            {
                Url = "http://image.png", Rating = -1
            };
            PostCollection pc3 = new PostCollection();

            pc3.Add(tp8);
            pc3.Add(ip7);
            int ratingSum = 0;

            pc3.ProcessPosts(p => ratingSum += p.Rating);
            score += AssertTrue(() => ratingSum == 9);

            double percent = score / 12.0;
            int    note    = percent > 0.875 ? 1 : percent > 0.75 ? 2 : percent > 0.625 ? 3 : percent > 0.5 ? 4 : 5;

            Console.WriteLine($"{score} von 12 Punkten erreicht. Note: {note}.");
            Console.ReadLine();
        }
Example #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     listPost = PostDA.SelectByCateID(CategoriesEnums.idCate_sharing);
     if (Current_user != null && Current_user.ID > 0)
         account = Current_user;
 }
Example #6
0
        protected override void HandleRequest(IGraffitiUser user, XmlTextWriter writer)
        {
            switch (Context.Request.HttpMethod.ToUpper())
            {
            case "GET":

                CategoryController controller = new CategoryController();
                CategoryCollection cc         = null;
                int count = 1;
                if (Request.QueryString["id"] != null)
                {
                    Category category = controller.GetCachedCategory(Int32.Parse(Request.QueryString["id"]), false);
                    cc = new CategoryCollection();
                    cc.Add(category);
                }
                else if (Request.QueryString["name"] != null)
                {
                    Category category = controller.GetCachedCategory(Request.QueryString["name"], false);
                    cc = new CategoryCollection();
                    cc.Add(category);
                }
                else
                {
                    cc    = controller.GetAllTopLevelCachedCategories();
                    count = controller.GetAllCachedCategories().Count;
                }
                writer.WriteStartElement("categories");
                writer.WriteAttributeString("pageIndex", "1");
                writer.WriteAttributeString("pageSize", count.ToString());
                writer.WriteAttributeString("totalCategories", count.ToString());

                foreach (Category category in cc)
                {
                    WriteCategoryToXML(category, writer);
                }
                writer.WriteEndElement();
                writer.Close();

                break;

            case "POST":

                XmlDocument doc = new XmlDocument();
                doc.Load(Request.InputStream);

                if (Request.Headers["Graffiti-Method"] != "DELETE")
                {
                    if (GraffitiUsers.IsAdmin(user))
                    {
                        string xml = CreateUpdateCategory(doc);
                        writer.WriteRaw(xml);
                    }
                    else
                    {
                        UnuathorizedRequest();
                    }
                }
                else
                {
                    XmlAttribute categoryIdAttribute = doc.SelectSingleNode("/category").Attributes["id"];

                    foreach (Post p in PostCollection.FetchAll())
                    {
                        if (p.CategoryId == Int32.Parse(categoryIdAttribute.Value))
                        {
                            if (p.IsDeleted)
                            {
                                Post.DestroyDeletedPost(p.Id);
                            }
                            else
                            {
                                Response.StatusCode = 500;
                                writer.WriteRaw("<error>You can not delete a category that contains post.</error>");
                                return;
                            }
                        }
                    }

                    Category.Destroy(Int32.Parse(categoryIdAttribute.Value));
                    CategoryController.Reset();

                    writer.WriteRaw("<result id=\"" + Int32.Parse(categoryIdAttribute.Value) + "\">deleted</result>");
                }

                break;

            default:


                break;
            }
        }
Example #7
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 #8
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.RequestType != "POST" || !context.Request.IsAuthenticated)
            {
                return;
            }

            IGraffitiUser user = GraffitiUsers.Current;

            if (user == null)
            {
                return;
            }

            if (!RolePermissionManager.CanViewControlPanel(user))
            {
                return;
            }

            context.Response.ContentType = "text/plain";


            switch (context.Request.QueryString["command"])
            {
            case "deleteComment":

                Comment c = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment.Delete(context.Request.Form["commentid"]);
                    context.Response.Write("success");
                }

                break;

            case "deleteCommentWithStatus":

                Comment c1 = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c1.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment.Delete(context.Request.Form["commentid"]);
                    context.Response.Write("The comment was deleted. <a href=\"javascript:void(0);\" onclick=\"Comments.unDelete('" +
                                           new Urls().AdminAjax + "'," + context.Request.Form["commentid"] +
                                           "); return false;\">Undo?</a>");
                }
                break;

            case "unDelete":
                Comment c2 = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c2.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment comment = new Comment(context.Request.Form["commentid"]);
                    comment.IsDeleted = false;
                    comment.Save();
                    context.Response.Write("The comment was un-deleted. You may need to refresh the page to see it");
                }
                break;

            case "approve":
                Comment c3 = new Comment(context.Request.Form["commentid"]);

                if (RolePermissionManager.GetPermissions(c3.Post.CategoryId, GraffitiUsers.Current).Publish)
                {
                    Comment cmt = new Comment(context.Request.Form["commentid"]);
                    cmt.IsDeleted   = false;
                    cmt.IsPublished = true;
                    cmt.Save();
                    context.Response.Write("The comment was un-deleted and/or approved. You may need to refresh the page to see it");
                }
                break;

            case "deletePost":
                try
                {
                    Post postToDelete = new Post(context.Request.Form["postid"]);

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

                    if (GraffitiUsers.IsAdmin(user) || perm.Publish)
                    {
                        postToDelete.IsDeleted = true;
                        postToDelete.Save(user.Name, DateTime.Now);

                        //Post.Delete(context.Request.Form["postid"]);
                        //ZCache.RemoveByPattern("Posts-");
                        //ZCache.RemoveCache("Post-" + context.Request.Form["postid"]);
                        context.Response.Write("The post was deleted. <a href=\"javascript:void(0);\" onclick=\"Posts.unDeletePost('" +
                                               new Urls().AdminAjax + "'," + context.Request.Form["postid"] +
                                               "); return false;\">Undo?</a>");
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "unDeletePost":
                Post p = new Post(context.Request.Form["postid"]);
                p.IsDeleted = false;
                p.Save();
                //ZCache.RemoveByPattern("Posts-");
                //ZCache.RemoveCache("Post-" + context.Request.Form["postid"]);
                //context.Response.Write("The post was un-deleted. You may need to fresh the page to see it");
                break;

            case "permanentDeletePost":
                Post tempPost = new Post(context.Request.Form["postid"]);
                Post.DestroyDeletedPost(tempPost.Id);
                context.Response.Write(tempPost.Title);
                break;

            case "createdWidget":
                string widgetID    = context.Request.Form["id"];
                var    the_widgets = Widgets.GetAvailableWidgets();
                Widget widget      = null;
                foreach (WidgetDescription wia in the_widgets)
                {
                    if (wia.UniqueId == widgetID)
                    {
                        widget = Widgets.Create(wia.WidgetType);
                        break;
                    }
                }

                context.Response.Write(widget.Id.ToString());

                break;

            case "updateWidgetsOrder":

                try
                {
                    string listID = context.Request.Form["id"];
                    string list   = "&" + context.Request.Form["list"];

                    Widgets.ReOrder(listID, list);

                    //StreamWriter sw = new StreamWriter(context.Server.MapPath("~/widgets.txt"), true);
                    //sw.WriteLine(DateTime.Now);
                    //sw.WriteLine();
                    //sw.WriteLine(context.Request.Form["left"]);
                    //sw.WriteLine(context.Request.Form["right"]);
                    //sw.WriteLine(context.Request.Form["queue"]);
                    //sw.WriteLine();
                    //sw.Close();

                    context.Response.Write("Saved!");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "deleteWidget":

                string deleteID = context.Request.Form["id"];
                Widgets.Delete(deleteID);
                context.Response.Write("The widget was removed!");

                break;

            case "createTextLink":
                DynamicNavigationItem di = new DynamicNavigationItem();
                di.NavigationType = DynamicNavigationType.Link;
                di.Text           = context.Request.Form["text"];
                di.Href           = context.Request.Form["href"];
                di.Id             = Guid.NewGuid();
                NavigationSettings.Add(di);
                context.Response.Write(di.Id);

                break;

            case "deleteTextLink":
                Guid g = new Guid(context.Request.Form["id"]);
                NavigationSettings.Remove(g);
                context.Response.Write("Success");
                break;

            case "reOrderNavigation":
                try
                {
                    string navItems = "&" + context.Request.Form["navItems"];
                    NavigationSettings.ReOrder(navItems);
                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "addNavigationItem":


                try
                {
                    if (context.Request.Form["type"] == "Post")
                    {
                        Post navPost = Post.FetchByColumn(Post.Columns.UniqueId, new Guid(context.Request.Form["id"]));
                        DynamicNavigationItem item = new DynamicNavigationItem();
                        item.PostId         = navPost.Id;
                        item.Id             = navPost.UniqueId;
                        item.NavigationType = DynamicNavigationType.Post;
                        NavigationSettings.Add(item);
                        context.Response.Write("Success");
                    }
                    else if (context.Request.Form["type"] == "Category")
                    {
                        Category navCategory       = Category.FetchByColumn(Category.Columns.UniqueId, new Guid(context.Request.Form["id"]));
                        DynamicNavigationItem item = new DynamicNavigationItem();
                        item.CategoryId     = navCategory.Id;
                        item.Id             = navCategory.UniqueId;
                        item.NavigationType = DynamicNavigationType.Category;
                        NavigationSettings.Add(item);
                        context.Response.Write("Success");
                    }
                }
                catch (Exception exp)
                {
                    context.Response.Write(exp.Message);
                }

                break;

            case "reOrderPosts":
                try
                {
                    var   posts = new Dictionary <int, Post>();
                    Query query = Post.CreateQuery();
                    query.AndWhere(Post.Columns.CategoryId, int.Parse(context.Request.QueryString["id"]));
                    foreach (Post post in PostCollection.FetchByQuery(query))
                    {
                        posts[post.Id] = post;
                    }

                    string postOrder   = context.Request.Form["posts"];
                    int    orderNumber = 1;
                    foreach (string sId in postOrder.Split('&'))
                    {
                        Post post = null;
                        posts.TryGetValue(int.Parse(sId), out post);
                        if (post != null && post.SortOrder != orderNumber)
                        {
                            post.SortOrder = orderNumber;
                            post.Save();
                        }

                        orderNumber++;
                    }

                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "reOrderHomePosts":
                try
                {
                    var   posts = new Dictionary <int, Post>();
                    Query query = Post.CreateQuery();
                    query.AndWhere(Post.Columns.IsHome, true);
                    foreach (Post post in PostCollection.FetchByQuery(query))
                    {
                        posts[post.Id] = post;
                    }

                    string postOrder   = context.Request.Form["posts"];
                    int    orderNumber = 1;
                    foreach (string sId in postOrder.Split('&'))
                    {
                        Post post = null;
                        posts.TryGetValue(int.Parse(sId), out post);
                        if (post != null && post.HomeSortOrder != orderNumber)
                        {
                            post.HomeSortOrder = orderNumber;
                            post.Save();
                        }

                        orderNumber++;
                    }

                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "categoryForm":

                int selectedCategory = int.Parse(context.Request.QueryString["category"] ?? "-1");
                int postId           = int.Parse(context.Request.QueryString["post"] ?? "-1");
                NameValueCollection nvcCustomFields;
                if (postId > 0)
                {
                    nvcCustomFields = new Post(postId).CustomFields();
                }
                else
                {
                    nvcCustomFields = new NameValueCollection();
                }

                CustomFormSettings cfs = CustomFormSettings.Get(selectedCategory);

                if (cfs.HasFields)
                {
                    foreach (CustomField cf in cfs.Fields)
                    {
                        if (context.Request.Form[cf.Id.ToString()] != null)
                        {
                            nvcCustomFields[cf.Name] = context.Request.Form[cf.Id.ToString()];
                        }
                    }

                    context.Response.Write(cfs.GetHtmlForm(nvcCustomFields, (postId < 1)));
                }
                else
                {
                    context.Response.Write("");
                }

                break;

            case "toggleEventStatus":

                try
                {
                    EventDetails ed = Events.GetEvent(context.Request.QueryString["t"]);
                    ed.Enabled = !ed.Enabled;

                    if (ed.Enabled)
                    {
                        ed.Event.EventEnabled();
                    }
                    else
                    {
                        ed.Event.EventDisabled();
                    }

                    Events.Save(ed);

                    context.Response.Write(ed.Enabled ? "Enabled" : "Disabled");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "buildMainFeed":
                try
                {
                    FileInfo mainFeedFileInfo = new FileInfo(HttpContext.Current.Server.MapPath("~/Feed/Default.aspx"));

                    if (!mainFeedFileInfo.Directory.Exists)
                    {
                        mainFeedFileInfo.Directory.Create();
                    }

                    using (StreamWriter sw = new StreamWriter(mainFeedFileInfo.FullName, false))
                    {
                        sw.WriteLine("<%@ Page Language=\"C#\" Inherits=\"Graffiti.Core.RSS\" %>");
                        sw.Close();
                    }

                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                    return;
                }

                break;

            case "removeFeedData":
                try
                {
                    FeedManager.RemoveFeedData();
                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;

            case "buildCategoryPages":

                try
                {
                    CategoryCollection cc = new CategoryController().GetCachedCategories();
                    foreach (Category cat in cc)
                    {
                        cat.WritePages();
                    }


                    context.Response.Write("Success");
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                    return;
                }

                break;

            case "buildPages":

                try
                {
                    Query q = Post.CreateQuery();
                    q.PageIndex = Int32.Parse(context.Request.Form["p"]);
                    q.PageSize  = 20;
                    q.OrderByDesc(Post.Columns.Id);

                    PostCollection pc = PostCollection.FetchByQuery(q);
                    if (pc.Count > 0)
                    {
                        foreach (Post postToWrite in pc)
                        {
                            postToWrite.WritePages();
                            foreach (string tagName in Util.ConvertStringToList(postToWrite.TagList))
                            {
                                if (!string.IsNullOrEmpty(tagName))
                                {
                                    Tag.WritePage(tagName);
                                }
                            }
                        }

                        context.Response.Write("Next");
                    }
                    else
                    {
                        context.Response.Write("Success");
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                    return;
                }


                break;

            case "importPosts":

                try
                {
                    Post newPost = new Post();
                    newPost.Title = HttpContext.Current.Server.HtmlDecode(context.Request.Form["subject"]);

                    string postName = HttpContext.Current.Server.HtmlDecode(context.Request.Form["name"]);

                    PostCollection pc = new PostCollection();

                    if (!String.IsNullOrEmpty(postName))
                    {
                        Query q = Post.CreateQuery();
                        q.AndWhere(Post.Columns.Name, Util.CleanForUrl(postName));
                        pc.LoadAndCloseReader(q.ExecuteReader());
                    }

                    if (pc.Count > 0)
                    {
                        newPost.Name   = "[RENAME ME - " + Guid.NewGuid().ToString().Substring(0, 7) + "]";
                        newPost.Status = (int)PostStatus.Draft;
                    }
                    else if (String.IsNullOrEmpty(postName))
                    {
                        newPost.Name   = "[RENAME ME - " + Guid.NewGuid().ToString().Substring(0, 7) + "]";
                        newPost.Status = (int)PostStatus.Draft;
                    }
                    else
                    {
                        newPost.Name   = postName;
                        newPost.Status = (int)PostStatus.Publish;
                    }

                    if (String.IsNullOrEmpty(newPost.Title))
                    {
                        newPost.Title = newPost.Name;
                    }


                    newPost.PostBody       = HttpContext.Current.Server.HtmlDecode(context.Request.Form["body"]);
                    newPost.CreatedOn      = Convert.ToDateTime(context.Request.Form["createdon"]);
                    newPost.CreatedBy      = context.Request.Form["author"];
                    newPost.ModifiedBy     = context.Request.Form["author"];
                    newPost.TagList        = context.Request.Form["tags"];
                    newPost.ContentType    = "text/html";
                    newPost.CategoryId     = Convert.ToInt32(context.Request.Form["category"]);
                    newPost.UserName       = context.Request.Form["author"];
                    newPost.EnableComments = true;
                    newPost.Published      = Convert.ToDateTime(context.Request.Form["createdon"]);
                    newPost.IsPublished    = Convert.ToBoolean(context.Request.Form["published"]);

                    // this was causing too many posts to be in draft status.
                    // updated text on migrator to flag users to just move their content/binary directory
                    // into graffiti's root
                    //if (context.Request.Form["method"] == "dasBlog")
                    //{
                    //    if (newPost.Body.ToLower().Contains("/content/binary/"))
                    //        newPost.Status = (int)PostStatus.Draft;
                    //}

                    newPost.Save(GraffitiUsers.Current.Name);

                    int postid = Convert.ToInt32(context.Request.Form["postid"]);

                    IMigrateFrom temp = null;

                    switch (context.Request.Form["method"])
                    {
                    case "CS2007Database":

                        CS2007Database db = new CS2007Database();
                        temp = db;

                        break;

                    case "Wordpress":

                        Wordpress wp = new Wordpress();
                        temp = wp;

                        break;

                    case "BlogML":

                        BlogML bml = new BlogML();
                        temp = bml;

                        break;

                    case "CS21Database":
                        CS21Database csDb = new CS21Database();
                        temp = csDb;

                        break;

                    case "dasBlog":
                        dasBlog dasb = new dasBlog();
                        temp = dasb;

                        break;
                    }

                    var comments = temp.GetComments(postid);

                    foreach (MigratorComment cmnt in comments)
                    {
                        Comment ct = new Comment();
                        ct.PostId         = newPost.Id;
                        ct.Body           = cmnt.Body;
                        ct.Published      = cmnt.PublishedOn;
                        ct.IPAddress      = cmnt.IPAddress;
                        ct.WebSite        = cmnt.WebSite;
                        ct.Email          = string.IsNullOrEmpty(cmnt.Email) ? "" : cmnt.Email;
                        ct.Name           = string.IsNullOrEmpty(cmnt.UserName) ? "" : cmnt.UserName;
                        ct.IsPublished    = cmnt.IsPublished;
                        ct.IsTrackback    = cmnt.IsTrackback;
                        ct.SpamScore      = cmnt.SpamScore;
                        ct.DontSendEmail  = true;
                        ct.DontChangeUser = true;

                        ct.Save();

                        Comment ctemp = new Comment(ct.Id);
                        ctemp.DontSendEmail  = true;
                        ctemp.DontChangeUser = true;
                        ctemp.Body           = HttpContext.Current.Server.HtmlDecode(ctemp.Body);
                        ctemp.Save();
                    }

                    if (newPost.Status == (int)PostStatus.Publish)
                    {
                        context.Response.Write("Success" + context.Request.Form["panel"]);
                    }
                    else
                    {
                        context.Response.Write("Warning" + context.Request.Form["panel"]);
                    }
                }
                catch (Exception ex)
                {
                    context.Response.Write(context.Request.Form["panel"] + ":" + ex.Message);
                }

                break;

            case "saveHomeSortStatus":

                SiteSettings siteSettings = SiteSettings.Get();
                siteSettings.UseCustomHomeList = bool.Parse(context.Request.Form["ic"]);
                siteSettings.Save();
                context.Response.Write("Success");

                break;

            case "checkCategoryPermission":

                try
                {
                    int        catID          = Int32.Parse(context.Request.QueryString["category"]);
                    string     permissionName = context.Request.QueryString["permission"];
                    Permission perm           = RolePermissionManager.GetPermissions(catID, user);

                    bool permissionResult = false;
                    switch (permissionName)
                    {
                    case "Publish":
                        permissionResult = perm.Publish;
                        break;

                    case "Read":
                        permissionResult = perm.Read;
                        break;

                    case "Edit":
                        permissionResult = perm.Edit;
                        break;
                    }

                    context.Response.Write(permissionResult.ToString().ToLower());
                }
                catch (Exception ex)
                {
                    context.Response.Write(ex.Message);
                }
                break;
            }
        }
Example #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        LiHyperLink.SetNameToCompare(Context, "presentation");

        NavigationSettings settings = NavigationSettings.Get();
        CategoryCollection cc       = new CategoryController().GetTopLevelCachedCategories();

        foreach (Category c in cc)
        {
            bool found = false;
            foreach (DynamicNavigationItem di in settings.SafeItems())
            {
                if (di.NavigationType == DynamicNavigationType.Category && di.CategoryId == c.Id)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                the_Categories.Items.Add(new ListItem(c.Name, "Category-" + c.UniqueId));
            }
        }


        Query q = Post.CreateQuery();

        q.AndWhere(Post.Columns.CategoryId, CategoryController.UnCategorizedId);
        q.AndWhere(Post.Columns.IsDeleted, false);
        q.AndWhere(Post.Columns.Status, 1);

        PostCollection pc = new PostCollection();

        pc.LoadAndCloseReader(q.ExecuteReader());

        foreach (Post p in pc)
        {
            bool found = false;
            foreach (DynamicNavigationItem di in settings.SafeItems())
            {
                if (di.NavigationType == DynamicNavigationType.Post && di.PostId == p.Id)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                the_Posts.Items.Add(new ListItem(p.Title, "Post-" + p.UniqueId));
            }
        }

        // 0 - Title, 1 - Type, 2 - LID
        string itemFormat =
            "<div style=\"border: solid 1px #999; padding: 4px;\"><strong>{0} ({1})</strong><div style=\"text-align:right;\"><a title=\"Delete Link\" href=\"javascript:void();\" onclick=\"remove_Link( &#39;{1}&#39;,&#39;{0}&#39;, &#39;{2}&#39;); return false;\">Delete</a></div></div>";

        foreach (DynamicNavigationItem dni in settings.SafeItems())
        {
            lbar.Items.Add(
                new OrderedListItem(string.Format(itemFormat, dni.Name, dni.NavigationType.ToString(), dni.Id),
                                    dni.Name, dni.NavigationType.ToString() + "-" + dni.Id.ToString()));
        }
    }
        // *********************************************************************
        //  DisplaySearchResults
        //
        /// <summary>
        /// This function grabs the dataset of search results for the particular page.
        /// If there are records in the DataSet, it is bound to the DataGrid, else
        /// a message is displayed explaining that no results were found.
        /// </summary>
        // ***********************************************************************/
        private void DisplaySearchResults()
        {
            // get the search results
            ToSearchEnum   ToSearch;
            SearchWhatEnum SearchWhat;

            // determine what we want to search (post body or poster's username?)
            switch (Convert.ToInt32(searchFor.SelectedItem.Value))
            {
            case 1:
                ToSearch = ToSearchEnum.PostsBySearch;
                break;

            default:
                ToSearch = ToSearchEnum.PostsSearch;
                break;
            }

            // determine how we want to search
            switch (Convert.ToInt32(matchingWords.SelectedItem.Value))
            {
            case 1:
                SearchWhat = SearchWhatEnum.SearchAnyWord;
                break;

            case 2:
                SearchWhat = SearchWhatEnum.SearchExactPhrase;
                break;

            default:
                SearchWhat = SearchWhatEnum.SearchAllWords;
                break;
            }

            // Clean up search text
            textToSearchFor.Text = textToSearchFor.Text.Replace("'", "''");

            // Perform the Search
            PostCollection posts = AspNetForums.Search.PerformSearch(ToSearch, SearchWhat,
                                                                     Convert.ToInt32(forumsToSearch.SelectedItem.Value),
                                                                     textToSearchFor.Text, searchResultsDataGrid.CurrentPageIndex + 1, searchResultsDataGrid.PageSize);

            // if the dataset is empty, show an appropriate message
            if (posts.Count == 0)
            {
                ((Label)FindControl("lblNoResults")).Visible       = true;
                ((Panel)FindControl("panelSearchResults")).Visible = false;
            }
            else
            {
                // we have results, bind it to the DataGrid.
                ((Panel)FindControl("panelSearchResults")).Visible = true;
                ((Label)FindControl("lblNoResults")).Visible       = false;

                searchResultsDataGrid.VirtualItemCount = ((searchResultsDataGrid.CurrentPageIndex + 1) * searchResultsDataGrid.PageSize) + posts.TotalRecordCount;
                searchResultsDataGrid.DataSource       = posts;
                searchResultsDataGrid.DataBind();

                // display how many results we got and what page we're viewing.
                ((Label)FindControl("lblInformation")).Text = String.Format("Viewing Page " + (searchResultsDataGrid.CurrentPageIndex + 1) + ".  More matches available? " + ((posts.TotalRecordCount == 0) ? "No" : "Yes"));
            }
        }