示例#1
0
        public virtual ActionResult Add(Piranha.Models.Comment model)
        {
            if (ModelState.IsValid)
            {
                using (var api = new Api()) {
                    model.IP         = HttpContext.Request.UserHostAddress;
                    model.UserAgent  = HttpContext.Request.UserAgent.Substring(0, Math.Min(HttpContext.Request.UserAgent.Length, 128));
                    model.SessionID  = Session.SessionID;
                    model.IsApproved = true;
                    if (User.Identity.IsAuthenticated)
                    {
                        model.UserId = User.Identity.Name;
                    }

                    if (User.Identity.IsAuthenticated && Config.Comments.ModerateAuthorized)
                    {
                        model.IsApproved = false;
                    }
                    else if (!User.Identity.IsAuthenticated && Config.Comments.ModerateAnonymous)
                    {
                        model.IsApproved = false;
                    }

                    api.Comments.Add(model);
                    api.SaveChanges();
                }
                var post = PostModel.GetById(model.PostId);

                return(Redirect("~/" + post.Type + "/" + post.Slug));
            }
            return(null);
        }
示例#2
0
        public async Task <IActionResult> Seed()
        {
            // Get the default site
            var site = await _api.Sites.GetDefaultAsync();

            site.SiteTypeId = nameof(BlogSite);
            await _api.Sites.SaveAsync(site);

            // Add media assets
            var bannerId = Guid.NewGuid();

            using (var stream = System.IO.File.OpenRead("seed/pexels-photo-355423.jpeg"))
            {
                await _api.Media.SaveAsync(new Piranha.Models.StreamMediaContent()
                {
                    Id       = bannerId,
                    Filename = "pexels-photo-355423.jpeg",
                    Data     = stream
                });
            }
            var banner = await _api.Media.GetByIdAsync(bannerId);

            var logoId = Guid.NewGuid();

            using (var stream = System.IO.File.OpenRead("seed/logo.png"))
            {
                await _api.Media.SaveAsync(new Piranha.Models.StreamMediaContent()
                {
                    Id       = logoId,
                    Filename = "logo.png",
                    Data     = stream
                });
            }

            // Add the site info
            var blogSite = await BlogSite.CreateAsync(_api);

            blogSite.Information.SiteLogo  = logoId;
            blogSite.Information.SiteTitle = "Piranha CMS";
            blogSite.Information.Tagline   = "A lightweight & unobtrusive CMS for Asp.NET Core.";
            await _api.Sites.SaveContentAsync(site.Id, blogSite);

            // Add the blog archive
            var blogId   = Guid.NewGuid();
            var blogPage = await BlogArchive.CreateAsync(_api);

            blogPage.Id              = blogId;
            blogPage.SiteId          = site.Id;
            blogPage.Title           = "Blog Archive";
            blogPage.MetaKeywords    = "Inceptos, Tristique, Pellentesque, Lorem, Vestibulum";
            blogPage.MetaDescription = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros.";
            blogPage.NavigationTitle = "Blog";
            blogPage.Published       = DateTime.Now;

            await _api.Pages.SaveAsync(blogPage);

            // Add a blog post
            var post = await BlogPost.CreateAsync(_api);

            post.BlogId   = blogPage.Id;
            post.Category = "Piranha CMS";
            post.Tags.Add("Welcome", "Fresh Start", "Information");
            post.Title             = "Welcome to Piranha CMS!";
            post.MetaKeywords      = "Welcome, Piranha CMS, AspNetCore, MVC, .NET Core";
            post.MetaDescription   = "Piranha is the fun, fast and lightweight framework for developing cms-based web applications with ASP.Net Core.";
            post.Hero.PrimaryImage = bannerId;
            post.Hero.Ingress      = "<p>Piranha CMS is a <strong>lightweight</strong>, <strong>cross-platform</strong> CMS <string>library</string> for <code>NetStandard 2.0</code>, <code>.NET Core</code> & <code>Entity Framework Core</code>. It can be used to add CMS functionality to your existing application or to build a new website from scratch. It has an extensible & pluggable architecture that can support a wide variety of runtime scenarios.</p>";
            post.Blocks.Add(new HtmlBlock
            {
                Body = "<p>Piranha CMS is a <strong>lightweight</strong>, <strong>cross-platform</strong> CMS <string>library</string> for <code>NetStandard 2.0</code>, <code>.NET Core</code> & <code>Entity Framework Core</code>. It can be used to add CMS functionality to your existing application or to build a new website from scratch. It has an extensible & pluggable architecture that can support a wide variety of runtime scenarios.</p><p>Piranha CMS is totally <strong>package based</strong> and available on <code>NuGet</code>. You can read more about the different packages available in the documentation.</p>"
            });
            post.Blocks.Add(new HtmlBlock
            {
                Body = "<h2>Getting Started</h2><p>To log into the manager interface and start writing content simply go the URL <code>/manager</code> and login with <code>admin</code> / <code>password</code> as your username and password.</p>"
            });
            post.Blocks.Add(new HtmlBlock
            {
                Body = "<h2>Licensing</h2><p>Piranha CMS is released under the <strong>MIT</strong> license. It is a permissive free software license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms and the copyright notice.</p>"
            });
            post.Published = DateTime.Now;
            await _api.Posts.SaveAsync(post);

            var comment = new Piranha.Models.Comment
            {
                Author     = "Håkan Edling",
                Email      = "*****@*****.**",
                Url        = "http://piranhacms.org",
                Body       = "Awesome to see that the project is up and running! Now maybe it's time to start customizing it to your needs. You can find a lot of information in the official docs.",
                IsApproved = true
            };
            await _api.Posts.SaveCommentAsync(post.Id, comment);

            // Add about page
            var page = await StandardPage.CreateAsync(_api);

            page.SiteId          = site.Id;
            page.SortOrder       = 1;
            page.Title           = "About Me";
            page.MetaKeywords    = "Inceptos, Tristique, Pellentesque, Lorem, Vestibulum";
            page.MetaDescription = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros.";
            page.Blocks.Add(new HtmlBlock
            {
                Body = "<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Donec sed odio dui. Vestibulum id ligula porta felis euismod semper. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla.</p>"
            });
            page.Blocks.Add(new QuoteBlock
            {
                Body = "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod."
            });
            page.Blocks.Add(new ColumnBlock
            {
                Items = new List <Block>
                {
                    new HtmlBlock
                    {
                        Body = $"<p><img src=\"{banner.PublicUrl.Replace("~", "")}\"></p>"
                    },
                    new HtmlBlock
                    {
                        Body = "<p>Maecenas faucibus mollis interdum. Aenean lacinia bibendum nulla sed consectetur. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.</p>"
                    }
                }
            });
            page.Published = DateTime.Now;
            await _api.Pages.SaveAsync(page);

            return(Redirect("~/"));
        }
