Exemple #1
0
        public void SendEmailToModerators(int TemplateId, int PortalId, int ForumId, int TopicId, int ReplyId, int ModuleID, int TabID, string Comments, DotNetNuke.Entities.Users.UserInfo User)
        {
            var          _portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]);
            SettingsInfo MainSettings    = DataCache.MainSettings(ModuleID);
            var          fc = new ForumController();
            Forum        fi = fc.Forums_Get(ForumId, -1, false, true);

            if (fi == null)
            {
                return;
            }
            var subs = new List <SubscriptionInfo>();
            var rc   = new Security.Roles.RoleController();
            var uc   = new Entities.Users.UserController();
            SubscriptionInfo si;
            string           modApprove = fi.Security.ModApprove;

            string[] modRoles = modApprove.Split('|')[0].Split(';');
            if (modRoles != null)
            {
                foreach (string r in modRoles)
                {
                    if (!(string.IsNullOrEmpty(r)))
                    {
                        int    rid   = Convert.ToInt32(r);
                        string rName = rc.GetRole(rid, PortalId).RoleName;
                        foreach (Entities.Users.UserRoleInfo usr in rc.GetUserRolesByRoleName(PortalId, rName))
                        {
                            var ui = uc.GetUser(PortalId, usr.UserID);
                            si = new SubscriptionInfo
                            {
                                UserId      = ui.UserID,
                                DisplayName = ui.DisplayName,
                                Email       = ui.Email,
                                FirstName   = ui.FirstName,
                                LastName    = ui.LastName
                            };
                            if (!(subs.Contains(si)))
                            {
                                subs.Add(si);
                            }
                        }
                    }
                }
            }

            if (subs.Count <= 0)
            {
                return;
            }
            string       Subject;
            string       BodyText;
            string       BodyHTML;
            string       sTemplate = string.Empty;
            var          tc        = new TemplateController();
            TemplateInfo ti        = tc.Template_Get(TemplateId, PortalId, ModuleID);

            Subject  = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, _portalSettings.TimeZoneOffset);
            BodyText = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset);
            BodyHTML = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, PortalId, ModuleID, TabID, ForumId, TopicId, ReplyId, Comments, User, -1, _portalSettings.TimeZoneOffset);
            string sFrom;

            sFrom = fi.EmailAddress != string.Empty ? fi.EmailAddress : _portalSettings.Email;

            var oEmail = new Email
            {
                Recipients         = subs,
                Subject            = Subject,
                From               = sFrom,
                BodyText           = BodyText,
                BodyHTML           = BodyHTML,
                SmtpServer         = Host.SMTPServer,                     // Convert.ToString(_portalSettings.HostSettings["SMTPServer"]),
                SmtpUserName       = Host.SMTPUsername,                   // Convert.ToString(_portalSettings.HostSettings["SMTPUsername"]),
                SmtpPassword       = Host.SMTPPassword,                   // Convert.ToString(_portalSettings.HostSettings["SMTPPassword"]),
                SmtpAuthentication = Host.SMTPAuthentication              // Convert.ToString(_portalSettings.HostSettings["SMTPAuthentication"])
            };

//#if SKU_ENTERPRISE
            oEmail.UseQueue = MainSettings.MailQueue;
