Ejemplo n.º 1
0
        public void Save()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                bool bNew           = false;
                carrot_ContentTag s = CompiledQueries.cqGetContentTagByID(_db, this.ContentTagID);

                if (s == null || (s != null && s.ContentTagID == Guid.Empty))
                {
                    s = new carrot_ContentTag();
                    s.ContentTagID = Guid.NewGuid();
                    s.SiteID       = this.SiteID;
                    bNew           = true;
                }

                s.TagSlug  = ContentPageHelper.ScrubSlug(this.TagSlug);
                s.TagText  = this.TagText;
                s.IsPublic = this.IsPublic;

                if (bNew)
                {
                    _db.carrot_ContentTags.InsertOnSubmit(s);
                }

                _db.SubmitChanges();

                this.ContentTagID = s.ContentTagID;
            }
        }
Ejemplo n.º 2
0
        public void Save()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
                carrot_Site s = CompiledQueries.cqGetSiteByID(_db, this.SiteID);

                bool bNew = false;
                if (s == null)
                {
                    s = new carrot_Site();
                    if (this.SiteID == Guid.Empty)
                    {
                        this.SiteID = Guid.NewGuid();
                    }
                    bNew = true;
                }

                // if updating the current site then blank out its cache
                if (CurrentSiteID == this.SiteID)
                {
                    CurrentSite = null;
                }

                s.SiteID = this.SiteID;

                s.TimeZone = this.TimeZoneIdentifier;

                FixMeta();
                s.MetaKeyword     = this.MetaKeyword.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ").Replace("  ", " ");
                s.MetaDescription = this.MetaDescription.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ").Replace("  ", " ");

                s.SiteName            = this.SiteName;
                s.SiteTagline         = this.SiteTagline;
                s.SiteTitlebarPattern = this.SiteTitlebarPattern;
                s.MainURL             = this.MainURL;
                s.BlockIndex          = this.BlockIndex;
                s.SendTrackbacks      = this.SendTrackbacks;
                s.AcceptTrackbacks    = this.AcceptTrackbacks;

                s.Blog_FolderPath   = ContentPageHelper.ScrubSlug(this.Blog_FolderPath);
                s.Blog_CategoryPath = ContentPageHelper.ScrubSlug(this.Blog_CategoryPath);
                s.Blog_TagPath      = ContentPageHelper.ScrubSlug(this.Blog_TagPath);
                s.Blog_EditorPath   = ContentPageHelper.ScrubSlug(this.Blog_EditorPath);
                s.Blog_DatePath     = ContentPageHelper.ScrubSlug(this.Blog_DatePath);

                s.Blog_Root_ContentID = this.Blog_Root_ContentID;
                s.Blog_DatePattern    = String.IsNullOrEmpty(this.Blog_DatePattern) ? "yyyy/MM/dd" : this.Blog_DatePattern;

                if (bNew)
                {
                    _db.carrot_Sites.InsertOnSubmit(s);
                }
                _db.SubmitChanges();
            }
        }
Ejemplo n.º 3
0
		internal ContentCategory(vw_carrot_CategoryCounted c) {
			if (c != null) {
				this.ContentCategoryID = c.ContentCategoryID;
				this.SiteID = c.SiteID;
				this.CategorySlug = ContentPageHelper.ScrubSlug(c.CategorySlug);
				this.CategoryText = c.CategoryText;
				this.UseCount = c.UseCount;
				this.PublicUseCount = 1;
				this.IsPublic = c.IsPublic;

				SiteData site = SiteData.GetSiteFromCache(c.SiteID);
				if (site != null) {
					this.CategoryURL = ContentPageHelper.ScrubFilename(c.ContentCategoryID, String.Format("/{0}/{1}", site.BlogCategoryPath, c.CategorySlug));
				}
			}
		}
