Exemple #1
0
        public static PostViewModel PostViewModelFromSlug(string slug) // todo: make the slug a unique property in the database
        {
            BlogDataDataContext database = new BlogDataDataContext();
            var post = database.Posts.FirstOrDefault(x => x.Slug == slug);

            return(new PostViewModel(post));
        }
Exemple #2
0
        public override void LoadSettings()
        {
            try
            {
                if (Page.IsPostBack == false)
                {
                    BlogDataDataContext db = new BlogDataDataContext();
                    var blogs = db.Blog_Blogs.Where(c => c.PortalID == PortalId).Select(c => new { Name = c.Title, ID = c.BlogID }).ToList();
                    ddlBlogID.DataSource     = blogs;
                    ddlBlogID.DataTextField  = "Name";
                    ddlBlogID.DataValueField = "ID";
                    ddlBlogID.DataBind();

                    if (Settings.Contains("txtArticlesQty"))
                    {
                        txtArticlesQty.Text = Settings["txtArticlesQty"].ToString();
                    }

                    if (Settings.Contains("txtBlogUrl"))
                    {
                        txtBlogUrl.Text = Settings["txtBlogUrl"].ToString();
                    }

                    if (Settings.Contains("ddlBlogID"))
                    {
                        ddlBlogID.SelectedValue = Settings["ddlBlogID"].ToString();
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #3
0
        public static PostViewModel PostViewModelFromId(string id)
        {
            BlogDataDataContext database = new BlogDataDataContext();
            var post = database.Posts.FirstOrDefault(x => x.Id == new Guid(id));

            return(new PostViewModel(post));
        }
Exemple #4
0
        public PostIndexModelPost(Blog.Post post)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Id    = post.Id.ToString();
            Title = post.Title.ToString();

            Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author);
            Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName);

            Dictionary <Guid, string>   categoriesTemp = new Dictionary <Guid, string>();
            List <Blog.PostCategoryMap> categoryMaps   = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var categoryMap in categoryMaps)
            {
                Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp.Add(category.Id, category.Name);
            }
            Categories = categoriesTemp;

            Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>();
            List <Blog.PostTagMap>    tagMaps  = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var tagMap in tagMaps)
            {
                Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp.Add(tag.Id, tag.Name);
            }
            Tags = tagsTemp;

            Comments  = "0"; // todo: add comments table, and do a count of them here
            Timestamp = post.Timestamp.ToString();
        }
Exemple #5
0
        public ActionResult Zarzadzanie()
        {
            var _db   = new BlogDataDataContext();
            var posts = from m in _db.Posts
                        select m;

            return(View(posts));
            //return View();
        }
Exemple #6
0
        protected void ddlArticles_SelectedIndexChanged(object sender, EventArgs e)
        {
            BlogDataDataContext db = new BlogDataDataContext();
            var b = db.Blog_Entries.Where(c => c.EntryID.ToString() == ddlArticles.SelectedValue).FirstOrDefault();

            txtTitle.Text        = b.Title;
            txtBody.Text         = b.Entry;
            txtSummary.Text      = b.Description;
            chkPublished.Checked = b.Published;
        }
Exemple #7
0
        public static UserIndexModel UserIndex()
        {
            UserIndexModel model = new UserIndexModel();

            BlogDataDataContext database = new BlogDataDataContext();
            List <Blog.User>    users    = database.Users.ToList();

            model.Users = users;

            return(model);
        }