//#endif
            var objThread = new System.Threading.Thread(oEmail.Send);

            objThread.Start();
        }
        public static void SendEmailToModerators(int templateId, int portalId, int forumId, int topicId, int replyId, int moduleID, int tabID, string comments, UserInfo user)
        {
            var portalSettings = (Entities.Portals.PortalSettings)(HttpContext.Current.Items["PortalSettings"]);
            var mainSettings   = DataCache.MainSettings(moduleID);
            var fc             = new ForumController();
            var fi             = fc.Forums_Get(forumId, -1, false, true);

            if (fi == null)
            {
                return;
            }

            var subs       = new List <SubscriptionInfo>();
            var rc         = new Security.Roles.RoleController();
            var rp         = RoleProvider.Instance();
            var uc         = new Entities.Users.UserController();
            var modApprove = fi.Security.ModApprove;
            var modRoles   = modApprove.Split('|')[0].Split(';');

            foreach (var r in modRoles)
            {
                if (string.IsNullOrEmpty(r))
                {
                    continue;
                }
                var rid   = Convert.ToInt32(r);
                var rName = rc.GetRole(rid, portalId).RoleName;
                foreach (UserRoleInfo usr in rp.GetUserRoles(portalId, null, rName))
                {
                    var ui = uc.GetUser(portalId, usr.UserID);
                    var si = new SubscriptionInfo
                    {
                        UserId      = ui.UserID,
                        DisplayName = ui.DisplayName,
                        Email       = ui.Email,
                        FirstName   = ui.FirstName,
                        LastName    = ui.LastName
                    };
                    if (!(subs.Contains(si)))
                    {
                        subs.Add(si);
                    }
                }
            }

            if (subs.Count <= 0)
            {
                return;
            }

            var sTemplate = string.Empty;
            var tc        = new TemplateController();
            var ti        = tc.Template_Get(templateId, portalId, moduleID);
            var subject   = TemplateUtils.ParseEmailTemplate(ti.Subject, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes));
            var bodyText  = TemplateUtils.ParseEmailTemplate(ti.TemplateText, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, comments, user, -1, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes));
            var bodyHTML  = TemplateUtils.ParseEmailTemplate(ti.TemplateHTML, string.Empty, portalId, moduleID, tabID, forumId, topicId, replyId, comments, user, -1, Convert.ToInt32(portalSettings.TimeZone.BaseUtcOffset.TotalMinutes));
            var sFrom     = fi.EmailAddress != string.Empty ? fi.EmailAddress : portalSettings.Email;

            var oEmail = new Email
            {
                Recipients = subs,
                Subject    = subject,
                From       = sFrom,
                BodyText   = bodyText,
                BodyHTML   = bodyHTML,
                UseQueue   = mainSettings.MailQueue
            };


            new Thread(oEmail.Send).Start();
        }
