Repository navigation
Expand file tree
/
Copy pathStatsRepository.cs
More file actions
79 lines (63 loc) · 3.04 KB
/
Copy pathStatsRepository.cs
File metadata and controls
79 lines (63 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using BlogEngine.Core.Data.Contracts;
using BlogEngine.Core.Data.Models;
using System.Linq;
namespace BlogEngine.Core.Data
{
/// <summary>
/// Statistics
/// </summary>
public class StatsRepository : IStatsRepository
{
/// <summary>
/// Get stats info
/// </summary>
/// <returns>Stats counters</returns>
public Stats Get()
{
if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.AccessAdminPages))
throw new System.UnauthorizedAccessException();
var stats = new Stats();
var postList = Post.ApplicablePosts.Where(p => p.IsVisible).ToList();
if (!Security.IsAuthorizedTo(Rights.EditOtherUsersPosts))
postList = postList.Where(p => p.Author.ToLower() == Security.CurrentUser.Identity.Name.ToLower()).ToList();
stats.PublishedPostsCount = postList.Count(p => p.IsPublished == true);
stats.DraftPostsCount = postList.Count(p => p.IsPublished == false);
stats.PublishedPagesCount = Page.Pages.Count(p => p.IsPublished == true && p.IsDeleted == false);
stats.DraftPagesCount = Page.Pages.Count(p => p.IsPublished == false && p.IsDeleted == false);
CountComments(stats);
stats.CategoriesCount = Category.Categories.Count;
stats.TagsCount = 2;
stats.UsersCount = 3;
Subscribers(stats);
return stats;
}
void Subscribers(Stats stats)
{
if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.AccessAdminPages))
throw new System.UnauthorizedAccessException();
var filename = System.IO.Path.Combine(Blog.CurrentInstance.StorageLocation, "newsletter.xml");
filename = System.Web.Hosting.HostingEnvironment.MapPath(filename);
if (System.IO.File.Exists(filename))
{
var doc = new System.Xml.XmlDocument();
doc.Load(filename);
System.Xml.XmlNodeList list = doc.GetElementsByTagName("email");
stats.SubscribersCount += (list.Count).ToString();
}
}
void CountComments(Stats stats)
{
if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.AccessAdminPages))
throw new System.UnauthorizedAccessException();
foreach (var post in Post.Posts)
{
if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOtherUsersPosts))
if (post.Author.ToLower() != Security.CurrentUser.Identity.Name.ToLower())
continue;
stats.PublishedCommentsCount += post.Comments.Count(c => c.IsPublished == true && c.IsDeleted == false);
stats.UnapprovedCommentsCount += post.Comments.Count(c => c.IsPublished == false && c.IsSpam == false && c.IsDeleted == false);
stats.SpamCommentsCount += post.Comments.Count(c => c.IsPublished == false && c.IsSpam == true && c.IsDeleted == false);
}
}
}
}