PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/eventHandlers/MainEventHandler.cfc

http://github.com/blueriver/MuraFBConnect
ColdFusion CFScript | 118 lines | 91 code | 27 blank | 0 comment | 2 complexity | 146b1b16fd76f9e303d74c3d8d64f9db MD5 | raw file
  1<!---
  2   Copyright 2011 Blue River Interactive
  3
  4   Licensed under the Apache License, Version 2.0 (the "License");
  5   you may not use this file except in compliance with the License.
  6   You may obtain a copy of the License at
  7
  8       http://www.apache.org/licenses/LICENSE-2.0
  9
 10   Unless required by applicable law or agreed to in writing, software
 11   distributed under the License is distributed on an "AS IS" BASIS,
 12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13   See the License for the specific language governing permissions and
 14   limitations under the License.
 15--->
 16<cfcomponent extends="mura.plugin.pluginGenericEventHandler">
 17	
 18	<cfset variables.rbFactories={}>
 19		
 20	<cffunction name="onApplicationLoad" access="public" returntype="void" output="false">
 21		<cfargument name="$" />
 22		<cfset var local={}>
 23		<cfset local.rsSites=variables.pluginConfig.getAssignedSites()>
 24	
 25		<cfloop query="local.rsSites">
 26			<!--- Get the siteBean--->
 27			<cfset local.site=$.getBean("settingsManager").getSite(local.rsSites.siteID)>
 28			<!--- Create an instance of a resource bundle factory for each site and set it int he plugin application object --->
 29			<cfset variables.rbFactories[local.rsSites.siteID]=createObject("component","mura.resourceBundle.resourceBundleFactory").init(local.site.getRBFactory(),"#expandPath('/plugins')#/#pluginConfig.getDirectory()#/resourceBundles/",local.site.getJavaLocale())>
 30			<!--- Make sure that the Facebook subtype is created.
 31			 	  user type eq 1, group eq 2--->
 32			<cfset variables.configBean.getClassExtensionManager().getSubTypeByName("2","Facebook",local.rsSites.siteID).save()>
 33			
 34			<!--- Make sure that the Facebook user group is created --->
 35			<cfset local.group=$.getBean("user").loadBy(groupname="Facebook",siteid=local.rsSites.siteID)>
 36			<cfif local.group.getIsNew()>
 37				<cfset local.group.setSiteID(local.rsSites.siteID).setType(1).setGroupName("Facebook").setIsPublic(1).save()>
 38			</cfif>
 39		</cfloop>
 40		
 41		<cfset variables.pluginConfig.addEventHandler(this)>
 42	</cffunction>
 43	
 44	<cffunction name="onGlobalRequestStart" access="public" returntype="void" output="false">
 45		<cfargument name="$" />
 46		
 47		<cfif NOT structKeyExists(application,pluginConfig.getPackage())>
 48			<cfset application[pluginConfig.getPackage()] = {} />
 49			<cfset application[pluginConfig.getPackage()]['settingsService'] = CreateObject('component','#pluginConfig.getPackage()#.com.blueriver.SettingsService').init(
 50						application.configBean.getContext() & '/plugins/' & pluginConfig.getDirectory(),
 51						'ps' & hash('#pluginConfig.getPackage()#') & '.json',
 52						getDefaultSettings(),
 53						'default'
 54					) />
 55		</cfif>
 56	</cffunction>
 57	
 58	<cffunction name="onSiteRequestStart" access="public" returntype="void" output="false">
 59		<cfargument name="$" />
 60		<cfset onGlobalRequestStart(arguments.$) />
 61	</cffunction>
 62	
 63	<cffunction name="onRenderStart" access="public" returntype="void" output="false">
 64		<cfargument name="$" />
 65
 66		<cfif $.currentUser('isLoggedIn') and listLast($.currentUser("email"),"@") eq "facebook.com" and $.event('display') neq 'editProfile'>
 67			<cflocation addtoken="no" url="#$.siteConfig('EditProfileURL')#&returnURL=#URLEncodedFormat($.getCurrentURL())#" />
 68		</cfif>
 69	
 70	</cffunction>
 71
 72	<cffunction name="onSiteLoginPromptRender" access="public" returntype="string" output="false">
 73		<cfargument name="$" />
 74		
 75		<cfset var outout = "" />
 76		
 77		<cfsavecontent variable="output">
 78			<cfoutput>#$.dspObject_Include(theFile="dsp_login.cfm")#</cfoutput><!--- Output the login form --->
 79			<cfinclude template="../displayObjects/dsp_facebookLogin.cfm" /><!--- include / ouput the facebook login button --->
 80		</cfsavecontent>
 81		
 82		<cfreturn trim(output) />
 83	</cffunction>
 84	
 85	<cffunction name="onSiteEditProfileRender" access="public" returntype="string" output="false">
 86		<cfargument name="$" />
 87		
 88		<cfset var local = {} />
 89		
 90		<cfset local.email = $.currentUser("email") />
 91		<cfif listLast($.currentUser("email"),'@') IS 'facebook.com'>
 92			<cfset local.email = "" />
 93		</cfif>
 94		
 95		<cfset local.rbFactory=variables.rbFactories[$.event('siteID')]>
 96		
 97		<cfsavecontent variable="local.output">
 98			<cfif listLast($.currentUser("email"),'@') IS 'facebook.com'>
 99				<cfinclude template="../displayObjects/dsp_facebookEmail.cfm">
100			<cfelse>
101				<cfinclude template="../displayObjects/dsp_edit_profile.cfm">
102			</cfif>
103		</cfsavecontent>
104		
105		<cfreturn trim(local.output) />
106	</cffunction>
107	
108	<cffunction name="getDefaultSettings" access="private" returntype="struct" output="false">
109		<cfset var local = {} />
110		<cfset local.settings = {} />
111		<cfset local.settings['default'] = {} />
112		<cfset local.settings['default']['facebook'] = {} />
113		<cfset local.settings['default']['facebook']['client_id'] = pluginConfig.getSetting('client_id') />
114		
115		<cfreturn local.settings />
116	</cffunction>
117
118</cfcomponent>