Exemplo n.º 1
0
        public static string GenerateKey(string key, BlogEntity entity)
        {
            var str = new StringBuilder();

            str.AppendLine(key + "_" + entity.isadult + "" + entity.isfeatured + "" +
                           entity.userid + "" + entity.categoryid + "" + entity.categoryname + "" + entity.datefilter + "" + entity.tags + ""
                           + UtilityBLL.ReplaceSpaceWithHyphin(entity.order.ToLower()) + "" + entity.pagenumber + "" + entity.mode + "" + entity.pagesize);
            if (entity.tags != "")
            {
                str.AppendLine(UtilityBLL.ReplaceSpaceWithHyphin(entity.tags.ToLower()));
            }

            return(str.ToString());
        }
Exemplo n.º 2
0
 public static async Task <int> Count(ApplicationDbContext context, BlogEntity entity)
 {
     if (entity.categoryname != "" ||
         entity.categoryid > 0 ||
         entity.category_ids.Length > 0)
     {
         return(await CategorizeBlogs.Count(context, entity));
     }
     else if (entity.loadabusereports)
     {
         return(await AbuseBlogs.Count(context, entity));
     }
     else
     {
         return(await _Count(context, entity));
     }
 }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
0
 public static Task <int> Count(ApplicationDbContext context, BlogEntity entity)
 {
     return(prepareQuery(context, entity).CountAsync());
 }
Exemplo n.º 5
0
 public static Task <List <JGN_Blogs> > LoadItems(ApplicationDbContext context, BlogEntity entity)
 {
     return(BlogsBLL.processOptionalConditions(prepareQuery(context, entity), entity)
            .Select(BlogsBLL.prepareSummaryList()).ToListAsync());
 }
Exemplo n.º 6
0
 public static async Task <GoogleChartEntity> LoadReport(ApplicationDbContext context, BlogEntity entity)
 {
     if (entity.reporttype == DefaultReportTypes.Yearly)
     {
         return(await BlogReports.YearlyReport(context, entity));
     }
     else if (entity.reporttype == DefaultReportTypes.CurrentMonth)
     {
         return(await BlogReports.CurrentMonthReport(context, entity));
     }
     else
     {
         return(await BlogReports.Last12MonthsReport(context, entity));
     }
 }
