Exemplo n.º 1
0
        void TopicSolved(object sender, ActionEventArgs e)
        {
            uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender;

                if (a.Alias == "TopicSolved") {

                    Comment c = new Comment(e.ItemId);

                    if (c != null) {
                        Topic t = new Topic(c.TopicId);

                        int answer = our.Data.SqlHelper.ExecuteScalar<int>("SELECT answer FROM forumTopics where id = @id", Data.SqlHelper.CreateParameter("@id", t.Id));

                        //if performer and author of the topic is the same... go ahead..

                        if (e.PerformerId == t.MemberId && answer == 0) {

                            //receiver of points is the comment author.
                            e.ReceiverId = c.MemberId;

                            //remove any previous votes by the author on this comment to ensure the solution is saved instead of just the vote
                            a.ClearVotes(e.PerformerId, e.ItemId);

                            //this uses a non-standard coloumn in the forum schema, so this is added manually..
                            our.Data.SqlHelper.ExecuteNonQuery("UPDATE forumTopics SET answer = @answer WHERE id = @id", Data.SqlHelper.CreateParameter("@id", t.Id), Data.SqlHelper.CreateParameter("@answer", c.Id));
                        }

                    }
                }
        }
Exemplo n.º 2
0
        void TopicVote(object sender, ActionEventArgs e)
        {
            uPowers.BusinessLogic.Action a = (uPowers.BusinessLogic.Action)sender;

                if (a.Alias == "LikeTopic" || a.Alias == "DisLikeTopic") {
                    Topic t = new Topic(e.ItemId);
                    e.ReceiverId = t.MemberId;
                 }
        }
        private void SendMarkAsSolutionReminders()
        {
            // Mark As Solution Reminder
            using (SqlConnection conn = new SqlConnection(umbraco.GlobalSettings.DbDSN))
            {
                try
                {
                    string select = @"select id, memberId from forumTopics where answer = 0
                                and created < getdate() - 7
                                and created > '2012-09-16 00:00:00'
                                and replies > 0
                                and id not in (select topicId from notificationMarkAsSolution)
                                order by created desc;";

                    SqlCommand comm = new SqlCommand(
                        select, conn);

                    conn.Open();

                    SqlDataReader dr = comm.ExecuteReader();

                    while (dr.Read())
                    {
                        InstantNotification not = new InstantNotification();

                        int topicId = dr.GetInt32(0);
                        int memberId = dr.GetInt32(1);

                        Topic t = new Topic(topicId);

                        not.Invoke(Config.ConfigurationFile, Config.AssemblyDir, "MarkAsSolutionReminderSingle", topicId, memberId, NiceTopicUrl(t));
                    }

                }
                catch (Exception ex)
                {
                    umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "[Notifications] " + ex.Message);

                }
                finally
                {
                    if(conn != null)
                        conn.Close();
                }
            }
        }
        private static string NiceTopicUrl(Topic t)
        {
            if (t.Exists)
            {
                string _url = umbraco.library.NiceUrl(t.ParentId);

                if (umbraco.GlobalSettings.UseDirectoryUrls)
                {
                    return "/" + _url.Trim('/') + "/" + t.Id.ToString() + "-" + t.UrlName;
                }
                else
                {
                    return "/" + _url.Substring(0, _url.LastIndexOf('.')).Trim('/') + "/" + t.Id.ToString() + "-" + t.UrlName + ".aspx";
                }
            }
            else
            {
                return "";
            }
        }