Exemple #8
0
        public wpPost(XElement postElement)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Title = postElement.Element("title").Value;
            Link  = postElement.Element("link").Value;
            //PubDate = DateTime.Parse(postElement.Element("pubDate").Value, new DateTimeFormatInfo(""));
            Creator     = database.Users.FirstOrDefault(x => x.Username == postElement.Element(dcNamespace + "creator").Value).Id;
            Guid        = postElement.Element("guid").Value;
            Description = postElement.Element("description").Value;
            Content     = postElement.Element(contentNamespace + "encoded").Value;
            Excerpt     = postElement.Element(excerptNamespace + "encoded").Value;
            PostId      = int.Parse(postElement.Element(wpNamespace + "post_id").Value);
            PostDate    = DateTime.Parse(postElement.Element(wpNamespace + "post_date").Value);
            //PostDateGmt = DateTime.Parse(postElement.Element(wpNamespace + "post_date_gmt").Value);
            CommentStatus = postElement.Element(wpNamespace + "comment_status").Value;
            PostName      = postElement.Element(wpNamespace + "post_name").Value;
            Status        = postElement.Element(wpNamespace + "status").Value;
            PostParent    = int.Parse(postElement.Element(wpNamespace + "post_parent").Value);
            MenuOrder     = int.Parse(postElement.Element(wpNamespace + "menu_order").Value);
            PostType      = postElement.Element(wpNamespace + "post_type").Value;
            PostPassword  = postElement.Element(wpNamespace + "post_password").Value;
            IsSticky      = postElement.Element(wpNamespace + "is_sticky").Value;

            List <wpCategory>      categoriesTemp = new List <wpCategory>();
            IEnumerable <XElement> categories     = postElement.Elements("category").Where(x => (string)x.Attribute("domain") == "category");

            foreach (var category in categories)
            {
                wpCategory newCategory = new wpCategory(category.Attribute("nicename").Value, category.Value);
                categoriesTemp.Add(newCategory);
            }
            Categories = categoriesTemp;

            List <wpTag>           tagsTemp = new List <wpTag>();
            IEnumerable <XElement> tags     = postElement.Elements("category").Where(x => (string)x.Attribute("domain") == "post_tag");

            foreach (var tag in tags)
            {
                wpTag newTag = new wpTag(tag.Attribute("nicename").Value, tag.Value);
                tagsTemp.Add(newTag);
            }
            Tags = tagsTemp;

            List <wpComment>       commentsTemp = new List <wpComment>();
            IEnumerable <XElement> comments     = postElement.Elements(wpNamespace + "comment");

            foreach (var comment in comments)
            {
                wpComment newComment = new wpComment(comment);
                commentsTemp.Add(newComment);
            }
            Comments = commentsTemp;
        }
        public ActionResult Index()
        {
            /*ViewData["Message"] = from m in _db.Posts
             *                          select m;
             *
             * return (ViewData["Message"]);*/

            var _db   = new BlogDataDataContext();
            var posts = from m in _db.Posts
                        select m;

            return(View(posts));
        }
Exemple #10
0
        public static bool DeletePost(string id)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            var post        = database.Posts.FirstOrDefault(x => x.Id == new Guid(id));
            var categoryMap = database.PostCategoryMaps.Where(x => x.PostId == post.Id);
            var tagMap      = database.PostTagMaps.Where(x => x.PostId == post.Id);

            database.Posts.DeleteOnSubmit(post);
            database.PostCategoryMaps.DeleteAllOnSubmit(categoryMap);
            database.PostTagMaps.DeleteAllOnSubmit(tagMap);

            database.SubmitChanges();
            return(true);
        }
