Ejemplo n.º 1
0
        public int Groups_Save(int portalId, ForumGroupInfo fg, bool isNew)
        {
            var rc = new Security.Roles.RoleController();
            var db = new Data.Common();

            var permissionsId = -1;

            if (fg.PermissionsId == -1)
            {
                var ri = rc.GetRoleByName(portalId, "Administrators");
                if (ri != null)
                {
                    fg.PermissionsId = db.CreatePermSet(ri.RoleID.ToString());
                    permissionsId    = fg.PermissionsId;
                }
            }

            var groupId = DataProvider.Instance().Groups_Save(portalId, fg.ModuleId, fg.ForumGroupId, fg.GroupName, fg.SortOrder, fg.Active, fg.Hidden, fg.PermissionsId, fg.PrefixURL);

            if (isNew)
            {
                Permissions.CreateDefaultSets(portalId, permissionsId);
                var moduleId = fg.ModuleId;
                var sKey     = "G:" + groupId.ToString();
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicsTemplateId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicTemplateId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicFormId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.ReplyFormId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.AllowRSS, "false");
            }

            DataCache.CacheClear(string.Format(CacheKeys.ForumList, fg.ModuleId));

            return(groupId);
        }
Ejemplo n.º 2
0
        public void Topics_Move(int PortalId, int ModuleId, int ForumId, int TopicId)
        {
            SettingsInfo settings = DataCache.MainSettings(ModuleId);

            if (settings.URLRewriteEnabled)
            {
                try
                {
                    Data.ForumsDB db         = new Data.ForumsDB();
                    int           oldForumId = -1;
                    oldForumId = db.Forum_GetByTopicId(TopicId);
                    ForumController fc = new ForumController();
                    Forum           fi = fc.Forums_Get(oldForumId, -1, false);
                    if (!(string.IsNullOrEmpty(fi.PrefixURL)))
                    {
                        Data.Common dbC  = new Data.Common();
                        string      sURL = dbC.GetUrl(ModuleId, fi.ForumGroupId, oldForumId, TopicId, -1, -1);
                        if (!(string.IsNullOrEmpty(sURL)))
                        {
                            dbC.ArchiveURL(PortalId, fi.ForumGroupId, ForumId, TopicId, sURL);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            DataProvider.Instance().Topics_Move(PortalId, ModuleId, ForumId, TopicId);
        }
Ejemplo n.º 3
0
        public int Groups_Save(int portalId, ForumGroupInfo fg, bool isNew)
        {
            var rc = new Security.Roles.RoleController();
            var db = new Data.Common();

            var permissionsId = -1;
            if (fg.PermissionsId == -1)
            {
                var ri = rc.GetRoleByName(portalId, "Administrators");
                if (ri != null)
                {
                    fg.PermissionsId = db.CreatePermSet(ri.RoleID.ToString());
                    permissionsId = fg.PermissionsId;
                }
            }

            var groupId = DataProvider.Instance().Groups_Save(portalId, fg.ModuleId, fg.ForumGroupId, fg.GroupName, fg.SortOrder, fg.Active, fg.Hidden, fg.PermissionsId, fg.PrefixURL);
            if (isNew)
            {
                Permissions.CreateDefaultSets(portalId, permissionsId);
                var moduleId = fg.ModuleId;
                var sKey = "G:" + groupId.ToString();
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicsTemplateId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicTemplateId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicFormId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.ReplyFormId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.AllowRSS, "false");
            }

            DataCache.CacheClear(string.Format(CacheKeys.ForumList, fg.ModuleId));

            return groupId;
        }
Ejemplo n.º 4
0
        public static string GetRoleIds(string[] Roles, int SiteId)
        {
            int    i       = 0;
            string RoleIds = "";
            var    db      = new Data.Common();
            object obj     = null;         // DataCache.CacheRetrieve(SiteId & "afroles")

            if (obj == null)
            {
                var rc = new Security.Roles.RoleController();
                foreach (Security.Roles.RoleInfo ri in rc.GetPortalRoles(SiteId))
                {
                    string roleName = ri.RoleName;
                    foreach (string role in Roles)
                    {
                        if (!string.IsNullOrEmpty(role))
                        {
                            if (roleName == role)
                            {
                                RoleIds += ri.RoleID.ToString() + ";";
                                break;
                            }
                        }
                    }
                }
                // DataCache.CacheStore(SiteId & "afroles", RoleIds)
            }
            return(RoleIds);
        }
        public HttpResponseMessage ToggleSecurity(ToggleSecurityDTO dto)
        {
            var db = new Data.Common();
            var sb = new StringBuilder();

            switch (dto.Action)
            {
            case "delete":
            {
                Permissions.RemoveObjectFromAll(dto.SecurityId, dto.SecurityType, dto.PermissionsId);
                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            case "addobject":
            {
                if (dto.SecurityType == 1)
                {
                    var uc = new UserController();
                    var ui = uc.GetUser(PortalSettings.PortalId, dto.ModuleId, dto.SecurityId);
                    dto.SecurityId = ui != null?ui.UserId.ToString() : string.Empty;
                }
                else
                {
                    if (dto.SecurityId.Contains(":"))
                    {
                        dto.SecurityType = 2;
                    }
                }
                if (!(string.IsNullOrEmpty(dto.SecurityId)))
                {
                    var permSet = db.GetPermSet(dto.PermissionsId, "View");
                    permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);
                    db.SavePermSet(dto.PermissionsId, "View", permSet);
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }

            default:
            {
                var permSet = db.GetPermSet(dto.PermissionsId, dto.SecurityKey);
                if (dto.Action == "remove")
                {
                    permSet = Permissions.RemovePermFromSet(dto.SecurityId, dto.SecurityType, permSet);
                }
                else
                {
                    permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);
                }

                db.SavePermSet(dto.PermissionsId, dto.SecurityKey, permSet);
                return(Request.CreateResponse(HttpStatusCode.OK, dto.Action + "|" + dto.ReturnId));
            }
            }
        }
Ejemplo n.º 6
0
        internal static bool RemoveObjectFromAll(string objectId, int objectType, int PermissionsId)
        {
            var   enumType = typeof(SecureActions);
            Array values   = Enum.GetValues(enumType);
            var   db       = new Data.Common();

            for (int i = 0; i < values.Length; i++)
            {
                string text    = Convert.ToString(Enum.Parse(enumType, values.GetValue(i).ToString()));
                string permSet = db.GetPermSet(PermissionsId, text);
                permSet = RemovePermFromSet(objectId, objectType, permSet);
                db.SavePermSet(PermissionsId, text, permSet);
            }
            return(true);
        }
        public HttpResponseMessage ToggleSecurity(ToggleSecurityDTO dto)
        {
            var db = new Data.Common();
            var sb = new StringBuilder();
            switch (dto.Action)
            {
                case "delete":
                    {
                        Permissions.RemoveObjectFromAll(dto.SecurityId, dto.SecurityType, dto.PermissionsId);
                        return Request.CreateResponse(HttpStatusCode.OK);
                    }
                case "addobject":
                    {
                        if (dto.SecurityType == 1)
                        {
                            var uc = new UserController();
                            var ui = uc.GetUser(PortalSettings.PortalId, dto.ModuleId, dto.SecurityId);
                            dto.SecurityId = ui != null ? ui.UserId.ToString() : string.Empty;
                        }
                        else
                        {
                            if (dto.SecurityId.Contains(":"))
                                dto.SecurityType = 2;
                        }
                        if (!(string.IsNullOrEmpty(dto.SecurityId)))
                        {
                            var permSet = db.GetPermSet(dto.PermissionsId, "View");
                            permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);
                            db.SavePermSet(dto.PermissionsId, "View", permSet);
                        }

                        return Request.CreateResponse(HttpStatusCode.OK);
                    }
                default:
                    {
                        var permSet = db.GetPermSet(dto.PermissionsId, dto.SecurityKey);
                        if (dto.Action == "remove")
                            permSet = Permissions.RemovePermFromSet(dto.SecurityId, dto.SecurityType, permSet);
                        else
                            permSet = Permissions.AddPermToSet(dto.SecurityId, dto.SecurityType, permSet);

                        db.SavePermSet(dto.PermissionsId, dto.SecurityKey, permSet);
                        return Request.CreateResponse(HttpStatusCode.OK, dto.Action + "|" + dto.ReturnId);
                    }
            }
        }
Ejemplo n.º 8
0
        internal static void CreateDefaultSets(int PortalId, int PermissionsId)
        {
            var db = new Data.Common();
            var rc = new Security.Roles.RoleController();

            Security.Roles.RoleInfo ri;
            ri = rc.GetRoleByName(PortalId, "Registered Users");
            string permSet;

            if (ri != null)
            {
                permSet = db.GetPermSet(PermissionsId, "View");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "View", permSet);
                permSet = db.GetPermSet(PermissionsId, "Read");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "Read", permSet);
                permSet = db.GetPermSet(PermissionsId, "Create");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "Create", permSet);
                permSet = db.GetPermSet(PermissionsId, "Reply");
                permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                db.SavePermSet(PermissionsId, "Reply", permSet);
            }
            permSet = db.GetPermSet(PermissionsId, "View");
            permSet = AddPermToSet("-3", 0, permSet);
            db.SavePermSet(PermissionsId, "View", permSet);
            permSet = db.GetPermSet(PermissionsId, "Read");
            permSet = AddPermToSet("-3", 0, permSet);
            db.SavePermSet(PermissionsId, "Read", permSet);
            permSet = db.GetPermSet(PermissionsId, "View");
            permSet = AddPermToSet("-1", 0, permSet);
            db.SavePermSet(PermissionsId, "View", permSet);
            permSet = db.GetPermSet(PermissionsId, "Read");
            permSet = AddPermToSet("-1", 0, permSet);
            db.SavePermSet(PermissionsId, "Read", permSet);
        }
        private void cbEditorAction_Callback(object sender, Controls.CallBackEventArgs e)
        {
            switch (e.Parameters[0].ToLowerInvariant())
            {
            case "forumsave":
            {
                var fi     = new Forum();
                var fc     = new ForumController();
                var bIsNew = false;
                int forumGroupId;
                var forumSettingsKey = string.Empty;

                if (Utilities.SafeConvertInt(e.Parameters[1]) <= 0)
                {
                    bIsNew     = true;
                    fi.ForumID = -1;
                }
                else
                {
                    fi = fc.Forums_Get(PortalId, ModuleId, Utilities.SafeConvertInt(e.Parameters[1]), UserId, false, false, -1);
                    forumSettingsKey = fi.ForumSettingsKey;
                }

                fi.ModuleId = ModuleId;
                fi.PortalId = PortalId;
                var sParentValue  = e.Parameters[2];
                var parentForumId = 0;

                if (sParentValue.Contains("GROUP"))
                {
                    sParentValue = sParentValue.Replace("GROUP", string.Empty);
                    forumGroupId = Utilities.SafeConvertInt(sParentValue);
                }
                else
                {
                    parentForumId = Utilities.SafeConvertInt(sParentValue.Replace("FORUM", string.Empty));
                    forumGroupId  = fc.Forums_GetGroupId(parentForumId);
                }

                fi.ForumGroupId  = forumGroupId;
                fi.ParentForumId = parentForumId;
                fi.ForumName     = e.Parameters[3];
                fi.ForumDesc     = e.Parameters[4];
                fi.Active        = Utilities.SafeConvertBool(e.Parameters[5]);
                fi.Hidden        = Utilities.SafeConvertBool(e.Parameters[6]);

                fi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]);

                var fkey = string.IsNullOrEmpty(fi.ForumSettingsKey) ? string.Empty : fi.ForumSettingsKey;

                if (Utilities.SafeConvertBool(e.Parameters[8]))
                {
                    var fgc = new ForumGroupController();
                    var fgi = fgc.GetForumGroup(ModuleId, forumGroupId);

                    if (bIsNew)
                    {
                        fi.PermissionsId = fgi.PermissionsId;
                    }
                    else if (fi.ForumSettingsKey != "G:" + forumGroupId)
                    {
                        fi.PermissionsId = fgi.PermissionsId;
                    }

                    fi.ForumSettingsKey = "G:" + forumGroupId;
                }
                else if (bIsNew || fkey.Contains("G:"))
                {
                    fi.ForumSettingsKey = string.Empty;
                    if (fi.InheritSecurity)
                    {
                        fi.PermissionsId = -1;
                    }
                }
                else
                {
                    fi.ForumSettingsKey = "F:" + fi.ForumID;
                }

                if (forumSettingsKey != fkey && fkey.Contains("F:"))
                {
                    bIsNew = true;
                }

                fi.PrefixURL = e.Parameters[9];
                if (!(string.IsNullOrEmpty(fi.PrefixURL)))
                {
                    var db = new Data.Common();
                    if (!(db.CheckForumURL(PortalId, ModuleId, fi.PrefixURL, fi.ForumID, fi.ForumGroupId)))
                    {
                        fi.PrefixURL = string.Empty;
                    }
                }

                var forumId = fc.Forums_Save(PortalId, fi, bIsNew, Utilities.SafeConvertBool(e.Parameters[8]));
                recordId = forumId;
                var securityKey = string.Empty;

                DataCache.ClearForumGroupsCache(ModuleId);

                var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId);
                DataCache.CacheClear(cachekey);

                cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                DataCache.CacheClearPrefix(cachekey);

                hidEditorResult.Value = forumId.ToString();
                break;
            }

            case "groupsave":
            {
                var bIsNew  = false;
                var groupId = Utilities.SafeConvertInt(e.Parameters[1]);
                var fgc     = new ForumGroupController();
                var gi      = (groupId > 0) ? fgc.Groups_Get(ModuleId, groupId) : new ForumGroupInfo();

                var securityKey = string.Empty;
                if (groupId == 0)
                {
                    bIsNew = true;
                }
                else
                {
                    securityKey = "G:" + groupId;
                }

                gi.ModuleId     = ModuleId;
                gi.ForumGroupId = groupId;
                gi.GroupName    = e.Parameters[3];
                gi.Active       = Utilities.SafeConvertBool(e.Parameters[5]);
                gi.Hidden       = Utilities.SafeConvertBool(e.Parameters[6]);

                gi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]);

                gi.PrefixURL = e.Parameters[9];
                if (!(string.IsNullOrEmpty(gi.PrefixURL)))
                {
                    var db = new Data.Common();
                    if (!(db.CheckGroupURL(PortalId, ModuleId, gi.PrefixURL, gi.ForumGroupId)))
                    {
                        gi.PrefixURL = string.Empty;
                    }
                }

                gi.GroupSettingsKey = securityKey;
                var gc = new ForumGroupController();
                groupId  = gc.Groups_Save(PortalId, gi, bIsNew);
                recordId = groupId;

                DataCache.ClearForumGroupsCache(ModuleId);
                var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                DataCache.CacheClearPrefix(cachekey);
                hidEditorResult.Value = groupId.ToString();

                break;
            }

            case "forumsettingssave":
            {
                var forumId = Utilities.SafeConvertInt(e.Parameters[1]);
                var sKey    = "F:" + forumId;
                SaveSettings(sKey, e.Parameters);

                hidEditorResult.Value = forumId.ToString();
                DataCache.CacheClear(forumId.ToString() + "ForumSettings");
                DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId));
                DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId) + "st");
                var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId);
                DataCache.CacheClear(cachekey);
                break;
            }

            case "groupsettingssave":
            {
                var forumId = Utilities.SafeConvertInt(e.Parameters[1]);
                var sKey    = "G:" + forumId;
                SaveSettings(sKey, e.Parameters);

                hidEditorResult.Value = forumId.ToString();
                DataCache.CacheClear(forumId.ToString() + "GroupSettings");
                DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId));
                DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId) + "st");

                break;
            }

            case "deleteforum":
            {
                var forumId = Utilities.SafeConvertInt(e.Parameters[1]);
                DataProvider.Instance().Forums_Delete(PortalId, ModuleId, forumId);
                var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                DataCache.CacheClearPrefix(cachekey);
                break;
            }

            case "deletegroup":
            {
                var groupId = Utilities.SafeConvertInt(e.Parameters[1]);
                DataProvider.Instance().Groups_Delete(ModuleId, groupId);
                var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                DataCache.CacheClearPrefix(cachekey);
                break;
            }
            }

            DataCache.CacheClear(string.Format(CacheKeys.ForumList, ModuleId));
            DataCache.ClearAllForumSettingsCache(ModuleId);
            DataCache.CacheClear(ModuleId + "fv");

            hidEditorResult.RenderControl(e.Output);
        }
