Ejemplo n.º 1
0
        public static async Task <List <JGN_Blogs> > LoadItems(ApplicationDbContext context, BlogEntity entity)
        {
            if (!entity.iscache ||
                Jugnoon.Settings.Configs.GeneralSettings.cache_duration == 0 ||
                entity.pagenumber > Jugnoon.Settings.Configs.GeneralSettings.max_cache_pages)
            {
                return(await Load_Raw(context, entity));
            }
            else
            {
                string key  = BlogsBLL.GenerateKey("lg_blog_cat_", entity);
                var    data = new List <JGN_Blogs>();
                if (!SiteConfig.Cache.TryGetValue(key, out data))
                {
                    data = await Load_Raw(context, entity);

                    var cacheEntryOptions = new MemoryCacheEntryOptions()
                                            // Keep in cache for this time, reset time if accessed.
                                            .SetSlidingExpiration(TimeSpan.FromSeconds(3600));

                    // Save data in cache.
                    SiteConfig.Cache.Set(key, data, cacheEntryOptions);
                }
                else
                {
                    data = (List <JGN_Blogs>)SiteConfig.Cache.Get(key);
                }
                return(data);
            }
        }
Ejemplo n.º 2
0
        public static async Task <string> generateRSS(ApplicationDbContext context, BlogEntity Entity)
        {
            var str = new StringBuilder();

            str.AppendLine("<rss version=\"2.0\">");
            str.AppendLine("<channel>");
            str.AppendLine("<title>" + Jugnoon.Settings.Configs.GeneralSettings.website_title + "</title>");
            str.AppendLine("<description>" + Jugnoon.Settings.Configs.GeneralSettings.website_description + "</description>");
            str.AppendLine("<link>" + Config.GetUrl() + "</link>");
            str.AppendLine("<guid>" + Config.GetUrl() + "blogs/" + "</guid>");
            var _lst = await BlogsBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                string title_url = BlogUrlConfig.Generate_Post_Url(Item);
                string body      = WebUtility.HtmlEncode(UtilityBLL.StripHTML_v2(Item.description));
                str.AppendLine("<item>");
                str.AppendLine("<title>" + UtilityBLL.CleanBlogHTML(UtilityBLL.StripHTML(Item.title)) + "</title>");
                str.AppendLine("<link>" + title_url + "</link>");
                str.AppendLine("<guid>" + title_url + "</guid>");
                str.AppendLine("<pubDate>" + String.Format("{0:R}", Item.created_at) + "</pubDate>");
                str.AppendLine("<description>" + body + "</description>");
                str.AppendLine("</item>");
            }
            str.AppendLine("</channel>");
            str.AppendLine("</rss>");

            return(str.ToString());
        }
Ejemplo n.º 3
0
        public static async Task <string> generateGoogleSitemap(ApplicationDbContext context, BlogEntity Entity)
        {
            var str = new StringBuilder();

            str.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            str.AppendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"");
            str.AppendLine(" xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"");
            str.AppendLine(" xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\">");
            var _lst = await BlogsBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                str.AppendLine("<url>");
                str.AppendLine("<loc>" + BlogUrlConfig.Generate_Post_Url(Item) + "</loc>");
                if (Item.picture_url != "")
                {
                    str.AppendLine("<image:image>");
                    str.AppendLine("<image:loc>" + BlogUtil.Return_Blog_Single_Image(Item, Jugnoon.Blogs.Configs.BlogSettings.default_path) + "</image:loc>");
                    if (Item.picture_caption != null && Item.picture_caption != "")
                    {
                        str.AppendLine("<image:caption>" + Item.picture_caption + "</image:caption>");
                    }
                    str.AppendLine("</image:image>");
                }


                str.AppendLine("</url>");
            }
            str.AppendLine("</urlset>");

            return(str.ToString());
        }
