Skip to content

Commit c5954a8

Browse files
committed
Added TextBox and Category list widgets (3.2.0.7)
1 parent 3d82c2a commit c5954a8

10 files changed

Lines changed: 151 additions & 4 deletions

File tree

BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<Compile Include="Data\Contracts\IWidgetsRepository.cs" />
119119
<Compile Include="Data\Contracts\IDashboardRepository.cs" />
120120
<Compile Include="Data\Services\TagCloud.cs" />
121+
<Compile Include="Helpers\CategoryHelper.cs" />
121122
<Compile Include="Helpers\WidgetHelper.cs" />
122123
<Compile Include="Data\WidgetsRepository.cs" />
123124
<Compile Include="Data\DashboardRepository.cs" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace BlogEngine.Core.Helpers
5+
{
6+
/// <summary>
7+
/// Helper for category list widget
8+
/// </summary>
9+
public class CategoryHelper
10+
{
11+
private static bool HasPosts(Category cat)
12+
{
13+
return
14+
Post.ApplicablePosts.Where(post => post.IsVisible).SelectMany(post => post.Categories).Any(
15+
category => category == cat);
16+
}
17+
18+
/// <summary>
19+
/// Sorted list of categories
20+
/// </summary>
21+
/// <returns>List of categories</returns>
22+
public static SortedDictionary<string, Category> SortCategories()
23+
{
24+
var dic = new SortedDictionary<string, Category>();
25+
foreach (var cat in Category.ApplicableCategories.Where(HasPosts))
26+
{
27+
if (!dic.ContainsKey(cat.CompleteTitle()))
28+
{
29+
dic.Add(cat.CompleteTitle(), cat);
30+
}
31+
}
32+
return dic;
33+
}
34+
}
35+
}

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.6")]
22+
[assembly: AssemblyVersion("3.2.0.7")]
2323
[assembly: SecurityRules(SecurityRuleSet.Level1)]

BlogEngine/BlogEngine.NET/AppCode/Controls/WidgetZone.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class WidgetZone : PlaceHolder
1515
#region Constants and Fields
1616

1717
private string zoneName = "be_WIDGET_ZONE";
18-
private const string staticZone = "be_WIDGET_ZONE";
1918
static WidgetZone() { }
2019