Ejemplo n.º 10
0
		public static string GetRoleIds(string[] Roles, int SiteId)
		{
			int i = 0;
			string RoleIds = "";
			var db = new Data.Common();
			object obj = null; // DataCache.CacheRetrieve(SiteId & "afroles")
			if (obj == null)
			{
				var rc = new Security.Roles.RoleController();
				foreach (Security.Roles.RoleInfo ri in rc.GetPortalRoles(SiteId))
				{
					string roleName = ri.RoleName;
					foreach (string role in Roles)
					{
						if (!string.IsNullOrEmpty(role))
						{
							if (roleName == role)
							{
								RoleIds += ri.RoleID.ToString() + ";";
								break;
							}
						}
					}
				}
				// DataCache.CacheStore(SiteId & "afroles", RoleIds)
			}
		    return RoleIds;
		}
Ejemplo n.º 11
0
        public static string ParseEmailTemplate(string template, string templateName, int portalID, int moduleID, int tabID, int forumID, int topicId, int replyId, string comments, Entities.Users.UserInfo user, int userId, int timeZoneOffset)
        {
            var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]);
            var ms             = DataCache.MainSettings(moduleID);
            var sOut           = template;

            // If we have a template name, load the template into sOut
            if (templateName != string.Empty)
            {
                if (templateName.Contains("_Subject_"))
                {
                    templateName = templateName.Replace("_Subject_" + moduleID, string.Empty);
                    var objTemplate = GetTemplateByName(templateName, moduleID, portalID);
                    sOut = objTemplate.Subject;
                }
                else
                {
                    var objTemplate = GetTemplateByName(templateName, moduleID, portalID);
                    sOut = objTemplate.TemplateHTML;
                }
            }

            // Load Subject and body from topic or reply

            var subject     = string.Empty;
            var body        = string.Empty;
            var dateCreated = Utilities.NullDate();
            var authorName  = string.Empty;

            if (topicId > 0 && replyId > 0)
            {
                var ri = new ReplyController().Reply_Get(portalID, moduleID, topicId, replyId);
                if (ri != null)
                {
                    subject     = ri.Content.Subject;
                    body        = ri.Content.Body;
                    dateCreated = ri.Content.DateCreated;
                    authorName  = ri.Content.AuthorName;
                }
            }
            else
            {
                var ti = new TopicsController().Topics_Get(portalID, moduleID, topicId);
                if (ti != null)
                {
                    subject     = ti.Content.Subject;
                    body        = ti.Content.Body;
                    dateCreated = ti.Content.DateCreated;
                    authorName  = ti.Content.AuthorName;
                }
            }

            body = Utilities.ManageImagePath(body, Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request)));

            // load the forum information
            var fi = new ForumController().Forums_Get(forumID, -1, false);

            // Load the user if needed
            if (user == null)
            {
                var objUsers = new Entities.Users.UserController();
                var objUser  = objUsers.GetUser(portalID, userId);
                user = objUser;
            }

            // Load the user properties

            string sFirstName;
            string sLastName;
            string sDisplayName;
            string sUsername;

            if (user != null)
            {
                sFirstName   = user.FirstName;
                sLastName    = user.LastName;
                sDisplayName = user.DisplayName;
                sUsername    = user.Username;
            }
            else
            {
                sFirstName   = string.Empty;
                sLastName    = string.Empty;
                sDisplayName = string.Empty;
                sUsername    = string.Empty;
            }

            // Build the link

            string link;

            if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.IsRewriteLoaded())
            {
                if (replyId == 0)
                {
                    link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId })
                        : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId });
                }
                else
                {
                    link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId })
                        : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId });
                }
            }
            else
            {
                var contentId = (replyId > 0) ? replyId : -1;
                link = new Data.Common().GetUrl(moduleID, -1, forumID, topicId, -1, contentId);
            }

            if (!(link.StartsWith("http")))
            {
                if (!link.StartsWith("/"))
                {
                    link = "/" + link;
                }

                if (link.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1)
                {
                    link = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + link;
                }
            }


            // Build the forum Url
            var forumURL = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID })
                : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topics });

            // Build Moderation url
            var modLink = Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ViewType + "=modtopics", ParamKeys.ForumId + "=" + forumID });

            if (modLink.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1)
            {
                modLink = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + modLink;
            }

            var result = new StringBuilder(sOut);

            result.Replace("[DISPLAYNAME]", UserProfiles.GetDisplayName(moduleID, userId, authorName, sFirstName, sLastName, sDisplayName));
            result.Replace("[USERNAME]", sUsername);
            result.Replace("[USERID]", userId.ToString());
            result.Replace("[FORUMNAME]", fi.ForumName);
            result.Replace("[PORTALID]", portalID.ToString());
            result.Replace("[FIRSTNAME]", sFirstName);
            result.Replace("[LASTNAME]", sLastName);
            result.Replace("[FULLNAME]", sFirstName + " " + sLastName);
            result.Replace("[GROUPNAME]", fi.GroupName);
            result.Replace("[POSTDATE]", Utilities.GetDate(dateCreated, moduleID, timeZoneOffset));
            result.Replace("[COMMENTS]", comments);
            result.Replace("[PORTALNAME]", portalSettings.PortalName);
            result.Replace("[MODLINK]", "<a href=\"" + modLink + "\">" + modLink + "</a>");
            result.Replace("[LINK]", "<a href=\"" + link + "\">" + link + "</a>");
            result.Replace("[HYPERLINK]", "<a href=\"" + link + "\">" + link + "</a>");
            result.Replace("[LINKURL]", link);
            result.Replace("[FORUMURL]", forumURL);
            result.Replace("[FORUMLINK]", "<a href=\"" + forumURL + "\">" + forumURL + "</a>");


            if (user != null)
            {
                result.Replace("[SENDERUSERNAME]", user.UserID.ToString());
                result.Replace("[SENDERFIRSTNAME]", user.FirstName);
                result.Replace("[SENDERLASTNAME]", user.LastName);
                result.Replace("[SENDERDISPLAYNAME]", user.DisplayName);
            }
            else
            {
                result.Replace("[SENDERUSERNAME]", string.Empty);
                result.Replace("[SENDERFIRSTNAME]", string.Empty);
                result.Replace("[SENDERLASTNAME]", string.Empty);
                result.Replace("[SENDERDISPLAYNAME]", string.Empty);
            }

            result.Replace("[SUBJECT]", subject);
            result.Replace("[BODY]", body);
            result.Replace("[Body]", body);

            return(result.ToString());
        }