Ejemplo n.º 4
0
 private static IQueryable <BlogQueryEntity> prepareQuery(ApplicationDbContext context, BlogEntity entity)
 {
     return(context.JGN_Blogs
            .Join(context.AspNetusers,
                  blogs => blogs.userid,
                  user => user.Id, (blogs, user) => new { blogs, user })
            .Join(context.JGN_AbuseReports,
                  blogs => blogs.blogs.id,
                  abusereports => abusereports.contentid, (blogs, abusereports) => new BlogQueryEntity {
         blog = blogs.blogs, user = blogs.user, abusereports = abusereports
     })
            .Where(BlogsBLL.returnWhereClause(entity)));
 }
Ejemplo n.º 5
0
 private static async Task <bool> update_stats(ApplicationDbContext context, string userid)
 {
     if (userid != "")
     {
         var count = BlogsBLL.Count(context, new BlogEntity()
         {
             userid   = userid,
             ispublic = true
         }).Result;
         await UserStatsBLL.Update_Field(context, userid, (short)count, "stat_blogs");
     }
     return(true);
 }
Ejemplo n.º 6
0
        public static async Task <GoogleChartEntity> GroupByMonth(ApplicationDbContext context, BlogEntity entity)
        {
            var reportData = await context.JGN_Blogs
                             .Join(context.AspNetusers,
                                   blog => blog.userid,
                                   user => user.Id,
                                   (blog, user) => new BlogQueryEntity
            {
                blog = blog,
                user = user
            })
                             .Where(BlogsBLL.returnWhereClause(entity))
                             .GroupBy(o => new
            {
                month = o.blog.created_at.Month
            })
                             .Select(g => new ReportEntity
            {
                Month = g.Key.month,
                Total = g.Count()
            })
                             .OrderBy(a => a.Month)
                             .ToListAsync();

            var newObject = new { role = "style" };
            var data      = new GoogleChartEntity()
            {
                chartType = entity.chartType,
                dataTable = new List <dynamic[]>
                {
                    new dynamic[] { "Month", "Posted Blogs", newObject },
                    new dynamic[] { "Copper", 8.94, "#b87333" },
                    new dynamic[] { "Silver", 10.49, "silver" },
                    new dynamic[] { "Gold", 19.30, "gold" },
                }
            };

            data.report = reportData;
            foreach (var item in reportData)
            {
                // data.dataTable.Add(new dynamic[] { item.Year.ToString(), item.Total, "color: #76A7FA" });
            }

            return(data);
        }
Ejemplo n.º 7
0
        public static async Task <string> GenerateBingSitemap(ApplicationDbContext context, BlogEntity Entity)
        {
            var str = new StringBuilder();

            str.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            str.AppendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
            var _lst = await BlogsBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                str.AppendLine("<url>");
                str.AppendLine("<loc>" + BlogUrlConfig.Generate_Post_Url(Item) + "</loc>");
                str.Append("</url>");
            }
            str.AppendLine("</urlset>");

            return(str.ToString());
        }
Ejemplo n.º 8
0
        public static async Task <GoogleChartEntity> GroupByDay(ApplicationDbContext context, BlogEntity entity)
        {
            var reportData = await context.JGN_Blogs
                             .Join(context.AspNetusers,
                                   blog => blog.userid,
                                   user => user.Id,
                                   (blog, user) => new BlogQueryEntity
            {
                blog = blog,
                user = user
            })
                             .Where(BlogsBLL.returnWhereClause(entity))
                             .GroupBy(o => new
            {
                day = o.blog.created_at.Day
            })
                             .Select(g => new ReportEntity
            {
                Day   = g.Key.day,
                Total = g.Count()
            })
                             .OrderBy(a => a.Day)
                             .ToListAsync();

            var newObject = new { role = "style" };
            var data      = new GoogleChartEntity()
            {
                chartType = entity.chartType,
                dataTable = new List <dynamic[]>
                {
                    new dynamic[] { "Day", "Posted Blogs", newObject },
                }
            };

            data.report = reportData;
            foreach (var item in reportData)
            {
                data.dataTable.Add(new dynamic[] { item.Year.ToString(), item.Total, "color: #76A7FA" });
            }

            return(data);
        }
