Skip to content

Commit cf0be40

Browse files
committed
Refactored widgets to be providers
1 parent dd561bd commit cf0be40

34 files changed

Lines changed: 347 additions & 637 deletions

src/Libraries/SmartStore.Core/WebHelper.cs

Lines changed: 15 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Web;
99
using System.Web.Configuration;
1010
using System.Web.Hosting;
11+
using SmartStore.Collections;
1112
using SmartStore.Core.Data;
1213
using SmartStore.Core.Domain;
1314
using SmartStore.Core.Domain.Stores;
@@ -371,92 +372,14 @@ public virtual string MapPath(string path)
371372
/// <returns>New url</returns>
372373
public virtual string ModifyQueryString(string url, string queryStringModification, string anchor)
373374
{
374-
if (url == null)
375-
url = string.Empty;
376-
url = url.ToLowerInvariant();
375+
var parts = url.EmptyNull().Split(new[] { '?' });
376+
var current = new QueryString(parts.Length == 2 ? parts[1] : "");
377+
var modify = new QueryString(queryStringModification.EmptyNull());
377378

378-
if (queryStringModification == null)
379-
queryStringModification = string.Empty;
380-
queryStringModification = queryStringModification.ToLowerInvariant();
379+
current.AddRange(modify);
381380

382-
if (anchor == null)
383-
anchor = string.Empty;
384-
anchor = anchor.ToLowerInvariant();
385-
386-
387-
string str = string.Empty;
388-
string str2 = string.Empty;
389-
if (url.Contains("#"))
390-
{
391-
str2 = url.Substring(url.IndexOf("#") + 1);
392-
url = url.Substring(0, url.IndexOf("#"));
393-
}
394-
if (url.Contains("?"))
395-
{
396-
str = url.Substring(url.IndexOf("?") + 1);
397-
url = url.Substring(0, url.IndexOf("?"));
398-
}
399-
if (!string.IsNullOrEmpty(queryStringModification))
400-
{
401-
if (!string.IsNullOrEmpty(str))
402-
{
403-
var dictionary = new Dictionary<string, string>();
404-
foreach (string str3 in str.Split(new char[] { '&' }))
405-
{
406-
if (!string.IsNullOrEmpty(str3))
407-
{
408-
string[] strArray = str3.Split(new char[] { '=' });
409-
if (strArray.Length == 2)
410-
{
411-
dictionary[strArray[0]] = strArray[1];
412-
}
413-
else
414-
{
415-
dictionary[str3] = null;
416-
}
417-
}
418-
}
419-
foreach (string str4 in queryStringModification.Split(new char[] { '&' }))
420-
{
421-
if (!string.IsNullOrEmpty(str4))
422-
{
423-
string[] strArray2 = str4.Split(new char[] { '=' });
424-
if (strArray2.Length == 2)
425-
{
426-
dictionary[strArray2[0]] = strArray2[1];
427-
}
428-
else
429-
{
430-
dictionary[str4] = null;
431-
}
432-
}
433-
}
434-
var builder = new StringBuilder();
435-
foreach (string str5 in dictionary.Keys)
436-
{
437-
if (builder.Length > 0)
438-
{
439-
builder.Append("&");
440-
}
441-
builder.Append(str5);
442-
if (dictionary[str5] != null)
443-
{
444-
builder.Append("=");
445-
builder.Append(dictionary[str5]);
446-
}
447-
}
448-
str = builder.ToString();
449-
}
450-
else
451-
{
452-
str = queryStringModification;
453-
}
454-
}
455-
if (!string.IsNullOrEmpty(anchor))
456-
{
457-
str2 = anchor;
458-
}
459-
return (url + (string.IsNullOrEmpty(str) ? "" : ("?" + str)) + (string.IsNullOrEmpty(str2) ? "" : ("#" + str2))).ToLowerInvariant();
381+
var result = "{0}{1}{2}".FormatCurrent(parts[0], current.ToString(), anchor.NullEmpty() == null ? "" : "#" + anchor);
382+
return result;
460383
}
461384