Ejemplo n.º 12
0
        protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

            jQuery.RequestRegistration();
            jQuery.RequestUIRegistration();

            IsCallBack = cbShell.IsCallback;

            btnReturn.ClientSideScript = "window.location.href = '" + Common.Globals.NavigateURL(TabId) + "';";
            var objModules = new Entities.Modules.ModuleController();
            cbModal.LoadingTemplate = GetLoadingTemplateSmall();
            Hashtable Settings = objModules.GetModuleSettings(ModuleId);
            string upFilePath = Server.MapPath("~/desktopmodules/activeforums/upgrade4x.txt");
            if (Convert.ToBoolean(Settings["AFINSTALLED"]) == false)
            {
                try
                {
                    var fc = new ForumsConfig();
                    bool configComplete = fc.ForumsInit(PortalId, ModuleId);
                    objModules.UpdateModuleSetting(ModuleId, "AFINSTALLED", configComplete.ToString());
                    if (System.IO.File.Exists(upFilePath))
                    {
                        System.IO.File.Delete(upFilePath);
                    }
                }
                catch (Exception ex)
                {
                    Services.Exceptions.Exceptions.LogException(ex);
                }
            }
            bool loadDefault = true;
            if (System.IO.File.Exists(upFilePath))
            {
                var db = new Data.Common();
                if (db.SecurityUpgraded())
                {
                    if (System.IO.File.Exists(upFilePath))
                    {
                        System.IO.File.Delete(upFilePath);
                    }
                }
                else
                {
                    loadDefault = false;
                    GetControl("upgrade", string.Empty, IsCallBack);
                }
            }

            ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/ActiveForums/ControlPanel.css");
            ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme + "/jquery-ui.min.css");


            lblProd.Visible = true;
            lblCopy.Visible = true;
            //TODO: this should be resources instead of harcoded text?
            lblProd.Text = "Active Forums " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            lblCopy.Text = "©" + DateTime.Now.Year + " DotNetNuke Corporation";

            try
            {
                if (!Page.IsPostBack)
                {
                    GetControl(CurrentView, Params, IsCallBack);
                }

            }
            catch (Exception ex)
            {

                if (Request.QueryString["cptry"] == null)
                {
                    string sURL = EditUrl("", "", "EDIT", "cptry=1");
                    Response.Redirect(sURL);
                }
                else
                {
                    Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
                }
            }


            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/json2009.min.js", 101);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/jquery.history.js", 102);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/afadmin.js", 103);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/jquery.listreorder.js", 104);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/active/amlib.js", 105);






            string lang = "en-US";
            if (Request.QueryString["language"] != null)
            {
                lang = Request.QueryString["language"];
            }
            if (string.IsNullOrEmpty(lang))
            {
                lang = PortalSettings.DefaultLanguage;
            }
            if (string.IsNullOrEmpty(lang))
            {
                lang = "en-US";
            }
            string adminHandler = VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/handlers/adminhelper.ashx") + "?TabId=" + TabId.ToString() + "&PortalId=" + PortalId.ToString() + "&moduleid=" + ModuleId + "&language=" + lang;
            var sb = new StringBuilder();
            sb.AppendLine("var asScriptPath = '" + VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/scripts/") + "';");
            sb.AppendFormat("var afAdminHandlerURL = '{0}';", adminHandler);
            sb.AppendLine("var af_imgPath = '" + VirtualPathUtility.ToAbsolute("~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme) + "';");
            string sLoadImg;
            sLoadImg = "var afSpinLg = new Image();afSpinLg.src='" + VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/images/spinner-lg.gif") + "';";
            sLoadImg += "var afSpin = new Image();afSpin.src='" + VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/images/spinner.gif") + "';";
            sb.AppendLine(sLoadImg);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "afscripts", sb.ToString(), true);

            ServicesFramework.Instance.RequestAjaxAntiForgerySupport();

        }
Ejemplo n.º 13
0
        public int CreateGroupForum(int portalId, int moduleId, int socialGroupId, int forumGroupId, string forumName, string forumDescription, bool isPrivate, string forumConfig)
        {
            var forumId = -1;

            try
            {
                var rc          = new RoleController();
                var forumsDb    = new Data.Common();
                var fgc         = new ForumGroupController();
                var gi          = fgc.Groups_Get(moduleId, forumGroupId);
                var socialGroup = rc.GetRole(socialGroupId, portalId);
                var groupAdmin  = socialGroupId.ToString() + ":0";
                var groupMember = socialGroupId.ToString();

                var ri            = rc.GetRoleByName(portalId, "Administrators");
                var permissionsId = forumsDb.CreatePermSet(ri.RoleID.ToString());

                moduleId = gi.ModuleId;

                var fi = new Forum
                {
                    ForumDesc     = forumDescription,
                    Active        = true,
                    ForumGroupId  = forumGroupId,
                    ForumID       = -1,
                    ForumName     = forumName,
                    Hidden        = isPrivate,
                    ModuleId      = gi.ModuleId,
                    ParentForumId = 0,
                    PortalId      = portalId,
                    PermissionsId = gi.PermissionsId,
                    SortOrder     = 0,
                    SocialGroupId = socialGroupId
                };

                forumId          = Forums_Save(portalId, fi, true, true);
                fi               = GetForum(portalId, moduleId, forumId);
                fi.PermissionsId = permissionsId;
                Forums_Save(portalId, fi, false, false);

                var xDoc = new XmlDocument();
                xDoc.LoadXml(forumConfig);

                var xRoot = xDoc.DocumentElement;
                if (xRoot != null)
                {
                    var    xSecList = xRoot.SelectSingleNode("//security[@type='groupadmin']");
                    string permSet;
                    string secKey;
                    if (xSecList != null)
                    {
                        foreach (XmlNode n in xSecList.ChildNodes)
                        {
                            secKey = n.Name;
                            if (n.Attributes == null || n.Attributes["value"].Value != "true")
                            {
                                continue;
                            }
                            permSet = forumsDb.GetPermSet(permissionsId, secKey);
                            permSet = Permissions.AddPermToSet(groupAdmin, 2, permSet);
                            forumsDb.SavePermSet(permissionsId, secKey, permSet);
                        }
                    }

                    xSecList = xRoot.SelectSingleNode("//security[@type='groupmember']");
                    if (xSecList != null)
                    {
                        foreach (XmlNode n in xSecList.ChildNodes)
                        {
                            secKey = n.Name;

                            if (n.Attributes == null || n.Attributes["value"].Value != "true")
                            {
                                continue;
                            }

                            permSet = forumsDb.GetPermSet(permissionsId, secKey);
                            permSet = Permissions.AddPermToSet(groupMember, 0, permSet);
                            forumsDb.SavePermSet(permissionsId, secKey, permSet);
                        }
                    }

                    if (socialGroup.IsPublic)
                    {
                        xSecList = xRoot.SelectSingleNode("//security[@type='registereduser']");
                        ri       = rc.GetRoleByName(portalId, "Registered Users");
                        if (xSecList != null)
                        {
                            foreach (XmlNode n in xSecList.ChildNodes)
                            {
                                secKey = n.Name;

                                if (n.Attributes == null || n.Attributes["value"].Value != "true")
                                {
                                    continue;
                                }

                                permSet = forumsDb.GetPermSet(permissionsId, secKey);
                                permSet = Permissions.AddPermToSet(ri.RoleID.ToString(), 0, permSet);
                                forumsDb.SavePermSet(permissionsId, secKey, permSet);
                            }
                        }

                        xSecList = xRoot.SelectSingleNode("//security[@type='anon']");
                        if (xSecList != null)
                        {
                            foreach (XmlNode n in xSecList.ChildNodes)
                            {
                                secKey = n.Name;

                                if (n.Attributes == null || n.Attributes["value"].Value != "true")
                                {
                                    continue;
                                }

                                permSet = forumsDb.GetPermSet(permissionsId, secKey);
                                permSet = Permissions.AddPermToSet("-1", 0, permSet);
                                forumsDb.SavePermSet(permissionsId, secKey, permSet);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }

            DataCache.CacheClear(moduleId + "fv");

            return(forumId);
        }
Ejemplo n.º 14
0
        public int Forums_Save(int portalId, Forum fi, bool isNew, bool useGroup)
        {
            var rc            = new RoleController();
            var db            = new Data.Common();
            var permissionsId = -1;

            if (useGroup && (string.IsNullOrEmpty(fi.ForumSettingsKey) || fi.PermissionsId == -1))
            {
                var fc = new ForumGroupController();
                var fg = fc.Groups_Get(fi.ModuleId, fi.ForumGroupId);
                if (fg != null)
                {
                    fi.ForumSettingsKey = fg.GroupSettingsKey;
                    //fi.ModuleId = fg.ModuleId
                    fi.PermissionsId = fg.PermissionsId;
                }
            }
            else if (fi.PermissionsId <= 0 && useGroup == false)
            {
                var ri = rc.GetRoleByName(portalId, "Administrators");
                if (ri != null)
                {
                    fi.PermissionsId = db.CreatePermSet(ri.RoleID.ToString());
                    permissionsId    = fi.PermissionsId;
                    isNew            = true;
                }
                if (fi.ForumID > 0 & !(string.IsNullOrEmpty(fi.ForumSettingsKey)))
                {
                    if (fi.ForumSettingsKey.Contains("G:"))
                    {
                        fi.ForumSettingsKey = string.Empty;
                    }
                }
                if (fi.ForumSettingsKey == "" && fi.ForumID > 0)
                {
                    fi.ForumSettingsKey = "F:" + fi.ForumID;
                }
            }
            else if (useGroup == false && string.IsNullOrEmpty(fi.ForumSettingsKey) && fi.ForumID > 0)
            {
                fi.ForumSettingsKey = "F:" + fi.ForumID;
            }

            var forumId = Convert.ToInt32(DataProvider.Instance().Forum_Save(portalId, fi.ForumID, fi.ModuleId, fi.ForumGroupId, fi.ParentForumId, fi.ForumName, fi.ForumDesc, fi.SortOrder, fi.Active, fi.Hidden, fi.ForumSettingsKey, fi.PermissionsId, fi.PrefixURL, fi.SocialGroupId, fi.HasProperties));

            if (String.IsNullOrEmpty(fi.ForumSettingsKey))
            {
                fi.ForumSettingsKey = "F:" + forumId;
            }

            if (fi.ForumSettingsKey.Contains("G:"))
            {
                DataProvider.Instance().Forum_ConfigCleanUp(fi.ModuleId, "F:" + fi.ForumID, "F:" + fi.ForumID);
            }

            if (isNew && useGroup == false)
            {
                var moduleId = fi.ModuleId;
                Permissions.CreateDefaultSets(portalId, permissionsId);

                var sKey = "F:" + forumId.ToString();
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicsTemplateId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicTemplateId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicFormId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.ReplyFormId, "0");
                Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.AllowRSS, "false");
            }

            // Clear the caches
            DataCache.CacheClear(string.Format(CacheKeys.ForumList, fi.ModuleId));

            var cachekey = string.Format(forumInfoCacheKey, portalId, fi.ModuleId, forumId);

            DataCache.CacheClear(cachekey);

            return(forumId);
        }
Ejemplo n.º 15
0
		public void OnBeginRequest(object s, EventArgs e)
		{
			_forumId = -1;
			_tabId = -1;
			_moduleId = -1;
			_topicId = -1;
			_page = 1;
			_contentId = -1;
			_archived = 0;
			_forumgroupId = -1;
			_mainSettings = null;
			_categoryId = -1;
			_tagId = -1;

			HttpApplication app = (HttpApplication)s;
			HttpServerUtility Server = app.Server;
			HttpRequest Request = app.Request;
			HttpResponse Response = app.Response;
			string requestedPath = app.Request.Url.AbsoluteUri;
			HttpContext Context = ((HttpApplication)s).Context;
			int PortalId = -1;
			DotNetNuke.Entities.Portals.PortalAliasInfo objPortalAliasInfo = null;
			string sUrl = HttpContext.Current.Request.RawUrl.Replace("http://", string.Empty).Replace("https://", string.Empty);
			objPortalAliasInfo = DotNetNuke.Entities.Portals.PortalSettings.GetPortalAliasInfo(HttpContext.Current.Request.Url.Host);
			if (Request.RawUrl.ToLowerInvariant().Contains("404.aspx"))
			{
				string sEx = ".jpg,.gif,.png,.swf,.js,.css,.html,.htm,desktopmodules,portals,.ashx,.ico,.txt,.doc,.docx,.pdf,.xml,.xls,.xlsx,.ppt,.pptx,.csv,.zip,.asmx,.aspx";
				foreach (string sn in sEx.Split(','))
				{
					if (sUrl.Contains(sn))
					{
						// IO.File.AppendAllText(sPath, Request.RawUrl & "165<br />")
						return;
					}
				}
			}
			if (Request.Url.LocalPath.ToLower().Contains("scriptresource.axd") || Request.Url.LocalPath.ToLower().Contains("webresource.axd") || Request.Url.LocalPath.ToLower().Contains("viewer.aspx") || Request.Url.LocalPath.ToLower().Contains("cb.aspx") || Request.Url.LocalPath.ToLower().Contains("filesupload.aspx") || Request.Url.LocalPath.ToLower().Contains(".gif") || Request.Url.LocalPath.ToLower().Contains(".jpg") || Request.Url.LocalPath.ToLower().Contains(".css") || Request.Url.LocalPath.ToLower().Contains(".png") || Request.Url.LocalPath.ToLower().Contains(".swf") || Request.Url.LocalPath.ToLower().Contains(".htm") || Request.Url.LocalPath.ToLower().Contains(".html") || Request.Url.LocalPath.ToLower().Contains(".ashx") || Request.Url.LocalPath.ToLower().Contains(".cur") || Request.Url.LocalPath.ToLower().Contains(".ico") || Request.Url.LocalPath.ToLower().Contains(".txt") || Request.Url.LocalPath.ToLower().Contains(".pdf") || Request.Url.LocalPath.ToLower().Contains(".xml") || Request.Url.LocalPath.ToLower().Contains("/portals/") || Request.Url.LocalPath.ToLower().Contains("/desktopmodules/") || Request.Url.LocalPath.ToLower().Contains("evexport.aspx") || Request.Url.LocalPath.ToLower().Contains("signupjs.aspx") || Request.Url.LocalPath.ToLower().Contains("evsexport.aspx") || Request.Url.LocalPath.ToLower().Contains("fbcomm.aspx") || Request.Url.LocalPath.ToLower().Contains(".aspx") || Request.Url.LocalPath.ToLower().Contains(".js"))
			{
				return;
			}
			if (Request.Url.LocalPath.ToLower().Contains("install.aspx") || Request.Url.LocalPath.ToLower().Contains("installwizard.aspx") || Request.Url.LocalPath.ToLower().Contains("captcha.aspx") || Request.RawUrl.Contains("viewer.aspx") || Request.RawUrl.Contains("blank.html") || Request.RawUrl.Contains("default.htm") || Request.RawUrl.Contains("autosuggest.aspx"))
			{
				return;
			}
			PortalId = objPortalAliasInfo.PortalID;
			string searchURL = sUrl;
			searchURL = searchURL.Replace(objPortalAliasInfo.HTTPAlias, string.Empty);
			if (searchURL.Length < 2)
			{
				return;
			}
			string query = string.Empty;
			if (searchURL.Contains("?"))
			{
				query = searchURL.Substring(searchURL.IndexOf("?"));
				searchURL = searchURL.Substring(0, searchURL.IndexOf("?") - 1);
			}
			string newSearchURL = string.Empty;
			foreach (string up in searchURL.Split('/'))
			{
				if (! (string.IsNullOrEmpty(up)))
				{
					if (! (SimulateIsNumeric.IsNumeric(up)))
					{
						newSearchURL += up + "/";
					}
				}
			}
			bool canContinue = false;
			Data.Common db = new Data.Common();
			string tagName = string.Empty;
			string catName = string.Empty;
			if (newSearchURL.Contains("/category/") || newSearchURL.Contains("/tag/"))
			{
				if (newSearchURL.Contains("/category/"))
				{
					string cat = "/category/";
					int iEnd = newSearchURL.IndexOf("/", newSearchURL.IndexOf(cat) + cat.Length + 1);
					string catString = newSearchURL.Substring(newSearchURL.IndexOf(cat), iEnd - newSearchURL.IndexOf(cat));
					catName = catString.Replace(cat, string.Empty);
					catName = catName.Replace("/", string.Empty);
					newSearchURL = newSearchURL.Replace(catString, string.Empty);
				}
				if (newSearchURL.Contains("/tag/"))
				{
					string tag = "/tag/";
					int iEnd = newSearchURL.IndexOf("/", newSearchURL.IndexOf(tag) + tag.Length + 1);
					string tagString = newSearchURL.Substring(newSearchURL.IndexOf(tag), iEnd - newSearchURL.IndexOf(tag));
					tagName = tagString.Replace(tag, string.Empty);
					tagName = tagName.Replace("/", string.Empty);
					newSearchURL = newSearchURL.Replace(tagString, string.Empty);
				}
			}
			if ((sUrl.Contains("afv") && sUrl.Contains("post")) | (sUrl.Contains("afv") && sUrl.Contains("confirmaction")) | (sUrl.Contains("afv") && sUrl.Contains("sendto")) | (sUrl.Contains("afv") && sUrl.Contains("modreport")) | (sUrl.Contains("afv") && sUrl.Contains("search")) | sUrl.Contains("dnnprintmode") || sUrl.Contains("asg") || (sUrl.Contains("afv") && sUrl.Contains("modtopics")))
			{
				return;
			}
			try
			{
				using (IDataReader dr = db.URLSearch(PortalId, newSearchURL))
				{
					while (dr.Read())
					{
						_tabId = int.Parse(dr["TabID"].ToString());
						_moduleId = int.Parse(dr["ModuleId"].ToString());
						_forumgroupId = int.Parse(dr["ForumGroupId"].ToString());
						_forumId = int.Parse(dr["ForumId"].ToString());
						_topicId = int.Parse(dr["TopicId"].ToString());
						_archived = int.Parse(dr["Archived"].ToString());
						_otherId = int.Parse(dr["OtherId"].ToString());
						_urlType = int.Parse(dr["UrlType"].ToString());
						canContinue = true;
					}
					dr.Close();
				}
			}
			catch (Exception ex)
			{

			}
			if (! (string.IsNullOrEmpty(catName)))
			{
				_categoryId = db.Tag_GetIdByName(PortalId, _moduleId, catName, true);
				_otherId = _categoryId;
				_urlType = 2;
			}
			if (! (string.IsNullOrEmpty(tagName)))
			{
				_tagId = db.Tag_GetIdByName(PortalId, _moduleId, tagName, false);
				_otherId = _tagId;
				_urlType = 3;
			}

			if (_archived == 1)
			{
				sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
				if (! (string.IsNullOrEmpty(sUrl)))
				{
					string sHost = objPortalAliasInfo.HTTPAlias;
					if (sUrl.StartsWith("/"))
					{
						sUrl = sUrl.Substring(1);
					}
					if (! (sHost.EndsWith("/")))
					{
						sHost += "/";
					}
					sUrl = sHost + sUrl;
					if (! (sUrl.EndsWith("/")))
					{
						sUrl += "/";
					}
					if (! (sUrl.StartsWith("http")))
					{
						if (Request.IsSecureConnection)
						{
							sUrl = "https://" + sUrl;
						}
						else
						{
							sUrl = "http://" + sUrl;
						}
					}
					Response.Clear();
					Response.Status = "301 Moved Permanently";
					Response.AddHeader("Location", sUrl);
					Response.End();

				}
			}
			if (_moduleId > 0)
			{
				Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController();
				SettingsInfo objSettings = new SettingsInfo();
				objSettings.MainSettings = objModules.GetModuleSettings(_moduleId);
				_mainSettings = objSettings; // DataCache.MainSettings(_moduleId)
			}
			if (_mainSettings == null)
			{
				return;
			}
			if (! _mainSettings.URLRewriteEnabled)
			{
				return;
			}
			if (! canContinue && (Request.RawUrl.Contains(ParamKeys.TopicId) || Request.RawUrl.Contains(ParamKeys.ForumId) || Request.RawUrl.Contains(ParamKeys.GroupId)))
			{
				sUrl = HandleOldUrls(Request.RawUrl, objPortalAliasInfo.HTTPAlias);
				if (! (string.IsNullOrEmpty(sUrl)))
				{
					if (! (sUrl.StartsWith("http")))
					{
						if (Request.IsSecureConnection)
						{
							sUrl = "https://" + sUrl;
						}
						else
						{
							sUrl = "http://" + sUrl;
						}
					}
					Response.Clear();
					Response.Status = "301 Moved Permanently";
					Response.AddHeader("Location", sUrl);
					Response.End();
				}
			}
			if (! canContinue)
			{
				string topicUrl = string.Empty;
				if (newSearchURL.EndsWith("/"))
				{
					newSearchURL = newSearchURL.Substring(0, newSearchURL.Length - 1);
				}
				if (newSearchURL.Contains("/"))
				{
					topicUrl = newSearchURL.Substring(newSearchURL.LastIndexOf("/"));
				}
				topicUrl = topicUrl.Replace("/", string.Empty);
				if (! (string.IsNullOrEmpty(topicUrl)))
				{
					Data.Topics topicsDb = new Data.Topics();
					_topicId = topicsDb.TopicIdByUrl(PortalId, _moduleId, topicUrl.ToLowerInvariant());
					if (_topicId > 0)
					{
						sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
					}
					else
					{
						sUrl = string.Empty;
					}
					if (! (string.IsNullOrEmpty(sUrl)))
					{
						string sHost = objPortalAliasInfo.HTTPAlias;
						if (sHost.EndsWith("/") && sUrl.StartsWith("/"))
						{
							sUrl = sHost.Substring(0, sHost.Length - 1) + sUrl;
						}
						else if (! (sHost.EndsWith("/")) && ! (sUrl.StartsWith("/")))
						{
							sUrl = sHost + "/" + sUrl;
						}
						else
						{
							sUrl = sHost + sUrl;
						}
						if (sUrl.StartsWith("/"))
						{
							sUrl = sUrl.Substring(1);
						}
						if (! (sUrl.StartsWith("http")))
						{
							if (Request.IsSecureConnection)
							{
								sUrl = "https://" + sUrl;
							}
							else
							{
								sUrl = "http://" + sUrl;
							}
						}
						if (! (string.IsNullOrEmpty(sUrl)))
						{
							Response.Clear();
							Response.Status = "301 Moved Permanently";
							Response.AddHeader("Location", sUrl);
							Response.End();
						}
					}
				}

			}

			if (canContinue)
			{
				if (searchURL != newSearchURL)
				{
					string urlTail = searchURL.Replace(newSearchURL, string.Empty);
					if (urlTail.StartsWith("/"))
					{
						urlTail = urlTail.Substring(1);
					}
					if (urlTail.EndsWith("/"))
					{
						urlTail = urlTail.Substring(0, urlTail.Length - 1);
					}
					if (urlTail.Contains("/"))
					{
						urlTail = urlTail.Substring(0, urlTail.IndexOf("/") - 1);
					}
					if (SimulateIsNumeric.IsNumeric(urlTail))
					{
						_page = Convert.ToInt32(urlTail);
					}
				}

				string sPage = string.Empty;
				sPage = "&afpg=" + _page.ToString();
				string qs = string.Empty;
				if (sUrl.Contains("?"))
				{
					qs = "&" + sUrl.Substring(sUrl.IndexOf("?") + 1);
				}
				string catQS = string.Empty;
				if (_categoryId > 0)
				{
					catQS = "&act=" + _categoryId.ToString();
				}
				string sendTo = string.Empty;
				if (_topicId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&aft=" + _topicId + sPage + qs);
				}
				else if (_forumId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&aff=" + _forumId + sPage + qs + catQS);
				}
				else if (_forumgroupId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afg=" + _forumgroupId + sPage + qs + catQS);
				}
				else if (_urlType == 2 && _otherId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&act=" + _otherId + sPage + qs);
				}
				else if (_urlType == 3 && _otherId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=tags&aftg=" + _otherId + sPage + qs);
				}
				else if (_urlType == 1)
				{
					string v = string.Empty;
					switch (_otherId)
					{
						case 1:
							v = "unanswered";
							break;
						case 2:
							v = "notread";
							break;
						case 3:
							v = "mytopics";
							break;
						case 4:
							v = "activetopics";
							break;
					}
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=" + v + sPage + qs);
				}
				else if (_tabId > 0)
				{
					sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + sPage + qs);
				}

				RewriteUrl(app.Context, sendTo);
			}
		}
Ejemplo n.º 16
0
        public static string ParseEmailTemplate(string template, string templateName, int portalID, int moduleID, int tabID, int forumID, int topicId, int replyId, string comments, Entities.Users.UserInfo user, int userId, int timeZoneOffset)
        {
            var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]);
            var ms = DataCache.MainSettings(moduleID);
            var sOut = template;

            // If we have a template name, load the template into sOut
            if (templateName != string.Empty)
            {
                if (templateName.Contains("_Subject_"))
                {
                    templateName = templateName.Replace("_Subject_" + moduleID, string.Empty);
                    var objTemplate = GetTemplateByName(templateName, moduleID, portalID);
                    sOut = objTemplate.Subject;
                }
                else
                {
                    var objTemplate = GetTemplateByName(templateName, moduleID, portalID);
                    sOut = objTemplate.TemplateHTML;
                }
            }

               // Load Subject and body from topic or reply

            var subject = string.Empty;
            var body = string.Empty;
            var dateCreated = Utilities.NullDate();
            var authorName = string.Empty;

            if (topicId > 0 && replyId > 0)
            {
                var ri = new ReplyController().Reply_Get(portalID, moduleID, topicId, replyId);
                if (ri != null)
                {
                    subject = ri.Content.Subject;
                    body = ri.Content.Body;
                    dateCreated = ri.Content.DateCreated;
                    authorName = ri.Content.AuthorName;
                }
            }
            else
            {
                var ti = new TopicsController().Topics_Get(portalID, moduleID, topicId);
                if (ti != null)
                {
                    subject = ti.Content.Subject;
                    body = ti.Content.Body;
                    dateCreated = ti.Content.DateCreated;
                    authorName = ti.Content.AuthorName;
                }
            }

            body = Utilities.ManageImagePath(body, Common.Globals.AddHTTP(Common.Globals.GetDomainName(HttpContext.Current.Request)));

            // load the forum information
            var fi = new ForumController().Forums_Get(forumID, -1, false);

            // Load the user if needed
            if (user == null)
            {
                var objUsers = new Entities.Users.UserController();
                var objUser = objUsers.GetUser(portalID, userId);
                user = objUser;
            }

            // Load the user properties

            string sFirstName;
            string sLastName;
            string sDisplayName;
            string sUsername;

            if (user != null)
            {
                sFirstName = user.FirstName;
                sLastName = user.LastName;
                sDisplayName = user.DisplayName;
                sUsername = user.Username;
            }
            else
            {
                sFirstName = string.Empty;
                sLastName = string.Empty;
                sDisplayName = string.Empty;
                sUsername = string.Empty;
            }

            // Build the link

            string link;
            if (string.IsNullOrEmpty(fi.PrefixURL) || !Utilities.IsRewriteLoaded())
            {
                if (replyId == 0)
                    link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId })
                        : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId });
                else
                    link = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId })
                        : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + topicId, ParamKeys.ContentJumpId + "=" + replyId });
            }
            else
            {
                var contentId = (replyId > 0) ? replyId : -1;
                link = new Data.Common().GetUrl(moduleID, -1, forumID, topicId, -1, contentId);
            }

            if (!(link.StartsWith("http")))
            {
                if (!link.StartsWith("/"))
                    link = "/" + link;

                if (link.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1)
                    link = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + link;
            }

            // Build the forum Url
            var forumURL = ms.UseShortUrls ? Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID })
                : Common.Globals.NavigateURL(tabID, string.Empty, new[] { ParamKeys.ForumId + "=" + forumID, ParamKeys.ViewType + "=" + Views.Topics });

            // Build Moderation url
            var modLink = Common.Globals.NavigateURL(tabID, string.Empty, new[] {ParamKeys.ViewType + "=modtopics", ParamKeys.ForumId + "=" + forumID});
            if (modLink.IndexOf(HttpContext.Current.Request.Url.Host, StringComparison.Ordinal) == -1)
                modLink = Common.Globals.AddHTTP(HttpContext.Current.Request.Url.Host) + modLink;

            var result = new StringBuilder(sOut);

            result.Replace("[DISPLAYNAME]", UserProfiles.GetDisplayName(moduleID, userId, authorName, sFirstName, sLastName, sDisplayName));
            result.Replace("[USERNAME]", sUsername);
            result.Replace("[USERID]", userId.ToString());
            result.Replace("[FORUMNAME]", fi.ForumName);
            result.Replace("[PORTALID]", portalID.ToString());
            result.Replace("[FIRSTNAME]", sFirstName);
            result.Replace("[LASTNAME]", sLastName);
            result.Replace("[FULLNAME]", sFirstName + " " + sLastName);
            result.Replace("[GROUPNAME]", fi.GroupName);
            result.Replace("[POSTDATE]", Utilities.GetDate(dateCreated, moduleID, timeZoneOffset));
            result.Replace("[COMMENTS]", comments);
            result.Replace("[PORTALNAME]", portalSettings.PortalName);
            result.Replace("[MODLINK]", "<a href=\"" + modLink + "\">" + modLink + "</a>");
            result.Replace("[LINK]", "<a href=\"" + link + "\">" + link + "</a>");
            result.Replace("[HYPERLINK]", "<a href=\"" + link + "\">" + link + "</a>");
            result.Replace("[LINKURL]", link);
            result.Replace("[FORUMURL]", forumURL);
            result.Replace("[FORUMLINK]", "<a href=\"" + forumURL + "\">" + forumURL + "</a>");

             // Introduced for Active Forum Email Connector plug-in Starts
            if (result.ToString().Contains("[EMAILCONNECTORITEMID]"))
            {
                // This Try with empty catch is introduced here because this code section is for Email Connector functionality only and this section should not
                // cause any issue to Active Forums functionality in case it does not run successfully.
                try
                {
                    long itemID = GetEmailInfo(portalID, moduleID, forumID, topicId, HttpContext.Current.Request.UserHostAddress);
                    result.Replace("[EMAILCONNECTORITEMID]", itemID.ToString());
                }
                catch
                { }
            }
            // Introduced for Active Forum Email Connector plug-in Ends

            if (user != null)
            {
                result.Replace("[SENDERUSERNAME]", user.UserID.ToString());
                result.Replace("[SENDERFIRSTNAME]", user.FirstName);
                result.Replace("[SENDERLASTNAME]", user.LastName);
                result.Replace("[SENDERDISPLAYNAME]", user.DisplayName);
            }
            else
            {
                result.Replace("[SENDERUSERNAME]", string.Empty);
                result.Replace("[SENDERFIRSTNAME]", string.Empty);
                result.Replace("[SENDERLASTNAME]", string.Empty);
                result.Replace("[SENDERDISPLAYNAME]", string.Empty);
            }

            result.Replace("[SUBJECT]", subject);
            result.Replace("[BODY]", body);
            result.Replace("[Body]", body);

            return result.ToString();
        }