Exemple #11
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadSettings loads the settings from the Database and displays them
        /// </summary>
        /// -----------------------------------------------------------------------------
        public override void LoadSettings()
        {
            try
            {
                if (Page.IsPostBack == false)
                {
                    //Check for existing settings and use those on this page
                    //Settings["SettingName"]



                    BlogDataDataContext db = new BlogDataDataContext();
                    var blogs = db.Blog_Blogs.Where(c => c.PortalID == PortalId).Select(c => new { Name = c.Title, ID = c.BlogID }).ToList();
                    ddlBlogID.DataSource     = blogs;
                    ddlBlogID.DataTextField  = "Name";
                    ddlBlogID.DataValueField = "ID";
                    ddlBlogID.DataBind();



                    //uncomment to load saved settings in the text boxes

                    if (Settings.Contains("BlogMode"))
                    {
                        ddlMode.SelectedValue = Settings["BlogMode"].ToString();
                    }

                    if (Settings.Contains("ddlBlogID"))
                    {
                        ddlBlogID.SelectedValue = Settings["ddlBlogID"].ToString();
                    }

                    if (Settings.Contains("txtArticlesQty"))
                    {
                        txtArticlesQty.Text = Settings["txtArticlesQty"].ToString();
                    }

                    if (Settings.Contains("txtBlogUrl"))
                    {
                        txtBlogUrl.Text = Settings["txtBlogUrl"].ToString();
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #12
0
        public static UserEditModel UserEdit(string id)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            if (id.IsNullOrWhiteSpace())
            {
                UserEditModel model = new UserEditModel(new Blog.User(), "Add");
                return(model);
            }
            else
            {
                Blog.User     user  = database.Users.FirstOrDefault(x => x.Id == new Guid(id));
                UserEditModel model = new UserEditModel(user, "Edit");
                return(model);
            }
        }
Exemple #13
0
        public static PostIndexModel PostIndex()
        {
            PostIndexModel model = new PostIndexModel();;

            BlogDataDataContext       database      = new BlogDataDataContext();
            List <Blog.Post>          databasePosts = database.Posts.ToList();
            List <PostIndexModelPost> posts         = new List <PostIndexModelPost>();

            foreach (var post in databasePosts)
            {
                posts.Add(new PostIndexModelPost(post));
            }
            model.Posts = posts;

            return(model);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                int artQty = 10;
                if (Settings.Contains("txtArticlesQty"))
                {
                    int.TryParse(Settings["txtArticlesQty"].ToString(), out artQty);
                }

                int blogID = 0;
                if (Settings.Contains("ddlBlogID"))
                {
                    blogID = Convert.ToInt32(Settings["ddlBlogID"].ToString());
                }

                BlogDataDataContext db = new BlogDataDataContext();
                var articlesRaw        = db.Blog_Entries.Where(c => c.BlogID == blogID && c.Published == true).OrderByDescending(c => c.AddedDate).Take(artQty).ToList();

                string url = "#";
                if (Settings.Contains("txtBlogUrl"))
                {
                    url = Settings["txtBlogUrl"].ToString();
                }


                var articles = articlesRaw
                               .Select(c => new
                {
                    ID      = c.EntryID,
                    Title   = c.Title,
                    Created = c.AddedDate,
                    //ReadMoreHyperLink = "<a href='" + url + "/tabid/" + Request["tabid"] + "/article/" + c.EntryID.ToString() + "'>read more</a>",
                    //RawUrl = url + "/tabid/" + Request["tabid"] + "/article/" + c.EntryID.ToString(),
                    ReadMoreHyperLink = "<a href='" + url + "?article=" + c.EntryID.ToString() + "'>read more</a>",
                    RawUrl            = url + "?article=" + c.EntryID.ToString()
                }).ToList();


                rptRecentArticles.DataSource = articles;
                rptRecentArticles.DataBind();
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #15
0
        public static PostIndexTableRow PostToRow(Blog.Post post, BlogDataDataContext database)
        {
            PostIndexTableRow row = new PostIndexTableRow();

            var commandButtonLeftHtml = "";

            commandButtonLeftHtml += "<a href='Post/ViewId?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-search'></i></span></a>";
            commandButtonLeftHtml += "<a href='PostAdmin/Edit?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-pencil'></i></span></a>";
            commandButtonLeftHtml += "<div class='btn btn-default hl-view deletePostButton' postId='" + post.Id + "'><i class='fa fa-trash'></i></div>";

            row.Id        = commandButtonLeftHtml;
            row.Title     = post.Title;
            row.Timestamp = post.Timestamp.ToString();


            var databaseAuthor = database.Users.FirstOrDefault(x => x.Id == post.Author);

            if (databaseAuthor != null)
            {
                row.Author = databaseAuthor.PublicName;
            }

            string tagsTemp        = "";
            var    databaseTagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id);

            foreach (var tagMap in databaseTagMaps)
            {
                var databaseTag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp += "<a href='" + "#" + "'>" + databaseTag.Name + "</a>, ";
            }
            row.Tags = tagsTemp;

            string categoriesTemp       = "";
            var    databaseCategoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id);

            foreach (var categoryMap in databaseCategoryMaps)
            {
                var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp += "<a href='" + "#" + "'>" + databaseCategory.Name + "</a>, ";
            }
            row.Categories = categoriesTemp;

            row.Comments = database.PostCommentMaps.Count(x => x.PostId == post.Id).ToString();

            return(row);
        }
Exemple #16
0
        public static PostIndexTable GetTable(int page)
        {
            PostIndexTable           table = new PostIndexTable();
            List <PostIndexTableRow> rows  = new List <PostIndexTableRow>();

            using (BlogDataDataContext database = new BlogDataDataContext())
            {
                var posts = database.Posts.ToList().OrderByDescending(x => x.Timestamp).Skip((page - 1) * 10).Take(10);
                foreach (var post in posts)
                {
                    rows.Add(PostIndexTableRow.PostToRow(post, database));
                }
            }
            table.Rows = rows;

            return(table);
        }
Exemple #17
0
        public static PostEditModel PostEdit(string id)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            if (id.IsNullOrWhiteSpace())
            {
                Blog.Post post = new Blog.Post();
                post.Timestamp = DateTime.Now;
                PostEditModel model = new PostEditModel(post, "Add");
                return(model);
            }
            else
            {
                Blog.Post     post  = database.Posts.FirstOrDefault(x => x.Id == new Guid(id));
                PostEditModel model = new PostEditModel(post, "Edit");
                return(model);
            }
        }
Exemple #18
0
        public static Blog.User UserEditPost(UserEditModel model)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Blog.User databaseModel = database.Users.FirstOrDefault(x => x.Id == model.Id);

            if (databaseModel != null)
            {
                databaseModel.Username       = model.Username;
                databaseModel.Email          = model.Email;
                databaseModel.Role           = model.Role;
                databaseModel.FirstName      = model.FirstName;
                databaseModel.LastName       = model.LastName;
                databaseModel.Nickname       = model.Nickname;
                databaseModel.PublicName     = model.PublicName;
                databaseModel.Website        = model.Website;
                databaseModel.Biography      = model.Biography;
                databaseModel.ProfilePicture = model.ProfilePicture;
                databaseModel.Password       = model.Password;
            }
            else
            {
                databaseModel = new Blog.User();

                databaseModel.Id = Guid.NewGuid();

                databaseModel.Username       = model.Username;
                databaseModel.Email          = model.Email;
                databaseModel.Role           = model.Role;
                databaseModel.FirstName      = model.FirstName;
                databaseModel.LastName       = model.LastName;
                databaseModel.Nickname       = model.Nickname;
                databaseModel.PublicName     = model.PublicName;
                databaseModel.Website        = model.Website;
                databaseModel.Biography      = model.Biography;
                databaseModel.ProfilePicture = model.ProfilePicture;
                databaseModel.Password       = model.Password;

                database.Users.InsertOnSubmit(databaseModel);
            }
            database.SubmitChanges();

            return(databaseModel);
        }