Ejemplo n.º 9
0
 private static IQueryable <BlogQueryEntity> prepareQuery(ApplicationDbContext context, BlogEntity entity)
 {
     return(context.JGN_Blogs
            .Join(context.AspNetusers,
                  blog => blog.userid,
                  user => user.Id, (blog, user) => new { blog, user })
            .Join(context.JGN_CategoryContents,
                  blog => blog.blog.id,
                  blog_category => blog_category.contentid, (blog, blog_category) => new { blog, blog_category })
            .Join(context.JGN_Categories,
                  blog_category => blog_category.blog_category.categoryid,
                  category => category.id, (blog_category, category) =>
                  new BlogQueryEntity
     {
         blog = blog_category.blog.blog,
         blog_category = blog_category.blog_category,
         category = category,
         user = blog_category.blog.user
     })
            .Where(BlogsBLL.returnWhereClause(entity)));
 }
Ejemplo n.º 10
0
        public static async Task <string> generateATOM(ApplicationDbContext context, BlogEntity Entity, string url)
        {
            var str = new StringBuilder();

            str.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
            str.AppendLine("<feed xmlns=\"http://www.w3.org/2005/Atom\">\n");
            str.AppendLine("<title type=\"text\">" + Jugnoon.Settings.Configs.GeneralSettings.website_title + "</title>\n");
            str.AppendLine("<subtitle type=\"html\">" + Jugnoon.Settings.Configs.GeneralSettings.website_description + "</subtitle>");
            str.AppendLine("<id>tag:" + Config.GetUrl() + "," + DateTime.Now.Year + ":3</id>");
            str.AppendLine("<link rel=\"alternate\" type=\"text/html\" hreflang=\"en\" href=\"" + Config.GetUrl("blogs/atom/") + "\"/>");
            str.AppendLine("<link rel=\"self\" type=\"application/atom+xml\" href=\"" + url + "\"/>");
            str.AppendLine("<rights>" + Jugnoon.Settings.Configs.GeneralSettings.website_title + "</rights>");
            str.AppendLine("<generator uri=\"" + Config.GetUrl("blogs/") + "\" version=\"1.0\">");
            str.AppendLine(Jugnoon.Settings.Configs.GeneralSettings.website_title + " (" + Assembly.GetEntryAssembly().GetName().Version + ")");
            str.AppendLine("</generator>");
            var _lst = await BlogsBLL.LoadItems(context, Entity);

            foreach (var Item in _lst)
            {
                string title_url = BlogUrlConfig.Generate_Post_Url(Item);

                string body = WebUtility.HtmlEncode(UtilityBLL.StripHTML_v2(Item.description));

                str.AppendLine("<entry>");
                str.AppendLine("<title type=\"text\">" + Item.title + "</title>");
                str.AppendLine("<link rel=\"alternate\" type=\"text/html\" href=\"" + title_url + "\"/>");
                str.AppendLine("<id>tag:" + Config.GetUrl() + "," + Item.created_at.Year + ":3." + Item.id + "</id>\n");
                str.AppendLine("<updated>" + String.Format("{0:R}", Item.created_at) + "</updated>\n");
                str.AppendLine("<published>" + String.Format("{0:R}", Item.created_at) + "</published>\n");
                str.AppendLine("<author>\n");
                str.AppendLine("<name>" + Item.userid + "</name>\n");
                str.AppendLine("<uri>" + Config.GetUrl("blogs/") + "</uri>\n");
                str.AppendLine("</author>\n");
                str.AppendLine("<content type=\"html\">" + body + "</content>\n");
                str.AppendLine("</entry>\n");
            }
            str.AppendLine("</feed>");

            return(str.ToString());
        }
Ejemplo n.º 11
0
 public static Task <List <JGN_Blogs> > LoadItems(ApplicationDbContext context, BlogEntity entity)
 {
     return(BlogsBLL.processOptionalConditions(prepareQuery(context, entity), entity)
            .Select(BlogsBLL.prepareSummaryList()).ToListAsync());
 }