YAFLogo

balbes
  • balbes
  • 94% (Exalted)
  • YAF Lover Topic Starter
13 years ago
Quote:


[ArgumentException: Строка не может иметь нулевую длину.
Parameter name: oldValue]
System.String.Replace(String oldValue, String newValue) +0
YAF.DotNetNuke.YafDnnModule.Forum1_PageTitleSet(Object sender, ForumPageTitleArgs e) +61
YAF.Forum.FirePageTitleSet(Object sender, ForumPageTitleArgs e) +25
YAF.Modules.PageTitleModule.GeneratePageTitle() +604
YAF.Modules.PageTitleModule.ForumPage_Load(Object sender, EventArgs e) +5
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Control.LoadRecursive() +141
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

[PageLoadException: Строка не может иметь нулевую длину.
Имя параметра: oldValue]
DotNetNuke.Services.Exceptions.Exceptions.ProcessPageLoadException(Exception exc, String URL) +271
DotNetNuke.Framework.PageBase.OnError(EventArgs e) +395
System.Web.UI.Page.HandleError(Exception e) +84
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6776
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.default_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75



fixed YafDnnModule.ascx.cs

#region Usings

using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using YAF.Classes.Core;
using YAF.Classes.Data;
using YAF.Classes.Utils;

#endregion

namespace YAF.DotNetNuke
{
    /// <summary>
    ///   Summary description for DotNetNukeModule.
    /// </summary>
    public partial class YafDnnModule : PortalModuleBase, IActionable
    {
        private bool _createNewBoard;
        private Forum _forum1;
        private PortalSettings _portalSettings;
        private CDefault _basePage;

        private PortalSettings CurrentPortalSettings
        {
            get { return _portalSettings ?? (_portalSettings = PortalController.GetCurrentPortalSettings()); }
        }

        /// <summary>
        /// </summary>
        public string SessionUserKeyName
        {
            get { return String.Format("yaf_dnn_boardid{0}_userid{1}_portalid{2}", _forum1.BoardID, UserId, CurrentPortalSettings.PortalId); }
        }

        /// <summary>
        ///   BasePage
        /// </summary>
        public CDefault BasePage
        {
            get { return _basePage ?? (_basePage = GetDefault(this)); }
        }

        #region IActionable Members

        /// <summary>
        ///   Add Menu Entries to Module Container
        /// </summary>
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection actions = new ModuleActionCollection
                                                 {
                                                     {
                                                         GetNextActionID(), 
                                                         "Edit YAF Settings", 
                                                         ModuleActionType.AddContent, 
                                                         String.Empty, 
                                                         String.Empty, 
                                                         EditUrl(), 
                                                         false,
                                                         SecurityAccessLevel.Host, 
                                                         true, 
                                                         false
                                                     },
                                                     {
                                                         GetNextActionID(), 
                                                         "DNN User Importer",
                                                         ModuleActionType.AddContent, 
                                                         String.Empty, 
                                                         String.Empty, 
                                                         EditUrl("Import"), 
                                                         false,
                                                         SecurityAccessLevel.Host, 
                                                         true, 
                                                         false
                                                      }
                                                 };