Exemple #19
0
        public static PostIndexTableModel FromPost(Blog.Post post, BlogDataDataContext database)
        {
            var model = new PostIndexTableModel();

            var commandButtonLeftHtml = "";

            commandButtonLeftHtml += "<a href='Post/ViewId?id=" + post.Id.ToString() + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-search'></i></span></a>";
            commandButtonLeftHtml += "<a href='PostAdmin/Edit?id=" + post.Id.ToString() + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-pencil'></i></span></a>";
            commandButtonLeftHtml += "<div class='btn btn-default hl-view deletePostButton' postId='" + post.Id.ToString() + "'><i class='fa fa-trash'></i></div>";

            model.Id        = commandButtonLeftHtml;
            model.Title     = post.Title;
            model.Timestamp = post.Timestamp.ToString();

            /*
             * var databaseAuthor = database.Users.FirstOrDefault(x => x.Id == post.Author);
             * if (databaseAuthor != null)
             * {
             *  model.Author = databaseAuthor.PublicName;
             * }*/

            /*string tagsTemp = "";
             * var databaseTagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id);
             * foreach (var tagMap in databaseTagMaps)
             * {
             *  var databaseTag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
             *  tagsTemp += "<a href='" + "#" + "'>" + databaseTag.Name + "</a>, ";
             * }
             * model.Tags = tagsTemp; */
            /*
             * string categoriesTemp = "";
             * var databaseCategoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id);
             * foreach (var categoryMap in databaseCategoryMaps)
             * {
             *  var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
             *  categoriesTemp += "<a href='" + "#" + "'>" + databaseCategory.Name + "</a>, ";
             * }
             * model.Categories = categoriesTemp;
             */

            //model.Comments = database.PostCommentMaps.Count(x => x.PostId == post.Id).ToString();

            return(model);
        }
