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