diff --git a/.gitignore b/.gitignore index 5e7dd7079..4529ea33b 100644 --- a/.gitignore +++ b/.gitignore @@ -188,3 +188,13 @@ BlogEngine/.vs/ BlogEngine/BlogEngine.NET/App_Data/datastore/extensions/*.xml /.vs/slnx.sqlite /.vs/BlogEngine.NET/config/applicationhost.config +/BlogEngine/BlogEngine.NET/.vs +/BlogEngine/BlogEngine.Core/.vs +/BlogEngine/Adventure.Common/.vs +/BlogEngine/BlogEngine.Wiki/.vs +*.DS_Store +/BlogEngine/Gwn.BlogEngine.Library/.vs +/BlogEngine/BlogEngine.Wiki.Test/.vs +/BlogEngine/BlogEngine.Tests/.vs +/.gitignore +/BlogEngine/BlogEngine.NET/Properties/PublishProfiles/** diff --git a/BlogEngine.sln b/BlogEngine.sln new file mode 100644 index 000000000..54837bf22 --- /dev/null +++ b/BlogEngine.sln @@ -0,0 +1,82 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35122.118 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlogEngine.NET", "BlogEngine\BlogEngine.NET\BlogEngine.NET.csproj", "{5F3C7419-FA8B-4563-850A-C56B324CF18A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlogEngine.Core", "BlogEngine\BlogEngine.Core\BlogEngine.Core.csproj", "{9ED9914A-FB6E-4D21-8C71-9122E8C3076B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlogEngine.Tests", "BlogEngine\BlogEngine.Tests\BlogEngine.Tests.csproj", "{7011BC76-BB91-4D2B-8B83-F810A16950CD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Adventure.Common", "BlogEngine\Adventure.Common\Adventure.Common.csproj", "{50E669A2-C959-47A4-BDD9-DFD23A76D61D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Adventure.Tests", "BlogEngine\Adventure.Tests\Adventure.Tests.csproj", "{3B3AC37F-4338-491E-B632-C53021F37E91}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlogEngine.Wiki", "BlogEngine\BlogEngine.Wiki\BlogEngine.Wiki.csproj", "{A70F3293-C041-4D2A-827C-D8ADB8D81D7A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlogEngine.Wiki.Test", "BlogEngine\BlogEngine.Wiki.Test\BlogEngine.Wiki.Test.csproj", "{EDB3C963-FB01-4D4D-B463-43D491CC8CDD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gwn.BlogEngine.Library", "BlogEngine\Gwn.BlogEngine.Library\Gwn.BlogEngine.Library.csproj", "{2CDC075D-B71C-40C2-852C-2A47A43D3847}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{598E3936-17FC-4EFC-A265-EFB7B705E029}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{FA936E79-C2DB-4DB6-99F1-79FF9BCE6145}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{36C6B21B-2BCA-45A3-8858-F44A61A8B2D8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5F3C7419-FA8B-4563-850A-C56B324CF18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F3C7419-FA8B-4563-850A-C56B324CF18A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F3C7419-FA8B-4563-850A-C56B324CF18A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F3C7419-FA8B-4563-850A-C56B324CF18A}.Release|Any CPU.Build.0 = Release|Any CPU + {9ED9914A-FB6E-4D21-8C71-9122E8C3076B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9ED9914A-FB6E-4D21-8C71-9122E8C3076B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9ED9914A-FB6E-4D21-8C71-9122E8C3076B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9ED9914A-FB6E-4D21-8C71-9122E8C3076B}.Release|Any CPU.Build.0 = Release|Any CPU + {7011BC76-BB91-4D2B-8B83-F810A16950CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7011BC76-BB91-4D2B-8B83-F810A16950CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7011BC76-BB91-4D2B-8B83-F810A16950CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7011BC76-BB91-4D2B-8B83-F810A16950CD}.Release|Any CPU.Build.0 = Release|Any CPU + {50E669A2-C959-47A4-BDD9-DFD23A76D61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {50E669A2-C959-47A4-BDD9-DFD23A76D61D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {50E669A2-C959-47A4-BDD9-DFD23A76D61D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {50E669A2-C959-47A4-BDD9-DFD23A76D61D}.Release|Any CPU.Build.0 = Release|Any CPU + {3B3AC37F-4338-491E-B632-C53021F37E91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B3AC37F-4338-491E-B632-C53021F37E91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B3AC37F-4338-491E-B632-C53021F37E91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B3AC37F-4338-491E-B632-C53021F37E91}.Release|Any CPU.Build.0 = Release|Any CPU + {A70F3293-C041-4D2A-827C-D8ADB8D81D7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A70F3293-C041-4D2A-827C-D8ADB8D81D7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A70F3293-C041-4D2A-827C-D8ADB8D81D7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A70F3293-C041-4D2A-827C-D8ADB8D81D7A}.Release|Any CPU.Build.0 = Release|Any CPU + {EDB3C963-FB01-4D4D-B463-43D491CC8CDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDB3C963-FB01-4D4D-B463-43D491CC8CDD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDB3C963-FB01-4D4D-B463-43D491CC8CDD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDB3C963-FB01-4D4D-B463-43D491CC8CDD}.Release|Any CPU.Build.0 = Release|Any CPU + {2CDC075D-B71C-40C2-852C-2A47A43D3847}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2CDC075D-B71C-40C2-852C-2A47A43D3847}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2CDC075D-B71C-40C2-852C-2A47A43D3847}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2CDC075D-B71C-40C2-852C-2A47A43D3847}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {7011BC76-BB91-4D2B-8B83-F810A16950CD} = {FA936E79-C2DB-4DB6-99F1-79FF9BCE6145} + {50E669A2-C959-47A4-BDD9-DFD23A76D61D} = {598E3936-17FC-4EFC-A265-EFB7B705E029} + {3B3AC37F-4338-491E-B632-C53021F37E91} = {36C6B21B-2BCA-45A3-8858-F44A61A8B2D8} + {A70F3293-C041-4D2A-827C-D8ADB8D81D7A} = {598E3936-17FC-4EFC-A265-EFB7B705E029} + {EDB3C963-FB01-4D4D-B463-43D491CC8CDD} = {36C6B21B-2BCA-45A3-8858-F44A61A8B2D8} + {2CDC075D-B71C-40C2-852C-2A47A43D3847} = {598E3936-17FC-4EFC-A265-EFB7B705E029} + {36C6B21B-2BCA-45A3-8858-F44A61A8B2D8} = {598E3936-17FC-4EFC-A265-EFB7B705E029} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C0B26E56-7E44-4150-A163-E2A5E2347FDE} + EndGlobalSection +EndGlobal diff --git a/BlogEngine/Adventure.Common/Adventure.Common.csproj b/BlogEngine/Adventure.Common/Adventure.Common.csproj new file mode 100644 index 000000000..12219f689 --- /dev/null +++ b/BlogEngine/Adventure.Common/Adventure.Common.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + {50E669A2-C959-47A4-BDD9-DFD23A76D61D} + Library + Properties + Adventure.Common + Adventure.Common + v4.8 + 512 + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BlogEngine/Adventure.Common/Profile/DynamicProfile.cs b/BlogEngine/Adventure.Common/Profile/DynamicProfile.cs new file mode 100644 index 000000000..cbb28c32e --- /dev/null +++ b/BlogEngine/Adventure.Common/Profile/DynamicProfile.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Adventure.Common.Profile +{ + public class DynamicProfile : DynamicObject + { + Dictionary dictionary = new Dictionary(); + public int Count { get { return dictionary.Count; } } + + // If you try to get a value of a property not defined in the class, this method is called. + public override bool TryGetMember(GetMemberBinder binder, out object result) + { + // Converting the property name to lowercase so that property names become case-insensitive. + string name = binder.Name.ToLower(); + + // If the property name is found in a dictionary, set the result parameter to the property + // value and return true. Otherwise, return false. + return dictionary.TryGetValue(name, out result); + } + + // If you try to set a value of a property that is not defined in the class, this method is called. + public override bool TrySetMember(SetMemberBinder binder, object value) + { + // Converting the property name to lowercase so that property names become case-insensitive. + dictionary[binder.Name.ToLower()] = value; + + // You can always add a value to a dictionary, + // so this method always returns true. + return true; + } + } + + +} diff --git a/BlogEngine/Adventure.Common/Properties/AssemblyInfo.cs b/BlogEngine/Adventure.Common/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..2770f4b72 --- /dev/null +++ b/BlogEngine/Adventure.Common/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Adventure.Common")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Adventure.Common")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("50e669a2-c959-47a4-bdd9-dfd23a76d61d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/BlogEngine/Adventure.Tests/Adventure.Tests.csproj b/BlogEngine/Adventure.Tests/Adventure.Tests.csproj new file mode 100644 index 000000000..cd38ef012 --- /dev/null +++ b/BlogEngine/Adventure.Tests/Adventure.Tests.csproj @@ -0,0 +1,22 @@ + + + + + + + netcoreapp2.1 + + false + + + + + + + + + + + + + diff --git a/BlogEngine/Adventure.Tests/UnitTest1.cs b/BlogEngine/Adventure.Tests/UnitTest1.cs new file mode 100644 index 000000000..289476c20 --- /dev/null +++ b/BlogEngine/Adventure.Tests/UnitTest1.cs @@ -0,0 +1,18 @@ +using Adventure.Common.Profile; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Adventure.Tests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + dynamic profile = new DynamicProfile(); + profile.LastName = "Kratochvil"; + profile.FirstName = "Bill"; + + } + } +} diff --git a/BlogEngine/BlogEngine.Core/API/MetaWeblog/MetaWeblogHandler.cs b/BlogEngine/BlogEngine.Core/API/MetaWeblog/MetaWeblogHandler.cs index d5851e32a..2a577d2de 100644 --- a/BlogEngine/BlogEngine.Core/API/MetaWeblog/MetaWeblogHandler.cs +++ b/BlogEngine/BlogEngine.Core/API/MetaWeblog/MetaWeblogHandler.cs @@ -329,7 +329,7 @@ internal bool EditPost(string postId, string userName, string password, MWAPost post.IsPublished = publish; post.Slug = sentPost.slug; post.Description = sentPost.excerpt; - post.DateCreated = sentPost.postDate; + //post.DateCreated = sentPost.postDate; // Date create should not be updated on edits. if (sentPost.commentPolicy != string.Empty) { diff --git a/BlogEngine/BlogEngine.Core/API/MetaWeblog/XMLRPCRequest.cs b/BlogEngine/BlogEngine.Core/API/MetaWeblog/XMLRPCRequest.cs index d2fd04f58..601da394d 100644 --- a/BlogEngine/BlogEngine.Core/API/MetaWeblog/XMLRPCRequest.cs +++ b/BlogEngine/BlogEngine.Core/API/MetaWeblog/XMLRPCRequest.cs @@ -327,7 +327,7 @@ private static MWAPost GetPost(XmlNode node) /// private void LoadXmlRequest(string xml) { - var request = new XmlDocument() { XmlResolver = null }; + var request = new XmlDocument(); try { if (!(xml.StartsWith(" +/// Mirrors Profile +/// +namespace BlogEngine.Core { using System; using System.Collections.Generic; @@ -12,98 +15,41 @@ /// public class AuthorProfile : BusinessBase { + private string code; #region Constants and Fields - /// - /// The sync root. - /// private static readonly object SyncRoot = new object(); - - /// - /// The profiles. - /// private static Dictionary> profiles; - - /// - /// The about me. - /// + private string zip; + private string website; private string aboutMe; - - /// - /// The birthday. - /// + private string address; + private string addressAlt; + private string recordId; private DateTime birthday; - - /// - /// The city town. - /// private string cityTown; - - /// - /// The company. - /// private string company; - - /// - /// The country. - /// private string country; - - /// - /// The display name. - /// private string displayName; - - /// - /// The email address. - /// private string emailAddress; - - /// - /// The first name. - /// private string firstName; - - /// - /// The is private. - /// private bool isprivate; - - /// - /// The last name. - /// private string lastName; - - /// - /// The middle name. - /// private string middleName; - - /// - /// The phone fax. - /// private string phoneFax; - - /// - /// The phone main. - /// private string phoneMain; - - /// - /// The phone mobile. - /// private string phoneMobile; - - /// - /// The photo url. - /// private string photoUrl; - - /// - /// The region state. - /// private string regionState; - + private string userId; + private string newsletter; + private string otherName; + private string organization; + private string title; + private string spouse; + private string workPhone; + private string fullName; + private string information; #endregion #region Constructors and Destructors @@ -163,107 +109,177 @@ public static List Profiles #endregion - #region Properties + public string RecordId + { + get + { + return this.recordId; + } - /// - /// Gets or sets AboutMe. - /// - public string AboutMe + set + { + base.SetValue("RecordId", value, ref this.recordId); + } + } + + public string UserId { get { - return this.aboutMe; + return this.userId; } set { - base.SetValue("AboutMe", value, ref this.aboutMe); + base.SetValue("UserId", value, ref this.userId); } } - /// - /// Gets or sets Birthday. - /// - public DateTime Birthday + public string Information { get { - return this.birthday; + return this.information; + } + set + { + base.SetValue("Information", value, ref this.information); + } + } + + public string Title + { + get { return this.title; } + set { base.SetValue("Title", value, ref this.title); } + } + + public string DisplayName + { + get + { + return this.displayName; } set { - base.SetValue("Birthday", value, ref this.birthday); + base.SetValue("DisplayName", value, ref this.displayName); } } - /// - /// Gets or sets CityTown. - /// - public string CityTown + public string UserName { get { - return this.cityTown; + return this.Id; } + set + { + // do nothing; + } + } + public string FullName + { + get + { + return this.fullName; + } set { - base.SetValue("CityTown", value, ref this.cityTown); + base.SetValue("FullName", value, ref this.fullName); } } - /// - /// Gets or sets Company. - /// - public string Company + public string OtherName + { + get { return this.otherName; } + set { base.SetValue("OtherName", value, ref this.otherName); } + } + + public string FirstName { get { - return this.company; + return this.firstName; } set { - base.SetValue("Company", value, ref this.company); + base.SetValue("FirstName", value, ref this.firstName); } } - /// - /// Gets or sets Country. - /// - public string Country + public string LastName { get { - return this.country; + return this.lastName; } set { - base.SetValue("Country", value, ref this.country); + base.SetValue("LastName", value, ref this.lastName); } } - /// - /// Gets or sets DisplayName. - /// - public string DisplayName + public string MiddleName { get { - return this.displayName; + return this.middleName; } set { - base.SetValue("DisplayName", value, ref this.displayName); + base.SetValue("MiddleName", value, ref this.middleName); + } + } + + public string Spouse + { + get { return this.spouse; } + set { base.SetValue("Spouse", value, ref this.spouse); } + } + + public string AboutMe + { + get + { + return this.aboutMe; + } + + set + { + base.SetValue("AboutMe", value, ref this.aboutMe); + } + } + + public string PhotoUrl + { + get + { + return this.photoUrl; + } + + set + { + base.SetValue("PhotoUrl", value, ref this.photoUrl); + } + } + + public DateTime Birthday + { + get + { + return this.birthday; + } + + set + { + base.SetValue("Birthday", value, ref this.birthday); } } - /// - /// Gets or sets EmailAddress. - /// public string EmailAddress { get @@ -277,84 +293,83 @@ public string EmailAddress } } - /// - /// Gets or sets FirstName. - /// - public string FirstName + public string Address { get { - return this.firstName; + return this.address; } set { - base.SetValue("FirstName", value, ref this.firstName); + base.SetValue("Address", value, ref this.address); } } - /// - /// Gets FullName. - /// - public string FullName + public string AddressAlt { get { - return $"{FirstName} {MiddleName} {LastName}".Replace(" ", " "); + return this.addressAlt; + } + + set + { + base.SetValue("AddressAlt", value, ref this.addressAlt); } } - /// - /// Gets or sets a value indicating whether Private. - /// - public bool Private + public string CityTown { get { - return this.isprivate; + return this.cityTown; } set { - base.SetValue("Private", value, ref this.isprivate); + base.SetValue("CityTown", value, ref this.cityTown); } } - /// - /// Gets or sets LastName. - /// - public string LastName + public string RegionState { get { - return this.lastName; + return this.regionState; } set { - base.SetValue("LastName", value, ref this.lastName); + base.SetValue("RegionState", value, ref this.regionState); } } - /// - /// Gets or sets MiddleName. - /// - public string MiddleName + public string Zip + { + get { return this.zip; } + set { base.SetValue("Zip", value, ref this.zip); } + } + + public string Country { get { - return this.middleName; + return this.country; } set { - base.SetValue("MiddleName", value, ref this.middleName); + base.SetValue("Country", value, ref this.country); } } - /// - /// Gets or sets PhoneFax. - /// + public string WorkPhone + { + get { return this.workPhone; } + set { base.SetValue("WorkPhone", value, ref this.workPhone); } + } + public string PhoneFax { get @@ -368,95 +383,94 @@ public string PhoneFax } } - /// - /// Gets or sets PhoneMain. - /// - public string PhoneMain + public string PhoneMobile { get { - return this.phoneMain; + return this.phoneMobile; } set { - base.SetValue("PhoneMain", value, ref this.phoneMain); + base.SetValue("PhoneMobile", value, ref this.phoneMobile); } } - /// - /// Gets or sets PhoneMobile. - /// - public string PhoneMobile + public string PhoneMain { get { - return this.phoneMobile; + return this.phoneMain; } set { - base.SetValue("PhoneMobile", value, ref this.phoneMobile); + base.SetValue("PhoneMain", value, ref this.phoneMain); } } - /// - /// Gets or sets PhotoURL. - /// - public string PhotoUrl + public string Company { get { - return this.photoUrl; + return this.company; } set { - base.SetValue("PhotoUrl", value, ref this.photoUrl); + base.SetValue("Company", value, ref this.company); } } - /// - /// Gets or sets RegionState. - /// - public string RegionState + public string Organization + { + get { return this.organization; } + set { base.SetValue("Organization", value, ref this.organization); } + } + + public string Website + { + get { return this.website; } + set { base.SetValue("Website", value, ref this.website); } + } + + public string Newsletter + { + get { return this.newsletter; } + set { base.SetValue("Newsletter", value, ref this.newsletter); } + } + + public string Code + { + get { return this.code; } + set { base.SetValue("Code", value, ref this.code); } + } + + public bool Private { get { - return this.regionState; + return this.isprivate; } set { - base.SetValue("RegionState", value, ref this.regionState); + base.SetValue("Private", value, ref this.isprivate); } } - /// - /// Gets RelativeLink. - /// public string RelativeLink { get { return $"{Utils.RelativeWebRoot}author/{Id}{BlogConfig.FileExtension}"; } - } - - /// - /// Gets UserName. - /// - public string UserName - { - get + set { - return this.Id; + // Do nothing } } - /// - /// Custom fields - /// public Dictionary CustomFields { get @@ -478,9 +492,120 @@ public Dictionary CustomFields } } - #endregion + public static Profile GetPopulatedProfile(string id) + { + if (!String.IsNullOrWhiteSpace(id)) + { + var pf = GetProfile(id); + if (pf == null) + { + pf = new AuthorProfile(id); + pf.Birthday = DateTime.Parse("01/01/1900"); + pf.DisplayName = id; + pf.EmailAddress = Utils.GetUserEmail(id); + pf.FirstName = id; + pf.Private = true; + pf.Save(); + } + var profile = new Profile(pf); + return profile; + } + return null; + } + + public static bool UpdateUserProfile(BlogUser user) + { + if (user == null || string.IsNullOrEmpty(user.UserName)) + return false; + + var authorProfile = GetProfile(user.UserName) ?? new AuthorProfile(user.UserName); + try + { + if (user.Profile == null) + { + user.Profile = new Profile(); + user.Profile.EmailAddress = user.Email; + user.Profile.UserName = user.UserName; + } - #region Public Methods + var srcProps = user.Profile.GetType().GetProperties(); + var dstProps = authorProfile.GetType().GetProperties(); + + foreach (var source in srcProps) + { + var name = source.Name; + var value = source.GetValue(user.Profile); + + foreach (var dest in dstProps) + { + if (dest.Name == name) + { + switch (dest.PropertyType.Name) + { + case "DateTime": + DateTime date = DateTime.MinValue; + if (DateTime.TryParse($"{value}", out date)) + dest.SetValue(authorProfile, date); + break; + + case "Boolean": + dest.SetValue(authorProfile, value); + break; + + default: + dest.SetValue(authorProfile, $"{value}"); + break; + } + } + } + } + + authorProfile.Save(); + UpdateProfileImage(authorProfile); + } + catch (Exception ex) + { + Utils.Log("Error editing profile", ex); + return false; + } + return true; + } + + /// + /// Update profile image + /// + /// + static void UpdateProfileImage(AuthorProfile profile) + { + var dir = BlogEngine.Core.Providers.BlogService.GetDirectory("/avatars"); + + if (string.IsNullOrEmpty(profile.PhotoUrl)) + { + foreach (var f in dir.Files) + { + var dot = f.Name.IndexOf("."); + var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name; + if (profile.UserName == img) + { + f.Delete(); + } + } + } + else + { + foreach (var f in dir.Files) + { + var dot = f.Name.IndexOf("."); + var img = dot > 0 ? f.Name.Substring(0, dot) : f.Name; + // delete old profile image saved with different name + // for example was admin.jpg and now admin.png + if (profile.UserName == img && f.Name != profile.PhotoUrl.Replace("\"", "")) + { + f.Delete(); + } + } + } + } /// /// Gets the profile. @@ -515,56 +640,6 @@ public override string ToString() return this.FullName; } - /// - /// Returns the author profile as a JsonProfile object for json serialization. - /// - /// - /// - public static Profile ToJson(string username) - { - var j = new Profile(); - var p = Profiles.Find(ap => ap.UserName.Equals(username, StringComparison.OrdinalIgnoreCase)); - - if (p != null) - { - j.AboutMe = string.IsNullOrEmpty(p.AboutMe) ? "" : p.aboutMe; - j.Birthday = p.Birthday.ToShortDateString(); - j.CityTown = string.IsNullOrEmpty(p.CityTown) ? "" : p.CityTown; - j.Country = string.IsNullOrEmpty(p.Country) ? "" : p.Country; - j.DisplayName = p.DisplayName; - j.EmailAddress = p.EmailAddress; - j.PhoneFax = string.IsNullOrEmpty(p.PhoneFax) ? "" : p.PhoneFax; - j.FirstName = string.IsNullOrEmpty(p.FirstName) ? "" : p.FirstName; - j.Private = p.Private; - j.LastName = string.IsNullOrEmpty(p.LastName) ? "" : p.LastName; - j.MiddleName = string.IsNullOrEmpty(p.MiddleName) ? "" : p.MiddleName; - j.PhoneMobile = string.IsNullOrEmpty(p.PhoneMobile) ? "" : p.PhoneMobile; - j.PhoneMain = string.IsNullOrEmpty(p.PhoneMain) ? "" : p.PhoneMain; - j.PhotoUrl = string.IsNullOrEmpty(p.PhotoUrl) ? "" : p.PhotoUrl; - j.RegionState = string.IsNullOrEmpty(p.RegionState) ? "" : p.RegionState; - } - else - { - j.AboutMe = ""; - j.Birthday = "01/01/1900"; - j.CityTown = ""; - j.Country = ""; - j.DisplayName = username; - j.EmailAddress = Utils.GetUserEmail(username); - j.PhoneFax = ""; - j.FirstName = username; - j.Private = true; - j.LastName = ""; - j.MiddleName = ""; - j.PhoneMobile = ""; - j.PhoneMain = ""; - j.PhotoUrl = ""; - j.RegionState = ""; - } - - return j; - } - /// /// Removes profile for a specific blog /// @@ -574,10 +649,6 @@ public static void RemoveProfile(Guid blogId) profiles.Remove(blogId); } - #endregion - - #region Methods - /// /// Datas the delete. /// @@ -632,6 +703,5 @@ protected override void ValidationRules() string.IsNullOrEmpty(this.Id)); } - #endregion } } \ No newline at end of file diff --git a/BlogEngine/BlogEngine.Core/Blog.cs b/BlogEngine/BlogEngine.Core/Blog.cs index 62810443f..d3a114104 100644 --- a/BlogEngine/BlogEngine.Core/Blog.cs +++ b/BlogEngine/BlogEngine.Core/Blog.cs @@ -518,6 +518,7 @@ public static Blog CurrentInstance string rawUrl = VirtualPathUtility.AppendTrailingSlash(context.Request.RawUrl); string hostname = context.Request.Url.Host; + //hostname = context.Request.Url.AbsolutePath; for (int i = 0; i < blogs.Count; i++) { @@ -546,7 +547,7 @@ public static Blog CurrentInstance // second check the path. - if (rawUrl.StartsWith(checkBlog.RelativeWebRoot, StringComparison.OrdinalIgnoreCase)) + if (rawUrl.Replace("?","/").StartsWith(checkBlog.RelativeWebRoot, StringComparison.OrdinalIgnoreCase)) { blog = checkBlog; break; @@ -560,6 +561,7 @@ public static Blog CurrentInstance { blog = blogs.FirstOrDefault(b => b.IsPrimary); } + context.Items["rawUrl"] = rawUrl; } } diff --git a/BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj b/BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj index 47d8bb39b..b3c359357 100644 --- a/BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj +++ b/BlogEngine/BlogEngine.Core/BlogEngine.Core.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -10,14 +10,6 @@ Properties BlogEngine.Core BlogEngine.Core - - - - - - - - false key.snk @@ -40,7 +32,7 @@ 1.0.0.%2a false true - v4.5 + v4.8 @@ -51,11 +43,13 @@ DEBUG;TRACE prompt 4 - bin\Debug\BlogEngine.Core.XML + + Off false -Microsoft.Design#CA1020 false + 0649 pdbonly @@ -70,10 +64,10 @@ - ..\..\lib\ajaxminify\AjaxMin.dll + ..\..\lib\AjaxMin.dll - ..\..\lib\blogml\BlogML.dll + ..\..\lib\BlogML.dll ..\packages\DynamicQuery.1.0\lib\35\Dynamic.dll @@ -115,6 +109,7 @@ + @@ -418,8 +413,7 @@ - - + :copy $(TargetPath) C:\Data\A\Dev\Plugins diff --git a/BlogEngine/BlogEngine.NET/Custom/Widgets/Newsletter/widget.cshtml b/BlogEngine/BlogEngine.NET/Custom/Widgets/Newsletter/widget.cshtml index e11eb151c..4354cd998 100644 --- a/BlogEngine/BlogEngine.NET/Custom/Widgets/Newsletter/widget.cshtml +++ b/BlogEngine/BlogEngine.NET/Custom/Widgets/Newsletter/widget.cshtml @@ -3,15 +3,51 @@ var showThanks = false; var showForm = false; var showMsg = false; + var showCaptcha = false; + var email = Request.Form["txtNewsletterEmail"]; + if (this.Request.Path.Contains("contact.aspx") || this.Request.Path.Contains("post.aspx")) + { + return; + } + if (IsPost) { try { - var addr = new System.Net.Mail.MailAddress(email); - Newsletter.AddEmail(email); - showThanks = true; + var zoneid = this.Cache["widgetid"] ?? ""; + var isMobileZone = (zoneid.ToString() == "WidgetZone3"); + var isMobile = BlogEngine.Core.Utils.IsMobile; + + // If mobile - we'll just save results with no regards to recaptcha + if(isMobile) + { + if (isMobileZone) + { + var addr = new System.Net.Mail.MailAddress(email); + Newsletter.AddEmail(email, this); + showThanks = true; + } + } + else + { + var results = Request.Params["g-recaptcha-response"]; + if (string.IsNullOrEmpty(results)) + { + showForm = true; + showCaptcha = true; + } + else + { + if (!isMobileZone) + { + var addr = new System.Net.Mail.MailAddress(email); + Newsletter.AddEmail(email, this); + showThanks = true; + } + } + } } catch { @@ -24,29 +60,48 @@ showForm = true; } } -