Exemple #20
0
        public static PostHomeFeaturedPost PostToFeaturedPost(Blog.Post post, BlogDataDataContext database)
        {
            PostHomeFeaturedPost featuredPost = new PostHomeFeaturedPost();

            string rootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";
            string postUrl = rootUrl + post.Slug;

            featuredPost.Title = post.Title;
            featuredPost.Url   = postUrl;

            string imageUrl = Regex.Match(post.Body, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;

            if (!String.IsNullOrEmpty(imageUrl) && !String.IsNullOrWhiteSpace(imageUrl))
            {
                featuredPost.FeaturedImageUrl = imageUrl;
            }

            return(featuredPost);
        }
Exemple #21
0
        public static PostIndexTableResultModel PostTable(HttpRequestBase Request)
        {
            string search   = Request.Form.GetValues("search[value]")[0];
            string draw     = Request.Form.GetValues("draw")[0];
            string order    = Request.Form.GetValues("order[0][column]")[0];
            string orderDir = Request.Form.GetValues("order[0][dir]")[0];
            int    startRec = Convert.ToInt32(Request.Form.GetValues("start")[0]);
            int    pageSize = Convert.ToInt32(Request.Form.GetValues("length")[0]);

            List <PostIndexTableModel> postsTable = new List <PostIndexTableModel>();

            using (BlogDataDataContext database = new BlogDataDataContext())
            {
                var posts = database.Posts.ToList();

                foreach (var post in posts)
                {
                    postsTable.Add(FromPost(post, database));
                }
            }

            int totalRecords = postsTable.Count;

            if (!string.IsNullOrEmpty(search) && !string.IsNullOrWhiteSpace(search))
            {
                postsTable = postsTable.Where(x =>
                                              (x.Title != null ? x.Title.ToLower() : "").Contains(search.ToLower()) ||
                                              (x.Author != null ? x.Author.ToLower() : "").Contains(search.ToLower()) ||
                                              (x.Categories != null ? x.Categories.ToLower() : "").Contains(search.ToLower()) ||
                                              (x.Tags != null ? x.Tags.ToLower() : "").Contains(search.ToLower()) ||
                                              (x.Comments != null ? x.Comments.ToLower() : "").Contains(search.ToLower()) ||
                                              (x.Timestamp != null ? x.Timestamp.ToLower() : "").Contains(search.ToLower())
                                              ).ToList();
            }

            postsTable = SortByColumnWithOrder(order, orderDir, postsTable);

            int recFilter = postsTable.Count;

            postsTable = postsTable.Skip(startRec).Take(pageSize).ToList();

            return(new PostIndexTableResultModel(Convert.ToInt32(draw), totalRecords, recFilter, postsTable));
        }
Exemple #22
0
        public ActionResult WyswietlPostData(string data)
        {
            int year  = int.Parse(data.Substring(0, 4));
            int month = int.Parse(data.Substring(5, 2));
            int day   = int.Parse(data.Substring(8, 2));

            DateTime data2 = new DateTime(year, month, day);

            var _db = new BlogDataDataContext();

            var posts = from m in db.Posts where m.data_dodania.Date == data2.Date
                        select m;



            return(View(posts));

            /*ViewData["data"] = data2;
             * return View();*/
        }
Exemple #23
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //Implement your edit logic for your module
                if (!Page.IsPostBack)
                {
                    BlogDataDataContext db = new BlogDataDataContext();
                    var articles           = db.Blog_Entries.Where(c => c.Blog_Blog.PortalID == PortalId).ToList();

                    ddlArticles.DataSource     = articles.Select(c => new { Name = c.Title + " (" + c.AddedDate.ToShortDateString() + ")", ID = c.EntryID, c.AddedDate }).OrderByDescending(c => c.AddedDate).ToList();
                    ddlArticles.DataTextField  = "Name";
                    ddlArticles.DataValueField = "ID";
                    ddlArticles.DataBind();
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #24
0
        public static Blog.Post PostEditPost(PostEditModel model)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Blog.Post databaseModel = database.Posts.FirstOrDefault(x => x.Id == model.Id);

            if (databaseModel != null)
            {
                databaseModel.Title           = model.Title;
                databaseModel.Body            = model.Body;
                databaseModel.Author          = new Guid("cebe8069-bd64-4dc9-8622-d3de189287b1"); // todo: get current user id
                databaseModel.Timestamp       = Convert.ToDateTime(model.Timestamp);
                databaseModel.CommentsEnabled = model.CommentsEnabled;
                databaseModel.Status          = model.Status;
                databaseModel.Visibility      = model.Visibility;
                databaseModel.FeaturedImage   = model.FeaturedImage;
                databaseModel.Slug            = model.Slug;
            }
            else
            {
                databaseModel = new Blog.Post();

                databaseModel.Id = Guid.NewGuid();

                databaseModel.Title           = model.Title;
                databaseModel.Body            = model.Body;
                databaseModel.Author          = new Guid("cebe8069-bd64-4dc9-8622-d3de189287b1"); // todo: get current user id
                databaseModel.Timestamp       = Convert.ToDateTime(model.Timestamp);
                databaseModel.CommentsEnabled = model.CommentsEnabled;
                databaseModel.Status          = model.Status;
                databaseModel.Visibility      = model.Visibility;
                databaseModel.FeaturedImage   = model.FeaturedImage;
                databaseModel.Slug            = model.Slug;

                database.Posts.InsertOnSubmit(databaseModel);
            }
            database.SubmitChanges();

            return(databaseModel);
        }
Exemple #25
0
        // todo: comments list

        public PostViewModel(Blog.Post post)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Id    = post.Id.ToString();
            Title = post.Title;
            Body  = post.Body;

            Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author);
            Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName);

            Dictionary <Guid, string>   categoriesTemp = new Dictionary <Guid, string>();
            List <Blog.PostCategoryMap> categoryMaps   = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var categoryMap in categoryMaps)
            {
                Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp.Add(category.Id, category.Name);
            }
            Categories = categoriesTemp;

            Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>();
            List <Blog.PostTagMap>    tagMaps  = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var tagMap in tagMaps)
            {
                Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp.Add(tag.Id, tag.Name);
            }
            Tags = tagsTemp;

            Timestamp       = post.Timestamp.ToString();
            CommentsEnabled = post.CommentsEnabled;
            Status          = post.Status;
            Visibility      = post.Visibility;
            Slug            = post.Slug;
        }
Exemple #26
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var t  = new Item();
            var tc = new ItemController();

            BlogDataDataContext db = new BlogDataDataContext();
            Blog_Entry          b  = new Blog_Entry();

            if (ddlArticles.SelectedValue != "0")
            {
                //edit
                b             = db.Blog_Entries.Where(c => c.EntryID == ArticleID).FirstOrDefault();
                b.Title       = txtTitle.Text;
                b.Entry       = txtBody.Text;
                b.Description = txtSummary.Text;
                b.Published   = chkPublished.Checked;
                db.SubmitChanges();
            }
            else
            {
                //new
                b.Title            = txtTitle.Text;
                b.Entry            = txtBody.Text;
                b.Description      = txtSummary.Text;
                b.Published        = chkPublished.Checked;
                b.AddedDate        = DateTime.Now;
                b.AllowComments    = false;
                b.BlogID           = Convert.ToInt32(Settings["BlogIDNum"].ToString());
                b.DisplayCopyright = true;
                b.PermaLink        = "n/a";

                db.Blog_Entries.InsertOnSubmit(b);
                db.SubmitChanges();
            }

            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL());
        }