Ejemplo n.º 17
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            jQuery.RequestRegistration();
            jQuery.RequestUIRegistration();

            IsCallBack = cbShell.IsCallback;

            btnReturn.ClientSideScript = "window.location.href = '" + Common.Globals.NavigateURL(TabId) + "';";
            var objModules = new Entities.Modules.ModuleController();

            cbModal.LoadingTemplate = GetLoadingTemplateSmall();
            Hashtable Settings   = objModules.GetModuleSettings(ModuleId);
            string    upFilePath = Server.MapPath("~/desktopmodules/activeforums/upgrade4x.txt");

            if (Convert.ToBoolean(Settings["AFINSTALLED"]) == false)
            {
                try
                {
                    var  fc             = new ForumsConfig();
                    bool configComplete = fc.ForumsInit(PortalId, ModuleId);
                    objModules.UpdateModuleSetting(ModuleId, "AFINSTALLED", configComplete.ToString());
                    if (System.IO.File.Exists(upFilePath))
                    {
                        System.IO.File.Delete(upFilePath);
                    }
                }
                catch (Exception ex)
                {
                    Services.Exceptions.Exceptions.LogException(ex);
                }
            }
            bool loadDefault = true;

            if (System.IO.File.Exists(upFilePath))
            {
                var db = new Data.Common();
                if (db.SecurityUpgraded())
                {
                    if (System.IO.File.Exists(upFilePath))
                    {
                        System.IO.File.Delete(upFilePath);
                    }
                }
                else
                {
                    loadDefault = false;
                    GetControl("upgrade", string.Empty, IsCallBack);
                }
            }

            ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/ActiveForums/ControlPanel.css");
            ClientResourceManager.RegisterStyleSheet(Page, "~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme + "/jquery-ui.min.css");


            lblProd.Visible = true;
            lblCopy.Visible = true;
            //TODO: this should be resources instead of harcoded text?
            lblProd.Text = "Active Forums " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            lblCopy.Text = "©" + DateTime.Now.Year + " DotNetNuke Corporation";

            try
            {
                if (!Page.IsPostBack)
                {
                    GetControl(CurrentView, Params, IsCallBack);
                }
            }
            catch (Exception ex)
            {
                if (Request.QueryString["cptry"] == null)
                {
                    string sURL = EditUrl("", "", "EDIT", "cptry=1");
                    Response.Redirect(sURL);
                }
                else
                {
                    Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
                }
            }


            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/json2009.min.js", 101);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/jquery.history.js", 102);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/afadmin.js", 103);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/scripts/jquery.listreorder.js", 104);
            ClientResourceManager.RegisterScript(Page, "~/desktopmodules/activeforums/active/amlib.js", 105);



            string lang = "en-US";

            if (Request.QueryString["language"] != null)
            {
                lang = Request.QueryString["language"];
            }
            if (string.IsNullOrEmpty(lang))
            {
                lang = PortalSettings.DefaultLanguage;
            }
            if (string.IsNullOrEmpty(lang))
            {
                lang = "en-US";
            }
            string adminHandler = VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/handlers/adminhelper.ashx") + "?TabId=" + TabId.ToString() + "&PortalId=" + PortalId.ToString() + "&moduleid=" + ModuleId + "&language=" + lang;
            var    sb           = new StringBuilder();

            sb.AppendLine("var asScriptPath = '" + VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/scripts/") + "';");
            sb.AppendFormat("var afAdminHandlerURL = '{0}';", adminHandler);
            sb.AppendLine("var af_imgPath = '" + VirtualPathUtility.ToAbsolute("~/DesktopModules/ActiveForums/themes/" + MainSettings.Theme) + "';");
            string sLoadImg;

            sLoadImg  = "var afSpinLg = new Image();afSpinLg.src='" + VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/images/spinner-lg.gif") + "';";
            sLoadImg += "var afSpin = new Image();afSpin.src='" + VirtualPathUtility.ToAbsolute("~/desktopmodules/activeforums/images/spinner.gif") + "';";
            sb.AppendLine(sLoadImg);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "afscripts", sb.ToString(), true);

            ServicesFramework.Instance.RequestAjaxAntiForgerySupport();
        }
