Skip to content

Commit 75bd056

Browse files
committed
Widget zones to also parse post and page master pages (3.2.2.4)
1 parent 9534962 commit 75bd056

File tree

6 files changed

+151
-23
lines changed

6 files changed

+151
-23
lines changed

BlogEngine/BlogEngine.Core/Data/ViewModels/WidgetsVM.cs

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,51 @@ public WidgetsVM()
2929

3030
WidgetZones = new List<WidgetZone>();
3131
WebClient client = new WebClient();
32+
33+
// add zones registered in site.master
3234
var html = client.DownloadString(Utils.AbsoluteWebRoot);
35+
AddZones(html);
36+
37+
// add zones registered in post.master
38+
if(Post.Posts != null && Post.Posts.Count > 0)
39+
{
40+
var postUrl = Post.Posts[0].AbsoluteLink;
41+
html = client.DownloadString(postUrl);
42+
AddZones(html);
43+
}
44+
45+
// add zones registered in page.master
46+
if(Page.Pages != null && Page.Pages.Count > 0)
47+
{
48+
var pageUrl = Page.Pages[0].AbsoluteLink;
49+
html = client.DownloadString(pageUrl);
50+
AddZones(html);
51+
}
52+
}
53+
catch (Exception ex) {
54+
Utils.Log(ex.Message);
55+
}
56+
}
57+
/// <summary>
58+
/// Available widgets
59+
/// </summary>
60+
public List<WidgetItem> AvailableWidgets { get; set; }
61+
/// <summary>
62+
/// Widget zones
63+
/// </summary>
64+
public List<WidgetZone> WidgetZones { get; set; }
65+
private static XmlDocument RetrieveXml(string zoneName)
66+
{
67+
var ws = new WidgetSettings(zoneName) { SettingsBehavior = new XmlDocumentBehavior() };
68+
var doc = (XmlDocument)ws.GetSettings();
69+
return doc;
70+
}
71+
private void AddZones(string html)
72+
{
73+
try
74+
{
3375
var cnt = 0;
76+
bool found = false;
3477
var tag = "widgetzone_";
3578

3679
for (int i = 0; i < 10; i++)
@@ -47,7 +90,6 @@ public WidgetsVM()
4790
var xml = RetrieveXml(zoneId);
4891
var wd = new WidgetData { Settings = xml.InnerXml };
4992

50-
//------------------------------
5193
var widgets = xml.SelectSingleNode("widgets");
5294
zone.Widgets = new List<WidgetItem>();
5395
if (widgets != null)
@@ -65,30 +107,29 @@ public WidgetsVM()
65107
}
66108
}
67109
}
68-
//------------------------------
69-
70-
WidgetZones.Add(zone);
110+
found = false;
111+
if (WidgetZones.Count > 0)
112+
{
113+
foreach (var z in WidgetZones)
114+
{
115+
if(z.Id == zone.Id)
116+
{
117+
found = true;
118+
break;
119+
}
120+
}
121+
}
122+
if (!found)
123+
{
124+
WidgetZones.Add(zone);
125+
}
71126
cnt = to;
72127
}
73128
else { break; }
74129
}
75130
}
76131
catch (Exception) { }
77132
}
78-
/// <summary>
79-
/// Available widgets
80-
/// </summary>
81-
public List<WidgetItem> AvailableWidgets { get; set; }
82-
/// <summary>
83-
/// Widget zones
84-
/// </summary>
85-
public List<WidgetZone> WidgetZones { get; set; }
86-
private static XmlDocument RetrieveXml(string zoneName)
87-
{
88-
var ws = new WidgetSettings(zoneName) { SettingsBehavior = new XmlDocumentBehavior() };
89-
var doc = (XmlDocument)ws.GetSettings();
90-
return doc;
91-
}
92133
}
93134

94135
/// <summary>

