forked from tkelley/MangoBlog-metaTags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasePlugin.cfc
151 lines (122 loc) · 6.98 KB
/
BasePlugin.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
149
150
151
<cfcomponent output="false">
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="init" access="public" output="false" returntype="any">
<cfargument name="mainManager" type="any" required="true" />
<cfargument name="preferences" type="any" required="true" />
<cfset variables.mainManager = arguments.mainManager />
<cfset variables.preferencesManager = arguments.preferences />
<cfreturn this/>
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getManager" access="public" output="false" returntype="any">
<cfreturn variables.mainManager />
</cffunction>
<cffunction name="setManager" access="public" output="false" returntype="void">
<cfargument name="mainManager" type="any" required="true" />
<cfset variables.mainManager = arguments.mainManager />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getPreferencesManager" access="public" output="false" returntype="any">
<cfreturn variables.preferencesManager />
</cffunction>
<cffunction name="setPreferencesManager" access="public" output="false" returntype="void">
<cfargument name="preferencesManager" type="any" required="true" />
<cfset variables.preferencesManager = arguments.preferencesManager />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getId" access="public" output="false" returntype="any">
<cfreturn variables.id />
</cffunction>
<cffunction name="setId" access="public" output="false" returntype="void">
<cfargument name="id" type="any" required="true" />
<cfset variables.id = arguments.id />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getName" access="public" output="false" returntype="string">
<cfreturn variables.name />
</cffunction>
<cffunction name="setName" access="public" output="false" returntype="void">
<cfargument name="name" type="string" required="true" />
<cfset variables.name = arguments.name />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="setup" hint="This is run when a plugin is activated" access="public" output="false" returntype="any">
<cfreturn "#variables.name# activated" />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="unsetup" hint="This is run when a plugin is de-activated" access="public" output="false" returntype="any">
<cfreturn "#variables.name# de-activated" />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="handleEvent" hint="Asynchronous event handling" access="public" output="false" returntype="any">
<cfargument name="event" type="any" required="true" />
<cfreturn />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="processEvent" hint="Synchronous event handling" access="public" output="false" returntype="any">
<cfargument name="event" type="any" required="true" />
<cfreturn arguments.event />
</cffunction>
<!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="remove" hint="This is run when a plugin is removed" access="public" output="false" returntype="any">
<!--- You should override this method, but at the very least, we clean up our preferences --->
<cfif structkeyexists(variables,"package")>
<cfset variables.preferencesManager.removeNode(variables.package) />
</cfif>
<cfreturn "#variables.name# removed" />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="upgrade" hint="This is run when a plugin is upgraded" access="public" output="false" returntype="any">
<cfargument name="fromVersion" type="string" />
<cfreturn "#variables.name# upgraded" />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getPackage" access="public" output="false" returntype="any">
<cfreturn variables.package />
</cffunction>
<cffunction name="setPackage" access="public" output="false" returntype="void">
<cfargument name="package" type="any" required="true" />
<cfset variables.package = arguments.package />
</cffunction>
<!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getAssetPath" access="public" output="false" returntype="any">
<cfreturn getManager().getBlog().getBasePath() & "assets/plugins/" & getPluginDirName() & "/" />
</cffunction>
<cffunction name="getAdminAssetPath" access="public" output="false" returntype="any">
<cfreturn getManager().getBlog().getBasePath() & "admin/assets/plugins/" & getPluginDirName() & "/" />
</cffunction>
<cffunction name="getPluginDirName" access="private" output="false" returntype="any">
<cfset var name = getMetaData(this).name />
<cfset var dir = ListGetAt(name, ListLen(name, ".")-1, ".")>
<cfreturn dir />
</cffunction>
<!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="initSettings" access="public" output="true" returntype="void">
<cfset var key = "" />
<cfset variables.settings = variables.preferencesManager.exportSubtreeAsStruct(variables.package) />
<cfloop collection="#arguments#" item="key">
<cfif NOT structkeyexists(variables.settings, key)>
<cfset variables.settings[key] = arguments[key] />
</cfif>
</cfloop>
</cffunction>
<!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="setSettings" access="public" output="false" returntype="void">
<cfset var key = "" />
<cfloop collection="#arguments#" item="key">
<cfset variables.settings[key] = arguments[key] />
</cfloop>
</cffunction>
<!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="getSetting" access="public" output="false" returntype="any">
<cfargument name="key" type="any" required="true" />
<cfreturn variables.settings[arguments.key] />
</cffunction>
<!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
<cffunction name="persistSettings" access="public" output="false" returntype="void">
<cfset var key = "" />
<cfloop collection="#variables.settings#" item="key">
<cfset variables.preferencesManager.put( variables.package, key, variables.settings[key]) />
</cfloop>
</cffunction>
</cfcomponent>