-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtility.cs
More file actions
83 lines (73 loc) · 3.47 KB
/
Utility.cs
File metadata and controls
83 lines (73 loc) · 3.47 KB
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
using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rock;
using Rock.Data;
using Rock.Model;
using Rock.Web.Cache;
namespace com.rocklabs.Forums
{
public static class Utility
{
/// <summary>
/// Convert the markdown into Html. This should be used anytime a project comment
/// is to be displayed as it automatically converst #1234 references into links
/// as well as fixes some standard formatting issues with images.
/// </summary>
/// <param name="markdown">The markdown text to be converted.</param>
/// <returns>A string of HTML text that may be displayed.</returns>
public static string ConvertMarkdownToHtml( string markdown )
{
var settings = CommonMark.CommonMarkSettings.Default.Clone();
settings.OutputDelegate = ( doc, output, dSettings ) =>
{
new Support.MarkdownHtmlFormatter( output, dSettings ).WriteDocument( doc );
};
return CommonMark.CommonMarkConverter.Convert( markdown, settings );
}
/// <summary>
/// Configures a control to display and toggle following for the specified entity
/// This is a duplication of core functionality until #2401 is fixed.
/// </summary>
/// <param name="followEntity">The follow entity. NOTE: Make sure to use PersonAlias instead of Person when following a Person</param>
/// <param name="followControl">The follow control.</param>
/// <param name="follower">The follower.</param>
public static void SetFollowing( IEntity followEntity, WebControl followControl, Person follower )
{
var followingEntityType = EntityTypeCache.Read( followEntity.GetType() );
if ( follower != null && follower.PrimaryAliasId.HasValue )
{
using ( var rockContext = new RockContext() )
{
var personAliasService = new PersonAliasService( rockContext );
var followingService = new FollowingService( rockContext );
var followingQry = followingService.Queryable()
.Where( f =>
f.EntityTypeId == followingEntityType.Id &&
f.PersonAlias.PersonId == follower.Id );
followingQry = followingQry.Where( f => f.EntityId == followEntity.Id );
if ( followingQry.Any() )
{
followControl.AddCssClass( "following" );
}
else
{
followControl.RemoveCssClass( "following" );
}
}
int entityId = followEntity.Id;
// only show the following control if the entity has been saved to the database
followControl.Visible = entityId > 0;
string script = string.Format(
@"Rock.controls.followingsToggler.initialize($('#{0}'), {1}, {2}, {3}, {4});",
followControl.ClientID,
followingEntityType.Id,
entityId,
follower.Id,
follower.PrimaryAliasId );
ScriptManager.RegisterStartupScript( followControl, followControl.GetType(), string.Format( "{0}_following", followControl.ClientID ), script, true );
}
}
}
}