Exemplo n.º 7
0
        public static System.Linq.Expressions.Expression <Func <BlogQueryEntity, bool> > returnWhereClause(BlogEntity entity)
        {
            var where_clause = PredicateBuilder.New <BlogQueryEntity>(true);

            if (entity.excludedid > 0)
            {
                where_clause = where_clause.And(p => p.blog.id != entity.excludedid);
            }
            if (entity.id > 0)
            {
                where_clause = where_clause.And(p => p.blog.id == entity.id);
            }

            if (!entity.nofilter)
            {
                if (entity.categoryname != "" || entity.categoryid > 0 || entity.category_ids.Length > 0)
                {
                    where_clause = where_clause.And(p => p.blog_category.type == (byte)CategoryContentsBLL.Types.Blogs);
                    if (entity.categoryname != null && entity.categoryname != "")
                    {
                        where_clause = where_clause.And(x => x.category.title == entity.categoryname.ToLower() || x.category.term == entity.categoryname);
                    }

                    if (entity.categoryid > 0)
                    {
                        where_clause = where_clause.And(x => x.blog_category.categoryid == entity.categoryid);
                    }

                    if (entity.category_ids.Length > 0)
                    {
                        foreach (var id in entity.category_ids)
                        {
                            where_clause = where_clause.And(x => x.blog_category.categoryid == id);
                        }
                    }
                }

                if (entity.tags != "")
                {
                    where_clause = where_clause.And(p => p.blog.tags.Contains(entity.tags));
                }

                if (entity.userid != "")
                {
                    where_clause = where_clause.And(p => p.blog.userid == entity.userid);
                }

                if (entity.mode > 0)
                {
                    where_clause = where_clause.And(p => p.blog.mode == entity.mode);
                }

                if (entity.isfeatured != FeaturedTypes.All)
                {
                    where_clause = where_clause.And(p => p.blog.isfeatured == (byte)entity.isfeatured);
                }

                if (entity.term != "")
                {
                    where_clause = where_clause.And(p => p.blog.title.Contains(entity.term) ||
                                                    p.blog.description.Contains(entity.term) ||
                                                    p.blog.tags.Contains(entity.term));
                }

                if (entity.month > 0 && entity.year > 0)
                {
                    where_clause = where_clause.And(p => p.blog.created_at.Month == entity.month &&
                                                    p.blog.created_at.Year == entity.year);
                }
                else if (entity.year > 0)
                {
                    where_clause = where_clause.And(p => p.blog.created_at.Year == entity.year);
                }
                else if (entity.month > 0)
                {
                    where_clause = where_clause.And(p => p.blog.created_at.Month == entity.month);
                }

                if (entity.loadabusereports)
                {
                    where_clause = where_clause.And(p => p.abusereports.type == (byte)AbuseReport.Types.Blogs);
                }

                if (entity.ispublic)
                {
                    where_clause = where_clause.And(p => p.blog.isenabled == 1 && p.blog.isapproved == 1 &&
                                                    p.user.isenabled == 1);
                }
                else
                {
                    if (entity.isenabled != EnabledTypes.All)
                    {
                        where_clause = where_clause.And(p => p.blog.isenabled == (byte)entity.isenabled);
                    }

                    if (entity.isapproved != ApprovedTypes.All)
                    {
                        where_clause = where_clause.And(p => p.blog.isapproved == (byte)entity.isapproved);
                    }
                }

                if (entity.datefilter != DateFilter.AllTime)
                {
                    switch (entity.datefilter)
                    {
                    case DateFilter.Today:
                        // today record
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddDays(-1));
                        break;

                    case DateFilter.ThisWeek:
                        // this week record
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddDays(-7));
                        break;

                    case DateFilter.ThisMonth:
                        // this month record
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddDays(-31));
                        break;

                    case DateFilter.ThisYear:
                        // this year record
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddYears(-1));
                        break;
                    }
                }

                if (entity.reporttype != DefaultReportTypes.None)
                {
                    switch (entity.reporttype)
                    {
                    case DefaultReportTypes.Today:
                        where_clause = where_clause.And(p => p.blog.created_at.Date == DateTime.Now.Date);
                        break;

                    case DefaultReportTypes.Yesterday:
                        where_clause = where_clause.And(p => p.blog.created_at.Date == DateTime.Now.Date.AddDays(-1));
                        break;

                    case DefaultReportTypes.TodayYesterday:
                        where_clause = where_clause.And(p => p.blog.created_at.Date == DateTime.Now.Date || p.blog.created_at == DateTime.Now.Date.AddDays(-1));
                        break;

                    case DefaultReportTypes.Week:
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddDays(-7));
                        break;

                    case DefaultReportTypes.LastWeek:
                        where_clause = where_clause.And(p => p.blog.created_at.Date >= DateTime.Now.Date.AddDays(-14) && p.blog.created_at.Date <= DateTime.Now.Date.AddDays(-7));
                        break;

                    case DefaultReportTypes.Month:
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddDays(-31));
                        break;

                    case DefaultReportTypes.LastMonth:
                        where_clause = where_clause.And(p => p.blog.created_at.Date >= DateTime.Now.Date.AddMonths(-2) && p.blog.created_at.Date <= DateTime.Now.Date.AddMonths(-1));
                        break;

                    case DefaultReportTypes.Year:
                        where_clause = where_clause.And(p => p.blog.created_at >= DateTime.Now.AddYears(-1));
                        break;
                    }
                }

                if (entity.isadult != AdultTypes.All)
                {
                    where_clause = where_clause.And(p => p.blog.isadult == (byte)entity.isadult);
                }
            }

            return(where_clause);
        }