Ejemplo n.º 4
0
        internal ContentTag(carrot_ContentTag c)
        {
            if (c != null)
            {
                this.ContentTagID   = c.ContentTagID;
                this.SiteID         = c.SiteID;
                this.TagSlug        = ContentPageHelper.ScrubSlug(c.TagSlug);
                this.TagText        = c.TagText;
                this.IsPublic       = c.IsPublic;
                this.UseCount       = 1;
                this.PublicUseCount = 1;

                SiteData site = SiteData.GetSiteFromCache(c.SiteID);
                if (site != null)
                {
                    this.TagURL = ContentPageHelper.ScrubFilename(c.ContentTagID, String.Format("/{0}/{1}", site.BlogTagPath, c.TagSlug));
                }
            }
        }
Ejemplo n.º 5
0
        public WordPressSite GetAllData(XmlDocument doc)
        {
            WordPressSite site = new WordPressSite();

            List <WordPressPost>    lstWPP  = new List <WordPressPost>();
            List <WordPressComment> lstWPC  = new List <WordPressComment>();
            List <WordPressUser>    lstAuth = new List <WordPressUser>();

            XmlNode rssNode = doc.SelectSingleNode("//rss");

            XmlNamespaceManager rssNamespace = new XmlNamespaceManager(doc.NameTable);

            foreach (XmlAttribute attrib in rssNode.Attributes)
            {
                if (attrib != null && attrib.Value.ToLowerInvariant().StartsWith("http"))
                {
                    rssNamespace.AddNamespace(attrib.LocalName, attrib.Value);
                }
            }

            site.SiteTitle       = rssNode.SelectSingleNode("channel/title").InnerText;
            site.SiteDescription = rssNode.SelectSingleNode("channel/description").InnerText;
            site.SiteURL         = rssNode.SelectSingleNode("channel/link").InnerText;
            site.ImportSource    = rssNode.SelectSingleNode("channel/generator").InnerText;
            site.ExtractDate     = Convert.ToDateTime(rssNode.SelectSingleNode("channel/pubDate").InnerText);
            site.wxrVersion      = rssNode.SelectSingleNode("channel/wp:wxr_version", rssNamespace).InnerText;

            site.Categories = new List <InfoKVP>();

            XmlNodeList catNodes = doc.SelectNodes("//rss/channel/wp:category", rssNamespace);

            foreach (XmlNode node in catNodes)
            {
                string slug  = node.SelectSingleNode("wp:category_nicename", rssNamespace).InnerText;
                string title = node.SelectSingleNode("wp:cat_name", rssNamespace).InnerText;
                site.Categories.Add(new InfoKVP(slug, title));
            }
            catNodes = doc.SelectNodes("//rss/channel/item/category[@domain='category']");
            foreach (XmlNode node in catNodes)
            {
                if (node.Attributes["nicename"] != null)
                {
                    string slug  = node.Attributes["nicename"].InnerText;
                    string title = node.InnerText;
                    site.Categories.Add(new InfoKVP(slug, title));
                }
            }

            site.Tags = new List <InfoKVP>();

            XmlNodeList tagNodes = doc.SelectNodes("//rss/channel/wp:tag", rssNamespace);

            foreach (XmlNode node in tagNodes)
            {
                string slug  = node.SelectSingleNode("wp:tag_slug", rssNamespace).InnerText;
                string title = node.SelectSingleNode("wp:tag_name", rssNamespace).InnerText;
                site.Tags.Add(new InfoKVP(slug, title));
            }
            tagNodes = doc.SelectNodes("//rss/channel/item/category[@domain='post_tag']");
            foreach (XmlNode node in tagNodes)
            {
                if (node.Attributes["nicename"] != null)
                {
                    string slug  = node.Attributes["nicename"].InnerText;
                    string title = node.InnerText;
                    site.Tags.Add(new InfoKVP(slug, title));
                }
            }

            XmlNodeList rssAuthors = doc.SelectNodes("//rss/channel/wp:author", rssNamespace);

            foreach (XmlNode node in rssAuthors)
            {
                WordPressUser wpu = new WordPressUser();
                wpu.AuthorId = int.Parse(node.SelectSingleNode("wp:author_id", rssNamespace).InnerText);
                wpu.Login    = node.SelectSingleNode("wp:author_login", rssNamespace).InnerText;
                wpu.Email    = node.SelectSingleNode("wp:author_email", rssNamespace).InnerText;
                try { wpu.FirstName = node.SelectSingleNode("wp:author_first_name", rssNamespace).InnerText; } catch { }
                try { wpu.LastName = node.SelectSingleNode("wp:author_last_name", rssNamespace).InnerText; } catch { }
                wpu.ImportUserID = Guid.Empty;

                lstAuth.Add(wpu);
            }

            XmlNodeList nodes = doc.SelectNodes("//rss/channel/item");

            foreach (XmlNode node in nodes)
            {
                WordPressPost wpp = new WordPressPost();
                wpp.PostType     = WordPressPost.WPPostType.Unknown;
                wpp.IsPublished  = false;
                wpp.PostOrder    = 0;
                wpp.ImportRootID = Guid.NewGuid();

                wpp.PostTitle = node.SelectSingleNode("title").InnerText.Trim();
                wpp.PostName  = node.SelectSingleNode("wp:post_name", rssNamespace).InnerText.Trim();

                if (string.IsNullOrEmpty(wpp.PostName))
                {
                    wpp.PostName = wpp.PostTitle.ToLowerInvariant();
                }
                if (string.IsNullOrEmpty(wpp.PostName))
                {
                    wpp.PostName = wpp.ImportRootID.ToString().ToLowerInvariant();
                }
                if (string.IsNullOrEmpty(wpp.PostTitle))
                {
                    wpp.PostTitle = "(No Title)";
                }

                wpp.PostName = ContentPageHelper.ScrubSlug(wpp.PostName);

                wpp.PostAuthor = node.SelectSingleNode("dc:creator", rssNamespace).InnerText;

                string postType = node.SelectSingleNode("wp:post_type", rssNamespace).InnerText;

                switch (postType)
                {
                case "attachment":
                    wpp.PostType = WordPressPost.WPPostType.Attachment;
                    break;

                case "post":
                    wpp.PostType = WordPressPost.WPPostType.BlogPost;
                    break;

                case "page":
                    wpp.PostType = WordPressPost.WPPostType.Page;
                    break;
                }

                if (wpp.PostName.Length > 200 && wpp.PostType == WordPressPost.WPPostType.Page)
                {
                    wpp.PostName = wpp.PostName.Substring(0, 175).Trim();
                }
                if (wpp.PostName.Length > 255 && (wpp.PostType == WordPressPost.WPPostType.BlogPost || wpp.PostType == WordPressPost.WPPostType.Attachment))
                {
                    wpp.PostName = wpp.PostName.Substring(0, 250).Trim();
                }

                wpp.PostDateUTC = DateTime.UtcNow;
                try { wpp.PostDateUTC = Convert.ToDateTime(node.SelectSingleNode("wp:post_date", rssNamespace).InnerText); } catch { }
                try { wpp.PostDateUTC = Convert.ToDateTime(node.SelectSingleNode("wp:post_date_gmt", rssNamespace).InnerText); } catch { }

                wpp.PostContent = node.SelectSingleNode("content:encoded", rssNamespace).InnerText;

                if (node.SelectSingleNode("wp:attachment_url", rssNamespace) != null)
                {
                    wpp.AttachmentURL = node.SelectSingleNode("wp:attachment_url", rssNamespace).InnerText;
                }

                wpp.ImportFileSlug = ContentPageHelper.ScrubFilename(wpp.ImportRootID, "/" + wpp.PostName.Trim() + ".aspx");
                wpp.ImportFileName = ContentPageHelper.ScrubFilename(wpp.ImportRootID, wpp.ImportFileSlug);

                if (wpp.PostType == WordPressPost.WPPostType.Attachment)
                {
                    wpp.ImportFileSlug = wpp.AttachmentURL.Substring(wpp.AttachmentURL.LastIndexOf("/")).Replace("//", "/").Trim();
                    wpp.ImportFileName = wpp.ImportFileSlug;

                    if (node.SelectSingleNode("excerpt:encoded", rssNamespace) != null)
                    {
                        wpp.PostTitle = node.SelectSingleNode("excerpt:encoded", rssNamespace).InnerText;
                    }
                    if (node.SelectSingleNode("content:encoded", rssNamespace) != null)
                    {
                        wpp.PostContent = node.SelectSingleNode("content:encoded", rssNamespace).InnerText;
                    }
                }

                if (string.IsNullOrEmpty(wpp.PostContent))
                {
                    wpp.PostContent = "";
                }
                wpp.PostContent = wpp.PostContent.Replace("\r\n", "\n").Trim();

                wpp.ParentPostID = int.Parse(node.SelectSingleNode("wp:post_parent", rssNamespace).InnerText);
                wpp.PostID       = int.Parse(node.SelectSingleNode("wp:post_id", rssNamespace).InnerText);
                wpp.PostOrder    = int.Parse(node.SelectSingleNode("wp:menu_order", rssNamespace).InnerText);

                if (node.SelectSingleNode("wp:status", rssNamespace).InnerText == "publish")
                {
                    wpp.IsPublished = true;
                }

                if (wpp.PostType == WordPressPost.WPPostType.BlogPost ||
                    (wpp.PostType == WordPressPost.WPPostType.Page && wpp.ParentPostID > 0))
                {
                    wpp.PostOrder = wpp.PostOrder + 10;
                }

                wpp.Categories = new List <string>();
                XmlNodeList nodesCat = node.SelectNodes("category[@domain='category']");
                foreach (XmlNode n in nodesCat)
                {
                    if (n.Attributes["nicename"] != null)
                    {
                        wpp.Categories.Add(n.Attributes["nicename"].Value);
                    }
                }

                wpp.Tags = new List <string>();
                XmlNodeList nodesTag = node.SelectNodes("category[@domain='post_tag']");
                foreach (XmlNode n in nodesTag)
                {
                    if (n.Attributes["nicename"] != null)
                    {
                        wpp.Tags.Add(n.Attributes["nicename"].Value);
                    }
                }

                wpp.CleanBody();

                lstWPP.Add(wpp);

                //=================
                XmlNodeList nodesC = node.SelectNodes("wp:comment", rssNamespace);
                foreach (XmlNode nodeC in nodesC)
                {
                    WordPressComment wpc = new WordPressComment();
                    wpc.ImportRootID   = Guid.Empty;
                    wpc.PostID         = wpp.PostID;
                    wpc.CommentID      = int.Parse(nodeC.SelectSingleNode("wp:comment_id", rssNamespace).InnerText);
                    wpc.Author         = nodeC.SelectSingleNode("wp:comment_author", rssNamespace).InnerText;
                    wpc.AuthorIP       = nodeC.SelectSingleNode("wp:comment_author_IP", rssNamespace).InnerText;
                    wpc.AuthorEmail    = nodeC.SelectSingleNode("wp:comment_author_email", rssNamespace).InnerText;
                    wpc.AuthorURL      = nodeC.SelectSingleNode("wp:comment_author_url", rssNamespace).InnerText;
                    wpc.CommentContent = nodeC.SelectSingleNode("wp:comment_content", rssNamespace).InnerText;

                    wpc.Approved = nodeC.SelectSingleNode("wp:comment_approved", rssNamespace).InnerText;
                    wpc.Type     = nodeC.SelectSingleNode("wp:comment_type", rssNamespace).InnerText;

                    wpc.CommentDateUTC = DateTime.UtcNow;
                    try { wpc.CommentDateUTC = Convert.ToDateTime(nodeC.SelectSingleNode("wp:comment_date", rssNamespace).InnerText); } catch { }
                    try { wpc.CommentDateUTC = Convert.ToDateTime(nodeC.SelectSingleNode("wp:comment_date_gmt", rssNamespace).InnerText); } catch { }

                    lstWPC.Add(wpc);
                }
            }

            foreach (WordPressPost w in lstWPP.Where(x => x.ParentPostID > 0 && x.PostType == WordPressPost.WPPostType.Page))
            {
                if (lstWPP.Where(x => x.PostID == w.ParentPostID &&
                                 x.PostType == WordPressPost.WPPostType.Page).Count() > 0)
                {
                    WordPressPost p = lstWPP.Where(x => x.PostID == w.ParentPostID).FirstOrDefault();
                    w.ImportFileName = "/" + p.PostName.Trim() + w.ImportFileSlug;
                }
            }

            site.Content  = lstWPP;
            site.Comments = lstWPC;
            site.Authors  = lstAuth;

            return(site);
        }
