Shaun Mccran

My digital playground

10
J
U
L
2009

Upgrading Blog CFC from 5.8.001 to 5.9.3.006

I've been having the odd database login problem, and RSS feed issue when this site gets spidered by search bots. I can't really give my web host much grief about it as I don't know if either of these issues have been fixed in newer releases of Blog CFC.

So last night I set about upgrading to the newest release. Now like most developers I rarely find that an application does exactly what I want out of the box, so I had modified several small areas of the installation to suit my needs. This left me with the dilemma of not being able to just copy the new code over the top.

There is a tool I have used in the past called Beyond Compare from Scooter software http://www.scootersoftware.com/. It is a file and folder comparison tool that allows you to enter individual files and resolve potential conflicts at line level if need be.

After an hour or so of running through the newest release of Blog CFC, which you can get here, http://blogcfc.riaforge.org/ I had merged in all the new change sets into my base code, and run the database scripts and bingo! I was up-to-date. Far more easily done than I would have thought.

My only gripe is that he wrote SQL change scripts for mySQL rather than MSSQL, but then that's just personal preference.

It would be nice to have an entirely separate skinning module, that way you could just replace code bases, but if you are running your Blog then chances are you can deal with that.

09
J
U
L
2009

Cfscript looping over lists

I really like cfscript, but as with any skill I don't use it often in my current role (its not 'standard') so I find that my knowledge of it is on the wane.

I do develop extensively outside of a working environment, so I find myself deliberately writing cfscript code rather than 'normal' coldfusion. I think it is because it is more like javascript, actionScript or .Net, I like the script formatting.

So I find myself looping over a series of lists in a form action template, I thought I would experiment with the different ways of doing the loop, cfscript and non script. So I create a simple list.

view plain print about
1<cfset variables.myList = "Banana,Apple,Orange,Pear,Strawberry,Kiwi,Mandarin,Melon">

Now loop over it in the traditional way.

view plain print about
1<cfoutput>
2    <cfloop from="1" to="#listLen(variables.myList)#" index="L">
3    #ListGetAt(variables.myList, L)#<br/>
4    </cfloop>
5</cfoutput>

And now the cfscript way.

view plain print about
1<cfscript>
2 For (i=1;i LTE ListLen(variables.myList); i=i+1)
3 writeoutput(ListGetAt(variables.myList, i)&'<BR>');
4
</cfscript>

Both code blocks give the same output, I much prefer the code style of the second block though.

09
J
U
L
2009

Basic fusebox fuseaction to handle security references

I am a big fan of fusebox, I like the way it handles inheritance, and I love the fact that it instinctively lends itself to a modular approach.

Part of the strength in using fusebox is in knowing exactly when each of the framework fuse actions run, and just what sort of functionality you can embed in them. In this case I'm using the "Pre fuse Action" to perform a basic security validation on any fuseactions in that circuit.

view plain print about
1<cffunction name="prefuseaction">
2        <cfargument name="myFusebox" />
3        <cfargument name="event" />
4
5
6    </cffunction>

Above is a blank prefuseaction, insert any code you want to perform on any of the other fuseactions in that circuit here. Note that it runs before the circuit action.

A basic session validation script could be something like:

view plain print about
1<!--- check that user is logged in --->
2        <cfif NOT isdefined('session.loggedIn')>
3            <cfset session.logoutMsg = "Your session has timed out, please login again">
4            <cflocation url="index.cfm">
5            
6            <cfif NOT isdefined('session.superadmin')>
7                <cfset session.logoutMsg = "You do not have sufficient rights to view Super admin functions">
8                <cflocation url="index.cfm">
9            </cfif>
10
11        </cfif>

In the code above I am checking for a valid session variables, and if it is not there sets an error message and redirects to the homepage.

This is a pretty basic "catch all - are you logged in?" type query, but if you have an administration circuit then it provides good basic fuseaction protection. I've extended it out one step further by creating a cfc call to this code which just returns true/false. Something like this:

view plain print about
1<cfif application.security.check()>true<cfelse>false</cfif>

I am currently extending this further with more robust security, and user roles and groups.

03
J
U
L
2009

Function for getting the last modified date of a template

Whilst looking at creating dynamic Sitemaps for Google bot spidering I found that I needed to populate an XML node with the last modified date of the templates. I figured there must be a programmatic way of doing this, so after some searching around this is what I ended out with:

view plain print about
1<cfset mod_time = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(getcurrenttemplatepath()).lastModified())>

This creates a java object, using the date and file utilities we can use 'getcurrenttemplatepath()' to provide the path data, finally referencing the lastModified property.

A handy and relatively quick way of getting the last modified date.

It is a bit of a mouthful though, so might be easier to create it as a handy referencable object:

view plain print about
1<cffunction name="modStamp" access="public" returntype="date" output="no" hint="Gets the last mod date of a file, returns a ts">
2    <cfargument name="file" type="string" required="yes" hint="File to get mod date">
3        <cfset var mod_time = now()>
4        
5        <cfif fileexists(arguments.file)>
6            <cfset mod_time = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(arguments.file).lastModified())>
7        </cfif>
8        
9    <cfreturn mod_time>
10</cffunction>

Then you can just do:

view plain print about
1<cfset variables.fileMod = modStamp()>

_UNKNOWNTRANSLATION_ /