PageRenderTime 18ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/MobileMura.cfc

http://github.com/Lagaffe/MobileMura
ColdFusion CFScript | 119 lines | 91 code | 28 blank | 0 comment | 7 complexity | e1acdcc276676ca9da710dd28da954d1 MD5 | raw file
  1<!---
  2
  3MobileMura/MobileMura.cfc
  4
  5Copyright 2011 Guust Nieuwenhuis 
  6
  7Licensed under the Apache License, Version 2.0 (the "License"); 
  8you may not use this file except in compliance with the License. 
  9You may obtain a copy of the License at 
 10
 11http://www.apache.org/licenses/LICENSE-2.0 
 12
 13Unless required by applicable law or agreed to in writing, software 
 14distributed under the License is distributed on an "AS IS" BASIS, 
 15WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 16See the License for the specific language governing permissions and 
 17limitations under the License. 
 18
 19--->
 20
 21<cfcomponent>
 22	
 23	<cffunction name="updateTemplate" output="false" returntype="any" access="public" >
 24		<cfargument name="contentBean" />
 25		
 26		<cfset var $ = application.serviceFactory.getBean("muraScope").init(session.siteID) />
 27
 28		<cfset var c = arguments.contentBean />
 29		<cfset var p = arguments.contentBean />
 30		
 31		<cfset var mobileTemplate = "" />
 32		
 33		<!--- check if a template is set --->
 34		<!--- inherit from parent == empty string --->
 35		<!--- if the template is an empty string: look for the parents template --->
 36		<cfloop condition="NOT Len(c.getTemplate())" >
 37			<!--- get the template --->
 38			<cfset c = c.getParent() />
 39		</cfloop>
 40		
 41		<!--- the 'mobiletemplate' is set --->
 42		<cfif Len(arguments.contentBean.getValue("mobiletemplate"))>
 43			
 44			<!--- Inherit From Parent --->
 45			<cfif arguments.contentBean.getValue("mobiletemplate") EQ "-1">
 46				<cfset i = true />
 47				<cfloop condition="i" >
 48					<cfif p.hasParent()>
 49						<cfset p = p.getParent() />
 50
 51						<cfif Len(p.getExtendedAttribute("mobiletemplate"))>
 52							<cfif p.getExtendedAttribute("mobiletemplate") EQ "-1">
 53								
 54							<cfelseif p.getExtendedAttribute("mobiletemplate") EQ "0">
 55								<cfset mobileTemplate = p.getTemplate() />
 56								<cfset i = false />
 57							<cfelse>
 58								<cfset mobileTemplate = p.getExtendedAttribute("mobiletemplate") />
 59								<cfset i = false />
 60							</cfif>
 61						</cfif>
 62					<cfelse>
 63						<cfset mobileTemplate = p.getTemplate() />
 64						<cfset i = false />
 65					</cfif>
 66				</cfloop>
 67			
 68			<!--- Desktop Template --->
 69			<cfelseif arguments.contentBean.getValue("mobiletemplate") EQ "-2">
 70				<cfset mobileTemplate = "" />
 71			<cfelse>
 72				<cfset mobileTemplate = arguments.contentBean.getValue("mobiletemplate") />
 73			</cfif>
 74			
 75		<!--- the 'mobiletemplate' isn't set --->
 76		<cfelse>
 77			<cfset mobileTemplate = "" />
 78		</cfif>
 79		
 80		<!--- if a mobiletemplate is set and if the file exists --->
 81		<cfif Len(mobileTemplate) AND FileExists($.siteConfig().getTemplateIncludeDir() & "/" & mobileTemplate)>
 82			<!--- change the template --->
 83			<cfset arguments.contentBean.setTemplate(mobileTemplate) />
 84		</cfif>
 85
 86		<cfreturn />
 87	</cffunction>
 88	
 89
 90	<cffunction name="updateTheme" output="false" returntype="any">
 91		<cfargument name="MuraScope" type="Any" required="true">
 92		<!---<cflog log="MobileMura" type="information" text="MobileTheme: #getMobileMuraData(session.siteid).getMobileTheme()#" />--->
 93		<cfif Len(getMobileMuraData(session.siteid).getMobileTheme())>
 94			<!---<cflog log="MobileMura" type="information" text="entered cfif" />--->
 95			<cfset MuraScope.event("altTheme",getMobileMuraData(session.siteid).getMobileTheme()) />
 96			<cfif fileExists(expandPath(MuraScope.siteConfig('themeIncludePath')) & "/contentRenderer.cfc" )>
 97				<cfset themeRenderer=createObject("component","#MuraScope.siteConfig('themeAssetMap')#.contentRenderer").init()>
 98				<cfset themeRenderer.injectMethod("mura",MuraScope)>
 99				<cfset themeRenderer.injectMethod("$",MuraScope)>
100				<cfset themeRenderer.injectMethod("event",MuraScope.event())>
101				<cfset MuraScope.event("themeRenderer",themeRenderer)>
102			</cfif>
103			<!---<cflog log="MobileMura" type="information" text="altTheme: #MuraScope.event('altTheme')#" />--->
104		</cfif>
105		<cfreturn />
106	</cffunction>
107
108	
109	<cffunction name="getMobileMuraData" output="false" returntype="any">
110		<cfargument name="siteID" type="Any" required="true">
111	
112		<cfset var myDataObject	= createObject("component","mura.extend.extendObject").init(Type="Custom",SubType="MobileMuraData",SiteID=arguments.siteID)>
113	
114		<cfset myDataObject.setID( siteID ) />
115	
116		<cfreturn myDataObject />
117	</cffunction>
118
119</cfcomponent>