-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathApplication.cfc
175 lines (146 loc) · 6.96 KB
/
Application.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<cfcomponent output="false">
<cfset this.name = "myaggregator">
<cfset this.sessionManagement = "true">
<cfset this.scriptProtect = "false">
<cfset this.datasource = "myaggregator">
<cfsetting showdebugoutput="false">
<cffunction name="onApplicationStart" returnType="boolean" output="false">
<!--- config info --->
<cfset application.dsn = "myaggregator">
<cfset application.siteName = "ColdFusionBloggers.org" />
<cfset application.siteTitle = "ColdFusionBloggers" />
<cfset application.siteURL = "www.coldfusionbloggers.org" />
<cfset application.alternateSiteNames = "cfbloggers.org, www.cfbloggers.org" />
<cfset application.RSSFeedURL = "http://feedproxy.google.com/ColdfusionbloggersorgFeed" />
<cfset application.twitterUser = "cfbloggers" />
<cfset application.perpage = 10>
<cfset application.adminemail = "test@test.com.com">
<cfset application.processkey = "changeme">
<cfset application.slogans = ["PHP is free - but so are farts","because coldfusion bloggers can't shut up","because coldfusion bloggers love to blog","because coldfusion bloggers aren't paranoid... really","because a phpbloggers site would be silly","this slogan for rent","building sites better and faster","coldfusion - the best dead language","visit the wishlist or the site dies!"] />
<cfset application.dev = false>
<cfset application.twitterNotification = true />
<cfset application.oAuth = {consumerKey = 'changeme',
consumerSecret = 'oriwontwork',
accessToken = "hopeyoureadthis",
accessTokenSecret = "ditto"} />
<!--- end config info --->
<!--- used to see if we are local. Yes, I have dev above. Going to keep this anyway. --->
<cfif findNoCase("dev", cgi.server_name)>
<cfset application.localserver = true>
<cfelse>
<cfset application.localserver = false>
</cfif>
<cfset application.aggregator = createObject("component", "components.aggregator")>
<cfset application.emailalert = createObject("component", "components.emailalert").init(application.dsn)>
<cfset application.entries = createObject("component", "components.entries").init(application.dsn)>
<cfset application.user = createObject("component", "components.user").init(application.dsn)>
<cfset application.toxml = createObject("component", "components.toxml")>
<cfset application.rss = createObject("component", "components.rss")>
<cfset var root = getDirectoryFromPath(getCurrentTemplatePath())>
<cfif application.twitterNotification>
<cfscript>
application.objMonkehTweet = createObject('component', 'components.coldfumonkeh.monkehTweet').init(
consumerKey = '#application.oAuth.consumerKey#',
consumerSecret = '#application.oAuth.consumerSecret#',
oauthToken = '#application.oAuth.accessToken#',
oauthTokenSecret = '#application.oAuth.accessTokenSecret#',
userAccountName = '#application.twitterUser#',
parseResults = true
);
</cfscript>
</cfif>
<cfset application.utils = createObject("component", "components.utils")>
<cfset application.usercount = 0>
<cfset application.rsscache = structNew()>
<cfset application.opmlcache = "">
<!--- clear cache --->
<cfset var ids = cacheGetAllIds()>
<cfset var id = "">
<cfloop index="id" array="#ids#">
<cfif findNoCase("feedlist", id)>
<cfset cacheRemove(id)>
</cfif>
</cfloop>
<cfreturn true>
</cffunction>
<cffunction name="onApplicationEnd" returnType="void" output="false">
<cfargument name="applicationScope" required="true">
</cffunction>
<cffunction name="onMissingTemplate" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cflocation url="/404.cfm?thepage=#urlEncodedFormat(arguments.thePage)#" addToken="false" statusCode="301">
</cffunction>
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cfif structKeyExists(url,"reinit")>
<cfset onApplicationStart()>
</cfif>
<cfif structKeyExists(url, "logout")>
<cfset session.loggedin = false>
<cfset structDelete(session, "user")>
<cflocation url="index.cfm" addToken="false">
</cfif>
<!--- support ?c=X urls for shorter click.cfm requests --->
<cfif structKeyExists(url, "c") and isNumeric(url.c)>
<cflocation url="http://#application.siteUrl#/click.cfm?entry=#url.c#" addToken="false">
</cfif>
<cfif listFindNoCase(application.alternateSiteNames,cgi.SERVER_NAME)>
<cflocation url="http://#application.siteURL##arguments.thepage#" statuscode="301" addToken="false">
</cfif>
<!--- check for key in scheduled folder --->
<cfif findNoCase("/scheduled/", arguments.thePage)>
<cfif not structKeyExists(url, "processkey") or url.processkey neq application.processkey>
<cfoutput>
<h2>Access Denied</h2>
</cfoutput>
<cfabort>
</cfif>
</cfif>
<cfif structKeyExists(form, "adminlogin") and form.adminpassword is application.processkey>
<cfset session.adminlogin = true>
</cfif>
<cfif findNoCase("/admin/", arguments.thePage) and (not structKeyExists(session, "adminlogin") OR NOT session.adminLogin)>
<cfinclude template="/admin/login.cfm">
<cfabort>
</cfif>
<cfif structKeyExists(url, "perpage") and isNumeric(url.perpage) and url.perpage gte 1 and url.perpage lte 100>
<cfcookie name="perpage" value="#round(url.perpage)#" expires="never">
</cfif>
<!--- check/set cookie for perpage --->
<cfif structKeyExists(cookie, "perpage") and isNumeric(cookie.perpage) and cookie.perpage gte 1 and cookie.perpage lte 100>
<cfset request.perpage = round(cookie.perpage)>
<cfelse>
<cfset request.perpage = application.perpage>
</cfif>
<cfreturn true>
</cffunction>
<cffunction name="onError" returnType="void" output="false">
<cfargument name="exception" required="true">
<cfargument name="eventname" type="string" required="true">
<!--- if adminemail does not exist, consider this a NOT loaded app --->
<cfif not structKeyExists(application,"adminemail") or (structKeyExists(application, "localserver") and application.localserver)>
<cfdump var="#arguments#" label="Error"><cfabort>
<cfelse>
<cfmail to="#application.adminemail#" from="#application.adminemail#" subject="#application.sitename# error" type="html">
<cfdump var="#arguments#" label="ERROR!!">
</cfmail>
<cflocation url="/error.cfm" addToken="false">
</cfif>
</cffunction>
<cffunction name="onSessionStart" returnType="void" output="false">
<cflock name="MyAppLock" type="exclusive" timeout="30">
<cfset application.usercount++>
</cflock>
<cfset session.loggedin = false>
</cffunction>
<cffunction name="onSessionEnd" returnType="void" output="false">
<cfargument name="sessionScope" type="struct" required="true">
<cfargument name="appScope" type="struct" required="false">
<cflock name="MyAppLock" type="exclusive" timeout="30">
<cfset arguments.appScope.usercount-->
<cfif arguments.appScope.userCount lt 0>
<cfset arguments.appScope.userCount = 0>
</cfif>
</cflock>
</cffunction>
</cfcomponent>