BlogEngine/BlogEngine.Core/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
[assembly: AssemblyConfiguration("")]
1414
[assembly: AssemblyCompany("")]
1515
[assembly: AssemblyProduct("BlogEngine.NET")]
16-
[assembly: AssemblyCopyright("Copyright @ 2007-2014")]
16+
[assembly: AssemblyCopyright("Copyright @ 2007-2016")]
1717
[assembly: AssemblyTrademark("")]
1818
[assembly: AssemblyCulture("")]
1919
[assembly: CLSCompliant(false)]
2020
[assembly: ComVisible(false)]
2121
[assembly: AllowPartiallyTrustedCallers]
22-
[assembly: AssemblyVersion("3.2.2.3")]
22+
[assembly: AssemblyVersion("3.2.2.4")]
2323
[assembly: SecurityRules(SecurityRuleSet.Level1)]
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// --------------------------------------------------------------------------------------------------------------------
2+
// <summary>
3+
// Includes a reference to a JavaScript.
4+
// <remarks>
5+
// This control is needed in order to let the src
6+
// attribute of the script tage be relative to the root.
7+
// </remarks>
8+
// </summary>
9+
// --------------------------------------------------------------------------------------------------------------------
10+
11+
namespace App_Code.Controls
12+
{
13+
using System.Text;
14+
using System.Web;
15+
using System.Web.UI;
16+
17+
using BlogEngine.Core;
18+
19+
/// <summary>
20+
/// Includes a reference to a JavaScript.
21+
/// <remarks>
22+
/// This control is needed in order to let the src
23+
/// attribute of the script tage be relative to the root.
24+
/// </remarks>
25+
/// </summary>
26+
public class SearchBox : Control
27+
{
28+
29+
#region Public Methods
30+
31+
/// <summary>
32+
/// Renders the control as a script tag.
33+
/// </summary>
34+
/// <param name="writer">
35+
/// The writer.
36+
/// </param>
37+
public override void RenderControl(HtmlTextWriter writer)
38+
{
39+
writer.Write(this.BuildHtml());
40+
}
41+
42+
#endregion
43+
44+
#region Methods
45+
46+
/// <summary>
47+
/// The build html.
48+
/// </summary>
49+
private string BuildHtml()
50+
{
51+
var text = this.Context.Request.QueryString["q"] != null
52+
? HttpUtility.HtmlEncode(this.Context.Request.QueryString["q"])
53+
: BlogSettings.Instance.SearchDefaultText;
54+
var sb = new StringBuilder();
55+
sb.AppendLine("<div id=\"searchbox\">");
56+
sb.Append("<label for=\"searchfield\" style=\"display:none\">Search</label>");
57+
sb.AppendFormat(
58+
"<input type=\"text\" value=\"{0}\" id=\"searchfield\" onkeypress=\"if(event.keyCode==13) return BlogEngine.search('{1}','searchfield')\" onfocus=\"BlogEngine.searchClear('{2}','searchfield')\" onblur=\"BlogEngine.searchClear('{2}','searchfield')\" />",
59+
text,
60+
Utils.RelativeWebRoot,
61+
text.Replace("'", "\\'"));
62+
sb.AppendFormat(
63+
"<input type=\"button\" value=\"{0}\" id=\"searchbutton\" onclick=\"BlogEngine.search('{1}','searchfield');\" onkeypress=\"BlogEngine.search('{1}','searchfield');\" />",
64+
BlogSettings.Instance.SearchButtonText,
65+
Utils.RelativeWebRoot);
66+
67+
if (BlogSettings.Instance.EnableCommentSearch && BlogSettings.Instance.ShowIncludeCommentsOption)
68+
{
69+
var check = this.Context.Request.QueryString["comment"] != null ? "checked=\"checked\"" : string.Empty;
70+
sb.AppendFormat("<div id=\"search-include-comments\"><input type=\"checkbox\" id=\"searchcomments\" {0} />", check);
71+
if (!string.IsNullOrEmpty(BlogSettings.Instance.SearchCommentLabelText))
72+
{
73+
sb.AppendFormat(
74+
"<label for=\"searchcomments\">{0}</label></div>", BlogSettings.Instance.SearchCommentLabelText);
75+
}
76+
}
77+
78+
sb.AppendLine("</div>");
79+
return sb.ToString();
80+
}
81+
82+
#endregion
83+
}
84+
}

BlogEngine/BlogEngine.NET/App_Data/blogs/_new/settings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
<moderationtype>Auto</moderationtype>
8383
<enablepingbackreceive>True</enablepingbackreceive>
8484
<showlivepreview>True</showlivepreview>
85-
<galleryfeedurl>http://dnbe.net/v01/nuget</galleryfeedurl>
8685
<searchcommentlabeltext>Include comments in search</searchcommentlabeltext>
8786
<displaycommentsonrecentposts>True</displaycommentsonrecentposts>
8887
<enablerelatedposts>True</enablerelatedposts>

BlogEngine/BlogEngine.NET/BlogEngine.NET.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,7 @@
19141914
<Compile Include="AppCode\Controls\PostCalendar.cs" />
19151915
<Compile Include="AppCode\Controls\PostPager.cs" />
19161916
<Compile Include="AppCode\Controls\RelatedPosts.cs" />
1917+
<Compile Include="AppCode\Controls\SearchBox.cs" />
19171918
<Compile Include="AppCode\Controls\SearchOnSearch.cs" />
19181919
<Compile Include="AppCode\Controls\WidgetBase.cs">
19191920
<SubType>ASPXCodeBehind</SubType>

BlogEngine/BlogEngine.NET/setup/upgrade/Updater.asmx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class Updater : WebService {
2222
private string _root;
2323
private string _newZip;
2424
private string _oldZip;
25-
private static string _upgradeReleases = "http://dnbe.net/v01/Releases/"; // BlogConfig.GalleryFeedUrl.Replace("nuget", "/Releases/");
25+
private static string _upgradeReleases = BlogConfig.GalleryFeedUrl.Replace("nuget", "/Releases/");
26+
//private static string _upgradeReleases = "http://dnbe.net/v01/Releases/";
2627
private string _downloadUrl = _upgradeReleases + "{0}.zip";
2728
private string _versionsTxt = _upgradeReleases + "versions.txt";
2829
private bool _test = false; // when set to "true" will run in test mode without actually updating site
@@ -232,6 +233,7 @@ public class Updater : WebService {
232233
DeleteDir("\\editors");
233234
DeleteDir("\\Modules");
234235
DeleteDir("\\pics");
236+
DeleteDir("\\App_Data\\datastore\\widgets");
235237

236238
ReplaceDir("\\Account");
237239
ReplaceDir("\\admin");
@@ -247,7 +249,8 @@ public class Updater : WebService {
247249
ReplaceDir("\\Scripts");
248250
ReplaceDir("\\Content");
249251
ReplaceDir("\\Custom\\Themes\\Standard");
250-
252+
ReplaceDir("\\Custom\\Widgets");
253+
251254
return "";
252255
}
253256
catch (Exception ex)

0 commit comments

Comments
 (0)