                return actions;
            }
        }

        #endregion

        private void DotNetNukeModule_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
                return;

            // Check for user
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return;
            }

            try
            {
                // Get current Dnn user (DNN 4)
                // UserInfo dnnUserInfo = UserController.GetUser(CurrentPortalSettings.PortalId, UserId, false);

                // Get current Dnn user (DNN 5)
                UserInfo dnnUserInfo = UserController.GetUserById(CurrentPortalSettings.PortalId, UserId);

                //get the user from the membership provider
                MembershipUser dnnUser = Membership.GetUser(dnnUserInfo.Username, true);

                if (dnnUser == null)
                    return;

                // see if the roles have been syncronized...
                if (Session[SessionUserKeyName + "_rolesloaded"] == null)
                {
                    bool roleChanged = false;
                    foreach (string role in dnnUserInfo.Roles)
                    {
                        if (!Roles.RoleExists(role))
                        {
                            Roles.CreateRole(role);
                            roleChanged = true;
                        }

                        if (!Roles.IsUserInRole(dnnUserInfo.Username, role))
                            Roles.AddUserToRole(dnnUserInfo.Username, role);
                    }

                    if (roleChanged)
                        MarkRolesChanged();

                    Session[SessionUserKeyName + "_rolesloaded"] = true;
                }

                //Admin or Host user?
                if ((dnnUserInfo.IsSuperUser || dnnUserInfo.UserID == CurrentPortalSettings.AdministratorId) && _createNewBoard)
                    CreateNewBoard(dnnUserInfo, dnnUser);

                int yafUserId;

                try
                {
                    yafUserId = DB.user_get(_forum1.BoardID, dnnUser.ProviderUserKey);
                    if (yafUserId > 0)
                        Session[string.Format("{0}_userSync", SessionUserKeyName)] = true;
                }
                catch (Exception)
                {
                    yafUserId = 0;
                    Session[string.Format("{0}_userSync", SessionUserKeyName)] = null;
                }

                // Has this user been registered in YAF already?
                if (Session[string.Format("{0}_userSync", SessionUserKeyName)] != null)
                    return;

                if (yafUserId == 0)
                    yafUserId = CreateYafUser(dnnUserInfo, dnnUser);

                // super admin check...
                if (dnnUserInfo.IsSuperUser)
                {
                    CreateYafHostUser(yafUserId);
                }

                if (YafContext.Current.Settings != null)
                    RoleMembershipHelper.UpdateForumUser(dnnUser, YafContext.Current.Settings.BoardID);

                YafContext.Current.Cache.Clear();

                DataCache.ClearPortalCache(CurrentPortalSettings.PortalId, true);

                Session.Clear();
                Response.Redirect(Globals.NavigateURL(), true);
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }

        private static void MarkRolesChanged()
        {
            RolePrincipal rolePrincipal;
            if (Roles.CacheRolesInCookie)
            {
                string roleCookie = "";

                HttpCookie cookie = HttpContext.Current.Request.Cookies[Roles.CookieName];
                if (cookie != null)
                    roleCookie = cookie.Value;

                rolePrincipal = new RolePrincipal(HttpContext.Current.User.Identity, roleCookie);
            }
            else
                rolePrincipal = new RolePrincipal(HttpContext.Current.User.Identity);

            rolePrincipal.SetDirty();
        }

        private void CreateYafHostUser(int yafUserId)
        {
            // get this user information...
            DataTable userInfo = DB.user_list(_forum1.BoardID, yafUserId, null, null, null);

            if (userInfo.Rows.Count <= 0)
                return;

            DataRow row = userInfo.Rows[0];

            if (Convert.ToBoolean(row["IsHostAdmin"]))
                return;

            // fix the ishostadmin flag...
            UserFlags userFlags = new UserFlags(row["Flags"]) {IsHostAdmin = true};

            // update...
            DB.user_adminsave(_forum1.BoardID, yafUserId, row["Name"], row["DisplayName"], row["Email"], userFlags.BitValue, row["RankID"]);
        }

        private int CreateYafUser(UserInfo dnnUserInfo, MembershipUser dnnUser)
        {
            YafContext.Current.Cache.Clear();
            // setup roles
            RoleMembershipHelper.SetupUserRoles(_forum1.BoardID, dnnUser.UserName);

            // create the user in the YAF DB so profile can ge created...
            int? userId = RoleMembershipHelper.CreateForumUser(dnnUser, _forum1.BoardID);

            if (userId == null)
                return 0;

            // create profile
            YafUserProfile userProfile = YafUserProfile.GetProfile(dnnUser.UserName);
            // setup their inital profile information
            userProfile.Initialize(dnnUser.UserName, true);

            userProfile.RealName = dnnUserInfo.Profile.FullName;
            userProfile.Location = dnnUserInfo.Profile.Country;
            userProfile.Homepage = dnnUserInfo.Profile.Website;

            userProfile.Save();

            int yafUserId = UserMembershipHelper.GetUserIDFromProviderUserKey(dnnUser.ProviderUserKey);

            // Save User
            DB.user_save(yafUserId,
                         _forum1.BoardID,
                         null,
                         null,
                         null,
                         GetUserTimeZoneOffset(dnnUserInfo, CurrentPortalSettings),
                         null,
                         null,
                         null,
                         true,
                         null,
                         null,
                         null,
                         null,
                         null,
                         null);

            return yafUserId;
        }

        private void CreateNewBoard(UserInfo dnnUserInfo, MembershipUser dnnUser)
        {
            // Add new admin users to group
            if (!Roles.IsUserInRole(dnnUserInfo.Username, "Administrators"))
                Roles.AddUserToRole(dnnUserInfo.Username, "Administrators");

            if (dnnUserInfo.IsSuperUser)
            {
                //This is HOST and probably the first board.
                //The install routine already created the first board.
                //Make sure Module settings are in place
                ModuleController objForumSettings = new ModuleController();
                objForumSettings.UpdateModuleSetting(ModuleId, "forumboardid", "1");
                objForumSettings.UpdateModuleSetting(ModuleId, "forumcategoryid", string.Empty);
                _forum1.BoardID = 1;
            }
            else
            {
                // This is an admin adding a new forum.
                string newBoardName = "{0} Forums".FormatWith(CurrentPortalSettings.PortalName);

                //Create the board

                YafCultureInfo yafCultureInfo = GetYafCultureInfo(Localization.GetPageLocale(CurrentPortalSettings));

                int largestBoardId = DB.board_create(dnnUserInfo.Username,
                                                     dnnUserInfo.Email,
                                                     dnnUser.ProviderUserKey,
                                                     newBoardName,
                                                     yafCultureInfo.Culture,
                                                     yafCultureInfo.LanguageFile,
                                                     "DotNetNuke",
                                                     "DotNetNuke");

                //Assign the new forum to this module
                ModuleController objForumSettings = new ModuleController();
                objForumSettings.UpdateModuleSetting(ModuleId, "forumboardid", largestBoardId.ToString());
                objForumSettings.UpdateModuleSetting(ModuleId, "forumcategoryid", string.Empty);
                _forum1.BoardID = largestBoardId;
            }
        }

        /// <summary>
        ///   Change Page Title
        /// </summary>
        /// <param name = "sender"></param>
        /// <param name = "e"></param>
        private void Forum1_PageTitleSet(object sender, ForumPageTitleArgs e)
        {
            if (!string.IsNullOrEmpty(CurrentPortalSettings.ActiveTab.Title))
                BasePage.Title = BasePage.Title.Replace(CurrentPortalSettings.ActiveTab.Title, string.Empty);
        }

        /// <summary>
        /// </summary>
        /// <param name = "e"></param>
        protected override void OnInit(EventArgs e)
        {
            InitializeComponent();

            base.OnInit(e);
        }

        /// <summary>
        /// </summary>
        private void InitializeComponent()
        {
            if (AJAX.IsInstalled())
            {
                AJAX.RegisterScriptManager();
            }

            _forum1 = new Forum();

            pnlModuleContent.Controls.Add(_forum1);

            Load += DotNetNukeModule_Load;
            _forum1.PageTitleSet += Forum1_PageTitleSet;

            //Get current BoardID
            try
            {
                _createNewBoard = false;
                // This will create an error if there is no setting for forumboardid
                _forum1.BoardID = int.Parse(Settings["forumboardid"].ToString());

                SetDnnLangToYaf();

                string cId = Settings["forumcategoryid"].ToString();

                if (cId != string.Empty)
                    _forum1.CategoryID = int.Parse(cId);
            }
            catch (Exception)
            {
                //A forum does not exist for this module
                //Create a new board
                _createNewBoard = true;
                //forum1.BoardID = 1;
            }
        }

        /// <summary>
        ///   Change YAF Language based on DNN Language, 
        ///   this will override the YAF Language Setting
        /// </summary>
        private void SetDnnLangToYaf()
        {
            YafCultureInfo yafCultureInfo = GetYafCultureInfo(Localization.GetPageLocale(CurrentPortalSettings));
            YafContext.Current.BoardSettings.Culture = yafCultureInfo.Culture;
            YafContext.Current.BoardSettings.Language = yafCultureInfo.LanguageFile;
        }

        protected override void OnError(EventArgs e)
        {
            Exception x = Server.GetLastError();
            DB.eventlog_create(YafContext.Current.PageUserID, this, x);
            base.OnError(e);
        }

        private static int GetUserTimeZoneOffset(UserInfo userInfo, PortalSettings portalSettings)
        {
            int timeZone;
            if ((userInfo != null) && (userInfo.UserID != Null.NullInteger))
                timeZone = userInfo.Profile.TimeZone;
            else
                timeZone = portalSettings.TimeZoneOffset;
            return timeZone;
        }

        private static Dictionary<string, string> GetYafCultures()
        {
            Dictionary<string, string> yafCultures = new Dictionary<string, string>();
            DataTable cult = StaticDataHelper.Cultures();

            foreach (DataRow row in cult.Rows)
            {
                try
                {
                    yafCultures.Add(row["CultureTag"].ToString(), row["CultureFile"].ToString());
                }
                catch
                {
                    continue;
                }
            }

            if (yafCultures.Count == 0)
            {
                yafCultures.Add("en", "english.xml");
            }

            return yafCultures;
        }

        private static YafCultureInfo GetYafCultureInfo(CultureInfo cultureInfo)
        {
            string culture = "en";
            string lngFile = "english.xml";
            Dictionary<string, string> cultures = GetYafCultures();
            YafCultureInfo yafCultureInfo = new YafCultureInfo();

            if (cultureInfo != null)
            {
                if (cultures.ContainsKey(cultureInfo.TwoLetterISOLanguageName))
                {
                    culture = cultureInfo.TwoLetterISOLanguageName;
                    lngFile = cultures[cultureInfo.TwoLetterISOLanguageName];
                }
                else if (cultures.ContainsKey(cultureInfo.Name))
                {
                    culture = cultureInfo.Name;
                    lngFile = cultures[cultureInfo.Name];
                }
            }

            yafCultureInfo.Culture = culture;
            yafCultureInfo.LanguageFile = lngFile;

            return yafCultureInfo;
        }

        private static CDefault GetDefault(Control c)
        {
            Control parent = c.Parent;
            if (parent != null)
            {
                if (parent is CDefault)
                {
                    return (CDefault)parent;
                }
                return GetDefault(parent);
            }
            return null;
        }

        #region Nested type: YafCultureInfo

        private struct YafCultureInfo
        {
            public string Culture;
            public string LanguageFile;
        }

        #endregion
    }
}

mir scheissegal
Sponsor

tha_watcha
  • tha_watcha
  • 100% (Exalted)
  • YAF.NET Project Lead 🤴 YAF Version: 3.0.3
13 years ago
Thx. Committed Changes Rev. 4143
balbes
  • balbes
  • 94% (Exalted)
  • YAF Lover Topic Starter
13 years ago
Es fällt mir schwer...
Tnx u

mir scheissegal
YAF Logo Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved
About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button