Exemplo n.º 5
0
        public SimpleDataSet CreateNewDocument(int id)
        {
            lock (m_Locker)
            {
                //JobDetailItem jobDetails = new JobDetailItem();
                Topic forumTopic = new Topic(id);

                //First generate the accumulated comment text:
                string commentText = String.Empty;
                foreach (Comment currentComment in forumTopic.Comments())
                {
                    commentText += umbraco.library.StripHtml(currentComment.Body);
                }

                return new SimpleDataSet()
                {
                    NodeDefinition = new IndexedNode() { NodeId = (id), Type = "ForumPosts" },
                    RowData = new Dictionary<string, string>()
                    {
                        { "Title", SanitizeXmlString(forumTopic.Title.Replace("<![CDATA[", string.Empty).Replace("]]>",string.Empty))},
                        { "Body", SanitizeXmlString(forumTopic.Body.Replace("<![CDATA[", string.Empty).Replace("]]>",string.Empty))},
                        { "Created", forumTopic.Created.ToString()},
                        { "Exists", forumTopic.Exists.ToString()},
                        { "LatestComment", forumTopic.LatestComment.ToString()},
                        { "LatestReplyAuthor", forumTopic.LatestReplyAuthor.ToString()},
                        { "Locked", forumTopic.Locked.ToString()},
                        { "MemberId", forumTopic.MemberId.ToString()},
                        { "ParentId", forumTopic.ParentId.ToString()},
                        { "Replies", forumTopic.Replies.ToString()},
                        { "Updated", forumTopic.Updated.ToString()},
                        { "UrlName", forumTopic.UrlName.ToString()},
                        {"nodeTypeAlias","forumPost"},
                        { "CommentsContent", SanitizeXmlString(commentText.Replace("<![CDATA[", string.Empty).Replace("]]>",string.Empty))}
                    }
                };
            }
        }
Exemplo n.º 6
0
        public static Topic GetFromReader(umbraco.DataLayer.IRecordsReader reader)
        {
            var topic = new Topic
                            {
                                Id = reader.GetInt("id"),
                                ParentId = reader.GetInt("parentId"),
                                MemberId = reader.GetInt("memberId"),
                                Replies = reader.GetInt("replies"),
                                Title = reader.GetString("title"),
                                Body = reader.GetString("body"),
                                LatestReplyAuthor = reader.GetInt("latestReplyAuthor"),
                                Created = reader.GetDateTime("created"),
                                Updated = reader.GetDateTime("updated"),
                                UrlName = reader.GetString("urlName"),
                                Locked = reader.GetBoolean("locked")
                            };

            return topic;
        }
Exemplo n.º 7
0
        public static Topic Create(int forumId, string title, string body, int memberId)
        {
            var topic = new Topic
                          {
                              ParentId = forumId,
                              Title = title,
                              Body = body,
                              MemberId = memberId,
                              LatestReplyAuthor = memberId,
                              Replies = 0
                          };
            topic.Save();

            return topic;
        }
Exemplo n.º 8
0
        public void Save()
        {
            if (Id == 0) {

                if (Library.Utills.IsMember(MemberId) && !string.IsNullOrEmpty(Body)) {
                    CreateEventArgs e = new CreateEventArgs();
                    FireBeforeCreate(e);
                    if (!e.Cancel) {
                        Data.SqlHelper.ExecuteNonQuery("INSERT INTO forumComments (topicId, memberId, body, position) VALUES(@topicId, @memberId, @body, @position)",
                            Data.SqlHelper.CreateParameter("@topicId", TopicId),
                            Data.SqlHelper.CreateParameter("@memberId", MemberId),
                            Data.SqlHelper.CreateParameter("@body", Body),
                            Data.SqlHelper.CreateParameter("@position", Position)
                            );

                        Created = DateTime.Now;
                        Id = Data.SqlHelper.ExecuteScalar<int>("SELECT MAX(id) FROM forumComments WHERE memberId = @memberId",
                            Data.SqlHelper.CreateParameter("@memberId", MemberId));

                        Topic t = new Topic(TopicId);
                        if (t.Exists) {
                            t.Save();
                        }

                        Forum f = new Forum(t.ParentId);
                        if (f.Exists) {
                            f.SetLatestComment(Id);
                            f.SetLatestTopic(t.Id);
                            f.SetLatestAuthor(MemberId);
                            f.LatestPostDate = DateTime.Now;
                            f.Save();
                        }

                        FireAfterCreate(e);
                    }
                }

            } else {

                UpdateEventArgs e = new UpdateEventArgs();
                FireBeforeUpdate(e);

                if (!e.Cancel) {
                    Data.SqlHelper.ExecuteNonQuery("UPDATE forumComments SET topicId = @topicId, memberId = @memberId, body = @body WHERE id = @id",
                        Data.SqlHelper.CreateParameter("@topicId", TopicId),
                        Data.SqlHelper.CreateParameter("@memberId", MemberId),
                        Data.SqlHelper.CreateParameter("@body", Body),
                        Data.SqlHelper.CreateParameter("@id", Id)
                        );
                    FireAfterUpdate(e);
                }
            }
        }