462385
/// <summary>
@@ -467,61 +390,16 @@ public virtual string ModifyQueryString(string url, string queryStringModificati
467390
/// <returns>New url</returns>
468391
public virtual string RemoveQueryString(string url, string queryString)
469392
{
470-
if (url == null)
471-
url = string.Empty;
472-
url = url.ToLowerInvariant();
473-
474-
if (queryString == null)
475-
queryString = string.Empty;
476-
queryString = queryString.ToLowerInvariant();
393+
var parts = url.EmptyNull().Split(new[] { '?' });
394+
var current = new QueryString(parts.Length == 2 ? parts[1] : "");
477395

396+
if (current.Count > 0 && queryString.HasValue())
397+
{
398+
current.Remove(queryString);
399+
}
478400

479-
string str = string.Empty;
480-
if (url.Contains("?"))
481-
{
482-
str = url.Substring(url.IndexOf("?") + 1);
483-
url = url.Substring(0, url.IndexOf("?"));
484-
}
485-
if (!string.IsNullOrEmpty(queryString))
486-
{
487-
if (!string.IsNullOrEmpty(str))
488-
{
489-
var dictionary = new Dictionary<string, string>();
490-
foreach (string str3 in str.Split(new char[] { '&' }))
491-
{
492-
if (!string.IsNullOrEmpty(str3))
493-
{
494-
string[] strArray = str3.Split(new char[] { '=' });
495-
if (strArray.Length == 2)
496-
{
497-
dictionary[strArray[0]] = strArray[1];
498-
}
499-
else
500-
{
501-
dictionary[str3] = null;
502-
}
503-
}
504-
}
505-
dictionary.Remove(queryString);
506-
507-
var builder = new StringBuilder();
508-
foreach (string str5 in dictionary.Keys)
509-
{
510-
if (builder.Length > 0)
511-
{
512-
builder.Append("&");
513-
}
514-
builder.Append(str5);
515-
if (dictionary[str5] != null)
516-
{
517-
builder.Append("=");
518-
builder.Append(dictionary[str5]);
519-
}
520-
}
521-
str = builder.ToString();
522-
}
523-
}
524-
return (url + (string.IsNullOrEmpty(str) ? "" : ("?" + str)));
401+
var result = "{0}{1}".FormatCurrent(parts[0], current.ToString());
402+
return result;
525403
}
526404

527405
/// <summary>

src/Libraries/SmartStore.Data/Migrations/201406262150229_Providers.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public void MigrateLocaleResources(LocaleResourcesBuilder builder)
6666
builder.AddOrUpdate("Admin.Plugins.KnownGroup.Design", "Design", "Design");
6767
builder.AddOrUpdate("Admin.Plugins.KnownGroup.Misc", "Miscellaneous", "Sonstige");
6868

69+
builder.AddOrUpdate("Admin.Providers.ProvidingPlugin", "Providing plugin", "Bereitstellendes Plugin");
70+
6971
builder.AddOrUpdate("Admin.PromotionFeeds", "Promotion feeds", "Promotion Feeds");
7072

7173
// some admin menu renaming / new entries

src/Libraries/SmartStore.Services/Cms/IWidget.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Collections.Generic;
22
using System.Web.Routing;
3+
using SmartStore.Core.Plugins;
34

45
namespace SmartStore.Services.Cms
56
{
67
/// <summary>
78
/// Provides an interface for creating widgets
89
/// </summary>
9-
public partial interface IWidget
10+
public partial interface IWidget : IProvider, IUserEditable
1011
{
1112
/// <summary>
1213
/// Gets widget zones where this widget should be rendered
@@ -19,7 +20,7 @@ public partial interface IWidget
1920
/// </summary>
2021
/// <param name="widgetZone">Widget zone where it's displayed</param>
2122
/// <param name="model">The model of the parent view context</param>
22-
/// <param name="storeId">The of the current store</param>
23+
/// <param name="storeId">The id of the current store</param>
2324
/// <param name="actionName">Action name</param>
2425
/// <param name="controllerName">Controller name</param>
2526
/// <param name="routeValues">Route values</param>

src/Libraries/SmartStore.Services/Cms/IWidgetPlugin.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/Libraries/SmartStore.Services/Cms/IWidgetService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using SmartStore.Core.Plugins;
23

34
namespace SmartStore.Services.Cms
45
{
@@ -12,7 +13,7 @@ public partial interface IWidgetService
1213
/// </summary>
1314
/// <param name="storeId">Load records allows only in specified store; pass 0 to load all records</param>
1415
/// <returns>Widgets</returns>
15-
IList<IWidgetPlugin> LoadActiveWidgets(int storeId = 0);
16+
IEnumerable<Provider<IWidget>> LoadActiveWidgets(int storeId = 0);
1617

1718

1819
/// <summary>
@@ -21,20 +22,20 @@ public partial interface IWidgetService
2122
/// <param name="widgetZone">Widget zone</param>
2223
/// <param name="storeId">Load records allows only in specified store; pass 0 to load all records</param>
2324
/// <returns>Widgets</returns>
24-
IList<IWidgetPlugin> LoadActiveWidgetsByWidgetZone(string widgetZone, int storeId = 0);
25+
IEnumerable<Provider<IWidget>> LoadActiveWidgetsByWidgetZone(string widgetZone, int storeId = 0);
2526

2627
/// <summary>
2728
/// Load widget by system name
2829
/// </summary>
2930
/// <param name="systemName">System name</param>
3031
/// <returns>Found widget</returns>
31-
IWidgetPlugin LoadWidgetBySystemName(string systemName);
32+
Provider<IWidget> LoadWidgetBySystemName(string systemName);
3233

3334
/// <summary>
3435
/// Load all widgets
3536
/// </summary>
3637
/// <param name="storeId">Load records allows only in specified store; pass 0 to load all records</param>
3738
/// <returns>Widgets</returns>
38-
IList<IWidgetPlugin> LoadAllWidgets(int storeId = 0);
39+
IEnumerable<Provider<IWidget>> LoadAllWidgets(int storeId = 0);
3940
}
4041
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
2+
using System.Linq;
23
using SmartStore.Core.Domain.Cms;
4+
using SmartStore.Core.Plugins;
35

46
namespace SmartStore.Services.Cms
57
{
68
public static class WidgetExtensions
79
{
8-
public static bool IsWidgetActive(this IWidgetPlugin widget, WidgetSettings widgetSettings)
10+
public static bool IsWidgetActive(this Provider<IWidget> widget, WidgetSettings widgetSettings)
911
{
1012
Guard.ArgumentNotNull(() => widget);
1113
Guard.ArgumentNotNull(() => widgetSettings);
@@ -15,13 +17,7 @@ public static bool IsWidgetActive(this IWidgetPlugin widget, WidgetSettings widg
1517
return false;
1618
}
1719

18-
foreach (string systemName in widgetSettings.ActiveWidgetSystemNames)
19-
{
20-
if (widget.PluginDescriptor.SystemName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase))
21-
return true;
22-
}
23-
24-
return false;
20+
return widgetSettings.ActiveWidgetSystemNames.Contains(widget.Metadata.SystemName, StringComparer.OrdinalIgnoreCase);
2521
}
2622
}
2723
}

0 commit comments

Comments
 (0)