Ejemplo n.º 18
0
        public void OnBeginRequest(object s, EventArgs e)
        {
            _forumId      = -1;
            _tabId        = -1;
            _moduleId     = -1;
            _topicId      = -1;
            _page         = 1;
            _contentId    = -1;
            _archived     = 0;
            _forumgroupId = -1;
            _mainSettings = null;
            _categoryId   = -1;
            _tagId        = -1;

            HttpApplication   app           = (HttpApplication)s;
            HttpServerUtility Server        = app.Server;
            HttpRequest       Request       = app.Request;
            HttpResponse      Response      = app.Response;
            string            requestedPath = app.Request.Url.AbsoluteUri;
            HttpContext       Context       = ((HttpApplication)s).Context;
            int PortalId = -1;

            DotNetNuke.Entities.Portals.PortalAliasInfo objPortalAliasInfo = null;
            string sUrl = HttpContext.Current.Request.RawUrl.Replace("http://", string.Empty).Replace("https://", string.Empty);

            objPortalAliasInfo = PortalAliasController.Instance.GetPortalAlias(HttpContext.Current.Request.Url.Host);
            if (Request.RawUrl.ToLowerInvariant().Contains("404.aspx"))
            {
                string sEx = ".jpg,.gif,.png,.swf,.js,.css,.html,.htm,desktopmodules,portals,.ashx,.ico,.txt,.doc,.docx,.pdf,.xml,.xls,.xlsx,.ppt,.pptx,.csv,.zip,.asmx,.aspx";
                foreach (string sn in sEx.Split(','))
                {
                    if (sUrl.Contains(sn))
                    {
                        // IO.File.AppendAllText(sPath, Request.RawUrl & "165<br />")
                        return;
                    }
                }
            }
            if (Request.Url.LocalPath.ToLower().Contains("scriptresource.axd") || Request.Url.LocalPath.ToLower().Contains("webresource.axd") || Request.Url.LocalPath.ToLower().Contains("viewer.aspx") || Request.Url.LocalPath.ToLower().Contains("cb.aspx") || Request.Url.LocalPath.ToLower().Contains("filesupload.aspx") || Request.Url.LocalPath.ToLower().Contains(".gif") || Request.Url.LocalPath.ToLower().Contains(".jpg") || Request.Url.LocalPath.ToLower().Contains(".css") || Request.Url.LocalPath.ToLower().Contains(".png") || Request.Url.LocalPath.ToLower().Contains(".swf") || Request.Url.LocalPath.ToLower().Contains(".htm") || Request.Url.LocalPath.ToLower().Contains(".html") || Request.Url.LocalPath.ToLower().Contains(".ashx") || Request.Url.LocalPath.ToLower().Contains(".cur") || Request.Url.LocalPath.ToLower().Contains(".ico") || Request.Url.LocalPath.ToLower().Contains(".txt") || Request.Url.LocalPath.ToLower().Contains(".pdf") || Request.Url.LocalPath.ToLower().Contains(".xml") || Request.Url.LocalPath.ToLower().Contains("/portals/") || Request.Url.LocalPath.ToLower().Contains("/desktopmodules/") || Request.Url.LocalPath.ToLower().Contains("evexport.aspx") || Request.Url.LocalPath.ToLower().Contains("signupjs.aspx") || Request.Url.LocalPath.ToLower().Contains("evsexport.aspx") || Request.Url.LocalPath.ToLower().Contains("fbcomm.aspx") || Request.Url.LocalPath.ToLower().Contains(".aspx") || Request.Url.LocalPath.ToLower().Contains(".js"))
            {
                return;
            }
            if (Request.Url.LocalPath.ToLower().Contains("install.aspx") || Request.Url.LocalPath.ToLower().Contains("installwizard.aspx") || Request.Url.LocalPath.ToLower().Contains("captcha.aspx") || Request.RawUrl.Contains("viewer.aspx") || Request.RawUrl.Contains("blank.html") || Request.RawUrl.Contains("default.htm") || Request.RawUrl.Contains("autosuggest.aspx"))
            {
                return;
            }
            PortalId = objPortalAliasInfo.PortalID;
            string searchURL = sUrl;

            searchURL = searchURL.Replace(objPortalAliasInfo.HTTPAlias, string.Empty);
            if (searchURL.Length < 2)
            {
                return;
            }
            string query = string.Empty;

            if (searchURL.Contains("?"))
            {
                query     = searchURL.Substring(searchURL.IndexOf("?"));
                searchURL = searchURL.Substring(0, searchURL.IndexOf("?") - 1);
            }
            string newSearchURL = string.Empty;

            foreach (string up in searchURL.Split('/'))
            {
                if (!(string.IsNullOrEmpty(up)))
                {
                    if (!(SimulateIsNumeric.IsNumeric(up)))
                    {
                        newSearchURL += up + "/";
                    }
                }
            }
            bool canContinue = false;

            Data.Common db      = new Data.Common();
            string      tagName = string.Empty;
            string      catName = string.Empty;

            if (newSearchURL.Contains("/category/") || newSearchURL.Contains("/tag/"))
            {
                if (newSearchURL.Contains("/category/"))
                {
                    string cat       = "/category/";
                    int    iEnd      = newSearchURL.IndexOf("/", newSearchURL.IndexOf(cat) + cat.Length + 1);
                    string catString = newSearchURL.Substring(newSearchURL.IndexOf(cat), iEnd - newSearchURL.IndexOf(cat));
                    catName      = catString.Replace(cat, string.Empty);
                    catName      = catName.Replace("/", string.Empty);
                    newSearchURL = newSearchURL.Replace(catString, string.Empty);
                }
                if (newSearchURL.Contains("/tag/"))
                {
                    string tag       = "/tag/";
                    int    iEnd      = newSearchURL.IndexOf("/", newSearchURL.IndexOf(tag) + tag.Length + 1);
                    string tagString = newSearchURL.Substring(newSearchURL.IndexOf(tag), iEnd - newSearchURL.IndexOf(tag));
                    tagName      = tagString.Replace(tag, string.Empty);
                    tagName      = tagName.Replace("/", string.Empty);
                    newSearchURL = newSearchURL.Replace(tagString, string.Empty);
                }
            }
            if ((sUrl.Contains("afv") && sUrl.Contains("post")) | (sUrl.Contains("afv") && sUrl.Contains("confirmaction")) | (sUrl.Contains("afv") && sUrl.Contains("sendto")) | (sUrl.Contains("afv") && sUrl.Contains("modreport")) | (sUrl.Contains("afv") && sUrl.Contains("search")) | sUrl.Contains("dnnprintmode") || sUrl.Contains("asg") || (sUrl.Contains("afv") && sUrl.Contains("modtopics")))
            {
                return;
            }
            try
            {
                using (IDataReader dr = db.URLSearch(PortalId, newSearchURL))
                {
                    while (dr.Read())
                    {
                        _tabId        = int.Parse(dr["TabID"].ToString());
                        _moduleId     = int.Parse(dr["ModuleId"].ToString());
                        _forumgroupId = int.Parse(dr["ForumGroupId"].ToString());
                        _forumId      = int.Parse(dr["ForumId"].ToString());
                        _topicId      = int.Parse(dr["TopicId"].ToString());
                        _archived     = int.Parse(dr["Archived"].ToString());
                        _otherId      = int.Parse(dr["OtherId"].ToString());
                        _urlType      = int.Parse(dr["UrlType"].ToString());
                        canContinue   = true;
                    }
                    dr.Close();
                }
            }
            catch (Exception ex)
            {
            }
            if (!(string.IsNullOrEmpty(catName)))
            {
                _categoryId = db.Tag_GetIdByName(PortalId, _moduleId, catName, true);
                _otherId    = _categoryId;
                _urlType    = 2;
            }
            if (!(string.IsNullOrEmpty(tagName)))
            {
                _tagId   = db.Tag_GetIdByName(PortalId, _moduleId, tagName, false);
                _otherId = _tagId;
                _urlType = 3;
            }

            if (_archived == 1)
            {
                sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
                if (!(string.IsNullOrEmpty(sUrl)))
                {
                    string sHost = objPortalAliasInfo.HTTPAlias;
                    if (sUrl.StartsWith("/"))
                    {
                        sUrl = sUrl.Substring(1);
                    }
                    if (!(sHost.EndsWith("/")))
                    {
                        sHost += "/";
                    }
                    sUrl = sHost + sUrl;
                    if (!(sUrl.EndsWith("/")))
                    {
                        sUrl += "/";
                    }
                    if (!(sUrl.StartsWith("http")))
                    {
                        if (Request.IsSecureConnection)
                        {
                            sUrl = "https://" + sUrl;
                        }
                        else
                        {
                            sUrl = "http://" + sUrl;
                        }
                    }
                    Response.Clear();
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", sUrl);
                    Response.End();
                }
            }
            if (_moduleId > 0)
            {
                Entities.Modules.ModuleController objModules = new Entities.Modules.ModuleController();
                SettingsInfo objSettings = new SettingsInfo();
                objSettings.MainSettings = objModules.GetModuleSettings(_moduleId);
                _mainSettings            = objSettings;      // DataCache.MainSettings(_moduleId)
            }
            if (_mainSettings == null)
            {
                return;
            }
            if (!_mainSettings.URLRewriteEnabled)
            {
                return;
            }
            if (!canContinue && (Request.RawUrl.Contains(ParamKeys.TopicId) || Request.RawUrl.Contains(ParamKeys.ForumId) || Request.RawUrl.Contains(ParamKeys.GroupId)))
            {
                sUrl = HandleOldUrls(Request.RawUrl, objPortalAliasInfo.HTTPAlias);
                if (!(string.IsNullOrEmpty(sUrl)))
                {
                    if (!(sUrl.StartsWith("http")))
                    {
                        if (Request.IsSecureConnection)
                        {
                            sUrl = "https://" + sUrl;
                        }
                        else
                        {
                            sUrl = "http://" + sUrl;
                        }
                    }
                    Response.Clear();
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", sUrl);
                    Response.End();
                }
            }
            if (!canContinue)
            {
                string topicUrl = string.Empty;
                if (newSearchURL.EndsWith("/"))
                {
                    newSearchURL = newSearchURL.Substring(0, newSearchURL.Length - 1);
                }
                if (newSearchURL.Contains("/"))
                {
                    topicUrl = newSearchURL.Substring(newSearchURL.LastIndexOf("/"));
                }
                topicUrl = topicUrl.Replace("/", string.Empty);
                if (!(string.IsNullOrEmpty(topicUrl)))
                {
                    Data.Topics topicsDb = new Data.Topics();
                    _topicId = topicsDb.TopicIdByUrl(PortalId, _moduleId, topicUrl.ToLowerInvariant());
                    if (_topicId > 0)
                    {
                        sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, -1);
                    }
                    else
                    {
                        sUrl = string.Empty;
                    }
                    if (!(string.IsNullOrEmpty(sUrl)))
                    {
                        string sHost = objPortalAliasInfo.HTTPAlias;
                        if (sHost.EndsWith("/") && sUrl.StartsWith("/"))
                        {
                            sUrl = sHost.Substring(0, sHost.Length - 1) + sUrl;
                        }
                        else if (!(sHost.EndsWith("/")) && !(sUrl.StartsWith("/")))
                        {
                            sUrl = sHost + "/" + sUrl;
                        }
                        else
                        {
                            sUrl = sHost + sUrl;
                        }
                        if (sUrl.StartsWith("/"))
                        {
                            sUrl = sUrl.Substring(1);
                        }
                        if (!(sUrl.StartsWith("http")))
                        {
                            if (Request.IsSecureConnection)
                            {
                                sUrl = "https://" + sUrl;
                            }
                            else
                            {
                                sUrl = "http://" + sUrl;
                            }
                        }
                        if (!(string.IsNullOrEmpty(sUrl)))
                        {
                            Response.Clear();
                            Response.Status = "301 Moved Permanently";
                            Response.AddHeader("Location", sUrl);
                            Response.End();
                        }
                    }
                }
            }

            if (canContinue)
            {
                if (searchURL != newSearchURL)
                {
                    string urlTail = searchURL.Replace(newSearchURL, string.Empty);
                    if (urlTail.StartsWith("/"))
                    {
                        urlTail = urlTail.Substring(1);
                    }
                    if (urlTail.EndsWith("/"))
                    {
                        urlTail = urlTail.Substring(0, urlTail.Length - 1);
                    }
                    if (urlTail.Contains("/"))
                    {
                        urlTail = urlTail.Substring(0, urlTail.IndexOf("/") - 1);
                    }
                    if (SimulateIsNumeric.IsNumeric(urlTail))
                    {
                        _page = Convert.ToInt32(urlTail);
                    }
                }

                string sPage = string.Empty;
                sPage = "&afpg=" + _page.ToString();
                string qs = string.Empty;
                if (sUrl.Contains("?"))
                {
                    qs = "&" + sUrl.Substring(sUrl.IndexOf("?") + 1);
                }
                string catQS = string.Empty;
                if (_categoryId > 0)
                {
                    catQS = "&act=" + _categoryId.ToString();
                }
                string sendTo = string.Empty;
                if (_topicId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&aft=" + _topicId + sPage + qs);
                }
                else if (_forumId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&aff=" + _forumId + sPage + qs + catQS);
                }
                else if (_forumgroupId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afg=" + _forumgroupId + sPage + qs + catQS);
                }
                else if (_urlType == 2 && _otherId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&act=" + _otherId + sPage + qs);
                }
                else if (_urlType == 3 && _otherId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=tags&aftg=" + _otherId + sPage + qs);
                }
                else if (_urlType == 1)
                {
                    string v = string.Empty;
                    switch (_otherId)
                    {
                    case 1:
                        v = "unanswered";
                        break;

                    case 2:
                        v = "notread";
                        break;

                    case 3:
                        v = "mytopics";
                        break;

                    case 4:
                        v = "activetopics";
                        break;

                    case 5:
                        v = "afprofile";
                        break;
                    }
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + "&afv=grid&afgt=" + v + sPage + qs);
                }
                else if (_tabId > 0)
                {
                    sendTo = ResolveUrl(app.Context.Request.ApplicationPath, "~/default.aspx?tabid=" + _tabId + sPage + qs);
                }

                RewriteUrl(app.Context, sendTo);
            }
        }