Exemple #27
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //load blog data

                if (Settings.Contains("ddlBlogID"))
                {
                    int artQty = 10;
                    if (Settings.Contains("txtArticlesQty"))
                    {
                        int.TryParse(Settings["txtArticlesQty"].ToString(), out artQty);
                    }

                    int blogID = 0;
                    if (Settings.Contains("ddlBlogID"))
                    {
                        blogID = Convert.ToInt32(Settings["ddlBlogID"].ToString());
                    }

                    BlogDataDataContext db = new BlogDataDataContext();
                    var articlesRaw        = db.Blog_Entries.Where(c => c.BlogID == blogID && c.Published == true).OrderByDescending(c => c.AddedDate).Take(artQty).ToList();

                    string url = "#";
                    if (Settings.Contains("txtBlogUrl"))
                    {
                        url = Settings["txtBlogUrl"].ToString();
                    }


                    var articles = articlesRaw
                                   .Select(c => new
                    {
                        ID      = c.EntryID,
                        Title   = c.Title,
                        Created = c.AddedDate,
                        //ReadMoreHyperLink = "<a href='" + url + "/tabid/" + Request["tabid"] + "/article/" + c.EntryID.ToString() + "'>read more</a>",
                        //RawUrl = url + "/tabid/" + Request["tabid"] + "/article/" + c.EntryID.ToString(),

                        ReadMoreHyperLink = "<a class='blogReadMore' href='" + url + "?article=" + c.EntryID.ToString() + "'>read more</a>",
                        RawUrl            = url + "?article=" + c.EntryID.ToString(),

                        Body    = HttpUtility.HtmlDecode(c.Entry),
                        Summary = HtmlStrip_DescriptionOrBody(c.Description ?? "", c.Entry ?? "", 250)
                    }).ToList();



                    rptArticles.Visible          = false;
                    rptBlogArticleDetail.Visible = false;
                    btnBackToList.Visible        = false;

                    if (Request["article"] == null)
                    {
                        rptArticles.Visible    = true;
                        rptArticles.DataSource = articles;
                        rptArticles.DataBind();
                    }
                    else
                    {
                        articles = articles.Where(c => c.ID == Convert.ToInt32(Request["article"])).ToList();
                        rptBlogArticleDetail.Visible    = true;
                        rptBlogArticleDetail.DataSource = articles;
                        rptBlogArticleDetail.DataBind();
                        btnBackToList.Visible = true;
                    }
                }
                else
                {
                    lblMsg.Text = "Not setup - please open the module settings and specify a Blog ID #.";
                    return;
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemple #28
0
        public static PostHomeTableRow PostToRow(Blog.Post post, BlogDataDataContext database)
        {
            PostHomeTableRow row = new PostHomeTableRow();

            string rootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";
            string postUrl = rootUrl + post.Slug;

            var commandButtonLeftHtml = "";

            commandButtonLeftHtml += "<a href='Post/ViewId?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-search'></i></span></a>";
            commandButtonLeftHtml += "<a href='PostAdmin/Edit?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-pencil'></i></span></a>";
            commandButtonLeftHtml += "<div class='btn btn-default hl-view deletePostButton' postId='" + post.Id + "'><i class='fa fa-trash'></i></div>";

            row.Id        = commandButtonLeftHtml;
            row.Title     = "<a href='" + postUrl + "'>" + post.Title + "</a>";
            row.Timestamp = post.Timestamp.ToString();


            var databaseAuthor = database.Users.FirstOrDefault(x => x.Id == post.Author);

            if (databaseAuthor != null)
            {
                row.Author = databaseAuthor.PublicName;
            }

            var bodyText = ScrubHtml(post.Body);

            if (bodyText.Length > 300)
            {
                row.Body = bodyText.Substring(0, 300) + " ... <a href='" + postUrl + "'>[Read more...]</a>";
            }
            else
            {
                row.Body = bodyText + " ... <a href='" + postUrl + "'>[Read more...]</a>";
            }

            string tagsTemp        = "";
            var    databaseTagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id);

            foreach (var tagMap in databaseTagMaps)
            {
                var databaseTag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp += "<a href='" + "#" + "'>" + databaseTag.Name + "</a>, ";
            }
            row.Tags = tagsTemp;

            string categoriesTemp       = "";
            var    databaseCategoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id);

            foreach (var categoryMap in databaseCategoryMaps)
            {
                var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp += "<a href='" + "#" + "'>" + databaseCategory.Name + "</a>, ";
            }
            row.Categories = categoriesTemp;

            row.Comments = database.PostCommentMaps.Count(x => x.PostId == post.Id).ToString();

            string imageUrl = Regex.Match(post.Body, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value;

            if (!String.IsNullOrEmpty(imageUrl) && !String.IsNullOrWhiteSpace(imageUrl))
            {
                row.FeaturedImage = "<div class='center-cropped-home'><a href='" + postUrl + "'><img src='" + imageUrl + "'/></a></div>";
            }

            return(row);
        }
