This repository has been archived by the owner on Apr 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pluginEventHandler.cfc
62 lines (48 loc) · 2.01 KB
/
pluginEventHandler.cfc
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
component extends='mura.plugin.pluginGenericEventHandler' {
variables.pluginConfig = application.pluginManager.getConfig( 'MuraMarkdown' );
public void function onContentEdit( required $ ) {
variables.pluginConfig.addToHTMLHeadQueue( 'headcode.cfm' );
}
public void function onBeforeContentSave( required $ ) {
var pluginPath = $.globalConfig('context') & '/plugins/' & variables.pluginConfig.getDirectory();
var jarPath = [ expandPath( pluginPath & '/markdown/markdownj.jar' ) ];
var processor = $.getBean('javaloader').init( jarPath ).create( 'com.petebevin.markdown.MarkdownProcessor' ).init();
var summary = $.content('summary');
var body = $.content('body');
$.content( 'summary', processMarkdown( processor, summary ) );
$.content( 'body', processMarkdown( processor, body ) );
processExtendedAttributes( $, processor );
}
private void function processExtendedAttributes( required $, required processor ) {
var rsAttributes = $.content().getExtendedData().getAllValues().data;
var attributeList = '';
var qrySvc = '';
if( rsAttributes.recordCount ) {
attributeList = valueList( rsAttributes.attributeID );
qrySvc = new query()
.setDatasource( $.globalConfig( 'datasource' ) )
.setUsername( $.globalConfig( 'dbUsername' ) )
.setPassword( $.globalConfig( 'dbPassword' ) );
qrySvc.setSQL("
SELECT
name
, attributeID
FROM
tclassextendattributes
WHERE
attributeID IN ( :attributeList )
AND
type = 'HTMLEditor'
");
qrySvc.addParam( name = 'attributeList', value = attributeList, cfsqltype = 'CF_SQL_VARCHAR', list = true );
rsAttributes = qrySvc.execute().getResult();
for( var i = 1; i LTE rsAttributes.recordCount; i++ ) {
var content = $.content( rsAttributes.name );
$.content( rsAttributes.name, processMarkdown( arguments.processor, content ) );
}
}
}
private string function processMarkdown( required processor, required string content ) {
return arguments.processor.markdown( arguments.content );
}
}