Ejemplo n.º 19
0
        private string HandleOldUrls(string rawUrl, string httpAlias)
        {
            string sUrl     = string.Empty;
            string currURL  = rawUrl;
            string splitter = "/";

            if (currURL.Contains("&"))
            {
                splitter = "&";
            }
            string[] parts = currURL.Split(Convert.ToChar(splitter));
            for (int i = 0; i < parts.Length; i++)
            {
                if (!(string.IsNullOrEmpty(parts[i])))
                {
                    if (parts[i].ToLowerInvariant().Contains("="))
                    {
                        string[] pair = parts[i].Split('=');
                        if (pair[0].ToLowerInvariant() == ParamKeys.ForumId)
                        {
                            _forumId = int.Parse(pair[1]);
                        }
                        else if (pair[0].ToLowerInvariant() == ParamKeys.TopicId)
                        {
                            _topicId = int.Parse(pair[1]);
                        }
                        else if (pair[0].ToLowerInvariant() == ParamKeys.PageId)
                        {
                            _page = int.Parse(pair[1]);
                        }
                        else if (pair[0].ToLowerInvariant() == ParamKeys.PageJumpId)
                        {
                            _page = int.Parse(pair[1]);
                        }
                        else if (pair[0].ToLowerInvariant() == ParamKeys.ContentJumpId)
                        {
                            _contentId = int.Parse(pair[1]);
                        }
                    }
                    else
                    {
                        if (parts[i].ToLowerInvariant() == ParamKeys.ForumId)
                        {
                            _forumId = int.Parse(parts[i + 1]);
                        }
                        else if (parts[i].ToLowerInvariant() == ParamKeys.TopicId)
                        {
                            _topicId = int.Parse(parts[i + 1]);
                        }
                        else if (parts[i].ToLowerInvariant() == ParamKeys.PageId)
                        {
                            _page = int.Parse(parts[i + 1]);
                        }
                        else if (parts[i].ToLowerInvariant() == ParamKeys.PageJumpId)
                        {
                            _page = int.Parse(parts[i + 1]);
                        }
                        else if (parts[i].ToLowerInvariant() == "tabid")
                        {
                            _tabId = int.Parse(parts[i + 1]);
                        }
                        else if (parts[i].ToLowerInvariant() == ParamKeys.ContentJumpId)
                        {
                            _contentId = int.Parse(parts[i + 1]);
                        }
                    }
                }
            }
            Data.Common db = new Data.Common();
            sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, _contentId);
            if (!(string.IsNullOrEmpty(sUrl)))
            {
                string sHost = httpAlias;
                if (sUrl.StartsWith("/"))
                {
                    sUrl = sUrl.Substring(1);
                }

                if (!(sHost.EndsWith("/")))
                {
                    sHost += "/";
                }
                sUrl = sHost + sUrl;
                if (!(sUrl.EndsWith("/")))
                {
                    sUrl += "/";
                }
                if (_contentId > 0)
                {
                    if (_page > 1)
                    {
                        sUrl += _page + "/";
                    }
                }
            }
            return(sUrl);
        }
Ejemplo n.º 20
0
        private void BindPosts(string sort = "ASC")
        {
            _pageSize = MainSettings.PageSize;

            if (UserId > 0)
            {
                _pageSize = UserDefaultPageSize;
            }

            if (_pageSize < 5)
            {
                _pageSize = 10;
            }

            _rowIndex = (PageId == 1) ? 0 : ((PageId * _pageSize) - _pageSize);

            var db       = new Data.Common();
            var fc       = new ForumController();
            var forumIds = fc.GetForumsForUser(ForumUser.UserRoles, PortalId, ModuleId, "CanRead");

            var sCrumb = "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ViewType + "=grid", "afgt=xxx" }) + "\">yyyy</a>";

            sCrumb = sCrumb.Replace("xxx", "{0}").Replace("yyyy", "{1}");

            if (Request.Params["afgt"] != null)
            {
                var gview = Utilities.XSSFilter(Request.Params["afgt"]).ToLowerInvariant();
                switch (gview)
                {
                case "notread":

                    if (UserId != -1)
                    {
                        lblHeader.Text = GetSharedResource("[RESX:NotRead]");
                        _dtResults     = db.UI_NotReadView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0];
                        if (_dtResults.Rows.Count > 0)
                        {
                            _rowCount             = _dtResults.Rows[0].GetInt("RecordCount");
                            btnMarkRead.Visible   = true;
                            btnMarkRead.InnerText = GetSharedResource("[RESX:MarkAllRead]");
                        }
                    }
                    else
                    {
                        Response.Redirect(NavigateUrl(TabId), true);
                    }
                    break;

                case "unanswered":

                    lblHeader.Text = GetSharedResource("[RESX:Unanswered]");
                    _dtResults     = db.UI_UnansweredView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0];
                    if (_dtResults.Rows.Count > 0)
                    {
                        _rowCount = _dtResults.Rows[0].GetInt("RecordCount");
                    }

                    break;

                case "tags":

                    var tagId = -1;
                    if (Request.QueryString["aftg"] != null && SimulateIsNumeric.IsNumeric(Request.QueryString["aftg"]))
                    {
                        tagId = int.Parse(Request.QueryString["aftg"]);
                    }

                    lblHeader.Text = GetSharedResource("[RESX:Tags]");
                    _dtResults     = db.UI_TagsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds, tagId).Tables[0];
                    if (_dtResults.Rows.Count > 0)
                    {
                        _rowCount = _dtResults.Rows[0].GetInt("RecordCount");
                    }

                    break;

                case "mytopics":

                    if (UserId != -1)
                    {
                        lblHeader.Text = GetSharedResource("[RESX:MyTopics]");
                        _dtResults     = db.UI_MyTopicsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0];
                        if (_dtResults.Rows.Count > 0)
                        {
                            _rowCount = _dtResults.Rows[0].GetInt("RecordCount");
                        }
                    }
                    else
                    {
                        Response.Redirect(NavigateUrl(TabId), true);
                    }

                    break;

                case "activetopics":

                    lblHeader.Text = GetSharedResource("[RESX:ActiveTopics]");

                    /*
                     * if (UserLastAccess != Utilities.NullDate())
                     * {
                     *  timeFrame = Convert.ToInt32(SimulateDateDiff.DateDiff(SimulateDateDiff.DateInterval.Minute, UserLastAccess, DateTime.Now));
                     *  drpTimeFrame.Items.Insert(0, new ListItem(GetDate(UserLastAccess), "~" + timeFrame.ToString()));
                     * }
                     */

                    var timeFrame = Utilities.SafeConvertInt(Request.Params["ts"], 1440);

                    if (timeFrame < 15 | timeFrame > 80640)
                    {
                        timeFrame = 1440;
                    }

                    drpTimeFrame.Visible       = true;
                    drpTimeFrame.SelectedIndex = drpTimeFrame.Items.IndexOf(drpTimeFrame.Items.FindByValue(timeFrame.ToString()));
                    _dtResults = db.UI_ActiveView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, timeFrame, forumIds).Tables[0];
                    if (_dtResults.Rows.Count > 0)
                    {
                        _rowCount = Convert.ToInt32(_dtResults.Rows[0]["RecordCount"]);
                    }

                    break;

                default:
                    Response.Redirect(NavigateUrl(TabId), true);
                    break;
                }

                sCrumb = string.Format(sCrumb, gview, lblHeader.Text);

                if (MainSettings.UseSkinBreadCrumb)
                {
                    Environment.UpdateBreadCrumb(Page.Controls, sCrumb);
                }

                var tempVar = BasePage;
                Environment.UpdateMeta(ref tempVar, "[VALUE] - " + lblHeader.Text, "[VALUE]", "[VALUE]");
            }


            if (_dtResults != null && _dtResults.Rows.Count > 0)
            {
                litRecordCount.Text = string.Format(GetSharedResource("[RESX:SearchRecords]"), _rowIndex + 1, _rowIndex + _dtResults.Rows.Count, _rowCount);

                pnlMessage.Visible = false;

                try
                {
                    rptTopics.Visible    = true;
                    rptTopics.DataSource = _dtResults;
                    rptTopics.DataBind();
                    BuildPager(PagerTop);
                    BuildPager(PagerBottom);
                }
                catch (Exception ex)
                {
                    litMessage.Text    = ex.Message;
                    pnlMessage.Visible = true;
                    rptTopics.Visible  = false;
                }
            }
            else
            {
                litMessage.Text    = GetSharedResource("[RESX:SearchNoResults]");
                pnlMessage.Visible = true;
            }
        }