Exemple #29
0
        static void Main(string[] args)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            XNamespace excerptNamespace = "http://wordpress.org/export/1.2/excerpt/";
            XNamespace contentNamespace = "http://purl.org/rss/1.0/modules/content/";
            XNamespace wfwNamespace     = "http://wellformedweb.org/CommentAPI/";
            XNamespace dcNamespace      = "http://purl.org/dc/elements/1.1/";
            XNamespace wpNamespace      = "http://wordpress.org/export/1.2/";

            XElement inputFile = XElement.Load(@"C:\Users\wquade\Downloads\theprime.wordpress.2016-06-28_posts.xml");

            /* IEnumerable<XElement> authorElements = inputFile.Elements().Elements(wpNamespace + "author");
             * foreach (XElement authorElement in authorElements)
             * {
             *   User user = wpAuthor.AuthorToUser(new wpAuthor(authorElement));
             *   Console.WriteLine("Importing user: "******"item");

            foreach (var element in elements)
            {
                wpPost post = new wpPost(element);
                wpPost.ImportPost(post);
            }


            /*string inputFile = File.ReadAllText(@"C:\Users\wquade\Downloads\theprime.wordpress.2016-06-28_posts.xml");
             * var wordpressBlog = new Blog(inputFile);
             * Console.WriteLine("Blog title: " + wordpressBlog.Title);
             * Console.WriteLine("Blog description: " + wordpressBlog.Description);
             * wordpressBlog.Initialize();
             * foreach (var author in wordpressBlog.Authors)
             * {
             *  Console.WriteLine("Importing author: " + author.Username);
             *  var matchingDatabaseUser = database.Users.FirstOrDefault(x => x.Username == author.Username); // search database to see if username already exists
             *  if (matchingDatabaseUser == null) // user doesn't exist
             *  {
             *      User newUser = new User(); // add user to database
             *      newUser.Id = Guid.NewGuid();
             *      newUser.Username = author.Username;
             *      newUser.Email = author.Email;
             *      newUser.Role = "User";
             *      newUser.PublicName = newUser.Username;
             *      database.Users.InsertOnSubmit(newUser);
             *      database.SubmitChanges();
             *  }
             * }
             *
             * foreach (var tag in wordpressBlog.Tags)
             * {
             *  Console.WriteLine("Importing tag: " + tag.Slug);
             *  var matchingDatabaseTag = database.PostTags.FirstOrDefault(x => x.Slug == tag.Slug); // search database to see if tag already exists
             *  if (matchingDatabaseTag == null) // tag doesn't exist
             *  {
             *      PostTag newTag = new PostTag(); // add tag to the database
             *      newTag.Id = Guid.NewGuid();
             *      newTag.Name = tag.Slug;
             *      newTag.Slug = tag.Slug;
             *      database.PostTags.InsertOnSubmit(newTag);
             *      database.SubmitChanges();
             *  }
             * }
             *
             * foreach (var category in wordpressBlog.Categories)
             * {
             *  Console.WriteLine("Importing category: " + category.Slug);
             *  var matchingDatabaseCategory = database.PostCategories.FirstOrDefault(x => x.Slug == category.Slug); // search database to see if category already exists
             *  if (matchingDatabaseCategory == null) // category doesn't exist
             *  {
             *      PostCategory newCategory = new PostCategory(); // add category to the database
             *      newCategory.Id = Guid.NewGuid();
             *      newCategory.Slug = category.Slug;
             *      newCategory.Name = category.Name;
             *      database.PostCategories.InsertOnSubmit(newCategory);
             *      database.SubmitChanges();
             *  }
             * }
             *
             * var posts = wordpressBlog.GetPosts();
             * foreach (var post in posts)
             * {
             *  Console.WriteLine("Importing post: " + post.Title);
             *  var matchingDatabasePost = database.Posts.FirstOrDefault(x => x.Slug == post.Slug); // search database to see if post already exists
             *  if (matchingDatabasePost == null) // post doesn't eixst
             *  {
             *      Post newPost = new Post(); // add post to the database
             *      newPost.Id = Guid.NewGuid();
             *      newPost.Slug = post.Slug;
             *      newPost.Body = post.Body;
             *      newPost.Title = post.Title;
             *      newPost.Author = database.Users.FirstOrDefault(x => x.Username == post.Author.Username).Id;
             *      newPost.Timestamp = post.PublishedAtUtc.LocalDateTime; // todo: may need an offset
             *      foreach (var category in post.Categories)
             *      {
             *          var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Slug == category.Slug);
             *          if (databaseCategory != null)
             *          {
             *              PostCategoryMap map = new PostCategoryMap();
             *              map.PostId = newPost.Id;
             *              map.CategoryId = databaseCategory.Id;
             *              map.Id = Guid.NewGuid();
             *              database.PostCategoryMaps.InsertOnSubmit(map);
             *              database.SubmitChanges();
             *          }
             *      }
             *      foreach (var tag in post.Tags)
             *      {
             *          var databaseTag = database.PostTags.FirstOrDefault(x => x.Slug == tag.Slug);
             *          if (databaseTag != null)
             *          {
             *              PostTagMap map = new PostTagMap();
             *              map.PostId = newPost.Id;
             *              map.TagId = databaseTag.Id;
             *              map.Id = Guid.NewGuid();
             *              database.PostTagMaps.InsertOnSubmit(map);
             *              database.SubmitChanges();
             *          }
             *      }
             *      newPost.CommentsEnabled = false;
             *      newPost.Status = "Published";
             *      newPost.Visibility = "Public";
             *  }
             * }
             * Console.WriteLine("Done"); */
            Console.WriteLine("Done");
            Console.ReadKey();
        }