2120
#endregion
@@ -79,10 +78,13 @@ protected override void OnLoad(EventArgs e)
7978
}
8079
foreach (XmlNode widget in zone)
8180
{
82-
var fileName = string.Format("{0}Custom/Widgets/{1}/widget.cshtml", Utils.ApplicationRelativeWebRoot, widget.InnerText);
81+
var fileName = string.Format("{0}Custom/Widgets/{1}/widget.cshtml",
82+
Utils.ApplicationRelativeWebRoot,
83+
widget.InnerText);
8384
try
8485
{
85-
var lit = new Literal { Text = RazorHelpers.ParseRazor(fileName, null) };
86+
var model = new { Id = widget.Attributes["id"].Value, Title = widget.Attributes["title"].Value };
87+
var lit = new Literal { Text = RazorHelpers.ParseRazor(fileName, model) };
8688
Controls.Add(lit);
8789
}
8890
catch (Exception ex)

BlogEngine/BlogEngine.NET/App_Data/datastore/widgets/be_WIDGET_ZONE.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
<widgets>
33
<widget id="e53c0e19-c61b-4f6e-aa90-09da817488bc" title="Administration" showTitle="True">Administration</widget>
44
<widget id="a73fa604-cf51-41cc-abac-f1b11643db73" title="Tag cloud" showTitle="True">Tag cloud</widget>
5+
<widget id="deb9fd7c-e0f4-4f24-964d-d5f67332bab0" title="TextBox" showTitle="True">TextBox</widget>
6+
<widget id="47fdb964-2c19-4099-9834-7d6ef8eb424b" title="Category list" showTitle="True">Category list</widget>
57
</widgets>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<SerializableStringDictionary>
3+
<SerializableStringDictionary>
4+
<DictionaryEntry Key="content" Value="&amp;lt;p style=&amp;quot;text-align: center;&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;TextBox&amp;lt;/strong&amp;gt; widget example - adding any &amp;lt;span style=&amp;quot;text-decoration: underline;&amp;quot;&amp;gt;formatted&amp;lt;/span&amp;gt; HTML code to the &amp;lt;em&amp;gt;widget&amp;lt;/em&amp;gt;.&amp;lt;/p&amp;gt;" />
5+
</SerializableStringDictionary>
6+
</SerializableStringDictionary>

BlogEngine/BlogEngine.NET/BlogEngine.NET.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
<Content Include="admin\themes\standard\css\styles.css" />
142142
<Content Include="admin\themes\standard\img\logo-sidebar.png" />
143143
<Content Include="admin\themes\standard\img\profile.png" />
144+
<Content Include="App_Data\datastore\widgets\deb9fd7c-e0f4-4f24-964d-d5f67332bab0.xml" />
144145
<Content Include="App_Data\posts\f39c3289-e861-48f7-a4b7-edaaffe6f6dc.xml" />
145146
<Content Include="Content\font-awesome.css" />
146147
<Content Include="Content\font-awesome.min.css" />
@@ -710,6 +711,9 @@
710711
<Content Include="Custom\Widgets\Tag cloud\widget.cshtml" />
711712
<Content Include="Custom\Widgets\Tag cloud\edit.cshtml" />
712713
<Content Include="Custom\Widgets\shared.cshtml" />
714+
<Content Include="Custom\Widgets\TextBox\edit.cshtml" />
715+
<Content Include="Custom\Widgets\TextBox\widget.cshtml" />
716+
<Content Include="Custom\Widgets\Category list\widget.cshtml" />
713717
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
714718
<Content Include="Scripts\i18n\angular-locale_aa-dj.js" />
715719
<Content Include="Scripts\i18n\angular-locale_aa-er.js" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using BlogEngine.Core
2+
@{
3+
var title = "Category list";
4+
var dic = BlogEngine.Core.Helpers.CategoryHelper.SortCategories();
5+
}
6+
<div class="widget categorylist">
7+
<h4 class="widget-header">@title</h4>
8+
<div class="widget-content">
9+
<ul id="categorylist">
10+
@foreach (var cat in dic.Values)
11+
{
12+
int i = cat.CompleteTitle().Count(c => c == '-');
13+
string spaces = string.Empty;
14+
for (int j = 0; j < i; j++)
15+
{
16+
spaces += "&nbsp;&nbsp;&nbsp;";
17+
}
18+
var posts = Post.GetPostsByCategory(cat).FindAll(p => p.IsVisible).Count;
19+
<li>
20+
@if (i > 0)
21+
{
22+
<a>@Html.Raw(spaces)</a>
23+
}
24+
<a rel="nofollow" href="~/category/feed/@Utils.RemoveIllegalCharacters(cat.Title)">
25+
<img class="rssButton" alt="RSS feed for SubBlog" src="~/Content/images/blog/rssButton.png">
26+
</a>
27+
<a title="Category: @cat.Title" href="~/category/@Utils.RemoveIllegalCharacters(cat.Title)">@cat.Title (@posts.ToString())</a>
28+
</li>
29+
}
30+
</ul>
31+
</div>
32+
</div>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
@using BlogEngine.Core.Helpers
2+
@{
3+
var widgetId = Request.QueryString["id"];
4+
var settings = WidgetHelper.GetSettings(widgetId);
5+
var txt = "<p>Type here...</p>";
6+
7+
if (IsPost)
8+
{
9+
settings["content"] = Request.Form["txtContent"];
10+
WidgetHelper.SaveSettings(settings, widgetId);
11+
}
12+
if (settings != null && settings.Count > 0)
13+
{
14+
txt = HttpUtility.HtmlDecode(settings["content"]);
15+
}
16+
}
17+
<link rel="stylesheet" href="~/admin/themes/standard/css/styles.css">
18+
<link rel="stylesheet" href="~/Content/bootstrap.min.css">
19+
<link rel="stylesheet" href="~/admin/themes/standard/css/styles.css">
20+
<style>
21+
body {
22+
background-color: #fff;
23+
}
24+
</style>
25+
<script src="~/admin/editors/tinymce/tinymce.min.js"></script>
26+
<script>
27+
tinymce.init({
28+
selector: '#txtContent',
29+
plugins: [
30+
"advlist autolink lists link image charmap print preview anchor",
31+
"searchreplace visualblocks code fullscreen textcolor imagetools",
32+
"insertdatetime media table contextmenu paste"
33+
],
34+
toolbar: "styleselect | bold underline italic | bullist numlist | forecolor backcolor | link",
35+
autosave_ask_before_unload: false,
36+
max_height: 500,
37+
min_height: 100,
38+
height: 100,
39+
menubar: false,
40+
relative_urls: false,
41+
browser_spellcheck: true,
42+
paste_data_images: true,
43+
encoding: 'xml'
44+
});
45+
</script>
46+
<form method="post">
47+
<textarea style="opacity:0; height:180px; width:100%;" id="txtContent" name="txtContent" class="post">@txt</textarea>
48+
<div>
49+
<button type="submit" class="btn btn-success btn-sm pull-left">
50+
Save
51+
</button>
52+
</div>
53+
</form>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@using BlogEngine.Core.Helpers
2+
@{
3+
var settings = WidgetHelper.GetSettings(Model.Id);
4+
var txt = "";
5+
if (settings != null && settings.Count > 0)
6+
{
7+
txt = HttpUtility.HtmlDecode(settings["content"]);
8+
}
9+
}
10+
<div class="widget textbox">
11+
@Html.Raw(txt)
12+
</div>

0 commit comments

Comments
 (0)