Ejemplo n.º 21
0
        private void BindPosts(string sort = "ASC")
        {
            _pageSize = MainSettings.PageSize;
            
            if (UserId > 0)
                _pageSize = UserDefaultPageSize;
            
            if (_pageSize < 5)
                _pageSize = 10;

            _rowIndex = (PageId == 1) ? 0 : ((PageId * _pageSize) - _pageSize);

            var db = new Data.Common();
            var fc = new ForumController();
            var forumIds = fc.GetForumsForUser(ForumUser.UserRoles, PortalId, ModuleId, "CanRead");
            
            var sCrumb = "<a href=\"" + Utilities.NavigateUrl(TabId, "", new[] { ParamKeys.ViewType + "=grid", "afgt=xxx" }) + "\">yyyy</a>";
            sCrumb = sCrumb.Replace("xxx", "{0}").Replace("yyyy", "{1}");
            
            if (Request.Params["afgt"] != null)
            {
                var gview = Utilities.XSSFilter(Request.Params["afgt"]).ToLowerInvariant();
                switch (gview)
                {
                    case "notread":

                        if (UserId != -1)
                        {
                            lblHeader.Text = GetSharedResource("[RESX:NotRead]");
                            _dtResults = db.UI_NotReadView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0];
                            if (_dtResults.Rows.Count > 0)
                            {
                                _rowCount = _dtResults.Rows[0].GetInt("RecordCount");
                                btnMarkRead.Visible = true;
                                btnMarkRead.InnerText = GetSharedResource("[RESX:MarkAllRead]");
                            }
                        }
                        else
                            Response.Redirect(NavigateUrl(TabId), true);
                        break;

                    case "unanswered":

                        lblHeader.Text = GetSharedResource("[RESX:Unanswered]");
                        _dtResults = db.UI_UnansweredView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0];
                        if (_dtResults.Rows.Count > 0)
                            _rowCount = _dtResults.Rows[0].GetInt("RecordCount");

                        break;

                    case "tags":

                        var tagId = -1;
                        if (Request.QueryString["aftg"] != null && SimulateIsNumeric.IsNumeric(Request.QueryString["aftg"]))
                            tagId = int.Parse(Request.QueryString["aftg"]);

                        lblHeader.Text = GetSharedResource("[RESX:Tags]");
                        _dtResults = db.UI_TagsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds, tagId).Tables[0];
                        if (_dtResults.Rows.Count > 0)
                            _rowCount = _dtResults.Rows[0].GetInt("RecordCount");

                        break;

                    case "mytopics":

                        if (UserId != -1)
                        {
                            lblHeader.Text = GetSharedResource("[RESX:MyTopics]");
                            _dtResults = db.UI_MyTopicsView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, forumIds).Tables[0];
                            if (_dtResults.Rows.Count > 0)
                                _rowCount = _dtResults.Rows[0].GetInt("RecordCount");
                        }
                        else
                            Response.Redirect(NavigateUrl(TabId), true);

                        break;

                    case "activetopics":

                        lblHeader.Text = GetSharedResource("[RESX:ActiveTopics]");

                        /*
                        if (UserLastAccess != Utilities.NullDate())
                        {
                            timeFrame = Convert.ToInt32(SimulateDateDiff.DateDiff(SimulateDateDiff.DateInterval.Minute, UserLastAccess, DateTime.Now));
                            drpTimeFrame.Items.Insert(0, new ListItem(GetDate(UserLastAccess), "~" + timeFrame.ToString()));
                        }
                         */

                        var timeFrame = Utilities.SafeConvertInt(Request.Params["ts"], 1440);

                        if (timeFrame < 15 | timeFrame > 80640)
                            timeFrame = 1440;

                        drpTimeFrame.Visible = true;
                        drpTimeFrame.SelectedIndex = drpTimeFrame.Items.IndexOf(drpTimeFrame.Items.FindByValue(timeFrame.ToString()));
                        _dtResults = db.UI_ActiveView(PortalId, ModuleId, UserId, _rowIndex, _pageSize, sort, timeFrame, forumIds).Tables[0];
                        if (_dtResults.Rows.Count > 0)
                            _rowCount = Convert.ToInt32(_dtResults.Rows[0]["RecordCount"]);

                        break;

                    default:
                        Response.Redirect(NavigateUrl(TabId), true);
                        break;
                }

                sCrumb = string.Format(sCrumb, gview, lblHeader.Text);
               
                if (MainSettings.UseSkinBreadCrumb)
                    Environment.UpdateBreadCrumb(Page.Controls, sCrumb);

                var tempVar = BasePage;
                Environment.UpdateMeta(ref tempVar, "[VALUE] - " + lblHeader.Text, "[VALUE]", "[VALUE]");
            }


            if (_dtResults != null && _dtResults.Rows.Count > 0)
            {
                litRecordCount.Text = string.Format(GetSharedResource("[RESX:SearchRecords]"), _rowIndex + 1, _rowIndex + _dtResults.Rows.Count, _rowCount);

                pnlMessage.Visible = false;

                try
                {
                    rptTopics.Visible = true;
                    rptTopics.DataSource = _dtResults;
                    rptTopics.DataBind();
                    BuildPager(PagerTop);
                    BuildPager(PagerBottom);
                }
                catch (Exception ex)
                {
                    litMessage.Text = ex.Message;
                    pnlMessage.Visible = true;
                    rptTopics.Visible = false;
                }
            }
            else
            {
                litMessage.Text = GetSharedResource("[RESX:SearchNoResults]");
                pnlMessage.Visible = true;
            }

        }
Ejemplo n.º 22
0
		internal static void CreateDefaultSets(int PortalId, int PermissionsId)
		{
			var db = new Data.Common();
			var rc = new Security.Roles.RoleController();
			Security.Roles.RoleInfo ri;
			ri = rc.GetRoleByName(PortalId, "Registered Users");
			string permSet;
			if (ri != null)
			{
				permSet = db.GetPermSet(PermissionsId, "View");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "View", permSet);
			    permSet = db.GetPermSet(PermissionsId, "Read");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "Read", permSet);
			    permSet = db.GetPermSet(PermissionsId, "Create");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "Create", permSet);
			    permSet = db.GetPermSet(PermissionsId, "Reply");
				permSet = AddPermToSet(ri.RoleID.ToString(), 0, permSet);
				db.SavePermSet(PermissionsId, "Reply", permSet);
			}
			permSet = db.GetPermSet(PermissionsId, "View");
			permSet = AddPermToSet("-3", 0, permSet);
			db.SavePermSet(PermissionsId, "View", permSet);
		    permSet = db.GetPermSet(PermissionsId, "Read");
			permSet = AddPermToSet("-3", 0, permSet);
			db.SavePermSet(PermissionsId, "Read", permSet);
		    permSet = db.GetPermSet(PermissionsId, "View");
			permSet = AddPermToSet("-1", 0, permSet);
			db.SavePermSet(PermissionsId, "View", permSet);
		    permSet = db.GetPermSet(PermissionsId, "Read");
			permSet = AddPermToSet("-1", 0, permSet);
			db.SavePermSet(PermissionsId, "Read", permSet);
		}
        private void cbEditorAction_Callback(object sender, Controls.CallBackEventArgs e)
        {
            switch (e.Parameters[0].ToLowerInvariant())
            {
                case "forumsave":
                {
                    var fi = new Forum();
                    var fc = new ForumController();
                    var bIsNew = false;
                    int forumGroupId;
                    var forumSettingsKey = string.Empty;

                    if (Utilities.SafeConvertInt(e.Parameters[1]) <= 0)
                    {
                        bIsNew = true;
                        fi.ForumID = -1;
                    }
                    else
                    {
                        fi = fc.Forums_Get(PortalId, ModuleId, Utilities.SafeConvertInt(e.Parameters[1]), UserId, false, false, -1);
                        forumSettingsKey = fi.ForumSettingsKey;
                    }

                    fi.ModuleId = ModuleId;
                    fi.PortalId = PortalId;
                    var sParentValue = e.Parameters[2];
                    var parentForumId = 0;

                    if (sParentValue.Contains("GROUP"))
                    {
                        sParentValue = sParentValue.Replace("GROUP", string.Empty);
                        forumGroupId = Utilities.SafeConvertInt(sParentValue);
                    }
                    else
                    {
                        parentForumId = Utilities.SafeConvertInt(sParentValue.Replace("FORUM", string.Empty));
                        forumGroupId = fc.Forums_GetGroupId(parentForumId);
                    }

                    fi.ForumGroupId = forumGroupId;
                    fi.ParentForumId = parentForumId;
                    fi.ForumName = e.Parameters[3];
                    fi.ForumDesc = e.Parameters[4];
                    fi.Active = Utilities.SafeConvertBool(e.Parameters[5]);
                    fi.Hidden = Utilities.SafeConvertBool(e.Parameters[6]);

                    fi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]);

                    var fkey = string.IsNullOrEmpty(fi.ForumSettingsKey) ? string.Empty : fi.ForumSettingsKey;

                    if (Utilities.SafeConvertBool(e.Parameters[8]))
                    {
                        var fgc = new ForumGroupController();
                        var fgi = fgc.GetForumGroup(ModuleId, forumGroupId);

                        if (bIsNew)
                            fi.PermissionsId = fgi.PermissionsId;
                        else if (fi.ForumSettingsKey != "G:" + forumGroupId)
                            fi.PermissionsId = fgi.PermissionsId;

                        fi.ForumSettingsKey = "G:" + forumGroupId;

                    }
                    else if (bIsNew || fkey.Contains("G:"))
                    {
                        fi.ForumSettingsKey = string.Empty;
                        if (fi.InheritSecurity)
                            fi.PermissionsId = -1;
                    }
                    else
                    {
                        fi.ForumSettingsKey = "F:" + fi.ForumID;
                    }

                    if (forumSettingsKey != fkey && fkey.Contains("F:"))
                        bIsNew = true;

                    fi.PrefixURL = e.Parameters[9];
                    if (!(string.IsNullOrEmpty(fi.PrefixURL)))
                    {
                        var db = new Data.Common();
                        if (!(db.CheckForumURL(PortalId, ModuleId, fi.PrefixURL, fi.ForumID, fi.ForumGroupId)))
                            fi.PrefixURL = string.Empty;
                    }

                    var forumId = fc.Forums_Save(PortalId, fi, bIsNew, Utilities.SafeConvertBool(e.Parameters[8]));
                    recordId = forumId;
                    var securityKey = string.Empty;

                    DataCache.ClearForumGroupsCache(ModuleId);

                    var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId);
                    DataCache.CacheClear(cachekey);

                    cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                    DataCache.CacheClearPrefix(cachekey);

                    hidEditorResult.Value = forumId.ToString();
                    break;
                }

                case "groupsave":
                {
                    var bIsNew = false;
                    var groupId = Utilities.SafeConvertInt(e.Parameters[1]);
                    var fgc = new ForumGroupController();
                    var gi = (groupId > 0) ? fgc.Groups_Get(ModuleId, groupId) : new ForumGroupInfo();

                    var securityKey = string.Empty;
                    if (groupId == 0)
                        bIsNew = true;
                    else
                        securityKey = "G:" + groupId;

                    gi.ModuleId = ModuleId;
                    gi.ForumGroupId = groupId;
                    gi.GroupName = e.Parameters[3];
                    gi.Active = Utilities.SafeConvertBool(e.Parameters[5]);
                    gi.Hidden = Utilities.SafeConvertBool(e.Parameters[6]);

                    gi.SortOrder = string.IsNullOrWhiteSpace(e.Parameters[7]) ? 0 : Utilities.SafeConvertInt(e.Parameters[7]);

                    gi.PrefixURL = e.Parameters[9];
                    if (!(string.IsNullOrEmpty(gi.PrefixURL)))
                    {
                        var db = new Data.Common();
                        if (!(db.CheckGroupURL(PortalId, ModuleId, gi.PrefixURL, gi.ForumGroupId)))
                            gi.PrefixURL = string.Empty;
                    }

                    gi.GroupSettingsKey = securityKey;
                    var gc = new ForumGroupController();
                    groupId = gc.Groups_Save(PortalId, gi, bIsNew);
                    recordId = groupId;

                    DataCache.ClearForumGroupsCache(ModuleId);
                    var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                    DataCache.CacheClearPrefix(cachekey);
                    hidEditorResult.Value = groupId.ToString();

                    break;
                }

                case "forumsettingssave":
                {
                    var forumId = Utilities.SafeConvertInt(e.Parameters[1]);
                    var sKey = "F:" + forumId;
                    SaveSettings(sKey, e.Parameters);

                    hidEditorResult.Value = forumId.ToString();
                    DataCache.CacheClear(forumId.ToString() + "ForumSettings");
                    DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId));
                    DataCache.CacheClear(string.Format(CacheKeys.ForumInfo, forumId) + "st");
                    var cachekey = string.Format("AF-FI-{0}-{1}-{2}", PortalId, ModuleId, forumId);
                    DataCache.CacheClear(cachekey);
                    break;
                }

                case "groupsettingssave":
                {
                    var forumId = Utilities.SafeConvertInt(e.Parameters[1]);
                    var sKey = "G:" + forumId;
                    SaveSettings(sKey, e.Parameters);

                    hidEditorResult.Value = forumId.ToString();
                    DataCache.CacheClear(forumId.ToString() + "GroupSettings");
                    DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId));
                    DataCache.CacheClear(string.Format(CacheKeys.GroupInfo, forumId) + "st");

                    break;
                }

                case "deleteforum":
                {
                    var forumId = Utilities.SafeConvertInt(e.Parameters[1]);
                    DataProvider.Instance().Forums_Delete(PortalId, ModuleId, forumId);
                    var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                    DataCache.CacheClearPrefix(cachekey);
                    break;
                }

                case "deletegroup":
                {
                    var groupId = Utilities.SafeConvertInt(e.Parameters[1]);
                    DataProvider.Instance().Groups_Delete(ModuleId, groupId);
                    var cachekey = string.Format("AF-FV-{0}-{1}", PortalId, ModuleId);
                    DataCache.CacheClearPrefix(cachekey);
                    break;
                }
            }

            DataCache.CacheClear(string.Format(CacheKeys.ForumList, ModuleId));
            DataCache.ClearAllForumSettingsCache(ModuleId);
            DataCache.CacheClear(ModuleId + "fv");

            hidEditorResult.RenderControl(e.Output);
        }