Exemple #3
0
        private string BuildItem(DataRow dr, int PostTabID, int Indent, bool IncludeBody, int PortalId)
        {
            SettingsInfo  MainSettings = DataCache.MainSettings(ModuleID);
            StringBuilder sb           = new StringBuilder(1024);

            string[] Params = { ParamKeys.ForumId + "=" + dr["ForumID"].ToString(), ParamKeys.TopicId + "=" + dr["TopicId"].ToString(), ParamKeys.ViewType + "=" + Views.Topic };
            string   URL    = DotNetNuke.Common.Globals.NavigateURL(PostTabID, "", Params);

            if (Request.QueryString["asg"] != null)
            {
                if (SimulateIsNumeric.IsNumeric(Request.QueryString["asg"]))
                {
                    Params = new string[] { "asg=" + Request.QueryString["asg"], ParamKeys.ForumId + "=" + dr["ForumId"].ToString(), ParamKeys.ViewType + "=" + Views.Topic, ParamKeys.TopicId + "=" + dr["TopicId"].ToString() };
                    URL    = DotNetNuke.Common.Globals.NavigateURL(PostTabID, "", Params);
                }
            }
            else if (MainSettings.URLRewriteEnabled && !(string.IsNullOrEmpty(dr["FullUrl"].ToString())))
            {
                string sTopicURL = string.Empty;
                if (!(string.IsNullOrEmpty(MainSettings.PrefixURLBase)))
                {
                    sTopicURL = "/" + MainSettings.PrefixURLBase;
                }
                sTopicURL += dr["FullUrl"].ToString();

                URL = sTopicURL;
            }
            if (URL.IndexOf(Request.Url.Host) == -1)
            {
                URL = DotNetNuke.Common.Globals.AddHTTP(Request.Url.Host) + URL;
            }
            if (LastBuildDate == new DateTime())
            {
                LastBuildDate = Convert.ToDateTime(dr["DateCreated"]).AddMinutes(offSet);
            }
            else
            {
                if (Convert.ToDateTime(dr["DateCreated"]).AddMinutes(offSet) > LastBuildDate)
                {
                    LastBuildDate = Convert.ToDateTime(dr["DateCreated"]).AddMinutes(offSet);
                }
            }
            sb.Append(WriteElement("item", Indent));
            string body = dr["Body"].ToString();

            if (body.IndexOf("<body>") > 0)
            {
                body = TemplateUtils.GetTemplateSection(body, "<body>", "</body>");
            }

            /*
             * if (body.Contains("&#91;IMAGE:"))
             * {
             *  string strHost = DotNetNuke.Common.Globals.AddHTTP(DotNetNuke.Common.Globals.GetDomainName(Request)) + "/";
             *  string pattern = "(&#91;IMAGE:(.+?)&#93;)";
             *  Regex regExp = new Regex(pattern);
             *  MatchCollection matches = null;
             *  matches = regExp.Matches(body);
             *  foreach (Match match in matches)
             *  {
             *      string sImage = "";
             *      sImage = "<img src=\"" + strHost + "DesktopModules/ActiveForums/viewer.aspx?portalid=" + PortalId + "&moduleid=" + ModuleID + "&attachid=" + match.Groups[2].Value + "\" border=\"0\" />";
             *      body = body.Replace(match.Value, sImage);
             *  }
             * }
             * if (body.Contains("&#91;THUMBNAIL:"))
             * {
             *  string strHost = DotNetNuke.Common.Globals.AddHTTP(DotNetNuke.Common.Globals.GetDomainName(Request)) + "/";
             *  string pattern = "(&#91;THUMBNAIL:(.+?)&#93;)";
             *  Regex regExp = new Regex(pattern);
             *  MatchCollection matches = null;
             *  matches = regExp.Matches(body);
             *  foreach (Match match in matches)
             *  {
             *      string sImage = "";
             *      string thumbId = match.Groups[2].Value.Split(':')[0];
             *      string parentId = match.Groups[2].Value.Split(':')[1];
             *      sImage = "<a href=\"" + strHost + "DesktopModules/ActiveForums/viewer.aspx?portalid=" + PortalId + "&moduleid=" + ModuleID + "&attachid=" + parentId + "\" target=\"_blank\"><img src=\"" + strHost + "DesktopModules/ActiveForums/viewer.aspx?portalid=" + PortalId + "&moduleid=" + ModuleID + "&attachid=" + thumbId + "\" border=\"0\" /></a>";
             *      body = body.Replace(match.Value, sImage);
             *  }
             * }
             */
            body = body.Replace("src=\"/Portals", "src=\"" + DotNetNuke.Common.Globals.AddHTTP(Request.Url.Host) + "/Portals");
            body = Utilities.ManageImagePath(body, DotNetNuke.Common.Globals.AddHTTP(Request.Url.Host));

            sb.Append(WriteElement("title", dr["Subject"].ToString(), Indent + 1));
            sb.Append(WriteElement("description", body, Indent + 1));
            sb.Append(WriteElement("link", URL, Indent + 1));
            sb.Append(WriteElement("dc:creator", UserProfiles.GetDisplayName(ModuleID, -1, dr["AuthorUserName"].ToString(), dr["AuthorFirstName"].ToString(), dr["AuthorLastName"].ToString(), dr["AuthorDisplayName"].ToString(), null), Indent + 1));
            sb.Append(WriteElement("pubDate", Convert.ToDateTime(dr["DateCreated"]).AddMinutes(offSet).ToString("r"), Indent + 1));
            sb.Append(WriteElement("guid", URL, Indent + 1));
            sb.Append(WriteElement("slash:comments", dr["ReplyCount"].ToString(), Indent + 1));
            sb.Append(WriteElement("/item", Indent));

            return(sb.ToString());
        }