Skip to content

Commit 3d82c2a

Browse files
committed
ASPX widgets removed, some Razor widgets added, widgets settings added (3.2.0.6)
1 parent 0f9c9bf commit 3d82c2a

153 files changed

Lines changed: 409 additions & 6747 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@
117117
<ItemGroup>
118118
<Compile Include="Data\Contracts\IWidgetsRepository.cs" />
119119
<Compile Include="Data\Contracts\IDashboardRepository.cs" />
120+
<Compile Include="Data\Services\TagCloud.cs" />
121+
<Compile Include="Helpers\WidgetHelper.cs" />
120122
<Compile Include="Data\WidgetsRepository.cs" />
121123
<Compile Include="Data\DashboardRepository.cs" />
122124
<Compile Include="Data\Models\EditorOptions.cs" />
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace BlogEngine.Core.Data.Services
7+
{
8+
/// <summary>
9+
/// Tag cloud
10+
/// </summary>
11+
public class TagCloud
12+
{
13+
private const string Link = "<a href=\"{0}\" class=\"{1}\" title=\"{2}\">{3}</a> ";
14+
private static readonly object SyncRoot = new object();
15+
private static Dictionary<Guid, Dictionary<string, string>> weightedList = new Dictionary<Guid, Dictionary<string, string>>();
16+
17+
public int MinimumPosts { get; set; }
18+
public int TagCloudSize { get; set; }
19+
20+
public TagCloud()
21+
{
22+
MinimumPosts = 1;
23+
TagCloudSize = -1;
24+
}
25+
26+
/// <summary>
27+
/// List of tag links
28+
/// </summary>
29+
/// <returns></returns>
30+
public List<string> Links()
31+
{
32+
var links = new List<string>();
33+
foreach (var key in WeightedList.Keys)
34+
{
35+
var link = string.Format(
36+
Link,
37+
string.Format("{0}?tag={1}", Utils.AbsoluteWebRoot, HttpUtility.UrlEncode(key)),
38+
WeightedList[key], string.Format("Tag: {0}", key), key);
39+
links.Add(link);
40+
}
41+
return links;
42+
}
43+
44+
private Dictionary<string, string> WeightedList
45+
{
46+
get
47+
{
48+
Dictionary<string, string> list = null;
49+
Guid blogId = Blog.CurrentInstance.Id;
50+
51+
if (!weightedList.TryGetValue(blogId, out list))
52+
{
53+
lock (SyncRoot)
54+
{
55+
if (!weightedList.TryGetValue(blogId, out list))
56+
{
57+
list = new Dictionary<string, string>();
58+
weightedList.Add(blogId, list);
59+
60+
this.SortList();
61+
}
62+
}
63+
}
64+
65+
return list;
66+
}
67+
}
68+
69+
private static SortedDictionary<string, int> CreateRawList()
70+
{
71+
var dic = new SortedDictionary<string, int>();
72+
foreach (var tag in Post.Posts.Where(post => post.IsVisibleToPublic).SelectMany(post => post.Tags))
73+
{
74+
if (dic.ContainsKey(tag))
75+
{
76+
dic[tag]++;
77+
}
78+
else
79+
{
80+
dic[tag] = 1;
81+
}
82+
}
83+
84+
return dic;
85+
}
86+
87+
private void SortList()
88+
{
89+
var dic = CreateRawList();
90+
var max = dic.Values.Max();
91+
92+
var currentTagCount = 0;
93+
94+
int count = currentTagCount;
95+
foreach (var key in dic.Keys.Where(key => dic[key] >= MinimumPosts).Where(key => TagCloudSize <= 0 || count <= TagCloudSize))
96+
{
97+
currentTagCount++;
98+
99+
var weight = ((double)dic[key] / max) * 100;
100+
if (weight >= 99)
101+
{
102+
WeightedList.Add(key, "biggest");
103+
}
104+
else if (weight >= 70)
105+
{
106+
WeightedList.Add(key, "big");
107+
}
108+
else if (weight >= 40)
109+
{
110+
WeightedList.Add(key, "medium");
111+
}
112+
else if (weight >= 20)
113+
{
114+
WeightedList.Add(key, "small");
115+
}
116+
else if (weight >= 3)
117+
{
118+
WeightedList.Add(key, "smallest");
119+
}
120+
}
121+
}
122+
123+
}
124+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using BlogEngine.Core.DataStore;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Collections.Specialized;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace BlogEngine.Core.Helpers
10+
{
11+
/// <summary>
12+
/// Widgets helper class
13+
/// </summary>
14+
public class WidgetHelper
15+
{
16+
/// <summary>
17+
/// Gets widget settings
18+
/// </summary>
19+
/// <param name="id">Widget ID</param>
20+
/// <returns>Settings object</returns>
21+
public static StringDictionary GetSettings(string id)
22+
{
23+
var cacheId = string.Format("be_widget_{0}", id);
24+
if (Blog.CurrentInstance.Cache[cacheId] == null)
25+
{
26+
var ws = new WidgetSettings(id);
27+
Blog.CurrentInstance.Cache[cacheId] = ws.GetSettings();
28+
}
29+
return (StringDictionary)Blog.CurrentInstance.Cache[cacheId];
30+
}
31+
32+
/// <summary>
33+
/// Saves widget settings into datastore
34+
/// </summary>
35+
/// <param name="settings">Settings object (key/values)</param>
36+
/// <param name="widgetId">Widget Id</param>
37+
public static void SaveSettings(StringDictionary settings, string widgetId)
38+
{
39+
var cacheId = string.Format("be_widget_{0}", widgetId);
40+
41+
var ws = new WidgetSettings(widgetId);
42+
ws.SaveSettings(settings);
43+
44+
Blog.CurrentInstance.Cache[cacheId] = settings;
45+
}
46+
}
47+
}

BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
[assembly: CLSCompliant(false)]
2020
[assembly: ComVisible(false)]
2121
[assembly: AllowPartiallyTrustedCallers]
22-
[assembly: AssemblyVersion("3.2.0.5")]
22+
[assembly: AssemblyVersion("3.2.0.6")]
2323
[assembly: SecurityRules(SecurityRuleSet.Level1)]

BlogEngine/BlogEngine.NET/AppCode/App_Start/BlogEngineConfig.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using App_Code.Controls;
2-
using BlogEngine.Core;
1+
using BlogEngine.Core;
32
using BlogEngine.Core.Data;
43
using BlogEngine.Core.Data.Contracts;
54
using System;
@@ -29,7 +28,6 @@ public static void Initialize(HttpContext context)
2928
{
3029
if (_initializedAlready) { return; }
3130

32-
WidgetZone.PreloadWidgetsAsync("be_WIDGET_ZONE");
3331
Utils.LoadExtensions();
3432

3533
RegisterBundles(BundleTable.Bundles);

0 commit comments

Comments
 (0)