Ejemplo n.º 24
0
		private string HandleOldUrls(string rawUrl, string httpAlias)
		{
			string sUrl = string.Empty;
			string currURL = rawUrl;
			string splitter = "/";
			if (currURL.Contains("&"))
			{
				splitter = "&";
			}
			string[] parts = currURL.Split(Convert.ToChar(splitter));
			for (int i = 0; i < parts.Length; i++)
			{
				if (! (string.IsNullOrEmpty(parts[i])))
				{
					if (parts[i].ToLowerInvariant().Contains("="))
					{
						string[] pair = parts[i].Split('=');
						if (pair[0].ToLowerInvariant() == ParamKeys.ForumId)
						{
							_forumId = int.Parse(pair[1]);
						}
						else if (pair[0].ToLowerInvariant() == ParamKeys.TopicId)
						{
							_topicId = int.Parse(pair[1]);
						}
						else if (pair[0].ToLowerInvariant() == ParamKeys.PageId)
						{
							_page = int.Parse(pair[1]);
						}
						else if (pair[0].ToLowerInvariant() == ParamKeys.PageJumpId)
						{
							_page = int.Parse(pair[1]);
						}
						else if (pair[0].ToLowerInvariant() == ParamKeys.ContentJumpId)
						{
							_contentId = int.Parse(pair[1]);
						}
					}
					else
					{
						if (parts[i].ToLowerInvariant() == ParamKeys.ForumId)
						{
							_forumId = int.Parse(parts[i + 1]);
						}
						else if (parts[i].ToLowerInvariant() == ParamKeys.TopicId)
						{
							_topicId = int.Parse(parts[i + 1]);
						}
						else if (parts[i].ToLowerInvariant() == ParamKeys.PageId)
						{
							_page = int.Parse(parts[i + 1]);
						}
						else if (parts[i].ToLowerInvariant() == ParamKeys.PageJumpId)
						{
							_page = int.Parse(parts[i + 1]);
						}
						else if (parts[i].ToLowerInvariant() == "tabid")
						{
							_tabId = int.Parse(parts[i + 1]);
						}
						else if (parts[i].ToLowerInvariant() == ParamKeys.ContentJumpId)
						{
							_contentId = int.Parse(parts[i + 1]);
						}
					}
				}
			}
			Data.Common db = new Data.Common();
			sUrl = db.GetUrl(_moduleId, _forumgroupId, _forumId, _topicId, _userId, _contentId);
			if (! (string.IsNullOrEmpty(sUrl)))
			{

				string sHost = httpAlias;
				if (sUrl.StartsWith("/"))
				{
					sUrl = sUrl.Substring(1);
				}

				if (! (sHost.EndsWith("/")))
				{
					sHost += "/";
				}
				sUrl = sHost + sUrl;
				if (! (sUrl.EndsWith("/")))
				{
					sUrl += "/";
				}
				if (_contentId > 0)
				{
					if (_page > 1)
					{
						sUrl += _page + "/";
					}
				}


			}
			return sUrl;
		}
Ejemplo n.º 25
0
		public int CreateGroupForum(int portalId, int moduleId, int socialGroupId, int forumGroupId, string forumName, string forumDescription, bool isPrivate, string forumConfig)
		{
			var forumId = -1;

			try
			{
				var rc = new RoleController();
				var forumsDb = new Data.Common();
			    var fgc = new ForumGroupController();
				var gi = fgc.Groups_Get(moduleId, forumGroupId);
				var socialGroup = rc.GetRole(socialGroupId, portalId);
				var groupAdmin = socialGroupId.ToString() + ":0";
				var groupMember = socialGroupId.ToString();

			    var ri = rc.GetRoleByName(portalId, "Administrators");
				var permissionsId = forumsDb.CreatePermSet(ri.RoleID.ToString());

				moduleId = gi.ModuleId;

				var fi = new Forum
				{
				    ForumDesc = forumDescription,
				    Active = true,
				    ForumGroupId = forumGroupId,
				    ForumID = -1,
				    ForumName = forumName,
				    Hidden = isPrivate,
				    ModuleId = gi.ModuleId,
				    ParentForumId = 0,
				    PortalId = portalId,
				    PermissionsId = gi.PermissionsId,
				    SortOrder = 0,
				    SocialGroupId = socialGroupId
				};

			    forumId = Forums_Save(portalId, fi, true, true);
				fi = GetForum(portalId, moduleId, forumId);
				fi.PermissionsId = permissionsId;
				Forums_Save(portalId, fi, false, false);

			    var xDoc = new XmlDocument();
				xDoc.LoadXml(forumConfig);

				var xRoot = xDoc.DocumentElement;
			    if (xRoot != null)
			    {
			        var xSecList = xRoot.SelectSingleNode("//security[@type='groupadmin']");
			        string permSet;
			        string secKey;
			        if (xSecList != null)
			        {
			            foreach (XmlNode n in xSecList.ChildNodes)
			            {
			                secKey = n.Name;
			                if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                    continue;
			                permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                permSet = Permissions.AddPermToSet(groupAdmin, 2, permSet);
			                forumsDb.SavePermSet(permissionsId, secKey, permSet);
			            }
			        }

			        xSecList = xRoot.SelectSingleNode("//security[@type='groupmember']");
			        if (xSecList != null)
			        {
			            foreach (XmlNode n in xSecList.ChildNodes)
			            {
			                secKey = n.Name;
						    
			                if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                    continue;
						    
			                permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                permSet = Permissions.AddPermToSet(groupMember, 0, permSet);
			                forumsDb.SavePermSet(permissionsId, secKey, permSet);
			            }
			        }

			        if (socialGroup.IsPublic)
			        {
			            xSecList = xRoot.SelectSingleNode("//security[@type='registereduser']");
			            ri = rc.GetRoleByName(portalId, "Registered Users");
			            if (xSecList != null)
			            {
			                foreach (XmlNode n in xSecList.ChildNodes)
			                {
			                    secKey = n.Name;
							    
			                    if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                        continue;
							    
			                    permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                    permSet = Permissions.AddPermToSet(ri.RoleID.ToString(), 0, permSet);
			                    forumsDb.SavePermSet(permissionsId, secKey, permSet);
			                }
			            }

			            xSecList = xRoot.SelectSingleNode("//security[@type='anon']");
			            if (xSecList != null)
			            {
			                foreach (XmlNode n in xSecList.ChildNodes)
			                {
			                    secKey = n.Name;

			                    if (n.Attributes == null || n.Attributes["value"].Value != "true") 
			                        continue;

			                    permSet = forumsDb.GetPermSet(permissionsId, secKey);
			                    permSet = Permissions.AddPermToSet("-1", 0, permSet);
			                    forumsDb.SavePermSet(permissionsId, secKey, permSet);
			                }
			            }
			        }
			    }
			}
			catch (Exception ex)
			{

			}

			DataCache.CacheClear(moduleId + "fv");

			return forumId;
		}
Ejemplo n.º 26
0
        public void Topics_Move(int PortalId, int ModuleId, int ForumId, int TopicId)
        {
            SettingsInfo settings = DataCache.MainSettings(ModuleId);
            if (settings.URLRewriteEnabled)
            {
                try
                {
                    Data.ForumsDB db = new Data.ForumsDB();
                    int oldForumId = -1;
                    oldForumId = db.Forum_GetByTopicId(TopicId);
                    ForumController fc = new ForumController();
                    Forum fi = fc.Forums_Get(oldForumId, -1, false);
                    if (! (string.IsNullOrEmpty(fi.PrefixURL)))
                    {
                        Data.Common dbC = new Data.Common();
                        string sURL = dbC.GetUrl(ModuleId, fi.ForumGroupId, oldForumId, TopicId, -1, -1);
                        if (! (string.IsNullOrEmpty(sURL)))
                        {
                            dbC.ArchiveURL(PortalId, fi.ForumGroupId, ForumId, TopicId, sURL);
                        }
                    }
                }
                catch (Exception ex)
                {

                }
            }
            DataProvider.Instance().Topics_Move(PortalId, ModuleId, ForumId, TopicId);
        }
Ejemplo n.º 27
0
		public int Forums_Save(int portalId, Forum fi, bool isNew, bool useGroup)
		{
			var rc = new RoleController();
		    var db = new Data.Common();
			var permissionsId = -1;
			if (useGroup && (string.IsNullOrEmpty(fi.ForumSettingsKey) || fi.PermissionsId == -1))
			{
				var fc = new ForumGroupController();
				var fg = fc.Groups_Get(fi.ModuleId, fi.ForumGroupId);
				if (fg != null)
				{
					fi.ForumSettingsKey = fg.GroupSettingsKey;
					//fi.ModuleId = fg.ModuleId
					fi.PermissionsId = fg.PermissionsId;
				}
			}
			else if (fi.PermissionsId <= 0 && useGroup == false)
			{
				var ri = rc.GetRoleByName(portalId, "Administrators");
				if (ri != null)
				{
					fi.PermissionsId = db.CreatePermSet(ri.RoleID.ToString());
					permissionsId = fi.PermissionsId;
					isNew = true;
				}
				if (fi.ForumID > 0 & ! (string.IsNullOrEmpty(fi.ForumSettingsKey)))
				{
					if (fi.ForumSettingsKey.Contains("G:"))
						fi.ForumSettingsKey = string.Empty;
				}
				if (fi.ForumSettingsKey == "" && fi.ForumID > 0)
				{
					fi.ForumSettingsKey = "F:" + fi.ForumID;
				}
			}
			else if (useGroup == false && string.IsNullOrEmpty(fi.ForumSettingsKey) && fi.ForumID > 0)
			{
				fi.ForumSettingsKey = "F:" + fi.ForumID;
			}

			var forumId = Convert.ToInt32(DataProvider.Instance().Forum_Save(portalId, fi.ForumID, fi.ModuleId, fi.ForumGroupId, fi.ParentForumId, fi.ForumName, fi.ForumDesc, fi.SortOrder, fi.Active, fi.Hidden, fi.ForumSettingsKey, fi.PermissionsId, fi.PrefixURL, fi.SocialGroupId, fi.HasProperties));
			if (String.IsNullOrEmpty(fi.ForumSettingsKey))
				fi.ForumSettingsKey = "F:" + forumId;

			if (fi.ForumSettingsKey.Contains("G:"))
			    DataProvider.Instance().Forum_ConfigCleanUp(fi.ModuleId, "F:" + fi.ForumID, "F:" + fi.ForumID);

			if (isNew && useGroup == false)
			{
				var moduleId = fi.ModuleId;
				Permissions.CreateDefaultSets(portalId, permissionsId);

				var sKey = "F:" + forumId.ToString();
				Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicsTemplateId, "0");
				Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicTemplateId, "0");
				Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.TopicFormId, "0");
				Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.ReplyFormId, "0");
				Settings.SaveSetting(moduleId, sKey, ForumSettingKeys.AllowRSS, "false");
			}
            
            // Clear the caches
			DataCache.CacheClear(string.Format(CacheKeys.ForumList, fi.ModuleId));

            var cachekey = string.Format(forumInfoCacheKey, portalId, fi.ModuleId, forumId);
			DataCache.CacheClear(cachekey);

			return forumId;
		}
Ejemplo n.º 28
0
		internal static bool RemoveObjectFromAll(string objectId, int objectType, int PermissionsId)
		{
			var enumType = typeof(SecureActions);
			Array values = Enum.GetValues(enumType);
			var db = new Data.Common();
			for (int i = 0; i < values.Length; i++)
			{
				string text = Convert.ToString(Enum.Parse(enumType, values.GetValue(i).ToString()));
				string permSet = db.GetPermSet(PermissionsId, text);
				permSet = RemovePermFromSet(objectId, objectType, permSet);
				db.SavePermSet(PermissionsId, text, permSet);
			}
			return true;
		}