This repository has been archived by the owner on May 28, 2024. It is now read-only.
forked from gregmoser/MuraBliss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fw1EventAdapter.cfc
148 lines (118 loc) · 5.08 KB
/
fw1EventAdapter.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
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
<cfcomponent extends="mura.plugin.pluginGenericEventHandler">
<cfset variables.preserveKeyList="context,base,cfcbase,subsystem,subsystembase,section,item,services,action,controllerExecutionStarted,generateses,view,layout">
<!--- Include FW/1 configuration that is shared between then adapter and the application. --->
<cfinclude template="fw1Config.cfm">
<cffunction name="onMissingMethod">
<cfargument name="missingMethodName" />
<cfargument name="missingMethodArguments" />
<cfset doAction(missingMethodArguments.$, "frontend:event.#lcase(missingMethodName)#") />
</cffunction>
<cffunction name="onRenderStart">
<cfargument name="$" />
<cfset doAction($, "frontend:event.onrenderstart") />
<cfif $.event('#variables.framework.action#') neq "">
<cfif $.event('overrideContent') eq true>
<cfset $.content('body', doAction($, $.event(variables.framework.action))) />
<cfelse>
<cfset $.content('body', $.content('body') & doAction($, $.event(variables.framework.action))) />
</cfif>
</cfif>
</cffunction>
<cffunction name="onGlobalSessionStart" output="false">
<cfargument name="$">
<cfset var state=preserveInternalState(request)>
<cfinvoke component="Application" method="onSessionStart" />
<cfset restoreInternalState(request,state)>
</cffunction>
<cffunction name="onApplicationLoad" output="false">
<cfargument name="$">
<cfset var state=preserveInternalState(request)>
<cfset request.pluginConfig=variables.pluginConfig>
<cfinvoke component="Application" method="onApplicationStart" />
<cfset restoreInternalState(request,state)>
</cffunction>
<cffunction name="preserveInternalState" output="false">
<cfargument name="state">
<cfset var preserveKeys=structNew()>
<cfset var k="">
<cfloop list="#variables.preserveKeyList#" index="k">
<cfif isDefined("arguments.state.#k#")>
<cfset preserveKeys[k]=arguments.state[k]>
<cfset structDelete(arguments.state,k)>
</cfif>
</cfloop>
<cfset structDelete( arguments.state, "serviceExecutionComplete" )>
<cfreturn preserveKeys>
</cffunction>
<cffunction name="restoreInternalState" output="false">
<cfargument name="state">
<cfargument name="restore">
<cfloop list="#variables.preserveKeyList#" index="k">
<cfset structDelete(arguments.state,k)>
</cfloop>
<cfset structAppend(state,restore,true)>
<cfset structDelete( state, "serviceExecutionComplete" )>
</cffunction>
<cffunction name="doAction" output="false">
<cfargument name="$">
<cfargument name="action" type="string" required="false" default="" hint="Optional: If not passed it looks into the event for a defined action, else it uses the default"/>
<cfset var result = "" />
<cfset var savedEvent = "" />
<cfset var savedAction = "" />
<cfset var fw1 = createObject("component","Application") />
<cfset var local=structNew()>
<cfset var state=structNew()>
<!--- Put the event url struct, to be used by FW/1 --->
<cfset url.$ = $ />
<!--- Check to see if the action is the page request action --->
<cfif not len( arguments.action )>
<cfif len(arguments.$.event(variables.framework.action))>
<cfset arguments.action=arguments.$.event(variables.framework.action)>
<cfelse>
<cfset arguments.action=variables.framework.home>
</cfif>
</cfif>
<!--- put the action passed into the url scope, saving any pre-existing value --->
<cfif StructKeyExists(request, variables.framework.action)>
<cfset savedEvent = request[variables.framework.action] />
</cfif>
<cfif StructKeyExists(url,variables.framework.action)>
<cfset savedAction = url[variables.framework.action] />
</cfif>
<cfset url[variables.framework.action] = arguments.action />
<cfset state=preserveInternalState(request)>
<!--- call the frameworks onRequestStart --->
<cfset fw1.onRequestStart(CGI.SCRIPT_NAME) />
<cfset request.generateses = false />
<!--- call the frameworks onRequest --->
<!--- we save the results via cfsavecontent so we can display it in mura --->
<cfsavecontent variable="result">
<cfset fw1.onRequest(CGI.SCRIPT_NAME) />
</cfsavecontent>
<!--- Remove anything custom set in the request scope from this action call --->
<cfif structKeyExists(request, "overrideviewaction")>
<cfset structDelete(request, "overrideviewaction") />
</cfif>
<cfif structKeyExists(request, "view")>
<cfset structDelete(request, "view") />
</cfif>
<cfif structKeyExists(request, "controllers")>
<cfset structDelete(request, "controllers") />
</cfif>
<!--- restore the url scope --->
<cfif structKeyExists(url,variables.framework.action)>
<cfset structDelete(url,variables.framework.action) />
</cfif>
<!--- if there was a passed in action via the url then restore it --->
<cfif Len(savedAction)>
<cfset url[variables.framework.action] = savedAction />
</cfif>
<!--- if there was a passed in request event then restore it --->
<cfif Len(savedEvent)>
<cfset request[variables.framework.action] = savedEvent />
</cfif>
<cfset restoreInternalState(request,state)>
<!--- return the result --->
<cfreturn result>
</cffunction>
</cfcomponent>