Exemple #30
0
        public static PostHomeTable GetTable(int page)
        {
            PostHomeTable table = new PostHomeTable();
            List <PostHomeFeaturedPost> featuredPosts = new List <PostHomeFeaturedPost>();
            List <PostHomeTableRow>     rows          = new List <PostHomeTableRow>();

            using (BlogDataDataContext database = new BlogDataDataContext())
            {
                var allPosts        = database.Posts.Where(x => x.Status == "publish" && x.Visibility == "Public").ToList().OrderByDescending(x => x.Timestamp);
                var firstThreePosts = allPosts.Take(3);
                foreach (var featuredPost in firstThreePosts)
                {
                    featuredPosts.Add(PostHomeFeaturedPost.PostToFeaturedPost(featuredPost, database));
                }

                var posts = allPosts.Skip((page - 1) * 10).Take(10);
                foreach (var post in posts)
                {
                    rows.Add(PostHomeTableRow.PostToRow(post, database));
                }
                table.Rows = rows;

                string rootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/";

                int    numberOfPages = (int)Math.Ceiling((double)allPosts.Count() / (double)10);
                string pagination    = "<ul class='pagination'>";
                if (page != 1)
                {
                    pagination += "<li><a href='" + rootUrl + "Page/" + (page - 1) + "'>« Previous Page</a></li>";
                    if ((page - 3) > 1)
                    {
                        pagination += "<li><a href='" + rootUrl + "Page/" + 1 + "'>1</a></li>";
                        pagination += "<li class='disabled'><a href='#'>...</a></li>";
                    }
                    else if (page == 4)
                    {
                        pagination += "<li><a href='" + rootUrl + "Page/" + 1 + "'>1</a></li>";
                    }
                }

                if ((page - 2) > 0)
                {
                    pagination += "<li><a href='" + rootUrl + "Page/" + (page - 2) + "'>" + (page - 2) + "</a></li>";
                }
                if ((page - 1) > 0)
                {
                    pagination += "<li><a href='" + rootUrl + "Page/" + (page - 1) + "'>" + (page - 1) + "</a></li>";
                }
                pagination += "<li class='active'><a href='" + rootUrl + "Page/" + (page) + "'>" + (page) + "</a></li>";
                if ((page + 1) < numberOfPages)
                {
                    pagination += "<li><a href='" + rootUrl + "Page/" + (page + 1) + "'>" + (page + 1) + "</a></li>";
                }
                if ((page + 2) < numberOfPages)
                {
                    pagination += "<li><a href='" + rootUrl + "Page/" + (page + 2) + "'>" + (page + 2) + "</a></li>";
                }

                if (page != numberOfPages)
                {
                    if ((page + 3) < numberOfPages)
                    {
                        pagination += "<li class='disabled'><a href='#'>...</a></li>";
                        pagination += "<li><a href='" + rootUrl + "Page/" + numberOfPages + "'>" + numberOfPages + "</a></li>";
                    }
                    else if (page == (numberOfPages - 1) || page == (numberOfPages - 2) || page == (numberOfPages - 3))
                    {
                        pagination += "<li><a href='" + rootUrl + "Page/" + numberOfPages + "'>" + numberOfPages + "</a></li>";
                    }
                    pagination += "<li><a href='" + rootUrl + "Page/" + (page + 1) + "'>Next Page »</a></li>";
                }

                pagination         += "</ul>";
                table.Pagination    = pagination;
                table.FeaturedPosts = featuredPosts;
            }


            return(table);
        }