Ejemplo n.º 6
0
        public void Save()
        {
            using (CarrotCMSDataContext _db = CarrotCMSDataContext.GetDataContext()) {
                SiteData site = SiteData.GetSiteFromCache(this.SiteID);

                carrot_RootContentSnippet rc = CompiledQueries.cqGetSnippetDataTbl(_db, this.SiteID, this.Root_ContentSnippetID);

                carrot_ContentSnippet oldC = CompiledQueries.cqGetLatestSnippetContentTbl(_db, this.SiteID, this.Root_ContentSnippetID);

                bool bNew = false;

                if (rc == null)
                {
                    rc = new carrot_RootContentSnippet();
                    rc.Root_ContentSnippetID = Guid.NewGuid();
                    rc.SiteID = site.SiteID;

                    rc.CreateDate = DateTime.UtcNow;
                    if (this.CreateUserId != Guid.Empty)
                    {
                        rc.CreateUserId = this.CreateUserId;
                    }
                    else
                    {
                        rc.CreateUserId = SecurityData.CurrentUserGuid;
                    }

                    _db.carrot_RootContentSnippets.InsertOnSubmit(rc);
                    bNew = true;
                }

                this.ContentSnippetSlug = ContentPageHelper.ScrubSlug(this.ContentSnippetSlug);

                rc.ContentSnippetActive = this.ContentSnippetActive;
                rc.ContentSnippetName   = this.ContentSnippetName;
                rc.ContentSnippetSlug   = this.ContentSnippetSlug;

                rc.GoLiveDate = site.ConvertSiteTimeToUTC(this.GoLiveDate);
                rc.RetireDate = site.ConvertSiteTimeToUTC(this.RetireDate);

                carrot_ContentSnippet c = new carrot_ContentSnippet();
                c.ContentSnippetID      = Guid.NewGuid();
                c.Root_ContentSnippetID = rc.Root_ContentSnippetID;
                c.IsLatestVersion       = true;

                if (!bNew)
                {
                    oldC.IsLatestVersion = false;
                }

                c.EditDate = DateTime.UtcNow;
                if (this.EditUserId != Guid.Empty)
                {
                    c.EditUserId = this.EditUserId;
                }
                else
                {
                    c.EditUserId = SecurityData.CurrentUserGuid;
                }

                c.ContentBody = this.ContentBody;

                rc.Heartbeat_UserId = c.EditUserId;
                rc.EditHeartbeat    = DateTime.UtcNow;

                _db.carrot_ContentSnippets.InsertOnSubmit(c);

                _db.SubmitChanges();

                this.ContentSnippetID      = c.ContentSnippetID;
                this.Root_ContentSnippetID = rc.Root_ContentSnippetID;
            }
        }