示例#3
0
        public static async Task RunAsync(IApi api)
        {
            if ((await api.Pages.GetStartpageAsync()) == null)
            {
                var images = new dynamic []
                {
                    new { id = Guid.NewGuid(), filename = "screenshot2.png" },
                    new { id = Guid.NewGuid(), filename = "logo.png" },
                    new { id = Guid.NewGuid(), filename = "teaser1.png" },
                    new { id = Guid.NewGuid(), filename = "teaser2.png" },
                    new { id = Guid.NewGuid(), filename = "teaser3.png" },
                    new { id = Guid.NewGuid(), filename = "drifter1.png" },
                    new { id = Guid.NewGuid(), filename = "drifter2.jpg" },
                };

                // Create secondary language
                var lang2Id = Guid.NewGuid();
                await api.Languages.SaveAsync(new Piranha.Models.Language
                {
                    Id      = lang2Id,
                    Title   = "Swedish",
                    Culture = "sv-SE"
                });

                // Get the default site id
                var siteId  = (await api.Sites.GetDefaultAsync()).Id;
                var site2Id = Guid.NewGuid();

                await api.Sites.SaveAsync(new Piranha.Models.Site
                {
                    Id         = site2Id,
                    LanguageId = lang2Id,
                    Title      = "Swedish",
                    Culture    = "sv-SE"
                });

                // Upload images
                foreach (var image in images)
                {
                    using (var stream = File.OpenRead("seed/" + image.filename))
                    {
                        await api.Media.SaveAsync(new Piranha.Models.StreamMediaContent
                        {
                            Id       = image.id,
                            Filename = image.filename,
                            Data     = stream
                        });
                    }
                }

                var content = await Models.StandardProduct.CreateAsync(api).ConfigureAwait(false);

                content.Title    = "My content";
                content.Category = "Uncategorized";
                content.Tags.Add("Lorem");
                content.Tags.Add("Ipsum");
                content.AllFields.Date = DateTime.Now;
                content.AllFields.Text = "Lorum ipsum";
                await api.Content.SaveAsync(content);

                content.Title          = "Mitt innehåll";
                content.AllFields.Text = "Svenskum dansum";
                await api.Content.SaveAsync(content, lang2Id);

                var loadedContent = await api.Content.GetByIdAsync <Models.StandardProduct>(content.Id);

                var swedishContent = await api.Content.GetByIdAsync <Models.StandardProduct>(content.Id, lang2Id);

                var infoContent = await api.Content.GetByIdAsync <Piranha.Models.ContentInfo>(content.Id, lang2Id);

                var dynamicSwedish = await api.Content.GetByIdAsync(content.Id, lang2Id);

                var allContent = await api.Content.GetAllAsync();

                // Create the start page
                var startpage = await Models.TeaserPage.CreateAsync(api).ConfigureAwait(false);

                startpage.SiteId          = siteId;
                startpage.Title           = "Piranha CMS - Open Source, Cross Platform Asp.NET Core CMS";
                startpage.NavigationTitle = "Home";
                startpage.MetaKeywords    = "Piranha, Piranha CMS, CMS, AspNetCore, DotNetCore, MVC, .NET, .NET Core";
                startpage.MetaDescription = "Piranha is the fun, fast and lightweight framework for developing cms-based web applications with AspNetCore.";

                // Start page hero
                startpage.Hero.Subtitle     = "By developers - for developers";
                startpage.Hero.PrimaryImage = images[1].id;
                startpage.Hero.Ingress      =
                    "<p>A lightweight & unobtrusive CMS for ASP.NET Core.</p>" +
                    "<p><small>Stable version 6.1.0 - 2019-05-01 - <a href=\"https://github.com/piranhacms/piranha.core/wiki/changelog\" target=\"_blank\">Changelog</a></small></p>";

                // Teasers
                startpage.Teasers.Add(new Models.Regions.Teaser
                {
                    Title = "Cross Platform",
                    Image = images[2].id,
                    Body  = "<p>Built for <code>NetStandard</code> and <code>AspNet Core</code>, Piranha CMS can be run on Windows, Linux and Mac OS X.</p>"
                });
                startpage.Teasers.Add(new Models.Regions.Teaser
                {
                    Title = "Super Fast",
                    Image = images[3].id,
                    Body  = "<p>Designed from the ground up for super-fast performance using <code>EF Core</code> and optional Caching.</p>"
                });
                startpage.Teasers.Add(new Models.Regions.Teaser
                {
                    Title = "Open Source",
                    Image = images[4].id,
                    Body  = "<p>Everything is Open Source and released under the <code>MIT</code> license for maximum flexibility.</p>"
                });

                // Start page blocks
                startpage.Blocks.Add(new ImageBlock
                {
                    Body = images[0].id
                });
                using (var stream = File.OpenRead("seed/startpage1.md"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        startpage.Blocks.Add(new HtmlBlock
                        {
                            Body = App.Markdown.Transform(reader.ReadToEnd())
                        });
                    }
                }
                startpage.Blocks.Add(new ImageGalleryBlock
                {
                    Items =
                    {
                        new ImageBlock
                        {
                            Body = images[5].id
                        },
                        new ImageBlock
                        {
                            Body = images[6].id
                        }
                    }
                });
                startpage.Blocks.Add(new ColumnBlock
                {
                    Items =
                    {
                        new ImageBlock
                        {
                            Body = images[6].id
                        },
                        new HtmlBlock
                        {
                            Body = "<h3>Ornare Mattis Vulputate</h3><p>Nullam id dolor id nibh ultricies vehicula ut id elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam quis risus eget urna mollis ornare vel eu leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>"
                        },
                        new ImageBlock
                        {
                            Body = images[5].id
                        }
                    }
                });
                using (var stream = File.OpenRead("seed/startpage2.md"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        startpage.Blocks.Add(new HtmlBlock
                        {
                            Body = App.Markdown.Transform(reader.ReadToEnd())
                        });
                    }
                }
                startpage.Published = DateTime.Now;
                await api.Pages.SaveAsync(startpage);

                startpage.Id     = Guid.NewGuid();
                startpage.SiteId = site2Id;
                await api.Pages.SaveAsync(startpage);

                // Features page
                var featurespage = await Models.StandardPage.CreateAsync(api);

                featurespage.SiteId    = siteId;
                featurespage.Title     = "Features";
                featurespage.Route     = "/pagewide";
                featurespage.SortOrder = 1;

                // Features hero
                featurespage.Hero.Subtitle = "Features";
                featurespage.Hero.Ingress  = "<p>It's all about who has the sharpest teeth in the pond.</p>";

                // Features blocks
                using (var stream = File.OpenRead("seed/features.md"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var body = reader.ReadToEnd();

                        foreach (var section in body.Split("%"))
                        {
                            var blocks = section.Split("@");

                            for (var n = 0; n < blocks.Length; n++)
                            {
                                var cols = blocks[n].Split("|");

                                if (cols.Length == 1)
                                {
                                    featurespage.Blocks.Add(new HtmlBlock
                                    {
                                        Body = App.Markdown.Transform(cols[0].Trim())
                                    });
                                }
                                else
                                {
                                    featurespage.Blocks.Add(new ColumnBlock
                                    {
                                        Items =
                                        {
                                            new HtmlBlock
                                            {
                                                Body = App.Markdown.Transform(cols[0].Trim())
                                            },
                                            new HtmlBlock
                                            {
                                                Body = App.Markdown.Transform(cols[1].Trim())
                                            }
                                        }
                                    });

                                    if (n < blocks.Length - 1)
                                    {
                                        featurespage.Blocks.Add(new SeparatorBlock());
                                    }
                                }
                            }
                        }
                    }
                }
                featurespage.Published = DateTime.Now;
                await api.Pages.SaveAsync(featurespage);

                // Blog Archive
                var blogpage = await Models.BlogArchive.CreateAsync(api);

                blogpage.Id              = Guid.NewGuid();
                blogpage.SiteId          = siteId;
                blogpage.Title           = "Blog Archive";
                blogpage.NavigationTitle = "Blog";
                blogpage.SortOrder       = 2;
                blogpage.MetaKeywords    = "Piranha, Piranha CMS, CMS, AspNetCore, DotNetCore, MVC, Blog, News";
                blogpage.MetaDescription = "Read the latest blog posts about Piranha, fast and lightweight framework for developing cms-based web applications with AspNetCore.";

                // Blog Hero
                blogpage.Hero.Subtitle = "Blog Archive";
                blogpage.Hero.Ingress  = "<p>Welcome to the blog, the best place to stay up to date with what's happening in the Piranha infested waters.</p>";

                blogpage.Published = DateTime.Now;
                await api.Pages.SaveAsync(blogpage);

                // Blog Post
                var blogpost = await Models.BlogPost.CreateAsync(api);

                blogpost.BlogId   = blogpage.Id;
                blogpost.Title    = "What is Piranha";
                blogpost.Excerpt  = "Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Nulla vitae elit libero, a pharetra augue. Etiam porta sem malesuada magna mollis euismod. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.";
                blogpost.Category = "Piranha CMS";
                blogpost.Tags.Add("welcome");

                using (var stream = File.OpenRead("seed/blogpost.md"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var body = reader.ReadToEnd();

                        foreach (var block in body.Split("@"))
                        {
                            blogpost.Blocks.Add(new HtmlBlock
                            {
                                Body = App.Markdown.Transform(block.Trim())
                            });
                        }
                    }
                }
                blogpost.Published = DateTime.Now;
                await api.Posts.SaveAsync(blogpost);

                // Add some comments
                var comment = new Piranha.Models.Comment
                {
                    Author     = "Håkan Edling",
                    Email      = "*****@*****.**",
                    Url        = "http://piranhacms.org",
                    Body       = "Awesome to see that the project is up and running! Now maybe it's time to start customizing it to your needs. You can find a lot of information in the official docs.",
                    IsApproved = true
                };
                await api.Posts.SaveCommentAsync(blogpost.Id, comment);

                comment.Id         = Guid.Empty;
                comment.IsApproved = false;

                await api.Pages.SaveCommentAsync(featurespage.Id, comment);

                // Unpublished Post
                blogpost = await Models.BlogPost.CreateAsync(api);

                blogpost.BlogId   = blogpage.Id;
                blogpost.Title    = "What is Piranha unpublished";
                blogpost.Category = "Piranha CMS";
                blogpost.Tags.Add("welcome");

                using (var stream = File.OpenRead("seed/blogpost.md"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var body = reader.ReadToEnd();

                        foreach (var block in body.Split("@"))
                        {
                            blogpost.Blocks.Add(new HtmlBlock
                            {
                                Body = App.Markdown.Transform(block.Trim())
                            });
                        }
                    }
                }
                await api.Posts.SaveAsync(blogpost);

                // Scheduled Post
                blogpost = await Models.BlogPost.CreateAsync(api);

                blogpost.BlogId   = blogpage.Id;
                blogpost.Title    = "What is Piranha scheduled";
                blogpost.Category = "Another category";
                blogpost.Tags.Add("welcome");

                using (var stream = File.OpenRead("seed/blogpost.md"))
                {
                    using (var reader = new StreamReader(stream))
                    {
                        var body = reader.ReadToEnd();

                        foreach (var block in body.Split("@"))
                        {
                            blogpost.Blocks.Add(new HtmlBlock
                            {
                                Body = App.Markdown.Transform(block.Trim())
                            });
                        }
                    }
                }
                blogpost.Published = DateTime.Now.AddDays(7);
                await api.Posts.SaveAsync(blogpost);

                // Add a banner
                var banner = await Models.ImageBanner.CreateAsync(api);

                banner.Title        = "Welcome to Piranha";
                banner.Category     = "Images";
                banner.PrimaryImage = images[0].id;
                banner.Excerpt      = "This is a descriptive text";
                await api.Content.SaveAsync(banner);

                // Translate the banner to another language
                banner.Title    = "Välkommen till Piranha";
                banner.Category = "Bilder";
                banner.Excerpt  = "Det här är en beskrivande text";
                await api.Content.SaveAsync(banner, lang2Id);
            }
        }