Exemplo n.º 9
0
        public void Delete()
        {
            DeleteEventArgs e = new DeleteEventArgs();
            FireBeforeDelete(e);
            if (!e.Cancel) {
                Topic t = new Topic(this.TopicId);
                Forum f = new Forum(t.ParentId);

                Data.SqlHelper.ExecuteNonQuery("DELETE FROM forumComments WHERE id = " + Id.ToString());
                Id = 0;

                t.Save(true);
                f.Save();

                FireAfterDelete(e);
            }
        }
Exemplo n.º 10
0
        public static Topic GetFromReader(umbraco.DataLayer.IRecordsReader dr)
        {
            Topic t = new Topic();
            t.Id = dr.GetInt("id");
            t.ParentId = dr.GetInt("parentId");
            t.MemberId = dr.GetInt("memberId");
            t.Replies = dr.GetInt("replies");
            t.Title = dr.GetString("title");
            t.Body = dr.GetString("body");
            t.LatestReplyAuthor = dr.GetInt("latestReplyAuthor");
            t.Created = dr.GetDateTime("created");
            t.Updated = dr.GetDateTime("updated");

            t.UrlName = dr.GetString("urlName");

            t.Locked = dr.GetBoolean("locked");

            return t;
        }
Exemplo n.º 11
0
        public static Topic Create(int forumId, string title, string body, int memberId)
        {
            Topic t = new Topic();
            t.ParentId = forumId;
            t.Title = title;
            t.Body = body;
            t.MemberId = memberId;
            t.LatestReplyAuthor = memberId;
            t.Replies = 0;
            t.Save();

            return t;
        }
Exemplo n.º 12
0
        public override bool SendNotification(System.Xml.XmlNode details, params object[] args)
        {
            try
            {
                SmtpClient c = new SmtpClient(details.SelectSingleNode("//smtp").InnerText);
                c.Credentials = new System.Net.NetworkCredential(details.SelectSingleNode("//username").InnerText, details.SelectSingleNode("//password").InnerText);

                MailAddress from = new MailAddress(
                    details.SelectSingleNode("//from/email").InnerText,
                    details.SelectSingleNode("//from/name").InnerText);

                string subject = details.SelectSingleNode("//subject").InnerText;
                string body = details.SelectSingleNode("//body").InnerText;

                Comment com = (Comment)args[0];
                Topic t = new Topic(com.TopicId);
                subject = string.Format(subject, t.Title);

                Member s = (Member)args[2];

                string domain = details.SelectSingleNode("//domain").InnerText;

                body = string.Format(body,
                    t.Title,
                    "http://" + domain + args[1].ToString(), s.Text,  HttpUtility.HtmlDecode(umbraco.library.StripHtml(com.Body)));

                SqlConnection conn = new SqlConnection(details.SelectSingleNode("//conn").InnerText);

                SqlCommand comm = new SqlCommand("Select memberId from forumTopicSubscribers where topicId = @topicId", conn);
                comm.Parameters.AddWithValue("@topicId", t.Id);

                conn.Open();

                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {

                    int mid = dr.GetInt32(0);
                    try
                    {
                        Member m = new Member(mid);

                        if (m.Id != com.MemberId
                            && m.getProperty("bugMeNot").Value.ToString() != "1")
                        {
                            MailMessage mm = new MailMessage();
                            mm.Subject = subject;
                            mm.Body = body;

                            mm.To.Add(m.Email);
                            mm.From = from;

                            c.Send(mm);
                        }
                    }
                    catch (Exception e)
                    {
                        umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1,
                            "[Notifications] Error sending mail to " +  mid.ToString() + " " + e.Message);
                    }
                }

                conn.Close();

            }
            catch (Exception e)
            {
                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "[Notifications]" + e.Message);
            }
            return true;
        }