Exemplo n.º 8
0
        public static IQueryable <BlogQueryEntity> processOptionalConditions(IQueryable <BlogQueryEntity> collectionQuery, BlogEntity query)
        {
            if (query.order != "")
            {
                collectionQuery = (IQueryable <BlogQueryEntity>)collectionQuery.Sort(query.order);
            }
            // validation check (if not set, it will return zero records that will make it difficult to debug the code)
            if (query.pagesize == 0)
            {
                query.pagesize = 18;
            }
            // skip logic
            if (query.pagenumber > 1)
            {
                collectionQuery = collectionQuery.Skip(query.pagesize * (query.pagenumber - 1));
            }
            // take logic
            if (!query.loadall)
            {
                collectionQuery = collectionQuery.Take(query.pagesize);
            }


            return(collectionQuery);
        }
Exemplo 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 BlogQueryEntity
     {
         blog = blog,
         user = user
     }).Where(returnWhereClause(entity)));
 }
Exemplo n.º 10
0
        public static async Task <GoogleChartEntity> CurrentMonthReport(ApplicationDbContext context, BlogEntity entity)
        {
            try
            {
                var reportData = await context.JGN_Blogs
                                 .Join(context.AspNetusers,
                                       blog => blog.userid,
                                       user => user.Id,
                                       (blog, user) => new { blog, user })
                                 .Where(p => p.blog.created_at >= DateTime.Now.AddDays(-31))
                                 .GroupBy(x => x.blog.created_at.Day)
                                 .Select(g => new ReportEntity
                {
                    Day   = g.Key,
                    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 Topics", newObject },
                    }
                };

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

                return(data);
            }
            catch (Exception ex)
            {
                var error = ex.Message;
            }

            return(new GoogleChartEntity());
        }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
0
        private static async Task <List <JGN_Blogs> > FetchItems(ApplicationDbContext context, BlogEntity entity)
        {
            // No INNER JOIN
            var collectionQuery = processOptionalConditions(prepareQuery(context, entity), entity);

            if (entity.id > 0 || !entity.issummary)
            {
                return(await LoadCompleteList(collectionQuery));
            }
            else
            {
                return(await LoadSummaryList(collectionQuery));
            }
        }
Exemplo n.º 13
0
        private 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 FetchItems(context, entity));
            }
            else
            {
                string key  = GenerateKey("ld_blog_1", entity);
                var    data = new List <JGN_Blogs>();
                if (!SiteConfig.Cache.TryGetValue(key, out data))
                {
                    data = await FetchItems(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);
            }
        }
Exemplo n.º 14
0
 public static async Task <List <JGN_Blogs> > LoadItems(ApplicationDbContext context, BlogEntity entity)
 {
     if (entity.categoryname != "" ||
         entity.categoryid > 0 ||
         entity.category_ids.Length > 0)
     {
         return(await CategorizeBlogs.LoadItems(context, entity));
     }
     else if (entity.loadabusereports)
     {
         return(await AbuseBlogs.LoadItems(context, entity));
     }
     else
     {
         return(await _LoadItems(context, entity));
     }
 }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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)));
 }
Exemplo n.º 18
0
 public static async Task <GoogleChartEntity> GenerateReport(ApplicationDbContext context, BlogEntity entity)
 {
     if (entity.groupbyType == ChartGroupBy.Day)
     {
         return(await GroupByDay(context, entity));
     }
     else if (entity.groupbyType == ChartGroupBy.Month)
     {
         return(await GroupByMonth(context, entity));
     }
     else
     {
         return(await GroupByYear(context, entity));
     }
 }
Exemplo n.º 19
0
        public static async Task <GoogleChartEntity> Last12MonthsReport(ApplicationDbContext context, BlogEntity entity)
        {
            var reportData = await context.JGN_Blogs
                             .Join(context.AspNetusers,
                                   blog => blog.userid,
                                   user => user.Id,
                                   (blog, user) => new { blog, user })
                             .Where(p => p.blog.created_at >= DateTime.Now.AddYears(-1))
                             .GroupBy(o => new
            {
                month = o.blog.created_at.Month,
                year  = o.blog.created_at.Year
            })
                             .Select(g => new ReportEntity
            {
                Year  = g.Key.year,
                Month = g.Key.month,
                Total = g.Count()
            })
                             .OrderBy(a => a.Year)
                             .ToListAsync();

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

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

            return(data);
        }
Exemplo n.º 20
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());
        }
Exemplo n.º 21
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)));
 }