forked from ChrisHammond/dnnCHAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Archive.ascx.cs
174 lines (150 loc) · 7.44 KB
/
Archive.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
' Copyright (c) 2016 Christoc.com Software Solutions
' All rights reserved.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
' and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
' SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
' ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
' OR OTHER DEALINGS IN THE SOFTWARE.
'
*/
using System.Globalization;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;
using Christoc.Modules.DnnChat.Components;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Users;
using DotNetNuke.Framework;
using DotNetNuke.Services.Localization;
namespace Christoc.Modules.DnnChat
{
using System;
using DotNetNuke.Services.Exceptions;
/// -----------------------------------------------------------------------------
/// <summary>
/// The Archive class displays old Chat messages
///
/// </summary>
/// -----------------------------------------------------------------------------
public partial class Archive : DnnChatModuleBase
{
override protected void OnInit(EventArgs e)
{
jQuery.RequestUIRegistration();
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
//TODO: be sure to check for permissions when enabled
if (!Page.IsPostBack)
{
var sd = Request.QueryString["sd"];
var ed = Request.QueryString["ed"];
var startDate = DateTime.UtcNow.Date;
var endDate = DateTime.UtcNow;
if (sd != null)
{
startDate = Convert.ToDateTime(sd);
}
if (ed != null)
{
endDate = Convert.ToDateTime(ed);
}
txtStartDate.Text = startDate.ToString(CultureInfo.InvariantCulture);
txtEndDate.Text = endDate.ToString(CultureInfo.InvariantCulture);
var mc = new MessageController();
rptMessages.DataSource = mc.GetMessagesByDate(ModuleId, startDate, endDate, RoomId);
rptMessages.DataBind();
//if we have any items, don't display the "no results found" message
if (rptMessages.Items.Count > 0)
{
lblNoResults.Visible = false;
}
BuildArchiveLinks(RoomId);
var rc = new RoomController();
var r = rc.GetRoom(RoomId, ModuleId);
var tp = (CDefault)Page;
var t = new TabController().GetTab(TabId, PortalId, false);
tp.Title += string.Format(Localization.GetString("ChatArchiveTitle.Text", LocalResourceFile), t.TabName, r.RoomName, startDate.ToShortDateString(), endDate.ToShortDateString());
lblArchiveTitle.Text = string.Format(Localization.GetString("ChatArchiveContentTitle.Text", LocalResourceFile), r.RoomName, startDate.ToShortDateString(), endDate.ToShortDateString());
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void BuildArchiveLinks(Guid roomId)
{
var curTime = DateTime.UtcNow;
var today = curTime.Date;
var month = new DateTime(today.Year, today.Month, 1);
var ci = System.Threading.Thread.CurrentThread.CurrentCulture;
DayOfWeek fdow = ci.DateTimeFormat.FirstDayOfWeek;
DayOfWeek todayDow = curTime.DayOfWeek;
DateTime sow = curTime.AddDays(-(todayDow - fdow)).Date;
lbToday.NavigateUrl = BuildArchiveLink(roomId, curTime.Date, curTime);
lbYesterday.NavigateUrl = BuildArchiveLink(roomId, curTime.Date.AddDays(-1), curTime.Date);
lbThisWeek.NavigateUrl = BuildArchiveLink(roomId, sow, curTime);
lbLastWeek.NavigateUrl = BuildArchiveLink(roomId, sow.AddDays(-7), sow);
lbThisMonth.NavigateUrl = BuildArchiveLink(roomId, month, curTime);
lbLastMonth.NavigateUrl = BuildArchiveLink(roomId, month.AddMonths(-1), month);
}
protected string BuildArchiveLink(Guid roomId, DateTime startDate, DateTime endDate)
{
return EditUrl(string.Empty, string.Empty, "Archive", "&roomid=" + roomId + "&sd=" + startDate + "&ed=" + endDate);
}
protected void lbGo_Click(object sender, EventArgs e)
{
var roomId = Request.QueryString["roomid"];
if (roomId != null)
{
var guidRoomId = new Guid(roomId);
Response.Redirect(EditUrl(string.Empty, string.Empty, "Archive", "&roomid=" + roomId + "&sd=" + txtStartDate.Text + "&ed=" + txtEndDate.Text));
}
}
public static string ActivateLinksInText(string source)
{
source = " " + source + " ";
// easier to convert BR's to something more neutral for now.
source = Regex.Replace(source, "<", "<");
source = Regex.Replace(source, ">", ">");
source = Regex.Replace(source, "<br>|<br />|<br/>", "\n");
source = Regex.Replace(source, @"([\s])(www\..*?|http://.*?)([\s])", "$1<a href=\"$2\" target=\"_blank\">$2</a>$3");
source = Regex.Replace(source, @"href=""www\.", "href=\"http://www.");
//source = Regex.Replace(source, "\n", "<br />");
return source.Trim();
}
protected void rptMessages_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (rptMessages.Items.Count > 0)
{
if (e.Item.ItemType == ListItemType.Footer)
{
var lblNoResults = (Label)e.Item.FindControl("lblNoResults");
lblNoResults.Visible = false;
}
}
}
public string GetPhotoUrl(object authorUserId)
{
var userId = Convert.ToInt32(authorUserId);
if (userId > 0)
{
return UserController.Instance.GetUserProfilePictureUrl(userId, 32, 32);
}
return Settings.Contains("DefaultAvatarUrl") ? Settings["DefaultAvatarUrl"].ToString() : Localization.GetString("DefaultAvatarUrl", LocalResourceFile); ;
}
}
}