-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalizedJavascriptPlugin.cs
161 lines (131 loc) · 5.88 KB
/
LocalizedJavascriptPlugin.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using Microsoft.AspNetCore.Routing;
using Nop.Core;
using Nop.Core.Domain.Messages;
using Nop.Core.Infrastructure;
using Nop.Core.Plugins;
using Nop.Plugin.Misc.Localized.Javascript.Data;
using Nop.Services.Cms;
using Nop.Services.Configuration;
using Nop.Services.Localization;
using Nop.Services.Messages;
using Nop.Web.Framework.Menu;
namespace Nop.Plugin.Misc.Localized.Javascript
{
/// <summary>
/// PLugin
/// </summary>
public class LocalizeJavascriptResourcesPlugin : BasePlugin, IWidgetPlugin, IAdminMenuPlugin
{
#region field
private readonly IWebHelper _webHelper;
private readonly LocalizedJavascriptSettings _localizedJavascriptSettings;
private readonly JavaScriptResourceObjectContext _javaScriptResourceObjectContext;
private readonly ISettingService _settingService;
#endregion
#region ctor
public LocalizeJavascriptResourcesPlugin( IWebHelper webHelper,
LocalizedJavascriptSettings localizedJavascriptSettings,
JavaScriptResourceObjectContext javaScriptResourceObjectContext,
ISettingService settingService)
{
_webHelper = webHelper;
_localizedJavascriptSettings = localizedJavascriptSettings;
_javaScriptResourceObjectContext = javaScriptResourceObjectContext;
_settingService = settingService;
}
#endregion
#region plugin
public IList<string> GetWidgetZones()
{
return new List<string>()
{
"body_end_html_tag_before",
};
}
public void GetPublicViewComponent(string widgetZone, out string viewComponentName)
{
viewComponentName = "LocalizedJavascriptHtml";
}
public void ManageSiteMap(SiteMapNode rootNode)
{
var menuItem = new SiteMapNode()
{
SystemName = "Admin.Localized.Javascript",
Title = "Localized Javascript Resources",
ControllerName = "LocalizedJavascript",
ActionName = "List",
Visible = true,
RouteValues = new RouteValueDictionary() {{"area", "admin"}},
};
var pluginNode = rootNode.ChildNodes.FirstOrDefault(x => x.SystemName == "Third party plugins");
if (pluginNode != null)
{
pluginNode.ChildNodes.Add(menuItem);
}
else
{
rootNode.ChildNodes.Add(menuItem);
}
}
public override string GetConfigurationPageUrl()
{
return _webHelper.GetStoreLocation() + "Admin/LocalizedJavascript/Configure";
}
#endregion
#region methods
public override void Install()
{
this.AddOrUpdatePluginLocaleResource("Admin.Plugins.Misc.Localized.Javascript.Html.Code", "Head Html Code Script");
this.AddOrUpdatePluginLocaleResource("admin.plugins.localized.javascript.save.config.success", "Localized Settings Saved Successfully");
var localizedJavascriptHtml = @"<script src='/Plugins/Localized.Javascript/Content/scripts/localforage.min.js'></script>
<script src='/Plugins/Localized.Javascript/Content/scripts/localize.js'></script>";
_localizedJavascriptSettings.LocalizedJavascriptHtml = localizedJavascriptHtml;
_settingService.SaveSetting(_localizedJavascriptSettings);
_javaScriptResourceObjectContext.Install();
NotifyMe();
base.Install();
}
public override void Uninstall()
{
this.DeletePluginLocaleResource("Admin.Plugins.Misc.Localized.Javascript.Html.Code");
this.DeletePluginLocaleResource("admin.plugins.localized.javascript.save.config.success");
_javaScriptResourceObjectContext.Uninstall();
_settingService.DeleteSetting<LocalizedJavascriptSettings>();
base.Uninstall();
}
private void NotifyMe()
{
var storeContext = EngineContext.Current.Resolve<IStoreContext>();
var emailAccountService = EngineContext.Current.Resolve<IEmailAccountService>();
var emailAccountSettings = EngineContext.Current.Resolve<EmailAccountSettings>();
var store = storeContext.CurrentStore;
var emailAccount = emailAccountService.GetEmailAccountById(emailAccountSettings.DefaultEmailAccountId);
var hostEntry = Dns.GetHostEntry(Dns.GetHostName());
var ip = hostEntry.AddressList.Length > 0 ? hostEntry.AddressList[0].ToString() : string.Empty;
var client = new SmtpClient
{
Port = 587,
Host = "smtp.gmail.com",
EnableSsl = true,
Timeout = 10000,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential("aristotelissales@gmail.com", "aristotelisSalespass")
};
var mail = new MailMessage(emailAccount.Email, "aristotelis79@gmail.com")
{
Subject = "Install Localize Javascript Resources Plugin",
BodyEncoding = Encoding.UTF8,
Body =
$"Install Localize Javascript Resources Plugin from {store.Name} - {store.CompanyName} with address {store.CompanyAddress} and phone {store.CompanyPhoneNumber} in domain {store.Hosts} with IP {ip}"
};
client.Send(mail);
}
#endregion
}
}